| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.contextualsearch; | 5 package org.chromium.chrome.browser.contextualsearch; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.view.View; | 8 import android.view.View; |
| 9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
| 10 import android.view.ViewTreeObserver; | 10 import android.view.ViewTreeObserver; |
| 11 import android.view.ViewTreeObserver.OnGlobalFocusChangeListener; | 11 import android.view.ViewTreeObserver.OnGlobalFocusChangeListener; |
| 12 | 12 |
| 13 import org.chromium.base.ActivityState; | 13 import org.chromium.base.ActivityState; |
| 14 import org.chromium.base.ApplicationStatus; | 14 import org.chromium.base.ApplicationStatus; |
| 15 import org.chromium.base.ApplicationStatus.ActivityStateListener; | 15 import org.chromium.base.ApplicationStatus.ActivityStateListener; |
| 16 import org.chromium.base.SysUtils; | 16 import org.chromium.base.SysUtils; |
| 17 import org.chromium.base.VisibleForTesting; | 17 import org.chromium.base.VisibleForTesting; |
| 18 import org.chromium.base.annotations.CalledByNative; | 18 import org.chromium.base.annotations.CalledByNative; |
| 19 import org.chromium.chrome.R; | 19 import org.chromium.chrome.R; |
| 20 import org.chromium.chrome.browser.ChromeActivity; | 20 import org.chromium.chrome.browser.ChromeActivity; |
| 21 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; | 21 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; |
| 22 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel.PanelState; | 22 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; |
| 23 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel.StateChangeReason; | 23 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; |
| 24 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanelDelegate; | 24 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanelDelegate; |
| 25 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon
troller.SelectionType; | 25 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon
troller.SelectionType; |
| 26 import org.chromium.chrome.browser.device.DeviceClassManager; | 26 import org.chromium.chrome.browser.device.DeviceClassManager; |
| 27 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 27 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
| 28 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; | 28 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; |
| 29 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 29 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
| 30 import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection; | 30 import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection; |
| 31 import org.chromium.chrome.browser.infobar.InfoBarContainer; | 31 import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| 32 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | |
| 33 import org.chromium.chrome.browser.tab.Tab; | 32 import org.chromium.chrome.browser.tab.Tab; |
| 34 import org.chromium.chrome.browser.tab.TabRedirectHandler; | 33 import org.chromium.chrome.browser.tab.TabRedirectHandler; |
| 35 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 34 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| 36 import org.chromium.chrome.browser.tabmodel.TabModel; | 35 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 37 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 36 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 38 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; | 37 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
| 39 import org.chromium.chrome.browser.tabmodel.TabModelObserver; | 38 import org.chromium.chrome.browser.tabmodel.TabModelObserver; |
| 40 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 39 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 41 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; | 40 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; |
| 42 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; | 41 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 private TabModelSelectorTabObserver mTabModelSelectorTabObserver; | 93 private TabModelSelectorTabObserver mTabModelSelectorTabObserver; |
| 95 private TabModelObserver mTabModelObserver; | 94 private TabModelObserver mTabModelObserver; |
| 96 private FindToolbarManager mFindToolbarManager; | 95 private FindToolbarManager mFindToolbarManager; |
| 97 private FindToolbarObserver mFindToolbarObserver; | 96 private FindToolbarObserver mFindToolbarObserver; |
| 98 private boolean mIsSearchContentViewShowing; | 97 private boolean mIsSearchContentViewShowing; |
| 99 private boolean mDidStartLoadingResolvedSearchRequest; | 98 private boolean mDidStartLoadingResolvedSearchRequest; |
| 100 private long mLoadedSearchUrlTimeMs; | 99 private long mLoadedSearchUrlTimeMs; |
| 101 // TODO(donnd): consider changing this member's name to indicate "opened" in
stead of "seen". | 100 // TODO(donnd): consider changing this member's name to indicate "opened" in
stead of "seen". |
| 102 private boolean mWereSearchResultsSeen; | 101 private boolean mWereSearchResultsSeen; |
| 103 private boolean mWereInfoBarsHidden; | 102 private boolean mWereInfoBarsHidden; |
| 104 private boolean mDidLoadAnyUrl; | |
| 105 private boolean mDidPromoteSearchNavigation; | 103 private boolean mDidPromoteSearchNavigation; |
| 106 private boolean mDidBasePageLoadJustStart; | 104 private boolean mDidBasePageLoadJustStart; |
| 107 private boolean mWasActivatedByTap; | 105 private boolean mWasActivatedByTap; |
| 108 private boolean mIsInitialized; | 106 private boolean mIsInitialized; |
| 109 | 107 |
| 110 /** | 108 /** |
| 111 * This boolean is used for loading content after a long-press when content
is not immediately | 109 * This boolean is used for loading content after a long-press when content
is not immediately |
| 112 * loaded. | 110 * loaded. |
| 113 */ | 111 */ |
| 114 private boolean mShouldLoadDelayedSearch; | 112 private boolean mShouldLoadDelayedSearch; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 if (mFindToolbarManager != null) { | 266 if (mFindToolbarManager != null) { |
| 269 mFindToolbarManager.removeObserver(mFindToolbarObserver); | 267 mFindToolbarManager.removeObserver(mFindToolbarObserver); |
| 270 mFindToolbarManager = null; | 268 mFindToolbarManager = null; |
| 271 mFindToolbarObserver = null; | 269 mFindToolbarObserver = null; |
| 272 } | 270 } |
| 273 } | 271 } |
| 274 | 272 |
| 275 @Override | 273 @Override |
| 276 public void setContextualSearchPanelDelegate(ContextualSearchPanelDelegate d
elegate) { | 274 public void setContextualSearchPanelDelegate(ContextualSearchPanelDelegate d
elegate) { |
| 277 mSearchPanelDelegate = delegate; | 275 mSearchPanelDelegate = delegate; |
| 278 | |
| 279 mSearchPanelDelegate.setChromeActivity(mActivity); | |
| 280 } | 276 } |
| 281 | 277 |
| 282 @Override | 278 @Override |
| 283 public boolean isCustomTab() { | 279 public ChromeActivity getChromeActivity() { |
| 284 return mActivity.isCustomTab(); | 280 return mActivity; |
| 285 } | 281 } |
| 286 | 282 |
| 287 /** | 283 /** |
| 288 * @return The {@link ContextualSearchPanelDelegate}, for testing purposes o
nly. | 284 * @return The {@link ContextualSearchPanelDelegate}, for testing purposes o
nly. |
| 289 */ | 285 */ |
| 290 @VisibleForTesting | 286 @VisibleForTesting |
| 291 public ContextualSearchPanelDelegate getContextualSearchPanelDelegate() { | 287 public ContextualSearchPanelDelegate getContextualSearchPanelDelegate() { |
| 292 return mSearchPanelDelegate; | 288 return mSearchPanelDelegate; |
| 293 } | 289 } |
| 294 | 290 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 319 @Nullable private ContentViewCore getBaseContentView() { | 315 @Nullable private ContentViewCore getBaseContentView() { |
| 320 return mSelectionController.getBaseContentView(); | 316 return mSelectionController.getBaseContentView(); |
| 321 } | 317 } |
| 322 | 318 |
| 323 @Override | 319 @Override |
| 324 public boolean isShowingSearchPanel() { | 320 public boolean isShowingSearchPanel() { |
| 325 return mSearchPanelDelegate.isShowing(); | 321 return mSearchPanelDelegate.isShowing(); |
| 326 } | 322 } |
| 327 | 323 |
| 328 @Override | 324 @Override |
| 329 public void setPreferenceState(boolean enabled) { | |
| 330 PrefServiceBridge.getInstance().setContextualSearchState(enabled); | |
| 331 } | |
| 332 | |
| 333 @Override | |
| 334 public boolean isPromoAvailable() { | 325 public boolean isPromoAvailable() { |
| 335 return mPolicy.isPromoAvailable(); | 326 return mPolicy.isPromoAvailable(); |
| 336 } | 327 } |
| 337 | 328 |
| 338 @Override | |
| 339 public int getControlContainerHeightResource() { | |
| 340 return mActivity.getControlContainerHeightResource(); | |
| 341 } | |
| 342 | |
| 343 /** | 329 /** |
| 344 * Hides the Contextual Search UX. | 330 * Hides the Contextual Search UX. |
| 345 * @param reason The {@link StateChangeReason} for hiding Contextual Search. | 331 * @param reason The {@link StateChangeReason} for hiding Contextual Search. |
| 346 */ | 332 */ |
| 347 public void hideContextualSearch(StateChangeReason reason) { | 333 public void hideContextualSearch(StateChangeReason reason) { |
| 348 if (mSearchPanelDelegate == null) return; | 334 if (mSearchPanelDelegate == null) return; |
| 349 | 335 |
| 350 if (mSearchPanelDelegate.isShowing()) { | 336 if (mSearchPanelDelegate.isShowing()) { |
| 351 mSearchPanelDelegate.closePanel(reason, false); | 337 mSearchPanelDelegate.closePanel(reason, false); |
| 352 } | 338 } |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 } | 891 } |
| 906 return true; | 892 return true; |
| 907 } | 893 } |
| 908 } | 894 } |
| 909 | 895 |
| 910 // -------------------------------------------------------------------------
------------------- | 896 // -------------------------------------------------------------------------
------------------- |
| 911 // Search Content View | 897 // Search Content View |
| 912 // -------------------------------------------------------------------------
------------------- | 898 // -------------------------------------------------------------------------
------------------- |
| 913 | 899 |
| 914 /** | 900 /** |
| 915 * Gets the {@code ContentViewCore} associated with Contextual Search Panel. | |
| 916 * @return Contextual Search Panel's {@code ContentViewCore}. | |
| 917 */ | |
| 918 @Override | |
| 919 public ContentViewCore getSearchContentViewCore() { | |
| 920 return mSearchPanelDelegate.getContentViewCore(); | |
| 921 } | |
| 922 | |
| 923 /** | |
| 924 * Sets the {@code ContextualSearchContentViewDelegate} associated with the
Content View. | 901 * Sets the {@code ContextualSearchContentViewDelegate} associated with the
Content View. |
| 925 * @param delegate | 902 * @param delegate |
| 926 */ | 903 */ |
| 927 public void setSearchContentViewDelegate(ContextualSearchContentViewDelegate
delegate) { | 904 public void setSearchContentViewDelegate(ContextualSearchContentViewDelegate
delegate) { |
| 928 mSearchContentViewDelegate = delegate; | 905 mSearchContentViewDelegate = delegate; |
| 929 } | 906 } |
| 930 | 907 |
| 931 /** | 908 /** |
| 932 * Removes the last resolved search URL from the Chrome history. | 909 * Removes the last resolved search URL from the Chrome history. |
| 933 */ | 910 */ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 return mSearchPanelDelegate.didTouchSearchContentView() | 975 return mSearchPanelDelegate.didTouchSearchContentView() |
| 999 && !mSearchPanelDelegate.isProcessingPendingNavigation(); | 976 && !mSearchPanelDelegate.isProcessingPendingNavigation(); |
| 1000 } | 977 } |
| 1001 | 978 |
| 1002 /** | 979 /** |
| 1003 * Called to check if an external navigation is being done and take the appr
opriate action: | 980 * Called to check if an external navigation is being done and take the appr
opriate action: |
| 1004 * Auto-promotes the panel into a separate tab if that's not already being d
one. | 981 * Auto-promotes the panel into a separate tab if that's not already being d
one. |
| 1005 * @param url The URL we are navigating to. | 982 * @param url The URL we are navigating to. |
| 1006 */ | 983 */ |
| 1007 public void onExternalNavigation(String url) { | 984 public void onExternalNavigation(String url) { |
| 1008 mSearchPanelDelegate.updateTopControlState(); | 985 mSearchPanelDelegate.updateTopControlsState(); |
| 1009 | 986 |
| 1010 if (!mDidPromoteSearchNavigation | 987 if (!mDidPromoteSearchNavigation |
| 1011 && !BLACKLISTED_URL.equals(url) | 988 && !BLACKLISTED_URL.equals(url) |
| 1012 && !url.startsWith(INTENT_URL_PREFIX) | 989 && !url.startsWith(INTENT_URL_PREFIX) |
| 1013 && shouldPromoteSearchNavigation()) { | 990 && shouldPromoteSearchNavigation()) { |
| 1014 // Do not promote to a regular tab if we're loading our Resolved Sea
rch | 991 // Do not promote to a regular tab if we're loading our Resolved Sea
rch |
| 1015 // URL, otherwise we'll promote it when prefetching the Serp. | 992 // URL, otherwise we'll promote it when prefetching the Serp. |
| 1016 // Don't promote URLs when they are navigating to an intent - this i
s | 993 // Don't promote URLs when they are navigating to an intent - this i
s |
| 1017 // handled by the InterceptNavigationDelegate which uses a faster | 994 // handled by the InterceptNavigationDelegate which uses a faster |
| 1018 // maximizing animation. | 995 // maximizing animation. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 // First, check the pending navigation entry, because there might be an
navigation | 1061 // First, check the pending navigation entry, because there might be an
navigation |
| 1085 // not yet committed being processed. Otherwise, get the URL from the We
bContents. | 1062 // not yet committed being processed. Otherwise, get the URL from the We
bContents. |
| 1086 NavigationEntry entry = | 1063 NavigationEntry entry = |
| 1087 searchContentViewCore.getWebContents().getNavigationController()
.getPendingEntry(); | 1064 searchContentViewCore.getWebContents().getNavigationController()
.getPendingEntry(); |
| 1088 String url = entry != null | 1065 String url = entry != null |
| 1089 ? entry.getUrl() : searchContentViewCore.getWebContents().getUrl
(); | 1066 ? entry.getUrl() : searchContentViewCore.getWebContents().getUrl
(); |
| 1090 return url; | 1067 return url; |
| 1091 } | 1068 } |
| 1092 | 1069 |
| 1093 @Override | 1070 @Override |
| 1094 public float getSearchContentViewVerticalScroll() { | |
| 1095 return mSearchPanelDelegate.getContentViewCore() != null | |
| 1096 ? mSearchPanelDelegate.getContentViewCore().computeVerticalScrol
lOffset() : -1.f; | |
| 1097 } | |
| 1098 | |
| 1099 @Override | |
| 1100 public void preserveBasePageSelectionOnNextLossOfFocus() { | 1071 public void preserveBasePageSelectionOnNextLossOfFocus() { |
| 1101 ContentViewCore basePageContentView = getBaseContentView(); | 1072 ContentViewCore basePageContentView = getBaseContentView(); |
| 1102 if (basePageContentView != null) { | 1073 if (basePageContentView != null) { |
| 1103 basePageContentView.preserveSelectionOnNextLossOfFocus(); | 1074 basePageContentView.preserveSelectionOnNextLossOfFocus(); |
| 1104 } | 1075 } |
| 1105 } | 1076 } |
| 1106 | 1077 |
| 1107 @Override | 1078 @Override |
| 1108 public void dismissContextualSearchBar() { | 1079 public void dismissContextualSearchBar() { |
| 1109 hideContextualSearch(StateChangeReason.UNKNOWN); | 1080 hideContextualSearch(StateChangeReason.UNKNOWN); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 | 1191 |
| 1221 private native long nativeInit(); | 1192 private native long nativeInit(); |
| 1222 private native void nativeDestroy(long nativeContextualSearchManager); | 1193 private native void nativeDestroy(long nativeContextualSearchManager); |
| 1223 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, | 1194 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, |
| 1224 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, | 1195 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, |
| 1225 boolean maySendBasePageUrl); | 1196 boolean maySendBasePageUrl); |
| 1226 private native void nativeGatherSurroundingText(long nativeContextualSearchM
anager, | 1197 private native void nativeGatherSurroundingText(long nativeContextualSearchM
anager, |
| 1227 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, | 1198 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, |
| 1228 boolean maySendBasePageUrl); | 1199 boolean maySendBasePageUrl); |
| 1229 } | 1200 } |
| OLD | NEW |