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.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.content.ServiceConnection; | 11 import android.content.ServiceConnection; |
12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
13 import android.os.Bundle; | 13 import android.os.Bundle; |
14 import android.os.Handler; | 14 import android.os.Handler; |
15 import android.os.IBinder; | 15 import android.os.IBinder; |
16 import android.os.RemoteException; | 16 import android.os.RemoteException; |
17 import android.util.JsonWriter; | 17 import android.util.JsonWriter; |
18 | 18 |
19 import org.chromium.IsReadyToPayService; | 19 import org.chromium.IsReadyToPayService; |
20 import org.chromium.IsReadyToPayServiceCallback; | 20 import org.chromium.IsReadyToPayServiceCallback; |
21 import org.chromium.chrome.R; | 21 import org.chromium.chrome.R; |
22 import org.chromium.content.browser.ContentViewCore; | 22 import org.chromium.content.browser.ContentViewCore; |
23 import org.chromium.content_public.browser.WebContents; | 23 import org.chromium.content_public.browser.WebContents; |
| 24 import org.chromium.payments.mojom.PaymentDetailsModifier; |
24 import org.chromium.payments.mojom.PaymentItem; | 25 import org.chromium.payments.mojom.PaymentItem; |
25 import org.chromium.payments.mojom.PaymentMethodData; | 26 import org.chromium.payments.mojom.PaymentMethodData; |
26 import org.chromium.ui.base.WindowAndroid; | 27 import org.chromium.ui.base.WindowAndroid; |
27 | 28 |
28 import java.io.IOException; | 29 import java.io.IOException; |
29 import java.io.StringWriter; | 30 import java.io.StringWriter; |
30 import java.util.ArrayList; | 31 import java.util.ArrayList; |
31 import java.util.Collections; | 32 import java.util.Collections; |
32 import java.util.HashSet; | 33 import java.util.HashSet; |
33 import java.util.List; | 34 import java.util.List; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 public Set<String> getAppMethodNames() { | 195 public Set<String> getAppMethodNames() { |
195 return Collections.unmodifiableSet(mMethodNames); | 196 return Collections.unmodifiableSet(mMethodNames); |
196 } | 197 } |
197 | 198 |
198 @Override | 199 @Override |
199 public Set<String> getInstrumentMethodNames() { | 200 public Set<String> getInstrumentMethodNames() { |
200 return getAppMethodNames(); | 201 return getAppMethodNames(); |
201 } | 202 } |
202 | 203 |
203 @Override | 204 @Override |
204 public void invokePaymentApp(String merchantName, String origin, PaymentItem
total, | 205 public void invokePaymentApp(String merchantName, String origin, |
205 List<PaymentItem> cart, Map<String, PaymentMethodData> methodDataMap
, | 206 Map<String, PaymentMethodData> methodDataMap, PaymentItem total, |
| 207 List<PaymentItem> displayItems, Map<String, PaymentDetailsModifier>
modifiers, |
206 InstrumentDetailsCallback callback) { | 208 InstrumentDetailsCallback callback) { |
207 assert !mMethodNames.isEmpty(); | 209 assert !mMethodNames.isEmpty(); |
208 Bundle extras = new Bundle(); | 210 Bundle extras = new Bundle(); |
209 extras.putString(EXTRA_ORIGIN, origin); | 211 extras.putString(EXTRA_ORIGIN, origin); |
210 | 212 |
211 String methodName = mMethodNames.iterator().next(); | 213 String methodName = mMethodNames.iterator().next(); |
212 extras.putString(EXTRA_METHOD_NAME, methodName); | 214 extras.putString(EXTRA_METHOD_NAME, methodName); |
213 | 215 |
214 PaymentMethodData methodData = methodDataMap.get(methodName); | 216 PaymentMethodData methodData = methodDataMap.get(methodName); |
215 extras.putString( | 217 extras.putString( |
216 EXTRA_DATA, methodData == null ? EMPTY_JSON_DATA : methodData.st
ringifiedData); | 218 EXTRA_DATA, methodData == null ? EMPTY_JSON_DATA : methodData.st
ringifiedData); |
217 | 219 |
218 String details = serializeDetails(total, cart); | 220 String details = serializeDetails(total, displayItems); |
219 extras.putString(EXTRA_DETAILS, details == null ? EMPTY_JSON_DATA : deta
ils); | 221 extras.putString(EXTRA_DETAILS, details == null ? EMPTY_JSON_DATA : deta
ils); |
220 mPayIntent.putExtras(extras); | 222 mPayIntent.putExtras(extras); |
221 | 223 |
222 mInstrumentDetailsCallback = callback; | 224 mInstrumentDetailsCallback = callback; |
223 | 225 |
224 ContentViewCore contentView = ContentViewCore.fromWebContents(mWebConten
ts); | 226 ContentViewCore contentView = ContentViewCore.fromWebContents(mWebConten
ts); |
225 if (contentView == null) { | 227 if (contentView == null) { |
226 notifyError(); | 228 notifyError(); |
227 return; | 229 return; |
228 } | 230 } |
(...skipping 11 matching lines...) Expand all Loading... |
240 | 242 |
241 private void notifyError() { | 243 private void notifyError() { |
242 mHandler.post(new Runnable() { | 244 mHandler.post(new Runnable() { |
243 @Override | 245 @Override |
244 public void run() { | 246 public void run() { |
245 mInstrumentDetailsCallback.onInstrumentDetailsError(); | 247 mInstrumentDetailsCallback.onInstrumentDetailsError(); |
246 } | 248 } |
247 }); | 249 }); |
248 } | 250 } |
249 | 251 |
250 private static String serializeDetails(PaymentItem total, List<PaymentItem>
cart) { | 252 private static String serializeDetails(PaymentItem total, List<PaymentItem>
displayItems) { |
251 StringWriter stringWriter = new StringWriter(); | 253 StringWriter stringWriter = new StringWriter(); |
252 JsonWriter json = new JsonWriter(stringWriter); | 254 JsonWriter json = new JsonWriter(stringWriter); |
253 try { | 255 try { |
254 // details {{{ | 256 // details {{{ |
255 json.beginObject(); | 257 json.beginObject(); |
256 | 258 |
257 // total {{{ | 259 // total {{{ |
258 json.name("total"); | 260 json.name("total"); |
259 serializePaymentItem(json, total); | 261 serializePaymentItem(json, total); |
260 // }}} total | 262 // }}} total |
261 | 263 |
262 // displayitems {{{ | 264 // displayitems {{{ |
263 if (cart != null) { | 265 if (displayItems != null) { |
264 json.name("displayItems").beginArray(); | 266 json.name("displayItems").beginArray(); |
265 for (int i = 0; i < cart.size(); i++) { | 267 for (int i = 0; i < displayItems.size(); i++) { |
266 serializePaymentItem(json, cart.get(i)); | 268 serializePaymentItem(json, displayItems.get(i)); |
267 } | 269 } |
268 json.endArray(); | 270 json.endArray(); |
269 } | 271 } |
270 // }}} displayItems | 272 // }}} displayItems |
271 | 273 |
272 json.endObject(); | 274 json.endObject(); |
273 // }}} details | 275 // }}} details |
274 } catch (IOException e) { | 276 } catch (IOException e) { |
275 return null; | 277 return null; |
276 } | 278 } |
(...skipping 26 matching lines...) Expand all Loading... |
303 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 305 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
304 data.getExtras().getString(EXTRA_METHOD_NAME), | 306 data.getExtras().getString(EXTRA_METHOD_NAME), |
305 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); | 307 data.getExtras().getString(EXTRA_INSTRUMENT_DETAILS)); |
306 } | 308 } |
307 mInstrumentDetailsCallback = null; | 309 mInstrumentDetailsCallback = null; |
308 } | 310 } |
309 | 311 |
310 @Override | 312 @Override |
311 public void dismissInstrument() {} | 313 public void dismissInstrument() {} |
312 } | 314 } |
OLD | NEW |