Commit 064942f6 authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[Shopping Demo] Fix a crash in TaskRecognizer.

Fixes a NPE in TaskRecognizer, and adds a check that the tab we're
trying to recognize is the current front tab.

Also clean up some spurious tags in the associated logging code.

BUG=965459, 942663

Change-Id: Ib8e1c0051f9151c548497e761aa71bdb935886f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1621564
Commit-Queue: Donn Denman <donnd@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Auto-Submit: Donn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662267}
parent 252307c8
......@@ -102,7 +102,7 @@ public abstract class ContextualSearchContext {
context.setInitialSelectedWord(surroundingText.substring(start, end));
}
if (context.hasValidSelection() && !TextUtils.isEmpty(context.getInitialSelectedWord())) {
Log.i(TAG, "ctxs identified default query: " + context.getWordTapped());
Log.i(TAG, "identified default query: " + context.getWordTapped());
// TODO(donnd): figure out which of these parameters should be passed in.
context.setResolveProperties("US", true, 0, 0);
return context;
......
......@@ -57,7 +57,7 @@ public class SimpleSearchTermResolver {
mResponseCallback = responseCallback;
if (baseWebContents != null && contextualSearchContext != null
&& contextualSearchContext.canResolve()) {
Log.i(TAG, "ctxs calling nativeStartSearchTermResolutionRequest!!");
Log.i(TAG, "calling nativeStartSearchTermResolutionRequest.");
nativeStartSearchTermResolutionRequest(
mNativePointer, contextualSearchContext, baseWebContents);
}
......@@ -108,7 +108,7 @@ public class SimpleSearchTermResolver {
selectionStartAdjust, selectionEndAdjust, contextLanguage, thumbnailUrl, caption,
quickActionUri, quickActionCategory, loggedEventId, searchUrlFull, searchUrlPreload,
cocaCardTag);
Log.v(TAG, "ctxs onSearchTermResolutionResponse received with " + resolvedSearchTerm);
Log.v(TAG, "onSearchTermResolutionResponse received with " + resolvedSearchTerm);
if (!TextUtils.isEmpty(resolvedSearchTerm.searchTerm())) {
ResolveResponse responseCallback = mResponseCallback;
mResponseCallback = null;
......
......@@ -8,6 +8,7 @@ import android.net.Uri;
import android.text.TextUtils;
import org.chromium.base.Log;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabPanel;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchContext;
import org.chromium.chrome.browser.contextualsearch.ResolvedSearchTerm;
import org.chromium.chrome.browser.contextualsearch.ResolvedSearchTerm.CardTag;
......@@ -65,7 +66,8 @@ public class TaskRecognizer extends EmptyTabObserver implements ResolveResponse
* @param tab The tab that might be about a product. Must be the current front tab.
*/
private void tryToShowProduct(Tab tab) {
if (mTabInUse != null) {
boolean isCurrentSelectedTab = tab.equals(tab.getActivity().getActivityTab());
if (mTabInUse != null || !isCurrentSelectedTab) {
return;
}
......@@ -126,17 +128,22 @@ public class TaskRecognizer extends EmptyTabObserver implements ResolveResponse
* Creates an {@code EphemeralTab} for the given searchUrl using details from the given
* {@code ResolvedSearchterm}.
*/
private void createEphemeralTabFor(ResolvedSearchTerm resolvedSearchTerm, Uri searchUrl) {
mTabInUse.getActivity().getEphemeralTabPanel().requestOpenPanel(
searchUrl.toString(), resolvedSearchTerm.displayText(), mTabInUse.isIncognito());
private void createEphemeralTabFor(
Tab activeTab, ResolvedSearchTerm resolvedSearchTerm, Uri searchUrl) {
EphemeralTabPanel displayPanel = activeTab.getActivity().getEphemeralTabPanel();
if (displayPanel != null) {
displayPanel.requestOpenPanel(searchUrl.toString(), resolvedSearchTerm.displayText(),
activeTab.isIncognito());
}
}
/** ResolveResponse overrides. */
@Override
public void onResolveResponse(ResolvedSearchTerm resolvedSearchTerm, Uri searchUri) {
Tab activeTab = mTabInUse;
mTabInUse = null;
if (looksLikeAProduct(resolvedSearchTerm)) {
createEphemeralTabFor(resolvedSearchTerm, searchUri);
if (looksLikeAProduct(resolvedSearchTerm) && activeTab != null) {
createEphemeralTabFor(activeTab, resolvedSearchTerm, searchUri);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment