From 9509d5a0932c78cf603c86803607c61c69cc6874 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Sat, 23 Feb 2019 00:22:39 +0000 Subject: [PATCH] Bug 1474143 - Use sharedData instead of initialProcessData for autofillSavedFieldNames. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D16646 --HG-- extra : moz-landing-system : lando --- .../formautofill/FormAutofillContent.jsm | 11 +++-------- .../formautofill/FormAutofillParent.jsm | 17 +++++++++-------- .../test/unit/test_savedFieldNames.js | 6 +++--- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/browser/extensions/formautofill/FormAutofillContent.jsm b/browser/extensions/formautofill/FormAutofillContent.jsm index f2f9a807801e..405d367e2ede 100644 --- a/browser/extensions/formautofill/FormAutofillContent.jsm +++ b/browser/extensions/formautofill/FormAutofillContent.jsm @@ -345,7 +345,9 @@ var FormAutofillContent = { /** * @type {Set} Set of the fields with usable values in any saved profile. */ - savedFieldNames: null, + get savedFieldNames() { + return Services.cpmm.sharedData.get("FormAutofill:savedFieldNames"); + }, /** * @type {Object} The object where to store the active items, e.g. element, @@ -357,7 +359,6 @@ var FormAutofillContent = { FormAutofill.defineLazyLogGetter(this, "FormAutofillContent"); Services.cpmm.addMessageListener("FormAutofill:enabledStatus", this); - Services.cpmm.addMessageListener("FormAutofill:savedFieldNames", this); Services.obs.addObserver(this, "earlyformsubmit"); let autofillEnabled = Services.cpmm.initialProcessData.autofillEnabled; @@ -370,9 +371,6 @@ var FormAutofillContent = { if (autofillEnabled || shouldEnableAutofill) { ProfileAutocomplete.ensureRegistered(); } - - this.savedFieldNames = - Services.cpmm.initialProcessData.autofillSavedFieldNames; }, /** @@ -440,9 +438,6 @@ var FormAutofillContent = { } break; } - case "FormAutofill:savedFieldNames": { - this.savedFieldNames = data; - } } }, diff --git a/browser/extensions/formautofill/FormAutofillParent.jsm b/browser/extensions/formautofill/FormAutofillParent.jsm index 5f5e56ee6875..0d5ab207bd1b 100644 --- a/browser/extensions/formautofill/FormAutofillParent.jsm +++ b/browser/extensions/formautofill/FormAutofillParent.jsm @@ -200,7 +200,7 @@ FormAutofillParent.prototype = { * @returns {boolean} whether form autofill is active (enabled and has data) */ _computeStatus() { - const savedFieldNames = Services.ppmm.initialProcessData.autofillSavedFieldNames; + const savedFieldNames = Services.ppmm.sharedData.get("FormAutofill:savedFieldNames"); return (Services.prefs.getBoolPref(ENABLED_AUTOFILL_ADDRESSES_PREF) || Services.prefs.getBoolPref(ENABLED_AUTOFILL_CREDITCARDS_PREF)) && @@ -375,18 +375,19 @@ FormAutofillParent.prototype = { _updateSavedFieldNames() { log.debug("_updateSavedFieldNames"); + let savedFieldNames; // Don't access the credit cards store unless it is enabled. if (FormAutofill.isAutofillCreditCardsAvailable) { - Services.ppmm.initialProcessData.autofillSavedFieldNames = - new Set([...this.formAutofillStorage.addresses.getSavedFieldNames(), - ...this.formAutofillStorage.creditCards.getSavedFieldNames()]); + savedFieldNames = new Set([ + ...this.formAutofillStorage.addresses.getSavedFieldNames(), + ...this.formAutofillStorage.creditCards.getSavedFieldNames(), + ]); } else { - Services.ppmm.initialProcessData.autofillSavedFieldNames = - this.formAutofillStorage.addresses.getSavedFieldNames(); + savedFieldNames = this.formAutofillStorage.addresses.getSavedFieldNames(); } - Services.ppmm.broadcastAsyncMessage("FormAutofill:savedFieldNames", - Services.ppmm.initialProcessData.autofillSavedFieldNames); + Services.ppmm.sharedData.set("FormAutofill:savedFieldNames", savedFieldNames); + this._updateStatus(); }, diff --git a/browser/extensions/formautofill/test/unit/test_savedFieldNames.js b/browser/extensions/formautofill/test/unit/test_savedFieldNames.js index f19e28ff0c7f..3e46db55b727 100644 --- a/browser/extensions/formautofill/test/unit/test_savedFieldNames.js +++ b/browser/extensions/formautofill/test/unit/test_savedFieldNames.js @@ -1,5 +1,5 @@ /* - * Test for keeping the valid fields information in initialProcessData. + * Test for keeping the valid fields information in sharedData. */ "use strict"; @@ -54,7 +54,7 @@ add_task(async function test_profileSavedFieldNames_update() { // The set is empty if there's no profile in the store. formAutofillParent._updateSavedFieldNames(); - Assert.equal(Services.ppmm.initialProcessData.autofillSavedFieldNames.size, 0); + Assert.equal(Services.ppmm.sharedData.get("FormAutofill:savedFieldNames").size, 0); // 2 profiles with 4 valid fields. formAutofillParent.formAutofillStorage.addresses._data = [{ @@ -81,7 +81,7 @@ add_task(async function test_profileSavedFieldNames_update() { formAutofillParent._updateSavedFieldNames(); - let autofillSavedFieldNames = Services.ppmm.initialProcessData.autofillSavedFieldNames; + let autofillSavedFieldNames = Services.ppmm.sharedData.get("FormAutofill:savedFieldNames"); Assert.equal(autofillSavedFieldNames.size, 4); Assert.equal(autofillSavedFieldNames.has("organization"), true); Assert.equal(autofillSavedFieldNames.has("street-address"), true);