Bug 1440041 - Add a new readonly attribute nsIPaymentRequest.shippingOption. r=baku.
authorEden Chuang <chenyu.chuang@gapp.nthu.edu.tw>
Fri, 13 Apr 2018 18:47:20 -0700
changeset 413318 8b12f74a216d
parent 413317 a3df33c5d526
child 413319 f07f19c30db9
push id102139
push usermozilla@noorenberghe.ca
push dateSat, 14 Apr 2018 04:54:11 +0000
treeherdermozilla-inbound@f07f19c30db9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1440041
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1440041 - Add a new readonly attribute nsIPaymentRequest.shippingOption. r=baku.
dom/interfaces/payments/nsIPaymentActionRequest.idl
dom/interfaces/payments/nsIPaymentRequest.idl
dom/payments/PaymentActionRequest.cpp
dom/payments/PaymentActionRequest.h
dom/payments/PaymentRequestData.cpp
dom/payments/PaymentRequestData.h
dom/payments/PaymentRequestManager.cpp
dom/payments/PaymentRequestService.cpp
dom/payments/ipc/PPaymentRequest.ipdl
dom/payments/ipc/PaymentRequestParent.cpp
--- a/dom/interfaces/payments/nsIPaymentActionRequest.idl
+++ b/dom/interfaces/payments/nsIPaymentActionRequest.idl
@@ -77,25 +77,31 @@ interface nsIPaymentCreateActionRequest 
   readonly attribute nsIPaymentDetails details;
 
   /*
    *  The Options information of the payment request.
    */
   readonly attribute nsIPaymentOptions options;
 
   /*
+   *  The selected shipping option of the payment request;
+   */
+  readonly attribute AString shippingOption;
+
+  /*
    *  Initialize function the this request.
    */
   void initRequest(in AString aRequestId,
                    in nsIPaymentActionCallback aCallback,
                    in uint64_t aTabId,
                    in nsIPrincipal aPrincipal,
                    in nsIArray aMethodData,
                    in nsIPaymentDetails aDetails,
-                   in nsIPaymentOptions aOptions);
+                   in nsIPaymentOptions aOptions,
+		   in AString aShippingOption);
 };
 
 [builtinclass, uuid(4429697d-1135-47de-a46e-5196d399ec55)]
 interface nsIPaymentCompleteActionRequest : nsIPaymentActionRequest
 {
   /*
    *  The complete status from merchant side.
    */
@@ -113,21 +119,27 @@ interface nsIPaymentCompleteActionReques
 interface nsIPaymentUpdateActionRequest : nsIPaymentActionRequest
 {
   /*
    *  The details information for updating the specified payment request.
    */
   readonly attribute nsIPaymentDetails details;
 
   /*
+   *  The selected shipping option information
+   */
+  readonly attribute AString shippingOption;
+
+  /*
    *  Initialize function for this request.
    */
   void initRequest(in AString aRequestId,
                    in nsIPaymentActionCallback aCallback,
-                   in nsIPaymentDetails aDetails);
+                   in nsIPaymentDetails aDetails,
+		   in AString aShippingOption);
 };
 
 %{C++
 #define NS_PAYMENT_ACTION_REQUEST_CID \
   { 0x7ddbe8be, 0xbeac, 0x4952, { 0x96, 0xf6, 0x61, 0x99, 0x81, 0xdf, 0xf7, 0xa6 } }
 #define NS_PAYMENT_ACTION_REQUEST_CONTRACT_ID \
   "@mozilla.org/dom/payments/payment-action-request;1"
 
--- a/dom/interfaces/payments/nsIPaymentRequest.idl
+++ b/dom/interfaces/payments/nsIPaymentRequest.idl
@@ -80,12 +80,14 @@ interface nsIPaymentRequest : nsISupport
 {
   readonly attribute uint64_t tabId;
   readonly attribute nsIPrincipal topLevelPrincipal;
   readonly attribute AString requestId;
   readonly attribute AString completeStatus;
   readonly attribute nsIArray paymentMethods;
   readonly attribute nsIPaymentDetails paymentDetails;
   readonly attribute nsIPaymentOptions paymentOptions;
+  readonly attribute AString shippingOption;
 
   [noscript] void setCompleteStatus(in AString aCompleteStatus);
-  void updatePaymentDetails(in nsIPaymentDetails aDetails);
+  void updatePaymentDetails(in nsIPaymentDetails aDetails,
+                            in AString aShippingOption);
 };
--- a/dom/payments/PaymentActionRequest.cpp
+++ b/dom/payments/PaymentActionRequest.cpp
@@ -73,32 +73,34 @@ PaymentCreateActionRequest::PaymentCreat
 
 NS_IMETHODIMP
 PaymentCreateActionRequest::InitRequest(const nsAString& aRequestId,
                                         nsIPaymentActionCallback* aCallback,
                                         const uint64_t aTabId,
                                         nsIPrincipal* aTopLevelPrincipal,
                                         nsIArray* aMethodData,
                                         nsIPaymentDetails* aDetails,
-                                        nsIPaymentOptions* aOptions)
+                                        nsIPaymentOptions* aOptions,
+					const nsAString& aShippingOption)
 {
   NS_ENSURE_ARG_POINTER(aCallback);
   NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
   NS_ENSURE_ARG_POINTER(aMethodData);
   NS_ENSURE_ARG_POINTER(aDetails);
   NS_ENSURE_ARG_POINTER(aOptions);
   nsresult rv = Init(aRequestId, nsIPaymentActionRequest::CREATE_ACTION, aCallback);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   mTabId = aTabId;
   mTopLevelPrincipal = aTopLevelPrincipal;
   mMethodData = aMethodData;
   mDetails = aDetails;
   mOptions = aOptions;
+  mShippingOption = aShippingOption;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PaymentCreateActionRequest::GetTabId(uint64_t* aTabId)
 {
   NS_ENSURE_ARG_POINTER(aTabId);
   *aTabId = mTabId;
@@ -140,16 +142,23 @@ PaymentCreateActionRequest::GetOptions(n
 {
   NS_ENSURE_ARG_POINTER(aOptions);
   MOZ_ASSERT(mOptions);
   nsCOMPtr<nsIPaymentOptions> options = mOptions;
   options.forget(aOptions);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+PaymentCreateActionRequest::GetShippingOption(nsAString& aShippingOption)
+{
+  aShippingOption = mShippingOption;
+  return NS_OK;
+}
+
 /* PaymentCompleteActionRequest */
 
 NS_IMPL_ISUPPORTS_INHERITED(PaymentCompleteActionRequest,
                             PaymentActionRequest,
                             nsIPaymentCompleteActionRequest)
 
 PaymentCompleteActionRequest::PaymentCompleteActionRequest()
   : mCompleteStatus(EmptyString())
@@ -189,24 +198,33 @@ PaymentUpdateActionRequest::GetDetails(n
   NS_ENSURE_ARG_POINTER(aDetails);
   MOZ_ASSERT(mDetails);
   nsCOMPtr<nsIPaymentDetails> details = mDetails;
   details.forget(aDetails);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+PaymentUpdateActionRequest::GetShippingOption(nsAString& aShippingOption)
+{
+  aShippingOption = mShippingOption;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 PaymentUpdateActionRequest::InitRequest(const nsAString& aRequestId,
                                         nsIPaymentActionCallback* aCallback,
-                                        nsIPaymentDetails* aDetails)
+                                        nsIPaymentDetails* aDetails,
+					const nsAString& aShippingOption)
 {
   NS_ENSURE_ARG_POINTER(aCallback);
   NS_ENSURE_ARG_POINTER(aDetails);
   nsresult rv = Init(aRequestId, nsIPaymentActionRequest::UPDATE_ACTION, aCallback);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   mDetails = aDetails;
+  mShippingOption = aShippingOption;
   return NS_OK;
 }
 
 } // end of namespace dom
 } // end of namespace mozilla
--- a/dom/payments/PaymentActionRequest.h
+++ b/dom/payments/PaymentActionRequest.h
@@ -44,16 +44,17 @@ public:
 private:
   ~PaymentCreateActionRequest() = default;
 
   uint64_t mTabId;
   nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
   nsCOMPtr<nsIArray> mMethodData;
   nsCOMPtr<nsIPaymentDetails> mDetails;
   nsCOMPtr<nsIPaymentOptions> mOptions;
+  nsString mShippingOption;
 };
 
 class PaymentCompleteActionRequest final : public nsIPaymentCompleteActionRequest
                                          , public PaymentActionRequest
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_FORWARD_NSIPAYMENTACTIONREQUEST(PaymentActionRequest::)
@@ -75,14 +76,15 @@ public:
   NS_FORWARD_NSIPAYMENTACTIONREQUEST(PaymentActionRequest::)
   NS_DECL_NSIPAYMENTUPDATEACTIONREQUEST
 
   PaymentUpdateActionRequest() = default;
 private:
   ~PaymentUpdateActionRequest() = default;
 
   nsCOMPtr<nsIPaymentDetails> mDetails;
+  nsString mShippingOption;
 };
 
 } // end of namespace dom
 } // end of namespace mozilla
 
 #endif
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -604,23 +604,25 @@ PaymentOptions::GetShippingType(nsAStrin
 NS_IMPL_ISUPPORTS(PaymentRequest,
                   nsIPaymentRequest)
 
 PaymentRequest::PaymentRequest(const uint64_t aTabId,
                                const nsAString& aRequestId,
                                nsIPrincipal* aTopLevelPrincipal,
                                nsIArray* aPaymentMethods,
                                nsIPaymentDetails* aPaymentDetails,
-                               nsIPaymentOptions* aPaymentOptions)
+                               nsIPaymentOptions* aPaymentOptions,
+			       const nsAString& aShippingOption)
   : mTabId(aTabId)
   , mRequestId(aRequestId)
   , mTopLevelPrincipal(aTopLevelPrincipal)
   , mPaymentMethods(aPaymentMethods)
   , mPaymentDetails(aPaymentDetails)
   , mPaymentOptions(aPaymentOptions)
+  , mShippingOption(aShippingOption)
 {
 }
 
 NS_IMETHODIMP
 PaymentRequest::GetTabId(uint64_t* aTabId)
 {
   NS_ENSURE_ARG_POINTER(aTabId);
   *aTabId = mTabId;
@@ -670,24 +672,33 @@ PaymentRequest::GetPaymentOptions(nsIPay
   NS_ENSURE_ARG_POINTER(aPaymentOptions);
   MOZ_ASSERT(mPaymentOptions);
   nsCOMPtr<nsIPaymentOptions> options = mPaymentOptions;
   options.forget(aPaymentOptions);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-PaymentRequest::UpdatePaymentDetails(nsIPaymentDetails* aPaymentDetails)
+PaymentRequest::GetShippingOption(nsAString& aShippingOption)
+{
+  aShippingOption = mShippingOption;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+PaymentRequest::UpdatePaymentDetails(nsIPaymentDetails* aPaymentDetails,
+                                     const nsAString& aShippingOption)
 {
   MOZ_ASSERT(aPaymentDetails);
   bool requestShipping;
   nsresult rv = mPaymentOptions->GetRequestShipping(&requestShipping);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
+  mShippingOption = aShippingOption;
   return mPaymentDetails->Update(aPaymentDetails, requestShipping);
 }
 
 NS_IMETHODIMP
 PaymentRequest::SetCompleteStatus(const nsAString& aCompleteStatus)
 {
   mCompleteStatus = aCompleteStatus;
   return NS_OK;
--- a/dom/payments/PaymentRequestData.h
+++ b/dom/payments/PaymentRequestData.h
@@ -179,28 +179,30 @@ public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPAYMENTREQUEST
 
   PaymentRequest(const uint64_t aTabId,
                  const nsAString& aRequestId,
                  nsIPrincipal* aPrincipal,
                  nsIArray* aPaymentMethods,
                  nsIPaymentDetails* aPaymentDetails,
-                 nsIPaymentOptions* aPaymentOptions);
+                 nsIPaymentOptions* aPaymentOptions,
+		 const nsAString& aShippingOption);
 
 private:
   ~PaymentRequest() = default;
 
   uint64_t mTabId;
   nsString mRequestId;
   nsString mCompleteStatus;
   nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
   nsCOMPtr<nsIArray> mPaymentMethods;
   nsCOMPtr<nsIPaymentDetails> mPaymentDetails;
   nsCOMPtr<nsIPaymentOptions> mPaymentOptions;
+  nsString mShippingOption;
 };
 
 class PaymentAddress final : public nsIPaymentAddress
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPAYMENTADDRESS
 
--- a/dom/payments/PaymentRequestManager.cpp
+++ b/dom/payments/PaymentRequestManager.cpp
@@ -462,17 +462,18 @@ PaymentRequestManager::CreatePayment(JSC
 
   IPCPaymentOptions options;
   ConvertOptions(aOptions, options);
 
   IPCPaymentCreateActionRequest action(internalId,
                                        IPC::Principal(aTopLevelPrincipal),
                                        methodData,
                                        details,
-                                       options);
+                                       options,
+				       shippingOption);
 
   rv = SendRequestPayment(request, action, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   mRequestQueue.AppendElement(request);
   request.forget(aRequest);
   return NS_OK;
@@ -568,17 +569,17 @@ PaymentRequestManager::UpdatePayment(JSC
   nsAutoString shippingOption;
   SetDOMStringToNull(shippingOption);
   if (aRequestShipping) {
     GetSelectedShippingOption(aDetails, shippingOption);
     request->SetShippingOption(shippingOption);
   }
 
   nsAutoString requestId(aRequestId);
-  IPCPaymentUpdateActionRequest action(requestId, details);
+  IPCPaymentUpdateActionRequest action(requestId, details, shippingOption);
   return SendRequestPayment(request, action);
 }
 
 nsresult
 PaymentRequestManager::RespondPayment(const IPCPaymentActionResponse& aResponse)
 {
   switch (aResponse.type()) {
     case IPCPaymentActionResponse::TIPCPaymentCanMakeActionResponse: {
--- a/dom/payments/PaymentRequestService.cpp
+++ b/dom/payments/PaymentRequestService.cpp
@@ -248,19 +248,23 @@ PaymentRequestService::RequestPayment(ns
       nsCOMPtr<nsIPaymentDetails> details;
       rv = request->GetDetails(getter_AddRefs(details));
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIPaymentOptions> options;
       rv = request->GetOptions(getter_AddRefs(options));
       NS_ENSURE_SUCCESS(rv, rv);
 
+      nsAutoString shippingOption;
+      rv = request->GetShippingOption(shippingOption);
+      NS_ENSURE_SUCCESS(rv, rv);
+
       nsCOMPtr<nsIPaymentRequest> payment =
         new payments::PaymentRequest(tabId, requestId, topLevelPrincipal,
-                                     methodData, details, options);
+                                     methodData, details, options, shippingOption);
 
       if (!mRequestQueue.AppendElement(payment, mozilla::fallible)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
       break;
     }
     case nsIPaymentActionRequest::CANMAKE_ACTION: {
       nsCOMPtr<nsIPaymentCanMakeActionResponse> canMakeResponse =
@@ -352,24 +356,28 @@ PaymentRequestService::RequestPayment(ns
     case nsIPaymentActionRequest::UPDATE_ACTION: {
       nsCOMPtr<nsIPaymentUpdateActionRequest> request = do_QueryInterface(aRequest);
       MOZ_ASSERT(request);
 
       nsCOMPtr<nsIPaymentDetails> details;
       rv = request->GetDetails(getter_AddRefs(details));
       NS_ENSURE_SUCCESS(rv, rv);
 
+      nsAutoString shippingOption;
+      rv = request->GetShippingOption(shippingOption);
+      NS_ENSURE_SUCCESS(rv, rv);
+
       rv = request->GetRequestId(requestId);
       NS_ENSURE_SUCCESS(rv, rv);
       nsCOMPtr<nsIPaymentRequest> payment;
       rv = GetPaymentRequestById(requestId, getter_AddRefs(payment));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
-      rv = payment->UpdatePaymentDetails(details);
+      rv = payment->UpdatePaymentDetails(details, shippingOption);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       if (mShowingRequest) {
         MOZ_ASSERT(mShowingRequest == payment);
         rv = LaunchUIAction(requestId, type);
       } else {
         mShowingRequest = payment;
--- a/dom/payments/ipc/PPaymentRequest.ipdl
+++ b/dom/payments/ipc/PPaymentRequest.ipdl
@@ -71,16 +71,17 @@ struct IPCPaymentOptions
 
 struct IPCPaymentCreateActionRequest
 {
   nsString requestId;
   Principal topLevelPrincipal;
   IPCPaymentMethodData[] methodData;
   IPCPaymentDetails details;
   IPCPaymentOptions options;
+  nsString shippingOption;
 };
 
 struct IPCPaymentCanMakeActionRequest
 {
   nsString requestId;
 };
 
 struct IPCPaymentShowActionRequest
@@ -98,16 +99,17 @@ struct IPCPaymentCompleteActionRequest
   nsString requestId;
   nsString completeStatus;
 };
 
 struct IPCPaymentUpdateActionRequest
 {
   nsString requestId;
   IPCPaymentDetails details;
+  nsString shippingOption;
 };
 
 union IPCPaymentActionRequest
 {
   IPCPaymentCreateActionRequest;
   IPCPaymentCanMakeActionRequest;
   IPCPaymentShowActionRequest;
   IPCPaymentAbortActionRequest;
--- a/dom/payments/ipc/PaymentRequestParent.cpp
+++ b/dom/payments/ipc/PaymentRequestParent.cpp
@@ -71,17 +71,18 @@ PaymentRequestParent::RecvRequestPayment
         return IPC_FAIL_NO_REASON(this);
       }
       rv = createAction->InitRequest(request.requestId(),
                                      callback,
                                      mTabId,
                                      request.topLevelPrincipal(),
                                      methodData,
                                      details,
-                                     options);
+                                     options,
+				     request.shippingOption());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return IPC_FAIL_NO_REASON(this);
       }
 
       action = do_QueryInterface(createAction);
       MOZ_ASSERT(action);
       break;
     }
@@ -137,17 +138,18 @@ PaymentRequestParent::RecvRequestPayment
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return IPC_FAIL_NO_REASON(this);
       }
 
       nsCOMPtr<nsIPaymentUpdateActionRequest> updateAction =
         do_CreateInstance(NS_PAYMENT_UPDATE_ACTION_REQUEST_CONTRACT_ID);
       rv = updateAction->InitRequest(request.requestId(),
                                      callback,
-                                     details);
+                                     details,
+				     request.shippingOption());
       action = do_QueryInterface(updateAction);
       MOZ_ASSERT(action);
       break;
     }
     default: {
       return IPC_FAIL(this, "Unexpected request type");
     }
   }