| 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" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 output->amount = CurrencyAmount::From(input.amount()); | 72 output->amount = CurrencyAmount::From(input.amount()); |
| 73 return output; | 73 return output; |
| 74 } | 74 } |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 template <> | 77 template <> |
| 78 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { | 78 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { |
| 79 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) | 79 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) |
| 80 { | 80 { |
| 81 PaymentDetailsPtr output = PaymentDetails::New(); | 81 PaymentDetailsPtr output = PaymentDetails::New(); |
| 82 output->items = mojo::WTFArray<PaymentItemPtr>::From(input.items()); | 82 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.displ
ayItems()); |
| 83 if (input.hasShippingOptions()) | 83 if (input.hasShippingOptions()) |
| 84 output->shipping_options = mojo::WTFArray<ShippingOptionPtr>::From(i
nput.shippingOptions()); | 84 output->shipping_options = mojo::WTFArray<ShippingOptionPtr>::From(i
nput.shippingOptions()); |
| 85 else | 85 else |
| 86 output->shipping_options = mojo::WTFArray<ShippingOptionPtr>::New(0)
; | 86 output->shipping_options = mojo::WTFArray<ShippingOptionPtr>::New(0)
; |
| 87 return output; | 87 return output; |
| 88 } | 88 } |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 template <> | 91 template <> |
| 92 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { | 92 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { |
| 93 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) | 93 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) |
| 94 { | 94 { |
| 95 PaymentOptionsPtr output = PaymentOptions::New(); | 95 PaymentOptionsPtr output = PaymentOptions::New(); |
| 96 output->request_shipping = input.requestShipping(); | 96 output->request_shipping = input.requestShipping(); |
| 97 return output; | 97 return output; |
| 98 } | 98 } |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 } // namespace mojo | 101 } // namespace mojo |
| 102 | 102 |
| 103 namespace blink { | 103 namespace blink { |
| 104 namespace { | 104 namespace { |
| 105 | 105 |
| 106 // Validates ShippingOption and PaymentItem dictionaries, which happen to have i
dentical fields. | 106 // Validates ShippingOption and PaymentItem dictionaries, which happen to have i
dentical fields, |
| 107 // except for "id", which is present only in ShippingOption. | 107 // except for "id", which is present only in ShippingOption. |
| 108 template <typename T> | 108 template <typename T> |
| 109 void validateShippingOptionsOrPaymentItems(HeapVector<T> items, ExceptionState&
exceptionState) | 109 void validateShippingOptionsOrPaymentItems(HeapVector<T> items, ExceptionState&
exceptionState) |
| 110 { | 110 { |
| 111 String errorMessage; | 111 String errorMessage; |
| 112 for (const auto& item : items) { | 112 for (const auto& item : items) { |
| 113 if (!item.hasLabel() || item.label().isEmpty()) { | 113 if (!item.hasLabel() || item.label().isEmpty()) { |
| 114 exceptionState.throwTypeError("Item label required"); | 114 exceptionState.throwTypeError("Item label required"); |
| 115 return; | 115 return; |
| 116 } | 116 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 147 for (const auto& option : options) { | 147 for (const auto& option : options) { |
| 148 if (!option.hasId() || option.id().isEmpty()) { | 148 if (!option.hasId() || option.id().isEmpty()) { |
| 149 exceptionState.throwTypeError("ShippingOption id required"); | 149 exceptionState.throwTypeError("ShippingOption id required"); |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep
tionState) | 155 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep
tionState) |
| 156 { | 156 { |
| 157 if (!details.hasItems()) { | 157 if (!details.hasDisplayItems()) { |
| 158 exceptionState.throwTypeError("Must specify items"); | 158 exceptionState.throwTypeError("Must specify display items"); |
| 159 return; | 159 return; |
| 160 } | 160 } |
| 161 | 161 |
| 162 if (details.items().isEmpty()) { | 162 if (details.displayItems().isEmpty()) { |
| 163 exceptionState.throwTypeError("Must specify at least one item"); | 163 exceptionState.throwTypeError("Must specify at least one item"); |
| 164 return; | 164 return; |
| 165 } | 165 } |
| 166 | 166 |
| 167 validateShippingOptionsOrPaymentItems(details.items(), exceptionState); | 167 validateShippingOptionsOrPaymentItems(details.displayItems(), exceptionState
); |
| 168 if (exceptionState.hadException()) | 168 if (exceptionState.hadException()) |
| 169 return; | 169 return; |
| 170 | 170 |
| 171 if (details.hasShippingOptions()) { | 171 if (details.hasShippingOptions()) { |
| 172 validateShippingOptionsOrPaymentItems(details.shippingOptions(), excepti
onState); | 172 validateShippingOptionsOrPaymentItems(details.shippingOptions(), excepti
onState); |
| 173 validateShippingOptionsIds(details.shippingOptions(), exceptionState); | 173 validateShippingOptionsIds(details.shippingOptions(), exceptionState); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace | 177 } // namespace |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 void PaymentRequest::clearResolversAndCloseMojoConnection() | 443 void PaymentRequest::clearResolversAndCloseMojoConnection() |
| 444 { | 444 { |
| 445 m_completeResolver.clear(); | 445 m_completeResolver.clear(); |
| 446 m_showResolver.clear(); | 446 m_showResolver.clear(); |
| 447 if (m_clientBinding.is_bound()) | 447 if (m_clientBinding.is_bound()) |
| 448 m_clientBinding.Close(); | 448 m_clientBinding.Close(); |
| 449 m_paymentProvider.reset(); | 449 m_paymentProvider.reset(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |