| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 8 import android.content.pm.ResolveInfo; | 8 import android.content.pm.ResolveInfo; |
| 9 import android.net.Uri; | 9 import android.net.Uri; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| 11 | 11 |
| 12 import org.chromium.base.Log; | 12 import org.chromium.base.Log; |
| 13 import org.chromium.chrome.browser.ChromeActivity; |
| 13 import org.chromium.chrome.browser.UrlConstants; | 14 import org.chromium.chrome.browser.UrlConstants; |
| 14 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedC
allback; | 15 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedC
allback; |
| 15 import org.chromium.chrome.browser.payments.PaymentManifestVerifier.ManifestVeri
fyCallback; | 16 import org.chromium.chrome.browser.payments.PaymentManifestVerifier.ManifestVeri
fyCallback; |
| 16 import org.chromium.components.payments.PaymentManifestDownloader; | 17 import org.chromium.components.payments.PaymentManifestDownloader; |
| 17 import org.chromium.components.payments.PaymentManifestParser; | 18 import org.chromium.components.payments.PaymentManifestParser; |
| 18 import org.chromium.content_public.browser.WebContents; | 19 import org.chromium.content_public.browser.WebContents; |
| 19 | 20 |
| 20 import java.net.URI; | 21 import java.net.URI; |
| 21 import java.net.URISyntaxException; | 22 import java.net.URISyntaxException; |
| 22 import java.util.ArrayList; | 23 import java.util.ArrayList; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 /** The maximum number of payment method manifests to download. */ | 54 /** The maximum number of payment method manifests to download. */ |
| 54 private static final int MAX_NUMBER_OF_MANIFESTS = 10; | 55 private static final int MAX_NUMBER_OF_MANIFESTS = 10; |
| 55 | 56 |
| 56 private final WebContents mWebContents; | 57 private final WebContents mWebContents; |
| 57 private final boolean mQueryBasicCard; | 58 private final boolean mQueryBasicCard; |
| 58 private final Set<URI> mPaymentMethods; | 59 private final Set<URI> mPaymentMethods; |
| 59 private final PaymentManifestDownloader mDownloader; | 60 private final PaymentManifestDownloader mDownloader; |
| 60 private final PaymentManifestParser mParser; | 61 private final PaymentManifestParser mParser; |
| 61 private final PackageManagerDelegate mPackageManagerDelegate; | 62 private final PackageManagerDelegate mPackageManagerDelegate; |
| 62 private final PaymentAppCreatedCallback mCallback; | 63 private final PaymentAppCreatedCallback mCallback; |
| 64 private final boolean mIsIncognito; |
| 63 | 65 |
| 64 /** | 66 /** |
| 65 * A map of payment method names to the list of (yet) unverified Android app
s that claim to | 67 * A map of payment method names to the list of (yet) unverified Android app
s that claim to |
| 66 * handle these methods. Example payment method names in this data structure
: | 68 * handle these methods. Example payment method names in this data structure
: |
| 67 * "https://bobpay.com", "https://android.com/pay". Basic card is excluded. | 69 * "https://bobpay.com", "https://android.com/pay". Basic card is excluded. |
| 68 */ | 70 */ |
| 69 private final Map<URI, Set<ResolveInfo>> mPendingApps; | 71 private final Map<URI, Set<ResolveInfo>> mPendingApps; |
| 70 | 72 |
| 71 /** A map of Android package name to the payment app. */ | 73 /** A map of Android package name to the payment app. */ |
| 72 private final Map<String, AndroidPaymentApp> mResult; | 74 private final Map<String, AndroidPaymentApp> mResult; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 mPaymentMethods.add(uri); | 136 mPaymentMethods.add(uri); |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 mDownloader = downloader; | 140 mDownloader = downloader; |
| 139 mParser = parser; | 141 mParser = parser; |
| 140 mPackageManagerDelegate = packageManagerDelegate; | 142 mPackageManagerDelegate = packageManagerDelegate; |
| 141 mCallback = callback; | 143 mCallback = callback; |
| 142 mPendingApps = new HashMap<>(); | 144 mPendingApps = new HashMap<>(); |
| 143 mResult = new HashMap<>(); | 145 mResult = new HashMap<>(); |
| 146 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); |
| 147 mIsIncognito = activity != null && activity.getCurrentTabModel() != null |
| 148 && activity.getCurrentTabModel().isIncognito(); |
| 144 mRequireShowInSettings = requireShowInSettings; | 149 mRequireShowInSettings = requireShowInSettings; |
| 145 mSettingsLookup = new Intent(AndroidPaymentApp.ACTION_PAY); | 150 mSettingsLookup = new Intent(AndroidPaymentApp.ACTION_PAY); |
| 146 } | 151 } |
| 147 | 152 |
| 148 private void findAndroidPaymentApps() { | 153 private void findAndroidPaymentApps() { |
| 149 List<PaymentManifestVerifier> verifiers = new ArrayList<>(); | 154 List<PaymentManifestVerifier> verifiers = new ArrayList<>(); |
| 150 if (!mPaymentMethods.isEmpty()) { | 155 if (!mPaymentMethods.isEmpty()) { |
| 151 Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY); | 156 Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY); |
| 152 for (URI methodName : mPaymentMethods) { | 157 for (URI methodName : mPaymentMethods) { |
| 153 payIntent.setData(Uri.parse(methodName.toString())); | 158 payIntent.setData(Uri.parse(methodName.toString())); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (mPackageManagerDelegate.resolveActivity(mSettingsLookup) ==
null) return; | 210 if (mPackageManagerDelegate.resolveActivity(mSettingsLookup) ==
null) return; |
| 206 } | 211 } |
| 207 CharSequence label = mPackageManagerDelegate.getAppLabel(resolveInfo
); | 212 CharSequence label = mPackageManagerDelegate.getAppLabel(resolveInfo
); |
| 208 if (TextUtils.isEmpty(label)) { | 213 if (TextUtils.isEmpty(label)) { |
| 209 Log.d(TAG, | 214 Log.d(TAG, |
| 210 String.format(Locale.getDefault(), "Skipping '%s' becaus
e of empty label.", | 215 String.format(Locale.getDefault(), "Skipping '%s' becaus
e of empty label.", |
| 211 packageName)); | 216 packageName)); |
| 212 return; | 217 return; |
| 213 } | 218 } |
| 214 app = new AndroidPaymentApp(mWebContents, packageName, resolveInfo.a
ctivityInfo.name, | 219 app = new AndroidPaymentApp(mWebContents, packageName, resolveInfo.a
ctivityInfo.name, |
| 215 label.toString(), mPackageManagerDelegate.getAppIcon(resolve
Info)); | 220 label.toString(), mPackageManagerDelegate.getAppIcon(resolve
Info), |
| 221 mIsIncognito); |
| 216 mResult.put(packageName, app); | 222 mResult.put(packageName, app); |
| 217 } | 223 } |
| 218 app.addMethodName(methodName); | 224 app.addMethodName(methodName); |
| 219 } | 225 } |
| 220 | 226 |
| 221 @Override | 227 @Override |
| 222 public void onInvalidPaymentApp(URI methodName, ResolveInfo resolveInfo) { | 228 public void onInvalidPaymentApp(URI methodName, ResolveInfo resolveInfo) { |
| 223 removePendingApp(methodName, resolveInfo); | 229 removePendingApp(methodName, resolveInfo); |
| 224 } | 230 } |
| 225 | 231 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 239 | 245 |
| 240 /** | 246 /** |
| 241 * Checks for IS_READY_TO_PAY service in each valid payment app and returns
the valid apps | 247 * Checks for IS_READY_TO_PAY service in each valid payment app and returns
the valid apps |
| 242 * to the caller. Called when finished verifying all payment methods and app
s. | 248 * to the caller. Called when finished verifying all payment methods and app
s. |
| 243 */ | 249 */ |
| 244 private void onSearchFinished() { | 250 private void onSearchFinished() { |
| 245 assert mPendingApps.isEmpty(); | 251 assert mPendingApps.isEmpty(); |
| 246 | 252 |
| 247 if (mParser.isUtilityProcessRunning()) mParser.stopUtilityProcess(); | 253 if (mParser.isUtilityProcessRunning()) mParser.stopUtilityProcess(); |
| 248 | 254 |
| 249 List<ResolveInfo> resolveInfos = mPackageManagerDelegate.getServicesThat
CanRespondToIntent( | 255 if (!mIsIncognito) { |
| 250 new Intent(ACTION_IS_READY_TO_PAY)); | 256 List<ResolveInfo> resolveInfos = |
| 251 for (int i = 0; i < resolveInfos.size(); i++) { | 257 mPackageManagerDelegate.getServicesThatCanRespondToIntent( |
| 252 ResolveInfo resolveInfo = resolveInfos.get(i); | 258 new Intent(ACTION_IS_READY_TO_PAY)); |
| 253 AndroidPaymentApp app = mResult.get(resolveInfo.serviceInfo.packageN
ame); | 259 for (int i = 0; i < resolveInfos.size(); i++) { |
| 254 if (app != null) app.setIsReadyToPayAction(resolveInfo.serviceInfo.n
ame); | 260 ResolveInfo resolveInfo = resolveInfos.get(i); |
| 261 AndroidPaymentApp app = mResult.get(resolveInfo.serviceInfo.pack
ageName); |
| 262 if (app != null) app.setIsReadyToPayAction(resolveInfo.serviceIn
fo.name); |
| 263 } |
| 255 } | 264 } |
| 256 | 265 |
| 257 for (Map.Entry<String, AndroidPaymentApp> entry : mResult.entrySet()) { | 266 for (Map.Entry<String, AndroidPaymentApp> entry : mResult.entrySet()) { |
| 258 mCallback.onPaymentAppCreated(entry.getValue()); | 267 mCallback.onPaymentAppCreated(entry.getValue()); |
| 259 } | 268 } |
| 260 | 269 |
| 261 mCallback.onAllPaymentAppsCreated(); | 270 mCallback.onAllPaymentAppsCreated(); |
| 262 } | 271 } |
| 263 } | 272 } |
| OLD | NEW |