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.content_public.browser.WebContents; | 7 import org.chromium.content_public.browser.WebContents; |
8 import org.chromium.payments.mojom.PaymentDetailsModifier; | 8 import org.chromium.payments.mojom.PaymentDetailsModifier; |
9 import org.chromium.payments.mojom.PaymentItem; | 9 import org.chromium.payments.mojom.PaymentItem; |
10 import org.chromium.payments.mojom.PaymentMethodData; | 10 import org.chromium.payments.mojom.PaymentMethodData; |
11 | 11 |
12 import java.util.Collections; | 12 import java.util.Collections; |
13 import java.util.HashSet; | 13 import java.util.HashSet; |
14 import java.util.List; | 14 import java.util.List; |
15 import java.util.Map; | 15 import java.util.Map; |
16 import java.util.Set; | 16 import java.util.Set; |
17 | 17 |
18 /** | 18 /** |
19 * This instrument class represents a single payment option for a service | 19 * This instrument class represents a single payment option for a service |
20 * worker based payment app. | 20 * worker based payment app. |
21 * | 21 * |
22 * @see org.chromium.chrome.browser.payments.ServiceWorkerPaymentApp | 22 * @see org.chromium.chrome.browser.payments.ServiceWorkerPaymentApp |
23 * | 23 * |
24 * @see https://w3c.github.io/webpayments-payment-apps-api/ | 24 * @see https://w3c.github.io/webpayments-payment-apps-api/ |
25 */ | 25 */ |
26 public class ServiceWorkerPaymentInstrument extends PaymentInstrument { | 26 public class ServiceWorkerPaymentInstrument extends PaymentInstrument { |
27 private final WebContents mWebContents; | 27 private final WebContents mWebContents; |
28 private final long mAppRegistrationId; | 28 private final long mSWRegistrationId; |
29 private final ServiceWorkerPaymentAppBridge.Option mOption; | 29 private final String mInstrumentId; |
30 private final Set<String> mMethodNames; | 30 private final Set<String> mMethodNames; |
31 | 31 |
32 /** | 32 /** |
33 * Build a service worker based payment instrument based on a single payment
option | 33 * Build a service worker based payment instrument based on a single payment
option |
34 * of an installed payment app. | 34 * of an installed payment app. |
35 * | 35 * |
36 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-opti
ons | 36 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-opti
ons |
37 * | 37 * |
38 * @param webContents The web contents where PaymentRequest was invoke
d. | 38 * @param webContents The web contents where PaymentRequest was invoke
d. |
39 * @param appRegistrationId The registration id of the corresponding service
worker payment app. | 39 * @param appRegistrationId The registration id of the corresponding service
worker payment app. |
40 * @param option A payment app option from the payment app. | 40 * @param option A payment app option from the payment app. |
41 */ | 41 */ |
42 public ServiceWorkerPaymentInstrument(WebContents webContents, long appRegis
trationId, | 42 public ServiceWorkerPaymentInstrument(WebContents webContents, long swRegist
rationId, |
43 ServiceWorkerPaymentAppBridge.Option option) { | 43 String instrumentId, String label, Set<String> methodNames) { |
44 super(Long.toString(appRegistrationId) + "#" + option.id, option.label,
null /* icon */, | 44 super(Long.toString(swRegistrationId) + "#" + instrumentId, label, null
/* sublabel */, |
45 option.icon); | 45 null /* icon */); |
46 mWebContents = webContents; | 46 mWebContents = webContents; |
47 mAppRegistrationId = appRegistrationId; | 47 mSWRegistrationId = swRegistrationId; |
48 mOption = option; | 48 mInstrumentId = instrumentId; |
49 | 49 mMethodNames = methodNames; |
50 mMethodNames = new HashSet<String>(option.enabledMethods); | |
51 } | 50 } |
52 | 51 |
53 @Override | 52 @Override |
54 public Set<String> getInstrumentMethodNames() { | 53 public Set<String> getInstrumentMethodNames() { |
55 return Collections.unmodifiableSet(mMethodNames); | 54 return Collections.unmodifiableSet(mMethodNames); |
56 } | 55 } |
57 | 56 |
58 @Override | 57 @Override |
59 public void invokePaymentApp(String id, String merchantName, String origin,
String iframeOrigin, | 58 public void invokePaymentApp(String id, String merchantName, String origin,
String iframeOrigin, |
60 byte[][] unusedCertificateChain, Map<String, PaymentMethodData> meth
odData, | 59 byte[][] unusedCertificateChain, Map<String, PaymentMethodData> meth
odData, |
61 PaymentItem total, List<PaymentItem> displayItems, | 60 PaymentItem total, List<PaymentItem> displayItems, |
62 Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCall
back callback) { | 61 Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCall
back callback) { |
63 ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mAppRegistr
ationId, mOption.id, | 62 ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mSWRegistra
tionId, |
64 origin, iframeOrigin, new HashSet<>(methodData.values()), total,
displayItems, | 63 mInstrumentId, origin, iframeOrigin, new HashSet<>(methodData.va
lues()), total, |
65 new HashSet<>(modifiers.values()), callback); | 64 displayItems, new HashSet<>(modifiers.values()), callback); |
66 } | 65 } |
67 | 66 |
68 @Override | 67 @Override |
69 public void dismissInstrument() {} | 68 public void dismissInstrument() {} |
70 } | 69 } |
OLD | NEW |