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.DialogInterface; | 10 import android.content.DialogInterface; |
(...skipping 19 matching lines...) Expand all Loading... | |
30 import org.chromium.content_public.browser.WebContents; | 30 import org.chromium.content_public.browser.WebContents; |
31 import org.chromium.payments.mojom.PaymentCurrencyAmount; | 31 import org.chromium.payments.mojom.PaymentCurrencyAmount; |
32 import org.chromium.payments.mojom.PaymentDetailsModifier; | 32 import org.chromium.payments.mojom.PaymentDetailsModifier; |
33 import org.chromium.payments.mojom.PaymentItem; | 33 import org.chromium.payments.mojom.PaymentItem; |
34 import org.chromium.payments.mojom.PaymentMethodData; | 34 import org.chromium.payments.mojom.PaymentMethodData; |
35 import org.chromium.ui.base.WindowAndroid; | 35 import org.chromium.ui.base.WindowAndroid; |
36 | 36 |
37 import java.io.IOException; | 37 import java.io.IOException; |
38 import java.io.StringWriter; | 38 import java.io.StringWriter; |
39 import java.util.ArrayList; | 39 import java.util.ArrayList; |
40 import java.util.Collection; | |
40 import java.util.Collections; | 41 import java.util.Collections; |
41 import java.util.HashSet; | 42 import java.util.HashSet; |
42 import java.util.List; | 43 import java.util.List; |
43 import java.util.Map; | 44 import java.util.Map; |
44 import java.util.Set; | 45 import java.util.Set; |
45 | 46 |
46 import javax.annotation.Nullable; | 47 import javax.annotation.Nullable; |
47 | 48 |
48 /** | 49 /** |
49 * The point of interaction with a locally installed 3rd party native Android pa yment app. | 50 * The point of interaction with a locally installed 3rd party native Android pa yment app. |
(...skipping 18 matching lines...) Expand all Loading... | |
68 private static final String EXTRA_DEPRECATED_ID = "id"; | 69 private static final String EXTRA_DEPRECATED_ID = "id"; |
69 private static final String EXTRA_DEPRECATED_IFRAME_ORIGIN = "iframeOrigin"; | 70 private static final String EXTRA_DEPRECATED_IFRAME_ORIGIN = "iframeOrigin"; |
70 private static final String EXTRA_DEPRECATED_METHOD_NAME = "methodName"; | 71 private static final String EXTRA_DEPRECATED_METHOD_NAME = "methodName"; |
71 private static final String EXTRA_DEPRECATED_ORIGIN = "origin"; | 72 private static final String EXTRA_DEPRECATED_ORIGIN = "origin"; |
72 | 73 |
73 // Freshest parameters sent to the payment app. | 74 // Freshest parameters sent to the payment app. |
74 private static final String EXTRA_CERTIFICATE = "certificate"; | 75 private static final String EXTRA_CERTIFICATE = "certificate"; |
75 private static final String EXTRA_MERCHANT_NAME = "merchantName"; | 76 private static final String EXTRA_MERCHANT_NAME = "merchantName"; |
76 private static final String EXTRA_METHOD_DATA = "methodData"; | 77 private static final String EXTRA_METHOD_DATA = "methodData"; |
77 private static final String EXTRA_METHOD_NAMES = "methodNames"; | 78 private static final String EXTRA_METHOD_NAMES = "methodNames"; |
79 private static final String EXTRA_MODIFIERS = "modifiers"; | |
78 private static final String EXTRA_PAYMENT_REQUEST_ID = "paymentRequestId"; | 80 private static final String EXTRA_PAYMENT_REQUEST_ID = "paymentRequestId"; |
79 private static final String EXTRA_PAYMENT_REQUEST_ORIGIN = "paymentRequestOr igin"; | 81 private static final String EXTRA_PAYMENT_REQUEST_ORIGIN = "paymentRequestOr igin"; |
80 private static final String EXTRA_TOP_LEVEL_CERTIFICATE_CHAIN = "topLevelCer tificateChain"; | 82 private static final String EXTRA_TOP_LEVEL_CERTIFICATE_CHAIN = "topLevelCer tificateChain"; |
81 private static final String EXTRA_TOP_LEVEL_ORIGIN = "topLevelOrigin"; | 83 private static final String EXTRA_TOP_LEVEL_ORIGIN = "topLevelOrigin"; |
82 private static final String EXTRA_TOTAL = "total"; | 84 private static final String EXTRA_TOTAL = "total"; |
83 | 85 |
84 // Response from the payment app. | 86 // Response from the payment app. |
85 private static final String EXTRA_DEPRECATED_RESPONSE_INSTRUMENT_DETAILS = " instrumentDetails"; | 87 private static final String EXTRA_DEPRECATED_RESPONSE_INSTRUMENT_DETAILS = " instrumentDetails"; |
86 private static final String EXTRA_RESPONSE_DETAILS = "details"; | 88 private static final String EXTRA_RESPONSE_DETAILS = "details"; |
87 private static final String EXTRA_RESPONSE_METHOD_NAME = "methodName"; | 89 private static final String EXTRA_RESPONSE_METHOD_NAME = "methodName"; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 extras.putStringArrayList(EXTRA_METHOD_NAMES, new ArrayList<>(methodData Map.keySet())); | 364 extras.putStringArrayList(EXTRA_METHOD_NAMES, new ArrayList<>(methodData Map.keySet())); |
363 | 365 |
364 Bundle methodDataBundle = new Bundle(); | 366 Bundle methodDataBundle = new Bundle(); |
365 for (Map.Entry<String, PaymentMethodData> methodData : methodDataMap.ent rySet()) { | 367 for (Map.Entry<String, PaymentMethodData> methodData : methodDataMap.ent rySet()) { |
366 methodDataBundle.putString(methodData.getKey(), | 368 methodDataBundle.putString(methodData.getKey(), |
367 methodData.getValue() == null ? EMPTY_JSON_DATA | 369 methodData.getValue() == null ? EMPTY_JSON_DATA |
368 : methodData.getValue().string ifiedData); | 370 : methodData.getValue().string ifiedData); |
369 } | 371 } |
370 extras.putParcelable(EXTRA_METHOD_DATA, methodDataBundle); | 372 extras.putParcelable(EXTRA_METHOD_DATA, methodDataBundle); |
371 | 373 |
374 if (modifiers != null) { | |
375 extras.putString(EXTRA_MODIFIERS, serializeModifiers(modifiers.value s())); | |
376 } | |
377 | |
372 String serializedTotalAmount = serializeTotalAmount(total.amount); | 378 String serializedTotalAmount = serializeTotalAmount(total.amount); |
373 extras.putString(EXTRA_TOTAL, | 379 extras.putString(EXTRA_TOTAL, |
374 serializedTotalAmount == null ? EMPTY_JSON_DATA : serializedTota lAmount); | 380 serializedTotalAmount == null ? EMPTY_JSON_DATA : serializedTota lAmount); |
375 | 381 |
376 return addDeprecatedExtras(id, origin, iframeOrigin, serializedCertifica teChain, | 382 return addDeprecatedExtras(id, origin, iframeOrigin, serializedCertifica teChain, |
377 methodDataMap, methodDataBundle, total, displayItems, extras); | 383 methodDataMap, methodDataBundle, total, displayItems, extras); |
378 } | 384 } |
379 | 385 |
380 private static Bundle addDeprecatedExtras(@Nullable String id, String origin , | 386 private static Bundle addDeprecatedExtras(@Nullable String id, String origin , |
381 String iframeOrigin, @Nullable Parcelable[] serializedCertificateCha in, | 387 String iframeOrigin, @Nullable Parcelable[] serializedCertificateCha in, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 json.name("amount").beginObject(); | 489 json.name("amount").beginObject(); |
484 json.name("currency").value(item.amount.currency); | 490 json.name("currency").value(item.amount.currency); |
485 json.name("value").value(item.amount.value); | 491 json.name("value").value(item.amount.value); |
486 json.endObject(); | 492 json.endObject(); |
487 // }}} amount | 493 // }}} amount |
488 | 494 |
489 json.endObject(); | 495 json.endObject(); |
490 // }}} item | 496 // }}} item |
491 } | 497 } |
492 | 498 |
499 private static String serializeModifiers(Collection<PaymentDetailsModifier> modifiers) { | |
500 StringWriter stringWriter = new StringWriter(); | |
501 JsonWriter json = new JsonWriter(stringWriter); | |
502 try { | |
503 json.beginArray(); | |
504 for (PaymentDetailsModifier modifier : modifiers) { | |
505 serializeModifier(modifier, json); | |
506 } | |
507 json.endArray(); | |
508 } catch (IOException e) { | |
509 return EMPTY_JSON_DATA; | |
510 } | |
511 return stringWriter.toString(); | |
512 } | |
513 | |
514 private static void serializeModifier(PaymentDetailsModifier modifier, JsonW riter json) | |
515 throws IOException { | |
516 // {{{ | |
517 json.beginObject(); | |
518 | |
519 // total {{{ | |
520 if (modifier.total != null) { | |
521 json.name("total"); | |
522 serializePaymentItem(modifier.total, json); | |
523 } else { | |
524 json.name("total").nullValue(); | |
525 } | |
526 // }}} total | |
527 | |
528 // supportedMethods {{{ | |
529 json.name("supportedMethods").beginArray(); | |
530 for (String method : modifier.methodData.supportedMethods) { | |
please use gerrit instead
2017/05/22 13:17:10
|modifier.methodData.stringified_data| also needs
wuandy1
2017/05/23 15:46:58
Done.
| |
531 json.value(method); | |
532 } | |
533 json.endArray(); | |
534 // }}} supportedMethods | |
535 | |
536 json.endObject(); | |
537 // }}} | |
538 } | |
539 | |
493 @Override | 540 @Override |
494 public void onIntentCompleted(WindowAndroid window, int resultCode, Intent d ata) { | 541 public void onIntentCompleted(WindowAndroid window, int resultCode, Intent d ata) { |
495 ThreadUtils.assertOnUiThread(); | 542 ThreadUtils.assertOnUiThread(); |
496 window.removeIntentCallback(this); | 543 window.removeIntentCallback(this); |
497 if (data == null || data.getExtras() == null || resultCode != Activity.R ESULT_OK) { | 544 if (data == null || data.getExtras() == null || resultCode != Activity.R ESULT_OK) { |
498 mInstrumentDetailsCallback.onInstrumentDetailsError(); | 545 mInstrumentDetailsCallback.onInstrumentDetailsError(); |
499 } else { | 546 } else { |
500 String details = data.getExtras().getString(EXTRA_RESPONSE_DETAILS); | 547 String details = data.getExtras().getString(EXTRA_RESPONSE_DETAILS); |
501 if (details == null) { | 548 if (details == null) { |
502 details = data.getExtras().getString(EXTRA_DEPRECATED_RESPONSE_I NSTRUMENT_DETAILS); | 549 details = data.getExtras().getString(EXTRA_DEPRECATED_RESPONSE_I NSTRUMENT_DETAILS); |
503 } | 550 } |
504 if (details == null) { | 551 if (details == null) { |
505 details = EMPTY_JSON_DATA; | 552 details = EMPTY_JSON_DATA; |
506 } | 553 } |
507 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 554 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
508 data.getExtras().getString(EXTRA_RESPONSE_METHOD_NAME), deta ils); | 555 data.getExtras().getString(EXTRA_RESPONSE_METHOD_NAME), deta ils); |
509 } | 556 } |
510 mInstrumentDetailsCallback = null; | 557 mInstrumentDetailsCallback = null; |
511 } | 558 } |
512 | 559 |
513 @Override | 560 @Override |
514 public void dismissInstrument() {} | 561 public void dismissInstrument() {} |
515 } | 562 } |
OLD | NEW |