| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 template <> | 89 template <> |
| 90 struct TypeConverter<PaymentDetailsModifierPtr, blink::PaymentDetailsModifier> { | 90 struct TypeConverter<PaymentDetailsModifierPtr, blink::PaymentDetailsModifier> { |
| 91 static PaymentDetailsModifierPtr Convert( | 91 static PaymentDetailsModifierPtr Convert( |
| 92 const blink::PaymentDetailsModifier& input) { | 92 const blink::PaymentDetailsModifier& input) { |
| 93 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); | 93 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); |
| 94 output->supported_methods = | 94 output->supported_methods = |
| 95 WTF::Vector<WTF::String>(input.supportedMethods()); | 95 WTF::Vector<WTF::String>(input.supportedMethods()); |
| 96 | 96 |
| 97 if (input.hasTotal()) | 97 if (input.hasTotal()) |
| 98 output->total = PaymentItem::From(input.total()); | 98 output->total = PaymentItem::From(input.total()); |
| 99 else | |
| 100 output->total = PaymentItem::New(); | |
| 101 | 99 |
| 102 if (input.hasAdditionalDisplayItems()) { | 100 if (input.hasAdditionalDisplayItems()) { |
| 103 for (size_t i = 0; i < input.additionalDisplayItems().size(); ++i) { | 101 for (size_t i = 0; i < input.additionalDisplayItems().size(); ++i) { |
| 104 output->additional_display_items.append( | 102 output->additional_display_items.append( |
| 105 PaymentItem::From(input.additionalDisplayItems()[i])); | 103 PaymentItem::From(input.additionalDisplayItems()[i])); |
| 106 } | 104 } |
| 107 } | 105 } |
| 108 return output; | 106 return output; |
| 109 } | 107 } |
| 110 }; | 108 }; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 264 |
| 267 void validatePaymentDetailsModifiers( | 265 void validatePaymentDetailsModifiers( |
| 268 const HeapVector<PaymentDetailsModifier>& modifiers, | 266 const HeapVector<PaymentDetailsModifier>& modifiers, |
| 269 ExceptionState& exceptionState) { | 267 ExceptionState& exceptionState) { |
| 270 if (modifiers.isEmpty()) { | 268 if (modifiers.isEmpty()) { |
| 271 exceptionState.throwTypeError( | 269 exceptionState.throwTypeError( |
| 272 "Must specify at least one payment details modifier"); | 270 "Must specify at least one payment details modifier"); |
| 273 return; | 271 return; |
| 274 } | 272 } |
| 275 | 273 |
| 276 HashSet<String> uniqueMethods; | |
| 277 for (const auto& modifier : modifiers) { | 274 for (const auto& modifier : modifiers) { |
| 278 if (modifier.supportedMethods().isEmpty()) { | 275 if (modifier.supportedMethods().isEmpty()) { |
| 279 exceptionState.throwTypeError( | 276 exceptionState.throwTypeError( |
| 280 "Must specify at least one payment method identifier"); | 277 "Must specify at least one payment method identifier"); |
| 281 return; | 278 return; |
| 282 } | 279 } |
| 283 | 280 |
| 284 for (const auto& method : modifier.supportedMethods()) { | |
| 285 if (uniqueMethods.contains(method)) { | |
| 286 exceptionState.throwTypeError( | |
| 287 "Duplicate payment method identifiers are not allowed"); | |
| 288 return; | |
| 289 } | |
| 290 uniqueMethods.add(method); | |
| 291 } | |
| 292 | |
| 293 if (modifier.hasTotal()) { | 281 if (modifier.hasTotal()) { |
| 294 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState); | 282 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState); |
| 295 if (exceptionState.hadException()) | 283 if (exceptionState.hadException()) |
| 296 return; | 284 return; |
| 297 | 285 |
| 298 if (modifier.total().amount().value()[0] == '-') { | 286 if (modifier.total().amount().value()[0] == '-') { |
| 299 exceptionState.throwTypeError( | 287 exceptionState.throwTypeError( |
| 300 "Total amount value should be non-negative"); | 288 "Total amount value should be non-negative"); |
| 301 return; | 289 return; |
| 302 } | 290 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 void validateAndConvertPaymentMethodData( | 349 void validateAndConvertPaymentMethodData( |
| 362 const HeapVector<PaymentMethodData>& paymentMethodData, | 350 const HeapVector<PaymentMethodData>& paymentMethodData, |
| 363 Vector<PaymentRequest::MethodData>* methodData, | 351 Vector<PaymentRequest::MethodData>* methodData, |
| 364 ExceptionState& exceptionState) { | 352 ExceptionState& exceptionState) { |
| 365 if (paymentMethodData.isEmpty()) { | 353 if (paymentMethodData.isEmpty()) { |
| 366 exceptionState.throwTypeError( | 354 exceptionState.throwTypeError( |
| 367 "Must specify at least one payment method identifier"); | 355 "Must specify at least one payment method identifier"); |
| 368 return; | 356 return; |
| 369 } | 357 } |
| 370 | 358 |
| 371 HashSet<String> uniqueMethods; | |
| 372 for (const auto& pmd : paymentMethodData) { | 359 for (const auto& pmd : paymentMethodData) { |
| 373 if (pmd.supportedMethods().isEmpty()) { | 360 if (pmd.supportedMethods().isEmpty()) { |
| 374 exceptionState.throwTypeError( | 361 exceptionState.throwTypeError( |
| 375 "Must specify at least one payment method identifier"); | 362 "Must specify at least one payment method identifier"); |
| 376 return; | 363 return; |
| 377 } | 364 } |
| 378 | 365 |
| 379 for (const auto& method : pmd.supportedMethods()) { | |
| 380 if (uniqueMethods.contains(method)) { | |
| 381 exceptionState.throwTypeError( | |
| 382 "Duplicate payment method identifiers are not allowed"); | |
| 383 return; | |
| 384 } | |
| 385 uniqueMethods.add(method); | |
| 386 } | |
| 387 | |
| 388 String stringifiedData = ""; | 366 String stringifiedData = ""; |
| 389 if (pmd.hasData() && !pmd.data().isEmpty()) { | 367 if (pmd.hasData() && !pmd.data().isEmpty()) { |
| 390 std::unique_ptr<JSONValue> value = | 368 std::unique_ptr<JSONValue> value = |
| 391 toJSONValue(pmd.data().context(), pmd.data().v8Value()); | 369 toJSONValue(pmd.data().context(), pmd.data().v8Value()); |
| 392 if (!value) { | 370 if (!value) { |
| 393 exceptionState.throwTypeError( | 371 exceptionState.throwTypeError( |
| 394 "Unable to parse payment method specific data"); | 372 "Unable to parse payment method specific data"); |
| 395 return; | 373 return; |
| 396 } | 374 } |
| 397 if (!value->isNull()) { | 375 if (!value->isNull()) { |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 m_completeTimer.stop(); | 845 m_completeTimer.stop(); |
| 868 m_completeResolver.clear(); | 846 m_completeResolver.clear(); |
| 869 m_showResolver.clear(); | 847 m_showResolver.clear(); |
| 870 m_abortResolver.clear(); | 848 m_abortResolver.clear(); |
| 871 if (m_clientBinding.is_bound()) | 849 if (m_clientBinding.is_bound()) |
| 872 m_clientBinding.Close(); | 850 m_clientBinding.Close(); |
| 873 m_paymentProvider.reset(); | 851 m_paymentProvider.reset(); |
| 874 } | 852 } |
| 875 | 853 |
| 876 } // namespace blink | 854 } // namespace blink |
| OLD | NEW |