2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-08-11 00:20:25 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-07-13 23:17:31 +04:00
|
|
|
|
2015-04-13 23:23:51 +03:00
|
|
|
/* This content script should work in any browser or iframe and should not
|
|
|
|
* depend on the frame being contained in tabbrowser. */
|
|
|
|
|
2017-02-07 13:52:06 +03:00
|
|
|
/* eslint-env mozilla/frame-script */
|
2018-05-26 03:50:22 +03:00
|
|
|
/* eslint no-unused-vars: ["error", {args: "none"}] */
|
2017-02-07 13:52:06 +03:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-06-20 03:30:53 +04:00
|
|
|
|
2018-05-25 20:22:13 +03:00
|
|
|
// TabChildGlobal
|
|
|
|
var global = this;
|
|
|
|
|
2017-08-09 23:03:36 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
2017-09-07 23:51:02 +03:00
|
|
|
ContentMetaHandler: "resource:///modules/ContentMetaHandler.jsm",
|
2017-08-09 23:03:36 +03:00
|
|
|
LoginFormFactory: "resource://gre/modules/LoginManagerContent.jsm",
|
|
|
|
InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.jsm",
|
2018-07-30 06:07:33 +03:00
|
|
|
ContextMenuChild: "resource:///actors/ContextMenuChild.jsm",
|
2018-05-25 20:22:13 +03:00
|
|
|
});
|
2014-08-21 19:42:42 +04:00
|
|
|
|
2018-06-25 04:07:59 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "LoginManagerContent", () => {
|
|
|
|
let tmp = {};
|
|
|
|
ChromeUtils.import("resource://gre/modules/LoginManagerContent.jsm", tmp);
|
|
|
|
tmp.LoginManagerContent.setupEventListeners(global);
|
|
|
|
return tmp.LoginManagerContent;
|
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: Much of this logic is duplicated in BrowserCLH.js for Android.
|
2015-05-13 17:34:14 +03:00
|
|
|
addMessageListener("RemoteLogins:fillForm", function(message) {
|
2017-08-22 01:42:37 +03:00
|
|
|
// intercept if ContextMenu.jsm had sent a plain object for remote targets
|
2018-07-30 06:07:33 +03:00
|
|
|
message.objects.inputElement = ContextMenuChild.getTarget(global, message, "inputElement");
|
2015-05-13 17:34:14 +03:00
|
|
|
LoginManagerContent.receiveMessage(message, content);
|
|
|
|
});
|
2018-10-02 10:59:12 +03:00
|
|
|
|
|
|
|
function shouldIgnoreLoginManagerEvent(event) {
|
|
|
|
// If we have a null principal then prevent any more password manager code from running and
|
|
|
|
// incorrectly using the document `location`.
|
|
|
|
return event.target.nodePrincipal.isNullPrincipal;
|
|
|
|
}
|
|
|
|
|
2014-06-28 22:09:45 +04:00
|
|
|
addEventListener("DOMFormHasPassword", function(event) {
|
2018-10-02 10:59:12 +03:00
|
|
|
if (shouldIgnoreLoginManagerEvent(event)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-13 17:34:14 +03:00
|
|
|
LoginManagerContent.onDOMFormHasPassword(event, content);
|
2018-04-07 02:34:15 +03:00
|
|
|
let formLike = LoginFormFactory.createFromForm(event.originalTarget);
|
2016-09-13 13:04:46 +03:00
|
|
|
InsecurePasswordUtils.reportInsecurePasswords(formLike);
|
2015-05-13 17:34:14 +03:00
|
|
|
});
|
2015-06-29 10:11:22 +03:00
|
|
|
addEventListener("DOMInputPasswordAdded", function(event) {
|
2018-10-02 10:59:12 +03:00
|
|
|
if (shouldIgnoreLoginManagerEvent(event)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 10:11:22 +03:00
|
|
|
LoginManagerContent.onDOMInputPasswordAdded(event, content);
|
2018-04-07 02:34:15 +03:00
|
|
|
let formLike = LoginFormFactory.createFromField(event.originalTarget);
|
2016-09-13 13:04:46 +03:00
|
|
|
InsecurePasswordUtils.reportInsecurePasswords(formLike);
|
2015-06-29 10:11:22 +03:00
|
|
|
});
|
2014-06-28 22:09:45 +04:00
|
|
|
addEventListener("DOMAutoComplete", function(event) {
|
2018-10-02 10:59:12 +03:00
|
|
|
if (shouldIgnoreLoginManagerEvent(event)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-28 22:09:45 +04:00
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
|
2017-09-07 23:51:02 +03:00
|
|
|
ContentMetaHandler.init(this);
|
2014-02-09 05:41:34 +04:00
|
|
|
|
2018-06-25 03:33:55 +03:00
|
|
|
// This is a temporary hack to prevent regressions (bug 1471327).
|
|
|
|
void content;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2017-03-23 10:59:01 +03:00
|
|
|
addEventListener("DOMWindowFocus", function(event) {
|
|
|
|
sendAsyncMessage("DOMWindowFocus", {});
|
2015-07-23 18:30:27 +03:00
|
|
|
}, false);
|