| 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 #include "modules/payments/PaymentRequest.h" | 5 #include "modules/payments/PaymentRequest.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/JSONValuesForV8.h" | 8 #include "bindings/core/v8/JSONValuesForV8.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "bindings/modules/v8/V8PaymentDetails.h" | 11 #include "bindings/modules/v8/V8PaymentDetails.h" |
| 12 #include "core/EventTypeNames.h" | 12 #include "core/EventTypeNames.h" |
| 13 #include "core/dom/DOMException.h" | 13 #include "core/dom/DOMException.h" |
| 14 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
| 15 #include "core/events/Event.h" | 15 #include "core/events/Event.h" |
| 16 #include "core/events/EventQueue.h" | 16 #include "core/events/EventQueue.h" |
| 17 #include "modules/EventTargetModulesNames.h" | 17 #include "modules/EventTargetModulesNames.h" |
| 18 #include "modules/payments/PaymentAddress.h" | 18 #include "modules/payments/PaymentAddress.h" |
| 19 #include "modules/payments/PaymentItem.h" | 19 #include "modules/payments/PaymentItem.h" |
| 20 #include "modules/payments/PaymentRequestUpdateEvent.h" | 20 #include "modules/payments/PaymentRequestUpdateEvent.h" |
| 21 #include "modules/payments/PaymentResponse.h" | 21 #include "modules/payments/PaymentResponse.h" |
| 22 #include "modules/payments/PaymentShippingOption.h" |
| 22 #include "modules/payments/PaymentsValidators.h" | 23 #include "modules/payments/PaymentsValidators.h" |
| 23 #include "modules/payments/ShippingOption.h" | |
| 24 #include "mojo/public/cpp/bindings/interface_request.h" | 24 #include "mojo/public/cpp/bindings/interface_request.h" |
| 25 #include "mojo/public/cpp/bindings/wtf_array.h" | 25 #include "mojo/public/cpp/bindings/wtf_array.h" |
| 26 #include "platform/mojo/MojoHelper.h" | 26 #include "platform/mojo/MojoHelper.h" |
| 27 #include "public/platform/ServiceRegistry.h" | 27 #include "public/platform/ServiceRegistry.h" |
| 28 #include <utility> | 28 #include <utility> |
| 29 | 29 |
| 30 namespace mojo { | 30 namespace mojo { |
| 31 | 31 |
| 32 using blink::mojom::blink::CurrencyAmount; | 32 using blink::mojom::blink::PaymentCurrencyAmount; |
| 33 using blink::mojom::blink::CurrencyAmountPtr; | 33 using blink::mojom::blink::PaymentCurrencyAmountPtr; |
| 34 using blink::mojom::blink::PaymentDetails; | 34 using blink::mojom::blink::PaymentDetails; |
| 35 using blink::mojom::blink::PaymentDetailsPtr; | 35 using blink::mojom::blink::PaymentDetailsPtr; |
| 36 using blink::mojom::blink::PaymentItem; | 36 using blink::mojom::blink::PaymentItem; |
| 37 using blink::mojom::blink::PaymentItemPtr; | 37 using blink::mojom::blink::PaymentItemPtr; |
| 38 using blink::mojom::blink::PaymentMethodData; | 38 using blink::mojom::blink::PaymentMethodData; |
| 39 using blink::mojom::blink::PaymentMethodDataPtr; | 39 using blink::mojom::blink::PaymentMethodDataPtr; |
| 40 using blink::mojom::blink::PaymentOptions; | 40 using blink::mojom::blink::PaymentOptions; |
| 41 using blink::mojom::blink::PaymentOptionsPtr; | 41 using blink::mojom::blink::PaymentOptionsPtr; |
| 42 using blink::mojom::blink::ShippingOption; | 42 using blink::mojom::blink::PaymentShippingOption; |
| 43 using blink::mojom::blink::ShippingOptionPtr; | 43 using blink::mojom::blink::PaymentShippingOptionPtr; |
| 44 | 44 |
| 45 template <> | 45 template <> |
| 46 struct TypeConverter<CurrencyAmountPtr, blink::CurrencyAmount> { | 46 struct TypeConverter<PaymentCurrencyAmountPtr, blink::PaymentCurrencyAmount> { |
| 47 static CurrencyAmountPtr Convert(const blink::CurrencyAmount& input) | 47 static PaymentCurrencyAmountPtr Convert(const blink::PaymentCurrencyAmount&
input) |
| 48 { | 48 { |
| 49 CurrencyAmountPtr output = CurrencyAmount::New(); | 49 PaymentCurrencyAmountPtr output = PaymentCurrencyAmount::New(); |
| 50 output->currency = input.currency(); | 50 output->currency = input.currency(); |
| 51 output->value = input.value(); | 51 output->value = input.value(); |
| 52 return output; | 52 return output; |
| 53 } | 53 } |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 template <> | 56 template <> |
| 57 struct TypeConverter<PaymentItemPtr, blink::PaymentItem> { | 57 struct TypeConverter<PaymentItemPtr, blink::PaymentItem> { |
| 58 static PaymentItemPtr Convert(const blink::PaymentItem& input) | 58 static PaymentItemPtr Convert(const blink::PaymentItem& input) |
| 59 { | 59 { |
| 60 PaymentItemPtr output = PaymentItem::New(); | 60 PaymentItemPtr output = PaymentItem::New(); |
| 61 output->label = input.label(); | 61 output->label = input.label(); |
| 62 output->amount = CurrencyAmount::From(input.amount()); | 62 output->amount = PaymentCurrencyAmount::From(input.amount()); |
| 63 return output; | 63 return output; |
| 64 } | 64 } |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 template <> | 67 template <> |
| 68 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> { | 68 struct TypeConverter<PaymentShippingOptionPtr, blink::PaymentShippingOption> { |
| 69 static ShippingOptionPtr Convert(const blink::ShippingOption& input) | 69 static PaymentShippingOptionPtr Convert(const blink::PaymentShippingOption&
input) |
| 70 { | 70 { |
| 71 ShippingOptionPtr output = ShippingOption::New(); | 71 PaymentShippingOptionPtr output = PaymentShippingOption::New(); |
| 72 output->id = input.id(); | 72 output->id = input.id(); |
| 73 output->label = input.label(); | 73 output->label = input.label(); |
| 74 output->amount = CurrencyAmount::From(input.amount()); | 74 output->amount = PaymentCurrencyAmount::From(input.amount()); |
| 75 output->selected = input.hasSelected() && input.selected(); | 75 output->selected = input.hasSelected() && input.selected(); |
| 76 return output; | 76 return output; |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 template <> | 80 template <> |
| 81 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { | 81 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { |
| 82 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) | 82 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) |
| 83 { | 83 { |
| 84 PaymentDetailsPtr output = PaymentDetails::New(); | 84 PaymentDetailsPtr output = PaymentDetails::New(); |
| 85 output->total = PaymentItem::From(input.total()); | 85 output->total = PaymentItem::From(input.total()); |
| 86 | 86 |
| 87 if (input.hasDisplayItems()) | 87 if (input.hasDisplayItems()) |
| 88 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.d
isplayItems()); | 88 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.d
isplayItems()); |
| 89 else | 89 else |
| 90 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 90 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); |
| 91 | 91 |
| 92 if (input.hasShippingOptions()) | 92 if (input.hasShippingOptions()) |
| 93 output->shipping_options = mojo::WTFArray<ShippingOptionPtr>::From(i
nput.shippingOptions()); | 93 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>:
:From(input.shippingOptions()); |
| 94 else | 94 else |
| 95 output->shipping_options = mojo::WTFArray<ShippingOptionPtr>::New(0)
; | 95 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>:
:New(0); |
| 96 | 96 |
| 97 return output; | 97 return output; |
| 98 } | 98 } |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 template <> | 101 template <> |
| 102 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { | 102 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { |
| 103 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) | 103 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) |
| 104 { | 104 { |
| 105 PaymentOptionsPtr output = PaymentOptions::New(); | 105 PaymentOptionsPtr output = PaymentOptions::New(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 void validateDisplayItems(const HeapVector<PaymentItem>& items, ExceptionState&
exceptionState) | 167 void validateDisplayItems(const HeapVector<PaymentItem>& items, ExceptionState&
exceptionState) |
| 168 { | 168 { |
| 169 for (const auto& item : items) { | 169 for (const auto& item : items) { |
| 170 validateShippingOptionOrPaymentItem(item, exceptionState); | 170 validateShippingOptionOrPaymentItem(item, exceptionState); |
| 171 if (exceptionState.hadException()) | 171 if (exceptionState.hadException()) |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 void validateShippingOptions(const HeapVector<ShippingOption>& options, Exceptio
nState& exceptionState) | 176 void validateShippingOptions(const HeapVector<PaymentShippingOption>& options, E
xceptionState& exceptionState) |
| 177 { | 177 { |
| 178 for (const auto& option : options) { | 178 for (const auto& option : options) { |
| 179 if (!option.hasId() || option.id().isEmpty()) { | 179 if (!option.hasId() || option.id().isEmpty()) { |
| 180 exceptionState.throwTypeError("ShippingOption id required"); | 180 exceptionState.throwTypeError("ShippingOption id required"); |
| 181 return; | 181 return; |
| 182 } | 182 } |
| 183 | 183 |
| 184 validateShippingOptionOrPaymentItem(option, exceptionState); | 184 validateShippingOptionOrPaymentItem(option, exceptionState); |
| 185 if (exceptionState.hadException()) | 185 if (exceptionState.hadException()) |
| 186 return; | 186 return; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 { | 535 { |
| 536 m_completeResolver.clear(); | 536 m_completeResolver.clear(); |
| 537 m_showResolver.clear(); | 537 m_showResolver.clear(); |
| 538 m_abortResolver.clear(); | 538 m_abortResolver.clear(); |
| 539 if (m_clientBinding.is_bound()) | 539 if (m_clientBinding.is_bound()) |
| 540 m_clientBinding.Close(); | 540 m_clientBinding.Close(); |
| 541 m_paymentProvider.reset(); | 541 m_paymentProvider.reset(); |
| 542 } | 542 } |
| 543 | 543 |
| 544 } // namespace blink | 544 } // namespace blink |
| OLD | NEW |