| 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.content.Context; | 8 import android.content.Context; |
| 9 import android.text.TextUtils; |
| 9 import android.view.View; | 10 import android.view.View; |
| 10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 11 import android.view.ViewTreeObserver; | 12 import android.view.ViewTreeObserver; |
| 12 import android.view.ViewTreeObserver.OnGlobalFocusChangeListener; | 13 import android.view.ViewTreeObserver.OnGlobalFocusChangeListener; |
| 13 | 14 |
| 14 import org.chromium.base.ActivityState; | 15 import org.chromium.base.ActivityState; |
| 15 import org.chromium.base.ApplicationStatus; | 16 import org.chromium.base.ApplicationStatus; |
| 16 import org.chromium.base.ApplicationStatus.ActivityStateListener; | 17 import org.chromium.base.ApplicationStatus.ActivityStateListener; |
| 17 import org.chromium.base.SysUtils; | 18 import org.chromium.base.SysUtils; |
| 18 import org.chromium.base.VisibleForTesting; | 19 import org.chromium.base.VisibleForTesting; |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 725 } |
| 725 mSearchPanel.onSearchTermResolutionResponse(message); | 726 mSearchPanel.onSearchTermResolutionResponse(message); |
| 726 | 727 |
| 727 // If there was an error, fall back onto a literal search for the select
ion. | 728 // If there was an error, fall back onto a literal search for the select
ion. |
| 728 // Since we're showing the panel, there must be a selection. | 729 // Since we're showing the panel, there must be a selection. |
| 729 if (doLiteralSearch) { | 730 if (doLiteralSearch) { |
| 730 searchTerm = mSelectionController.getSelectedText(); | 731 searchTerm = mSelectionController.getSelectedText(); |
| 731 alternateTerm = null; | 732 alternateTerm = null; |
| 732 doPreventPreload = true; | 733 doPreventPreload = true; |
| 733 } | 734 } |
| 734 if (!searchTerm.isEmpty()) { | 735 if (!TextUtils.isEmpty(searchTerm)) { |
| 735 // TODO(donnd): Instead of preloading, we should prefetch (ie the UR
L should not | 736 // TODO(donnd): Instead of preloading, we should prefetch (ie the UR
L should not |
| 736 // appear in the user's history until the user views it). See crbug
.com/406446. | 737 // appear in the user's history until the user views it). See crbug
.com/406446. |
| 737 boolean shouldPreload = !doPreventPreload && mPolicy.shouldPrefetchS
earchResult(true); | 738 boolean shouldPreload = !doPreventPreload && mPolicy.shouldPrefetchS
earchResult(true); |
| 738 mSearchRequest = new ContextualSearchRequest(searchTerm, alternateTe
rm, shouldPreload); | 739 mSearchRequest = new ContextualSearchRequest(searchTerm, alternateTe
rm, shouldPreload); |
| 739 // Trigger translation, if enabled. | 740 // Trigger translation, if enabled. |
| 740 if (!contextLanguage.isEmpty()) { | 741 if (!contextLanguage.isEmpty()) { |
| 741 if (mPolicy.needsTranslation(contextLanguage, getReadableLanguag
es())) { | 742 if (mPolicy.needsTranslation(contextLanguage, getReadableLanguag
es())) { |
| 742 boolean doForceTranslate = !mPolicy.disableForceTranslationO
nebox(); | 743 boolean doForceTranslate = !mPolicy.disableForceTranslationO
nebox(); |
| 743 if (doForceTranslate) { | 744 if (doForceTranslate) { |
| 744 mSearchRequest.forceTranslation(contextLanguage, | 745 mSearchRequest.forceTranslation(contextLanguage, |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 private native void nativeDestroy(long nativeContextualSearchManager); | 1293 private native void nativeDestroy(long nativeContextualSearchManager); |
| 1293 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, | 1294 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, |
| 1294 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, | 1295 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, |
| 1295 boolean maySendBasePageUrl); | 1296 boolean maySendBasePageUrl); |
| 1296 private native void nativeGatherSurroundingText(long nativeContextualSearchM
anager, | 1297 private native void nativeGatherSurroundingText(long nativeContextualSearchM
anager, |
| 1297 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, | 1298 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, |
| 1298 boolean maySendBasePageUrl); | 1299 boolean maySendBasePageUrl); |
| 1299 private native String nativeGetTargetLanguage(long nativeContextualSearchMan
ager); | 1300 private native String nativeGetTargetLanguage(long nativeContextualSearchMan
ager); |
| 1300 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa
nager); | 1301 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa
nager); |
| 1301 } | 1302 } |
| OLD | NEW |