Commit 14c5a8f2 authored by tedchoc's avatar tedchoc Committed by Commit Bot

Do not process incoming intents to the search activity if promo is needed.

BUG=738628

Review-Url: https://codereview.chromium.org/2963393002
Cr-Commit-Position: refs/heads/master@{#486483}
parent 148fef68
......@@ -31,12 +31,13 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
}
private Delegate mDelegate;
private boolean mShowSuggestions;
private boolean mPendingSearchPromoDecision;
private boolean mPendingBeginQuery;
public SearchActivityLocationBarLayout(Context context, AttributeSet attrs) {
super(context, attrs, R.layout.location_bar_base);
setUrlBarFocusable(true);
mShowSuggestions = !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckForSearchEnginePromo();
}
/** Set the {@link Delegate}. */
......@@ -69,14 +70,15 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
public void onNativeLibraryReady() {
super.onNativeLibraryReady();
setAutocompleteProfile(Profile.getLastUsedProfile().getOriginalProfile());
mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckForSearchEnginePromo();
setShowCachedZeroSuggestResults(true);
mShowSuggestions = !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
}
@Override
public void onSuggestionsReceived(
List<OmniboxSuggestion> newSuggestions, String inlineAutocompleteText) {
if (!mShowSuggestions) return;
if (mPendingSearchPromoDecision) return;
super.onSuggestionsReceived(newSuggestions, inlineAutocompleteText);
}
......@@ -85,11 +87,39 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
SearchWidgetProvider.updateCachedVoiceSearchAvailability(isVoiceSearchEnabled());
if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true);
if (!TextUtils.isEmpty(mUrlBar.getText())) onTextChangedForAutocomplete();
mShowSuggestions = true;
assert !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
mPendingSearchPromoDecision = false;
if (mPendingBeginQuery) {
beginQueryInternal(isVoiceSearchIntent);
mPendingBeginQuery = false;
}
}
/** Begins a new query. */
void beginQuery(boolean isVoiceSearchIntent) {
// Clear the text regardless of the promo decision. This allows the user to enter text
// before native has been initialized and have it not be cleared one the delayed beginQuery
// logic is performed.
mUrlBar.setIgnoreTextChangesForAutocomplete(true);
mUrlBar.setUrl("", null);
mUrlBar.setIgnoreTextChangesForAutocomplete(false);
mUrlBar.setCursorVisible(true);
mUrlBar.setSelection(0, mUrlBar.getText().length());
if (mPendingSearchPromoDecision) {
mPendingBeginQuery = true;
return;
}
beginQueryInternal(isVoiceSearchIntent);
}
private void beginQueryInternal(boolean isVoiceSearchIntent) {
assert !mPendingSearchPromoDecision;
if (isVoiceSearchEnabled() && isVoiceSearchIntent) {
startVoiceRecognition();
} else {
......@@ -105,14 +135,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
}
private void focusTextBox() {
if (mNativeInitialized) onUrlFocusChange(true);
if (!mUrlBar.hasFocus()) mUrlBar.requestFocus();
mUrlBar.setIgnoreTextChangesForAutocomplete(true);
mUrlBar.setUrl("", null);
mUrlBar.setIgnoreTextChangesForAutocomplete(false);
mUrlBar.setCursorVisible(true);
mUrlBar.setSelection(0, mUrlBar.getText().length());
new Handler().post(new Runnable() {
@Override
public void run() {
......
......@@ -98,10 +98,15 @@ public class SearchActivityTest {
}
});
super.showSearchEngineDialogIfNeeded(activity, onSearchEngineFinalized);
return;
} else {
LocaleManager.setInstanceForTest(new LocaleManager() {
@Override
public boolean needToCheckForSearchEnginePromo() {
return false;
}
});
if (!shouldDelayDeferredInitialization) onSearchEngineFinalized.onResult(true);
}
if (!shouldDelayDeferredInitialization) onSearchEngineFinalized.onResult(true);
}
@Override
......@@ -132,6 +137,7 @@ public class SearchActivityTest {
@After
public void tearDown() {
SearchActivity.setDelegateForTests(null);
LocaleManager.setInstanceForTest(null);
}
@Test
......@@ -454,6 +460,7 @@ public class SearchActivityTest {
@Override
public void run() {
UrlBar urlBar = (UrlBar) activity.findViewById(R.id.url_bar);
if (!urlBar.hasFocus()) urlBar.requestFocus();
urlBar.setText(url);
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment