| 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.text.TextUtils; | 7 import android.text.TextUtils; |
| 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.ObserverList; | 13 import org.chromium.base.ObserverList; |
| 14 import org.chromium.base.SysUtils; | 14 import org.chromium.base.SysUtils; |
| 15 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
| 16 import org.chromium.base.annotations.CalledByNative; | 16 import org.chromium.base.annotations.CalledByNative; |
| 17 import org.chromium.base.metrics.RecordUserAction; | 17 import org.chromium.base.metrics.RecordUserAction; |
| 18 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
| 19 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
| 20 import org.chromium.chrome.browser.UrlConstants; | |
| 21 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; | 20 import org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate; |
| 22 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; | 21 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; |
| 23 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; | 22 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; |
| 24 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelContentViewD
elegate; | 23 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelContentViewD
elegate; |
| 25 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel; | 24 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel; |
| 26 import org.chromium.chrome.browser.contextualsearch.ContextualSearchBlacklist.Bl
acklistReason; | 25 import org.chromium.chrome.browser.contextualsearch.ContextualSearchBlacklist.Bl
acklistReason; |
| 27 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon
troller.SelectionType; | 26 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon
troller.SelectionType; |
| 28 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 27 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
| 29 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; | 28 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; |
| 30 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 29 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; | 41 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; |
| 43 import org.chromium.chrome.browser.widget.findinpage.FindToolbarObserver; | 42 import org.chromium.chrome.browser.widget.findinpage.FindToolbarObserver; |
| 44 import org.chromium.components.navigation_interception.NavigationParams; | 43 import org.chromium.components.navigation_interception.NavigationParams; |
| 45 import org.chromium.content.browser.ContentViewCore; | 44 import org.chromium.content.browser.ContentViewCore; |
| 46 import org.chromium.content.browser.SelectionClient; | 45 import org.chromium.content.browser.SelectionClient; |
| 47 import org.chromium.content_public.browser.GestureStateListener; | 46 import org.chromium.content_public.browser.GestureStateListener; |
| 48 import org.chromium.content_public.browser.LoadUrlParams; | 47 import org.chromium.content_public.browser.LoadUrlParams; |
| 49 import org.chromium.content_public.browser.NavigationEntry; | 48 import org.chromium.content_public.browser.NavigationEntry; |
| 50 import org.chromium.content_public.browser.WebContents; | 49 import org.chromium.content_public.browser.WebContents; |
| 51 import org.chromium.content_public.common.BrowserControlsState; | 50 import org.chromium.content_public.common.BrowserControlsState; |
| 51 import org.chromium.content_public.common.ContentUrlConstants; |
| 52 import org.chromium.net.NetworkChangeNotifier; | 52 import org.chromium.net.NetworkChangeNotifier; |
| 53 import org.chromium.ui.base.WindowAndroid; | 53 import org.chromium.ui.base.WindowAndroid; |
| 54 | 54 |
| 55 import java.net.MalformedURLException; | 55 import java.net.MalformedURLException; |
| 56 import java.net.URL; | 56 import java.net.URL; |
| 57 import java.util.regex.Pattern; | 57 import java.util.regex.Pattern; |
| 58 | 58 |
| 59 import javax.annotation.Nullable; | 59 import javax.annotation.Nullable; |
| 60 | 60 |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Manager for the Contextual Search feature. | 63 * Manager for the Contextual Search feature. |
| 64 * This class keeps track of the status of Contextual Search and coordinates the
control | 64 * This class keeps track of the status of Contextual Search and coordinates the
control |
| 65 * with the layout. | 65 * with the layout. |
| 66 */ | 66 */ |
| 67 public class ContextualSearchManager implements ContextualSearchManagementDelega
te, | 67 public class ContextualSearchManager implements ContextualSearchManagementDelega
te, |
| 68 ContextualSearchTranslateInterfa
ce, | 68 ContextualSearchTranslateInterfa
ce, |
| 69 ContextualSearchNetworkCommunica
tor, | 69 ContextualSearchNetworkCommunica
tor, |
| 70 ContextualSearchSelectionHandler
, SelectionClient { | 70 ContextualSearchSelectionHandler
, SelectionClient { |
| 71 private static final String INTENT_URL_PREFIX = "intent:"; | 71 private static final String INTENT_URL_PREFIX = "intent:"; |
| 72 | 72 |
| 73 // The animation duration of a URL being promoted to a tab when triggered by
an | 73 // The animation duration of a URL being promoted to a tab when triggered by
an |
| 74 // intercept navigation. This is faster than the standard tab promotion anim
ation | 74 // intercept navigation. This is faster than the standard tab promotion anim
ation |
| 75 // so that it completes before the navigation. | 75 // so that it completes before the navigation. |
| 76 private static final long INTERCEPT_NAVIGATION_PROMOTION_ANIMATION_DURATION_
MS = 40; | 76 private static final long INTERCEPT_NAVIGATION_PROMOTION_ANIMATION_DURATION_
MS = 40; |
| 77 | 77 |
| 78 // We blacklist this URL because malformed URLs may bring up this page. | 78 // We blacklist this URL because malformed URLs may bring up this page. |
| 79 private static final String BLACKLISTED_URL = UrlConstants.ABOUT_BLANK_DISPL
AY_URL; | 79 private static final String BLACKLISTED_URL = ContentUrlConstants.ABOUT_BLAN
K_DISPLAY_URL; |
| 80 | 80 |
| 81 private static final Pattern CONTAINS_WHITESPACE_PATTERN = Pattern.compile("
\\s"); | 81 private static final Pattern CONTAINS_WHITESPACE_PATTERN = Pattern.compile("
\\s"); |
| 82 | 82 |
| 83 // When we don't need to send any "home country" code we can just pass the e
mpty string. | 83 // When we don't need to send any "home country" code we can just pass the e
mpty string. |
| 84 private static final String NO_HOME_COUNTRY = ""; | 84 private static final String NO_HOME_COUNTRY = ""; |
| 85 | 85 |
| 86 private final ObserverList<ContextualSearchObserver> mObservers = | 86 private final ObserverList<ContextualSearchObserver> mObservers = |
| 87 new ObserverList<ContextualSearchObserver>(); | 87 new ObserverList<ContextualSearchObserver>(); |
| 88 | 88 |
| 89 private final ChromeActivity mActivity; | 89 private final ChromeActivity mActivity; |
| (...skipping 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, | 1455 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, |
| 1456 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); | 1456 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); |
| 1457 protected native void nativeGatherSurroundingText(long nativeContextualSearc
hManager, | 1457 protected native void nativeGatherSurroundingText(long nativeContextualSearc
hManager, |
| 1458 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); | 1458 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); |
| 1459 private native void nativeEnableContextualSearchJsApiForOverlay( | 1459 private native void nativeEnableContextualSearchJsApiForOverlay( |
| 1460 long nativeContextualSearchManager, WebContents overlayWebContents); | 1460 long nativeContextualSearchManager, WebContents overlayWebContents); |
| 1461 // Don't call these directly, instead call the private methods that cache th
e results. | 1461 // Don't call these directly, instead call the private methods that cache th
e results. |
| 1462 private native String nativeGetTargetLanguage(long nativeContextualSearchMan
ager); | 1462 private native String nativeGetTargetLanguage(long nativeContextualSearchMan
ager); |
| 1463 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa
nager); | 1463 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa
nager); |
| 1464 } | 1464 } |
| OLD | NEW |