diff --git a/browser/extensions/formautofill/FormAutofillParent.jsm b/browser/extensions/formautofill/FormAutofillParent.jsm index f112f139b067..5944312f5978 100644 --- a/browser/extensions/formautofill/FormAutofillParent.jsm +++ b/browser/extensions/formautofill/FormAutofillParent.jsm @@ -27,7 +27,9 @@ "use strict"; -this.EXPORTED_SYMBOLS = ["FormAutofillParent"]; +// We expose a singleton from this module. Some tests may import the +// constructor via a backstage pass. +this.EXPORTED_SYMBOLS = ["formAutofillParent"]; const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; @@ -78,10 +80,30 @@ FormAutofillParent.prototype = { */ _active: null, + /** + * The status of Form Autofill's initialization. + */ + _initialized: false, + + /** + * Exposes the status of Form Autofill's initialization. It can be used to + * determine whether Form Autofill is available for current users. + * + * @returns {boolean} Whether FormAutofillParent is initialized. + */ + get initialized() { + return this._initialized; + }, + /** * Initializes ProfileStorage and registers the message handler. */ async init() { + if (this._initialized) { + return; + } + this._initialized = true; + Services.obs.addObserver(this, "sync-pane-loaded"); Services.ppmm.addMessageListener("FormAutofill:InitStorage", this); Services.ppmm.addMessageListener("FormAutofill:GetRecords", this); @@ -552,3 +574,5 @@ FormAutofillParent.prototype = { histogram.add(`${formType}-${fillingType}`, Date.now() - startedFillingMS); }, }; + +this.formAutofillParent = new FormAutofillParent(); diff --git a/browser/extensions/formautofill/bootstrap.js b/browser/extensions/formautofill/bootstrap.js index 3a21191a5b0b..22c3906b809b 100644 --- a/browser/extensions/formautofill/bootstrap.js +++ b/browser/extensions/formautofill/bootstrap.js @@ -16,7 +16,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate", "resource://gre/modules/AddonManager.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillParent", +XPCOMUtils.defineLazyModuleGetter(this, "formAutofillParent", "resource://formautofill/FormAutofillParent.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillUtils", "resource://formautofill/FormAutofillUtils.jsm"); @@ -110,8 +110,7 @@ function startup(data) { // Listen for the autocomplete popup message to lazily append our stylesheet related to the popup. Services.mm.addMessageListener("FormAutoComplete:MaybeOpenPopup", onMaybeOpenPopup); - let parent = new FormAutofillParent(); - parent.init().catch(Cu.reportError); + formAutofillParent.init().catch(Cu.reportError); Services.ppmm.loadProcessScript("data:,new " + function() { Components.utils.import("resource://formautofill/FormAutofillContent.jsm"); }, true); diff --git a/browser/extensions/formautofill/test/unit/test_activeStatus.js b/browser/extensions/formautofill/test/unit/test_activeStatus.js index 6c23177c037c..1bee59801df4 100644 --- a/browser/extensions/formautofill/test/unit/test_activeStatus.js +++ b/browser/extensions/formautofill/test/unit/test_activeStatus.js @@ -4,7 +4,7 @@ "use strict"; -Cu.import("resource://formautofill/FormAutofillParent.jsm"); +let {FormAutofillParent} = Cu.import("resource://formautofill/FormAutofillParent.jsm", {}); Cu.import("resource://formautofill/ProfileStorage.jsm"); add_task(async function test_activeStatus_init() { diff --git a/browser/extensions/formautofill/test/unit/test_getRecords.js b/browser/extensions/formautofill/test/unit/test_getRecords.js index 0a751734eec9..d7f9e32c8bcc 100644 --- a/browser/extensions/formautofill/test/unit/test_getRecords.js +++ b/browser/extensions/formautofill/test/unit/test_getRecords.js @@ -4,7 +4,7 @@ "use strict"; -Cu.import("resource://formautofill/FormAutofillParent.jsm"); +let {FormAutofillParent} = Cu.import("resource://formautofill/FormAutofillParent.jsm", {}); Cu.import("resource://formautofill/MasterPassword.jsm"); Cu.import("resource://formautofill/ProfileStorage.jsm"); diff --git a/browser/extensions/formautofill/test/unit/test_savedFieldNames.js b/browser/extensions/formautofill/test/unit/test_savedFieldNames.js index b278b6b32474..6aaa3435490b 100644 --- a/browser/extensions/formautofill/test/unit/test_savedFieldNames.js +++ b/browser/extensions/formautofill/test/unit/test_savedFieldNames.js @@ -4,7 +4,7 @@ "use strict"; -Cu.import("resource://formautofill/FormAutofillParent.jsm"); +let {FormAutofillParent} = Cu.import("resource://formautofill/FormAutofillParent.jsm", {}); Cu.import("resource://formautofill/ProfileStorage.jsm"); add_task(async function test_profileSavedFieldNames_init() {