Bug 1474143 - Use sharedData instead of initialProcessData for autofillEnabled. r=Felipe
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Sat, 23 Feb 2019 00:22:57 +0000
changeset 460708 93aed64c54ca61d0cc4cfa137461c18ce2abadc9
parent 460707 913a5a45b3c51c40db3a086c81bac8b7ea36935b
child 460709 ffc0f96ff0b12b89142e2097889e2b2c8eb31e48
push id78821
push usermozilla@noorenberghe.ca
push dateSat, 23 Feb 2019 00:27:30 +0000
treeherderautoland@5a471d8ee829 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1474143
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1474143 - Use sharedData instead of initialProcessData for autofillEnabled. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D16647
browser/extensions/formautofill/FormAutofillContent.jsm
browser/extensions/formautofill/FormAutofillParent.jsm
browser/extensions/formautofill/test/unit/test_activeStatus.js
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -353,20 +353,21 @@ var FormAutofillContent = {
    * @type {Object} The object where to store the active items, e.g. element,
    * handler, section, and field detail.
    */
   _activeItems: {},
 
   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.
     let shouldEnableAutofill = autofillEnabled === undefined &&
                                (FormAutofill.isAutofillAddressesEnabled ||
                                FormAutofill.isAutofillCreditCardsEnabled);
     if (autofillEnabled || shouldEnableAutofill) {
       ProfileAutocomplete.ensureRegistered();
@@ -423,20 +424,23 @@ var FormAutofillContent = {
 
       this._onFormSubmit(records, domWin, handler.timeStartedFillingMS);
     } catch (ex) {
       Cu.reportError(ex);
     }
     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();
         }
         break;
       }
     }
   },
--- a/browser/extensions/formautofill/FormAutofillParent.jsm
+++ b/browser/extensions/formautofill/FormAutofillParent.jsm
@@ -182,20 +182,20 @@ FormAutofillParent.prototype = {
     }
   },
 
   /**
    * Broadcast the status to frames when the form autofill status changes.
    */
   _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();
   },
 
   /**
    * Query preference and storage status to determine the overall status of the
    * form autofill feature.
    *
    * @returns {boolean} whether form autofill is active (enabled and has data)
    */
--- a/browser/extensions/formautofill/test/unit/test_activeStatus.js
+++ b/browser/extensions/formautofill/test/unit/test_activeStatus.js
@@ -11,29 +11,29 @@ add_task(async function setup() {
 });
 
 add_task(async function test_activeStatus_init() {
   let formAutofillParent = new FormAutofillParent();
   sinon.spy(formAutofillParent, "_updateStatus");
 
   // 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();
 });
 
 add_task(async function test_activeStatus_observe() {
   let formAutofillParent = new FormAutofillParent();
   sinon.stub(formAutofillParent, "_computeStatus");
   sinon.spy(formAutofillParent, "_onStatusChanged");