| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const blink::PaymentDetailsModifier& input) { | 90 const blink::PaymentDetailsModifier& input) { |
| 91 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); | 91 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); |
| 92 output->supported_methods = | 92 output->supported_methods = |
| 93 WTF::Vector<WTF::String>(input.supportedMethods()); | 93 WTF::Vector<WTF::String>(input.supportedMethods()); |
| 94 | 94 |
| 95 if (input.hasTotal()) | 95 if (input.hasTotal()) |
| 96 output->total = PaymentItem::From(input.total()); | 96 output->total = PaymentItem::From(input.total()); |
| 97 else | 97 else |
| 98 output->total = PaymentItem::New(); | 98 output->total = PaymentItem::New(); |
| 99 | 99 |
| 100 if (input.hasAdditionalDisplayItems()) | 100 if (input.hasAdditionalDisplayItems()) { |
| 101 output->additional_display_items = | 101 for (size_t i = 0; i < input.additionalDisplayItems().size(); ++i) { |
| 102 mojo::WTFArray<PaymentItemPtr>::From(input.additionalDisplayItems()); | 102 output->additional_display_items.append( |
| 103 else | 103 PaymentItem::From(input.additionalDisplayItems()[i])); |
| 104 output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 104 } |
| 105 | 105 } |
| 106 return output; | 106 return output; |
| 107 } | 107 } |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 template <> | 110 template <> |
| 111 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { | 111 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { |
| 112 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) { | 112 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) { |
| 113 PaymentDetailsPtr output = PaymentDetails::New(); | 113 PaymentDetailsPtr output = PaymentDetails::New(); |
| 114 output->total = PaymentItem::From(input.total()); | 114 output->total = PaymentItem::From(input.total()); |
| 115 | 115 |
| 116 if (input.hasDisplayItems()) | 116 if (input.hasDisplayItems()) { |
| 117 output->display_items = | 117 for (size_t i = 0; i < input.displayItems().size(); ++i) { |
| 118 mojo::WTFArray<PaymentItemPtr>::From(input.displayItems()); | 118 output->display_items.append( |
| 119 else | 119 PaymentItem::From(input.displayItems()[i])); |
| 120 output->display_items = mojo::WTFArray<PaymentItemPtr>::New(0); | 120 } |
| 121 } |
| 121 | 122 |
| 122 if (input.hasShippingOptions()) | 123 if (input.hasShippingOptions()) { |
| 123 output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>::From( | 124 for (size_t i = 0; i < input.shippingOptions().size(); ++i) { |
| 124 input.shippingOptions()); | 125 output->shipping_options.append( |
| 125 else | 126 PaymentShippingOption::From(input.shippingOptions()[i])); |
| 126 output->shipping_options = | 127 } |
| 127 mojo::WTFArray<PaymentShippingOptionPtr>::New(0); | 128 } |
| 128 | 129 |
| 129 if (input.hasModifiers()) | 130 if (input.hasModifiers()) { |
| 130 output->modifiers = | 131 for (size_t i = 0; i < input.modifiers().size(); ++i) { |
| 131 mojo::WTFArray<PaymentDetailsModifierPtr>::From(input.modifiers()); | 132 output->modifiers.append( |
| 132 else | 133 PaymentDetailsModifier::From(input.modifiers()[i])); |
| 133 output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::New(0); | 134 } |
| 135 } |
| 134 | 136 |
| 135 if (input.hasError()) | 137 if (input.hasError()) |
| 136 output->error = input.error(); | 138 output->error = input.error(); |
| 137 else | 139 else |
| 138 output->error = WTF::emptyString(); | 140 output->error = WTF::emptyString(); |
| 139 | 141 |
| 140 return output; | 142 return output; |
| 141 } | 143 } |
| 142 }; | 144 }; |
| 143 | 145 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (ownerElement && isHTMLIFrameElement(ownerElement)) { | 454 if (ownerElement && isHTMLIFrameElement(ownerElement)) { |
| 453 HTMLIFrameElement* iframe = toHTMLIFrameElement(ownerElement); | 455 HTMLIFrameElement* iframe = toHTMLIFrameElement(ownerElement); |
| 454 if (HTMLIFrameElementPayments::from(*iframe).allowPaymentRequest(*iframe)) | 456 if (HTMLIFrameElementPayments::from(*iframe).allowPaymentRequest(*iframe)) |
| 455 return allowedToUsePaymentRequest(frame->tree().parent()); | 457 return allowedToUsePaymentRequest(frame->tree().parent()); |
| 456 } | 458 } |
| 457 | 459 |
| 458 // 4. Return false. | 460 // 4. Return false. |
| 459 return false; | 461 return false; |
| 460 } | 462 } |
| 461 | 463 |
| 464 WTF::Vector<mojom::blink::PaymentMethodDataPtr> ConvertPaymentMethodData( |
| 465 const Vector<PaymentRequest::MethodData>& blinkMethods) { |
| 466 WTF::Vector<mojom::blink::PaymentMethodDataPtr> mojoMethods( |
| 467 blinkMethods.size()); |
| 468 for (size_t i = 0; i < blinkMethods.size(); ++i) { |
| 469 mojoMethods[i] = mojom::blink::PaymentMethodData::New(); |
| 470 mojoMethods[i]->supported_methods = |
| 471 WTF::Vector<WTF::String>(blinkMethods[i].supportedMethods); |
| 472 mojoMethods[i]->stringified_data = blinkMethods[i].stringifiedData; |
| 473 } |
| 474 return mojoMethods; |
| 475 } |
| 476 |
| 462 } // namespace | 477 } // namespace |
| 463 | 478 |
| 464 PaymentRequest* PaymentRequest::create( | 479 PaymentRequest* PaymentRequest::create( |
| 465 ScriptState* scriptState, | 480 ScriptState* scriptState, |
| 466 const HeapVector<PaymentMethodData>& methodData, | 481 const HeapVector<PaymentMethodData>& methodData, |
| 467 const PaymentDetails& details, | 482 const PaymentDetails& details, |
| 468 ExceptionState& exceptionState) { | 483 ExceptionState& exceptionState) { |
| 469 return new PaymentRequest(scriptState, methodData, details, PaymentOptions(), | 484 return new PaymentRequest(scriptState, methodData, details, PaymentOptions(), |
| 470 exceptionState); | 485 exceptionState); |
| 471 } | 486 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 m_shippingType = getValidShippingType(m_options.shippingType()); | 676 m_shippingType = getValidShippingType(m_options.shippingType()); |
| 662 } | 677 } |
| 663 | 678 |
| 664 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( | 679 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( |
| 665 mojo::GetProxy(&m_paymentProvider)); | 680 mojo::GetProxy(&m_paymentProvider)); |
| 666 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( | 681 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( |
| 667 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), | 682 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), |
| 668 mojom::blink::PaymentErrorReason::UNKNOWN))); | 683 mojom::blink::PaymentErrorReason::UNKNOWN))); |
| 669 m_paymentProvider->Init( | 684 m_paymentProvider->Init( |
| 670 m_clientBinding.CreateInterfacePtrAndBind(), | 685 m_clientBinding.CreateInterfacePtrAndBind(), |
| 671 mojo::WTFArray<mojom::blink::PaymentMethodDataPtr>::From( | 686 ConvertPaymentMethodData(validatedMethodData), |
| 672 validatedMethodData), | |
| 673 maybeKeepShippingOptions( | 687 maybeKeepShippingOptions( |
| 674 mojom::blink::PaymentDetails::From(details), | 688 mojom::blink::PaymentDetails::From(details), |
| 675 keepShippingOptions && m_options.requestShipping()), | 689 keepShippingOptions && m_options.requestShipping()), |
| 676 mojom::blink::PaymentOptions::From(m_options)); | 690 mojom::blink::PaymentOptions::From(m_options)); |
| 677 } | 691 } |
| 678 | 692 |
| 679 void PaymentRequest::contextDestroyed() { | 693 void PaymentRequest::contextDestroyed() { |
| 680 clearResolversAndCloseMojoConnection(); | 694 clearResolversAndCloseMojoConnection(); |
| 681 } | 695 } |
| 682 | 696 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 m_completeTimer.stop(); | 857 m_completeTimer.stop(); |
| 844 m_completeResolver.clear(); | 858 m_completeResolver.clear(); |
| 845 m_showResolver.clear(); | 859 m_showResolver.clear(); |
| 846 m_abortResolver.clear(); | 860 m_abortResolver.clear(); |
| 847 if (m_clientBinding.is_bound()) | 861 if (m_clientBinding.is_bound()) |
| 848 m_clientBinding.Close(); | 862 m_clientBinding.Close(); |
| 849 m_paymentProvider.reset(); | 863 m_paymentProvider.reset(); |
| 850 } | 864 } |
| 851 | 865 |
| 852 } // namespace blink | 866 } // namespace blink |
| OLD | NEW |