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/PaymentShippingOption.h" |
23 #include "modules/payments/PaymentsValidators.h" | 23 #include "modules/payments/PaymentsValidators.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 "wtf/HashSet.h" |
28 #include <utility> | 29 #include <utility> |
29 | 30 |
30 namespace mojo { | 31 namespace mojo { |
31 | 32 |
32 using blink::mojom::blink::PaymentCurrencyAmount; | 33 using blink::mojom::blink::PaymentCurrencyAmount; |
33 using blink::mojom::blink::PaymentCurrencyAmountPtr; | 34 using blink::mojom::blink::PaymentCurrencyAmountPtr; |
34 using blink::mojom::blink::PaymentDetails; | 35 using blink::mojom::blink::PaymentDetails; |
35 using blink::mojom::blink::PaymentDetailsModifier; | 36 using blink::mojom::blink::PaymentDetailsModifier; |
36 using blink::mojom::blink::PaymentDetailsModifierPtr; | 37 using blink::mojom::blink::PaymentDetailsModifierPtr; |
37 using blink::mojom::blink::PaymentDetailsPtr; | 38 using blink::mojom::blink::PaymentDetailsPtr; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 218 } |
218 } | 219 } |
219 | 220 |
220 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m
odifiers, ExceptionState& exceptionState) | 221 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m
odifiers, ExceptionState& exceptionState) |
221 { | 222 { |
222 if (modifiers.isEmpty()) { | 223 if (modifiers.isEmpty()) { |
223 exceptionState.throwTypeError("Must specify at least one payment details
modifier"); | 224 exceptionState.throwTypeError("Must specify at least one payment details
modifier"); |
224 return; | 225 return; |
225 } | 226 } |
226 | 227 |
| 228 HashSet<String> uniqueMethods; |
227 for (const auto& modifier : modifiers) { | 229 for (const auto& modifier : modifiers) { |
228 if (modifier.supportedMethods().isEmpty()) { | 230 if (modifier.supportedMethods().isEmpty()) { |
229 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); | 231 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); |
230 return; | 232 return; |
231 } | 233 } |
| 234 for (const auto& method : modifier.supportedMethods()) { |
| 235 if (uniqueMethods.contains(method)) { |
| 236 exceptionState.throwTypeError("Duplicate payment method identifi
ers are not allowed"); |
| 237 return; |
| 238 } |
| 239 uniqueMethods.add(method); |
| 240 } |
232 | 241 |
233 if (modifier.hasTotal()) { | 242 if (modifier.hasTotal()) { |
234 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState
); | 243 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState
); |
235 if (exceptionState.hadException()) | 244 if (exceptionState.hadException()) |
236 return; | 245 return; |
237 | 246 |
238 if (modifier.total().amount().value()[0] == '-') { | 247 if (modifier.total().amount().value()[0] == '-') { |
239 exceptionState.throwTypeError("Total amount value should be non-
negative"); | 248 exceptionState.throwTypeError("Total amount value should be non-
negative"); |
240 return; | 249 return; |
241 } | 250 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 291 } |
283 } | 292 } |
284 | 293 |
285 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa
ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState&
exceptionState) | 294 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa
ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState&
exceptionState) |
286 { | 295 { |
287 if (paymentMethodData.isEmpty()) { | 296 if (paymentMethodData.isEmpty()) { |
288 exceptionState.throwTypeError("Must specify at least one payment method
identifier"); | 297 exceptionState.throwTypeError("Must specify at least one payment method
identifier"); |
289 return; | 298 return; |
290 } | 299 } |
291 | 300 |
| 301 HashSet<String> uniqueMethods; |
292 for (const auto& pmd : paymentMethodData) { | 302 for (const auto& pmd : paymentMethodData) { |
293 if (pmd.supportedMethods().isEmpty()) { | 303 if (pmd.supportedMethods().isEmpty()) { |
294 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); | 304 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); |
295 return; | 305 return; |
296 } | 306 } |
| 307 for (const auto& method : pmd.supportedMethods()) { |
| 308 if (uniqueMethods.contains(method)) { |
| 309 exceptionState.throwTypeError("Duplicate payment method identifi
ers are not allowed"); |
| 310 return; |
| 311 } |
| 312 uniqueMethods.add(method); |
| 313 } |
297 | 314 |
298 String stringifiedData = ""; | 315 String stringifiedData = ""; |
299 if (pmd.hasData() && !pmd.data().isEmpty()) { | 316 if (pmd.hasData() && !pmd.data().isEmpty()) { |
300 RefPtr<JSONValue> value = toJSONValue(pmd.data().context(), pmd.data
().v8Value()); | 317 RefPtr<JSONValue> value = toJSONValue(pmd.data().context(), pmd.data
().v8Value()); |
301 if (!value) { | 318 if (!value) { |
302 exceptionState.throwTypeError("Unable to parse payment method sp
ecific data"); | 319 exceptionState.throwTypeError("Unable to parse payment method sp
ecific data"); |
303 return; | 320 return; |
304 } | 321 } |
305 if (!value->isNull()) { | 322 if (!value->isNull()) { |
306 if (value->getType() != JSONValue::TypeObject) { | 323 if (value->getType() != JSONValue::TypeObject) { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 { | 624 { |
608 m_completeResolver.clear(); | 625 m_completeResolver.clear(); |
609 m_showResolver.clear(); | 626 m_showResolver.clear(); |
610 m_abortResolver.clear(); | 627 m_abortResolver.clear(); |
611 if (m_clientBinding.is_bound()) | 628 if (m_clientBinding.is_bound()) |
612 m_clientBinding.Close(); | 629 m_clientBinding.Close(); |
613 m_paymentProvider.reset(); | 630 m_paymentProvider.reset(); |
614 } | 631 } |
615 | 632 |
616 } // namespace blink | 633 } // namespace blink |
OLD | NEW |