diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/payments')
75 files changed, 971 insertions, 836 deletions
diff --git a/chromium/third_party/blink/renderer/modules/payments/BUILD.gn b/chromium/third_party/blink/renderer/modules/payments/BUILD.gn index 7a61f03750c..7fd286a66b2 100644 --- a/chromium/third_party/blink/renderer/modules/payments/BUILD.gn +++ b/chromium/third_party/blink/renderer/modules/payments/BUILD.gn @@ -10,6 +10,8 @@ blink_modules_sources("payments") { "abort_payment_event.h", "abort_payment_respond_with_observer.cc", "abort_payment_respond_with_observer.h", + "address_init_type_converter.cc", + "address_init_type_converter.h", "basic_card_helper.cc", "basic_card_helper.h", "can_make_payment_event.cc", @@ -22,8 +24,6 @@ blink_modules_sources("payments") { "merchant_validation_event.h", "payment_address.cc", "payment_address.h", - "payment_address_init_type_converter.cc", - "payment_address_init_type_converter.h", "payment_app_service_worker_global_scope.h", "payment_app_service_worker_registration.cc", "payment_app_service_worker_registration.h", @@ -62,7 +62,5 @@ blink_modules_sources("payments") { ] } - deps = [ - "//components/payments/mojom:mojom_blink", - ] + deps = [ "//components/payments/mojom:mojom_blink" ] } diff --git a/chromium/third_party/blink/renderer/modules/payments/DEPS b/chromium/third_party/blink/renderer/modules/payments/DEPS index ffd1489d709..a7c0a85b25e 100644 --- a/chromium/third_party/blink/renderer/modules/payments/DEPS +++ b/chromium/third_party/blink/renderer/modules/payments/DEPS @@ -1,5 +1,3 @@ include_rules = [ "+components/payments/mojom", - "+mojo/public/cpp/bindings/binding.h", - "+mojo/public/cpp/bindings/interface_request.h", ] diff --git a/chromium/third_party/blink/renderer/modules/payments/OWNERS b/chromium/third_party/blink/renderer/modules/payments/OWNERS index c7040d66ea4..3bc3573d3eb 100644 --- a/chromium/third_party/blink/renderer/modules/payments/OWNERS +++ b/chromium/third_party/blink/renderer/modules/payments/OWNERS @@ -1,12 +1,13 @@ -# TEAM: paymentrequest@chromium.org +# TEAM: payments-dev@chromium.org # COMPONENT: Blink>Payments +file://components/payments/OWNERS + jinho.bang@samsung.com -mathp@chromium.org mek@chromium.org -rouslan@chromium.org -danyao@chromium.org -sahel@chromium.org per-file *_type_converter*.*=set noparent per-file *_type_converter*.*=file://ipc/SECURITY_OWNERS + +# Emeritus +mathp@chromium.org diff --git a/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.cc b/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.cc index 99dcad8a830..eccca7e5b28 100644 --- a/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.cc +++ b/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.cc @@ -6,8 +6,8 @@ #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_extendable_event_init.h" #include "third_party/blink/renderer/modules/event_modules.h" -#include "third_party/blink/renderer/modules/service_worker/extendable_event_init.h" #include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h" #include "third_party/blink/renderer/modules/service_worker/wait_until_observer.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" @@ -47,7 +47,7 @@ void AbortPaymentEvent::respondWith(ScriptState* script_state, } } -void AbortPaymentEvent::Trace(blink::Visitor* visitor) { +void AbortPaymentEvent::Trace(Visitor* visitor) { visitor->Trace(observer_); ExtendableEvent::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.h b/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.h index 06bfa035529..43716808d9e 100644 --- a/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.h +++ b/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.h @@ -42,7 +42,7 @@ class MODULES_EXPORT AbortPaymentEvent final : public ExtendableEvent { void respondWith(ScriptState*, ScriptPromise, ExceptionState&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<RespondWithObserver> observer_; diff --git a/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.idl b/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.idl index e1cd327f99c..0bb4311eb72 100644 --- a/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.idl +++ b/chromium/third_party/blink/renderer/modules/payments/abort_payment_event.idl @@ -6,8 +6,8 @@ [ RuntimeEnabled=PaymentApp, - Constructor(DOMString type, ExtendableEventInit eventInitDict), Exposed=ServiceWorker ] interface AbortPaymentEvent : ExtendableEvent { + constructor(DOMString type, ExtendableEventInit eventInitDict); [CallWith=ScriptState, RaisesException] void respondWith(Promise<boolean> paymentAbortedResponse); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.cc b/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.cc index c1b726fc76c..64212d5be81 100644 --- a/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.cc +++ b/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.cc @@ -57,7 +57,7 @@ void AbortPaymentRespondWithObserver::OnNoResponse() { ->RespondToAbortPaymentEvent(event_id_, false); } -void AbortPaymentRespondWithObserver::Trace(blink::Visitor* visitor) { +void AbortPaymentRespondWithObserver::Trace(Visitor* visitor) { RespondWithObserver::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.h b/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.h index 112e23f1d28..da44a5a0102 100644 --- a/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.h +++ b/chromium/third_party/blink/renderer/modules/payments/abort_payment_respond_with_observer.h @@ -33,7 +33,7 @@ class MODULES_EXPORT AbortPaymentRespondWithObserver final const char* property_name) override; void OnNoResponse() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/payments/abort_test.cc b/chromium/third_party/blink/renderer/modules/payments/abort_test.cc index 744bf207dc1..0e1963d90d8 100644 --- a/chromium/third_party/blink/renderer/modules/payments/abort_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/abort_test.cc @@ -8,6 +8,7 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/modules/payments/payment_request.h" #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" +#include "third_party/blink/renderer/platform/bindings/exception_code.h" namespace blink { namespace { @@ -16,28 +17,28 @@ namespace { // abort() should reject with exception. TEST(AbortTest, CannotAbortBeforeShow) { PaymentRequestV8TestingScope scope; - PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->abort(scope.GetScriptState()) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->abort(scope.GetScriptState(), scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } // If request.abort() is called again before the previous abort() resolved, then // the second abort() should reject with exception. TEST(AbortTest, CannotAbortTwiceConcurrently) { PaymentRequestV8TestingScope scope; - PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - request->show(scope.GetScriptState()); - request->abort(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION); - request->abort(scope.GetScriptState()) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->abort(scope.GetScriptState(), scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } // If request.abort() is called after calling request.show(), then abort() @@ -47,10 +48,10 @@ TEST(AbortTest, CanAbortAfterShow) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); - request->abort(scope.GetScriptState()) + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); } @@ -61,10 +62,10 @@ TEST(AbortTest, FailedAbortShouldRejectAbortPromise) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); - request->abort(scope.GetScriptState()) + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( @@ -78,13 +79,13 @@ TEST(AbortTest, CanAbortAgainAfterFirstAbortRejected) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - request->show(scope.GetScriptState()); - request->abort(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( false); - request->abort(scope.GetScriptState()) + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); } @@ -95,11 +96,11 @@ TEST(AbortTest, SuccessfulAbortShouldRejectShowPromiseAndResolveAbortPromise) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); - request->abort(scope.GetScriptState()) + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_address_init.idl b/chromium/third_party/blink/renderer/modules/payments/address_init.idl index fb7733fa217..bd1dc3d456e 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_address_init.idl +++ b/chromium/third_party/blink/renderer/modules/payments/address_init.idl @@ -4,7 +4,7 @@ // https://w3c.github.io/payment-request/#dom-addressinit -dictionary PaymentAddressInit { +dictionary AddressInit { DOMString country; sequence<DOMString> addressLine; DOMString region; @@ -15,4 +15,4 @@ dictionary PaymentAddressInit { DOMString organization; DOMString recipient; DOMString phone; -};
\ No newline at end of file +}; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_address_init_type_converter.cc b/chromium/third_party/blink/renderer/modules/payments/address_init_type_converter.cc index a983a133f4d..21fc8270d17 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_address_init_type_converter.cc +++ b/chromium/third_party/blink/renderer/modules/payments/address_init_type_converter.cc @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "third_party/blink/renderer/modules/payments/payment_address_init_type_converter.h" +#include "third_party/blink/renderer/modules/payments/address_init_type_converter.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace mojo { -payments::mojom::blink::PaymentAddressPtr TypeConverter< - payments::mojom::blink::PaymentAddressPtr, - blink::PaymentAddressInit*>::Convert(const blink::PaymentAddressInit* - input) { +payments::mojom::blink::PaymentAddressPtr +TypeConverter<payments::mojom::blink::PaymentAddressPtr, + blink::AddressInit*>::Convert(const blink::AddressInit* input) { payments::mojom::blink::PaymentAddressPtr output = payments::mojom::blink::PaymentAddress::New(); output->country = input->hasCountry() ? input->country() : g_empty_string; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_address_init_type_converter.h b/chromium/third_party/blink/renderer/modules/payments/address_init_type_converter.h index f857842673c..10dff24f9fd 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_address_init_type_converter.h +++ b/chromium/third_party/blink/renderer/modules/payments/address_init_type_converter.h @@ -2,22 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_ADDRESS_INIT_TYPE_CONVERTER_H_ -#define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_ADDRESS_INIT_TYPE_CONVERTER_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_ADDRESS_INIT_TYPE_CONVERTER_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_ADDRESS_INIT_TYPE_CONVERTER_H_ #include "components/payments/mojom/payment_request_data.mojom-blink.h" #include "mojo/public/cpp/bindings/type_converter.h" -#include "third_party/blink/renderer/modules/payments/payment_address_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_init.h" namespace mojo { template <> struct TypeConverter<payments::mojom::blink::PaymentAddressPtr, - blink::PaymentAddressInit*> { + blink::AddressInit*> { static payments::mojom::blink::PaymentAddressPtr Convert( - const blink::PaymentAddressInit* input); + const blink::AddressInit* input); }; } // namespace mojo -#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_ADDRESS_INIT_TYPE_CONVERTER_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_ADDRESS_INIT_TYPE_CONVERTER_H_ diff --git a/chromium/third_party/blink/renderer/modules/payments/android_pay_method_data.idl b/chromium/third_party/blink/renderer/modules/payments/android_pay_method_data.idl index ad52173b460..301c118d885 100644 --- a/chromium/third_party/blink/renderer/modules/payments/android_pay_method_data.idl +++ b/chromium/third_party/blink/renderer/modules/payments/android_pay_method_data.idl @@ -7,10 +7,6 @@ dictionary AndroidPayMethodData { DOMString environment; - DOMString merchantName; - DOMString merchantId; - sequence<DOMString> allowedCardNetworks; - AndroidPayTokenization paymentMethodTokenizationParameters; DOMString minGooglePlayServicesVersion; long apiVersion; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/android_pay_tokenization.idl b/chromium/third_party/blink/renderer/modules/payments/android_pay_tokenization.idl deleted file mode 100644 index dfd76880731..00000000000 --- a/chromium/third_party/blink/renderer/modules/payments/android_pay_tokenization.idl +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// https://developers.google.com/web/fundamentals/getting-started/primers/payment-request/android-pay -// TODO(rouslan): Stop parsing Android Pay data. http://crbug.com/620173 - -dictionary AndroidPayTokenization { - DOMString tokenizationType; - Dictionary parameters; -}; diff --git a/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.cc b/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.cc index 96d7c5fd9c5..042ba904134 100644 --- a/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.cc +++ b/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.cc @@ -5,8 +5,8 @@ #include "third_party/blink/renderer/modules/payments/basic_card_helper.h" #include "base/stl_util.h" +#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_basic_card_request.h" -#include "third_party/blink/renderer/modules/payments/basic_card_request.h" #include "third_party/blink/renderer/modules/payments/payment_request.h" namespace blink { @@ -14,7 +14,6 @@ namespace blink { namespace { using ::payments::mojom::blink::BasicCardNetwork; -using ::payments::mojom::blink::BasicCardType; const struct { const payments::mojom::BasicCardNetwork code; @@ -28,26 +27,17 @@ const struct { {BasicCardNetwork::UNIONPAY, "unionpay"}, {BasicCardNetwork::VISA, "visa"}}; -const struct { - const BasicCardType code; - const char* const name; -} kBasicCardTypes[] = {{BasicCardType::CREDIT, "credit"}, - {BasicCardType::DEBIT, "debit"}, - {BasicCardType::PREPAID, "prepaid"}}; - } // namespace void BasicCardHelper::ParseBasiccardData( const ScriptValue& input, Vector<BasicCardNetwork>& supported_networks_output, - Vector<BasicCardType>& supported_types_output, - bool* has_supported_card_types, ExceptionState& exception_state) { DCHECK(!input.IsEmpty()); - BasicCardRequest* basic_card = BasicCardRequest::Create(); - V8BasicCardRequest::ToImpl(input.GetIsolate(), input.V8Value(), basic_card, - exception_state); + BasicCardRequest* basic_card = + NativeValueTraits<BasicCardRequest>::NativeValue( + input.GetIsolate(), input.V8Value(), exception_state); if (exception_state.HadException()) return; @@ -67,27 +57,6 @@ void BasicCardHelper::ParseBasiccardData( } } } - - if (basic_card->hasSupportedTypes()) { - if (has_supported_card_types) { - *has_supported_card_types = true; - } - - if (basic_card->supportedTypes().size() > PaymentRequest::kMaxListSize) { - exception_state.ThrowTypeError( - "basic-card supportedTypes cannot be longer than 1024 elements"); - return; - } - - for (const String& type : basic_card->supportedTypes()) { - for (size_t i = 0; i < base::size(kBasicCardTypes); ++i) { - if (type == kBasicCardTypes[i].name) { - supported_types_output.push_back(kBasicCardTypes[i].code); - break; - } - } - } - } } bool BasicCardHelper::IsNetworkName(const String& input) { diff --git a/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.h b/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.h index 67b7a83f3da..647f49315ae 100644 --- a/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.h +++ b/chromium/third_party/blink/renderer/modules/payments/basic_card_helper.h @@ -18,17 +18,11 @@ class BasicCardHelper { public: // Parse 'basic-card' data in |input| and store result in - // |supported_networks_output| and |supported_types_output| or throw - // exception. - // - // If |has_supported_card_types| is not null, then it is set to true if the - // basic-card specific method data has the "supportedTypes" field. + // |supported_networks_output| or throw exception. static void ParseBasiccardData( const ScriptValue& input, Vector<::payments::mojom::blink::BasicCardNetwork>& supported_networks_output, - Vector<::payments::mojom::blink::BasicCardType>& supported_types_output, - bool* has_supported_card_types, ExceptionState&); // Check whether |input| is 'basic-card' network name. diff --git a/chromium/third_party/blink/renderer/modules/payments/basic_card_request.idl b/chromium/third_party/blink/renderer/modules/payments/basic_card_request.idl index 9bd0aeb9b2b..98d9b5d47ca 100644 --- a/chromium/third_party/blink/renderer/modules/payments/basic_card_request.idl +++ b/chromium/third_party/blink/renderer/modules/payments/basic_card_request.idl @@ -2,15 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// https://w3c.github.io/webpayments-methods-card/#basiccardrequest - -enum BasicCardType { - "credit", - "debit", - "prepaid" -}; +// https://w3c.github.io/payment-method-basic-card/#basiccardrequest-dictionary dictionary BasicCardRequest { - sequence<DOMString> supportedNetworks; - sequence<BasicCardType> supportedTypes; + sequence<DOMString> supportedNetworks = []; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.cc b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.cc index f30ba000e7d..f78a31117f9 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.cc +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.cc @@ -8,7 +8,7 @@ #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_location.h" -#include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h" +#include "third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" @@ -24,7 +24,7 @@ CanMakePaymentEvent* CanMakePaymentEvent::Create( CanMakePaymentEvent* CanMakePaymentEvent::Create( const AtomicString& type, const CanMakePaymentEventInit* initializer, - RespondWithObserver* respond_with_observer, + CanMakePaymentRespondWithObserver* respond_with_observer, WaitUntilObserver* wait_until_observer) { return MakeGarbageCollected<CanMakePaymentEvent>( type, initializer, respond_with_observer, wait_until_observer); @@ -57,20 +57,23 @@ CanMakePaymentEvent::modifiers() const { void CanMakePaymentEvent::respondWith(ScriptState* script_state, ScriptPromise script_promise, ExceptionState& exception_state) { - if (!isTrusted()) { - exception_state.ThrowDOMException( - DOMExceptionCode::kInvalidStateError, - "Cannot respond with data when the event is not trusted"); - return; - } + RespondToCanMakePaymentEvent(script_state, script_promise, exception_state, + /*is_minimal_ui=*/false); +} - stopImmediatePropagation(); - if (observer_) { - observer_->RespondWith(script_state, script_promise, exception_state); - } +const String& CanMakePaymentEvent::currency() const { + return currency_; +} + +void CanMakePaymentEvent::respondWithMinimalUI( + ScriptState* script_state, + ScriptPromise script_promise, + ExceptionState& exception_state) { + RespondToCanMakePaymentEvent(script_state, script_promise, exception_state, + /*is_minimal_ui=*/true); } -void CanMakePaymentEvent::Trace(blink::Visitor* visitor) { +void CanMakePaymentEvent::Trace(Visitor* visitor) { visitor->Trace(method_data_); visitor->Trace(modifiers_); visitor->Trace(observer_); @@ -80,7 +83,7 @@ void CanMakePaymentEvent::Trace(blink::Visitor* visitor) { CanMakePaymentEvent::CanMakePaymentEvent( const AtomicString& type, const CanMakePaymentEventInit* initializer, - RespondWithObserver* respond_with_observer, + CanMakePaymentRespondWithObserver* respond_with_observer, WaitUntilObserver* wait_until_observer) : ExtendableEvent(type, initializer, wait_until_observer), top_origin_(initializer->topOrigin()), @@ -91,6 +94,26 @@ CanMakePaymentEvent::CanMakePaymentEvent( modifiers_(initializer->hasModifiers() ? initializer->modifiers() : HeapVector<Member<PaymentDetailsModifier>>()), + currency_(initializer->currency()), observer_(respond_with_observer) {} +void CanMakePaymentEvent::RespondToCanMakePaymentEvent( + ScriptState* script_state, + ScriptPromise script_promise, + ExceptionState& exception_state, + bool is_minimal_ui) { + if (!isTrusted()) { + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "Cannot respond with data when the event is not trusted"); + return; + } + + stopImmediatePropagation(); + if (observer_) { + observer_->ObservePromiseResponse(script_state, script_promise, + exception_state, is_minimal_ui); + } +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.h b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.h index 32a0ffaaab5..42d84b9f54a 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.h +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.h @@ -7,10 +7,10 @@ #include "base/macros.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_can_make_payment_event_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_modifier.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" #include "third_party/blink/renderer/modules/event_modules.h" -#include "third_party/blink/renderer/modules/payments/can_make_payment_event_init.h" -#include "third_party/blink/renderer/modules/payments/payment_details_modifier.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" #include "third_party/blink/renderer/modules/service_worker/extendable_event.h" #include "third_party/blink/renderer/platform/heap/handle.h" @@ -20,7 +20,7 @@ class AtomicString; namespace blink { -class RespondWithObserver; +class CanMakePaymentRespondWithObserver; class ScriptState; class MODULES_EXPORT CanMakePaymentEvent final : public ExtendableEvent { @@ -31,12 +31,12 @@ class MODULES_EXPORT CanMakePaymentEvent final : public ExtendableEvent { const CanMakePaymentEventInit*); static CanMakePaymentEvent* Create(const AtomicString& type, const CanMakePaymentEventInit*, - RespondWithObserver*, + CanMakePaymentRespondWithObserver*, WaitUntilObserver*); CanMakePaymentEvent(const AtomicString& type, const CanMakePaymentEventInit*, - RespondWithObserver*, + CanMakePaymentRespondWithObserver*, WaitUntilObserver*); ~CanMakePaymentEvent() override; @@ -49,15 +49,24 @@ class MODULES_EXPORT CanMakePaymentEvent final : public ExtendableEvent { void respondWith(ScriptState*, ScriptPromise, ExceptionState&); - void Trace(blink::Visitor*) override; + const String& currency() const; + void respondWithMinimalUI(ScriptState*, ScriptPromise, ExceptionState&); + + void Trace(Visitor*) override; private: + void RespondToCanMakePaymentEvent(ScriptState*, + ScriptPromise, + ExceptionState&, + bool is_minimal_ui); + String top_origin_; String payment_request_origin_; HeapVector<Member<PaymentMethodData>> method_data_; HeapVector<Member<PaymentDetailsModifier>> modifiers_; + String currency_; - Member<RespondWithObserver> observer_; + Member<CanMakePaymentRespondWithObserver> observer_; DISALLOW_COPY_AND_ASSIGN(CanMakePaymentEvent); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.idl b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.idl index b56ea70f03f..9f08ffdabcc 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.idl +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event.idl @@ -2,17 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// https://github.com/w3c/payment-handler/pull/170 +// https://w3c.github.io/payment-handler/#the-canmakepaymentevent [ RuntimeEnabled=PaymentApp, - Constructor(DOMString type, CanMakePaymentEventInit eventInitDict), Exposed=ServiceWorker ] interface CanMakePaymentEvent : ExtendableEvent { + constructor(DOMString type, CanMakePaymentEventInit eventInitDict); readonly attribute USVString topOrigin; readonly attribute USVString paymentRequestOrigin; readonly attribute FrozenArray<PaymentMethodData> methodData; readonly attribute FrozenArray<PaymentDetailsModifier> modifiers; [CallWith=ScriptState, RaisesException] void respondWith(Promise<boolean> canMakePaymentResponse); + + // https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c + [RuntimeEnabled=PaymentHandlerMinimalUI] readonly attribute DOMString currency; + [RuntimeEnabled=PaymentHandlerMinimalUI, CallWith=ScriptState, RaisesException] void respondWithMinimalUI(Promise<CanMakePaymentResponse> response); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event_init.idl b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event_init.idl index aed5b687b5a..e7d2240a6dd 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event_init.idl +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_event_init.idl @@ -9,4 +9,7 @@ dictionary CanMakePaymentEventInit : ExtendableEventInit { USVString paymentRequestOrigin; sequence<PaymentMethodData> methodData; sequence<PaymentDetailsModifier> modifiers; + + // https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c + DOMString currency; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.cc b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.cc index 6bcf47031e8..0b11a249f30 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.cc +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.cc @@ -6,14 +6,22 @@ #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_can_make_payment_response.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" +#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/modules/payments/payment_handler_utils.h" +#include "third_party/blink/renderer/modules/payments/payments_validators.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h" #include "third_party/blink/renderer/modules/service_worker/wait_until_observer.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "v8/include/v8.h" namespace blink { +namespace { + +using ResponseType = payments::mojom::blink::CanMakePaymentEventResponseType; + +} // namespace CanMakePaymentRespondWithObserver::CanMakePaymentRespondWithObserver( ExecutionContext* context, @@ -22,12 +30,14 @@ CanMakePaymentRespondWithObserver::CanMakePaymentRespondWithObserver( : RespondWithObserver(context, event_id, observer) {} void CanMakePaymentRespondWithObserver::OnResponseRejected( - blink::mojom::ServiceWorkerResponseError error) { + mojom::blink::ServiceWorkerResponseError error) { PaymentHandlerUtils::ReportResponseError(GetExecutionContext(), "CanMakePaymentEvent", error); - - To<ServiceWorkerGlobalScope>(GetExecutionContext()) - ->RespondToCanMakePaymentEvent(event_id_, false); + RespondWithoutMinimalUI( + error == mojom::blink::ServiceWorkerResponseError::kPromiseRejected + ? ResponseType::REJECT + : ResponseType::INTERNAL_ERROR, + false); } void CanMakePaymentRespondWithObserver::OnResponseFulfilled( @@ -39,26 +49,120 @@ void CanMakePaymentRespondWithObserver::OnResponseFulfilled( DCHECK(GetExecutionContext()); ExceptionState exception_state(script_state->GetIsolate(), context_type, interface_name, property_name); - bool response = + if (is_minimal_ui_) { + OnResponseFulfilledForMinimalUI(script_state, value, exception_state); + return; + } + + bool can_make_payment = ToBoolean(script_state->GetIsolate(), value.V8Value(), exception_state); if (exception_state.HadException()) { - exception_state.ClearException(); - OnResponseRejected(blink::mojom::ServiceWorkerResponseError::kNoV8Instance); + RespondWithoutMinimalUI(ResponseType::BOOLEAN_CONVERSION_ERROR, false); return; } - To<ServiceWorkerGlobalScope>(GetExecutionContext()) - ->RespondToCanMakePaymentEvent(event_id_, response); + RespondWithoutMinimalUI(ResponseType::SUCCESS, can_make_payment); } void CanMakePaymentRespondWithObserver::OnNoResponse() { - DCHECK(GetExecutionContext()); - To<ServiceWorkerGlobalScope>(GetExecutionContext()) - ->RespondToCanMakePaymentEvent(event_id_, true); + ConsoleWarning( + "To control whether your payment handler can be used, handle the " + "'canmakepayment' event explicitly. Otherwise, it is assumed implicitly " + "that your payment handler can always be used."); + RespondWithoutMinimalUI(ResponseType::NO_RESPONSE, true); } -void CanMakePaymentRespondWithObserver::Trace(blink::Visitor* visitor) { +void CanMakePaymentRespondWithObserver::Trace(Visitor* visitor) { RespondWithObserver::Trace(visitor); } +void CanMakePaymentRespondWithObserver::ObservePromiseResponse( + ScriptState* script_state, + ScriptPromise promise, + ExceptionState& exception_state, + bool is_minimal_ui) { + is_minimal_ui_ = is_minimal_ui; + RespondWith(script_state, promise, exception_state); +} + +void CanMakePaymentRespondWithObserver::OnResponseFulfilledForMinimalUI( + ScriptState* script_state, + const ScriptValue& value, + ExceptionState& exception_state) { + CanMakePaymentResponse* response = + NativeValueTraits<CanMakePaymentResponse>::NativeValue( + script_state->GetIsolate(), value.V8Value(), exception_state); + if (exception_state.HadException()) { + RespondWithoutMinimalUI(ResponseType::MINIMAL_UI_RESPONSE_CONVERSION_ERROR, + false); + return; + } + + if (!response->hasCanMakePayment()) { + ConsoleWarning( + "To use minimal UI, specify the value of 'canMakePayment' explicitly. " + "Otherwise, the value of 'false' is assumed implicitly."); + RespondWithoutMinimalUI(ResponseType::NO_CAN_MAKE_PAYMENT_VALUE, false); + return; + } + + if (!response->hasReadyForMinimalUI()) { + ConsoleWarning( + "To use minimal UI, specify the value of 'readyForMinimalUI' " + "explicitly. Otherwise, the value of 'false' is assumed implicitly."); + RespondWithoutMinimalUI(ResponseType::NO_READY_FOR_MINIMAL_UI_VALUE, + response->canMakePayment()); + return; + } + + if (!response->hasAccountBalance() || response->accountBalance().IsEmpty()) { + ConsoleWarning( + "To use minimal UI, specify 'accountBalance' value, e.g., '1.00'."); + RespondWithoutMinimalUI(ResponseType::NO_ACCOUNT_BALANCE_VALUE, + response->canMakePayment()); + return; + } + + String error_message; + if (!PaymentsValidators::IsValidAmountFormat( + response->accountBalance(), "account balance", &error_message)) { + ConsoleWarning(error_message + + ". To use minimal UI, format 'accountBalance' as, for " + "example, '1.00'."); + RespondWithoutMinimalUI(ResponseType::INVALID_ACCOUNT_BALANCE_VALUE, + response->canMakePayment()); + return; + } + + RespondInternal(ResponseType::SUCCESS, response->canMakePayment(), + response->readyForMinimalUI(), response->accountBalance()); +} + +void CanMakePaymentRespondWithObserver::ConsoleWarning(const String& message) { + GetExecutionContext()->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( + mojom::blink::ConsoleMessageSource::kJavaScript, + mojom::blink::ConsoleMessageLevel::kWarning, message)); +} + +void CanMakePaymentRespondWithObserver::RespondWithoutMinimalUI( + ResponseType response_type, + bool can_make_payment) { + RespondInternal(response_type, can_make_payment, + /*ready_for_minimal_ui=*/false, + /*account_balance=*/String()); +} + +void CanMakePaymentRespondWithObserver::RespondInternal( + ResponseType response_type, + bool can_make_payment, + bool ready_for_minimal_ui, + const String& account_balance) { + DCHECK(GetExecutionContext()); + To<ServiceWorkerGlobalScope>(GetExecutionContext()) + ->RespondToCanMakePaymentEvent( + event_id_, payments::mojom::blink::CanMakePaymentResponse::New( + response_type, can_make_payment, ready_for_minimal_ui, + account_balance)); +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.h b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.h index 4adbd591a0f..41a0b5ca480 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.h +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_respond_with_observer.h @@ -5,6 +5,7 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_CAN_MAKE_PAYMENT_RESPOND_WITH_OBSERVER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_CAN_MAKE_PAYMENT_RESPOND_WITH_OBSERVER_H_ +#include "third_party/blink/public/mojom/payments/payment_app.mojom-blink.h" #include "third_party/blink/public/mojom/service_worker/service_worker_error_type.mojom-blink-forward.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h" @@ -15,8 +16,9 @@ class ExecutionContext; class ScriptValue; class WaitUntilObserver; -// Implementation for CanMakePaymentEvent.respondWith(), which is used by the -// payment handler to indicate whether it can respond to a payment request. +// Implementation for CanMakePaymentEvent.respondWith() and +// CanMakePayment.respondWithMinimalUI(), which are used by the payment handler +// to indicate whether it can respond to a payment request. class MODULES_EXPORT CanMakePaymentRespondWithObserver final : public RespondWithObserver { public: @@ -25,7 +27,7 @@ class MODULES_EXPORT CanMakePaymentRespondWithObserver final WaitUntilObserver*); ~CanMakePaymentRespondWithObserver() override = default; - void OnResponseRejected(mojom::ServiceWorkerResponseError) override; + void OnResponseRejected(mojom::blink::ServiceWorkerResponseError) override; void OnResponseFulfilled(ScriptState*, const ScriptValue&, ExceptionState::ContextType, @@ -33,7 +35,31 @@ class MODULES_EXPORT CanMakePaymentRespondWithObserver final const char* property_name) override; void OnNoResponse() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; + + // Observes the given promise and calls OnResponseRejected() or + // OnResponseFulfilled(). + void ObservePromiseResponse(ScriptState*, + ScriptPromise, + ExceptionState&, + bool is_minimal_ui); + + private: + void OnResponseFulfilledForMinimalUI(ScriptState*, + const ScriptValue&, + ExceptionState&); + + void ConsoleWarning(const String& message); + void RespondWithoutMinimalUI( + payments::mojom::blink::CanMakePaymentEventResponseType response_type, + bool can_make_payment); + void RespondInternal( + payments::mojom::blink::CanMakePaymentEventResponseType response_type, + bool can_make_payment, + bool ready_for_minimal_ui, + const String& account_balance); + + bool is_minimal_ui_ = false; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_response.idl b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_response.idl new file mode 100644 index 00000000000..6d28b324374 --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_response.idl @@ -0,0 +1,11 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c + +dictionary CanMakePaymentResponse { + boolean canMakePayment; + boolean readyForMinimalUI; + DOMString accountBalance; +}; diff --git a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_test.cc b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_test.cc index aa8eee53e38..96b539aee6d 100644 --- a/chromium/third_party/blink/renderer/modules/payments/can_make_payment_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/can_make_payment_test.cc @@ -8,6 +8,7 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/modules/payments/payment_request.h" #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" +#include "third_party/blink/renderer/platform/bindings/exception_code.h" namespace blink { namespace { @@ -22,9 +23,9 @@ TEST(HasEnrolledInstrumentTest, RejectPromiseOnUserCancel) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->hasEnrolledInstrument(scope.GetScriptState()) + request->hasEnrolledInstrument(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<PaymentRequestClient*>(request)->OnError( @@ -36,9 +37,9 @@ TEST(HasEnrolledInstrumentTest, RejectPromiseOnUnknownError) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->hasEnrolledInstrument(scope.GetScriptState()) + request->hasEnrolledInstrument(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<PaymentRequestClient*>(request)->OnError( @@ -47,13 +48,14 @@ TEST(HasEnrolledInstrumentTest, RejectPromiseOnUnknownError) { TEST(HasEnrolledInstrumentTest, RejectDuplicateRequest) { PaymentRequestV8TestingScope scope; - PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - request->hasEnrolledInstrument(scope.GetScriptState()); - request->hasEnrolledInstrument(scope.GetScriptState()) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->hasEnrolledInstrument(scope.GetScriptState(), ASSERT_NO_EXCEPTION); + request->hasEnrolledInstrument(scope.GetScriptState(), + scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } TEST(HasEnrolledInstrumentTest, RejectQueryQuotaExceeded) { @@ -61,9 +63,9 @@ TEST(HasEnrolledInstrumentTest, RejectQueryQuotaExceeded) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->hasEnrolledInstrument(scope.GetScriptState()) + request->hasEnrolledInstrument(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<PaymentRequestClient*>(request)->OnHasEnrolledInstrument( @@ -75,9 +77,9 @@ TEST(HasEnrolledInstrumentTest, ReturnHasNoEnrolledInstrument) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String captor; - request->hasEnrolledInstrument(scope.GetScriptState()) + request->hasEnrolledInstrument(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(&captor), funcs.ExpectNoCall()); static_cast<PaymentRequestClient*>(request)->OnHasEnrolledInstrument( @@ -92,9 +94,9 @@ TEST(HasEnrolledInstrumentTest, ReturnHasEnrolledInstrument) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String captor; - request->hasEnrolledInstrument(scope.GetScriptState()) + request->hasEnrolledInstrument(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(&captor), funcs.ExpectNoCall()); static_cast<PaymentRequestClient*>(request)->OnHasEnrolledInstrument( @@ -109,9 +111,9 @@ TEST(CanMakePaymentTest, RejectPromiseOnUserCancel) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->canMakePayment(scope.GetScriptState()) + request->canMakePayment(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<PaymentRequestClient*>(request)->OnError( @@ -124,9 +126,9 @@ TEST(CanMakePaymentTest, RejectPromiseOnUnknownError) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->canMakePayment(scope.GetScriptState()) + request->canMakePayment(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<PaymentRequestClient*>(request)->OnError( @@ -135,14 +137,14 @@ TEST(CanMakePaymentTest, RejectPromiseOnUnknownError) { TEST(CanMakePaymentTest, RejectDuplicateRequest) { PaymentRequestV8TestingScope scope; - PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - request->canMakePayment(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->canMakePayment(scope.GetScriptState(), ASSERT_NO_EXCEPTION); - request->canMakePayment(scope.GetScriptState()) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->canMakePayment(scope.GetScriptState(), scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } TEST(CanMakePaymentTest, ReturnCannotMakePayment) { @@ -150,9 +152,9 @@ TEST(CanMakePaymentTest, ReturnCannotMakePayment) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String captor; - request->canMakePayment(scope.GetScriptState()) + request->canMakePayment(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(&captor), funcs.ExpectNoCall()); static_cast<PaymentRequestClient*>(request)->OnCanMakePayment( @@ -167,9 +169,9 @@ TEST(CanMakePaymentTest, ReturnCanMakePayment) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String captor; - request->canMakePayment(scope.GetScriptState()) + request->canMakePayment(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(&captor), funcs.ExpectNoCall()); static_cast<PaymentRequestClient*>(request)->OnCanMakePayment( diff --git a/chromium/third_party/blink/renderer/modules/payments/complete_test.cc b/chromium/third_party/blink/renderer/modules/payments/complete_test.cc index eb6d5eb7dcd..112020f7ef5 100644 --- a/chromium/third_party/blink/renderer/modules/payments/complete_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/complete_test.cc @@ -8,27 +8,28 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/modules/payments/payment_request.h" #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" +#include "third_party/blink/renderer/platform/bindings/exception_code.h" namespace blink { namespace { TEST(CompleteTest, CannotCallCompleteTwice) { PaymentRequestV8TestingScope scope; - PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); request->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kFail); + PaymentStateResolver::PaymentComplete::kFail, + ASSERT_NO_EXCEPTION); - request - ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->Complete(scope.GetScriptState(), + PaymentStateResolver::PaymentComplete::kSuccess, + scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } TEST(CompleteTest, ResolveCompletePromiseOnUnknownError) { @@ -36,15 +37,15 @@ TEST(CompleteTest, ResolveCompletePromiseOnUnknownError) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); request ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) + PaymentStateResolver::PaymentComplete::kSuccess, + ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( @@ -56,15 +57,15 @@ TEST(CompleteTest, ResolveCompletePromiseOnUserClosingUI) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); request ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) + PaymentStateResolver::PaymentComplete::kSuccess, + ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( @@ -76,22 +77,21 @@ TEST(CompleteTest, ResolveCompletePromiseOnUserClosingUI) { // should be rejected. TEST(CompleteTest, RejectCompletePromiseAfterError) { PaymentRequestV8TestingScope scope; - PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( payments::mojom::blink::PaymentErrorReason::USER_CANCEL, "User closed the UI."); - request - ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->Complete(scope.GetScriptState(), + PaymentStateResolver::PaymentComplete::kSuccess, + scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } TEST(CompleteTest, ResolvePromiseOnComplete) { @@ -99,15 +99,15 @@ TEST(CompleteTest, ResolvePromiseOnComplete) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); request ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) + PaymentStateResolver::PaymentComplete::kSuccess, + ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -119,9 +119,8 @@ TEST(CompleteTest, RejectCompletePromiseOnUpdateDetailsFailure) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()) + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); @@ -129,7 +128,8 @@ TEST(CompleteTest, RejectCompletePromiseOnUpdateDetailsFailure) { String error_message; request ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) + PaymentStateResolver::PaymentComplete::kSuccess, + ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); request->OnUpdatePaymentDetailsFailure("oops"); @@ -143,25 +143,23 @@ TEST(CompleteTest, RejectCompletePromiseAfterTimeout) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()) + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); request->OnCompleteTimeoutForTesting(); String error_message; - request - ->Complete(scope.GetScriptState(), - PaymentStateResolver::PaymentComplete::kSuccess) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); + request->Complete(scope.GetScriptState(), + PaymentStateResolver::PaymentComplete::kSuccess, + scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate()); - EXPECT_EQ( - "InvalidStateError: Timed out after 60 seconds, complete() called too " - "late", - error_message); + EXPECT_EQ("Timed out after 60 seconds, complete() called too late", + scope.GetExceptionState().Message()); } } // namespace diff --git a/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.cc b/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.cc index 0170596ef7d..09752416771 100644 --- a/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.cc +++ b/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.cc @@ -18,15 +18,15 @@ const char HTMLIFrameElementPayments::kSupplementName[] = // static bool HTMLIFrameElementPayments::FastHasAttribute( - const QualifiedName& name, - const HTMLIFrameElement& element) { + const HTMLIFrameElement& element, + const QualifiedName& name) { DCHECK(name == html_names::kAllowpaymentrequestAttr); return element.FastHasAttribute(name); } // static -void HTMLIFrameElementPayments::SetBooleanAttribute(const QualifiedName& name, - HTMLIFrameElement& element, +void HTMLIFrameElementPayments::SetBooleanAttribute(HTMLIFrameElement& element, + const QualifiedName& name, bool value) { DCHECK(name == html_names::kAllowpaymentrequestAttr); element.SetBooleanAttribute(name, value); @@ -51,7 +51,7 @@ bool HTMLIFrameElementPayments::AllowPaymentRequest( element.FastHasAttribute(html_names::kAllowpaymentrequestAttr); } -void HTMLIFrameElementPayments::Trace(blink::Visitor* visitor) { +void HTMLIFrameElementPayments::Trace(Visitor* visitor) { Supplement<HTMLIFrameElement>::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.h b/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.h index 195d5e3de67..810d72a3148 100644 --- a/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.h +++ b/chromium/third_party/blink/renderer/modules/payments/html_iframe_element_payments.h @@ -24,14 +24,14 @@ class HTMLIFrameElementPayments final HTMLIFrameElementPayments(); - static bool FastHasAttribute(const QualifiedName&, const HTMLIFrameElement&); - static void SetBooleanAttribute(const QualifiedName&, - HTMLIFrameElement&, + static bool FastHasAttribute(const HTMLIFrameElement&, const QualifiedName&); + static void SetBooleanAttribute(HTMLIFrameElement&, + const QualifiedName&, bool); static HTMLIFrameElementPayments& From(HTMLIFrameElement&); static bool AllowPaymentRequest(HTMLIFrameElement&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/payments/idls.gni b/chromium/third_party/blink/renderer/modules/payments/idls.gni new file mode 100644 index 00000000000..f48bed77859 --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/payments/idls.gni @@ -0,0 +1,51 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +modules_idl_files = [ + "abort_payment_event.idl", + "can_make_payment_event.idl", + "merchant_validation_event.idl", + "payment_address.idl", + "payment_instruments.idl", + "payment_manager.idl", + "payment_method_change_event.idl", + "payment_request.idl", + "payment_request_event.idl", + "payment_request_update_event.idl", + "payment_response.idl", +] + +modules_dictionary_idl_files = [ + "address_errors.idl", + "android_pay_method_data.idl", + "basic_card_request.idl", + "can_make_payment_event_init.idl", + "can_make_payment_response.idl", + "image_object.idl", + "merchant_validation_event_init.idl", + "payer_errors.idl", + "address_init.idl", + "payment_currency_amount.idl", + "payment_details_base.idl", + "payment_details_init.idl", + "payment_details_modifier.idl", + "payment_details_update.idl", + "payment_handler_response.idl", + "payment_instrument.idl", + "payment_item.idl", + "payment_method_change_event_init.idl", + "payment_method_data.idl", + "payment_options.idl", + "payment_request_details_update.idl", + "payment_request_event_init.idl", + "payment_request_update_event_init.idl", + "payment_shipping_option.idl", + "payment_validation_errors.idl", +] + +modules_dependency_idl_files = [ + "html_iframe_element_payments.idl", + "payment_app_service_worker_global_scope.idl", + "payment_app_service_worker_registration.idl", +] diff --git a/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.h b/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.h index eb6b7544a3a..41c35327258 100644 --- a/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.h +++ b/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.h @@ -8,9 +8,9 @@ #include "base/macros.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_merchant_validation_event_init.h" #include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/modules/event_modules.h" -#include "third_party/blink/renderer/modules/payments/merchant_validation_event_init.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" namespace WTF { diff --git a/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.idl b/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.idl index df9f1f35e9a..7388579fd93 100644 --- a/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.idl +++ b/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event.idl @@ -6,12 +6,10 @@ // https://crbug.com/867904 [ RuntimeEnabled=PaymentRequestMerchantValidationEvent, - Constructor(DOMString type, optional MerchantValidationEventInit eventInitDict), - ConstructorCallWith=ScriptState, - RaisesException=Constructor, SecureContext, Exposed=Window ] interface MerchantValidationEvent : Event { + [CallWith=ScriptState, RaisesException] constructor(DOMString type, optional MerchantValidationEventInit eventInitDict = {}); readonly attribute DOMString methodName; readonly attribute USVString validationURL; [CallWith=ScriptState,RaisesException] void complete(Promise<any> merchantSessionPromise); diff --git a/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event_test.cc b/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event_test.cc index 3e7d086c930..1b3a54592a8 100644 --- a/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/merchant_validation_event_test.cc @@ -8,7 +8,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" -#include "third_party/blink/renderer/modules/payments/merchant_validation_event_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_merchant_validation_event_init.h" #include "third_party/blink/renderer/platform/bindings/exception_code.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" diff --git a/chromium/third_party/blink/renderer/modules/payments/on_payment_response_test.cc b/chromium/third_party/blink/renderer/modules/payments/on_payment_response_test.cc index 4876a3184ae..fd30e364600 100644 --- a/chromium/third_party/blink/renderer/modules/payments/on_payment_response_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/on_payment_response_test.cc @@ -25,14 +25,13 @@ TEST(OnPaymentResponseTest, RejectMissingShippingOption) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_address = payments::mojom::blink::PaymentAddress::New(); response->shipping_address->country = "US"; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -48,13 +47,12 @@ TEST(OnPaymentResponseTest, RejectMissingAddress) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_option = "standardShipping"; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -70,12 +68,11 @@ TEST(OnPaymentResponseTest, RejectMissingName) { options->setRequestPayerName(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -91,12 +88,11 @@ TEST(OnPaymentResponseTest, RejectMissingEmail) { options->setRequestPayerEmail(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -112,12 +108,11 @@ TEST(OnPaymentResponseTest, RejectMissingPhone) { options->setRequestPayerPhone(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -133,15 +128,14 @@ TEST(OnPaymentResponseTest, RejectEmptyShippingOption) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_option = ""; response->shipping_address = payments::mojom::blink::PaymentAddress::New(); response->shipping_address->country = "US"; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -157,14 +151,13 @@ TEST(OnPaymentResponseTest, RejectEmptyAddress) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_option = "standardShipping"; response->shipping_address = payments::mojom::blink::PaymentAddress::New(); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -180,13 +173,12 @@ TEST(OnPaymentResponseTest, RejectEmptyName) { options->setRequestPayerName(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->name = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -202,13 +194,12 @@ TEST(OnPaymentResponseTest, RejectEmptyEmail) { options->setRequestPayerEmail(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->email = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -224,13 +215,12 @@ TEST(OnPaymentResponseTest, RejectEmptyPhone) { options->setRequestPayerPhone(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->phone = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -246,14 +236,13 @@ TEST(OnPaymentResponseTest, RejectNotRequestedAddress) { options->setRequestShipping(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_address = payments::mojom::blink::PaymentAddress::New(); response->shipping_address->country = "US"; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -269,13 +258,12 @@ TEST(OnPaymentResponseTest, RejectNotRequestedShippingOption) { options->setRequestShipping(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_option = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -291,13 +279,12 @@ TEST(OnPaymentResponseTest, RejectNotRequestedName) { options->setRequestPayerName(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->name = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -313,13 +300,12 @@ TEST(OnPaymentResponseTest, RejectNotRequestedEmail) { options->setRequestPayerEmail(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->email = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -335,13 +321,12 @@ TEST(OnPaymentResponseTest, RejectNotRequestedPhone) { options->setRequestPayerPhone(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->phone = ""; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -357,15 +342,14 @@ TEST(OnPaymentResponseTest, RejectInvalidAddress) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_option = "standardShipping"; response->shipping_address = payments::mojom::blink::PaymentAddress::New(); response->shipping_address->country = "Atlantis"; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -405,15 +389,14 @@ TEST(OnPaymentResponseTest, CanRequestShippingInformation) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->shipping_option = "standardShipping"; response->shipping_address = payments::mojom::blink::PaymentAddress::New(); response->shipping_address->country = "US"; ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -435,14 +418,13 @@ TEST(OnPaymentResponseTest, CanRequestName) { options->setRequestPayerName(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer = payments::mojom::blink::PayerDetail::New(); response->payer->name = "Jon Doe"; ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -464,13 +446,12 @@ TEST(OnPaymentResponseTest, CanRequestEmail) { options->setRequestPayerEmail(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->email = "abc@gmail.com"; ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -492,14 +473,13 @@ TEST(OnPaymentResponseTest, CanRequestPhone) { options->setRequestPayerPhone(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->phone = "0123"; ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -521,10 +501,9 @@ TEST(OnPaymentResponseTest, ShippingInformationNotRequired) { options->setRequestShipping(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - ASSERT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -547,13 +526,12 @@ TEST(OnPaymentResponseTest, PhoneNotRequred) { options->setRequestPayerPhone(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->phone = String(); ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -575,13 +553,12 @@ TEST(OnPaymentResponseTest, NameNotRequired) { options->setRequestPayerName(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->name = String(); ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); @@ -603,13 +580,12 @@ TEST(OnPaymentResponseTest, EmailNotRequired) { options->setRequestPayerEmail(false); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); payments::mojom::blink::PaymentResponsePtr response = BuildPaymentResponseForTest(); response->payer->email = String(); ScriptValue out_value; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(PaymentResponseFunction::Create(scope.GetScriptState(), &out_value), funcs.ExpectNoCall()); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.cc b/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.cc index 55b96f6e9ed..70c052af16c 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.cc @@ -41,12 +41,12 @@ PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager( PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager( ScriptState* script_state) { if (!payment_manager_) { - payment_manager_ = PaymentManager::Create(registration_); + payment_manager_ = MakeGarbageCollected<PaymentManager>(registration_); } return payment_manager_.Get(); } -void PaymentAppServiceWorkerRegistration::Trace(blink::Visitor* visitor) { +void PaymentAppServiceWorkerRegistration::Trace(Visitor* visitor) { visitor->Trace(registration_); visitor->Trace(payment_manager_); Supplement<ServiceWorkerRegistration>::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.h b/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.h index 92733d22ab7..9a8a29ec407 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_app_service_worker_registration.h @@ -33,7 +33,7 @@ class PaymentAppServiceWorkerRegistration final ServiceWorkerRegistration&); PaymentManager* paymentManager(ScriptState*); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<ServiceWorkerRegistration> registration_; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.cc b/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.cc index 620081a417b..18816cf7913 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.cc @@ -6,14 +6,13 @@ #include "third_party/blink/public/mojom/payments/payment_app.mojom-blink.h" #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h" -#include "third_party/blink/renderer/modules/payments/can_make_payment_event_init.h" -#include "third_party/blink/renderer/modules/payments/payment_currency_amount.h" -#include "third_party/blink/renderer/modules/payments/payment_details_modifier.h" -#include "third_party/blink/renderer/modules/payments/payment_item.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" -#include "third_party/blink/renderer/modules/payments/payment_request_event_init.h" -#include "third_party/blink/renderer/modules/payments/payment_shipping_option.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_currency_amount.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_modifier.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_item.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_request_event_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" namespace blink { @@ -192,6 +191,7 @@ CanMakePaymentEventInit* PaymentEventDataConversion::ToCanMakePaymentEventInit( ToPaymentDetailsModifier(script_state, std::move(modifier))); } event_init->setModifiers(modifiers); + event_init->setCurrency(event_data->currency); return event_init; } diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.h b/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.h index c9d4999e9aa..b6ceee1454d 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion.h @@ -6,8 +6,8 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_EVENT_DATA_CONVERSION_H_ #include "third_party/blink/public/mojom/payments/payment_app.mojom-blink-forward.h" -#include "third_party/blink/renderer/modules/payments/can_make_payment_event_init.h" -#include "third_party/blink/renderer/modules/payments/payment_request_event_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_can_make_payment_event_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_request_event_init.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" namespace blink { diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion_test.cc b/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion_test.cc index 035de93715a..81190c3d8f5 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_event_data_conversion_test.cc @@ -10,10 +10,10 @@ #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" -#include "third_party/blink/renderer/modules/payments/payment_currency_amount.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" -#include "third_party/blink/renderer/modules/payments/payment_shipping_option.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_currency_amount.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" namespace blink { diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_handler_response.idl b/chromium/third_party/blink/renderer/modules/payments/payment_handler_response.idl index 6f17e0d6e2a..c00df854f91 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_handler_response.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_handler_response.idl @@ -10,6 +10,6 @@ dictionary PaymentHandlerResponse { [RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] DOMString? payerName; [RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] DOMString? payerEmail; [RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] DOMString? payerPhone; - [RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] PaymentAddressInit shippingAddress; + [RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] AddressInit shippingAddress; [RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] DOMString? shippingOption; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_handler_utils.cc b/chromium/third_party/blink/renderer/modules/payments/payment_handler_utils.cc index 415470686a6..49b54a10d8f 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_handler_utils.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_handler_utils.cc @@ -7,6 +7,7 @@ #include "third_party/blink/public/mojom/service_worker/service_worker_error_type.mojom-blink.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/inspector/console_message.h" +#include "third_party/blink/renderer/platform/heap/heap.h" using blink::mojom::ServiceWorkerResponseError; @@ -53,7 +54,7 @@ void PaymentHandlerUtils::ReportResponseError( } DCHECK(execution_context); - execution_context->AddConsoleMessage(ConsoleMessage::Create( + execution_context->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kWarning, error_message)); } diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_instruments.cc b/chromium/third_party/blink/renderer/modules/payments/payment_instruments.cc index dc245032b6b..36b523af43f 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_instruments.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_instruments.cc @@ -16,6 +16,8 @@ #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_image_object.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_instrument.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/execution_context/security_context.h" @@ -23,8 +25,6 @@ #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/modules/payments/basic_card_helper.h" -#include "third_party/blink/renderer/modules/payments/image_object.h" -#include "third_party/blink/renderer/modules/payments/payment_instrument.h" #include "third_party/blink/renderer/modules/payments/payment_manager.h" #include "third_party/blink/renderer/modules/permissions/permission_utils.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" @@ -80,15 +80,16 @@ bool AllowedToUsePaymentFeatures(ScriptState* script_state) { return ExecutionContext::From(script_state) ->GetSecurityContext() .GetFeaturePolicy() - ->IsFeatureEnabled(mojom::FeaturePolicyFeature::kPayment); + ->IsFeatureEnabled(mojom::blink::FeaturePolicyFeature::kPayment); } -ScriptPromise RejectNotAllowedToUsePaymentFeatures(ScriptState* script_state) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kSecurityError, - "Must be in a top-level browsing context or an iframe " - "needs to specify allow=\"payment\" explicitly")); +ScriptPromise RejectNotAllowedToUsePaymentFeatures( + ScriptState* script_state, + ExceptionState& exception_state) { + exception_state.ThrowSecurityError( + "Must be in a top-level browsing context or an iframe needs to specify " + "allow=\"payment\" explicitly"); + return ScriptPromise(); } } // namespace @@ -125,7 +126,7 @@ class PaymentInstrumentParameter final bool has_name() const { return has_name_; } const String& name() const { return name_; } - void Trace(blink::Visitor* visitor) { + void Trace(Visitor* visitor) { visitor->Trace(icons_); visitor->Trace(capabilities_); } @@ -148,15 +149,15 @@ PaymentInstruments::PaymentInstruments( ScriptPromise PaymentInstruments::deleteInstrument( ScriptState* script_state, - const String& instrument_key) { + const String& instrument_key, + ExceptionState& exception_state) { if (!AllowedToUsePaymentFeatures(script_state)) - return RejectNotAllowedToUsePaymentFeatures(script_state); + return RejectNotAllowedToUsePaymentFeatures(script_state, exception_state); if (!manager_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - kPaymentManagerUnavailable)); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + kPaymentManagerUnavailable); + return ScriptPromise(); } auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); @@ -170,15 +171,15 @@ ScriptPromise PaymentInstruments::deleteInstrument( } ScriptPromise PaymentInstruments::get(ScriptState* script_state, - const String& instrument_key) { + const String& instrument_key, + ExceptionState& exception_state) { if (!AllowedToUsePaymentFeatures(script_state)) - return RejectNotAllowedToUsePaymentFeatures(script_state); + return RejectNotAllowedToUsePaymentFeatures(script_state, exception_state); if (!manager_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - kPaymentManagerUnavailable)); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + kPaymentManagerUnavailable); + return ScriptPromise(); } auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); @@ -191,15 +192,15 @@ ScriptPromise PaymentInstruments::get(ScriptState* script_state, return promise; } -ScriptPromise PaymentInstruments::keys(ScriptState* script_state) { +ScriptPromise PaymentInstruments::keys(ScriptState* script_state, + ExceptionState& exception_state) { if (!AllowedToUsePaymentFeatures(script_state)) - return RejectNotAllowedToUsePaymentFeatures(script_state); + return RejectNotAllowedToUsePaymentFeatures(script_state, exception_state); if (!manager_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - kPaymentManagerUnavailable)); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + kPaymentManagerUnavailable); + return ScriptPromise(); } auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); @@ -212,15 +213,15 @@ ScriptPromise PaymentInstruments::keys(ScriptState* script_state) { } ScriptPromise PaymentInstruments::has(ScriptState* script_state, - const String& instrument_key) { + const String& instrument_key, + ExceptionState& exception_state) { if (!AllowedToUsePaymentFeatures(script_state)) - return RejectNotAllowedToUsePaymentFeatures(script_state); + return RejectNotAllowedToUsePaymentFeatures(script_state, exception_state); if (!manager_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - kPaymentManagerUnavailable)); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + kPaymentManagerUnavailable); + return ScriptPromise(); } auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); @@ -238,18 +239,17 @@ ScriptPromise PaymentInstruments::set(ScriptState* script_state, const PaymentInstrument* details, ExceptionState& exception_state) { if (!AllowedToUsePaymentFeatures(script_state)) - return RejectNotAllowedToUsePaymentFeatures(script_state); + return RejectNotAllowedToUsePaymentFeatures(script_state, exception_state); if (!manager_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - kPaymentManagerUnavailable)); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + kPaymentManagerUnavailable); + return ScriptPromise(); } auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); ExecutionContext* context = ExecutionContext::From(script_state); - Document* doc = DynamicTo<Document>(context); + Document* doc = Document::DynamicFrom(context); // Should move this permission check to browser process. // Please see http://crbug.com/795929 @@ -267,15 +267,15 @@ ScriptPromise PaymentInstruments::set(ScriptState* script_state, return resolver->Promise(); } -ScriptPromise PaymentInstruments::clear(ScriptState* script_state) { +ScriptPromise PaymentInstruments::clear(ScriptState* script_state, + ExceptionState& exception_state) { if (!AllowedToUsePaymentFeatures(script_state)) - return RejectNotAllowedToUsePaymentFeatures(script_state); + return RejectNotAllowedToUsePaymentFeatures(script_state, exception_state); if (!manager_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - kPaymentManagerUnavailable)); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + kPaymentManagerUnavailable); + return ScriptPromise(); } auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); @@ -364,10 +364,9 @@ void PaymentInstruments::OnRequestPermission( ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(), ExceptionState::kSetterContext, "PaymentInstruments", "set"); - BasicCardHelper::ParseBasiccardData( - details->capabilities(), instrument->supported_networks, - instrument->supported_types, /*has_supported_card_types=*/nullptr, - exception_state); + BasicCardHelper::ParseBasiccardData(details->capabilities(), + instrument->supported_networks, + exception_state); if (exception_state.HadException()) { resolver->Reject(exception_state); return; @@ -417,7 +416,7 @@ void PaymentInstruments::onGetPaymentInstrument( image_object->setType(icon->type); String sizes = WTF::g_empty_string; for (const auto& size : icon->sizes) { - sizes = sizes + String::Format("%dx%d ", size.width, size.height); + sizes = sizes + String::Format("%dx%d ", size.width(), size.height()); } image_object->setSizes(sizes.StripWhiteSpace()); icons.push_back(image_object); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_instruments.h b/chromium/third_party/blink/renderer/modules/payments/payment_instruments.h index 13e9824aaf2..c7cb763b739 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_instruments.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_instruments.h @@ -30,15 +30,21 @@ class MODULES_EXPORT PaymentInstruments final : public ScriptWrappable { explicit PaymentInstruments( const mojo::Remote<payments::mojom::blink::PaymentManager>&); - ScriptPromise deleteInstrument(ScriptState*, const String& instrument_key); - ScriptPromise get(ScriptState*, const String& instrument_key); - ScriptPromise keys(ScriptState*); - ScriptPromise has(ScriptState*, const String& instrument_key); + ScriptPromise deleteInstrument(ScriptState*, + const String& instrument_key, + ExceptionState&); + ScriptPromise get(ScriptState*, + const String& instrument_key, + ExceptionState&); + ScriptPromise keys(ScriptState*, ExceptionState&); + ScriptPromise has(ScriptState*, + const String& instrument_key, + ExceptionState&); ScriptPromise set(ScriptState*, const String& instrument_key, const PaymentInstrument* details, ExceptionState&); - ScriptPromise clear(ScriptState*); + ScriptPromise clear(ScriptState*, ExceptionState&); private: mojom::blink::PermissionService* GetPermissionService(ScriptState*); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_instruments.idl b/chromium/third_party/blink/renderer/modules/payments/payment_instruments.idl index 3bf03fba218..0914d6f6eee 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_instruments.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_instruments.idl @@ -8,10 +8,10 @@ RuntimeEnabled=PaymentApp, Exposed=(Window,Worker) ] interface PaymentInstruments { - [CallWith=ScriptState, ImplementedAs=deleteInstrument] Promise<boolean> delete(DOMString instrumentKey); - [CallWith=ScriptState] Promise<any> get(DOMString instrumentKey); - [CallWith=ScriptState] Promise<sequence<DOMString>> keys(); - [CallWith=ScriptState] Promise<boolean> has(DOMString instrumentKey); + [CallWith=ScriptState, RaisesException, ImplementedAs=deleteInstrument] Promise<boolean> delete(DOMString instrumentKey); + [CallWith=ScriptState, RaisesException] Promise<any> get(DOMString instrumentKey); + [CallWith=ScriptState, RaisesException] Promise<sequence<DOMString>> keys(); + [CallWith=ScriptState, RaisesException] Promise<boolean> has(DOMString instrumentKey); [CallWith=ScriptState, RaisesException] Promise<void> set(DOMString instrumentKey, PaymentInstrument details); - [CallWith=ScriptState] Promise<void> clear(); + [CallWith=ScriptState, RaisesException] Promise<void> clear(); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_manager.cc b/chromium/third_party/blink/renderer/modules/payments/payment_manager.cc index 029f5ce7901..f1029af6e40 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_manager.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_manager.cc @@ -10,16 +10,12 @@ #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/modules/payments/payment_instruments.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h" +#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/wtf/functional.h" namespace blink { -PaymentManager* PaymentManager::Create( - ServiceWorkerRegistration* registration) { - return MakeGarbageCollected<PaymentManager>(registration); -} - PaymentInstruments* PaymentManager::instruments() { if (!instruments_) instruments_ = MakeGarbageCollected<PaymentInstruments>(manager_); @@ -37,20 +33,20 @@ void PaymentManager::setUserHint(const String& user_hint) { ScriptPromise PaymentManager::enableDelegations( ScriptState* script_state, - const Vector<String>& stringified_delegations) { + const Vector<String>& stringified_delegations, + ExceptionState& exception_state) { if (!script_state->ContextIsValid()) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Cannot enable payment delegations")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot enable payment delegations"); + return ScriptPromise(); } if (enable_delegations_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Cannot call enableDelegations() again until " - "the previous enableDelegations() is finished")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "Cannot call enableDelegations() again until the previous " + "enableDelegations() is finished"); + return ScriptPromise(); } Vector<payments::mojom::blink::PaymentDelegation> delegations; @@ -80,7 +76,7 @@ ScriptPromise PaymentManager::enableDelegations( return enable_delegations_resolver_->Promise(); } -void PaymentManager::Trace(blink::Visitor* visitor) { +void PaymentManager::Trace(Visitor* visitor) { visitor->Trace(registration_); visitor->Trace(instruments_); visitor->Trace(enable_delegations_resolver_); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_manager.h b/chromium/third_party/blink/renderer/modules/payments/payment_manager.h index d60f8bcc1c6..de761cae3d4 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_manager.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_manager.h @@ -14,6 +14,7 @@ namespace blink { +class ExceptionState; class PaymentInstruments; class ScriptPromiseResolver; class ScriptPromise; @@ -24,8 +25,6 @@ class MODULES_EXPORT PaymentManager final : public ScriptWrappable { DEFINE_WRAPPERTYPEINFO(); public: - static PaymentManager* Create(ServiceWorkerRegistration*); - explicit PaymentManager(ServiceWorkerRegistration*); PaymentInstruments* instruments(); @@ -33,11 +32,11 @@ class MODULES_EXPORT PaymentManager final : public ScriptWrappable { const String& userHint(); void setUserHint(const String&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; - ScriptPromise enableDelegations( - ScriptState*, - const Vector<String>& stringified_delegations); + ScriptPromise enableDelegations(ScriptState*, + const Vector<String>& stringified_delegations, + ExceptionState&); private: void OnServiceConnectionError(); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_manager.idl b/chromium/third_party/blink/renderer/modules/payments/payment_manager.idl index 10b88279dc2..48abe2f66e5 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_manager.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_manager.idl @@ -17,5 +17,5 @@ enum PaymentDelegation { ] interface PaymentManager { [SameObject] readonly attribute PaymentInstruments instruments; attribute DOMString userHint; - [CallWith=ScriptState, RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] Promise<void> enableDelegations(FrozenArray<PaymentDelegation> delegations); + [CallWith=ScriptState, RaisesException, RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] Promise<void> enableDelegations(FrozenArray<PaymentDelegation> delegations); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.h b/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.h index 162ce1e3e1d..993446ac1f5 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.h @@ -7,8 +7,8 @@ #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/world_safe_v8_reference.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_change_event_init.h" #include "third_party/blink/renderer/modules/modules_export.h" -#include "third_party/blink/renderer/modules/payments/payment_method_change_event_init.h" #include "third_party/blink/renderer/modules/payments/payment_request_update_event.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.idl b/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.idl index 98e6d845206..f2f85fc3412 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_method_change_event.idl @@ -6,11 +6,10 @@ [ RuntimeEnabled=PaymentMethodChangeEvent, - ConstructorCallWith=ScriptState, - Constructor(DOMString type, optional PaymentMethodChangeEventInit eventInitDict), SecureContext, Exposed=Window ] interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent { + [CallWith=ScriptState] constructor(DOMString type, optional PaymentMethodChangeEventInit eventInitDict = {}); readonly attribute DOMString methodName; [CallWith=ScriptState] readonly attribute object? methodDetails; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request.cc index e55238490af..b173aafff04 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request.cc @@ -17,11 +17,19 @@ #include "third_party/blink/public/mojom/web_feature/web_feature.mojom-blink.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/task_type.h" +#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/v8_string_resource.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_errors.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_android_pay_method_data.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_basic_card_request.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payer_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_modifier.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_update.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_item.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_validation_errors.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/events/event.h" @@ -35,23 +43,12 @@ #include "third_party/blink/renderer/core/html/html_iframe_element.h" #include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/modules/event_target_modules_names.h" -#include "third_party/blink/renderer/modules/payments/address_errors.h" -#include "third_party/blink/renderer/modules/payments/android_pay_method_data.h" -#include "third_party/blink/renderer/modules/payments/android_pay_tokenization.h" #include "third_party/blink/renderer/modules/payments/basic_card_helper.h" -#include "third_party/blink/renderer/modules/payments/basic_card_request.h" #include "third_party/blink/renderer/modules/payments/html_iframe_element_payments.h" -#include "third_party/blink/renderer/modules/payments/payer_errors.h" #include "third_party/blink/renderer/modules/payments/payment_address.h" -#include "third_party/blink/renderer/modules/payments/payment_details_init.h" -#include "third_party/blink/renderer/modules/payments/payment_details_modifier.h" -#include "third_party/blink/renderer/modules/payments/payment_details_update.h" -#include "third_party/blink/renderer/modules/payments/payment_item.h" #include "third_party/blink/renderer/modules/payments/payment_method_change_event.h" #include "third_party/blink/renderer/modules/payments/payment_request_update_event.h" #include "third_party/blink/renderer/modules/payments/payment_response.h" -#include "third_party/blink/renderer/modules/payments/payment_shipping_option.h" -#include "third_party/blink/renderer/modules/payments/payment_validation_errors.h" #include "third_party/blink/renderer/modules/payments/payments_validators.h" #include "third_party/blink/renderer/modules/payments/update_payment_details_function.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" @@ -261,7 +258,7 @@ void ValidateShippingOptionOrPaymentItem(const T* item, } if (item->label().IsEmpty()) { - execution_context.AddConsoleMessage(ConsoleMessage::Create( + execution_context.AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kError, "Empty " + item_name + " label may be confusing the user")); @@ -320,7 +317,7 @@ void ValidateAndConvertShippingOptions( } if (option->id().IsEmpty()) { - execution_context.AddConsoleMessage(ConsoleMessage::Create( + execution_context.AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kWarning, "Empty shipping option ID may be hard to debug")); @@ -367,9 +364,9 @@ void SetAndroidPayMethodData(v8::Isolate* isolate, const ScriptValue& input, PaymentMethodDataPtr& output, ExceptionState& exception_state) { - AndroidPayMethodData* android_pay = AndroidPayMethodData::Create(); - V8AndroidPayMethodData::ToImpl(isolate, input.V8Value(), android_pay, - exception_state); + AndroidPayMethodData* android_pay = + NativeValueTraits<AndroidPayMethodData>::NativeValue( + isolate, input.V8Value(), exception_state); if (exception_state.HadException()) return; @@ -394,13 +391,11 @@ void SetAndroidPayMethodData(v8::Isolate* isolate, output->api_version = android_pay->apiVersion(); } -void StringifyAndParseMethodSpecificData( - v8::Isolate* isolate, - const String& supported_method, - const ScriptValue& input, - PaymentMethodDataPtr& output, - bool* basic_card_has_supported_card_types, - ExceptionState& exception_state) { +void StringifyAndParseMethodSpecificData(v8::Isolate* isolate, + const String& supported_method, + const ScriptValue& input, + PaymentMethodDataPtr& output, + ExceptionState& exception_state) { PaymentsValidators::ValidateAndStringifyObject( isolate, "Payment method data", input, output->stringified_data, exception_state); @@ -419,16 +414,14 @@ void StringifyAndParseMethodSpecificData( if (supported_method == "basic-card") { // Parses basic-card data to avoid parsing JSON in the browser. - BasicCardHelper::ParseBasiccardData( - input, output->supported_networks, output->supported_types, - basic_card_has_supported_card_types, exception_state); + BasicCardHelper::ParseBasiccardData(input, output->supported_networks, + exception_state); } } void ValidateAndConvertPaymentDetailsModifiers( const HeapVector<Member<PaymentDetailsModifier>>& input, Vector<PaymentDetailsModifierPtr>& output, - bool* basic_card_has_supported_card_types, ExecutionContext& execution_context, ExceptionState& exception_state) { if (input.size() > PaymentRequest::kMaxListSize) { @@ -468,22 +461,19 @@ void ValidateAndConvertPaymentDetailsModifiers( if (modifier->hasData() && !modifier->data().IsEmpty()) { StringifyAndParseMethodSpecificData( execution_context.GetIsolate(), modifier->supportedMethod(), - modifier->data(), output.back()->method_data, - basic_card_has_supported_card_types, exception_state); + modifier->data(), output.back()->method_data, exception_state); } else { output.back()->method_data->stringified_data = ""; } } } -void ValidateAndConvertPaymentDetailsBase( - const PaymentDetailsBase* input, - const PaymentOptions* options, - PaymentDetailsPtr& output, - String& shipping_option_output, - bool* basic_card_has_supported_card_types, - ExecutionContext& execution_context, - ExceptionState& exception_state) { +void ValidateAndConvertPaymentDetailsBase(const PaymentDetailsBase* input, + const PaymentOptions* options, + PaymentDetailsPtr& output, + String& shipping_option_output, + ExecutionContext& execution_context, + ExceptionState& exception_state) { if (input->hasDisplayItems()) { output->display_items = Vector<PaymentItemPtr>(); ValidateAndConvertDisplayItems(input->displayItems(), "display items", @@ -509,29 +499,26 @@ void ValidateAndConvertPaymentDetailsBase( if (input->hasModifiers()) { output->modifiers = Vector<PaymentDetailsModifierPtr>(); ValidateAndConvertPaymentDetailsModifiers( - input->modifiers(), *output->modifiers, - basic_card_has_supported_card_types, execution_context, + input->modifiers(), *output->modifiers, execution_context, exception_state); } } -void ValidateAndConvertPaymentDetailsInit( - const PaymentDetailsInit* input, - const PaymentOptions* options, - PaymentDetailsPtr& output, - String& shipping_option_output, - bool* basic_card_has_supported_card_types, - ExecutionContext& execution_context, - ExceptionState& exception_state) { +void ValidateAndConvertPaymentDetailsInit(const PaymentDetailsInit* input, + const PaymentOptions* options, + PaymentDetailsPtr& output, + String& shipping_option_output, + ExecutionContext& execution_context, + ExceptionState& exception_state) { DCHECK(input->hasTotal()); ValidateAndConvertTotal(input->total(), "total", output->total, execution_context, exception_state); if (exception_state.HadException()) return; - ValidateAndConvertPaymentDetailsBase( - input, options, output, shipping_option_output, - basic_card_has_supported_card_types, execution_context, exception_state); + ValidateAndConvertPaymentDetailsBase(input, options, output, + shipping_option_output, + execution_context, exception_state); } void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate* input, @@ -540,9 +527,9 @@ void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate* input, String& shipping_option_output, ExecutionContext& execution_context, ExceptionState& exception_state) { - ValidateAndConvertPaymentDetailsBase( - input, options, output, shipping_option_output, - /*has_supported_card_types=*/nullptr, execution_context, exception_state); + ValidateAndConvertPaymentDetailsBase(input, options, output, + shipping_option_output, + execution_context, exception_state); if (exception_state.HadException()) return; @@ -590,7 +577,6 @@ void ValidateAndConvertPaymentMethodData( bool& skip_to_gpay_ready, Vector<payments::mojom::blink::PaymentMethodDataPtr>& output, HashSet<String>& method_names, - bool* basic_card_has_supported_card_types, ExecutionContext& execution_context, ExceptionState& exception_state) { if (input.IsEmpty()) { @@ -627,7 +613,7 @@ void ValidateAndConvertPaymentMethodData( StringifyAndParseMethodSpecificData( execution_context.GetIsolate(), payment_method_data->supportedMethod(), payment_method_data->data(), - output.back(), basic_card_has_supported_card_types, exception_state); + output.back(), exception_state); if (exception_state.HadException()) continue; @@ -650,13 +636,14 @@ bool AllowedToUsePaymentRequest(const ExecutionContext* execution_context) { // Note: PaymentRequest is only exposed to Window and not workers. // 1. If |document| has no browsing context, then return false. - const Document* document = To<Document>(execution_context); + const Document* document = Document::From(execution_context); if (!document->GetFrame()) return false; // 2. If Feature Policy is enabled, return the policy for "payment" feature. - return document->IsFeatureEnabled(mojom::FeaturePolicyFeature::kPayment, - ReportOptions::kReportOnFailure); + return document->IsFeatureEnabled( + mojom::blink::FeaturePolicyFeature::kPayment, + ReportOptions::kReportOnFailure); } void WarnIgnoringQueryQuotaForCanMakePayment( @@ -667,9 +654,9 @@ void WarnIgnoringQueryQuotaForCanMakePayment( "reject the promise, but allowing continued usage on localhost and " "file:// scheme origins.", method_name); - execution_context.AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, error)); + execution_context.AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, error)); } } // namespace @@ -696,25 +683,25 @@ PaymentRequest* PaymentRequest::Create( PaymentRequest::~PaymentRequest() = default; -ScriptPromise PaymentRequest::show(ScriptState* script_state) { - return show(script_state, ScriptPromise()); +ScriptPromise PaymentRequest::show(ScriptState* script_state, + ExceptionState& exception_state) { + return show(script_state, ScriptPromise(), exception_state); } ScriptPromise PaymentRequest::show(ScriptState* script_state, - ScriptPromise details_promise) { + ScriptPromise details_promise, + ExceptionState& exception_state) { if (!script_state->ContextIsValid() || !LocalDOMWindow::From(script_state) || !LocalDOMWindow::From(script_state)->GetFrame()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError, - "Cannot show the payment request")); + exception_state.ThrowDOMException(DOMExceptionCode::kAbortError, + "Cannot show the payment request"); + return ScriptPromise(); } if (!payment_provider_.is_bound() || accept_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Already called show() once")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Already called show() once"); + return ScriptPromise(); } // TODO(crbug.com/825270): Reject with SecurityError DOMException if triggered @@ -725,17 +712,12 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state, WebFeature::kPaymentRequestShowWithoutGesture); } - if (basic_card_has_supported_card_types_) { - UseCounter::Count(GetExecutionContext(), WebFeature::kBasicCardType); - } - // TODO(crbug.com/779126): add support for handling payment requests in // immersive mode. if (GetFrame()->GetDocument()->GetSettings()->GetImmersiveModeEnabled()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Page popups are suppressed")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Page popups are suppressed"); + return ScriptPromise(); } UseCounter::Count(GetExecutionContext(), WebFeature::kPaymentRequestShow); @@ -761,28 +743,26 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state, return accept_resolver_->Promise(); } -ScriptPromise PaymentRequest::abort(ScriptState* script_state) { +ScriptPromise PaymentRequest::abort(ScriptState* script_state, + ExceptionState& exception_state) { if (!script_state->ContextIsValid()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Cannot abort payment")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot abort payment"); + return ScriptPromise(); } if (abort_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Cannot abort() again until the previous abort() " - "has resolved or rejected")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot abort() again until the previous " + "abort() has resolved or rejected"); + return ScriptPromise(); } if (!GetPendingAcceptPromiseResolver()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "No show() or retry() in progress, so nothing to abort")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "No show() or retry() in progress, so nothing to abort"); + return ScriptPromise(); } abort_resolver_ = MakeGarbageCollected<ScriptPromiseResolver>(script_state); @@ -790,13 +770,13 @@ ScriptPromise PaymentRequest::abort(ScriptState* script_state) { return abort_resolver_->Promise(); } -ScriptPromise PaymentRequest::canMakePayment(ScriptState* script_state) { +ScriptPromise PaymentRequest::canMakePayment(ScriptState* script_state, + ExceptionState& exception_state) { if (!payment_provider_.is_bound() || GetPendingAcceptPromiseResolver() || can_make_payment_resolver_ || !script_state->ContextIsValid()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Cannot query payment request")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot query payment request"); + return ScriptPromise(); } payment_provider_->CanMakePayment(); @@ -806,13 +786,14 @@ ScriptPromise PaymentRequest::canMakePayment(ScriptState* script_state) { return can_make_payment_resolver_->Promise(); } -ScriptPromise PaymentRequest::hasEnrolledInstrument(ScriptState* script_state) { +ScriptPromise PaymentRequest::hasEnrolledInstrument( + ScriptState* script_state, + ExceptionState& exception_state) { if (!payment_provider_.is_bound() || GetPendingAcceptPromiseResolver() || has_enrolled_instrument_resolver_ || !script_state->ContextIsValid()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Cannot query payment request")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot query payment request"); + return ScriptPromise(); } bool per_method_quota = @@ -839,83 +820,83 @@ const AtomicString& PaymentRequest::InterfaceName() const { } ExecutionContext* PaymentRequest::GetExecutionContext() const { - return ContextLifecycleObserver::GetExecutionContext(); + return ExecutionContextLifecycleObserver::GetExecutionContext(); } ScriptPromise PaymentRequest::Retry(ScriptState* script_state, - const PaymentValidationErrors* errors) { + const PaymentValidationErrors* errors, + ExceptionState& exception_state) { if (!script_state->ContextIsValid() || !LocalDOMWindow::From(script_state) || !LocalDOMWindow::From(script_state)->GetFrame()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError, - "Cannot retry the payment request")); + exception_state.ThrowDOMException(DOMExceptionCode::kAbortError, + "Cannot retry the payment request"); + return ScriptPromise(); } if (complete_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Cannot call retry() because already called complete()")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "Cannot call retry() because already called complete()"); + return ScriptPromise(); } if (retry_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Cannot call retry() again until " - "the previous retry() is finished")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot call retry() again until " + "the previous retry() is finished"); + return ScriptPromise(); } if (!payment_provider_) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Payment request terminated")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Payment request terminated"); + return ScriptPromise(); } String error_message; if (!PaymentsValidators::IsValidPaymentValidationErrorsFormat( errors, &error_message)) { - return ScriptPromise::Reject( - script_state, V8ThrowException::CreateTypeError( - script_state->GetIsolate(), error_message)); + exception_state.ThrowTypeError(error_message); + return ScriptPromise(); } if (!options_->requestPayerName() && errors->hasPayer() && errors->payer()->hasName()) { GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, - "The payer.name passed to retry() may not be " - "shown because requestPayerName is false")); + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, + "The payer.name passed to retry() may not be " + "shown because requestPayerName is false")); } if (!options_->requestPayerEmail() && errors->hasPayer() && errors->payer()->hasEmail()) { GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, - "The payer.email passed to retry() may not be " - "shown because requestPayerEmail is false")); + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, + "The payer.email passed to retry() may not be " + "shown because requestPayerEmail is false")); } if (!options_->requestPayerPhone() && errors->hasPayer() && errors->payer()->hasPhone()) { GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, - "The payer.phone passed to retry() may not be " - "shown because requestPayerPhone is false")); + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, + "The payer.phone passed to retry() may not be " + "shown because requestPayerPhone is false")); } if (!options_->requestShipping() && errors->hasShippingAddress()) { GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, - "The shippingAddress passed to retry() may not " - "be shown because requestShipping is false")); + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, + "The shippingAddress passed to retry() may not " + "be shown because requestShipping is false")); } complete_timer_.Stop(); @@ -931,41 +912,39 @@ ScriptPromise PaymentRequest::Retry(ScriptState* script_state, } ScriptPromise PaymentRequest::Complete(ScriptState* script_state, - PaymentComplete result) { + PaymentComplete result, + ExceptionState& exception_state) { if (!script_state->ContextIsValid()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Cannot complete payment")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Cannot complete payment"); + return ScriptPromise(); } if (complete_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, - "Already called complete() once")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Already called complete() once"); + return ScriptPromise(); } if (retry_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Cannot call complete() before retry() is finished")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "Cannot call complete() before retry() is finished"); + return ScriptPromise(); } if (!complete_timer_.IsActive()) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Timed out after 60 seconds, complete() called too late")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "Timed out after 60 seconds, complete() called too late"); + return ScriptPromise(); } // User has cancelled the transaction while the website was processing it. if (!payment_provider_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kAbortError, "Request cancelled")); + exception_state.ThrowDOMException(DOMExceptionCode::kAbortError, + "Request cancelled"); + return ScriptPromise(); } complete_timer_.Stop(); @@ -988,13 +967,13 @@ void PaymentRequest::OnUpdatePaymentDetails( update_payment_details_timer_.Stop(); - PaymentDetailsUpdate* details = PaymentDetailsUpdate::Create(); ExceptionState exception_state(v8::Isolate::GetCurrent(), ExceptionState::kConstructionContext, "PaymentDetailsUpdate"); - V8PaymentDetailsUpdate::ToImpl(resolver->GetScriptState()->GetIsolate(), - details_script_value.V8Value(), details, - exception_state); + PaymentDetailsUpdate* details = + NativeValueTraits<PaymentDetailsUpdate>::NativeValue( + resolver->GetScriptState()->GetIsolate(), + details_script_value.V8Value(), exception_state); if (exception_state.HadException()) { resolver->Reject(exception_state.GetException()); ClearResolversAndCloseMojoConnection(); @@ -1052,7 +1031,7 @@ bool PaymentRequest::IsInteractive() const { return !!GetPendingAcceptPromiseResolver(); } -void PaymentRequest::Trace(blink::Visitor* visitor) { +void PaymentRequest::Trace(Visitor* visitor) { visitor->Trace(options_); visitor->Trace(shipping_address_); visitor->Trace(payment_response_); @@ -1063,7 +1042,7 @@ void PaymentRequest::Trace(blink::Visitor* visitor) { visitor->Trace(can_make_payment_resolver_); visitor->Trace(has_enrolled_instrument_resolver_); EventTargetWithInlineData::Trace(visitor); - ContextLifecycleObserver::Trace(visitor); + ExecutionContextLifecycleObserver::Trace(visitor); } void PaymentRequest::OnCompleteTimeoutForTesting() { @@ -1088,7 +1067,7 @@ PaymentRequest::PaymentRequest( const PaymentDetailsInit* details, const PaymentOptions* options, ExceptionState& exception_state) - : ContextLifecycleObserver(execution_context), + : ExecutionContextLifecycleObserver(execution_context), options_(options), complete_timer_( execution_context->GetTaskRunner(TaskType::kMiscPlatformAPI), @@ -1098,8 +1077,7 @@ PaymentRequest::PaymentRequest( execution_context->GetTaskRunner(TaskType::kMiscPlatformAPI), this, &PaymentRequest::OnUpdatePaymentDetailsTimeout), - is_waiting_for_show_promise_to_resolve_(false), - basic_card_has_supported_card_types_(false) { + is_waiting_for_show_promise_to_resolve_(false) { DCHECK(GetExecutionContext()->IsSecureContext()); if (!AllowedToUsePaymentRequest(execution_context)) { @@ -1129,15 +1107,13 @@ PaymentRequest::PaymentRequest( Vector<payments::mojom::blink::PaymentMethodDataPtr> validated_method_data; ValidateAndConvertPaymentMethodData(method_data, options_, skip_to_gpay_ready, validated_method_data, method_names_, - &basic_card_has_supported_card_types_, *GetExecutionContext(), exception_state); if (exception_state.HadException()) return; ValidateAndConvertPaymentDetailsInit(details, options_, validated_details, - shipping_option_, - &basic_card_has_supported_card_types_, - *GetExecutionContext(), exception_state); + shipping_option_, *GetExecutionContext(), + exception_state); if (exception_state.HadException()) return; @@ -1186,7 +1162,7 @@ PaymentRequest::PaymentRequest( #endif } -void PaymentRequest::ContextDestroyed(ExecutionContext*) { +void PaymentRequest::ContextDestroyed() { ClearResolversAndCloseMojoConnection(); } @@ -1487,15 +1463,15 @@ void PaymentRequest::OnHasEnrolledInstrument( } void PaymentRequest::WarnNoFavicon() { - GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, - "Favicon not found for PaymentRequest UI. User " - "may not recognize the website.")); + GetExecutionContext()->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, + "Favicon not found for PaymentRequest UI. User " + "may not recognize the website.")); } void PaymentRequest::OnCompleteTimeout(TimerBase*) { - GetExecutionContext()->AddConsoleMessage(ConsoleMessage::Create( + GetExecutionContext()->AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( mojom::ConsoleMessageSource::kJavaScript, mojom::ConsoleMessageLevel::kError, "Timed out waiting for a PaymentResponse.complete() call.")); @@ -1550,8 +1526,9 @@ void PaymentRequest::DispatchPaymentRequestUpdateEvent( "line items and total.", event->type().Ascii().c_str()); GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kWarning, message)); + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kWarning, message)); payment_provider_->OnPaymentDetailsNotUpdated(); // Make sure that updateWith() is only allowed to be called within the same // event loop as the event dispatch. See diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request.h b/chromium/third_party/blink/renderer/modules/payments/payment_request.h index 2315ff65bfa..c3aec087ca3 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request.h @@ -14,11 +14,11 @@ #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" #include "third_party/blink/renderer/core/dom/events/event_target.h" -#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/modules/modules_export.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" #include "third_party/blink/renderer/modules/payments/payment_request_delegate.h" #include "third_party/blink/renderer/modules/payments/payment_state_resolver.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" @@ -43,7 +43,7 @@ class MODULES_EXPORT PaymentRequest final public payments::mojom::blink::PaymentRequestClient, public PaymentStateResolver, public PaymentRequestDelegate, - public ContextLifecycleObserver, + public ExecutionContextLifecycleObserver, public ActiveScriptWrappable<PaymentRequest> { DEFINE_WRAPPERTYPEINFO(); USING_GARBAGE_COLLECTED_MIXIN(PaymentRequest); @@ -67,9 +67,11 @@ class MODULES_EXPORT PaymentRequest final ExceptionState&); ~PaymentRequest() override; - ScriptPromise show(ScriptState*); - ScriptPromise show(ScriptState*, ScriptPromise details_promise); - ScriptPromise abort(ScriptState*); + ScriptPromise show(ScriptState*, ExceptionState&); + ScriptPromise show(ScriptState*, + ScriptPromise details_promise, + ExceptionState&); + ScriptPromise abort(ScriptState*, ExceptionState&); const String& id() const { return id_; } PaymentAddress* getShippingAddress() const { return shipping_address_.Get(); } @@ -80,8 +82,8 @@ class MODULES_EXPORT PaymentRequest final DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingoptionchange, kShippingoptionchange) DEFINE_ATTRIBUTE_EVENT_LISTENER(paymentmethodchange, kPaymentmethodchange) - ScriptPromise canMakePayment(ScriptState*); - ScriptPromise hasEnrolledInstrument(ScriptState*); + ScriptPromise canMakePayment(ScriptState*, ExceptionState&); + ScriptPromise hasEnrolledInstrument(ScriptState*, ExceptionState&); // ScriptWrappable: bool HasPendingActivity() const override; @@ -91,15 +93,19 @@ class MODULES_EXPORT PaymentRequest final ExecutionContext* GetExecutionContext() const override; // PaymentStateResolver: - ScriptPromise Complete(ScriptState*, PaymentComplete result) override; - ScriptPromise Retry(ScriptState*, const PaymentValidationErrors*) override; + ScriptPromise Complete(ScriptState*, + PaymentComplete result, + ExceptionState&) override; + ScriptPromise Retry(ScriptState*, + const PaymentValidationErrors*, + ExceptionState&) override; // PaymentRequestDelegate: void OnUpdatePaymentDetails(const ScriptValue& details_script_value) override; void OnUpdatePaymentDetailsFailure(const String& error) override; bool IsInteractive() const override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; void OnCompleteTimeoutForTesting(); void OnUpdatePaymentDetailsTimeoutForTesting(); @@ -116,7 +122,7 @@ class MODULES_EXPORT PaymentRequest final void OnConnectionError(); // LifecycleObserver: - void ContextDestroyed(ExecutionContext*) override; + void ContextDestroyed() override; // payments::mojom::blink::PaymentRequestClient: void OnPaymentMethodChange(const String& method_name, @@ -172,7 +178,6 @@ class MODULES_EXPORT PaymentRequest final TaskRunnerTimer<PaymentRequest> complete_timer_; TaskRunnerTimer<PaymentRequest> update_payment_details_timer_; bool is_waiting_for_show_promise_to_resolve_; - bool basic_card_has_supported_card_types_; DISALLOW_COPY_AND_ASSIGN(PaymentRequest); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request.idl b/chromium/third_party/blink/renderer/modules/payments/payment_request.idl index db417602b7b..9ef367ee752 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request.idl @@ -7,17 +7,15 @@ [ RuntimeEnabled=PaymentRequest, - Constructor(sequence<PaymentMethodData> methodData, PaymentDetailsInit details, optional PaymentOptions options), - ConstructorCallWith=ExecutionContext, - RaisesException=Constructor, SecureContext, Exposed=Window, ActiveScriptWrappable ] interface PaymentRequest : EventTarget { - [CallWith=ScriptState, NewObject] Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise); - [CallWith=ScriptState, NewObject] Promise<void> abort(); - [CallWith=ScriptState, HighEntropy, Measure, NewObject] Promise<boolean> canMakePayment(); - [CallWith=ScriptState, HighEntropy, Measure, NewObject] Promise<boolean> hasEnrolledInstrument(); + [CallWith=ExecutionContext, RaisesException] constructor(sequence<PaymentMethodData> methodData, PaymentDetailsInit details, optional PaymentOptions options = {}); + [CallWith=ScriptState, RaisesException, NewObject] Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise); + [CallWith=ScriptState, RaisesException, NewObject] Promise<void> abort(); + [CallWith=ScriptState, RaisesException, HighEntropy, Measure, NewObject] Promise<boolean> canMakePayment(); + [CallWith=ScriptState, RaisesException, HighEntropy, Measure, NewObject] Promise<boolean> hasEnrolledInstrument(); readonly attribute DOMString id; [ImplementedAs=getShippingAddress] readonly attribute PaymentAddress? shippingAddress; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_details_test.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request_details_test.cc index 15164172895..ce5fdf02c55 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_details_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_details_test.cc @@ -7,9 +7,9 @@ #include <ostream> // NOLINT #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" #include "third_party/blink/renderer/core/dom/document.h" -#include "third_party/blink/renderer/modules/payments/payment_details_init.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_event.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request_event.cc index 3ee4b87118f..df0a14ca8e3 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_event.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_event.cc @@ -7,25 +7,25 @@ #include <utility> #include "third_party/blink/public/mojom/payments/payment_request.mojom-blink.h" -#include "third_party/blink/public/platform/interface_provider.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_currency_amount.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_modifier.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_item.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_request_details_update.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_location.h" -#include "third_party/blink/renderer/modules/payments/address_errors.h" -#include "third_party/blink/renderer/modules/payments/payment_address_init_type_converter.h" -#include "third_party/blink/renderer/modules/payments/payment_currency_amount.h" -#include "third_party/blink/renderer/modules/payments/payment_details_modifier.h" -#include "third_party/blink/renderer/modules/payments/payment_item.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" -#include "third_party/blink/renderer/modules/payments/payment_request_details_update.h" -#include "third_party/blink/renderer/modules/payments/payment_shipping_option.h" +#include "third_party/blink/renderer/modules/payments/address_init_type_converter.h" #include "third_party/blink/renderer/modules/payments/payments_validators.h" #include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_window_client.h" +#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" @@ -127,6 +127,13 @@ const ScriptValue PaymentRequestEvent::paymentOptions( return ScriptValue::From(script_state, payment_options_); } +base::Optional<HeapVector<Member<PaymentShippingOption>>> +PaymentRequestEvent::shippingOptions() const { + if (shipping_options_.IsEmpty()) + return base::nullopt; + return shipping_options_; +} + const HeapVector<Member<PaymentShippingOption>>& PaymentRequestEvent::shippingOptions(bool& is_null) const { is_null = shipping_options_.IsEmpty(); @@ -190,18 +197,17 @@ ScriptPromise PaymentRequestEvent::changePaymentMethod( const ScriptValue& method_details, ExceptionState& exception_state) { if (change_payment_request_details_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Waiting for response to the previous payment " - "request details change")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Waiting for response to the previous " + "payment request details change"); + return ScriptPromise(); } if (!payment_handler_host_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "No corresponding PaymentRequest object found")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "No corresponding PaymentRequest object found"); + return ScriptPromise(); } auto method_data = payments::mojom::blink::PaymentHandlerMethodData::New(); @@ -225,26 +231,25 @@ ScriptPromise PaymentRequestEvent::changePaymentMethod( ScriptPromise PaymentRequestEvent::changeShippingAddress( ScriptState* script_state, - PaymentAddressInit* shipping_address) { + AddressInit* shipping_address, + ExceptionState& exception_state) { if (change_payment_request_details_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Waiting for response to the previous payment " - "request details change")); + exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, + "Waiting for response to the previous " + "payment request details change"); + return ScriptPromise(); } if (!payment_handler_host_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "No corresponding PaymentRequest object found")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "No corresponding PaymentRequest object found"); + return ScriptPromise(); } if (!shipping_address) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kSyntaxError, - "Shipping address cannot be null")); + exception_state.ThrowDOMException(DOMExceptionCode::kSyntaxError, + "Shipping address cannot be null"); + return ScriptPromise(); } auto shipping_address_ptr = @@ -252,10 +257,9 @@ ScriptPromise PaymentRequestEvent::changeShippingAddress( String shipping_address_error; if (!PaymentsValidators::IsValidShippingAddress(shipping_address_ptr, &shipping_address_error)) { - return ScriptPromise::RejectWithDOMException( - script_state, - MakeGarbageCollected<DOMException>(DOMExceptionCode::kSyntaxError, - shipping_address_error)); + exception_state.ThrowDOMException(DOMExceptionCode::kSyntaxError, + shipping_address_error); + return ScriptPromise(); } payment_handler_host_->ChangeShippingAddress( @@ -269,20 +273,20 @@ ScriptPromise PaymentRequestEvent::changeShippingAddress( ScriptPromise PaymentRequestEvent::changeShippingOption( ScriptState* script_state, - const String& shipping_option_id) { + const String& shipping_option_id, + ExceptionState& exception_state) { if (change_payment_request_details_resolver_) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "Waiting for response to the previous payment " - "request details change")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "Waiting for response to the previous payment request details change"); + return ScriptPromise(); } if (!payment_handler_host_.is_bound()) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kInvalidStateError, - "No corresponding PaymentRequest object found")); + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + "No corresponding PaymentRequest object found"); + return ScriptPromise(); } bool shipping_option_id_is_valid = false; @@ -293,10 +297,9 @@ ScriptPromise PaymentRequestEvent::changeShippingOption( } } if (!shipping_option_id_is_valid) { - return ScriptPromise::RejectWithDOMException( - script_state, MakeGarbageCollected<DOMException>( - DOMExceptionCode::kSyntaxError, - "Shipping option identifier is invalid")); + exception_state.ThrowDOMException(DOMExceptionCode::kSyntaxError, + "Shipping option identifier is invalid"); + return ScriptPromise(); } payment_handler_host_->ChangeShippingOption( @@ -324,7 +327,7 @@ void PaymentRequestEvent::respondWith(ScriptState* script_state, } } -void PaymentRequestEvent::Trace(blink::Visitor* visitor) { +void PaymentRequestEvent::Trace(Visitor* visitor) { visitor->Trace(method_data_); visitor->Trace(total_); visitor->Trace(modifiers_); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_event.h b/chromium/third_party/blink/renderer/modules/payments/payment_request_event.h index 868d5c9959e..f4ecd6f05ae 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_event.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_event.h @@ -10,9 +10,9 @@ #include "mojo/public/cpp/bindings/remote.h" #include "third_party/blink/public/mojom/payments/payment_handler_host.mojom-blink.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_request_event_init.h" #include "third_party/blink/renderer/modules/event_modules.h" -#include "third_party/blink/renderer/modules/payments/payment_address_init.h" -#include "third_party/blink/renderer/modules/payments/payment_request_event_init.h" #include "third_party/blink/renderer/modules/service_worker/extendable_event.h" #include "third_party/blink/renderer/platform/heap/handle.h" @@ -22,6 +22,7 @@ class AtomicString; namespace blink { +class ExceptionState; class RespondWithObserver; class ScriptPromiseResolver; class ScriptState; @@ -58,8 +59,11 @@ class MODULES_EXPORT PaymentRequestEvent final : public ExtendableEvent { const HeapVector<Member<PaymentDetailsModifier>>& modifiers() const; const String& instrumentKey() const; const ScriptValue paymentOptions(ScriptState*) const; + base::Optional<HeapVector<Member<PaymentShippingOption>>> shippingOptions() + const; + // TODO(crbug.com/1060971): Remove |is_null| version. const HeapVector<Member<PaymentShippingOption>>& shippingOptions( - bool& is_null) const; + bool& is_null) const; // DEPRECATED ScriptPromise openWindow(ScriptState*, const String& url); ScriptPromise changePaymentMethod(ScriptState*, @@ -70,12 +74,14 @@ class MODULES_EXPORT PaymentRequestEvent final : public ExtendableEvent { const ScriptValue& method_details, ExceptionState& exception_state); ScriptPromise changeShippingAddress(ScriptState*, - PaymentAddressInit* shippingAddress); + AddressInit*, + ExceptionState&); ScriptPromise changeShippingOption(ScriptState*, - const String& shipping_option_id); + const String& shipping_option_id, + ExceptionState&); void respondWith(ScriptState*, ScriptPromise, ExceptionState&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void OnChangePaymentRequestDetailsResponse( diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_event.idl b/chromium/third_party/blink/renderer/modules/payments/payment_request_event.idl index 21608ee8516..5b245c1c351 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_event.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_event.idl @@ -6,9 +6,9 @@ [ RuntimeEnabled=PaymentApp, - Constructor(DOMString type, PaymentRequestEventInit eventInitDict), Exposed=ServiceWorker ] interface PaymentRequestEvent : ExtendableEvent { + constructor(DOMString type, PaymentRequestEventInit eventInitDict); readonly attribute USVString topOrigin; readonly attribute USVString paymentRequestOrigin; readonly attribute DOMString paymentRequestId; @@ -22,6 +22,6 @@ [CallWith=ScriptState] Promise<WindowClient?> openWindow(USVString url); [CallWith=ScriptState, RaisesException, RuntimeEnabled=PaymentHandlerChangePaymentMethod] Promise<PaymentRequestDetailsUpdate?> changePaymentMethod(DOMString methodName, optional object? methodDetails = null); [CallWith=ScriptState, RaisesException] void respondWith(Promise<PaymentResponse> response); - [CallWith=ScriptState, RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] Promise<PaymentRequestDetailsUpdate?> changeShippingAddress(PaymentAddressInit shippingAddress); - [CallWith=ScriptState, RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] Promise<PaymentRequestDetailsUpdate> changeShippingOption(DOMString shippingOption); + [CallWith=ScriptState, RaisesException, RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] Promise<PaymentRequestDetailsUpdate?> changeShippingAddress(AddressInit shippingAddress); + [CallWith=ScriptState, RaisesException, RuntimeEnabled=PaymentHandlerHandlesShippingAndContact] Promise<PaymentRequestDetailsUpdate> changeShippingOption(DOMString shippingOption); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.cc index 5fcc26a45e5..2d6a3b72b58 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.cc @@ -4,21 +4,22 @@ #include "third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.h" +#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_init.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_address.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_payment_handler_response.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/inspector/console_message.h" +#include "third_party/blink/renderer/modules/payments/address_init_type_converter.h" #include "third_party/blink/renderer/modules/payments/payment_address.h" -#include "third_party/blink/renderer/modules/payments/payment_address_init.h" -#include "third_party/blink/renderer/modules/payments/payment_address_init_type_converter.h" -#include "third_party/blink/renderer/modules/payments/payment_handler_response.h" #include "third_party/blink/renderer/modules/payments/payment_handler_utils.h" #include "third_party/blink/renderer/modules/payments/payments_validators.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope.h" #include "third_party/blink/renderer/modules/service_worker/wait_until_observer.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" +#include "third_party/blink/renderer/platform/heap/heap.h" #include "v8/include/v8.h" namespace blink { @@ -69,11 +70,12 @@ void PaymentRequestRespondWithObserver::OnResponseFulfilled( !response->hasDetails() || response->details().IsNull() || !response->details().IsObject()) { GetExecutionContext()->AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kError, - "'PaymentHandlerResponse.methodName' and " - "'PaymentHandlerResponse.details' must not " - "be empty in payment response.")); + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kError, + "'PaymentHandlerResponse.methodName' and " + "'PaymentHandlerResponse.details' must not " + "be empty in payment response.")); } if (!response->hasMethodName() || response->methodName().IsEmpty()) { @@ -97,11 +99,12 @@ void PaymentRequestRespondWithObserver::OnResponseFulfilled( if (!v8::JSON::Stringify(script_state->GetContext(), response->details().V8Value().As<v8::Object>()) .ToLocal(&details_value)) { - GetExecutionContext()->AddConsoleMessage(ConsoleMessage::Create( - mojom::ConsoleMessageSource::kJavaScript, - mojom::ConsoleMessageLevel::kError, - "Failed to stringify PaymentHandlerResponse.details in payment " - "response.")); + GetExecutionContext()->AddConsoleMessage( + MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kJavaScript, + mojom::ConsoleMessageLevel::kError, + "Failed to stringify PaymentHandlerResponse.details in payment " + "response.")); BlankResponseWithError( PaymentEventResponseType::PAYMENT_DETAILS_STRINGIFY_ERROR); return; @@ -169,7 +172,7 @@ PaymentRequestRespondWithObserver::PaymentRequestRespondWithObserver( WaitUntilObserver* observer) : RespondWithObserver(context, event_id, observer) {} -void PaymentRequestRespondWithObserver::Trace(blink::Visitor* visitor) { +void PaymentRequestRespondWithObserver::Trace(Visitor* visitor) { RespondWithObserver::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.h b/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.h index a9428dc89fc..2f06819f32b 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_respond_with_observer.h @@ -39,7 +39,7 @@ class MODULES_EXPORT PaymentRequestRespondWithObserver final const char* property_name) override; void OnNoResponse() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; void set_should_have_payer_name(bool should_have_payer_name) { should_have_payer_name_ = should_have_payer_name; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_test.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request_test.cc index a8f012eadf2..740369cac3d 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_test.cc @@ -9,6 +9,7 @@ #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/event_type_names.h" #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" +#include "third_party/blink/renderer/platform/bindings/exception_code.h" #include "third_party/blink/renderer/platform/heap/heap_allocator.h" namespace blink { @@ -244,10 +245,9 @@ TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -259,10 +259,9 @@ TEST(PaymentRequestTest, OnShippingOptionChange) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -274,12 +273,12 @@ TEST(PaymentRequestTest, CannotCallShowTwice) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->show(scope.GetScriptState(), scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); } TEST(PaymentRequestTest, CannotShowAfterAborted) { @@ -287,15 +286,16 @@ TEST(PaymentRequestTest, CannotShowAfterAborted) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()); - request->abort(scope.GetScriptState()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION); + request->abort(scope.GetScriptState(), ASSERT_NO_EXCEPTION); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( true); - request->show(scope.GetScriptState()) - .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); + request->show(scope.GetScriptState(), scope.GetExceptionState()); + EXPECT_EQ(scope.GetExceptionState().Code(), + ToExceptionCode(DOMExceptionCode::kInvalidStateError)); + ; } TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { @@ -303,11 +303,10 @@ TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( @@ -324,11 +323,10 @@ TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( @@ -344,11 +342,10 @@ TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -364,9 +361,8 @@ TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()) + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnPaymentResponse(BuildPaymentResponseForTest()); @@ -380,10 +376,9 @@ TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -397,10 +392,9 @@ TEST(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -409,8 +403,7 @@ TEST(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) { scope.GetScriptState(), FromJSONString(scope.GetScriptState()->GetIsolate(), scope.GetScriptState()->GetContext(), "{\"total\": {}}", - scope.GetExceptionState()))); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + ASSERT_NO_EXCEPTION))); } TEST(PaymentRequestTest, @@ -423,10 +416,9 @@ TEST(PaymentRequestTest, options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details, - options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + options, ASSERT_NO_EXCEPTION); EXPECT_TRUE(request->shippingOption().IsNull()); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnShippingAddressChange(BuildPaymentAddressForTest()); @@ -440,8 +432,7 @@ TEST(PaymentRequestTest, scope.GetScriptState(), FromJSONString(scope.GetScriptState()->GetIsolate(), scope.GetScriptState()->GetContext(), - detail_with_shipping_options, scope.GetExceptionState()))); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + detail_with_shipping_options, ASSERT_NO_EXCEPTION))); EXPECT_EQ("standardShippingOption", request->shippingOption()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnShippingAddressChange(BuildPaymentAddressForTest()); @@ -449,14 +440,12 @@ TEST(PaymentRequestTest, "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " "\"value\": \"5.00\"}}}"; - request->OnUpdatePaymentDetails( - ScriptValue::From(scope.GetScriptState(), - FromJSONString(scope.GetScriptState()->GetIsolate(), - scope.GetScriptState()->GetContext(), - detail_without_shipping_options, - scope.GetExceptionState()))); + request->OnUpdatePaymentDetails(ScriptValue::From( + scope.GetScriptState(), + FromJSONString(scope.GetScriptState()->GetIsolate(), + scope.GetScriptState()->GetContext(), + detail_without_shipping_options, ASSERT_NO_EXCEPTION))); - EXPECT_FALSE(scope.GetExceptionState().HadException()); EXPECT_TRUE(request->shippingOption().IsNull()); } @@ -469,9 +458,8 @@ TEST( options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()) + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " @@ -485,8 +473,7 @@ TEST( ScriptValue::From(scope.GetScriptState(), FromJSONString(scope.GetScriptState()->GetIsolate(), scope.GetScriptState()->GetContext(), - detail, scope.GetExceptionState()))); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + detail, ASSERT_NO_EXCEPTION))); EXPECT_TRUE(request->shippingOption().IsNull()); } @@ -498,9 +485,8 @@ TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { options->setRequestShipping(true); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), options, scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); - request->show(scope.GetScriptState()) + BuildPaymentDetailsInitForTest(), options, ASSERT_NO_EXCEPTION); + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnShippingAddressChange(BuildPaymentAddressForTest()); @@ -516,8 +502,7 @@ TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { ScriptValue::From(scope.GetScriptState(), FromJSONString(scope.GetScriptState()->GetIsolate(), scope.GetScriptState()->GetContext(), - detail, scope.GetExceptionState()))); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + detail, ASSERT_NO_EXCEPTION))); EXPECT_EQ("fast", request->shippingOption()); } @@ -527,10 +512,9 @@ TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { PaymentRequestMockFunctionScope funcs(scope.GetScriptState()); PaymentRequest* request = PaymentRequest::Create( scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), - BuildPaymentDetailsInitForTest(), scope.GetExceptionState()); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + BuildPaymentDetailsInitForTest(), ASSERT_NO_EXCEPTION); - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); String detail_with_error_msg = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " @@ -541,8 +525,7 @@ TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { scope.GetScriptState(), FromJSONString(scope.GetScriptState()->GetIsolate(), scope.GetScriptState()->GetContext(), - detail_with_error_msg, scope.GetExceptionState()))); - EXPECT_FALSE(scope.GetExceptionState().HadException()); + detail_with_error_msg, ASSERT_NO_EXCEPTION))); } TEST(PaymentRequestTest, diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.cc index 7af3e8cd6f8..fe6de07bba3 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.cc @@ -70,7 +70,7 @@ void PaymentRequestUpdateEvent::updateWith(ScriptState* script_state, UpdatePaymentDetailsFunction::ResolveType::kReject)); } -void PaymentRequestUpdateEvent::Trace(blink::Visitor* visitor) { +void PaymentRequestUpdateEvent::Trace(Visitor* visitor) { visitor->Trace(request_); Event::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.h b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.h index f3e5e0469e5..96d0b510421 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.h @@ -6,9 +6,9 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_REQUEST_UPDATE_EVENT_H_ #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_request_update_event_init.h" #include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/modules/modules_export.h" -#include "third_party/blink/renderer/modules/payments/payment_request_update_event_init.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/timer.h" @@ -44,7 +44,7 @@ class MODULES_EXPORT PaymentRequestUpdateEvent : public Event, void start_waiting_for_update(bool value) { wait_for_update_ = value; } bool is_waiting_for_update() const { return wait_for_update_; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: // True after event.updateWith() was called. diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.idl b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.idl index 90e0ad438f0..0dded8b3f22 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event.idl @@ -6,9 +6,8 @@ [ RuntimeEnabled=PaymentRequest, - Constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict), - ConstructorCallWith=ExecutionContext, Exposed=Window ] interface PaymentRequestUpdateEvent : Event { + [CallWith=ExecutionContext] constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict = {}); [CallWith=ScriptState,RaisesException] void updateWith(Promise<PaymentDetailsUpdate> detailsPromise); }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event_test.cc b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event_test.cc index 930831f133b..f2af6da908e 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_request_update_event_test.cc @@ -34,7 +34,7 @@ class MockPaymentRequest : public GarbageCollected<MockPaymentRequest>, MOCK_METHOD1(OnUpdatePaymentDetailsFailure, void(const String& error)); bool IsInteractive() const override { return true; } - void Trace(blink::Visitor* visitor) override {} + void Trace(Visitor* visitor) override {} private: DISALLOW_COPY_AND_ASSIGN(MockPaymentRequest); @@ -147,7 +147,7 @@ TEST(PaymentRequestUpdateEventTest, AddressChangeUpdateWithTimeout) { EXPECT_FALSE(scope.GetExceptionState().HadException()); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), scope.GetExceptionState()) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -184,7 +184,7 @@ TEST(PaymentRequestUpdateEventTest, OptionChangeUpdateWithTimeout) { EXPECT_FALSE(scope.GetExceptionState().HadException()); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), scope.GetExceptionState()) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) @@ -221,7 +221,7 @@ TEST(PaymentRequestUpdateEventTest, AddressChangePromiseTimeout) { event->SetPaymentRequest(request); event->SetEventPhase(Event::kCapturingPhase); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), scope.GetExceptionState()) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnShippingAddressChange(BuildPaymentAddressForTest()); @@ -255,7 +255,7 @@ TEST(PaymentRequestUpdateEventTest, OptionChangePromiseTimeout) { event->SetPaymentRequest(request); event->SetEventPhase(Event::kCapturingPhase); String error_message; - request->show(scope.GetScriptState()) + request->show(scope.GetScriptState(), scope.GetExceptionState()) .Then(funcs.ExpectNoCall(), funcs.ExpectCall(&error_message)); static_cast<payments::mojom::blink::PaymentRequestClient*>(request) ->OnShippingAddressChange(BuildPaymentAddressForTest()); diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_response.cc b/chromium/third_party/blink/renderer/modules/payments/payment_response.cc index e95bb6f80d3..22418c87097 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_response.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_response.cc @@ -6,9 +6,10 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_validation_errors.h" +#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/modules/payments/payment_address.h" #include "third_party/blink/renderer/modules/payments/payment_state_resolver.h" -#include "third_party/blink/renderer/modules/payments/payment_validation_errors.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/wtf/assertions.h" @@ -21,7 +22,7 @@ PaymentResponse::PaymentResponse( PaymentAddress* shipping_address, PaymentStateResolver* payment_state_resolver, const String& request_id) - : ContextLifecycleObserver(ExecutionContext::From(script_state)), + : ExecutionContextClient(ExecutionContext::From(script_state)), request_id_(request_id), method_name_(response->method_name), shipping_address_(shipping_address), @@ -109,20 +110,24 @@ ScriptValue PaymentResponse::details(ScriptState* script_state) const { } ScriptPromise PaymentResponse::complete(ScriptState* script_state, - const String& result) { + const String& result, + ExceptionState& exception_state) { PaymentStateResolver::PaymentComplete converted_result = PaymentStateResolver::PaymentComplete::kUnknown; if (result == "success") converted_result = PaymentStateResolver::PaymentComplete::kSuccess; else if (result == "fail") converted_result = PaymentStateResolver::PaymentComplete::kFail; - return payment_state_resolver_->Complete(script_state, converted_result); + return payment_state_resolver_->Complete(script_state, converted_result, + exception_state); } ScriptPromise PaymentResponse::retry( ScriptState* script_state, - const PaymentValidationErrors* error_fields) { - return payment_state_resolver_->Retry(script_state, error_fields); + const PaymentValidationErrors* error_fields, + ExceptionState& exception_state) { + return payment_state_resolver_->Retry(script_state, error_fields, + exception_state); } bool PaymentResponse::HasPendingActivity() const { @@ -134,15 +139,15 @@ const AtomicString& PaymentResponse::InterfaceName() const { } ExecutionContext* PaymentResponse::GetExecutionContext() const { - return ContextLifecycleObserver::GetExecutionContext(); + return ExecutionContextClient::GetExecutionContext(); } -void PaymentResponse::Trace(blink::Visitor* visitor) { +void PaymentResponse::Trace(Visitor* visitor) { visitor->Trace(details_); visitor->Trace(shipping_address_); visitor->Trace(payment_state_resolver_); EventTargetWithInlineData::Trace(visitor); - ContextLifecycleObserver::Trace(visitor); + ExecutionContextClient::Trace(visitor); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_response.h b/chromium/third_party/blink/renderer/modules/payments/payment_response.h index c890b371325..4a48f2e9d34 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_response.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_response.h @@ -11,16 +11,17 @@ #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/world_safe_v8_reference.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_currency_amount.h" #include "third_party/blink/renderer/core/dom/events/event_target.h" -#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/modules/modules_export.h" -#include "third_party/blink/renderer/modules/payments/payment_currency_amount.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace blink { +class ExceptionState; class PaymentAddress; class PaymentStateResolver; class PaymentValidationErrors; @@ -28,7 +29,7 @@ class ScriptState; class MODULES_EXPORT PaymentResponse final : public EventTargetWithInlineData, - public ContextLifecycleObserver, + public ExecutionContextClient, public ActiveScriptWrappable<PaymentResponse> { DEFINE_WRAPPERTYPEINFO(); USING_GARBAGE_COLLECTED_MIXIN(PaymentResponse); @@ -58,8 +59,10 @@ class MODULES_EXPORT PaymentResponse final const String& payerEmail() const { return payer_email_; } const String& payerPhone() const { return payer_phone_; } - ScriptPromise complete(ScriptState*, const String& result = ""); - ScriptPromise retry(ScriptState*, const PaymentValidationErrors*); + ScriptPromise complete(ScriptState*, const String& result, ExceptionState&); + ScriptPromise retry(ScriptState*, + const PaymentValidationErrors*, + ExceptionState&); bool HasPendingActivity() const override; @@ -68,7 +71,7 @@ class MODULES_EXPORT PaymentResponse final const AtomicString& InterfaceName() const override; ExecutionContext* GetExecutionContext() const override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: String request_id_; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_response.idl b/chromium/third_party/blink/renderer/modules/payments/payment_response.idl index 6401233f885..21a43c33a33 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_response.idl +++ b/chromium/third_party/blink/renderer/modules/payments/payment_response.idl @@ -29,8 +29,8 @@ enum PaymentComplete { readonly attribute DOMString? payerEmail; readonly attribute DOMString? payerPhone; - [CallWith=ScriptState, NewObject] Promise<void> complete(optional PaymentComplete paymentResult = "unknown"); - [CallWith=ScriptState, NewObject, RuntimeEnabled=PaymentRetry] Promise<void> retry(optional PaymentValidationErrors errorFields); + [CallWith=ScriptState, RaisesException, NewObject] Promise<void> complete(optional PaymentComplete paymentResult = "unknown"); + [CallWith=ScriptState, RaisesException, NewObject, RuntimeEnabled=PaymentRetry] Promise<void> retry(optional PaymentValidationErrors errorFields = {}); [RuntimeEnabled=PaymentRetry] attribute EventHandler onpayerdetailchange; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_response_test.cc b/chromium/third_party/blink/renderer/modules/payments/payment_response_test.cc index 35d6d02f1c4..86e2b2af20b 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_response_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_response_test.cc @@ -14,10 +14,10 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_validation_errors.h" #include "third_party/blink/renderer/modules/payments/payment_address.h" #include "third_party/blink/renderer/modules/payments/payment_state_resolver.h" #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" -#include "third_party/blink/renderer/modules/payments/payment_validation_errors.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" @@ -31,20 +31,22 @@ class MockPaymentStateResolver final public: MockPaymentStateResolver() { - ON_CALL(*this, Complete(testing::_, testing::_)) + ON_CALL(*this, Complete(testing::_, testing::_, testing::_)) .WillByDefault(testing::ReturnPointee(&dummy_promise_)); } ~MockPaymentStateResolver() override = default; - MOCK_METHOD2(Complete, ScriptPromise(ScriptState*, PaymentComplete result)); - MOCK_METHOD2(Retry, + MOCK_METHOD3(Complete, ScriptPromise(ScriptState*, - const PaymentValidationErrors* errorFields)); + PaymentComplete result, + ExceptionState&)); + MOCK_METHOD3(Retry, + ScriptPromise(ScriptState*, + const PaymentValidationErrors* errorFields, + ExceptionState&)); - void Trace(blink::Visitor* visitor) override { - visitor->Trace(dummy_promise_); - } + void Trace(Visitor* visitor) override { visitor->Trace(dummy_promise_); } private: ScriptPromise dummy_promise_; @@ -145,9 +147,11 @@ TEST(PaymentResponseTest, CompleteCalledWithSuccess) { "id"); EXPECT_CALL(*complete_callback, - Complete(scope.GetScriptState(), PaymentStateResolver::kSuccess)); + Complete(scope.GetScriptState(), PaymentStateResolver::kSuccess, + testing::_)); - output->complete(scope.GetScriptState(), "success"); + output->complete(scope.GetScriptState(), "success", + scope.GetExceptionState()); } TEST(PaymentResponseTest, CompleteCalledWithFailure) { @@ -163,9 +167,10 @@ TEST(PaymentResponseTest, CompleteCalledWithFailure) { "id"); EXPECT_CALL(*complete_callback, - Complete(scope.GetScriptState(), PaymentStateResolver::kFail)); + Complete(scope.GetScriptState(), PaymentStateResolver::kFail, + testing::_)); - output->complete(scope.GetScriptState(), "fail"); + output->complete(scope.GetScriptState(), "fail", scope.GetExceptionState()); } TEST(PaymentResponseTest, JSONSerializerTest) { diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_state_resolver.h b/chromium/third_party/blink/renderer/modules/payments/payment_state_resolver.h index c9014ac1e96..781e24c9353 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_state_resolver.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_state_resolver.h @@ -18,8 +18,12 @@ class MODULES_EXPORT PaymentStateResolver : public GarbageCollectedMixin { public: enum PaymentComplete { kFail, kSuccess, kUnknown }; - virtual ScriptPromise Complete(ScriptState*, PaymentComplete result) = 0; - virtual ScriptPromise Retry(ScriptState*, const PaymentValidationErrors*) = 0; + virtual ScriptPromise Complete(ScriptState*, + PaymentComplete result, + ExceptionState&) = 0; + virtual ScriptPromise Retry(ScriptState*, + const PaymentValidationErrors*, + ExceptionState&) = 0; protected: virtual ~PaymentStateResolver() = default; diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.cc b/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.cc index 609c8cd60a5..b79e0eb6f59 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.cc @@ -4,10 +4,10 @@ #include "third_party/blink/renderer/modules/payments/payment_test_helper.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_currency_amount.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_modifier.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" #include "third_party/blink/renderer/core/dom/document.h" -#include "third_party/blink/renderer/modules/payments/payment_currency_amount.h" -#include "third_party/blink/renderer/modules/payments/payment_details_modifier.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/heap/heap_allocator.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h" @@ -215,7 +215,8 @@ payments::mojom::blink::PaymentAddressPtr BuildPaymentAddressForTest() { PaymentRequestV8TestingScope::PaymentRequestV8TestingScope() : V8TestingScope(KURL("https://www.example.com/")) { - GetDocument().SetSecureContextStateForTesting(SecureContextState::kSecure); + GetDocument().SetSecureContextModeForTesting( + SecureContextMode::kSecureContext); } PaymentRequestMockFunctionScope::PaymentRequestMockFunctionScope( diff --git a/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.h b/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.h index 50477fdbb13..44933b8c6d9 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.h +++ b/chromium/third_party/blink/renderer/modules/payments/payment_test_helper.h @@ -10,10 +10,10 @@ #include "third_party/blink/renderer/bindings/core/v8/script_function.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/bindings/core/v8/v8_dom_exception.h" -#include "third_party/blink/renderer/modules/payments/payment_details_init.h" -#include "third_party/blink/renderer/modules/payments/payment_details_update.h" -#include "third_party/blink/renderer/modules/payments/payment_item.h" -#include "third_party/blink/renderer/modules/payments/payment_shipping_option.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_init.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_update.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_item.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h" #include "third_party/blink/renderer/platform/heap/heap_allocator.h" #include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" @@ -116,7 +116,7 @@ class PaymentRequestMockFunctionScope { String* value_; }; - Member<ScriptState> script_state_; + ScriptState* script_state_; Vector<Persistent<MockFunction>> mock_functions_; }; diff --git a/chromium/third_party/blink/renderer/modules/payments/payments_validators.cc b/chromium/third_party/blink/renderer/modules/payments/payments_validators.cc index 2262c8f8733..e103eea6449 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payments_validators.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payments_validators.cc @@ -6,9 +6,9 @@ #include "third_party/blink/renderer/bindings/core/v8/script_regexp.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" -#include "third_party/blink/renderer/modules/payments/address_errors.h" -#include "third_party/blink/renderer/modules/payments/payer_errors.h" -#include "third_party/blink/renderer/modules/payments/payment_validation_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payer_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_validation_errors.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/string_resource.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" diff --git a/chromium/third_party/blink/renderer/modules/payments/payments_validators_test.cc b/chromium/third_party/blink/renderer/modules/payments/payments_validators_test.cc index 1dc6e1baedc..e13cf4a7fdc 100644 --- a/chromium/third_party/blink/renderer/modules/payments/payments_validators_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/payments_validators_test.cc @@ -7,9 +7,9 @@ #include <ostream> // NOLINT #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/blink/renderer/modules/payments/address_errors.h" -#include "third_party/blink/renderer/modules/payments/payer_errors.h" -#include "third_party/blink/renderer/modules/payments/payment_validation_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_address_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payer_errors.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_validation_errors.h" #include "third_party/blink/renderer/platform/weborigin/security_policy.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" diff --git a/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils.cc b/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils.cc index 1a7f1426e13..5e7fb9f1744 100644 --- a/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils.cc +++ b/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils.cc @@ -5,8 +5,8 @@ #include "third_party/blink/renderer/modules/payments/skip_to_gpay_utils.h" #include "base/logging.h" -#include "third_party/blink/renderer/modules/payments/payment_method_data.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_method_data.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/json/json_parser.h" #include "third_party/blink/renderer/platform/json/json_values.h" diff --git a/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils_test.cc b/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils_test.cc index 0d56ae8025d..0de3ffca4a0 100644 --- a/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils_test.cc +++ b/chromium/third_party/blink/renderer/modules/payments/skip_to_gpay_utils_test.cc @@ -8,7 +8,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/blink/renderer/modules/payments/payment_options.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_options.h" namespace blink { namespace { diff --git a/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.cc b/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.cc index 3cdf2fb5da9..b019e50b7e5 100644 --- a/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.cc +++ b/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.cc @@ -30,7 +30,7 @@ UpdatePaymentDetailsFunction::UpdatePaymentDetailsFunction( DCHECK(delegate_); } -void UpdatePaymentDetailsFunction::Trace(blink::Visitor* visitor) { +void UpdatePaymentDetailsFunction::Trace(Visitor* visitor) { visitor->Trace(delegate_); ScriptFunction::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.h b/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.h index 11d32ba1aba..3b7a6426972 100644 --- a/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.h +++ b/chromium/third_party/blink/renderer/modules/payments/update_payment_details_function.h @@ -28,7 +28,7 @@ class UpdatePaymentDetailsFunction : public ScriptFunction { UpdatePaymentDetailsFunction(ScriptState*, PaymentRequestDelegate*, ResolveType); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; ScriptValue Call(ScriptValue) override; private: |