OLD | NEW |
---|---|
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.Intent; | 7 import android.content.Intent; |
8 import android.net.Uri; | 8 import android.net.Uri; |
9 import android.support.v4.app.ActivityOptionsCompat; | 9 import android.support.v4.app.ActivityOptionsCompat; |
10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
11 import android.view.LayoutInflater; | 11 import android.view.LayoutInflater; |
12 import android.view.View; | 12 import android.view.View; |
13 import android.view.ViewGroup; | 13 import android.view.ViewGroup; |
14 | 14 |
15 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
17 import org.chromium.chrome.browser.IntentHandler; | 17 import org.chromium.chrome.browser.IntentHandler; |
18 import org.chromium.chrome.browser.WebContentsFactory; | 18 import org.chromium.chrome.browser.WebContentsFactory; |
19 import org.chromium.chrome.browser.WindowDelegate; | 19 import org.chromium.chrome.browser.WindowDelegate; |
20 import org.chromium.chrome.browser.customtabs.CustomTabsConnection; | 20 import org.chromium.chrome.browser.customtabs.CustomTabsConnection; |
21 import org.chromium.chrome.browser.init.AsyncInitializationActivity; | 21 import org.chromium.chrome.browser.init.AsyncInitializationActivity; |
22 import org.chromium.chrome.browser.locale.LocaleManager; | |
22 import org.chromium.chrome.browser.omnibox.AutocompleteController; | 23 import org.chromium.chrome.browser.omnibox.AutocompleteController; |
23 import org.chromium.chrome.browser.snackbar.SnackbarManager; | 24 import org.chromium.chrome.browser.snackbar.SnackbarManager; |
24 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; | 25 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; |
25 import org.chromium.chrome.browser.tab.Tab; | 26 import org.chromium.chrome.browser.tab.Tab; |
26 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 27 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
27 import org.chromium.chrome.browser.tab.TabIdManager; | 28 import org.chromium.chrome.browser.tab.TabIdManager; |
28 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 29 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
29 import org.chromium.chrome.browser.util.IntentUtils; | 30 import org.chromium.chrome.browser.util.IntentUtils; |
30 import org.chromium.components.url_formatter.UrlFormatter; | 31 import org.chromium.components.url_formatter.UrlFormatter; |
31 import org.chromium.content_public.browser.LoadUrlParams; | 32 import org.chromium.content_public.browser.LoadUrlParams; |
32 import org.chromium.ui.base.ActivityWindowAndroid; | 33 import org.chromium.ui.base.ActivityWindowAndroid; |
33 | 34 |
34 /** Queries the user's default search engine and shows autocomplete suggestions. */ | 35 /** Queries the user's default search engine and shows autocomplete suggestions. */ |
35 public class SearchActivity extends AsyncInitializationActivity | 36 public class SearchActivity extends AsyncInitializationActivity |
36 implements SnackbarManageable, SearchActivityLocationBarLayout.Delegate { | 37 implements SnackbarManageable, SearchActivityLocationBarLayout.Delegate { |
37 /** Setting this field causes the Activity to finish itself immediately for tests. */ | 38 /** Setting this field causes the Activity to finish itself immediately for tests. */ |
38 private static boolean sIsDisabledForTest; | 39 private static boolean sIsDisabledForTest; |
39 | 40 |
41 /** Run when the SearchActivity knows what info it needs to display to the u ser. */ | |
42 private final Runnable mSearchEngineAvailableRunnable = new Runnable() { | |
43 @Override | |
44 public void run() { | |
45 AutocompleteController.nativePrefetchZeroSuggestResults(); | |
46 CustomTabsConnection.getInstance(getApplication()).warmup(0); | |
Ted C
2017/04/26 20:21:52
wha?
gone
2017/04/26 21:45:15
/me shrugs. It was already there. It's been push
| |
47 mSearchBox.onDeferredStartup(isVoiceSearchIntent()); | |
48 } | |
49 }; | |
50 | |
40 /** Main content view. */ | 51 /** Main content view. */ |
41 private ViewGroup mContentView; | 52 private ViewGroup mContentView; |
42 | 53 |
43 /** Whether the native library has been loaded. */ | 54 /** Whether the native library has been loaded. */ |
44 private boolean mIsNativeReady; | 55 private boolean mIsNativeReady; |
45 | 56 |
46 /** Input submitted before before the native library was loaded. */ | 57 /** Input submitted before before the native library was loaded. */ |
47 private String mQueuedUrl; | 58 private String mQueuedUrl; |
48 | 59 |
49 /** The View that represents the search box. */ | 60 /** The View that represents the search box. */ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // Build the search box. | 93 // Build the search box. |
83 mContentView = createContentView(); | 94 mContentView = createContentView(); |
84 mSearchBox = (SearchActivityLocationBarLayout) mContentView.findViewById ( | 95 mSearchBox = (SearchActivityLocationBarLayout) mContentView.findViewById ( |
85 R.id.search_location_bar); | 96 R.id.search_location_bar); |
86 mSearchBox.setDelegate(this); | 97 mSearchBox.setDelegate(this); |
87 mSearchBox.setToolbarDataProvider(mSearchBoxDataProvider); | 98 mSearchBox.setToolbarDataProvider(mSearchBoxDataProvider); |
88 mSearchBox.initializeControls(new WindowDelegate(getWindow()), getWindow Android()); | 99 mSearchBox.initializeControls(new WindowDelegate(getWindow()), getWindow Android()); |
89 setContentView(mContentView); | 100 setContentView(mContentView); |
90 | 101 |
91 // Kick off everything needed for the user to type into the box. | 102 // Kick off everything needed for the user to type into the box. |
103 // TODO(dfalcantara): We should prevent the user from doing anything whi le we're running the | |
104 // logic to determine if they need to see a search en gine promo. Given | |
105 // that the logic requires native to be loaded, we'll have to make some | |
106 // easy Java-only first-pass checks. | |
92 beginQuery(); | 107 beginQuery(); |
93 mSearchBox.showCachedZeroSuggestResultsIfAvailable(); | 108 mSearchBox.showCachedZeroSuggestResultsIfAvailable(); |
94 | 109 |
95 // Kick off loading of the native library. | 110 // Kick off loading of the native library. |
96 mHandler.post(new Runnable() { | 111 mHandler.post(new Runnable() { |
97 @Override | 112 @Override |
98 public void run() { | 113 public void run() { |
99 beginLoadingLibrary(); | 114 beginLoadingLibrary(); |
100 } | 115 } |
101 }); | 116 }); |
(...skipping 21 matching lines...) Expand all Loading... | |
123 public void run() { | 138 public void run() { |
124 onDeferredStartup(); | 139 onDeferredStartup(); |
125 } | 140 } |
126 }); | 141 }); |
127 } | 142 } |
128 | 143 |
129 @Override | 144 @Override |
130 public void onDeferredStartup() { | 145 public void onDeferredStartup() { |
131 super.onDeferredStartup(); | 146 super.onDeferredStartup(); |
132 | 147 |
133 AutocompleteController.nativePrefetchZeroSuggestResults(); | 148 // Force the user to choose a search engine if they have to. |
134 CustomTabsConnection.getInstance(getApplication()).warmup(0); | 149 if (!LocaleManager.getInstance().showSearchEnginePromoIfNeeded( |
135 mSearchBox.onDeferredStartup(isVoiceSearchIntent()); | 150 this, mSearchEngineAvailableRunnable)) { |
151 mSearchEngineAvailableRunnable.run(); | |
152 } | |
136 } | 153 } |
137 | 154 |
138 @Override | 155 @Override |
139 protected View getViewToBeDrawnBeforeInitializingNative() { | 156 protected View getViewToBeDrawnBeforeInitializingNative() { |
140 return mSearchBox; | 157 return mSearchBox; |
141 } | 158 } |
142 | 159 |
143 @Override | 160 @Override |
144 public void onNewIntent(Intent intent) { | 161 public void onNewIntent(Intent intent) { |
145 super.onNewIntent(intent); | 162 super.onNewIntent(intent); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 finish(); | 232 finish(); |
216 overridePendingTransition(0, R.anim.activity_close_exit); | 233 overridePendingTransition(0, R.anim.activity_close_exit); |
217 } | 234 } |
218 | 235 |
219 /** See {@link #sIsDisabledForTest}. */ | 236 /** See {@link #sIsDisabledForTest}. */ |
220 @VisibleForTesting | 237 @VisibleForTesting |
221 static void disableForTests() { | 238 static void disableForTests() { |
222 sIsDisabledForTest = true; | 239 sIsDisabledForTest = true; |
223 } | 240 } |
224 } | 241 } |
OLD | NEW |