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 android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.drawable.Drawable; | 8 import android.graphics.drawable.Drawable; |
9 | 9 |
10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
11 import org.chromium.base.annotations.SuppressFBWarnings; | 11 import org.chromium.base.annotations.SuppressFBWarnings; |
12 import org.chromium.content_public.browser.WebContents; | 12 import org.chromium.content_public.browser.WebContents; |
13 import org.chromium.payments.mojom.PaymentDetailsModifier; | |
14 import org.chromium.payments.mojom.PaymentItem; | |
13 import org.chromium.payments.mojom.PaymentMethodData; | 15 import org.chromium.payments.mojom.PaymentMethodData; |
14 | 16 |
15 import java.util.ArrayList; | 17 import java.util.ArrayList; |
16 import java.util.List; | 18 import java.util.List; |
17 import java.util.Set; | 19 import java.util.Set; |
18 | 20 |
19 /** | 21 /** |
20 * Native bridge for interacting with service worker based payment apps. | 22 * Native bridge for interacting with service worker based payment apps. |
21 */ | 23 */ |
22 // TODO(tommyt): crbug.com/669876. Remove these suppressions when we actually | 24 // TODO(tommyt): crbug.com/669876. Remove these suppressions when we actually |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 PaymentAppFactory.PaymentAppCreatedCallback callback) { | 62 PaymentAppFactory.PaymentAppCreatedCallback callback) { |
61 nativeGetAllAppManifests(webContents, callback); | 63 nativeGetAllAppManifests(webContents, callback); |
62 } | 64 } |
63 | 65 |
64 /** | 66 /** |
65 * Invoke a payment app with a given option and matching method data. | 67 * Invoke a payment app with a given option and matching method data. |
66 * | 68 * |
67 * @param webContents The web contents that invoked PaymentRequest. | 69 * @param webContents The web contents that invoked PaymentRequest. |
68 * @param registrationId The service worker registration ID of the Payment A pp. | 70 * @param registrationId The service worker registration ID of the Payment A pp. |
69 * @param optionId The ID of the PaymentOption that was selected by th e user. | 71 * @param optionId The ID of the PaymentOption that was selected by th e user. |
70 * @param methodDataSet The PaymentMethodData objects that are relevant for this payment | 72 * @param methodData The PaymentMethodData objects that are relevant for this payment |
71 * app. | 73 * app. |
please use gerrit instead
2017/01/19 16:45:04
Please align indentation of "app" with "The" above
tommyt
2017/01/20 09:33:29
Done.
| |
74 * @param total The PaymentItem that represents the total cost of t he payment. | |
75 * @param modifiers Payment method specific modifiers to the payment it ems and the total. | |
72 */ | 76 */ |
73 public static void invokePaymentApp(WebContents webContents, long registrati onId, | 77 public static void invokePaymentApp(WebContents webContents, long registrati onId, |
74 String optionId, Set<PaymentMethodData> methodDataSet) { | 78 String optionId, Set<PaymentMethodData> methodData, PaymentItem tota l, |
79 List<PaymentItem> displayItems, Set<PaymentDetailsModifier> modifier s) { | |
75 nativeInvokePaymentApp(webContents, registrationId, optionId, | 80 nativeInvokePaymentApp(webContents, registrationId, optionId, |
76 methodDataSet.toArray(new PaymentMethodData[methodDataSet.size() ])); | 81 methodData.toArray(new PaymentMethodData[0]), total, |
82 modifiers.toArray(new PaymentDetailsModifier[0])); | |
77 } | 83 } |
78 | 84 |
79 @CalledByNative | 85 @CalledByNative |
80 private static Manifest createManifest(long registrationId, String label, St ring icon) { | 86 private static Manifest createManifest(long registrationId, String label, St ring icon) { |
81 Manifest manifest = new Manifest(); | 87 Manifest manifest = new Manifest(); |
82 manifest.registrationId = registrationId; | 88 manifest.registrationId = registrationId; |
83 manifest.label = label; | 89 manifest.label = label; |
84 // TODO(tommyt): crbug.com/669876. Handle icons. | 90 // TODO(tommyt): crbug.com/669876. Handle icons. |
85 manifest.icon = null; | 91 manifest.icon = null; |
86 return manifest; | 92 return manifest; |
(...skipping 10 matching lines...) Expand all Loading... | |
97 manifest.options.add(option); | 103 manifest.options.add(option); |
98 return option; | 104 return option; |
99 } | 105 } |
100 | 106 |
101 @CalledByNative | 107 @CalledByNative |
102 private static void addEnabledMethod(Option option, String enabledMethod) { | 108 private static void addEnabledMethod(Option option, String enabledMethod) { |
103 option.enabledMethods.add(enabledMethod); | 109 option.enabledMethods.add(enabledMethod); |
104 } | 110 } |
105 | 111 |
106 @CalledByNative | 112 @CalledByNative |
113 private static String[] getSupportedMethodsFromMethodData(PaymentMethodData data) { | |
114 return data.supportedMethods; | |
115 } | |
116 | |
117 @CalledByNative | |
118 private static String getStringifiedDataFromMethodData(PaymentMethodData dat a) { | |
119 return data.stringifiedData; | |
120 } | |
121 | |
122 @CalledByNative | |
123 private static PaymentMethodData getMethodDataFromModifier(PaymentDetailsMod ifier modifier) { | |
124 return modifier.methodData; | |
125 } | |
126 | |
127 @CalledByNative | |
128 private static PaymentItem getTotalFromModifier(PaymentDetailsModifier modif ier) { | |
129 return modifier.total; | |
130 } | |
131 | |
132 @CalledByNative | |
133 private static String getLabelFromPaymentItem(PaymentItem item) { | |
134 return item.label; | |
135 } | |
136 | |
137 @CalledByNative | |
138 private static String getCurrencyFromPaymentItem(PaymentItem item) { | |
139 return item.amount.currency; | |
140 } | |
141 | |
142 @CalledByNative | |
143 private static String getValueFromPaymentItem(PaymentItem item) { | |
144 return item.amount.value; | |
145 } | |
146 | |
147 @CalledByNative | |
107 private static void onGotManifest(Manifest manifest, WebContents webContents , Object callback) { | 148 private static void onGotManifest(Manifest manifest, WebContents webContents , Object callback) { |
108 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback; | 149 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback; |
109 ((PaymentAppFactory.PaymentAppCreatedCallback) callback) | 150 ((PaymentAppFactory.PaymentAppCreatedCallback) callback) |
110 .onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents, ma nifest)); | 151 .onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents, ma nifest)); |
111 } | 152 } |
112 | 153 |
113 @CalledByNative | 154 @CalledByNative |
114 private static void onGotAllManifests(Object callback) { | 155 private static void onGotAllManifests(Object callback) { |
115 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback; | 156 assert callback instanceof PaymentAppFactory.PaymentAppCreatedCallback; |
116 ((PaymentAppFactory.PaymentAppCreatedCallback) callback).onAllPaymentApp sCreated(); | 157 ((PaymentAppFactory.PaymentAppCreatedCallback) callback).onAllPaymentApp sCreated(); |
117 } | 158 } |
118 | 159 |
119 /* | 160 /* |
120 * TODO(tommyt): crbug.com/505554. Change the |callback| parameter below to | 161 * TODO(tommyt): crbug.com/505554. Change the |callback| parameter below to |
121 * be of type PaymentAppFactory.PaymentAppCreatedCallback, once this JNI bug | 162 * be of type PaymentAppFactory.PaymentAppCreatedCallback, once this JNI bug |
122 * has been resolved. | 163 * has been resolved. |
123 */ | 164 */ |
124 private static native void nativeGetAllAppManifests(WebContents webContents, Object callback); | 165 private static native void nativeGetAllAppManifests(WebContents webContents, Object callback); |
125 | 166 |
126 private static native void nativeInvokePaymentApp(WebContents webContents, l ong registrationId, | 167 private static native void nativeInvokePaymentApp(WebContents webContents, l ong registrationId, |
127 String optionId, PaymentMethodData[] methodData); | 168 String optionId, PaymentMethodData[] methodData, PaymentItem total, |
169 PaymentDetailsModifier[] modifiers); | |
128 } | 170 } |
OLD | NEW |