Chromium Code Reviews| 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.os.Handler; | 8 import android.os.Handler; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 /** | 646 /** |
| 647 * Called in response to the | 647 * Called in response to the |
| 648 * {@link ContextualSearchManager#nativeStartSearchTermResolutionRequest} me thod. | 648 * {@link ContextualSearchManager#nativeStartSearchTermResolutionRequest} me thod. |
| 649 * @param isNetworkUnavailable Indicates if the network is unavailable, in w hich case all other | 649 * @param isNetworkUnavailable Indicates if the network is unavailable, in w hich case all other |
| 650 * parameters should be ignored. | 650 * parameters should be ignored. |
| 651 * @param responseCode The HTTP response code. If the code is not OK, the q uery | 651 * @param responseCode The HTTP response code. If the code is not OK, the q uery |
| 652 * should be ignored. | 652 * should be ignored. |
| 653 * @param searchTerm The term to use in our subsequent search. | 653 * @param searchTerm The term to use in our subsequent search. |
| 654 * @param displayText The text to display in our UX. | 654 * @param displayText The text to display in our UX. |
| 655 * @param alternateTerm The alternate term to display on the results page. | 655 * @param alternateTerm The alternate term to display on the results page. |
| 656 * @param selectionStartAdjust The start offset adjustment of the selection to use to highlight | |
| 657 * the search term. | |
| 658 * @param selectionEndAdjust The end offset adjustment of the selection to u se to highlight | |
| 659 * the search term. | |
| 656 */ | 660 */ |
| 657 @CalledByNative | 661 @CalledByNative |
| 658 public void onSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode, | 662 public void onSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode, |
| 659 final String searchTerm, final String displayText, final String alte rnateTerm, | 663 final String searchTerm, final String displayText, final String alte rnateTerm, |
| 660 boolean doPreventPreload) { | 664 boolean doPreventPreload, int selectionStartAdjust, int selectionEnd Adjust) { |
| 661 mNetworkCommunicator.handleSearchTermResolutionResponse(isNetworkUnavail able, responseCode, | 665 mNetworkCommunicator.handleSearchTermResolutionResponse(isNetworkUnavail able, responseCode, |
| 662 searchTerm, displayText, alternateTerm, doPreventPreload); | 666 searchTerm, displayText, alternateTerm, doPreventPreload, select ionStartAdjust, |
| 667 selectionEndAdjust); | |
| 663 } | 668 } |
| 664 | 669 |
| 665 @Override | 670 @Override |
| 666 public void handleSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode, | 671 public void handleSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode, |
| 667 String searchTerm, String displayText, String alternateTerm, boolean doPreventPreload) { | 672 String searchTerm, String displayText, String alternateTerm, boolean doPreventPreload, |
| 673 int selectionStartAdjust, int selectionEndAdjust) { | |
| 668 if (!mSearchPanelDelegate.isShowing()) return; | 674 if (!mSearchPanelDelegate.isShowing()) return; |
| 669 | 675 |
| 670 // Show an appropriate message for what to search for. | 676 // Show an appropriate message for what to search for. |
| 671 String message; | 677 String message; |
| 672 boolean doLiteralSearch = false; | 678 boolean doLiteralSearch = false; |
| 673 if (isNetworkUnavailable) { | 679 if (isNetworkUnavailable) { |
| 674 message = mActivity.getResources().getString( | 680 message = mActivity.getResources().getString( |
| 675 R.string.contextual_search_network_unavailable); | 681 R.string.contextual_search_network_unavailable); |
| 676 } else if (!isHttpFailureCode(responseCode)) { | 682 } else if (!isHttpFailureCode(responseCode)) { |
| 677 message = displayText; | 683 message = displayText; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 700 mDidLoadResolvedSearchRequest = false; | 706 mDidLoadResolvedSearchRequest = false; |
| 701 if (mIsSearchContentViewShowing) { | 707 if (mIsSearchContentViewShowing) { |
| 702 mSearchRequest.setNormalPriority(); | 708 mSearchRequest.setNormalPriority(); |
| 703 } | 709 } |
| 704 if (mIsSearchContentViewShowing || shouldPreload) { | 710 if (mIsSearchContentViewShowing || shouldPreload) { |
| 705 loadSearchUrl(); | 711 loadSearchUrl(); |
| 706 } | 712 } |
| 707 mPolicy.logSearchTermResolutionDetails(searchTerm, | 713 mPolicy.logSearchTermResolutionDetails(searchTerm, |
| 708 mNetworkCommunicator.getBasePageUrl()); | 714 mNetworkCommunicator.getBasePageUrl()); |
| 709 } | 715 } |
| 716 | |
| 717 if (selectionStartAdjust != 0 || selectionEndAdjust != 0) { | |
| 718 mSelectionController.adjustSelection(selectionStartAdjust, selection EndAdjust); | |
|
pedro (no code reviews)
2015/06/25 01:30:28
Nit: Call it expandSelection() instead?
aurimas (slooooooooow)
2015/07/01 00:45:38
Done
| |
| 719 } | |
| 710 } | 720 } |
| 711 | 721 |
| 712 /** | 722 /** |
| 713 * Loads a Search Request in the Contextual Search's Content View. | 723 * Loads a Search Request in the Contextual Search's Content View. |
| 714 */ | 724 */ |
| 715 private void loadSearchUrl() { | 725 private void loadSearchUrl() { |
| 716 mLoadedSearchUrlTimeMs = System.currentTimeMillis(); | 726 mLoadedSearchUrlTimeMs = System.currentTimeMillis(); |
| 717 mNetworkCommunicator.loadUrl(mSearchRequest.getSearchUrl()); | 727 mNetworkCommunicator.loadUrl(mSearchRequest.getSearchUrl()); |
| 718 mDidLoadResolvedSearchRequest = true; | 728 mDidLoadResolvedSearchRequest = true; |
| 719 | 729 |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1239 long nativeContextualSearchManager, String searchUrl, long searchUrl TimeMs); | 1249 long nativeContextualSearchManager, String searchUrl, long searchUrl TimeMs); |
| 1240 private native void nativeSetWebContents(long nativeContextualSearchManager, | 1250 private native void nativeSetWebContents(long nativeContextualSearchManager, |
| 1241 ContentViewCore searchContentViewCore, WebContentsDelegateAndroid de legate); | 1251 ContentViewCore searchContentViewCore, WebContentsDelegateAndroid de legate); |
| 1242 private native void nativeDestroyWebContents(long nativeContextualSearchMana ger); | 1252 private native void nativeDestroyWebContents(long nativeContextualSearchMana ger); |
| 1243 private native void nativeReleaseWebContents(long nativeContextualSearchMana ger); | 1253 private native void nativeReleaseWebContents(long nativeContextualSearchMana ger); |
| 1244 private native void nativeDestroyWebContentsFromContentViewCore( | 1254 private native void nativeDestroyWebContentsFromContentViewCore( |
| 1245 long nativeContextualSearchManager, ContentViewCore contentViewCore) ; | 1255 long nativeContextualSearchManager, ContentViewCore contentViewCore) ; |
| 1246 private native void nativeSetInterceptNavigationDelegate(long nativeContextu alSearchManager, | 1256 private native void nativeSetInterceptNavigationDelegate(long nativeContextu alSearchManager, |
| 1247 InterceptNavigationDelegate delegate, WebContents webContents); | 1257 InterceptNavigationDelegate delegate, WebContents webContents); |
| 1248 } | 1258 } |
| OLD | NEW |