From 68bb5bfa3c12d26024cfa9ca75f2cafff7c7055c Mon Sep 17 00:00:00 2001 From: Eden Chuang Date: Thu, 16 Aug 2018 14:27:24 +0200 Subject: [PATCH] Bug 1483470 - Handling PaymentRequestService::RespondPayment() to a closed PaymentRequest. r=baku 1. Returning NS_ERROR_FAILURE in PaymentRequestService::RespondPayment() when the specified PaymentRequest does not exist in PaymentRequestService. 2. Renaming "cleanup" to "close" in DOM::WebPayment codes to fit the actual behavior. --- dom/interfaces/payments/nsIPaymentActionRequest.idl | 2 +- dom/payments/PaymentRequest.cpp | 2 +- dom/payments/PaymentRequestManager.cpp | 4 ++-- dom/payments/PaymentRequestManager.h | 2 +- dom/payments/PaymentRequestService.cpp | 7 +++++-- dom/payments/ipc/PPaymentRequest.ipdl | 4 ++-- dom/payments/ipc/PaymentRequestParent.cpp | 6 +++--- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dom/interfaces/payments/nsIPaymentActionRequest.idl b/dom/interfaces/payments/nsIPaymentActionRequest.idl index a9d1eff1f52d..73b2889ecfd0 100644 --- a/dom/interfaces/payments/nsIPaymentActionRequest.idl +++ b/dom/interfaces/payments/nsIPaymentActionRequest.idl @@ -29,7 +29,7 @@ interface nsIPaymentActionRequest : nsISupports const uint32_t ABORT_ACTION = 4; const uint32_t COMPLETE_ACTION = 5; const uint32_t UPDATE_ACTION = 6; - const uint32_t CLEANUP_ACTION = 7; + const uint32_t CLOSE_ACTION = 7; /* * The payment request identifier. diff --git a/dom/payments/PaymentRequest.cpp b/dom/payments/PaymentRequest.cpp index 3e025e47ac53..b28389dc5ed3 100644 --- a/dom/payments/PaymentRequest.cpp +++ b/dom/payments/PaymentRequest.cpp @@ -1094,7 +1094,7 @@ PaymentRequest::NotifyOwnerDocumentActivityChanged() if (!doc->IsCurrentActiveDocument()) { RefPtr mgr = PaymentRequestManager::GetSingleton(); - mgr->CleanupPayment(this); + mgr->ClosePayment(this); } } diff --git a/dom/payments/PaymentRequestManager.cpp b/dom/payments/PaymentRequestManager.cpp index 0ba6fba878b1..078e3dd50ed2 100644 --- a/dom/payments/PaymentRequestManager.cpp +++ b/dom/payments/PaymentRequestManager.cpp @@ -524,7 +524,7 @@ PaymentRequestManager::UpdatePayment(JSContext* aCx, } nsresult -PaymentRequestManager::CleanupPayment(PaymentRequest* aRequest) +PaymentRequestManager::ClosePayment(PaymentRequest* aRequest) { // for the case, the payment request is waiting for response from user. if (auto entry = mActivePayments.Lookup(aRequest)) { @@ -535,7 +535,7 @@ PaymentRequestManager::CleanupPayment(PaymentRequest* aRequest) } nsAutoString requestId; aRequest->GetInternalId(requestId); - IPCPaymentCleanupActionRequest action(requestId); + IPCPaymentCloseActionRequest action(requestId); return SendRequestPayment(aRequest, action, false); } diff --git a/dom/payments/PaymentRequestManager.h b/dom/payments/PaymentRequestManager.h index c91f1d2a80d1..89e2b644547d 100644 --- a/dom/payments/PaymentRequestManager.h +++ b/dom/payments/PaymentRequestManager.h @@ -57,7 +57,7 @@ public: const PaymentDetailsUpdate& aDetails, bool aRequestShipping, bool aDeferredShow); - nsresult CleanupPayment(PaymentRequest* aRequest); + nsresult ClosePayment(PaymentRequest* aRequest); nsresult RespondPayment(PaymentRequest* aRequest, const IPCPaymentActionResponse& aResponse); diff --git a/dom/payments/PaymentRequestService.cpp b/dom/payments/PaymentRequestService.cpp index a54b82f3989f..2d910b4b7e83 100644 --- a/dom/payments/PaymentRequestService.cpp +++ b/dom/payments/PaymentRequestService.cpp @@ -382,7 +382,7 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest) } break; } - case nsIPaymentActionRequest::CLEANUP_ACTION: { + case nsIPaymentActionRequest::CLOSE_ACTION: { nsCOMPtr payment; rv = GetPaymentRequestById(requestId, getter_AddRefs(payment)); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -393,7 +393,6 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest) mShowingRequest = nullptr; } mRequestQueue.RemoveElement(payment); - //RemoveActionCallback(requestId); break; } default: { @@ -417,6 +416,10 @@ PaymentRequestService::RespondPayment(nsIPaymentActionResponse* aResponse) return rv; } + if (!request) { + return NS_ERROR_FAILURE; + } + nsCOMPtr callback; if (!mCallbackHashtable.Get(requestId, getter_AddRefs(callback))) { return NS_ERROR_FAILURE; diff --git a/dom/payments/ipc/PPaymentRequest.ipdl b/dom/payments/ipc/PPaymentRequest.ipdl index 7f2f1311f810..f104c4acdf97 100644 --- a/dom/payments/ipc/PPaymentRequest.ipdl +++ b/dom/payments/ipc/PPaymentRequest.ipdl @@ -105,7 +105,7 @@ struct IPCPaymentUpdateActionRequest nsString shippingOption; }; -struct IPCPaymentCleanupActionRequest +struct IPCPaymentCloseActionRequest { nsString requestId; }; @@ -118,7 +118,7 @@ union IPCPaymentActionRequest IPCPaymentAbortActionRequest; IPCPaymentCompleteActionRequest; IPCPaymentUpdateActionRequest; - IPCPaymentCleanupActionRequest; + IPCPaymentCloseActionRequest; }; struct IPCPaymentCanMakeActionResponse diff --git a/dom/payments/ipc/PaymentRequestParent.cpp b/dom/payments/ipc/PaymentRequestParent.cpp index 6529980f1c9f..94119ce4bc34 100644 --- a/dom/payments/ipc/PaymentRequestParent.cpp +++ b/dom/payments/ipc/PaymentRequestParent.cpp @@ -147,10 +147,10 @@ PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest MOZ_ASSERT(action); break; } - case IPCPaymentActionRequest::TIPCPaymentCleanupActionRequest: { - const IPCPaymentCleanupActionRequest& request = aRequest; + case IPCPaymentActionRequest::TIPCPaymentCloseActionRequest: { + const IPCPaymentCloseActionRequest& request = aRequest; rv = CreateActionRequest(request.requestId(), - nsIPaymentActionRequest::CLEANUP_ACTION, + nsIPaymentActionRequest::CLOSE_ACTION, getter_AddRefs(action)); if (NS_WARN_IF(NS_FAILED(rv))) { return IPC_FAIL_NO_REASON(this);