[M87] Lens Controller - add a queryImage method to support passing back app intent key from Lens Prime SDK.
The app intent key will be used when generate the Lens deeplink intent in LensUtils.java.
Cherry pick of https://chromium-review.googlesource.com/c/chromium/src/+/2450709
for the M87 branch which was approved here:
https://bugs.chromium.org/p/chromium/issues/detail?id=1099982
(cherry picked from commit b10bf33a7da56dfe5062f568588fe02ffc4f0bea)
Change-Id: I40a58eaabaadb23a3113825400c3be95396aa4f0
Bug: 170126006
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450709
Commit-Queue: Yu Su <[email protected]>
Reviewed-by: Theresa <[email protected]>
Reviewed-by: Ben Goldberger <[email protected]>
Reviewed-by: Sinan Sahin <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#814967}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485622
Cr-Commit-Position: refs/branch-heads/4280@{#514}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/chrome/android/chrome_java_sources.gni b/chrome/android/chrome_java_sources.gni
index a8f04bd1..5353c2b 100644
--- a/chrome/android/chrome_java_sources.gni
+++ b/chrome/android/chrome_java_sources.gni
@@ -891,6 +891,8 @@
"java/src/org/chromium/chrome/browser/language/settings/LanguageSettings.java",
"java/src/org/chromium/chrome/browser/language/settings/LanguagesManager.java",
"java/src/org/chromium/chrome/browser/lens/LensController.java",
+ "java/src/org/chromium/chrome/browser/lens/LensQueryParams.java",
+ "java/src/org/chromium/chrome/browser/lens/LensQueryResult.java",
"java/src/org/chromium/chrome/browser/locale/DefaultSearchEngineDialogHelper.java",
"java/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialog.java",
"java/src/org/chromium/chrome/browser/locale/LocaleChangedBroadcastReceiver.java",
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/lens/LensController.java b/chrome/android/java/src/org/chromium/chrome/browser/lens/LensController.java
index 7275b705..e0269c63 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/lens/LensController.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/lens/LensController.java
@@ -33,6 +33,7 @@
return false;
}
+ // TODO(yusuyoutube): deprecate once we switch to use #queryImage.
/**
* Classify an image and once complete trigger a callback with a boolean on whether that image
* supports a lens action.
@@ -41,18 +42,29 @@
*/
public void classifyImage(Uri imageUri, Callback<Boolean> classifyCallback) {}
+ // TODO(yusuyoutube): deprecate once we switch to use #queryImage.
/**
* Classify an image and once complete trigger a callback with a boolean on whether that image
* supports a lens action.
* @param imageUri The URI of the image to classify.
- * @param classifyCallback A callback to trigger once classification is complete.
* @param pageUrl Url of the top level page domain.
* @param titleOrAltText Title or alt text of the selected image tag.
+ * @param classifyCallback A callback to trigger once classification is complete.
*
*/
public void classifyImage(Uri imageUri, String pageUrl, String titleOrAltText,
Callback<Boolean> classifyCallback) {}
+ /**
+ * Classify an image and once complete trigger a callback with a LensQueryResult on whether that
+ * image supports a lens action.
+ * @param LensQueryParams A wrapper object which contains params for the Lens image query.
+ * @param queryCallback A callback to trigger once classification is complete.
+ *
+ */
+ public void queryImage(
+ LensQueryParams lensQueryParams, Callback<LensQueryResult> queryCallback) {}
+
/*
* If an image classification request is pending but no longer needed, explicitly terminate
* the request.
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/lens/LensQueryParams.java b/chrome/android/java/src/org/chromium/chrome/browser/lens/LensQueryParams.java
new file mode 100644
index 0000000..64402c1
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/lens/LensQueryParams.java
@@ -0,0 +1,89 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.lens;
+
+import android.net.Uri;
+
+import org.chromium.content_public.browser.WebContents;
+
+/**
+ * A wrapper class for the Lens image query params (e.g. used in LensController.queryImage)
+ * to provide a more consistent and extensible API.
+ */
+public class LensQueryParams {
+ private Uri mImageUri;
+ private String mPageUrl;
+ private String mImageTitleOrAltText;
+ private String mPageTitle;
+ private WebContents mWebContents;
+
+ /**
+ * Builder class for LensQueryParams.
+ */
+ public static class Builder {
+ private Uri mImageUri = Uri.EMPTY;
+ private String mPageUrl;
+ private String mImageTitleOrAltText;
+ private String mPageTitle;
+ private WebContents mWebContents;
+
+ public Builder() {}
+
+ public Builder withImageUri(Uri imageUri) {
+ this.mImageUri = imageUri;
+ return this;
+ }
+
+ public Builder withPageUrl(String pageUrl) {
+ this.mPageUrl = pageUrl;
+ return this;
+ }
+
+ public Builder withImageTitleOrAltText(String imageTitleOrAltText) {
+ this.mImageTitleOrAltText = imageTitleOrAltText;
+ return this;
+ }
+
+ public Builder withPageTitle(String pageTitle) {
+ this.mPageTitle = pageTitle;
+ return this;
+ }
+
+ public Builder withWebContents(WebContents webContents) {
+ this.mWebContents = webContents;
+ return this;
+ }
+
+ public LensQueryParams build() {
+ LensQueryParams lensQueryParams = new LensQueryParams();
+ lensQueryParams.mImageUri = this.mImageUri;
+ lensQueryParams.mPageUrl = this.mPageUrl;
+ lensQueryParams.mImageTitleOrAltText = this.mImageTitleOrAltText;
+ lensQueryParams.mPageTitle = this.mPageTitle;
+ lensQueryParams.mWebContents = this.mWebContents;
+ return lensQueryParams;
+ }
+ }
+
+ public Uri getImageUri() {
+ return mImageUri;
+ }
+
+ public String getPageUrl() {
+ return mPageUrl;
+ }
+
+ public String getImageTitleOrAltText() {
+ return mImageTitleOrAltText;
+ }
+
+ public String getPageTitle() {
+ return mPageTitle;
+ }
+
+ public WebContents getWebContents() {
+ return mWebContents;
+ }
+}
\ No newline at end of file
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/lens/LensQueryResult.java b/chrome/android/java/src/org/chromium/chrome/browser/lens/LensQueryResult.java
new file mode 100644
index 0000000..bbc0a1c
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/lens/LensQueryResult.java
@@ -0,0 +1,66 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.lens;
+
+/**
+ * A wrapper class for the Lens image query result from Lens Prime SDK.
+ */
+public class LensQueryResult {
+ private boolean mIsShoppyIntent;
+ private int mLensIntentType;
+
+ /**
+ * Builder class for LensQueryParams.
+ */
+ public static class Builder {
+ private boolean mIsShoppyIntent;
+ private int mLensIntentType;
+ public Builder() {}
+
+ public Builder withIsShoppyIntent(boolean isShoppyIntent) {
+ this.mIsShoppyIntent = isShoppyIntent;
+ return this;
+ }
+
+ public Builder withLensIntentType(int lensIntentType) {
+ this.mLensIntentType = lensIntentType;
+ return this;
+ }
+
+ public LensQueryResult build() {
+ LensQueryResult lensQueryResult = new LensQueryResult();
+ lensQueryResult.mIsShoppyIntent = this.mIsShoppyIntent;
+ lensQueryResult.mLensIntentType = this.mLensIntentType;
+ return lensQueryResult;
+ }
+ }
+
+ public boolean getIsShoppyIntent() {
+ return mIsShoppyIntent;
+ }
+
+ public int getLensIntentType() {
+ return mLensIntentType;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) {
+ return false;
+ }
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof LensQueryResult)) {
+ return false;
+ }
+
+ final LensQueryResult other = (LensQueryResult) o;
+
+ return mLensIntentType == other.getLensIntentType()
+ && mIsShoppyIntent == other.getIsShoppyIntent();
+ }
+}
\ No newline at end of file