Commit b10bf33a authored by Yu Su's avatar Yu Su Committed by Commit Bot

Lens Controller - add a queryImage method to support passing back app intent...

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.

Change-Id: I40a58eaabaadb23a3113825400c3be95396aa4f0
Bug: 170126006
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450709
Commit-Queue: Yu Su <yusuyoutube@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarBen Goldberger <benwgold@google.com>
Reviewed-by: default avatarSinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#814967}
parent 88d141e6
...@@ -885,6 +885,8 @@ chrome_java_sources = [ ...@@ -885,6 +885,8 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/language/settings/LanguageSettings.java", "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/language/settings/LanguagesManager.java",
"java/src/org/chromium/chrome/browser/lens/LensController.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/DefaultSearchEngineDialogHelper.java",
"java/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialog.java", "java/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialog.java",
"java/src/org/chromium/chrome/browser/locale/LocaleChangedBroadcastReceiver.java", "java/src/org/chromium/chrome/browser/locale/LocaleChangedBroadcastReceiver.java",
......
...@@ -33,6 +33,7 @@ public class LensController { ...@@ -33,6 +33,7 @@ public class LensController {
return false; 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 * Classify an image and once complete trigger a callback with a boolean on whether that image
* supports a lens action. * supports a lens action.
...@@ -41,18 +42,29 @@ public class LensController { ...@@ -41,18 +42,29 @@ public class LensController {
*/ */
public void classifyImage(Uri imageUri, Callback<Boolean> classifyCallback) {} 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 * Classify an image and once complete trigger a callback with a boolean on whether that image
* supports a lens action. * supports a lens action.
* @param imageUri The URI of the image to classify. * @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 pageUrl Url of the top level page domain.
* @param titleOrAltText Title or alt text of the selected image tag. * @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, public void classifyImage(Uri imageUri, String pageUrl, String titleOrAltText,
Callback<Boolean> classifyCallback) {} 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 * If an image classification request is pending but no longer needed, explicitly terminate
* the request. * the request.
......
// 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
// 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
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