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

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

Issue 2322793002: [Contextual Search] Fetch and display thumbnails returned in resolution response (Closed)
Patch Set: std::unique_ptr Created 4 years, 3 months 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
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.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;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 mIsShowingPeekPromo = mPolicy.isPeekPromoAvailable(); 473 mIsShowingPeekPromo = mPolicy.isPeekPromoAvailable();
474 if (mIsShowingPeekPromo) { 474 if (mIsShowingPeekPromo) {
475 mSearchPanel.showPeekPromo(); 475 mSearchPanel.showPeekPromo();
476 mPolicy.registerPeekPromoSeen(); 476 mPolicy.registerPeekPromoSeen();
477 } 477 }
478 } 478 }
479 479
480 // Note: whether the sprite should be animated or not needs to be set be fore the call to 480 // Note: whether the sprite should be animated or not needs to be set be fore the call to
481 // peekPanel(). If the sprite should be animated, the animation will beg in after the panel 481 // peekPanel(). If the sprite should be animated, the animation will beg in after the panel
482 // finishes peeking. If it should not be animated, the icon will be draw n right away. 482 // finishes peeking. If it should not be animated, the icon will be draw n right away.
483 mSearchPanel.setShouldAnimateIconSprite(mPolicy.shouldAnimateSearchProvi derIcon(), 483 mSearchPanel.setShouldAnimateIconSprite(mPolicy.shouldAnimateSearchProvi derIcon());
484 ContextualSearchFieldTrial.areExtraSearchBarAnimationsDisabled() );
485 484
486 // Note: now that the contextual search has properly started, set the pr omo involvement. 485 // Note: now that the contextual search has properly started, set the pr omo involvement.
487 if (mPolicy.isPromoAvailable()) { 486 if (mPolicy.isPromoAvailable()) {
488 mIsShowingPromo = true; 487 mIsShowingPromo = true;
489 mIsMandatoryPromo = mPolicy.isMandatoryPromoAvailable(); 488 mIsMandatoryPromo = mPolicy.isMandatoryPromoAvailable();
490 mDidLogPromoOutcome = false; 489 mDidLogPromoOutcome = false;
491 mSearchPanel.setIsPromoActive(true, mIsMandatoryPromo); 490 mSearchPanel.setIsPromoActive(true, mIsMandatoryPromo);
492 mSearchPanel.setDidSearchInvolvePromo(); 491 mSearchPanel.setDidSearchInvolvePromo();
493 } 492 }
494 493
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 * @param searchTerm The term to use in our subsequent search. 645 * @param searchTerm The term to use in our subsequent search.
647 * @param displayText The text to display in our UX. 646 * @param displayText The text to display in our UX.
648 * @param alternateTerm The alternate term to display on the results page. 647 * @param alternateTerm The alternate term to display on the results page.
649 * @param mid the MID for an entity to use to trigger a Knowledge Panel, or an empty string. 648 * @param mid the MID for an entity to use to trigger a Knowledge Panel, or an empty string.
650 * A MID is a unique identifier for an entity in the Search Knowl edge Graph. 649 * A MID is a unique identifier for an entity in the Search Knowl edge Graph.
651 * @param selectionStartAdjust A positive number of characters that the star t of the existing 650 * @param selectionStartAdjust A positive number of characters that the star t of the existing
652 * selection should be expanded by. 651 * selection should be expanded by.
653 * @param selectionEndAdjust A positive number of characters that the end of the existing 652 * @param selectionEndAdjust A positive number of characters that the end of the existing
654 * selection should be expanded by. 653 * selection should be expanded by.
655 * @param contextLanguage The language of the original search term, or an em pty string. 654 * @param contextLanguage The language of the original search term, or an em pty string.
655 * @param thumbnailUrl The URL of the thumbnail to display in our UX.
656 */ 656 */
657 @CalledByNative 657 @CalledByNative
658 public void onSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode, 658 public void onSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode,
659 final String searchTerm, final String displayText, final String alte rnateTerm, 659 final String searchTerm, final String displayText, final String alte rnateTerm,
660 final String mid, boolean doPreventPreload, int selectionStartAdjust , 660 final String mid, boolean doPreventPreload, int selectionStartAdjust ,
661 int selectionEndAdjust, final String contextLanguage) { 661 int selectionEndAdjust, final String contextLanguage, final String t humbnailUrl) {
662 mNetworkCommunicator.handleSearchTermResolutionResponse(isNetworkUnavail able, responseCode, 662 mNetworkCommunicator.handleSearchTermResolutionResponse(isNetworkUnavail able, responseCode,
663 searchTerm, displayText, alternateTerm, mid, doPreventPreload, s electionStartAdjust, 663 searchTerm, displayText, alternateTerm, mid, doPreventPreload, s electionStartAdjust,
664 selectionEndAdjust, contextLanguage); 664 selectionEndAdjust, contextLanguage, thumbnailUrl);
665 } 665 }
666 666
667 @Override 667 @Override
668 public void handleSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode, 668 public void handleSearchTermResolutionResponse(boolean isNetworkUnavailable, int responseCode,
669 String searchTerm, String displayText, String alternateTerm, String mid, 669 String searchTerm, String displayText, String alternateTerm, String mid,
670 boolean doPreventPreload, int selectionStartAdjust, int selectionEnd Adjust, 670 boolean doPreventPreload, int selectionStartAdjust, int selectionEnd Adjust,
671 String contextLanguage) { 671 String contextLanguage, String thumbnailUrl) {
672 // Show an appropriate message for what to search for. 672 // Show an appropriate message for what to search for.
673 String message; 673 String message;
674 boolean doLiteralSearch = false; 674 boolean doLiteralSearch = false;
675 if (isNetworkUnavailable) { 675 if (isNetworkUnavailable) {
676 // TODO(donnd): double-check that the network is really unavailable? 676 // TODO(donnd): double-check that the network is really unavailable?
677 message = mActivity.getResources().getString( 677 message = mActivity.getResources().getString(
678 R.string.contextual_search_network_unavailable); 678 R.string.contextual_search_network_unavailable);
679 } else if (!isHttpFailureCode(responseCode) && !TextUtils.isEmpty(displa yText)) { 679 } else if (!isHttpFailureCode(responseCode) && !TextUtils.isEmpty(displa yText)) {
680 message = displayText; 680 message = displayText;
681 } else if (!mPolicy.shouldShowErrorCodeInBar()) { 681 } else if (!mPolicy.shouldShowErrorCodeInBar()) {
682 message = mSelectionController.getSelectedText(); 682 message = mSelectionController.getSelectedText();
683 doLiteralSearch = true; 683 doLiteralSearch = true;
684 } else { 684 } else {
685 message = mActivity.getResources().getString( 685 message = mActivity.getResources().getString(
686 R.string.contextual_search_error, responseCode); 686 R.string.contextual_search_error, responseCode);
687 doLiteralSearch = true; 687 doLiteralSearch = true;
688 } 688 }
689 mSearchPanel.onSearchTermResolved(message); 689 thumbnailUrl = ContextualSearchFieldTrial.isNowOnTapBarIntegrationEnable d()
690 ? thumbnailUrl : "";
691 mSearchPanel.onSearchTermResolved(message, thumbnailUrl);
690 692
691 // If there was an error, fall back onto a literal search for the select ion. 693 // If there was an error, fall back onto a literal search for the select ion.
692 // Since we're showing the panel, there must be a selection. 694 // Since we're showing the panel, there must be a selection.
693 if (doLiteralSearch) { 695 if (doLiteralSearch) {
694 searchTerm = mSelectionController.getSelectedText(); 696 searchTerm = mSelectionController.getSelectedText();
695 alternateTerm = null; 697 alternateTerm = null;
696 doPreventPreload = true; 698 doPreventPreload = true;
697 } 699 }
698 if (!TextUtils.isEmpty(searchTerm)) { 700 if (!TextUtils.isEmpty(searchTerm)) {
699 // TODO(donnd): Instead of preloading, we should prefetch (ie the UR L should not 701 // TODO(donnd): Instead of preloading, we should prefetch (ie the UR L should not
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 boolean maySendBasePageUrl); 1384 boolean maySendBasePageUrl);
1383 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager, 1385 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager,
1384 String selection, boolean useResolvedSearchTerm, WebContents baseWeb Contents, 1386 String selection, boolean useResolvedSearchTerm, WebContents baseWeb Contents,
1385 boolean maySendBasePageUrl); 1387 boolean maySendBasePageUrl);
1386 private native void nativeEnableContextualSearchJsApiForOverlay( 1388 private native void nativeEnableContextualSearchJsApiForOverlay(
1387 long nativeContextualSearchManager, WebContents overlayWebContents); 1389 long nativeContextualSearchManager, WebContents overlayWebContents);
1388 // Don't call these directly, instead call the private methods that cache th e results. 1390 // Don't call these directly, instead call the private methods that cache th e results.
1389 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager); 1391 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager);
1390 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager); 1392 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager);
1391 } 1393 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698