Bug 1474143 - Switch earlyformsubmit pwmgr observers to DOMFormBeforeSubmit listeners. r=Felipe

Differential Revision: https://phabricator.services.mozilla.com/D16652

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matthew Noorenberghe 2019-02-22 15:12:48 +00:00
Родитель bc7d5bc37e
Коммит 24787216b4
3 изменённых файлов: 25 добавлений и 20 удалений

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

@ -41,6 +41,12 @@ function shouldIgnoreLoginManagerEvent(event) {
return event.target.nodePrincipal.isNullPrincipal;
}
addEventListener("DOMFormBeforeSubmit", function(event) {
if (shouldIgnoreLoginManagerEvent(event)) {
return;
}
LoginManagerContent.onDOMFormBeforeSubmit(event);
});
addEventListener("DOMFormHasPassword", function(event) {
if (shouldIgnoreLoginManagerEvent(event)) {
return;

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

@ -226,6 +226,12 @@ BrowserCLH.prototype = {
// NOTE: Much of this logic is duplicated in browser/base/content/content.js
// for desktop.
aWindow.addEventListener("DOMFormBeforeSubmit", event => {
if (shouldIgnoreLoginManagerEvent(event)) {
return;
}
this.LoginManagerContent.onDOMFormBeforeSubmit(event);
});
aWindow.addEventListener("DOMFormHasPassword", event => {
if (shouldIgnoreLoginManagerEvent(event)) {
return;

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

@ -51,27 +51,9 @@ var gLastRightClickTimeStamp = Number.NEGATIVE_INFINITY;
var observer = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver,
Ci.nsIFormSubmitObserver,
Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference]),
// nsIFormSubmitObserver
notify(formElement, aWindow, actionURI) {
log("observer notified for form submission.");
// We're invoked before the content's |onsubmit| handlers, so we
// can grab form data before it might be modified (see bug 257781).
try {
let formLike = LoginFormFactory.createFromForm(formElement);
LoginManagerContent._onFormSubmit(formLike);
} catch (e) {
log("Caught error in onFormSubmit(", e.lineNumber, "):", e.message);
Cu.reportError(e);
}
return true; // Always return true, or form submit will be canceled.
},
// nsIWebProgressListener
onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
@ -145,7 +127,6 @@ var observer = {
},
};
Services.obs.addObserver(observer, "earlyformsubmit");
// This object maps to the "child" process (even in the single-process case).
var LoginManagerContent = {
@ -360,6 +341,18 @@ var LoginManagerContent = {
}
},
onDOMFormBeforeSubmit(event) {
if (!event.isTrusted) {
return;
}
// We're invoked before the content's |submit| event handlers, so we
// can grab form data before it might be modified (see bug 257781).
log("notified before form submission");
let formLike = LoginFormFactory.createFromForm(event.target);
LoginManagerContent._onFormSubmit(formLike);
},
onDOMFormHasPassword(event) {
if (!event.isTrusted) {
return;
@ -903,7 +896,7 @@ var LoginManagerContent = {
if (ChromeUtils.getClassName(formRoot) === "HTMLFormElement") {
// For now only perform capture upon navigation for FormLike's without
// a <form> to avoid capture from both an earlyformsubmit and
// a <form> to avoid capture from both a DOMFormBeforeSubmit event and
// navigation for the same "form".
log("Ignoring navigation for the form root to avoid multiple prompts " +
"since it was for a real <form>");