| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const blink::PaymentDetailsModifier& input) { | 87 const blink::PaymentDetailsModifier& input) { |
| 88 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); | 88 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); |
| 89 output->supported_methods = | 89 output->supported_methods = |
| 90 WTF::Vector<WTF::String>(input.supportedMethods()); | 90 WTF::Vector<WTF::String>(input.supportedMethods()); |
| 91 | 91 |
| 92 if (input.hasTotal()) | 92 if (input.hasTotal()) |
| 93 output->total = PaymentItem::From(input.total()); | 93 output->total = PaymentItem::From(input.total()); |
| 94 else | 94 else |
| 95 output->total = PaymentItem::New(); | 95 output->total = PaymentItem::New(); |
| 96 | 96 |
| 97 if (input.hasAdditionalDisplayItems()) | 97 if (input.hasAdditionalDisplayItems()) { |
| 98 output->additional_display_items = | 98 for (size_t i = 0; i < input.additionalDisplayItems().size(); ++i) { |
| 99 mojo::WTFArray<PaymentItemPtr>::From(input.additionalDisplayItems()); | 99 output->additional_display_items.append( |
| 100 else | 100 PaymentItem::From(input.additionalDisplayItems()[i])); |
| 101 output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 101 } |
| 102 | 102 } |
| 103 return output; | 103 return output; |
| 104 } | 104 } |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 template <> | 107 template <> |
| 108 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { | 108 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { |
| 109 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) { | 109 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) { |
| 110 PaymentDetailsPtr output = PaymentDetails::New(); | 110 PaymentDetailsPtr output = PaymentDetails::New(); |
| 111 output->total = PaymentItem::From(input.total()); | 111 output->total = PaymentItem::From(input.total()); |
| 112 | 112 |
| 113 if (input.hasDisplayItems()) | 113 if (input.hasDisplayItems()) { |
| 114 output->display_items = | 114 for (size_t i = 0; i < input.displayItems().size(); ++i) { |
| 115 mojo::WTFArray<PaymentItemPtr>::From(input.displayItems()); | 115 output->display_items.append( |
| 116 else | 116 PaymentItem::From(input.displayItems()[i])); |
| 117 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 117 } |
| 118 } |
| 118 | 119 |
| 119 if (input.hasShippingOptions()) | 120 if (input.hasShippingOptions()) { |
| 120 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>::From( | 121 for (size_t i = 0; i < input.shippingOptions().size(); ++i) { |
| 121 input.shippingOptions()); | 122 output->shipping_options.append( |
| 122 else | 123 PaymentShippingOption::From(input.shippingOptions()[i])); |
| 123 output->shipping_options = | 124 } |
| 124 mojo::WTFArray<PaymentShippingOptionPtr>::New(0); | 125 } |
| 125 | 126 |
| 126 if (input.hasModifiers()) | 127 if (input.hasModifiers()) { |
| 127 output->modifiers = | 128 for (size_t i = 0; i < input.modifiers().size(); ++i) { |
| 128 mojo::WTFArray<PaymentDetailsModifierPtr>::From(input.modifiers()); | 129 output->modifiers.append( |
| 129 else | 130 PaymentDetailsModifier::From(input.modifiers()[i])); |
| 130 output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::New(0); | 131 } |
| 132 } |
| 131 | 133 |
| 132 if (input.hasError()) | 134 if (input.hasError()) |
| 133 output->error = input.error(); | 135 output->error = input.error(); |
| 134 else | 136 else |
| 135 output->error = WTF::emptyString(); | 137 output->error = WTF::emptyString(); |
| 136 | 138 |
| 137 return output; | 139 return output; |
| 138 } | 140 } |
| 139 }; | 141 }; |
| 140 | 142 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 423 |
| 422 mojom::blink::PaymentDetailsPtr maybeKeepShippingOptions( | 424 mojom::blink::PaymentDetailsPtr maybeKeepShippingOptions( |
| 423 mojom::blink::PaymentDetailsPtr details, | 425 mojom::blink::PaymentDetailsPtr details, |
| 424 bool keep) { | 426 bool keep) { |
| 425 if (!keep) | 427 if (!keep) |
| 426 details->shipping_options.resize(0); | 428 details->shipping_options.resize(0); |
| 427 | 429 |
| 428 return details; | 430 return details; |
| 429 } | 431 } |
| 430 | 432 |
| 433 WTF::Vector<mojom::blink::PaymentMethodDataPtr> ConvertPaymentMethodData( |
| 434 const Vector<PaymentRequest::MethodData>& blinkMethods) { |
| 435 WTF::Vector<mojom::blink::PaymentMethodDataPtr> mojoMethods( |
| 436 blinkMethods.size()); |
| 437 for (size_t i = 0; i < blinkMethods.size(); ++i) { |
| 438 mojoMethods[i] = mojom::blink::PaymentMethodData::New(); |
| 439 mojoMethods[i]->supported_methods = |
| 440 WTF::Vector<WTF::String>(blinkMethods[i].supportedMethods); |
| 441 mojoMethods[i]->stringified_data = blinkMethods[i].stringifiedData; |
| 442 } |
| 443 return mojoMethods; |
| 444 } |
| 445 |
| 431 } // namespace | 446 } // namespace |
| 432 | 447 |
| 433 PaymentRequest* PaymentRequest::create( | 448 PaymentRequest* PaymentRequest::create( |
| 434 ScriptState* scriptState, | 449 ScriptState* scriptState, |
| 435 const HeapVector<PaymentMethodData>& methodData, | 450 const HeapVector<PaymentMethodData>& methodData, |
| 436 const PaymentDetails& details, | 451 const PaymentDetails& details, |
| 437 ExceptionState& exceptionState) { | 452 ExceptionState& exceptionState) { |
| 438 return new PaymentRequest(scriptState, methodData, details, PaymentOptions(), | 453 return new PaymentRequest(scriptState, methodData, details, PaymentOptions(), |
| 439 exceptionState); | 454 exceptionState); |
| 440 } | 455 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 if (keepShippingOptions) | 643 if (keepShippingOptions) |
| 629 m_shippingOption = getSelectedShippingOption(details); | 644 m_shippingOption = getSelectedShippingOption(details); |
| 630 m_shippingType = getValidShippingType(m_options.shippingType()); | 645 m_shippingType = getValidShippingType(m_options.shippingType()); |
| 631 } | 646 } |
| 632 | 647 |
| 633 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( | 648 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( |
| 634 mojo::GetProxy(&m_paymentProvider)); | 649 mojo::GetProxy(&m_paymentProvider)); |
| 635 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( | 650 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( |
| 636 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), | 651 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), |
| 637 mojom::blink::PaymentErrorReason::UNKNOWN))); | 652 mojom::blink::PaymentErrorReason::UNKNOWN))); |
| 653 |
| 638 m_paymentProvider->Init( | 654 m_paymentProvider->Init( |
| 639 m_clientBinding.CreateInterfacePtrAndBind(), | 655 m_clientBinding.CreateInterfacePtrAndBind(), |
| 640 mojo::WTFArray<mojom::blink::PaymentMethodDataPtr>::From( | 656 ConvertPaymentMethodData(validatedMethodData), |
| 641 validatedMethodData), | |
| 642 maybeKeepShippingOptions(mojom::blink::PaymentDetails::From(details), | 657 maybeKeepShippingOptions(mojom::blink::PaymentDetails::From(details), |
| 643 keepShippingOptions), | 658 keepShippingOptions), |
| 644 mojom::blink::PaymentOptions::From(m_options)); | 659 mojom::blink::PaymentOptions::From(m_options)); |
| 645 } | 660 } |
| 646 | 661 |
| 647 void PaymentRequest::contextDestroyed() { | 662 void PaymentRequest::contextDestroyed() { |
| 648 clearResolversAndCloseMojoConnection(); | 663 clearResolversAndCloseMojoConnection(); |
| 649 } | 664 } |
| 650 | 665 |
| 651 void PaymentRequest::OnShippingAddressChange( | 666 void PaymentRequest::OnShippingAddressChange( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 m_completeTimer.stop(); | 826 m_completeTimer.stop(); |
| 812 m_completeResolver.clear(); | 827 m_completeResolver.clear(); |
| 813 m_showResolver.clear(); | 828 m_showResolver.clear(); |
| 814 m_abortResolver.clear(); | 829 m_abortResolver.clear(); |
| 815 if (m_clientBinding.is_bound()) | 830 if (m_clientBinding.is_bound()) |
| 816 m_clientBinding.Close(); | 831 m_clientBinding.Close(); |
| 817 m_paymentProvider.reset(); | 832 m_paymentProvider.reset(); |
| 818 } | 833 } |
| 819 | 834 |
| 820 } // namespace blink | 835 } // namespace blink |
| OLD | NEW |