Index: chrome/android/java/src/org/chromium/chrome/browser/searchwidget/SearchActivityLocationBarLayout.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/searchwidget/SearchActivityLocationBarLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/searchwidget/SearchActivityLocationBarLayout.java |
index 995ffa48db9cfa6ee44a93f5ed59a1b5d89fad45..39705708fee6692a798e19d98d39803a9c62272e 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/searchwidget/SearchActivityLocationBarLayout.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/searchwidget/SearchActivityLocationBarLayout.java |
@@ -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() { |