Bug 1443914 - Force updating PaymentDetails when requestShipping is true. r=baku
authorEden Chuang <chenyu.chuang@gapp.nthu.edu.tw>
Thu, 29 Mar 2018 23:09:52 +0800
changeset 410745 200ba8d2989253c995cfa93c8ad3e3a43546bc13
parent 410744 e207f035fa3d7ba5cb542e793341baca862be6d3
child 410746 1ce3dc676ee905929d1bce3146e19a028deeced3
push id33736
push usershindli@mozilla.com
push dateFri, 30 Mar 2018 09:56:41 +0000
treeherdermozilla-central@b7fa9d95150e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1443914
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 1443914 - Force updating PaymentDetails when requestShipping is true. r=baku Update the implementation according to the spec update. Force updating the saved PaymentDetails when requestShipping is true, even the data(shippingOptions) doesn't present in the DetailsUpdate.
dom/interfaces/payments/nsIPaymentRequest.idl
dom/payments/PaymentRequestData.cpp
--- a/dom/interfaces/payments/nsIPaymentRequest.idl
+++ b/dom/interfaces/payments/nsIPaymentRequest.idl
@@ -57,17 +57,17 @@ interface nsIPaymentDetails : nsISupport
 {
   readonly attribute AString id;
   readonly attribute nsIPaymentItem totalItem;
   readonly attribute nsIArray displayItems;
   readonly attribute nsIArray shippingOptions;
   readonly attribute nsIArray modifiers;
   readonly attribute AString error;
 
-  void update(in nsIPaymentDetails aDetails);
+  void update(in nsIPaymentDetails aDetails, in boolean aRequestShipping);
 };
 
 [scriptable, builtinclass, uuid(d53f9f20-138e-47cc-9fd5-db16a3f6d301)]
 interface nsIPaymentOptions : nsISupports
 {
   readonly attribute boolean requestPayerName;
   readonly attribute boolean requestPayerEmail;
   readonly attribute boolean requestPayerPhone;
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -470,17 +470,17 @@ PaymentDetails::GetModifiers(nsIArray** 
 NS_IMETHODIMP
 PaymentDetails::GetError(nsAString& aError)
 {
   aError = mError;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-PaymentDetails::Update(nsIPaymentDetails* aDetails)
+PaymentDetails::Update(nsIPaymentDetails* aDetails, const bool aRequestShipping)
 {
   MOZ_ASSERT(aDetails);
   /*
    * According to the spec [1], update the attributes if they present in new
    * details (i.e., PaymentDetailsUpdate); otherwise, keep original value.
    * Note |id| comes only from initial details (i.e., PaymentDetailsInit) and
    * |error| only from new details.
    *
@@ -496,22 +496,22 @@ PaymentDetails::Update(nsIPaymentDetails
   rv = aDetails->GetDisplayItems(getter_AddRefs(displayItems));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   if (displayItems) {
     mDisplayItems = displayItems;
   }
 
-  nsCOMPtr<nsIArray> shippingOptions;
-  rv = aDetails->GetShippingOptions(getter_AddRefs(shippingOptions));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  if (shippingOptions) {
+  if (aRequestShipping) {
+    nsCOMPtr<nsIArray> shippingOptions;
+    rv = aDetails->GetShippingOptions(getter_AddRefs(shippingOptions));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
     mShippingOptions = shippingOptions;
   }
 
   nsCOMPtr<nsIArray> modifiers;
   rv = aDetails->GetModifiers(getter_AddRefs(modifiers));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
@@ -673,17 +673,22 @@ PaymentRequest::GetPaymentOptions(nsIPay
   options.forget(aPaymentOptions);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PaymentRequest::UpdatePaymentDetails(nsIPaymentDetails* aPaymentDetails)
 {
   MOZ_ASSERT(aPaymentDetails);
-  return mPaymentDetails->Update(aPaymentDetails);
+  bool requestShipping;
+  nsresult rv = mPaymentOptions->GetRequestShipping(&requestShipping);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+  return mPaymentDetails->Update(aPaymentDetails, requestShipping);
 }
 
 NS_IMETHODIMP
 PaymentRequest::SetCompleteStatus(const nsAString& aCompleteStatus)
 {
   mCompleteStatus = aCompleteStatus;
   return NS_OK;
 }