Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java

Issue 1487923002: [Contextual Search] Fix NPE when no Search Term. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698