Bug 1469719: Avoid loading LoginManagerContent before it's needed. r=felipe

The "pageshow" and "blur" event listeners in LoginManagerContent only matter
once the module has loaded and processed other events. Before that, they're
guaranteed to be no-ops.

This patch delays adding those listeners before LoginManagerContent is used
for a given frame script.

MozReview-Commit-ID: 1f5AOkRkAhp

--HG--
extra : rebase_source : 392abe8ca2743fa4fdc40e642743acef1b314683
This commit is contained in:
Kris Maglione 2018-06-24 18:07:59 -07:00
Родитель ab6b58eddf
Коммит b35027d743
5 изменённых файлов: 24 добавлений и 13 удалений

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

@ -21,7 +21,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
ContentLinkHandler: "resource:///modules/ContentLinkHandler.jsm",
ContentMetaHandler: "resource:///modules/ContentMetaHandler.jsm",
ContentWebRTC: "resource:///modules/ContentWebRTC.jsm",
LoginManagerContent: "resource://gre/modules/LoginManagerContent.jsm",
LoginFormFactory: "resource://gre/modules/LoginManagerContent.jsm",
InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.jsm",
PluginContent: "resource:///modules/PluginContent.jsm",
@ -37,6 +36,13 @@ XPCOMUtils.defineLazyProxy(this, "contextMenu", () => {
return new ContextMenu(global);
});
XPCOMUtils.defineLazyGetter(this, "LoginManagerContent", () => {
let tmp = {};
ChromeUtils.import("resource://gre/modules/LoginManagerContent.jsm", tmp);
tmp.LoginManagerContent.setupEventListeners(global);
return tmp.LoginManagerContent;
});
XPCOMUtils.defineLazyProxy(this, "formSubmitObserver", () => {
return new FormSubmitObserver(content, this);
}, {
@ -56,6 +62,7 @@ Services.obs.addObserver(formSubmitObserver, "invalidformsubmit", true);
addMessageListener("PageInfo:getData", PageInfoListener);
// NOTE: Much of this logic is duplicated in BrowserCLH.js for Android.
addMessageListener("RemoteLogins:fillForm", function(message) {
// intercept if ContextMenu.jsm had sent a plain object for remote targets
message.objects.inputElement = contextMenu.getTarget(message, "inputElement");
@ -71,15 +78,9 @@ addEventListener("DOMInputPasswordAdded", function(event) {
let formLike = LoginFormFactory.createFromField(event.originalTarget);
InsecurePasswordUtils.reportInsecurePasswords(formLike);
});
addEventListener("pageshow", function(event) {
LoginManagerContent.onPageShow(event, content);
});
addEventListener("DOMAutoComplete", function(event) {
LoginManagerContent.onUsernameInput(event);
});
addEventListener("blur", function(event) {
LoginManagerContent.onUsernameInput(event);
});
var AboutBlockedSiteListener = {
init(chromeGlobal) {

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

@ -26,6 +26,8 @@ const blacklist = {
"resource:///modules/ContentWebRTC.jsm",
"resource://gre/modules/InlineSpellChecker.jsm",
"resource://gre/modules/InlineSpellCheckerContent.jsm",
"resource://gre/modules/LoginHelper.jsm",
"resource://gre/modules/LoginManagerContent.jsm",
"resource://gre/modules/Promise.jsm",
"resource://gre/modules/Task.jsm",
"resource://gre/modules/osfile.jsm",

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

@ -185,6 +185,8 @@ BrowserCLH.prototype = {
mozSystemGroup: true,
};
// NOTE: Much of this logic is duplicated in browser/base/content/content.js
// for desktop.
aWindow.addEventListener("DOMFormHasPassword", event => {
this.LoginManagerContent.onDOMFormHasPassword(event, event.target.ownerGlobal.top);
}, options);

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

@ -34,7 +34,6 @@ var LoginHelper = {
formlessCaptureEnabled: Services.prefs.getBoolPref("signon.formlessCapture.enabled"),
schemeUpgrades: Services.prefs.getBoolPref("signon.schemeUpgrades"),
insecureAutofill: Services.prefs.getBoolPref("signon.autofillForms.http"),
showInsecureFieldWarning: Services.prefs.getBoolPref("security.insecure_field_warning.contextual.enabled"),
createLogger(aLogPrefix) {
let getMaxLogLevel = () => {
@ -58,10 +57,6 @@ var LoginHelper = {
logger.maxLogLevel = getMaxLogLevel();
});
Services.prefs.addObserver("security.insecure_field_warning.", () => {
this.showInsecureFieldWarning = Services.prefs.getBoolPref("security.insecure_field_warning.contextual.enabled");
});
return logger;
},
@ -777,6 +772,9 @@ var LoginHelper = {
}
};
XPCOMUtils.defineLazyPreferenceGetter(LoginHelper, "showInsecureFieldWarning",
"security.insecure_field_warning.contextual.enabled");
XPCOMUtils.defineLazyGetter(this, "log", () => {
let logger = LoginHelper.createLogger("LoginHelper");
return logger;

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

@ -163,7 +163,6 @@ function messageManagerFromWindow(win) {
// This object maps to the "child" process (even in the single-process case).
var LoginManagerContent = {
__formFillService: null, // FormFillController, for username autocompleting
get _formFillService() {
if (!this.__formFillService)
@ -348,6 +347,15 @@ var LoginManagerContent = {
messageData);
},
setupEventListeners(global) {
global.addEventListener("pageshow", (event) => {
this.onPageShow(event, global.content);
});
global.addEventListener("blur", (event) => {
this.onUsernameInput(event);
});
},
setupProgressListener(window) {
if (!LoginHelper.formlessCaptureEnabled) {
return;