Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFinder.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFinder.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFinder.java |
| index 252fc4be2ab2e62592cecf48678b63e43db05033..cee3a513d7b251c84cbecf4c515005fec0cedb12 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFinder.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFinder.java |
| @@ -6,7 +6,6 @@ package org.chromium.chrome.browser.payments; |
| import android.content.Intent; |
| import android.content.pm.ResolveInfo; |
| -import android.net.Uri; |
| import android.text.TextUtils; |
| import org.chromium.base.Log; |
| @@ -41,16 +40,24 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback { |
| /* package */ static final String ACTION_IS_READY_TO_PAY = |
| "org.chromium.intent.action.IS_READY_TO_PAY"; |
| - /** The name of the intent for the action of paying using "basic-card" method. */ |
| - /* package */ static final String ACTION_PAY_BASIC_CARD = |
| - "org.chromium.intent.action.PAY_BASIC_CARD"; |
| - |
| /** |
| * The basic-card payment method name used by merchant and defined by W3C: |
| * https://w3c.github.io/webpayments-methods-card/#method-id |
| */ |
| /* package */ static final String BASIC_CARD_PAYMENT_METHOD = "basic-card"; |
| + /** |
| + * Meta data name of an app's supported payment method names. |
| + */ |
| + static final String META_DATA_NAME_OF_PAYMENT_METHOD_NAMES = |
| + "org.chromium.payment_method_names"; |
| + |
| + /** |
| + * Meta data name of an app's supported default payment method name. |
| + */ |
| + static final String META_DATA_NAME_OF_DEFAULT_PAYMENT_METHOD_NAME = |
| + "org.chromum.default_payment_method_name"; |
| + |
| /** The maximum number of payment method manifests to download. */ |
| private static final int MAX_NUMBER_OF_MANIFESTS = 10; |
| @@ -151,22 +158,42 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback { |
| } |
| private void findAndroidPaymentApps() { |
| + Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY); |
| + List<ResolveInfo> apps = |
| + mPackageManagerDelegate.getActivitiesThatCanRespondToIntent(payIntent); |
| + if (apps.isEmpty()) { |
| + onSearchFinished(); |
| + return; |
| + } |
| + |
| + List<String[]> appSupportedMethods = new ArrayList<String[]>(); |
| + for (int i = 0; i < apps.size(); i++) { |
| + appSupportedMethods.add(mPackageManagerDelegate.getStringArrayMetaData( |
| + apps.get(i).activityInfo.packageName, META_DATA_NAME_OF_PAYMENT_METHOD_NAMES)); |
| + } |
| + |
| + List<String> appSupportedDefaultMethods = new ArrayList<String>(); |
| + for (int i = 0; i < apps.size(); i++) { |
| + appSupportedDefaultMethods.add( |
| + mPackageManagerDelegate.getStringMetaData(apps.get(i).activityInfo.packageName, |
| + META_DATA_NAME_OF_DEFAULT_PAYMENT_METHOD_NAME)); |
| + } |
| + |
| List<PaymentManifestVerifier> verifiers = new ArrayList<>(); |
| if (!mPaymentMethods.isEmpty()) { |
|
please use gerrit instead
2017/03/31 15:47:08
This check seems redundant now. Let's remove it.
gogerald1
2017/03/31 16:18:43
Why? mPaymentMethods is merchant queried methods w
please use gerrit instead
2017/03/31 16:26:30
It's redundant because the for loop on the next li
gogerald1
2017/03/31 16:28:54
yes, my bad, updated in the new patch
|
| - Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY); |
| for (URI methodName : mPaymentMethods) { |
| - payIntent.setData(Uri.parse(methodName.toString())); |
| - List<ResolveInfo> apps = |
| - mPackageManagerDelegate.getActivitiesThatCanRespondToIntent(payIntent); |
| - if (apps.isEmpty()) continue; |
| + List<ResolveInfo> supportedApps = findOutAppsSupportTheGivenPaymentMethod(apps, |
| + appSupportedMethods, appSupportedDefaultMethods, methodName.toString()); |
| + if (supportedApps.isEmpty()) continue; |
| // Start the parser utility process as soon as possible, once we know that a |
| // manifest file needs to be parsed. The startup can take up to 2 seconds. |
| if (!mParser.isUtilityProcessRunning()) mParser.startUtilityProcess(); |
| - verifiers.add(new PaymentManifestVerifier(methodName, apps, mDownloader, mParser, |
| - mPackageManagerDelegate, this /* callback */)); |
| - mPendingApps.put(methodName, new HashSet<>(apps)); |
| + verifiers.add(new PaymentManifestVerifier(methodName, supportedApps, mDownloader, |
| + mParser, mPackageManagerDelegate, this /* callback */)); |
| + mPendingApps.put(methodName, new HashSet<>(supportedApps)); |
| + |
| if (verifiers.size() == MAX_NUMBER_OF_MANIFESTS) { |
| Log.d(TAG, "Reached maximum number of allowed payment app manifests."); |
| break; |
| @@ -175,12 +202,11 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback { |
| } |
| if (mQueryBasicCard) { |
| - Intent basicCardPayIntent = new Intent(ACTION_PAY_BASIC_CARD); |
| - List<ResolveInfo> apps = |
| - mPackageManagerDelegate.getActivitiesThatCanRespondToIntent(basicCardPayIntent); |
| - for (int i = 0; i < apps.size(); i++) { |
| + List<ResolveInfo> supportedApps = findOutAppsSupportTheGivenPaymentMethod(apps, |
| + appSupportedMethods, appSupportedDefaultMethods, BASIC_CARD_PAYMENT_METHOD); |
| + for (int i = 0; i < supportedApps.size(); i++) { |
| // Chrome does not verify app manifests for "basic-card" support. |
| - onValidPaymentApp(BASIC_CARD_PAYMENT_METHOD, apps.get(i)); |
| + onValidPaymentApp(BASIC_CARD_PAYMENT_METHOD, supportedApps.get(i)); |
| } |
| } |
| @@ -194,6 +220,32 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback { |
| } |
| } |
| + private List<ResolveInfo> findOutAppsSupportTheGivenPaymentMethod(List<ResolveInfo> apps, |
|
please use gerrit instead
2017/03/31 15:47:08
static?
please use gerrit instead
2017/03/31 15:47:08
filterAppsByMethodName().
gogerald1
2017/03/31 16:18:43
Done.
gogerald1
2017/03/31 16:18:43
Done.
|
| + List<String[]> appsMethods, List<String> appsDefaultMethods, String targetMethodName) { |
|
please use gerrit instead
2017/03/31 15:47:08
Let's pass URI data type in as many places as poss
gogerald1
2017/03/31 16:18:43
Looks not good since this interface is also used f
|
| + assert apps.size() == appsMethods.size(); |
| + assert apps.size() == appsDefaultMethods.size(); |
| + |
| + // Note that apps, appsMethods and appsDefaultMethods must have the same size. And the |
| + // information at the same index must correspond to the same app. |
| + List<ResolveInfo> supportedApps = new ArrayList<ResolveInfo>(); |
| + for (int i = 0; i < apps.size(); i++) { |
| + if (targetMethodName.equalsIgnoreCase(appsDefaultMethods.get(i))) { |
|
please use gerrit instead
2017/03/31 15:47:08
Don't ignore case. Let's be strict.
gogerald1
2017/03/31 16:18:43
Done. I am worried that the merchant might use upp
please use gerrit instead
2017/03/31 16:26:30
We prohibit variations in the spec as much as poss
|
| + supportedApps.add(apps.get(i)); |
| + continue; |
| + } |
| + |
| + String[] methods = appsMethods.get(i); |
| + if (methods == null) continue; |
| + for (int j = 0; j < methods.length; j++) { |
| + if (targetMethodName.equalsIgnoreCase(methods[j])) { |
| + supportedApps.add(apps.get(i)); |
| + break; |
| + } |
| + } |
| + } |
| + return supportedApps; |
| + } |
| + |
| @Override |
| public void onValidPaymentApp(URI methodName, ResolveInfo resolveInfo) { |
| onValidPaymentApp(methodName.toString(), resolveInfo); |