Bug 1421551 - Make FormAutofillParent singleton and expose the initialized status. r=MattN

MozReview-Commit-ID: IMd25HcNTMa

--HG--
extra : rebase_source : 1cbb863199fc78074d7ab8a5547c87cb8b3f8c58
This commit is contained in:
Luke Chang 2017-11-29 17:02:59 +08:00
Родитель 211750c567
Коммит 38cd380efa
5 изменённых файлов: 30 добавлений и 7 удалений

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

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

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

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

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

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

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

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

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

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