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
This commit is contained in:
Matthew Noorenberghe 2019-02-23 00:22:57 +00:00
Родитель 9509d5a093
Коммит b15b8a8c36
3 изменённых файлов: 16 добавлений и 12 удалений

Просмотреть файл

@ -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();

Просмотреть файл

@ -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();
},
/**

Просмотреть файл

@ -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();
});