From 058bb67c47c6d207e214f342592b80dd80f23dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Thu, 13 Sep 2018 21:06:00 +0300 Subject: [PATCH] Bug 1490599 - Implement MerchantValidationEvent.prototype.methodName attribute. r=baku --- dom/payments/MerchantValidationEvent.cpp | 26 ++++++++++++++++++++++- dom/payments/MerchantValidationEvent.h | 5 +++++ dom/webidl/MerchantValidationEvent.webidl | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dom/payments/MerchantValidationEvent.cpp b/dom/payments/MerchantValidationEvent.cpp index 974cb6959761..ddfab8eb55ca 100644 --- a/dom/payments/MerchantValidationEvent.cpp +++ b/dom/payments/MerchantValidationEvent.cpp @@ -64,6 +64,17 @@ bool MerchantValidationEvent::init(const MerchantValidationEventInit& aEventInitDict, ErrorResult& aRv) { + // Check methodName is valid + if (!aEventInitDict.mMethodName.IsEmpty()) { + nsString errMsg; + auto rv = PaymentRequest::IsValidPaymentMethodIdentifier( + aEventInitDict.mMethodName, errMsg); + if (NS_FAILED(rv)) { + aRv.ThrowRangeError(errMsg); + return false; + } + } + SetMethodName(aEventInitDict.mMethodName); nsCOMPtr window = do_QueryInterface(GetParentObject()); auto doc = window->GetExtantDoc(); if (!doc) { @@ -120,7 +131,8 @@ MerchantValidationEvent::ResolvedCallback(JSContext* aCx, // https://w3c.github.io/payment-request/#validate-merchant-s-details-algorithm // // Right now, MerchantValidationEvent is only implemented for standards - // conformance, which is why at this point we throw a NS_ERROR_DOM_NOT_SUPPORTED_ERR. + // conformance, which is why at this point we throw a + // NS_ERROR_DOM_NOT_SUPPORTED_ERR. mRequest->AbortUpdate(NS_ERROR_DOM_NOT_SUPPORTED_ERR, false); mRequest->SetUpdating(false); @@ -184,6 +196,18 @@ MerchantValidationEvent::SetValidationURL(nsAString& aValidationURL) mValidationURL.Assign(aValidationURL); } +void +MerchantValidationEvent::GetMethodName(nsAString& aMethodName) +{ + aMethodName.Assign(mMethodName); +} + +void +MerchantValidationEvent::SetMethodName(const nsAString& aMethodName) +{ + mMethodName.Assign(aMethodName); +} + MerchantValidationEvent::~MerchantValidationEvent() {} JSObject* diff --git a/dom/payments/MerchantValidationEvent.h b/dom/payments/MerchantValidationEvent.h index be6555f34434..ad641cc13173 100644 --- a/dom/payments/MerchantValidationEvent.h +++ b/dom/payments/MerchantValidationEvent.h @@ -60,6 +60,10 @@ public: void SetValidationURL(nsAString& aValidationURL); + void GetMethodName(nsAString& aMethodName); + + void SetMethodName(const nsAString& aMethodName); + protected: bool init(const MerchantValidationEventInit& aEventInitDict, ErrorResult& aRv); ~MerchantValidationEvent(); @@ -69,6 +73,7 @@ private: bool mWaitForUpdate; nsString mValidationURL; RefPtr mRequest; + nsString mMethodName; }; } // namespace dom diff --git a/dom/webidl/MerchantValidationEvent.webidl b/dom/webidl/MerchantValidationEvent.webidl index e2e35ec42aed..a3c279cf5c04 100644 --- a/dom/webidl/MerchantValidationEvent.webidl +++ b/dom/webidl/MerchantValidationEvent.webidl @@ -13,11 +13,13 @@ SecureContext, Exposed=Window, Func="mozilla::dom::PaymentRequest::PrefEnabled"] interface MerchantValidationEvent : Event { + readonly attribute DOMString methodName; readonly attribute USVString validationURL; [Throws] void complete(Promise merchantSessionPromise); }; dictionary MerchantValidationEventInit : EventInit { + DOMString methodName = ""; USVString validationURL = ""; };