Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ServiceWorkerPaymentAppBridge.java

Issue 2867273003: PaymentHandler: Replace GetAllManifests() with GetAllPaymentApps(). (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 android.graphics.drawable.Drawable;
8
9 import org.chromium.base.annotations.CalledByNative; 7 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.base.annotations.SuppressFBWarnings; 8 import org.chromium.base.annotations.SuppressFBWarnings;
11 import org.chromium.content_public.browser.WebContents; 9 import org.chromium.content_public.browser.WebContents;
12 import org.chromium.payments.mojom.PaymentDetailsModifier; 10 import org.chromium.payments.mojom.PaymentDetailsModifier;
13 import org.chromium.payments.mojom.PaymentItem; 11 import org.chromium.payments.mojom.PaymentItem;
14 import org.chromium.payments.mojom.PaymentMethodData; 12 import org.chromium.payments.mojom.PaymentMethodData;
15 13
16 import java.util.ArrayList; 14 import java.util.ArrayList;
15 import java.util.Arrays;
16 import java.util.HashSet;
17 import java.util.List; 17 import java.util.List;
18 import java.util.Set; 18 import java.util.Set;
19 19
20 /** 20 /**
21 * Native bridge for interacting with service worker based payment apps. 21 * Native bridge for interacting with service worker based payment apps.
22 */ 22 */
23 // TODO(tommyt): crbug.com/669876. Remove these suppressions when we actually 23 // TODO(tommyt): crbug.com/669876. Remove these suppressions when we actually
24 // start using all of the functionality in this class. 24 // start using all of the functionality in this class.
25 @SuppressFBWarnings({"UWF_NULL_FIELD", "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", 25 @SuppressFBWarnings({"UWF_NULL_FIELD", "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD",
26 "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UUF_UNUSED_PUBLIC_OR_PROTECT ED_FIELD"}) 26 "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UUF_UNUSED_PUBLIC_OR_PROTECT ED_FIELD"})
27 public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ppFactoryAddition { 27 public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ppFactoryAddition {
28 /** 28 @Override
29 * This class represents a payment app manifest as defined in the Payment 29 public void create(WebContents webContents, Set<String> methodNames,
30 * App API specification. 30 PaymentAppFactory.PaymentAppCreatedCallback callback) {
31 * 31 nativeGetAllPaymentApps(webContents, callback);
32 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-mani fest
33 */
34 public static class Manifest {
35 /**
36 * The registration ID of the service worker.
37 *
38 * This can be used to identify a service worker based payment app.
39 */
40 public long registrationId;
41 public String label;
42 public Drawable icon;
43 public List<Option> options = new ArrayList<>();
44 } 32 }
45 33
46 /** 34 /**
47 * This class represents a payment option as defined in the Payment App API
48 * specification.
49 *
50 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-opti ons
51 */
52 public static class Option {
53 public String id;
54 public String label;
55 public Drawable icon;
56 public List<String> enabledMethods = new ArrayList<>();
57 }
58
59 @Override
60 public void create(WebContents webContents, Set<String> methodNames,
61 PaymentAppFactory.PaymentAppCreatedCallback callback) {
62 nativeGetAllAppManifests(webContents, callback);
63 }
64
65 /**
66 * Invoke a payment app with a given option and matching method data. 35 * Invoke a payment app with a given option and matching method data.
67 * 36 *
68 * @param webContents The web contents that invoked PaymentRequest. 37 * @param webContents The web contents that invoked PaymentRequest.
69 * @param registrationId The service worker registration ID of the Payment A pp. 38 * @param registrationId The service worker registration ID of the Payment A pp.
70 * @param optionId The ID of the PaymentOption that was selected by th e user. 39 * @param optionId The ID of the PaymentOption that was selected by th e user.
71 * @param methodData The PaymentMethodData objects that are relevant for this payment 40 * @param methodData The PaymentMethodData objects that are relevant for this payment
72 * app. 41 * app.
73 * @param total The PaymentItem that represents the total cost of t he payment. 42 * @param total The PaymentItem that represents the total cost of t he payment.
74 * @param modifiers Payment method specific modifiers to the payment it ems and the total. 43 * @param modifiers Payment method specific modifiers to the payment it ems and the total.
75 * @param callback Called after the payment app is finished running. 44 * @param callback Called after the payment app is finished running.
76 */ 45 */
77 public static void invokePaymentApp(WebContents webContents, long registrati onId, 46 public static void invokePaymentApp(WebContents webContents, long registrati onId,
78 String optionId, String origin, String unusedIframeOrigin, 47 String optionId, String origin, String unusedIframeOrigin,
79 Set<PaymentMethodData> methodData, PaymentItem total, List<PaymentIt em> displayItems, 48 Set<PaymentMethodData> methodData, PaymentItem total, List<PaymentIt em> displayItems,
80 Set<PaymentDetailsModifier> modifiers, 49 Set<PaymentDetailsModifier> modifiers,
81 PaymentInstrument.InstrumentDetailsCallback callback) { 50 PaymentInstrument.InstrumentDetailsCallback callback) {
82 nativeInvokePaymentApp(webContents, registrationId, optionId, origin, 51 nativeInvokePaymentApp(webContents, registrationId, optionId, origin,
83 methodData.toArray(new PaymentMethodData[0]), total, 52 methodData.toArray(new PaymentMethodData[0]), total,
84 modifiers.toArray(new PaymentDetailsModifier[0]), callback); 53 modifiers.toArray(new PaymentDetailsModifier[0]), callback);
85 } 54 }
86 55
87 @CalledByNative 56 @CalledByNative
88 private static Manifest createManifest(long registrationId, String label, St ring icon) { 57 private static List<PaymentInstrument> createInstrumentList() {
89 Manifest manifest = new Manifest(); 58 return new ArrayList<PaymentInstrument>();
90 manifest.registrationId = registrationId;
91 manifest.label = label;
92 // TODO(tommyt): crbug.com/669876. Handle icons.
93 manifest.icon = null;
94 return manifest;
95 } 59 }
96 60
97 @CalledByNative 61 @CalledByNative
98 private static Option createAndAddOption( 62 private static void addInstrument(List<PaymentInstrument> instruments, WebCo ntents webContents,
99 Manifest manifest, String id, String label, String icon) { 63 long swRegistrationId, String instrumentId, String label, String[] m ethodNames) {
100 Option option = new Option(); 64 instruments.add(new ServiceWorkerPaymentInstrument(webContents, swRegist rationId,
101 option.id = id; 65 instrumentId, label, new HashSet<String>(Arrays.asList(methodNam es))));
please use gerrit instead 2017/05/09 18:54:36 Instead of creating an intermediate List and then
zino 2017/05/10 18:28:39 Done.
102 option.label = label;
103 // TODO(tommyt): crbug.com/669876. Handle icons.
104 option.icon = null;
105 manifest.options.add(option);
106 return option;
107 } 66 }
108 67
109 @CalledByNative 68 @CalledByNative
110 private static void addEnabledMethod(Option option, String enabledMethod) {
111 option.enabledMethods.add(enabledMethod);
112 }
113
114 @CalledByNative
115 private static String[] getSupportedMethodsFromMethodData(PaymentMethodData data) { 69 private static String[] getSupportedMethodsFromMethodData(PaymentMethodData data) {
116 return data.supportedMethods; 70 return data.supportedMethods;
117 } 71 }
118 72
119 @CalledByNative 73 @CalledByNative
120 private static String getStringifiedDataFromMethodData(PaymentMethodData dat a) { 74 private static String getStringifiedDataFromMethodData(PaymentMethodData dat a) {
121 return data.stringifiedData; 75 return data.stringifiedData;
122 } 76 }
123 77
124 @CalledByNative 78 @CalledByNative
(...skipping 15 matching lines...) Expand all
140 private static String getCurrencyFromPaymentItem(PaymentItem item) { 94 private static String getCurrencyFromPaymentItem(PaymentItem item) {
141 return item.amount.currency; 95 return item.amount.currency;
142 } 96 }
143 97
144 @CalledByNative 98 @CalledByNative
145 private static String getValueFromPaymentItem(PaymentItem item) { 99 private static String getValueFromPaymentItem(PaymentItem item) {
146 return item.amount.value; 100 return item.amount.value;
147 } 101 }
148 102
149 @CalledByNative 103 @CalledByNative
150 private static void onGotManifest(Manifest manifest, WebContents webContents , Object callback) { 104 private static void onPaymentAppCreated(
105 List<PaymentInstrument> instruments, WebContents webContents, Object callback) {
151 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback; 106 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback;
152 ((PaymentAppFactory.PaymentAppCreatedCallback) callback) 107 ((PaymentAppFactory.PaymentAppCreatedCallback) callback)
153 .onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents, ma nifest)); 108 .onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents, in struments));
154 } 109 }
155 110
156 @CalledByNative 111 @CalledByNative
157 private static void onGotAllManifests(Object callback) { 112 private static void onAllPaymentAppsCreated(Object callback) {
158 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback; 113 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback;
159 ((PaymentAppFactory.PaymentAppCreatedCallback) callback).onAllPaymentApp sCreated(); 114 ((PaymentAppFactory.PaymentAppCreatedCallback) callback).onAllPaymentApp sCreated();
160 } 115 }
161 116
162 @CalledByNative 117 @CalledByNative
163 private static void onPaymentAppInvoked( 118 private static void onPaymentAppInvoked(
164 Object callback, String methodName, String stringifiedDetails) { 119 Object callback, String methodName, String stringifiedDetails) {
165 assert callback instanceof PaymentInstrument.InstrumentDetailsCallback; 120 assert callback instanceof PaymentInstrument.InstrumentDetailsCallback;
166 if (methodName == null) { 121 if (methodName == null) {
167 ((PaymentInstrument.InstrumentDetailsCallback) callback).onInstrumen tDetailsError(); 122 ((PaymentInstrument.InstrumentDetailsCallback) callback).onInstrumen tDetailsError();
168 } else { 123 } else {
169 ((PaymentInstrument.InstrumentDetailsCallback) callback) 124 ((PaymentInstrument.InstrumentDetailsCallback) callback)
170 .onInstrumentDetailsReady(methodName, stringifiedDetails); 125 .onInstrumentDetailsReady(methodName, stringifiedDetails);
171 } 126 }
172 } 127 }
173 128
174 /* 129 /*
175 * TODO(tommyt): crbug.com/505554. Change the |callback| parameter below to 130 * TODO(tommyt): crbug.com/505554. Change the |callback| parameter below to
176 * be of type PaymentAppFactory.PaymentAppCreatedCallback, once this JNI bug 131 * be of type PaymentInstrument.InstrumentDetailsCallback, once this JNI bug
177 * has been resolved. 132 * has been resolved.
178 */ 133 */
179 private static native void nativeGetAllAppManifests(WebContents webContents, Object callback); 134 private static native void nativeGetAllPaymentApps(WebContents webContents, Object callback);
180 135
181 /* 136 /*
182 * TODO(tommyt): crbug.com/505554. Change the |callback| parameter below to 137 * TODO(tommyt): crbug.com/505554. Change the |callback| parameter below to
183 * be of type PaymentInstrument.InstrumentDetailsCallback, once this JNI bug 138 * be of type PaymentInstrument.InstrumentDetailsCallback, once this JNI bug
184 * has been resolved. 139 * has been resolved.
185 */ 140 */
186 private static native void nativeInvokePaymentApp(WebContents webContents, l ong registrationId, 141 private static native void nativeInvokePaymentApp(WebContents webContents, l ong registrationId,
187 String optionId, String origin, PaymentMethodData[] methodData, Paym entItem total, 142 String optionId, String origin, PaymentMethodData[] methodData, Paym entItem total,
188 PaymentDetailsModifier[] modifiers, Object callback); 143 PaymentDetailsModifier[] modifiers, Object callback);
189 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698