| 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.os.Handler; | 9 import android.os.Handler; |
| 10 import android.support.customtabs.CustomTabsIntent; | 10 import android.support.customtabs.CustomTabsIntent; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; | 28 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; |
| 29 import org.chromium.chrome.browser.tab.Tab; | 29 import org.chromium.chrome.browser.tab.Tab; |
| 30 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 30 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 31 import org.chromium.chrome.browser.tab.TabIdManager; | 31 import org.chromium.chrome.browser.tab.TabIdManager; |
| 32 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 32 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 33 import org.chromium.chrome.browser.util.IntentUtils; | 33 import org.chromium.chrome.browser.util.IntentUtils; |
| 34 import org.chromium.components.url_formatter.UrlFormatter; | 34 import org.chromium.components.url_formatter.UrlFormatter; |
| 35 import org.chromium.content_public.browser.LoadUrlParams; | 35 import org.chromium.content_public.browser.LoadUrlParams; |
| 36 import org.chromium.ui.base.ActivityWindowAndroid; | 36 import org.chromium.ui.base.ActivityWindowAndroid; |
| 37 | 37 |
| 38 /** Prototype that queries the user's default search engine and shows autocomple
te suggestions. */ | 38 /** Queries the user's default search engine and shows autocomplete suggestions.
*/ |
| 39 public class SearchActivity extends AsyncInitializationActivity | 39 public class SearchActivity extends AsyncInitializationActivity |
| 40 implements SnackbarManageable, SearchActivityLocationBarLayout.Delegate, | 40 implements SnackbarManageable, SearchActivityLocationBarLayout.Delegate, |
| 41 View.OnLayoutChangeListener { | 41 View.OnLayoutChangeListener { |
| 42 | 42 |
| 43 /** Main content view. */ | 43 /** Main content view. */ |
| 44 private ViewGroup mContentView; | 44 private ViewGroup mContentView; |
| 45 | 45 |
| 46 /** Whether the native library has been loaded. */ | 46 /** Whether the native library has been loaded. */ |
| 47 private boolean mIsNativeReady; | 47 private boolean mIsNativeReady; |
| 48 | 48 |
| 49 /** Input submitted before before the native library was loaded. */ | 49 /** Input submitted before before the native library was loaded. */ |
| 50 private String mQueuedUrl; | 50 private String mQueuedUrl; |
| 51 | 51 |
| 52 /** The View that represents the search box. */ | 52 /** The View that represents the search box. */ |
| 53 private SearchActivityLocationBarLayout mSearchBox; | 53 private SearchActivityLocationBarLayout mSearchBox; |
| 54 | 54 |
| 55 private ActivityWindowAndroid mWindowAndroid; | |
| 56 private SnackbarManager mSnackbarManager; | 55 private SnackbarManager mSnackbarManager; |
| 57 private SearchBoxDataProvider mSearchBoxDataProvider; | 56 private SearchBoxDataProvider mSearchBoxDataProvider; |
| 58 private Tab mTab; | 57 private Tab mTab; |
| 59 | 58 |
| 60 @Override | 59 @Override |
| 61 public void backKeyPressed() { | 60 public void backKeyPressed() { |
| 62 cancelSearch(); | 61 cancelSearch(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 @Override | 64 @Override |
| 66 protected boolean shouldDelayBrowserStartup() { | 65 protected boolean shouldDelayBrowserStartup() { |
| 67 return true; | 66 return true; |
| 68 } | 67 } |
| 69 | 68 |
| 70 @Override | 69 @Override |
| 71 public boolean onActivityResultWithNative(int requestCode, int resultCode, I
ntent intent) { | 70 protected ActivityWindowAndroid createWindowAndroid() { |
| 72 if (super.onActivityResultWithNative(requestCode, resultCode, intent)) r
eturn true; | 71 return new ActivityWindowAndroid(this); |
| 73 return mWindowAndroid.onActivityResult(requestCode, resultCode, intent); | |
| 74 } | |
| 75 | |
| 76 @Override | |
| 77 public void onRequestPermissionsResult( | |
| 78 int requestCode, String[] permissions, int[] grantResults) { | |
| 79 // TODO(dfalcantara): This is from ChromeWindow. It should be moved int
o the | |
| 80 // AsyncInitializationActivity, but that has a lot of
subclasses that | |
| 81 // don't need a WindowAndroid. | |
| 82 if (mWindowAndroid != null) { | |
| 83 if (mWindowAndroid.onRequestPermissionsResult(requestCode, permissio
ns, grantResults)) { | |
| 84 return; | |
| 85 } | |
| 86 } | |
| 87 super.onRequestPermissionsResult(requestCode, permissions, grantResults)
; | |
| 88 } | 72 } |
| 89 | 73 |
| 90 @Override | 74 @Override |
| 91 protected void setContentView() { | 75 protected void setContentView() { |
| 92 mWindowAndroid = new ActivityWindowAndroid(this); | |
| 93 mSnackbarManager = new SnackbarManager(this, null); | 76 mSnackbarManager = new SnackbarManager(this, null); |
| 94 mSearchBoxDataProvider = new SearchBoxDataProvider(); | 77 mSearchBoxDataProvider = new SearchBoxDataProvider(); |
| 95 | 78 |
| 96 mContentView = createContentView(); | 79 mContentView = createContentView(); |
| 97 | 80 |
| 98 // Build the search box. | 81 // Build the search box. |
| 99 mSearchBox = (SearchActivityLocationBarLayout) mContentView.findViewById
( | 82 mSearchBox = (SearchActivityLocationBarLayout) mContentView.findViewById
( |
| 100 R.id.search_location_bar); | 83 R.id.search_location_bar); |
| 101 mSearchBox.setDelegate(this); | 84 mSearchBox.setDelegate(this); |
| 102 mSearchBox.setToolbarDataProvider(mSearchBoxDataProvider); | 85 mSearchBox.setToolbarDataProvider(mSearchBoxDataProvider); |
| 103 mSearchBox.initializeControls(new WindowDelegate(getWindow()), mWindowAn
droid); | 86 mSearchBox.initializeControls(new WindowDelegate(getWindow()), getWindow
Android()); |
| 104 | 87 |
| 105 setContentView(mContentView); | 88 setContentView(mContentView); |
| 106 } | 89 } |
| 107 | 90 |
| 108 @Override | 91 @Override |
| 109 public void finishNativeInitialization() { | 92 public void finishNativeInitialization() { |
| 110 super.finishNativeInitialization(); | 93 super.finishNativeInitialization(); |
| 111 mIsNativeReady = true; | 94 mIsNativeReady = true; |
| 112 | 95 |
| 113 mTab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TA
B_ID), | 96 mTab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TA
B_ID), |
| 114 Tab.INVALID_TAB_ID, false, this, mWindowAndroid, TabLaunchType.F
ROM_EXTERNAL_APP, | 97 Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), |
| 115 null, null); | 98 TabLaunchType.FROM_EXTERNAL_APP, null, null); |
| 116 mTab.initialize(WebContentsFactory.createWebContents(false, false), null
, | 99 mTab.initialize(WebContentsFactory.createWebContents(false, false), null
, |
| 117 new TabDelegateFactory(), false, false); | 100 new TabDelegateFactory(), false, false); |
| 118 mTab.loadUrl(new LoadUrlParams("about:blank")); | 101 mTab.loadUrl(new LoadUrlParams("about:blank")); |
| 119 | 102 |
| 120 mSearchBoxDataProvider.onNativeLibraryReady(mTab); | 103 mSearchBoxDataProvider.onNativeLibraryReady(mTab); |
| 121 mSearchBox.onNativeLibraryReady(); | 104 mSearchBox.onNativeLibraryReady(); |
| 122 | 105 |
| 123 if (mQueuedUrl != null) loadUrl(mQueuedUrl); | 106 if (mQueuedUrl != null) loadUrl(mQueuedUrl); |
| 124 | 107 |
| 125 new Handler().post(new Runnable() { | 108 new Handler().post(new Runnable() { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 }); | 226 }); |
| 244 ChromeBrowserInitializer.getInstance(getApplicationContext()) | 227 ChromeBrowserInitializer.getInstance(getApplicationContext()) |
| 245 .handlePreNativeStartup(SearchActivity.this); | 228 .handlePreNativeStartup(SearchActivity.this); |
| 246 } | 229 } |
| 247 | 230 |
| 248 private void cancelSearch() { | 231 private void cancelSearch() { |
| 249 finish(); | 232 finish(); |
| 250 overridePendingTransition(0, R.anim.activity_close_exit); | 233 overridePendingTransition(0, R.anim.activity_close_exit); |
| 251 } | 234 } |
| 252 } | 235 } |
| OLD | NEW |