Bug 1486954 - Part V, Prevent credit card record from being accessed if not initialize r=MattN
authorTimothy Guan-tin Chien <timdream@gmail.com>
Thu, 18 Oct 2018 22:10:25 +0000
changeset 490745 740ead88dd207c38155800e176c693987a762d2d
parent 490744 f5c7e2bc2d6315e9a28436c4a4849e0ae241c9a9
child 490746 98061ccbb1578415b354083859381fb3a588444a
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersMattN
bugs1486954
milestone65.0a1
Bug 1486954 - Part V, Prevent credit card record from being accessed if not initialize r=MattN This patch changed the initialization of records so that we don't call into credit card AutofillRecords class if it is pref-off. Differential Revision: https://phabricator.services.mozilla.com/D9158
browser/components/payments/test/browser/browser.ini
browser/extensions/formautofill/FormAutofillStorage.jsm
--- a/browser/components/payments/test/browser/browser.ini
+++ b/browser/components/payments/test/browser/browser.ini
@@ -1,13 +1,14 @@
 [DEFAULT]
 head = head.js
 prefs =
   browser.pagethumbnails.capturing_disabled=true
   dom.payments.request.enabled=true
+  extensions.formautofill.creditCards.available=true
 skip-if = !e10s # Bug 1365964 - Payment Request isn't implemented for non-e10s
 support-files =
   blank_page.html
 
 [browser_address_edit.js]
 skip-if = verify && debug && os == 'mac'
 [browser_card_edit.js]
 skip-if = (verify && debug && os == 'mac') || (os == 'linux' && debug) # bug 1465673
--- a/browser/extensions/formautofill/FormAutofillStorage.jsm
+++ b/browser/extensions/formautofill/FormAutofillStorage.jsm
@@ -1920,19 +1920,32 @@ FormAutofillStorage.prototype = {
    */
   initialize() {
     if (!this._initializePromise) {
       this._store = new JSONFile({
         path: this._path,
         dataPostProcessor: this._dataPostProcessor.bind(this),
       });
       this._initializePromise = this._store.load()
-        .then(() => Promise.all([
-          this.addresses.initialize(),
-          this.creditCards.initialize()]));
+        .then(() => {
+          let initializeAutofillRecords = [this.addresses.initialize()];
+          if (FormAutofill.isAutofillCreditCardsEnabled) {
+            initializeAutofillRecords.push(this.creditCards.initialize());
+          } else {
+            // Make creditCards records unavailable to other modules
+            // because we never initialize it.
+            Object.defineProperty(this, "creditCards", {
+              get() {
+                throw new Error("CreditCards is not initialized. " +
+                                "Please restart if you flip the pref manually.");
+              },
+            });
+          }
+          return Promise.all(initializeAutofillRecords);
+        });
     }
     return this._initializePromise;
   },
 
   _dataPostProcessor(data) {
     data.version = this.version;
     if (!data.addresses) {
       data.addresses = [];