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.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
10 import android.content.pm.ResolveInfo; | 10 import android.content.pm.ResolveInfo; |
11 import android.net.Uri; | 11 import android.net.Uri; |
12 | 12 |
13 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedC
allback; | 13 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedC
allback; |
14 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryA
ddition; | 14 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryA
ddition; |
15 import org.chromium.content_public.browser.WebContents; | 15 import org.chromium.content_public.browser.WebContents; |
16 | 16 |
17 import java.util.HashMap; | 17 import java.util.HashMap; |
18 import java.util.List; | 18 import java.util.List; |
19 import java.util.Map; | 19 import java.util.Map; |
20 import java.util.Set; | 20 import java.util.Set; |
21 | 21 |
22 /** Builds instances of payment apps based on installed third party Android paym
ent apps. */ | 22 /** Builds instances of payment apps based on installed third party Android paym
ent apps. */ |
23 public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition { | 23 public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition { |
24 private static final String ACTION_PAY = "org.chromium.intent.action.PAY"; | |
25 private static final String ACTION_IS_READY_TO_PAY = | 24 private static final String ACTION_IS_READY_TO_PAY = |
26 "org.chromium.intent.action.IS_READY_TO_PAY"; | 25 "org.chromium.intent.action.IS_READY_TO_PAY"; |
27 private static final String METHOD_PREFIX = "https://"; | 26 private static final String METHOD_PREFIX = "https://"; |
28 | 27 |
29 @Override | 28 @Override |
30 public void create(Context context, WebContents webContents, Set<String> met
hods, | 29 public void create(Context context, WebContents webContents, Set<String> met
hods, |
31 PaymentAppCreatedCallback callback) { | 30 PaymentAppCreatedCallback callback) { |
32 Map<String, AndroidPaymentApp> installedApps = new HashMap<>(); | 31 Map<String, AndroidPaymentApp> installedApps = new HashMap<>(); |
33 PackageManager pm = context.getPackageManager(); | 32 PackageManager pm = context.getPackageManager(); |
34 Intent payIntent = new Intent(ACTION_PAY); | 33 Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY); |
35 | 34 |
36 for (String methodName : methods) { | 35 for (String methodName : methods) { |
37 if (!methodName.startsWith(METHOD_PREFIX)) continue; | 36 if (!methodName.startsWith(METHOD_PREFIX)) continue; |
38 | 37 |
39 payIntent.setData(Uri.parse(methodName)); | 38 payIntent.setData(Uri.parse(methodName)); |
40 List<ResolveInfo> matches = pm.queryIntentActivities(payIntent, 0); | 39 List<ResolveInfo> matches = pm.queryIntentActivities(payIntent, 0); |
41 for (int i = 0; i < matches.size(); i++) { | 40 for (int i = 0; i < matches.size(); i++) { |
42 ResolveInfo match = matches.get(i); | 41 ResolveInfo match = matches.get(i); |
43 String packageName = match.activityInfo.packageName; | 42 String packageName = match.activityInfo.packageName; |
44 AndroidPaymentApp installedApp = installedApps.get(packageName); | 43 AndroidPaymentApp installedApp = installedApps.get(packageName); |
(...skipping 14 matching lines...) Expand all Loading... |
59 for (int i = 0; i < matches.size(); i++) { | 58 for (int i = 0; i < matches.size(); i++) { |
60 ResolveInfo match = matches.get(i); | 59 ResolveInfo match = matches.get(i); |
61 String packageName = match.serviceInfo.packageName; | 60 String packageName = match.serviceInfo.packageName; |
62 AndroidPaymentApp installedApp = installedApps.get(packageName); | 61 AndroidPaymentApp installedApp = installedApps.get(packageName); |
63 if (installedApp != null) installedApp.setIsReadyToPayService(match.
serviceInfo.name); | 62 if (installedApp != null) installedApp.setIsReadyToPayService(match.
serviceInfo.name); |
64 } | 63 } |
65 | 64 |
66 callback.onAllPaymentAppsCreated(); | 65 callback.onAllPaymentAppsCreated(); |
67 } | 66 } |
68 } | 67 } |
OLD | NEW |