Commit 154fb055 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Do not lookup Android payment apps for Google Play Billing

Before this patch, creating a Payment Request for
"https://play.google.com/billing" on a device where an Android payment
app with that payment method is installed would cause manifest lookups
at https://play.google.com/billing.

This patch removes "https://play.google.com/billing" from the list of
payment methods for which Android payment apps should be looked up.

After this patch, Chrome does not attempt to download manifests for the
Google Play Billing payment method when a locally installed Android
payment app provides support for it.

Bug: 1062376
Change-Id: Ibfb2ae9d189aada2161552f2e80e0ed2be5d84b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2125873
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754927}
parent b984d895
......@@ -60,8 +60,14 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
/* package */ static final String META_DATA_NAME_OF_DEFAULT_PAYMENT_METHOD_NAME =
"org.chromium.default_payment_method_name";
private final Set<String> mNonUriPaymentMethods;
private final Set<URI> mUriPaymentMethods;
/**
* The ignored payment method identifiers. Payment apps with this payment method identifier are
* ignored.
*/
private final Set<String> mIgnoredMethods = new HashSet<>();
private final Set<String> mNonUriPaymentMethods = new HashSet<>();
private final Set<URI> mUriPaymentMethods = new HashSet<>();
private final PaymentManifestDownloader mDownloader;
private final PaymentManifestWebDataService mWebDataService;
private final PaymentManifestParser mParser;
......@@ -152,6 +158,23 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
PaymentAppFactoryInterface factory) {
mDelegate = delegate;
mIgnoredMethods.add(MethodStrings.GOOGLE_PLAY_BILLING);
mDownloader = downloader;
mWebDataService = webDataService;
mParser = parser;
mPackageManagerDelegate = packageManagerDelegate;
mFactory = factory;
ChromeActivity activity =
ChromeActivity.fromWebContents(mDelegate.getParams().getWebContents());
mIsIncognito = activity != null && activity.getCurrentTabModel().isIncognito();
}
/**
* Finds and validates the installed android payment apps that support the payment method names
* that the merchant is using.
*/
/* package */ void findAndroidPaymentApps() {
// For non-URI payment method names, only names published by W3C should be supported. Keep
// this in sync with manifest_verifier.cc.
Set<String> supportedNonUriPaymentMethods = new HashSet<>();
......@@ -161,10 +184,9 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
supportedNonUriPaymentMethods.add(MethodStrings.PAYER_CREDIT_TRANSFER);
supportedNonUriPaymentMethods.add(MethodStrings.TOKENIZED_CARD);
mNonUriPaymentMethods = new HashSet<>();
mUriPaymentMethods = new HashSet<>();
for (String method : mDelegate.getParams().getMethodData().keySet()) {
assert !TextUtils.isEmpty(method);
if (mIgnoredMethods.contains(method)) continue;
if (supportedNonUriPaymentMethods.contains(method)) {
mNonUriPaymentMethods.add(method);
} else if (UriUtils.looksLikeUriMethod(method)) {
......@@ -173,21 +195,6 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
}
}
mDownloader = downloader;
mWebDataService = webDataService;
mParser = parser;
mPackageManagerDelegate = packageManagerDelegate;
mFactory = factory;
ChromeActivity activity =
ChromeActivity.fromWebContents(mDelegate.getParams().getWebContents());
mIsIncognito = activity != null && activity.getCurrentTabModel().isIncognito();
}
/**
* Finds and validates the installed android payment apps that support the payment method names
* that the merchant is using.
*/
/* package */ void findAndroidPaymentApps() {
List<ResolveInfo> allInstalledPaymentApps =
mPackageManagerDelegate.getActivitiesThatCanRespondToIntentWithMetaData(
new Intent(WebPaymentIntentHelper.ACTION_PAY));
......@@ -592,4 +599,16 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
String string = uri.toString();
return string.endsWith("/") ? string.substring(0, string.length() - 1) : string;
}
/**
* Ignores the given payment method identifier, so no Android payment apps for this method are
* looked up in findAndroidPaymentApps(). Calling this multiple times will union the new payment
* methods with the existing set.
*
* @param ignoredPaymentMethodIdentifier The ignored payment method identifier.
*/
@VisibleForTesting
/* package */ void ignorePaymentMethodForTest(String ignoredPaymentMethodIdentifier) {
mIgnoredMethods.add(ignoredPaymentMethodIdentifier);
}
}
......@@ -371,6 +371,21 @@ public class AndroidPaymentAppFinderTest
Assert.assertEquals("com.bobpay", mPaymentApps.get(0).getIdentifier());
}
/** Ignored payment methods should be filtered out. */
@Test
@Feature({"Payments"})
public void testIgnoredPaymentMethodIdentifier() throws Throwable {
Set<String> methods = new HashSet<>();
methods.add("https://bobpay.com/webpay");
mPackageManager.installPaymentApp("BobPay", "com.bobpay", "https://bobpay.com/webpay",
/*signature=*/"01020304050607080900");
ignorePaymentMethodIdentifierAndFindApps(
/*ignoredPaymentMethodIdentifier=*/"https://bobpay.com/webpay", methods);
Assert.assertTrue("No apps should match the query", mPaymentApps.isEmpty());
}
/**
* Test BobPay with an incorrect signature and https://bobpay.com/webpay payment method name.
*/
......@@ -1166,7 +1181,13 @@ public class AndroidPaymentAppFinderTest
mPaymentApps.get(0).getInstrumentMethodNames().contains("tokenized-card"));
}
private void findApps(final Set<String> methodNames) throws Throwable {
private void findApps(Set<String> methodNames) throws Throwable {
ignorePaymentMethodIdentifierAndFindApps(
/*ignoredPaymentMethodIdentifier=*/null, methodNames);
}
private void ignorePaymentMethodIdentifierAndFindApps(
String ignoredPaymentMethodIdentifier, Set<String> methodNames) throws Throwable {
mMethodData = buildMethodData(methodNames);
mRule.runOnUiThread(() -> {
AndroidPaymentAppFinder finder =
......@@ -1174,6 +1195,9 @@ public class AndroidPaymentAppFinderTest
new PaymentManifestParser(), mPackageManager,
/*delegate=*/AndroidPaymentAppFinderTest.this, /*factory=*/null);
finder.bypassIsReadyToPayServiceInTest();
if (ignoredPaymentMethodIdentifier != null) {
finder.ignorePaymentMethodForTest(ignoredPaymentMethodIdentifier);
}
finder.findAndroidPaymentApps();
});
CriteriaHelper.pollInstrumentationThread(new Criteria() {
......
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