Bug 1358921: Lazily load LoginManagerParent.jsm when first needed. r=florian
MozReview-Commit-ID: 4Aq0mBGXBX3
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -141,16 +141,24 @@ const listeners = {
mm: {
"AboutHome:MaybeShowAutoMigrationUndoNotification": ["AboutHome"],
"AboutHome:RequestUpdate": ["AboutHome"],
"Content:Click": ["ContentClick"],
"ContentSearch": ["ContentSearch"],
"FormValidation:ShowPopup": ["FormValidationHandler"],
"FormValidation:HidePopup": ["FormValidationHandler"],
"Prompt:Open": ["RemotePrompt"],
+ // PLEASE KEEP THIS LIST IN SYNC WITH THE LISTENERS ADDED IN LoginManagerParent.init
+ "RemoteLogins:findLogins": ["LoginManagerParent"],
+ "RemoteLogins:findRecipes": ["LoginManagerParent"],
+ "RemoteLogins:onFormSubmit": ["LoginManagerParent"],
+ "RemoteLogins:autoCompleteLogins": ["LoginManagerParent"],
+ "RemoteLogins:removeLogin": ["LoginManagerParent"],
+ "RemoteLogins:insecureLoginFormPresent": ["LoginManagerParent"],
+ // PLEASE KEEP THIS LIST IN SYNC WITH THE LISTENERS ADDED IN LoginManagerParent.init
"WCCR:registerProtocolHandler": ["Feeds"],
"WCCR:registerContentHandler": ["Feeds"],
"rtcpeer:CancelRequest": ["webrtcUI"],
"rtcpeer:Request": ["webrtcUI"],
"webrtc:CancelRequest": ["webrtcUI"],
"webrtc:Request": ["webrtcUI"],
"webrtc:StopRecording": ["webrtcUI"],
"webrtc:UpdateBrowserIndicators": ["webrtcUI"],
@@ -162,23 +170,25 @@ const listeners = {
this[module].observe(subject, topic, data);
} catch (e) {
Cu.reportError(e);
}
}
},
receiveMessage(modules, data) {
+ let val;
for (let module of modules[data.name]) {
try {
- global[module].receiveMessage(data);
+ val = global[module].receiveMessage(data) || val;
} catch (e) {
Cu.reportError(e);
}
}
+ return val;
},
init() {
for (let observer of Object.keys(this.observers)) {
Services.obs.addObserver(this, observer);
}
let receiveMessageMM = this.receiveMessage.bind(this, this.mm);
@@ -592,17 +602,16 @@ BrowserGlue.prototype = {
NewTabUtils.init();
NewTabUtils.links.addProvider(DirectoryLinksProvider);
AboutNewTab.init();
SessionStore.init();
BrowserUsageTelemetry.init();
BrowserUITelemetry.init();
- LoginManagerParent.init();
ReaderParent.init();
SelfSupportBackend.init();
if (AppConstants.INSTALL_COMPACT_THEMES) {
let vendorShortName = gBrandBundle.GetStringFromName("vendorShortName");
LightweightThemeManager.addBuiltInTheme({
--- a/toolkit/components/passwordmgr/LoginManagerParent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerParent.jsm
@@ -31,35 +31,34 @@ var LoginManagerParent = {
* synchronous access. This is a temporary hack and new consumers should yield on
* recipeParentPromise instead.
*
* @type LoginRecipesParent
* @deprecated
*/
_recipeManager: null,
+ // This should only be called on Android. Listeners are added in
+ // nsBrowserGlue.js on desktop. Please make sure that the list of
+ // listeners added here stays in sync with the listeners added in
+ // nsBrowserGlue when you change either.
init() {
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
+ // PLEASE KEEP THIS LIST IN SYNC WITH THE LISTENERS ADDED IN nsBrowserGlue
mm.addMessageListener("RemoteLogins:findLogins", this);
mm.addMessageListener("RemoteLogins:findRecipes", this);
mm.addMessageListener("RemoteLogins:onFormSubmit", this);
mm.addMessageListener("RemoteLogins:autoCompleteLogins", this);
mm.addMessageListener("RemoteLogins:removeLogin", this);
mm.addMessageListener("RemoteLogins:insecureLoginFormPresent", this);
-
- XPCOMUtils.defineLazyGetter(this, "recipeParentPromise", () => {
- const { LoginRecipesParent } = Cu.import("resource://gre/modules/LoginRecipes.jsm", {});
- this._recipeManager = new LoginRecipesParent({
- defaults: Services.prefs.getStringPref("signon.recipes.path"),
- });
- return this._recipeManager.initializationPromise;
- });
+ // PLEASE KEEP THIS LIST IN SYNC WITH THE LISTENERS ADDED IN nsBrowserGlue
},
+ // Listeners are added in nsBrowserGlue.js
receiveMessage(msg) {
let data = msg.data;
switch (msg.name) {
case "RemoteLogins:findLogins": {
// TODO Verify msg.target's principals against the formOrigin?
this.sendLoginDataToChild(data.options.showMasterPassword,
data.formOrigin,
data.actionOrigin,
@@ -471,8 +470,16 @@ var LoginManagerParent = {
// processed in order, this will always be the latest version to use.
state.hasInsecureLoginForms = hasInsecureLoginForms;
// Report the insecure login form state immediately.
browser.dispatchEvent(new browser.ownerGlobal
.CustomEvent("InsecureLoginFormsStateChange"));
},
};
+
+XPCOMUtils.defineLazyGetter(LoginManagerParent, "recipeParentPromise", function() {
+ const { LoginRecipesParent } = Cu.import("resource://gre/modules/LoginRecipes.jsm", {});
+ this._recipeManager = new LoginRecipesParent({
+ defaults: Services.prefs.getStringPref("signon.recipes.path"),
+ });
+ return this._recipeManager.initializationPromise;
+});
--- a/toolkit/components/passwordmgr/test/pwmgr_common.js
+++ b/toolkit/components/passwordmgr/test/pwmgr_common.js
@@ -368,16 +368,17 @@ function runChecksAfterCommonInit(aFunct
// Code to run when loaded as a chrome script in tests via loadChromeScript
if (this.addMessageListener) {
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
var SpecialPowers = { Cc, Ci, Cr, Cu, };
var ok, is;
// Ignore ok/is in commonInit since they aren't defined in a chrome script.
ok = is = () => {}; // eslint-disable-line no-native-reassign
+ Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/LoginHelper.jsm");
Cu.import("resource://gre/modules/LoginManagerParent.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
function onStorageChanged(subject, topic, data) {
sendAsyncMessage("storageChanged", {
topic,
@@ -393,17 +394,19 @@ if (this.addMessageListener) {
});
}
Services.obs.addObserver(onPrompt, "passwordmgr-prompt-change");
Services.obs.addObserver(onPrompt, "passwordmgr-prompt-save");
addMessageListener("setupParent", ({selfFilling = false} = {selfFilling: false}) => {
// Force LoginManagerParent to init for the tests since it's normally delayed
// by apps such as on Android.
- LoginManagerParent.init();
+ if (AppConstants.platform == "android") {
+ LoginManagerParent.init();
+ }
commonInit(selfFilling);
sendAsyncMessage("doneSetup");
});
addMessageListener("loadRecipes", Task.async(function*(recipes) {
var recipeParent = yield LoginManagerParent.recipeParentPromise;
yield recipeParent.load(recipes);