Bug 1435155 - Redact the shipping address as it is visible before the promise from PaymentRequest.show() resolves successfully. r?baku draft
authorHenri Sivonen <hsivonen@hsivonen.fi>
Wed, 07 Mar 2018 09:39:08 +0200
changeset 764795 3c3713c63324fe21ca7e626ff16dd5d139364590
parent 764106 1a8e77cb2c21d4f42dd3e90fdcbece7a633b473b
child 764803 8a292997b3addc8bab5da48ce3d05cc6e8a1d076
push id101848
push userbmo:hsivonen@hsivonen.fi
push dateThu, 08 Mar 2018 09:35:37 +0000
reviewersbaku
bugs1435155
milestone60.0a1
Bug 1435155 - Redact the shipping address as it is visible before the promise from PaymentRequest.show() resolves successfully. r?baku Spec PR: https://github.com/w3c/payment-request/pull/654 MozReview-Commit-ID: 2AiKI7htRhk
dom/payments/PaymentRequest.cpp
dom/payments/PaymentRequest.h
dom/payments/test/ShowPaymentChromeScript.js
dom/payments/test/test_showPayment.html
--- a/dom/payments/PaymentRequest.cpp
+++ b/dom/payments/PaymentRequest.cpp
@@ -26,25 +26,27 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PaymentRequest,
                                                   DOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResultPromise)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAcceptPromise)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAbortPromise)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResponse)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mShippingAddress)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFullShippingAddress)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PaymentRequest,
                                                 DOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mResultPromise)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAcceptPromise)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAbortPromise)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mResponse)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mShippingAddress)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mFullShippingAddress)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PaymentRequest)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(PaymentRequest, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(PaymentRequest, DOMEventTargetHelper)
 
@@ -738,16 +740,20 @@ PaymentRequest::RespondShowPayment(const
   MOZ_ASSERT(ReadyForUpdate());
   MOZ_ASSERT(mState == eInteractive);
 
   if (NS_FAILED(aRv)) {
     RejectShowPayment(aRv);
     return;
   }
 
+  // https://github.com/w3c/payment-request/issues/692
+  mShippingAddress.swap(mFullShippingAddress);
+  mFullShippingAddress = nullptr;
+
   RefPtr<PaymentResponse> paymentResponse =
     new PaymentResponse(GetOwner(), mInternalId, mId, aMethodName,
                         mShippingOption, mShippingAddress, aDetails,
                         aPayerName, aPayerEmail, aPayerPhone);
   mResponse = paymentResponse;
   mAcceptPromise->MaybeResolve(paymentResponse);
 
   mState = eClosed;
@@ -935,21 +941,25 @@ PaymentRequest::UpdateShippingAddress(co
                                       const nsAString& aDependentLocality,
                                       const nsAString& aPostalCode,
                                       const nsAString& aSortingCode,
                                       const nsAString& aLanguageCode,
                                       const nsAString& aOrganization,
                                       const nsAString& aRecipient,
                                       const nsAString& aPhone)
 {
-  mShippingAddress = new PaymentAddress(GetOwner(), aCountry, aAddressLine,
+  nsTArray<nsString> emptyArray;
+  mShippingAddress = new PaymentAddress(GetOwner(), aCountry, emptyArray,
                                         aRegion, aCity, aDependentLocality,
                                         aPostalCode, aSortingCode, aLanguageCode,
-                                        aOrganization, aRecipient, aPhone);
-
+                                        EmptyString(), EmptyString(), EmptyString());
+  mFullShippingAddress = new PaymentAddress(GetOwner(), aCountry, aAddressLine,
+                                            aRegion, aCity, aDependentLocality,
+                                            aPostalCode, aSortingCode, aLanguageCode,
+                                            aOrganization, aRecipient, aPhone);
   // Fire shippingaddresschange event
   return DispatchUpdateEvent(NS_LITERAL_STRING("shippingaddresschange"));
 }
 
 void
 PaymentRequest::SetShippingOption(const nsAString& aShippingOption)
 {
   mShippingOption = aShippingOption;
--- a/dom/payments/PaymentRequest.h
+++ b/dom/payments/PaymentRequest.h
@@ -156,18 +156,20 @@ protected:
   // Promise for "PaymentRequest::CanMakePayment"
   RefPtr<Promise> mResultPromise;
   // Promise for "PaymentRequest::Show"
   RefPtr<Promise> mAcceptPromise;
   // Promise for "PaymentRequest::Abort"
   RefPtr<Promise> mAbortPromise;
   // Resolve mAcceptPromise with mResponse if user accepts the request.
   RefPtr<PaymentResponse> mResponse;
-  // It is populated when the user provides a shipping address.
+  // The redacted shipping address.
   RefPtr<PaymentAddress> mShippingAddress;
+  // The full shipping address to be used in the response upon payment.
+  RefPtr<PaymentAddress> mFullShippingAddress;
   // It is populated when the user chooses a shipping option.
   nsString mShippingOption;
 
   Nullable<PaymentShippingType> mShippingType;
 
   // "true" when there is a pending updateWith() call to update the payment request
   // and "false" otherwise.
   bool mUpdating;
--- a/dom/payments/test/ShowPaymentChromeScript.js
+++ b/dom/payments/test/ShowPaymentChromeScript.js
@@ -16,21 +16,21 @@ const shippingAddress = Cc["@mozilla.org
 const addressLine = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
 const address = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
 address.data = "Easton Ave";
 addressLine.appendElement(address);
 shippingAddress.init("USA",              // country
                      addressLine,        // address line
                      "CA",               // region
                      "San Bruno",        // city
-                     "",                 // dependent locality
+                     "Test locality",    // dependent locality
                      "94066",            // postal code
                      "123456",           // sorting code
                      "en",               // language code
-                     "",                 // organization
+                     "Testing Org",      // organization
                      "Bill A. Pacheco",  // recipient
                      "+1-434-441-3879"); // phone
 
 const NormalUIService = {
   shippingOptionChanged: false,
   showPayment: function(requestId) {
     paymentSrv.changeShippingAddress(requestId, shippingAddress);
   },
--- a/dom/payments/test/test_showPayment.html
+++ b/dom/payments/test/test_showPayment.html
@@ -18,17 +18,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   function testFailHandler(message) {
     ok(false, message);
   }
   gScript.addMessageListener("test-fail", testFailHandler);
 
   const defaultMethods = [{
     supportedMethods: "basic-card",
-    data: { 
+    data: {
       supportedNetworks: ['unionpay', 'visa', 'mastercard', 'amex', 'discover',
                           'diners', 'jcb', 'mir',
       ],
       supportedTypes: ['prepaid', 'debit', 'credit'],
     },
   }, {
     supportedMethods: "testing-payment-method",
   }];
@@ -155,40 +155,61 @@ https://bugzilla.mozilla.org/show_bug.cg
     });
   }
 
   function testShow() {
     gScript.sendAsyncMessage("set-normal-ui-service");
     return new Promise((resolve, reject) => {
       const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
       payRequest.addEventListener("shippingaddresschange", event => {
+        is(payRequest.shippingAddress.country, "USA", "payRequest.shippingAddress.country should be 'USA' from event.");
+        is(payRequest.shippingAddress.addressLine.length, 0, "payRequest.shippingAddress.addressLine.length should be 0 from event.");
+        is(payRequest.shippingAddress.region, "CA", "payRequest.shippingAddress.region should be 'CA' from event.");
+        is(payRequest.shippingAddress.city, "San Bruno", "payRequest.shippingAddress.city should be 'San Bruno' from event.");
+        is(payRequest.shippingAddress.dependentLocality, "Test locality", "payRequest.shippingAddress.dependentLocality should be 'Test locality' from event.");
+        is(payRequest.shippingAddress.postalCode, "94066", "payRequest.shippingAddress.postalCode should be '94066' from event.");
+        is(payRequest.shippingAddress.sortingCode, "123456", "payRequest.shippingAddress.sortingCode should be '123456' from event.");
+        is(payRequest.shippingAddress.organization, "", "payRequest.shippingAddress.organization should be empty from event.");
+        is(payRequest.shippingAddress.recipient, "", "payRequest.shippingAddress.recipient should be empty from event.");
+        is(payRequest.shippingAddress.phone, "", "payRequest.shippingAddress.phone should be empty from event.");
         event.updateWith(updateWithShippingAddress());
       });
       payRequest.addEventListener("shippingoptionchange", event => {
         event.updateWith(updateWithShippingOption());
       });
       payRequest.show().then(response => {
         is(response.requestId, "test payment", "response.requestId should be 'test payment'.");
         is(response.methodName, "testing-payment-method", "response.methodName should be 'testing-payment-method'.");
         is(response.details.paymentToken, "6880281f-0df3-4b8e-916f-66575e2457c1", "response.details.paymentToken should be '6880281f-0df3-4b8e-916f-66575e2457c1'.");
         is(response.shippingAddress.country, "USA", "response.shippingAddress.country should be 'USA'.");
         is(response.shippingAddress.addressLine.length, 1, "response.shippingAddress.addressLine.length should be 1.");
         is(response.shippingAddress.addressLine[0], "Easton Ave", "response.shippingAddress.addressLine[0] should be 'Easton Ave'.");
         is(response.shippingAddress.region, "CA", "response.shippingAddress.region should be 'CA'.");
         is(response.shippingAddress.city, "San Bruno", "response.shippingAddress.city should be 'San Bruno'.");
-        is(response.shippingAddress.dependentLocality, "", "response.shippingAddress.dependentLocality should be empty.");
+        is(response.shippingAddress.dependentLocality, "Test locality", "response.shippingAddress.dependentLocality should be 'Test locality'.");
         is(response.shippingAddress.postalCode, "94066", "response.shippingAddress.postalCode should be '94066'.");
         is(response.shippingAddress.sortingCode, "123456", "response.shippingAddress.sortingCode should be '123456'.");
-        is(response.shippingAddress.organization, "", "response.shippingAddress.organization should be empty.");
+        is(response.shippingAddress.organization, "Testing Org", "response.shippingAddress.organization should be 'Testing Org'.");
         is(response.shippingAddress.recipient, "Bill A. Pacheco", "response.shippingAddress.recipient should be 'Bill A. Pacheco'.");
         is(response.shippingAddress.phone, "+1-434-441-3879", "response.shippingAddress.phone should be '+1-434-441-3879'.");
         is(response.shippingOption, "FastShipping", "response.shippingOption should be 'FastShipping'.");
         is(response.payerName, "Bill A. Pacheco", "response.payerName should be 'Bill A. Pacheco'.");
-        ok(!response.payerEamil, "response.payerEmail should be empty");
+        ok(!response.payerEmail, "response.payerEmail should be empty");
         ok(!response.payerPhone, "response.payerPhone should be empty");
+        is(payRequest.shippingAddress.country, "USA", "payRequest.shippingAddress.country should be 'USA' from promise.");
+        is(payRequest.shippingAddress.addressLine.length, 1, "payRequest.shippingAddress.addressLine.length should be 1 from promise.");
+        is(payRequest.shippingAddress.addressLine[0], "Easton Ave", "payRequest.shippingAddress.addressLine[0] should be 'Easton Ave' from promise.");
+        is(payRequest.shippingAddress.region, "CA", "payRequest.shippingAddress.region should be 'CA' from promise.");
+        is(payRequest.shippingAddress.city, "San Bruno", "payRequest.shippingAddress.city should be 'San Bruno' from promise.");
+        is(payRequest.shippingAddress.dependentLocality, "Test locality", "payRequest.shippingAddress.dependentLocality should be 'Test locality' from promise.");
+        is(payRequest.shippingAddress.postalCode, "94066", "payRequest.shippingAddress.postalCode should be '94066' from promise.");
+        is(payRequest.shippingAddress.sortingCode, "123456", "payRequest.shippingAddress.sortingCode should be '123456' from promise.");
+        is(payRequest.shippingAddress.organization, "Testing Org", "payRequest.shippingAddress.organization should be 'Testing Org' from promise.");
+        is(payRequest.shippingAddress.recipient, "Bill A. Pacheco", "payRequest.shippingAddress.recipient should be 'Bill A. Pacheco' from promise.");
+        is(payRequest.shippingAddress.phone, "+1-434-441-3879", "payRequest.shippingAddress.phone should be '+1-434-441-3879' from promise.");
         response.complete("success").then(() =>{
           resolve();
         }).catch(e => {
           ok(false, "Unexpected error: " + e.name);
           resolve();
         });
       }).catch( e => {
         ok(false, "Unexpected error: " + e.name);