OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 org.chromium.base.VisibleForTesting; | 7 import org.chromium.base.VisibleForTesting; |
8 import org.chromium.chrome.browser.ChromeFeatureList; | 8 import org.chromium.chrome.browser.ChromeFeatureList; |
9 import org.chromium.content_public.browser.WebContents; | 9 import org.chromium.content_public.browser.WebContents; |
| 10 import org.chromium.payments.mojom.PaymentRequestClient.ParsePaymentManifestResp
onse; |
10 | 11 |
11 import java.util.ArrayList; | 12 import java.util.ArrayList; |
12 import java.util.HashSet; | 13 import java.util.HashSet; |
13 import java.util.List; | 14 import java.util.List; |
14 import java.util.Set; | 15 import java.util.Set; |
15 | 16 |
16 /** | 17 /** |
17 * Builds instances of payment apps. | 18 * Builds instances of payment apps. |
18 */ | 19 */ |
19 public class PaymentAppFactory { | 20 public class PaymentAppFactory { |
20 private static PaymentAppFactory sInstance; | 21 private static PaymentAppFactory sInstance; |
21 | 22 |
22 /** | 23 /** |
23 * Can be used to build additional types of payment apps without Chrome know
ing about their | 24 * Can be used to build additional types of payment apps without Chrome know
ing about their |
24 * types. | 25 * types. |
25 */ | 26 */ |
26 private final List<PaymentAppFactoryAddition> mAdditionalFactories; | 27 private final List<PaymentAppFactoryAddition> mAdditionalFactories; |
27 | 28 |
28 /** | 29 /** Interface for receiving newly created apps. */ |
29 * Interface for receiving newly created apps. | |
30 */ | |
31 public interface PaymentAppCreatedCallback { | 30 public interface PaymentAppCreatedCallback { |
32 /** | 31 /** |
33 * Called when the factory has create a payment app. This method may be
called | 32 * Called when the factory has create a payment app. This method may be
called |
34 * zero, one, or many times before the app creation is finished. | 33 * zero, one, or many times before the app creation is finished. |
35 */ | 34 */ |
36 void onPaymentAppCreated(PaymentApp paymentApp); | 35 void onPaymentAppCreated(PaymentApp paymentApp); |
37 | 36 |
38 /** | 37 /** Called when the factory is finished creating payment apps. */ |
39 * Called when the factory is finished creating payment apps. | |
40 */ | |
41 void onAllPaymentAppsCreated(); | 38 void onAllPaymentAppsCreated(); |
42 } | 39 } |
43 | 40 |
44 /** | 41 /** Interface for parsing payment manifest. */ |
45 * The interface for additional payment app factories. | 42 public interface PaymentManifestParser { |
46 */ | 43 /** |
| 44 * Parses the payment manifest. |
| 45 * |
| 46 * @param content The content to parse. |
| 47 * @param callback The callback to invoke with parsed data, or null on f
ailure. |
| 48 */ |
| 49 void parsePaymentManifest(String content, ParsePaymentManifestResponse c
allback); |
| 50 } |
| 51 |
| 52 /** The interface for additional payment app factories. */ |
47 public interface PaymentAppFactoryAddition { | 53 public interface PaymentAppFactoryAddition { |
48 /** | 54 /** |
49 * Builds instances of payment apps. | 55 * Builds instances of payment apps. |
50 * | 56 * |
51 * @param webContents The web contents that invoked PaymentRequest. | 57 * @param webContents The web contents that invoked PaymentRequest. |
52 * @param methods The methods that the merchant supports. | 58 * @param methods The methods that the merchant supports. |
| 59 * @param parser The payment manifest parser. |
53 * @param callback The callback to invoke when apps are created. | 60 * @param callback The callback to invoke when apps are created. |
54 */ | 61 */ |
55 void create( | 62 void create(WebContents webContents, Set<String> methods, PaymentManifes
tParser parser, |
56 WebContents webContents, Set<String> methods, PaymentAppCreatedC
allback callback); | 63 PaymentAppCreatedCallback callback); |
57 } | 64 } |
58 | 65 |
59 private PaymentAppFactory() { | 66 private PaymentAppFactory() { |
60 mAdditionalFactories = new ArrayList<>(); | 67 mAdditionalFactories = new ArrayList<>(); |
61 | 68 |
62 if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS))
{ | 69 if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS))
{ |
63 mAdditionalFactories.add(new AndroidPaymentAppFactory()); | 70 mAdditionalFactories.add(new AndroidPaymentAppFactory()); |
64 } | 71 } |
65 | 72 |
66 if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT
_APPS)) { | 73 if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT
_APPS)) { |
(...skipping 17 matching lines...) Expand all Loading... |
84 @VisibleForTesting | 91 @VisibleForTesting |
85 public void addAdditionalFactory(PaymentAppFactoryAddition additionalFactory
) { | 92 public void addAdditionalFactory(PaymentAppFactoryAddition additionalFactory
) { |
86 mAdditionalFactories.add(additionalFactory); | 93 mAdditionalFactories.add(additionalFactory); |
87 } | 94 } |
88 | 95 |
89 /** | 96 /** |
90 * Builds instances of payment apps. | 97 * Builds instances of payment apps. |
91 * | 98 * |
92 * @param webContents The web contents where PaymentRequest was invoked. | 99 * @param webContents The web contents where PaymentRequest was invoked. |
93 * @param methods The methods that the merchant supports. | 100 * @param methods The methods that the merchant supports. |
| 101 * @param parser The payment manifest parser. |
94 * @param callback The callback to invoke when apps are created. | 102 * @param callback The callback to invoke when apps are created. |
95 */ | 103 */ |
96 public void create(WebContents webContents, Set<String> methods, | 104 public void create(WebContents webContents, Set<String> methods, PaymentMani
festParser parser, |
97 final PaymentAppCreatedCallback callback) { | 105 final PaymentAppCreatedCallback callback) { |
98 callback.onPaymentAppCreated(new AutofillPaymentApp(webContents)); | 106 callback.onPaymentAppCreated(new AutofillPaymentApp(webContents)); |
99 | 107 |
100 if (mAdditionalFactories.isEmpty()) { | 108 if (mAdditionalFactories.isEmpty()) { |
101 callback.onAllPaymentAppsCreated(); | 109 callback.onAllPaymentAppsCreated(); |
102 return; | 110 return; |
103 } | 111 } |
104 | 112 |
105 final Set<PaymentAppFactoryAddition> mPendingTasks = | 113 final Set<PaymentAppFactoryAddition> mPendingTasks = |
106 new HashSet<PaymentAppFactoryAddition>(mAdditionalFactories); | 114 new HashSet<PaymentAppFactoryAddition>(mAdditionalFactories); |
107 | 115 |
108 for (int i = 0; i < mAdditionalFactories.size(); i++) { | 116 for (int i = 0; i < mAdditionalFactories.size(); i++) { |
109 final PaymentAppFactoryAddition additionalFactory = mAdditionalFacto
ries.get(i); | 117 final PaymentAppFactoryAddition additionalFactory = mAdditionalFacto
ries.get(i); |
110 PaymentAppCreatedCallback cb = new PaymentAppCreatedCallback() { | 118 PaymentAppCreatedCallback cb = new PaymentAppCreatedCallback() { |
111 @Override | 119 @Override |
112 public void onPaymentAppCreated(PaymentApp paymentApp) { | 120 public void onPaymentAppCreated(PaymentApp paymentApp) { |
113 callback.onPaymentAppCreated(paymentApp); | 121 callback.onPaymentAppCreated(paymentApp); |
114 } | 122 } |
115 | 123 |
116 @Override | 124 @Override |
117 public void onAllPaymentAppsCreated() { | 125 public void onAllPaymentAppsCreated() { |
118 mPendingTasks.remove(additionalFactory); | 126 mPendingTasks.remove(additionalFactory); |
119 if (mPendingTasks.isEmpty()) callback.onAllPaymentAppsCreate
d(); | 127 if (mPendingTasks.isEmpty()) callback.onAllPaymentAppsCreate
d(); |
120 } | 128 } |
121 }; | 129 }; |
122 additionalFactory.create(webContents, methods, cb); | 130 additionalFactory.create(webContents, methods, parser, cb); |
123 } | 131 } |
124 } | 132 } |
125 } | 133 } |
OLD | NEW |