Skip to content

Commit

Permalink
Bug 1490599 - Implement MerchantValidationEvent.prototype.methodName …
Browse files Browse the repository at this point in the history
…attribute. r=baku
  • Loading branch information
Marcos Cáceres committed Sep 13, 2018
1 parent 735929b commit 058bb67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
26 changes: 25 additions & 1 deletion dom/payments/MerchantValidationEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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*
Expand Down
5 changes: 5 additions & 0 deletions dom/payments/MerchantValidationEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class MerchantValidationEvent

void SetValidationURL(nsAString& aValidationURL);

void GetMethodName(nsAString& aMethodName);

void SetMethodName(const nsAString& aMethodName);

protected:
bool init(const MerchantValidationEventInit& aEventInitDict, ErrorResult& aRv);
~MerchantValidationEvent();
Expand All @@ -69,6 +73,7 @@ class MerchantValidationEvent
bool mWaitForUpdate;
nsString mValidationURL;
RefPtr<PaymentRequest> mRequest;
nsString mMethodName;
};

} // namespace dom
Expand Down
2 changes: 2 additions & 0 deletions dom/webidl/MerchantValidationEvent.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
};

0 comments on commit 058bb67

Please sign in to comment.