From b15b8a8c36581e06c86420cd97c4815ff31b1d34 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Sat, 23 Feb 2019 00:22:57 +0000 Subject: [PATCH] Bug 1474143 - Use sharedData instead of initialProcessData for autofillEnabled. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D16647 --HG-- extra : moz-landing-system : lando --- .../formautofill/FormAutofillContent.jsm | 16 ++++++++++------ .../formautofill/FormAutofillParent.jsm | 6 +++--- .../formautofill/test/unit/test_activeStatus.js | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/browser/extensions/formautofill/FormAutofillContent.jsm b/browser/extensions/formautofill/FormAutofillContent.jsm index 405d367e2ede..9fd194b3b11a 100644 --- a/browser/extensions/formautofill/FormAutofillContent.jsm +++ b/browser/extensions/formautofill/FormAutofillContent.jsm @@ -358,10 +358,11 @@ var FormAutofillContent = { init() { FormAutofill.defineLazyLogGetter(this, "FormAutofillContent"); - Services.cpmm.addMessageListener("FormAutofill:enabledStatus", this); + // eslint-disable-next-line mozilla/balanced-listeners + Services.cpmm.sharedData.addEventListener("change", this); Services.obs.addObserver(this, "earlyformsubmit"); - let autofillEnabled = Services.cpmm.initialProcessData.autofillEnabled; + let autofillEnabled = Services.cpmm.sharedData.get("FormAutofill:enabled"); // If storage hasn't be initialized yet autofillEnabled is undefined but we need to ensure // autocomplete is registered before the focusin so register it in this case as long as the // pref is true. @@ -428,10 +429,13 @@ var FormAutofillContent = { return true; }, - receiveMessage({name, data}) { - switch (name) { - case "FormAutofill:enabledStatus": { - if (data) { + handleEvent(evt) { + switch (evt.type) { + case "change": { + if (!evt.changedKeys.includes("FormAutofill:enabled")) { + return; + } + if (Services.cpmm.sharedData.get("FormAutofill:enabled")) { ProfileAutocomplete.ensureRegistered(); } else { ProfileAutocomplete.ensureUnregistered(); diff --git a/browser/extensions/formautofill/FormAutofillParent.jsm b/browser/extensions/formautofill/FormAutofillParent.jsm index 0d5ab207bd1b..b46895598902 100644 --- a/browser/extensions/formautofill/FormAutofillParent.jsm +++ b/browser/extensions/formautofill/FormAutofillParent.jsm @@ -187,10 +187,10 @@ FormAutofillParent.prototype = { */ _onStatusChanged() { log.debug("_onStatusChanged: Status changed to", this._active); - Services.ppmm.broadcastAsyncMessage("FormAutofill:enabledStatus", this._active); - // Sync process data autofillEnabled to make sure the value up to date + Services.ppmm.sharedData.set("FormAutofill:enabled", this._active); + // Sync autofill enabled to make sure the value is up-to-date // no matter when the new content process is initialized. - Services.ppmm.initialProcessData.autofillEnabled = this._active; + Services.ppmm.sharedData.flush(); }, /** diff --git a/browser/extensions/formautofill/test/unit/test_activeStatus.js b/browser/extensions/formautofill/test/unit/test_activeStatus.js index edff798742d0..013809ebb988 100644 --- a/browser/extensions/formautofill/test/unit/test_activeStatus.js +++ b/browser/extensions/formautofill/test/unit/test_activeStatus.js @@ -16,19 +16,19 @@ add_task(async function test_activeStatus_init() { // Default status is null before initialization Assert.equal(formAutofillParent._active, null); - Assert.equal(Services.ppmm.initialProcessData.autofillEnabled, undefined); + Assert.equal(Services.ppmm.sharedData.get("FormAutofill:enabled"), undefined); await formAutofillParent.init(); // init shouldn't call updateStatus since that requires storage which will // lead to startup time regressions. Assert.equal(formAutofillParent._updateStatus.called, false); - Assert.equal(Services.ppmm.initialProcessData.autofillEnabled, undefined); + Assert.equal(Services.ppmm.sharedData.get("FormAutofill:enabled"), undefined); // Initialize profile storage await formAutofillParent.formAutofillStorage.initialize(); // Upon first initializing profile storage, status should be computed. Assert.equal(formAutofillParent._updateStatus.called, true); - Assert.equal(Services.ppmm.initialProcessData.autofillEnabled, false); + Assert.equal(Services.ppmm.sharedData.get("FormAutofill:enabled"), false); formAutofillParent._uninit(); });