Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/searchwidget/SearchActivityLocationBarLayout.java

Issue 2963393002: Do not process incoming intents to the search activity if promo is needed. (Closed)
Patch Set: Fix tests Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/searchwidget/SearchActivityTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.searchwidget; 5 package org.chromium.chrome.browser.searchwidget;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.Handler; 8 import android.os.Handler;
9 import android.text.TextUtils; 9 import android.text.TextUtils;
10 import android.util.AttributeSet; 10 import android.util.AttributeSet;
(...skipping 13 matching lines...) Expand all
24 /** Delegates calls out to the containing Activity. */ 24 /** Delegates calls out to the containing Activity. */
25 public static interface Delegate { 25 public static interface Delegate {
26 /** Load a URL in the associated tab. */ 26 /** Load a URL in the associated tab. */
27 void loadUrl(String url); 27 void loadUrl(String url);
28 28
29 /** The user hit the back button. */ 29 /** The user hit the back button. */
30 void backKeyPressed(); 30 void backKeyPressed();
31 } 31 }
32 32
33 private Delegate mDelegate; 33 private Delegate mDelegate;
34 private boolean mShowSuggestions; 34 private boolean mPendingSearchPromoDecision;
35 private boolean mPendingBeginQuery;
35 36
36 public SearchActivityLocationBarLayout(Context context, AttributeSet attrs) { 37 public SearchActivityLocationBarLayout(Context context, AttributeSet attrs) {
37 super(context, attrs, R.layout.location_bar_base); 38 super(context, attrs, R.layout.location_bar_base);
38 setUrlBarFocusable(true); 39 setUrlBarFocusable(true);
39 mShowSuggestions = !LocaleManager.getInstance().needToCheckForSearchEngi nePromo(); 40 mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckFor SearchEnginePromo();
40 } 41 }
41 42
42 /** Set the {@link Delegate}. */ 43 /** Set the {@link Delegate}. */
43 void setDelegate(Delegate delegate) { 44 void setDelegate(Delegate delegate) {
44 mDelegate = delegate; 45 mDelegate = delegate;
45 } 46 }
46 47
47 @Override 48 @Override
48 protected void loadUrl(String url, int transition) { 49 protected void loadUrl(String url, int transition) {
49 mDelegate.loadUrl(url); 50 mDelegate.loadUrl(url);
(...skipping 12 matching lines...) Expand all
62 63
63 @Override 64 @Override
64 public void setUrlToPageUrl() { 65 public void setUrlToPageUrl() {
65 // Explicitly do nothing. The tab is invisible, so showing its URL woul d be confusing. 66 // Explicitly do nothing. The tab is invisible, so showing its URL woul d be confusing.
66 } 67 }
67 68
68 @Override 69 @Override
69 public void onNativeLibraryReady() { 70 public void onNativeLibraryReady() {
70 super.onNativeLibraryReady(); 71 super.onNativeLibraryReady();
71 setAutocompleteProfile(Profile.getLastUsedProfile().getOriginalProfile() ); 72 setAutocompleteProfile(Profile.getLastUsedProfile().getOriginalProfile() );
73
74 mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckFor SearchEnginePromo();
72 setShowCachedZeroSuggestResults(true); 75 setShowCachedZeroSuggestResults(true);
73 mShowSuggestions = !LocaleManager.getInstance().needToCheckForSearchEngi nePromo();
74 } 76 }
75 77
76 @Override 78 @Override
77 public void onSuggestionsReceived( 79 public void onSuggestionsReceived(
78 List<OmniboxSuggestion> newSuggestions, String inlineAutocompleteTex t) { 80 List<OmniboxSuggestion> newSuggestions, String inlineAutocompleteTex t) {
79 if (!mShowSuggestions) return; 81 if (mPendingSearchPromoDecision) return;
80 super.onSuggestionsReceived(newSuggestions, inlineAutocompleteText); 82 super.onSuggestionsReceived(newSuggestions, inlineAutocompleteText);
81 } 83 }
82 84
83 /** Called when the SearchActivity has finished initialization. */ 85 /** Called when the SearchActivity has finished initialization. */
84 void onDeferredStartup(boolean isVoiceSearchIntent) { 86 void onDeferredStartup(boolean isVoiceSearchIntent) {
85 SearchWidgetProvider.updateCachedVoiceSearchAvailability(isVoiceSearchEn abled()); 87 SearchWidgetProvider.updateCachedVoiceSearchAvailability(isVoiceSearchEn abled());
86 if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true); 88 if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true);
87 if (!TextUtils.isEmpty(mUrlBar.getText())) onTextChangedForAutocomplete( ); 89 if (!TextUtils.isEmpty(mUrlBar.getText())) onTextChangedForAutocomplete( );
88 mShowSuggestions = true; 90
91 assert !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
92 mPendingSearchPromoDecision = false;
93
94 if (mPendingBeginQuery) {
95 beginQueryInternal(isVoiceSearchIntent);
96 mPendingBeginQuery = false;
97 }
89 } 98 }
90 99
91 /** Begins a new query. */ 100 /** Begins a new query. */
92 void beginQuery(boolean isVoiceSearchIntent) { 101 void beginQuery(boolean isVoiceSearchIntent) {
102 // Clear the text regardless of the promo decision. This allows the use r to enter text
103 // before native has been initialized and have it not be cleared one the delayed beginQuery
104 // logic is performed.
105 mUrlBar.setIgnoreTextChangesForAutocomplete(true);
106 mUrlBar.setUrl("", null);
107 mUrlBar.setIgnoreTextChangesForAutocomplete(false);
108
109 mUrlBar.setCursorVisible(true);
110 mUrlBar.setSelection(0, mUrlBar.getText().length());
111
112 if (mPendingSearchPromoDecision) {
113 mPendingBeginQuery = true;
114 return;
115 }
116
117 beginQueryInternal(isVoiceSearchIntent);
118 }
119
120 private void beginQueryInternal(boolean isVoiceSearchIntent) {
121 assert !mPendingSearchPromoDecision;
122
93 if (isVoiceSearchEnabled() && isVoiceSearchIntent) { 123 if (isVoiceSearchEnabled() && isVoiceSearchIntent) {
94 startVoiceRecognition(); 124 startVoiceRecognition();
95 } else { 125 } else {
96 focusTextBox(); 126 focusTextBox();
97 } 127 }
98 } 128 }
99 129
100 @Override 130 @Override
101 protected void updateButtonVisibility() { 131 protected void updateButtonVisibility() {
102 super.updateButtonVisibility(); 132 super.updateButtonVisibility();
103 updateMicButtonVisibility(1.0f); 133 updateMicButtonVisibility(1.0f);
104 findViewById(R.id.url_action_container).setVisibility(View.VISIBLE); 134 findViewById(R.id.url_action_container).setVisibility(View.VISIBLE);
105 } 135 }
106 136
107 private void focusTextBox() { 137 private void focusTextBox() {
108 if (mNativeInitialized) onUrlFocusChange(true); 138 if (!mUrlBar.hasFocus()) mUrlBar.requestFocus();
109 139
110 mUrlBar.setIgnoreTextChangesForAutocomplete(true);
111 mUrlBar.setUrl("", null);
112 mUrlBar.setIgnoreTextChangesForAutocomplete(false);
113
114 mUrlBar.setCursorVisible(true);
115 mUrlBar.setSelection(0, mUrlBar.getText().length());
116 new Handler().post(new Runnable() { 140 new Handler().post(new Runnable() {
117 @Override 141 @Override
118 public void run() { 142 public void run() {
119 UiUtils.showKeyboard(mUrlBar); 143 UiUtils.showKeyboard(mUrlBar);
120 } 144 }
121 }); 145 });
122 } 146 }
123 } 147 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/searchwidget/SearchActivityTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698