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 14 matching lines...) Expand all Loading... |
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::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::PaymentDetailsModifier; |
| 36 using blink::mojom::blink::PaymentDetailsModifierPtr; |
35 using blink::mojom::blink::PaymentDetailsPtr; | 37 using blink::mojom::blink::PaymentDetailsPtr; |
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 |
(...skipping 26 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 |
| 89 if (input.hasTotal()) |
| 90 output->total = PaymentItem::From(input.total()); |
| 91 else |
| 92 output->total = PaymentItem::New(); |
| 93 |
| 94 if (input.hasAdditionalDisplayItems()) |
| 95 output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::F
rom(input.additionalDisplayItems()); |
| 96 else |
| 97 output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::N
ew(0); |
| 98 |
| 99 return output; |
| 100 } |
| 101 }; |
| 102 |
| 103 template <> |
81 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { | 104 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { |
82 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) | 105 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) |
83 { | 106 { |
84 PaymentDetailsPtr output = PaymentDetails::New(); | 107 PaymentDetailsPtr output = PaymentDetails::New(); |
85 output->total = PaymentItem::From(input.total()); | 108 output->total = PaymentItem::From(input.total()); |
86 | 109 |
87 if (input.hasDisplayItems()) | 110 if (input.hasDisplayItems()) |
88 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.d
isplayItems()); | 111 output->display_items = mojo::WTFArray<PaymentItemPtr>::From(input.d
isplayItems()); |
89 else | 112 else |
90 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 113 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); |
91 | 114 |
92 if (input.hasShippingOptions()) | 115 if (input.hasShippingOptions()) |
93 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>:
:From(input.shippingOptions()); | 116 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>:
:From(input.shippingOptions()); |
94 else | 117 else |
95 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>:
:New(0); | 118 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>:
:New(0); |
96 | 119 |
| 120 if (input.hasModifiers()) |
| 121 output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::From(
input.modifiers()); |
| 122 else |
| 123 output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::New(0
); |
| 124 |
97 return output; | 125 return output; |
98 } | 126 } |
99 }; | 127 }; |
100 | 128 |
101 template <> | 129 template <> |
102 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { | 130 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { |
103 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) | 131 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) |
104 { | 132 { |
105 PaymentOptionsPtr output = PaymentOptions::New(); | 133 PaymentOptionsPtr output = PaymentOptions::New(); |
106 output->request_payer_email = input.requestPayerEmail(); | 134 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"); | 210 exceptionState.throwTypeError("ShippingOption id required"); |
183 return; | 211 return; |
184 } | 212 } |
185 | 213 |
186 validateShippingOptionOrPaymentItem(option, exceptionState); | 214 validateShippingOptionOrPaymentItem(option, exceptionState); |
187 if (exceptionState.hadException()) | 215 if (exceptionState.hadException()) |
188 return; | 216 return; |
189 } | 217 } |
190 } | 218 } |
191 | 219 |
| 220 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m
odifiers, ExceptionState& exceptionState) |
| 221 { |
| 222 if (modifiers.isEmpty()) { |
| 223 exceptionState.throwTypeError("Must specify at least one payment details
modifier"); |
| 224 return; |
| 225 } |
| 226 |
| 227 for (const auto& modifier : modifiers) { |
| 228 if (modifier.supportedMethods().isEmpty()) { |
| 229 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); |
| 230 return; |
| 231 } |
| 232 |
| 233 if (modifier.hasTotal()) { |
| 234 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState
); |
| 235 if (exceptionState.hadException()) |
| 236 return; |
| 237 |
| 238 if (modifier.total().amount().value()[0] == '-') { |
| 239 exceptionState.throwTypeError("Total amount value should be non-
negative"); |
| 240 return; |
| 241 } |
| 242 } |
| 243 |
| 244 if (modifier.hasAdditionalDisplayItems()) { |
| 245 validateDisplayItems(modifier.additionalDisplayItems(), exceptionSta
te); |
| 246 if (exceptionState.hadException()) |
| 247 return; |
| 248 } |
| 249 } |
| 250 } |
| 251 |
192 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep
tionState) | 252 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep
tionState) |
193 { | 253 { |
194 if (!details.hasTotal()) { | 254 if (!details.hasTotal()) { |
195 exceptionState.throwTypeError("Must specify total"); | 255 exceptionState.throwTypeError("Must specify total"); |
196 return; | 256 return; |
197 } | 257 } |
198 | 258 |
199 validateShippingOptionOrPaymentItem(details.total(), exceptionState); | 259 validateShippingOptionOrPaymentItem(details.total(), exceptionState); |
200 if (exceptionState.hadException()) | 260 if (exceptionState.hadException()) |
201 return; | 261 return; |
202 | 262 |
203 if (details.total().amount().value()[0] == '-') { | 263 if (details.total().amount().value()[0] == '-') { |
204 exceptionState.throwTypeError("Total amount value should be non-negative
"); | 264 exceptionState.throwTypeError("Total amount value should be non-negative
"); |
205 return; | 265 return; |
206 } | 266 } |
207 | 267 |
208 if (details.hasDisplayItems()) { | 268 if (details.hasDisplayItems()) { |
209 validateDisplayItems(details.displayItems(), exceptionState); | 269 validateDisplayItems(details.displayItems(), exceptionState); |
210 if (exceptionState.hadException()) | 270 if (exceptionState.hadException()) |
211 return; | 271 return; |
212 } | 272 } |
213 | 273 |
214 if (details.hasShippingOptions()) { | 274 if (details.hasShippingOptions()) { |
215 validateShippingOptions(details.shippingOptions(), exceptionState); | 275 validateShippingOptions(details.shippingOptions(), exceptionState); |
| 276 if (exceptionState.hadException()) |
| 277 return; |
| 278 } |
| 279 |
| 280 if (details.hasModifiers()) { |
| 281 validatePaymentDetailsModifiers(details.modifiers(), exceptionState); |
216 } | 282 } |
217 } | 283 } |
218 | 284 |
219 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa
ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState&
exceptionState) | 285 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa
ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState&
exceptionState) |
220 { | 286 { |
221 if (paymentMethodData.isEmpty()) { | 287 if (paymentMethodData.isEmpty()) { |
222 exceptionState.throwTypeError("Must specify at least one payment method
identifier"); | 288 exceptionState.throwTypeError("Must specify at least one payment method
identifier"); |
223 return; | 289 return; |
224 } | 290 } |
225 | 291 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 { | 607 { |
542 m_completeResolver.clear(); | 608 m_completeResolver.clear(); |
543 m_showResolver.clear(); | 609 m_showResolver.clear(); |
544 m_abortResolver.clear(); | 610 m_abortResolver.clear(); |
545 if (m_clientBinding.is_bound()) | 611 if (m_clientBinding.is_bound()) |
546 m_clientBinding.Close(); | 612 m_clientBinding.Close(); |
547 m_paymentProvider.reset(); | 613 m_paymentProvider.reset(); |
548 } | 614 } |
549 | 615 |
550 } // namespace blink | 616 } // namespace blink |
OLD | NEW |