Bug 1429205 - Add a sendMessageToContent helper for paymentDialogWrapper. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 20 Feb 2018 15:56:33 -0800
changeset 759104 9d9d274ee33699c3c1a85ec689e0491d71431f3f
parent 759103 d3363d47276bf078c00d6d3bd9d231ebbce4c4b4
child 759105 88503c645f6a6310e30607ef4e3df9df52aa4627
push id100272
push userrwood@mozilla.com
push dateFri, 23 Feb 2018 18:27:33 +0000
reviewersjaws
bugs1429205
milestone60.0a1
Bug 1429205 - Add a sendMessageToContent helper for paymentDialogWrapper. r=jaws MozReview-Commit-ID: FgeQaOR5yno
toolkit/components/payments/content/paymentDialogWrapper.js
--- a/toolkit/components/payments/content/paymentDialogWrapper.js
+++ b/toolkit/components/payments/content/paymentDialogWrapper.js
@@ -232,22 +232,26 @@ var paymentDialogWrapper = {
       // Filter out the encrypted card number since the dialog content is
       // considered untrusted and runs in a content process.
       delete card["cc-number-encrypted"];
     }
     return savedBasicCards;
   },
 
   onAutofillStorageChange() {
+    this.sendMessageToContent("updateState", {
+      savedAddresses: this.fetchSavedAddresses(),
+      savedBasicCards: this.fetchSavedPaymentCards(),
+    });
+  },
+
+  sendMessageToContent(messageType, data = {}) {
     this.mm.sendAsyncMessage("paymentChromeToContent", {
-      messageType: "updateState",
-      data: {
-        savedAddresses: this.fetchSavedAddresses(),
-        savedBasicCards: this.fetchSavedPaymentCards(),
-      },
+      data,
+      messageType,
     });
   },
 
   /**
    * Recursively convert and filter input to the subset of data types supported by JSON
    *
    * @param {*} value - any type of input to serialize
    * @param {string?} name - name or key associated with this input.
@@ -320,24 +324,20 @@ var paymentDialogWrapper = {
         obj[key] = result;
       }
     }
     return obj;
   },
 
   initializeFrame() {
     let requestSerialized = this._serializeRequest(this.request);
-
-    this.mm.sendAsyncMessage("paymentChromeToContent", {
-      messageType: "showPaymentRequest",
-      data: {
-        request: requestSerialized,
-        savedAddresses: this.fetchSavedAddresses(),
-        savedBasicCards: this.fetchSavedPaymentCards(),
-      },
+    this.sendMessageToContent("showPaymentRequest", {
+      request: requestSerialized,
+      savedAddresses: this.fetchSavedAddresses(),
+      savedBasicCards: this.fetchSavedPaymentCards(),
     });
 
     Services.obs.addObserver(this, "formautofill-storage-changed", true);
   },
 
   debugFrame() {
     // To avoid self-XSS-type attacks, ensure that Browser Chrome debugging is enabled.
     if (!Services.prefs.getBoolPref("devtools.chrome.enabled", false)) {