Bug 1379892 - Reject PaymentRequest.show() with AbortError DOMException if a request is showing. r=baku

This commit is contained in:
Eden Chuang 2017-07-25 15:39:39 +08:00
parent c92100c21c
commit 3aa4930b7a
5 changed files with 72 additions and 5 deletions

View File

@ -384,7 +384,11 @@ PaymentRequest::Show(ErrorResult& aRv)
}
nsresult rv = manager->ShowPayment(mInternalId);
if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(NS_ERROR_FAILURE);
if (rv == NS_ERROR_ABORT) {
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
} else {
promise->MaybeReject(NS_ERROR_DOM_NOT_ALLOWED_ERR);
}
mState = eClosed;
return promise.forget();
}

View File

@ -490,6 +490,9 @@ PaymentRequestManager::CanMakePayment(const nsAString& aRequestId)
nsresult
PaymentRequestManager::ShowPayment(const nsAString& aRequestId)
{
if (mShowingRequest) {
return NS_ERROR_ABORT;
}
RefPtr<PaymentRequest> request = GetPaymentRequestById(aRequestId);
if (!request) {
return NS_ERROR_FAILURE;
@ -497,8 +500,9 @@ PaymentRequestManager::ShowPayment(const nsAString& aRequestId)
nsAutoString requestId(aRequestId);
IPCPaymentShowActionRequest action(requestId);
return SendRequestPayment(request, action);
nsresult rv = SendRequestPayment(request, action);
mShowingRequest = request;
return rv;
}
nsresult
@ -593,6 +597,8 @@ PaymentRequestManager::RespondPayment(const IPCPaymentActionResponse& aResponse)
response.payerEmail(),
response.payerPhone());
if (!response.isAccepted()) {
MOZ_ASSERT(mShowingRequest == request);
mShowingRequest = nullptr;
mRequestQueue.RemoveElement(request);
nsresult rv = ReleasePaymentChild(request);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -609,6 +615,8 @@ PaymentRequestManager::RespondPayment(const IPCPaymentActionResponse& aResponse)
}
request->RespondAbortPayment(response.isSucceeded());
if (response.isSucceeded()) {
MOZ_ASSERT(mShowingRequest == request);
mShowingRequest = nullptr;
mRequestQueue.RemoveElement(request);
nsresult rv = ReleasePaymentChild(request);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -624,6 +632,8 @@ PaymentRequestManager::RespondPayment(const IPCPaymentActionResponse& aResponse)
return NS_ERROR_FAILURE;
}
request->RespondComplete();
MOZ_ASSERT(mShowingRequest == request);
mShowingRequest = nullptr;
mRequestQueue.RemoveElement(request);
nsresult rv = ReleasePaymentChild(request);
if (NS_WARN_IF(NS_FAILED(rv))) {

View File

@ -79,6 +79,7 @@ private:
// The container for the created PaymentRequests
nsTArray<RefPtr<PaymentRequest>> mRequestQueue;
nsRefPtrHashtable<nsRefPtrHashKey<PaymentRequest>, PaymentRequestChild> mPaymentChildHash;
RefPtr<PaymentRequest> mShowingRequest;
};
} // end of namespace dom

View File

@ -306,11 +306,46 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest)
* 2. Check third party payment app support by traversing all
* registered third party payment apps.
*/
case nsIPaymentActionRequest::CANMAKE_ACTION:
case nsIPaymentActionRequest::CANMAKE_ACTION: {
rv = CallTestingUIAction(requestId, type);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_FAILURE;
}
break;
}
/*
* TODO: Launch/inform payment UI here once the UI module is implemented.
*/
case nsIPaymentActionRequest::SHOW_ACTION:
case nsIPaymentActionRequest::SHOW_ACTION: {
if (mShowingRequest) {
nsCOMPtr<nsIPaymentShowActionResponse> showResponse =
do_CreateInstance(NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID);
MOZ_ASSERT(showResponse);
rv = showResponse->Init(requestId,
nsIPaymentActionResponse::PAYMENT_REJECTED,
EmptyString(),
EmptyString(),
EmptyString(),
EmptyString(),
EmptyString());
nsCOMPtr<nsIPaymentActionResponse> response = do_QueryInterface(showResponse);
MOZ_ASSERT(response);
rv = RespondPayment(response);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
rv = GetPaymentRequestById(requestId, getter_AddRefs(mShowingRequest));
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_FAILURE;
}
rv = CallTestingUIAction(requestId, type);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_FAILURE;
}
}
break;
}
case nsIPaymentActionRequest::ABORT_ACTION:
case nsIPaymentActionRequest::COMPLETE_ACTION: {
rv = CallTestingUIAction(requestId, type);
@ -391,11 +426,26 @@ PaymentRequestService::RespondPayment(nsIPaymentActionResponse* aResponse)
rv = response->IsSucceeded(&isSucceeded);
NS_ENSURE_SUCCESS(rv, rv);
if (isSucceeded) {
mShowingRequest = nullptr;
mRequestQueue.RemoveElement(request);
}
break;
}
case nsIPaymentActionResponse::SHOW_ACTION: {
nsCOMPtr<nsIPaymentShowActionResponse> response =
do_QueryInterface(aResponse);
MOZ_ASSERT(response);
bool isAccepted;
rv = response->IsAccepted(&isAccepted);
NS_ENSURE_SUCCESS(rv, rv);
if (!isAccepted) {
mShowingRequest = nullptr;
mRequestQueue.RemoveElement(request);
}
break;
}
case nsIPaymentActionResponse::COMPLETE_ACTION: {
mShowingRequest = nullptr;
mRequestQueue.RemoveElement(request);
break;
}

View File

@ -51,6 +51,8 @@ private:
nsInterfaceHashtable<nsStringHashKey, nsIPaymentActionCallback> mCallbackHashtable;
nsCOMPtr<nsIPaymentUIService> mTestingUIService;
nsCOMPtr<nsIPaymentRequest> mShowingRequest;
};
} // end of namespace dom