Bug 1490599 - Implement MerchantValidationEvent.prototype.methodName attribute. r=baku

This commit is contained in:
Marcos Cáceres 2018-09-13 21:06:00 +03:00
parent 735929bed7
commit 058bb67c47
3 changed files with 32 additions and 1 deletions

View File

@ -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<MSG_ILLEGAL_RANGE_PR_CONSTRUCTOR>(errMsg);
return false;
}
}
SetMethodName(aEventInitDict.mMethodName);
nsCOMPtr<nsPIDOMWindowInner> 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*

View File

@ -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<PaymentRequest> mRequest;
nsString mMethodName;
};
} // namespace dom

View File

@ -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<any> merchantSessionPromise);
};
dictionary MerchantValidationEventInit : EventInit {
DOMString methodName = "";
USVString validationURL = "";
};