2014-06-24 22:12:07 -07:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-08-10 13:20:25 -07: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 12:17:31 -07:00
|
|
|
|
2014-05-15 05:56:37 -07:00
|
|
|
let {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
2011-07-13 12:17:31 -07:00
|
|
|
|
2013-06-19 16:30:53 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2014-03-14 11:45:53 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-06-19 16:30:53 -07:00
|
|
|
|
2014-08-21 08:42:42 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
|
|
|
|
"resource://gre/modules/BrowserUtils.jsm");
|
2014-02-08 17:41:34 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "ContentLinkHandler",
|
|
|
|
"resource:///modules/ContentLinkHandler.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerContent",
|
|
|
|
"resource://gre/modules/LoginManagerContent.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "InsecurePasswordUtils",
|
|
|
|
"resource://gre/modules/InsecurePasswordUtils.jsm");
|
2013-07-05 13:55:00 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2013-05-29 14:50:59 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UITour",
|
|
|
|
"resource:///modules/UITour.jsm");
|
2014-08-21 08:42:42 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FormSubmitObserver",
|
|
|
|
"resource:///modules/FormSubmitObserver.jsm");
|
2013-06-19 16:30:53 -07:00
|
|
|
|
2014-08-21 08:42:42 -07:00
|
|
|
// TabChildGlobal
|
|
|
|
var global = this;
|
|
|
|
|
|
|
|
// Load the form validation popup handler
|
|
|
|
var formSubmitObserver = new FormSubmitObserver(content, this);
|
2013-09-30 00:57:26 -07:00
|
|
|
|
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" &&
|
2014-08-18 17:27:35 -07:00
|
|
|
(container = doc.getElementById("sessionRestoreContainer"))) {
|
2011-07-28 13:20:52 -07:00
|
|
|
container.hidden = true;
|
|
|
|
}
|
|
|
|
});
|
2013-06-19 16:30:53 -07:00
|
|
|
|
2014-07-08 18:27:59 -07:00
|
|
|
addMessageListener("Browser:Reload", function(message) {
|
|
|
|
/* First, we'll try to use the session history object to reload so
|
|
|
|
* that framesets are handled properly. If we're in a special
|
|
|
|
* window (such as view-source) that has no session history, fall
|
|
|
|
* back on using the web navigation's reload method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
try {
|
|
|
|
let sh = webNav.sessionHistory;
|
|
|
|
if (sh)
|
|
|
|
webNav = sh.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
let reloadFlags = message.data.flags;
|
|
|
|
let handlingUserInput;
|
|
|
|
try {
|
|
|
|
handlingUserInput = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.setHandlingUserInput(message.data.handlingUserInput);
|
|
|
|
webNav.reload(reloadFlags);
|
|
|
|
} catch (e) {
|
|
|
|
} finally {
|
|
|
|
handlingUserInput.destruct();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-28 11:09:45 -07:00
|
|
|
addEventListener("DOMFormHasPassword", function(event) {
|
|
|
|
InsecurePasswordUtils.checkForInsecurePasswords(event.target);
|
|
|
|
LoginManagerContent.onFormPassword(event);
|
|
|
|
});
|
|
|
|
addEventListener("DOMAutoComplete", function(event) {
|
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
addEventListener("blur", function(event) {
|
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
|
2014-02-11 09:01:08 -08:00
|
|
|
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
2013-08-06 15:00:07 -07:00
|
|
|
addEventListener("contextmenu", function (event) {
|
2014-08-26 11:44:10 -07:00
|
|
|
let defaultPrevented = event.defaultPrevented;
|
|
|
|
if (!Services.prefs.getBoolPref("dom.event.contextmenu.enabled")) {
|
|
|
|
let plugin = null;
|
|
|
|
try {
|
|
|
|
plugin = event.target.QueryInterface(Ci.nsIObjectLoadingContent);
|
|
|
|
} catch (e) {}
|
|
|
|
if (plugin && plugin.displayedType == Ci.nsIObjectLoadingContent.TYPE_PLUGIN) {
|
|
|
|
// Don't open a context menu for plugins.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultPrevented = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defaultPrevented) {
|
|
|
|
sendSyncMessage("contextmenu", {}, { event: event });
|
|
|
|
}
|
2013-08-06 15:00:07 -07:00
|
|
|
}, false);
|
|
|
|
} else {
|
2013-05-29 14:50:59 -07:00
|
|
|
addEventListener("mozUITour", function(event) {
|
|
|
|
if (!Services.prefs.getBoolPref("browser.uitour.enabled"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let handled = UITour.onPageEvent(event);
|
|
|
|
if (handled)
|
|
|
|
addEventListener("pagehide", UITour);
|
|
|
|
}, false, true);
|
2013-07-26 14:26:22 -07:00
|
|
|
}
|
2013-07-05 13:55:00 -07:00
|
|
|
|
2013-07-05 13:55:00 -07:00
|
|
|
let AboutHomeListener = {
|
|
|
|
init: function(chromeGlobal) {
|
2014-08-18 17:27:35 -07:00
|
|
|
chromeGlobal.addEventListener('AboutHomeLoad', this, false, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
get isAboutHome() {
|
|
|
|
return content.document.documentURI.toLowerCase() == "about:home";
|
2013-07-05 13:55:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
2014-08-18 17:27:35 -07:00
|
|
|
if (!this.isAboutHome) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-05 13:55:00 -07:00
|
|
|
switch (aEvent.type) {
|
|
|
|
case "AboutHomeLoad":
|
|
|
|
this.onPageLoad();
|
|
|
|
break;
|
2014-08-18 17:27:35 -07:00
|
|
|
case "AboutHomeSearchEvent":
|
|
|
|
this.onSearch(aEvent);
|
|
|
|
break;
|
|
|
|
case "click":
|
|
|
|
this.onClick(aEvent);
|
|
|
|
break;
|
|
|
|
case "pagehide":
|
|
|
|
this.onPageHide(aEvent);
|
|
|
|
break;
|
2013-07-05 13:55:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
2014-08-18 17:27:35 -07:00
|
|
|
if (!this.isAboutHome) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-05 13:55:00 -07:00
|
|
|
switch (aMessage.name) {
|
|
|
|
case "AboutHome:Update":
|
|
|
|
this.onUpdate(aMessage.data);
|
|
|
|
break;
|
2014-08-14 12:48:00 -07:00
|
|
|
case "AboutHome:FocusInput":
|
|
|
|
this.onFocusInput();
|
|
|
|
break;
|
2013-07-05 13:55:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onUpdate: function(aData) {
|
|
|
|
let doc = content.document;
|
|
|
|
if (aData.showRestoreLastSession && !PrivateBrowsingUtils.isWindowPrivate(content))
|
|
|
|
doc.getElementById("launcher").setAttribute("session", "true");
|
|
|
|
|
|
|
|
// Inject search engine and snippets URL.
|
|
|
|
let docElt = doc.documentElement;
|
2013-08-30 09:20:22 -07:00
|
|
|
// set the following attributes BEFORE searchEngineName, which triggers to
|
2013-07-05 13:55:00 -07:00
|
|
|
// show the snippets when it's set.
|
|
|
|
docElt.setAttribute("snippetsURL", aData.snippetsURL);
|
|
|
|
if (aData.showKnowYourRights)
|
|
|
|
docElt.setAttribute("showKnowYourRights", "true");
|
|
|
|
docElt.setAttribute("snippetsVersion", aData.snippetsVersion);
|
2013-10-25 14:14:55 -07:00
|
|
|
docElt.setAttribute("searchEngineName", aData.defaultEngineName);
|
2013-07-05 13:55:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onPageLoad: function() {
|
|
|
|
let doc = content.document;
|
2014-08-18 17:27:35 -07:00
|
|
|
if (doc.documentElement.hasAttribute("hasBrowserHandlers")) {
|
2013-07-05 13:55:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc.documentElement.setAttribute("hasBrowserHandlers", "true");
|
2014-08-18 17:27:35 -07:00
|
|
|
addMessageListener("AboutHome:Update", this);
|
|
|
|
addMessageListener("AboutHome:FocusInput", this);
|
|
|
|
addEventListener("click", this, true);
|
|
|
|
addEventListener("pagehide", this, true);
|
2013-07-05 13:55:00 -07:00
|
|
|
|
|
|
|
// XXX bug 738646 - when Marketplace is launched, remove this statement and
|
|
|
|
// the hidden attribute set on the apps button in aboutHome.xhtml
|
|
|
|
if (Services.prefs.getPrefType("browser.aboutHome.apps") == Services.prefs.PREF_BOOL &&
|
|
|
|
Services.prefs.getBoolPref("browser.aboutHome.apps"))
|
|
|
|
doc.getElementById("apps").removeAttribute("hidden");
|
|
|
|
|
|
|
|
sendAsyncMessage("AboutHome:RequestUpdate");
|
2014-08-18 17:27:35 -07:00
|
|
|
doc.addEventListener("AboutHomeSearchEvent", this, true, true);
|
2013-07-05 13:55:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(aEvent) {
|
|
|
|
if (!aEvent.isTrusted || // Don't trust synthetic events
|
|
|
|
aEvent.button == 2 || aEvent.target.localName != "button") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let originalTarget = aEvent.originalTarget;
|
|
|
|
let ownerDoc = originalTarget.ownerDocument;
|
2014-01-20 15:13:35 -08:00
|
|
|
if (ownerDoc.documentURI != "about:home") {
|
|
|
|
// This shouldn't happen, but we're being defensive.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-05 13:55:00 -07:00
|
|
|
let elmId = originalTarget.getAttribute("id");
|
|
|
|
|
|
|
|
switch (elmId) {
|
|
|
|
case "restorePreviousSession":
|
|
|
|
sendAsyncMessage("AboutHome:RestorePreviousSession");
|
|
|
|
ownerDoc.getElementById("launcher").removeAttribute("session");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "downloads":
|
|
|
|
sendAsyncMessage("AboutHome:Downloads");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "bookmarks":
|
|
|
|
sendAsyncMessage("AboutHome:Bookmarks");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "history":
|
|
|
|
sendAsyncMessage("AboutHome:History");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "apps":
|
|
|
|
sendAsyncMessage("AboutHome:Apps");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "addons":
|
|
|
|
sendAsyncMessage("AboutHome:Addons");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "sync":
|
|
|
|
sendAsyncMessage("AboutHome:Sync");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "settings":
|
|
|
|
sendAsyncMessage("AboutHome:Settings");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2014-08-14 12:48:00 -07:00
|
|
|
|
2014-08-18 17:27:35 -07:00
|
|
|
onPageHide: function(aEvent) {
|
2014-08-20 08:27:03 -07:00
|
|
|
if (aEvent.target.defaultView.frameElement) {
|
2014-08-18 17:27:35 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
removeMessageListener("AboutHome:Update", this);
|
|
|
|
removeEventListener("click", this, true);
|
|
|
|
removeEventListener("pagehide", this, true);
|
2014-08-20 08:27:03 -07:00
|
|
|
if (aEvent.target.documentElement) {
|
|
|
|
aEvent.target.documentElement.removeAttribute("hasBrowserHandlers");
|
2014-08-18 17:27:35 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearch: function(aEvent) {
|
|
|
|
sendAsyncMessage("AboutHome:Search", { searchData: aEvent.detail });
|
|
|
|
},
|
|
|
|
|
2014-08-14 12:48:00 -07:00
|
|
|
onFocusInput: function () {
|
2014-08-18 17:27:35 -07:00
|
|
|
let searchInput = content.document.getElementById("searchText");
|
|
|
|
if (searchInput) {
|
|
|
|
searchInput.focus();
|
|
|
|
}
|
2014-08-14 12:48:00 -07:00
|
|
|
},
|
2013-07-05 13:55:00 -07:00
|
|
|
};
|
|
|
|
AboutHomeListener.init(this);
|
|
|
|
|
2014-04-24 19:09:20 -07:00
|
|
|
|
2014-07-31 22:42:00 -07:00
|
|
|
// An event listener for custom "WebChannelMessageToChrome" events on pages
|
|
|
|
addEventListener("WebChannelMessageToChrome", function (e) {
|
|
|
|
// if target is window then we want the document principal, otherwise fallback to target itself.
|
|
|
|
let principal = e.target.nodePrincipal ? e.target.nodePrincipal : e.target.document.nodePrincipal;
|
|
|
|
|
|
|
|
if (e.detail) {
|
|
|
|
sendAsyncMessage("WebChannelMessageToChrome", e.detail, null, principal);
|
|
|
|
} else {
|
|
|
|
Cu.reportError("WebChannel message failed. No message detail.");
|
|
|
|
}
|
|
|
|
}, true, true);
|
|
|
|
|
|
|
|
// Add message listener for "WebChannelMessageToContent" messages from chrome scripts
|
|
|
|
addMessageListener("WebChannelMessageToContent", function (e) {
|
|
|
|
if (e.data) {
|
|
|
|
content.dispatchEvent(new content.CustomEvent("WebChannelMessageToContent", {
|
|
|
|
detail: Cu.cloneInto({
|
|
|
|
id: e.data.id,
|
|
|
|
message: e.data.message,
|
|
|
|
}, content),
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
Cu.reportError("WebChannel message failed. No message data.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-04-24 19:09:20 -07:00
|
|
|
let ContentSearchMediator = {
|
|
|
|
|
|
|
|
whitelist: new Set([
|
2014-08-01 12:00:44 -07:00
|
|
|
"about:home",
|
2014-04-24 19:09:20 -07:00
|
|
|
"about:newtab",
|
|
|
|
]),
|
|
|
|
|
|
|
|
init: function (chromeGlobal) {
|
|
|
|
chromeGlobal.addEventListener("ContentSearchClient", this, true, true);
|
|
|
|
addMessageListener("ContentSearch", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function (event) {
|
|
|
|
if (this._contentWhitelisted) {
|
|
|
|
this._sendMsg(event.detail.type, event.detail.data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function (msg) {
|
|
|
|
if (msg.data.type == "AddToWhitelist") {
|
|
|
|
for (let uri of msg.data.data) {
|
|
|
|
this.whitelist.add(uri);
|
|
|
|
}
|
|
|
|
this._sendMsg("AddToWhitelistAck");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._contentWhitelisted) {
|
|
|
|
this._fireEvent(msg.data.type, msg.data.data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get _contentWhitelisted() {
|
2014-08-01 12:00:44 -07:00
|
|
|
return this.whitelist.has(content.document.documentURI);
|
2014-04-24 19:09:20 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_sendMsg: function (type, data=null) {
|
|
|
|
sendAsyncMessage("ContentSearch", {
|
|
|
|
type: type,
|
|
|
|
data: data,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_fireEvent: function (type, data=null) {
|
2014-08-01 12:00:44 -07:00
|
|
|
let event = Cu.cloneInto({
|
2014-04-24 19:09:20 -07:00
|
|
|
detail: {
|
|
|
|
type: type,
|
|
|
|
data: data,
|
|
|
|
},
|
2014-08-01 12:00:44 -07:00
|
|
|
}, content);
|
|
|
|
content.dispatchEvent(new content.CustomEvent("ContentSearchService",
|
|
|
|
event));
|
2014-04-24 19:09:20 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
ContentSearchMediator.init(this);
|
|
|
|
|
2013-09-13 16:27:19 -07:00
|
|
|
// Lazily load the finder code
|
|
|
|
addMessageListener("Finder:Initialize", function () {
|
|
|
|
let {RemoteFinderListener} = Cu.import("resource://gre/modules/RemoteFinder.jsm", {});
|
|
|
|
new RemoteFinderListener(global);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-08-08 17:16:47 -07:00
|
|
|
let ClickEventHandler = {
|
|
|
|
init: function init() {
|
|
|
|
Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService)
|
|
|
|
.addSystemEventListener(global, "click", this, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(event) {
|
2014-07-02 12:27:35 -07:00
|
|
|
if (!event.isTrusted || event.defaultPrevented || event.button == 2) {
|
2013-08-08 17:16:47 -07:00
|
|
|
return;
|
2014-07-02 12:27:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
let originalTarget = event.originalTarget;
|
|
|
|
let ownerDoc = originalTarget.ownerDocument;
|
|
|
|
|
|
|
|
// Handle click events from about pages
|
|
|
|
if (ownerDoc.documentURI.startsWith("about:certerror")) {
|
|
|
|
this.onAboutCertError(originalTarget, ownerDoc);
|
|
|
|
return;
|
|
|
|
} else if (ownerDoc.documentURI.startsWith("about:blocked")) {
|
|
|
|
this.onAboutBlocked(originalTarget, ownerDoc);
|
|
|
|
return;
|
|
|
|
} else if (ownerDoc.documentURI.startsWith("about:neterror")) {
|
|
|
|
this.onAboutNetError(originalTarget, ownerDoc);
|
|
|
|
}
|
2013-08-08 17:16:47 -07:00
|
|
|
|
|
|
|
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";
|
2014-07-02 12:27:35 -07:00
|
|
|
if (json.bookmark) {
|
2013-08-08 17:16:47 -07:00
|
|
|
event.preventDefault(); // Need to prevent the pageload.
|
2014-07-02 12:27:35 -07:00
|
|
|
}
|
2013-08-08 17:16:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("Content:Click", json);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This might be middle mouse navigation.
|
2014-07-02 12:27:35 -07:00
|
|
|
if (event.button == 1) {
|
2013-08-08 17:16:47 -07:00
|
|
|
sendAsyncMessage("Content:Click", json);
|
2014-07-02 12:27:35 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onAboutCertError: function (targetElement, ownerDoc) {
|
2014-07-07 15:33:07 -07:00
|
|
|
let docshell = ownerDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell);
|
2014-07-02 12:27:35 -07:00
|
|
|
sendAsyncMessage("Browser:CertExceptionError", {
|
|
|
|
location: ownerDoc.location.href,
|
|
|
|
elementId: targetElement.getAttribute("id"),
|
2014-07-07 15:33:07 -07:00
|
|
|
isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView),
|
|
|
|
}, {
|
|
|
|
failedChannel: docshell.failedChannel
|
2014-07-02 12:27:35 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onAboutBlocked: function (targetElement, ownerDoc) {
|
|
|
|
sendAsyncMessage("Browser:SiteBlockedError", {
|
|
|
|
location: ownerDoc.location.href,
|
|
|
|
isMalware: /e=malwareBlocked/.test(ownerDoc.documentURI),
|
|
|
|
elementId: targetElement.getAttribute("id"),
|
|
|
|
isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onAboutNetError: function (targetElement, ownerDoc) {
|
|
|
|
let elmId = targetElement.getAttribute("id");
|
|
|
|
if (elmId != "errorTryAgain" || !/e=netOffline/.test(ownerDoc.documentURI)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendSyncMessage("Browser:NetworkError", {});
|
2013-08-08 17:16:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2013-09-30 00:57:26 -07:00
|
|
|
baseURI = node.ownerDocument.baseURIObject;
|
2013-08-08 17:16:47 -07:00
|
|
|
}
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case of XLink, we don't return the node we got href from since
|
|
|
|
// callers expect <a>-like elements.
|
2013-09-30 00:57:26 -07:00
|
|
|
// Note: makeURI() will throw if aUri is not a valid URI.
|
2014-08-21 08:42:42 -07:00
|
|
|
return [href ? BrowserUtils.makeURI(href, null, baseURI).spec : null, null];
|
2013-08-08 17:16:47 -07:00
|
|
|
}
|
|
|
|
};
|
2013-08-30 09:20:22 -07:00
|
|
|
ClickEventHandler.init();
|
2014-01-13 04:56:28 -08:00
|
|
|
|
2014-02-08 17:41:34 -08:00
|
|
|
ContentLinkHandler.init(this);
|
|
|
|
|
2014-01-13 04:56:28 -08:00
|
|
|
addEventListener("DOMWebNotificationClicked", function(event) {
|
|
|
|
sendAsyncMessage("DOMWebNotificationClicked", {});
|
|
|
|
}, false);
|
2014-03-11 20:13:45 -07:00
|
|
|
|
|
|
|
let PageStyleHandler = {
|
|
|
|
init: function() {
|
|
|
|
addMessageListener("PageStyle:Switch", this);
|
|
|
|
addMessageListener("PageStyle:Disable", this);
|
|
|
|
|
|
|
|
// Send a CPOW to the parent so that it can synchronously request
|
|
|
|
// the list of style sheets.
|
|
|
|
sendSyncMessage("PageStyle:SetSyncHandler", {}, {syncHandler: this});
|
|
|
|
},
|
|
|
|
|
|
|
|
get markupDocumentViewer() {
|
2014-07-09 14:27:49 -07:00
|
|
|
return docShell.contentViewer;
|
2014-03-11 20:13:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Called synchronously via CPOW from the parent.
|
|
|
|
getStyleSheetInfo: function() {
|
|
|
|
let styleSheets = this._filterStyleSheets(this.getAllStyleSheets());
|
|
|
|
return {
|
|
|
|
styleSheets: styleSheets,
|
|
|
|
authorStyleDisabled: this.markupDocumentViewer.authorStyleDisabled,
|
|
|
|
preferredStyleSheetSet: content.document.preferredStyleSheetSet
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called synchronously via CPOW from the parent.
|
|
|
|
getAllStyleSheets: function(frameset = content) {
|
|
|
|
let selfSheets = Array.slice(frameset.document.styleSheets);
|
|
|
|
let subSheets = Array.map(frameset.frames, frame => this.getAllStyleSheets(frame));
|
|
|
|
return selfSheets.concat(...subSheets);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(msg) {
|
|
|
|
switch (msg.name) {
|
|
|
|
case "PageStyle:Switch":
|
|
|
|
this.markupDocumentViewer.authorStyleDisabled = false;
|
|
|
|
this._stylesheetSwitchAll(content, msg.data.title);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "PageStyle:Disable":
|
|
|
|
this.markupDocumentViewer.authorStyleDisabled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_stylesheetSwitchAll: function (frameset, title) {
|
|
|
|
if (!title || this._stylesheetInFrame(frameset, title)) {
|
|
|
|
this._stylesheetSwitchFrame(frameset, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < frameset.frames.length; i++) {
|
|
|
|
// Recurse into sub-frames.
|
|
|
|
this._stylesheetSwitchAll(frameset.frames[i], title);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_stylesheetSwitchFrame: function (frame, title) {
|
|
|
|
var docStyleSheets = frame.document.styleSheets;
|
|
|
|
|
|
|
|
for (let i = 0; i < docStyleSheets.length; ++i) {
|
|
|
|
let docStyleSheet = docStyleSheets[i];
|
|
|
|
if (docStyleSheet.title) {
|
|
|
|
docStyleSheet.disabled = (docStyleSheet.title != title);
|
|
|
|
} else if (docStyleSheet.disabled) {
|
|
|
|
docStyleSheet.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_stylesheetInFrame: function (frame, title) {
|
|
|
|
return Array.some(frame.document.styleSheets, (styleSheet) => styleSheet.title == title);
|
|
|
|
},
|
|
|
|
|
|
|
|
_filterStyleSheets: function(styleSheets) {
|
|
|
|
let result = [];
|
|
|
|
|
|
|
|
for (let currentStyleSheet of styleSheets) {
|
|
|
|
if (!currentStyleSheet.title)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Skip any stylesheets that don't match the screen media type.
|
|
|
|
if (currentStyleSheet.media.length > 0) {
|
|
|
|
let mediaQueryList = currentStyleSheet.media.mediaText;
|
|
|
|
if (!content.matchMedia(mediaQueryList).matches) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.push({title: currentStyleSheet.title,
|
|
|
|
disabled: currentStyleSheet.disabled});
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
PageStyleHandler.init();
|
2014-04-16 15:02:33 -07:00
|
|
|
|
2014-05-19 13:33:41 -07:00
|
|
|
// Keep a reference to the translation content handler to avoid it it being GC'ed.
|
|
|
|
let trHandler = null;
|
|
|
|
if (Services.prefs.getBoolPref("browser.translation.detectLanguage")) {
|
|
|
|
Cu.import("resource:///modules/translation/TranslationContentHandler.jsm");
|
|
|
|
trHandler = new TranslationContentHandler(global, docShell);
|
|
|
|
}
|
2014-08-19 13:58:00 -07:00
|
|
|
|
|
|
|
let DOMFullscreenHandler = {
|
|
|
|
_fullscreenDoc: null,
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
addMessageListener("DOMFullscreen:Approved", this);
|
|
|
|
addMessageListener("DOMFullscreen:CleanUp", this);
|
|
|
|
addEventListener("MozEnteredDomFullscreen", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
switch(aMessage.name) {
|
|
|
|
case "DOMFullscreen:Approved": {
|
|
|
|
if (this._fullscreenDoc) {
|
|
|
|
Services.obs.notifyObservers(this._fullscreenDoc,
|
|
|
|
"fullscreen-approved",
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "DOMFullscreen:CleanUp": {
|
|
|
|
this._fullscreenDoc = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
if (aEvent.type == "MozEnteredDomFullscreen") {
|
|
|
|
this._fullscreenDoc = aEvent.target;
|
|
|
|
sendAsyncMessage("MozEnteredDomFullscreen", {
|
|
|
|
origin: this._fullscreenDoc.nodePrincipal.origin,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-08-26 11:44:10 -07:00
|
|
|
DOMFullscreenHandler.init();
|
2014-09-02 14:43:08 -07:00
|
|
|
|
|
|
|
addMessageListener("Browser:AppTab", function(message) {
|
|
|
|
docShell.isAppTab = message.data.isAppTab;
|
|
|
|
});
|
|
|
|
|
|
|
|
let WebBrowserChrome = {
|
|
|
|
onBeforeLinkTraversal: function(originalTarget, linkURI, linkNode, isAppTab) {
|
|
|
|
return BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
|
|
|
let tabchild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsITabChild);
|
|
|
|
tabchild.webBrowserChrome = WebBrowserChrome;
|
|
|
|
}
|