2012-08-10 13:20:25 -07:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 12:17:31 -07:00
|
|
|
|
2011-11-17 13:21:25 -08:00
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
let Cu = Components.utils;
|
2011-07-13 12:17:31 -07:00
|
|
|
|
2013-06-19 16:30:53 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this,
|
|
|
|
"LoginManagerContent", "resource://gre/modules/LoginManagerContent.jsm");
|
2013-08-06 07:14:40 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this,
|
|
|
|
"InsecurePasswordUtils", "resource://gre/modules/InsecurePasswordUtils.jsm");
|
2013-06-19 16:30:53 -07:00
|
|
|
|
2011-07-13 12:17:31 -07:00
|
|
|
// Bug 671101 - directly using webNavigation in this context
|
|
|
|
// causes docshells to leak
|
2012-09-25 11:44:40 -07:00
|
|
|
this.__defineGetter__("webNavigation", function () {
|
2011-07-13 12:17:31 -07:00
|
|
|
return docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
});
|
|
|
|
|
2011-07-19 03:50:36 -07:00
|
|
|
addMessageListener("WebNavigation:LoadURI", function (message) {
|
2011-07-13 12:17:31 -07:00
|
|
|
let flags = message.json.flags || webNavigation.LOAD_FLAGS_NONE;
|
|
|
|
|
|
|
|
webNavigation.loadURI(message.json.uri, flags, null, null, null);
|
|
|
|
});
|
2011-07-28 13:20:52 -07:00
|
|
|
|
|
|
|
addMessageListener("Browser:HideSessionRestoreButton", function (message) {
|
|
|
|
// Hide session restore button on about:home
|
|
|
|
let doc = content.document;
|
|
|
|
let container;
|
|
|
|
if (doc.documentURI.toLowerCase() == "about:home" &&
|
|
|
|
(container = doc.getElementById("sessionRestoreContainer"))){
|
|
|
|
container.hidden = true;
|
|
|
|
}
|
|
|
|
});
|
2013-06-19 16:30:53 -07:00
|
|
|
|
2013-08-06 15:00:07 -07:00
|
|
|
if (Services.prefs.getBoolPref("browser.tabs.remote")) {
|
|
|
|
addEventListener("contextmenu", function (event) {
|
|
|
|
sendAsyncMessage("contextmenu", {}, { event: event });
|
|
|
|
}, false);
|
|
|
|
} else {
|
2013-07-26 14:26:22 -07:00
|
|
|
addEventListener("DOMContentLoaded", function(event) {
|
|
|
|
LoginManagerContent.onContentLoaded(event);
|
|
|
|
});
|
2013-08-06 07:14:40 -07:00
|
|
|
addEventListener("DOMFormHasPassword", function(event) {
|
|
|
|
InsecurePasswordUtils.checkForInsecurePasswords(event.target);
|
|
|
|
});
|
2013-07-26 14:26:22 -07:00
|
|
|
addEventListener("DOMAutoComplete", function(event) {
|
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
addEventListener("blur", function(event) {
|
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
}
|
2013-07-05 13:55:00 -07:00
|
|
|
|
2013-08-08 17:16:47 -07:00
|
|
|
|
|
|
|
var global = this;
|
|
|
|
|
|
|
|
let ClickEventHandler = {
|
|
|
|
init: function init() {
|
|
|
|
Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService)
|
|
|
|
.addSystemEventListener(global, "click", this, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(event) {
|
|
|
|
// Bug 903016: Most of this code is an unfortunate duplication from
|
|
|
|
// contentAreaClick in browser.js.
|
|
|
|
if (!event.isTrusted || event.defaultPrevented || event.button == 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [href, node] = this._hrefAndLinkNodeForClickEvent(event);
|
|
|
|
|
|
|
|
let json = { button: event.button, shiftKey: event.shiftKey,
|
|
|
|
ctrlKey: event.ctrlKey, metaKey: event.metaKey,
|
|
|
|
altKey: event.altKey, href: null, title: null,
|
|
|
|
bookmark: false };
|
|
|
|
|
|
|
|
if (href) {
|
|
|
|
json.href = href;
|
|
|
|
if (node) {
|
|
|
|
json.title = node.getAttribute("title");
|
|
|
|
|
|
|
|
if (event.button == 0 && !event.ctrlKey && !event.shiftKey &&
|
|
|
|
!event.altKey && !event.metaKey) {
|
|
|
|
json.bookmark = node.getAttribute("rel") == "sidebar";
|
|
|
|
if (json.bookmark)
|
|
|
|
event.preventDefault(); // Need to prevent the pageload.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("Content:Click", json);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This might be middle mouse navigation.
|
|
|
|
if (event.button == 1)
|
|
|
|
sendAsyncMessage("Content:Click", json);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts linkNode and href for the current click target.
|
|
|
|
*
|
|
|
|
* @param event
|
|
|
|
* The click event.
|
|
|
|
* @return [href, linkNode].
|
|
|
|
*
|
|
|
|
* @note linkNode will be null if the click wasn't on an anchor
|
|
|
|
* element (or XLink).
|
|
|
|
*/
|
|
|
|
_hrefAndLinkNodeForClickEvent: function(event) {
|
|
|
|
function isHTMLLink(aNode) {
|
|
|
|
// Be consistent with what nsContextMenu.js does.
|
|
|
|
return ((aNode instanceof content.HTMLAnchorElement && aNode.href) ||
|
|
|
|
(aNode instanceof content.HTMLAreaElement && aNode.href) ||
|
|
|
|
aNode instanceof content.HTMLLinkElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeURLAbsolute(aBase, aUrl) {
|
|
|
|
// Note: makeURI() will throw if aUri is not a valid URI
|
|
|
|
return makeURI(aUrl, null, makeURI(aBase)).spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
let node = event.target;
|
|
|
|
while (node && !isHTMLLink(node)) {
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
return [node.href, node];
|
|
|
|
|
|
|
|
// If there is no linkNode, try simple XLink.
|
|
|
|
let href, baseURI;
|
|
|
|
node = event.target;
|
|
|
|
while (node && !href) {
|
|
|
|
if (node.nodeType == content.Node.ELEMENT_NODE) {
|
|
|
|
href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href");
|
|
|
|
if (href)
|
|
|
|
baseURI = node.baseURI;
|
|
|
|
}
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case of XLink, we don't return the node we got href from since
|
|
|
|
// callers expect <a>-like elements.
|
|
|
|
return [href ? makeURLAbsolute(baseURI, href) : null, null];
|
|
|
|
}
|
|
|
|
};
|
2013-08-08 18:26:37 -07:00
|
|
|
ClickEventHandler.init();
|