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 15 matching lines...) Expand all Loading... | |
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::PaymentCurrencyAmount; | 32 using blink::mojom::blink::PaymentCurrencyAmount; |
33 using blink::mojom::blink::PaymentCurrencyAmountPtr; | 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::PaymentDetailsModifier; | |
please use gerrit instead
2016/06/26 19:45:25
Please sort this list. PaymentDetailsModifier* sho
zino
2016/06/27 17:29:24
Done.
| |
37 using blink::mojom::blink::PaymentDetailsModifierPtr; | |
36 using blink::mojom::blink::PaymentItem; | 38 using blink::mojom::blink::PaymentItem; |
37 using blink::mojom::blink::PaymentItemPtr; | 39 using blink::mojom::blink::PaymentItemPtr; |
38 using blink::mojom::blink::PaymentMethodData; | 40 using blink::mojom::blink::PaymentMethodData; |
39 using blink::mojom::blink::PaymentMethodDataPtr; | 41 using blink::mojom::blink::PaymentMethodDataPtr; |
40 using blink::mojom::blink::PaymentOptions; | 42 using blink::mojom::blink::PaymentOptions; |
41 using blink::mojom::blink::PaymentOptionsPtr; | 43 using blink::mojom::blink::PaymentOptionsPtr; |
42 using blink::mojom::blink::PaymentShippingOption; | 44 using blink::mojom::blink::PaymentShippingOption; |
43 using blink::mojom::blink::PaymentShippingOptionPtr; | 45 using blink::mojom::blink::PaymentShippingOptionPtr; |
44 | 46 |
45 template <> | 47 template <> |
(...skipping 25 matching lines...) Expand all Loading... | |
71 PaymentShippingOptionPtr output = PaymentShippingOption::New(); | 73 PaymentShippingOptionPtr output = PaymentShippingOption::New(); |
72 output->id = input.id(); | 74 output->id = input.id(); |
73 output->label = input.label(); | 75 output->label = input.label(); |
74 output->amount = PaymentCurrencyAmount::From(input.amount()); | 76 output->amount = PaymentCurrencyAmount::From(input.amount()); |
75 output->selected = input.hasSelected() && input.selected(); | 77 output->selected = input.hasSelected() && input.selected(); |
76 return output; | 78 return output; |
77 } | 79 } |
78 }; | 80 }; |
79 | 81 |
80 template <> | 82 template <> |
83 struct TypeConverter<PaymentDetailsModifierPtr, blink::PaymentDetailsModifier> { | |
84 static PaymentDetailsModifierPtr Convert(const blink::PaymentDetailsModifier & input) | |
85 { | |
86 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); | |
87 output->supported_methods = WTF::Vector<WTF::String>(input.supportedMeth ods()); | |
88 output->total = PaymentItem::From(input.total()); | |
please use gerrit instead
2016/06/26 19:45:25
Total is not required in the spec, so check for it
zino
2016/06/27 17:29:23
Done.
| |
89 | |
90 if (input.hasAdditionalDisplayItems()) | |
91 output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::F rom(input.additionalDisplayItems()); | |
92 else | |
93 output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::N ew(0); | |
94 | |
95 return output; | |
96 } | |
97 }; | |
98 | |
99 template <> | |
81 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { | 100 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { |
82 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) | 101 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) |
83 { | 102 { |
84 PaymentDetailsPtr output = PaymentDetails::New(); | 103 PaymentDetailsPtr output = PaymentDetails::New(); |
85 output->total = PaymentItem::From(input.total()); | 104 output->total = PaymentItem::From(input.total()); |
86 | 105 |
87 if (input.hasDisplayItems()) | 106 if (input.hasDisplayItems()) |
88 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.d isplayItems()); | 107 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.d isplayItems()); |
89 else | 108 else |
90 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 109 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); |
91 | 110 |
92 if (input.hasShippingOptions()) | 111 if (input.hasShippingOptions()) |
93 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>: :From(input.shippingOptions()); | 112 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>: :From(input.shippingOptions()); |
94 else | 113 else |
95 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>: :New(0); | 114 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>: :New(0); |
96 | 115 |
116 if (input.hasModifiers()) | |
117 output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::From( input.modifiers()); | |
118 else | |
119 output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::New(0 ); | |
120 | |
97 return output; | 121 return output; |
98 } | 122 } |
99 }; | 123 }; |
100 | 124 |
101 template <> | 125 template <> |
102 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { | 126 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { |
103 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) | 127 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) |
104 { | 128 { |
105 PaymentOptionsPtr output = PaymentOptions::New(); | 129 PaymentOptionsPtr output = PaymentOptions::New(); |
106 output->request_payer_email = input.requestPayerEmail(); | 130 output->request_payer_email = input.requestPayerEmail(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 exceptionState.throwTypeError("ShippingOption id required"); | 206 exceptionState.throwTypeError("ShippingOption id required"); |
183 return; | 207 return; |
184 } | 208 } |
185 | 209 |
186 validateShippingOptionOrPaymentItem(option, exceptionState); | 210 validateShippingOptionOrPaymentItem(option, exceptionState); |
187 if (exceptionState.hadException()) | 211 if (exceptionState.hadException()) |
188 return; | 212 return; |
189 } | 213 } |
190 } | 214 } |
191 | 215 |
216 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m odifiers, ExceptionState& exceptionState) | |
217 { | |
218 if (modifiers.isEmpty()) { | |
219 exceptionState.throwTypeError("Must specify at least one payment details modifier"); | |
220 return; | |
221 } | |
222 | |
223 for (const auto& modifier : modifiers) { | |
224 if (modifier.supportedMethods().isEmpty()) { | |
225 exceptionState.throwTypeError("Must specify at least one payment met hod identifier"); | |
226 return; | |
227 } | |
228 | |
229 if (modifier.hasTotal()) { | |
230 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState ); | |
231 if (exceptionState.hadException()) | |
232 return; | |
233 | |
234 if (modifier.total().amount().value()[0] == '-') { | |
235 exceptionState.throwTypeError("Total amount value should be non- negative"); | |
236 return; | |
237 } | |
238 } | |
239 | |
240 if (modifier.hasAdditionalDisplayItems()) { | |
241 validateDisplayItems(modifier.additionalDisplayItems(), exceptionSta te); | |
242 if (exceptionState.hadException()) | |
243 return; | |
244 } | |
245 } | |
246 } | |
247 | |
192 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep tionState) | 248 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep tionState) |
193 { | 249 { |
194 if (!details.hasTotal()) { | 250 if (!details.hasTotal()) { |
195 exceptionState.throwTypeError("Must specify total"); | 251 exceptionState.throwTypeError("Must specify total"); |
196 return; | 252 return; |
197 } | 253 } |
198 | 254 |
199 validateShippingOptionOrPaymentItem(details.total(), exceptionState); | 255 validateShippingOptionOrPaymentItem(details.total(), exceptionState); |
200 if (exceptionState.hadException()) | 256 if (exceptionState.hadException()) |
201 return; | 257 return; |
202 | 258 |
203 if (details.total().amount().value()[0] == '-') { | 259 if (details.total().amount().value()[0] == '-') { |
204 exceptionState.throwTypeError("Total amount value should be non-negative "); | 260 exceptionState.throwTypeError("Total amount value should be non-negative "); |
205 return; | 261 return; |
206 } | 262 } |
207 | 263 |
208 if (details.hasDisplayItems()) { | 264 if (details.hasDisplayItems()) { |
209 validateDisplayItems(details.displayItems(), exceptionState); | 265 validateDisplayItems(details.displayItems(), exceptionState); |
210 if (exceptionState.hadException()) | 266 if (exceptionState.hadException()) |
211 return; | 267 return; |
212 } | 268 } |
213 | 269 |
214 if (details.hasShippingOptions()) { | 270 if (details.hasShippingOptions()) { |
215 validateShippingOptions(details.shippingOptions(), exceptionState); | 271 validateShippingOptions(details.shippingOptions(), exceptionState); |
272 if (exceptionState.hadException()) | |
273 return; | |
274 } | |
275 | |
276 if (details.hasModifiers()) { | |
277 validatePaymentDetailsModifiers(details.modifiers(), exceptionState); | |
216 } | 278 } |
217 } | 279 } |
218 | 280 |
219 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState& exceptionState) | 281 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState& exceptionState) |
220 { | 282 { |
221 if (paymentMethodData.isEmpty()) { | 283 if (paymentMethodData.isEmpty()) { |
222 exceptionState.throwTypeError("Must specify at least one payment method identifier"); | 284 exceptionState.throwTypeError("Must specify at least one payment method identifier"); |
223 return; | 285 return; |
224 } | 286 } |
225 | 287 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 { | 603 { |
542 m_completeResolver.clear(); | 604 m_completeResolver.clear(); |
543 m_showResolver.clear(); | 605 m_showResolver.clear(); |
544 m_abortResolver.clear(); | 606 m_abortResolver.clear(); |
545 if (m_clientBinding.is_bound()) | 607 if (m_clientBinding.is_bound()) |
546 m_clientBinding.Close(); | 608 m_clientBinding.Close(); |
547 m_paymentProvider.reset(); | 609 m_paymentProvider.reset(); |
548 } | 610 } |
549 | 611 |
550 } // namespace blink | 612 } // namespace blink |
OLD | NEW |