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
|
|
|
|
2014-05-15 16:56:37 +04:00
|
|
|
let {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
2011-07-13 23:17:31 +04:00
|
|
|
|
2013-06-20 03:30:53 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2014-03-14 22:45:53 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2014-09-22 22:39:57 +04:00
|
|
|
Cu.import("resource:///modules/ContentWebRTC.jsm");
|
2015-02-04 20:13:38 +03:00
|
|
|
Cu.import("resource:///modules/ContentObservers.jsm");
|
2014-10-03 18:52:37 +04:00
|
|
|
Cu.import("resource://gre/modules/InlineSpellChecker.jsm");
|
|
|
|
Cu.import("resource://gre/modules/InlineSpellCheckerContent.jsm");
|
2013-06-20 03:30:53 +04:00
|
|
|
|
2014-09-25 22:35:45 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
|
|
|
|
"resource:///modules/E10SUtils.jsm");
|
2014-08-21 19:42:42 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
|
|
|
|
"resource://gre/modules/BrowserUtils.jsm");
|
2014-02-09 05:41:34 +04: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");
|
2014-09-18 00:06:58 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PluginContent",
|
|
|
|
"resource:///modules/PluginContent.jsm");
|
2013-07-06 00:55:00 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2014-08-21 19:42:42 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FormSubmitObserver",
|
|
|
|
"resource:///modules/FormSubmitObserver.jsm");
|
2014-12-30 18:44:34 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AboutReader",
|
|
|
|
"resource://gre/modules/AboutReader.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode",
|
|
|
|
"resource://gre/modules/ReaderMode.jsm");
|
2015-03-06 01:43:05 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PageMetadata",
|
|
|
|
"resource://gre/modules/PageMetadata.jsm");
|
2014-12-16 02:52:55 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "SimpleServiceDiscovery", function() {
|
|
|
|
let ssdp = Cu.import("resource://gre/modules/SimpleServiceDiscovery.jsm", {}).SimpleServiceDiscovery;
|
|
|
|
// Register targets
|
|
|
|
ssdp.registerDevice({
|
|
|
|
id: "roku:ecp",
|
|
|
|
target: "roku:ecp",
|
|
|
|
factory: function(aService) {
|
|
|
|
Cu.import("resource://gre/modules/RokuApp.jsm");
|
|
|
|
return new RokuApp(aService);
|
|
|
|
},
|
|
|
|
mirror: true,
|
|
|
|
types: ["video/mp4"],
|
|
|
|
extensions: ["mp4"]
|
|
|
|
});
|
|
|
|
return ssdp;
|
|
|
|
});
|
2014-12-16 19:21:11 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "PageMenuChild", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource://gre/modules/PageMenu.jsm", tmp);
|
|
|
|
return new tmp.PageMenuChild();
|
|
|
|
});
|
2013-06-20 03:30:53 +04:00
|
|
|
|
2014-08-21 19:42:42 +04:00
|
|
|
// TabChildGlobal
|
|
|
|
var global = this;
|
|
|
|
|
|
|
|
// Load the form validation popup handler
|
|
|
|
var formSubmitObserver = new FormSubmitObserver(content, this);
|
2013-09-30 11:57:26 +04:00
|
|
|
|
2011-07-29 00:20:52 +04: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-19 04:27:35 +04:00
|
|
|
(container = doc.getElementById("sessionRestoreContainer"))) {
|
2011-07-29 00:20:52 +04:00
|
|
|
container.hidden = true;
|
|
|
|
}
|
|
|
|
});
|
2013-06-20 03:30:53 +04:00
|
|
|
|
2014-07-09 05:27:59 +04: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-10-23 00:05:17 +04:00
|
|
|
addMessageListener("MixedContent:ReenableProtection", function() {
|
|
|
|
docShell.mixedContentChannel = null;
|
|
|
|
});
|
|
|
|
|
2014-12-16 02:52:55 +03:00
|
|
|
addMessageListener("SecondScreen:tab-mirror", function(message) {
|
2015-03-09 16:15:55 +03:00
|
|
|
if (!Services.prefs.getBoolPref("browser.casting.enabled")) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-16 02:52:55 +03:00
|
|
|
let app = SimpleServiceDiscovery.findAppForService(message.data.service);
|
|
|
|
if (app) {
|
2014-12-17 01:35:10 +03:00
|
|
|
let width = content.innerWidth;
|
|
|
|
let height = content.innerHeight;
|
2014-12-16 02:52:55 +03:00
|
|
|
let viewport = {cssWidth: width, cssHeight: height, width: width, height: height};
|
|
|
|
app.mirror(function() {}, content, viewport, function() {}, content);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-16 19:21:11 +03:00
|
|
|
addMessageListener("ContextMenu:DoCustomCommand", function(message) {
|
|
|
|
PageMenuChild.executeMenu(message.data);
|
|
|
|
});
|
|
|
|
|
2014-06-28 22:09:45 +04: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-11-17 21:58:13 +03:00
|
|
|
let handleContentContextMenu = function (event) {
|
|
|
|
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;
|
2014-08-26 22:44:10 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 21:58:13 +03:00
|
|
|
defaultPrevented = false;
|
2014-11-11 23:52:13 +03:00
|
|
|
}
|
2013-07-06 00:55:00 +04:00
|
|
|
|
2014-11-17 21:58:13 +03:00
|
|
|
if (defaultPrevented)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let addonInfo = {};
|
|
|
|
let subject = {
|
|
|
|
event: event,
|
|
|
|
addonInfo: addonInfo,
|
|
|
|
};
|
|
|
|
subject.wrappedJSObject = subject;
|
|
|
|
Services.obs.notifyObservers(subject, "content-contextmenu", null);
|
|
|
|
|
2015-02-21 03:22:39 +03:00
|
|
|
let doc = event.target.ownerDocument;
|
|
|
|
let docLocation = doc.location.href;
|
|
|
|
let charSet = doc.characterSet;
|
|
|
|
let baseURI = doc.baseURI;
|
|
|
|
let referrer = doc.referrer;
|
2015-03-05 10:29:55 +03:00
|
|
|
let referrerPolicy = doc.referrerPolicy;
|
2015-02-21 03:22:39 +03:00
|
|
|
|
2014-11-17 21:58:13 +03:00
|
|
|
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
|
|
|
let editFlags = SpellCheckHelper.isEditable(event.target, content);
|
|
|
|
let spellInfo;
|
|
|
|
if (editFlags &
|
|
|
|
(SpellCheckHelper.EDITABLE | SpellCheckHelper.CONTENTEDITABLE)) {
|
|
|
|
spellInfo =
|
|
|
|
InlineSpellCheckerContent.initContextMenu(event, editFlags, this);
|
|
|
|
}
|
2014-11-12 01:27:17 +03:00
|
|
|
|
2014-12-16 19:21:11 +03:00
|
|
|
let customMenuItems = PageMenuChild.build(event.target);
|
2015-02-21 03:22:39 +03:00
|
|
|
let principal = doc.nodePrincipal;
|
2015-01-29 22:28:01 +03:00
|
|
|
sendSyncMessage("contextmenu",
|
2015-02-21 03:22:39 +03:00
|
|
|
{ editFlags, spellInfo, customMenuItems, addonInfo,
|
2015-03-05 10:29:55 +03:00
|
|
|
principal, docLocation, charSet, baseURI, referrer,
|
|
|
|
referrerPolicy },
|
2015-01-29 22:28:01 +03:00
|
|
|
{ event, popupNode: event.target });
|
2014-11-17 21:58:13 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Break out to the parent window and pass the add-on info along
|
|
|
|
let browser = docShell.chromeEventHandler;
|
|
|
|
let mainWin = browser.ownerDocument.defaultView;
|
|
|
|
mainWin.gContextMenuContentData = {
|
|
|
|
isRemote: false,
|
|
|
|
event: event,
|
|
|
|
popupNode: event.target,
|
|
|
|
browser: browser,
|
|
|
|
addonInfo: addonInfo,
|
2015-02-21 03:22:39 +03:00
|
|
|
documentURIObject: doc.documentURIObject,
|
|
|
|
docLocation: docLocation,
|
|
|
|
charSet: charSet,
|
|
|
|
referrer: referrer,
|
2015-03-05 10:29:55 +03:00
|
|
|
referrerPolicy: referrerPolicy,
|
2014-11-17 21:58:13 +03:00
|
|
|
};
|
|
|
|
}
|
2014-11-12 01:27:17 +03:00
|
|
|
}
|
2014-11-11 23:52:13 +03:00
|
|
|
|
2014-11-17 21:58:13 +03:00
|
|
|
Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService)
|
|
|
|
.addSystemEventListener(global, "contextmenu", handleContentContextMenu, false);
|
|
|
|
|
2014-10-30 14:52:00 +03:00
|
|
|
let AboutNetErrorListener = {
|
|
|
|
init: function(chromeGlobal) {
|
|
|
|
chromeGlobal.addEventListener('AboutNetErrorLoad', this, false, true);
|
|
|
|
chromeGlobal.addEventListener('AboutNetErrorSetAutomatic', this, false, true);
|
|
|
|
chromeGlobal.addEventListener('AboutNetErrorSendReport', this, false, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
get isAboutNetError() {
|
|
|
|
return content.document.documentURI.startsWith("about:neterror");
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
if (!this.isAboutNetError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "AboutNetErrorLoad":
|
|
|
|
this.onPageLoad(aEvent);
|
|
|
|
break;
|
|
|
|
case "AboutNetErrorSetAutomatic":
|
|
|
|
this.onSetAutomatic(aEvent);
|
|
|
|
break;
|
|
|
|
case "AboutNetErrorSendReport":
|
|
|
|
this.onSendReport(aEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPageLoad: function(evt) {
|
|
|
|
let automatic = Services.prefs.getBoolPref("security.ssl.errorReporting.automatic");
|
|
|
|
content.dispatchEvent(new content.CustomEvent("AboutNetErrorOptions", {
|
|
|
|
detail: JSON.stringify({
|
|
|
|
enabled: Services.prefs.getBoolPref("security.ssl.errorReporting.enabled"),
|
|
|
|
automatic: automatic
|
|
|
|
})
|
|
|
|
}
|
|
|
|
));
|
|
|
|
if (automatic) {
|
|
|
|
this.onSendReport(evt);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSetAutomatic: function(evt) {
|
|
|
|
sendAsyncMessage("Browser:SetSSLErrorReportAuto", {
|
|
|
|
automatic: evt.detail
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSendReport: function(evt) {
|
|
|
|
let contentDoc = content.document;
|
|
|
|
|
|
|
|
let reportSendingMsg = contentDoc.getElementById("reportSendingMessage");
|
|
|
|
let reportSentMsg = contentDoc.getElementById("reportSentMessage");
|
|
|
|
let reportBtn = contentDoc.getElementById("reportCertificateError");
|
|
|
|
let retryBtn = contentDoc.getElementById("reportCertificateErrorRetry");
|
|
|
|
|
|
|
|
addMessageListener("Browser:SSLErrorReportStatus", function(message) {
|
|
|
|
// show and hide bits - but only if this is a message for the right
|
|
|
|
// document - we'll compare on document URI
|
|
|
|
if (contentDoc.documentURI === message.data.documentURI) {
|
|
|
|
switch(message.data.reportStatus) {
|
|
|
|
case "activity":
|
|
|
|
// Hide the button that was just clicked
|
|
|
|
reportBtn.style.display = "none";
|
|
|
|
retryBtn.style.display = "none";
|
|
|
|
reportSentMsg.style.display = "none";
|
|
|
|
reportSendingMsg.style.display = "inline";
|
|
|
|
break;
|
|
|
|
case "error":
|
|
|
|
// show the retry button
|
|
|
|
retryBtn.style.display = "inline";
|
|
|
|
reportSendingMsg.style.display = "none";
|
|
|
|
break;
|
|
|
|
case "complete":
|
|
|
|
// Show a success indicator
|
|
|
|
reportSentMsg.style.display = "inline";
|
|
|
|
reportSendingMsg.style.display = "none";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let failedChannel = docShell.failedChannel;
|
|
|
|
let location = contentDoc.location.href;
|
|
|
|
|
|
|
|
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
|
|
|
.getService(Ci.nsISerializationHelper);
|
|
|
|
|
|
|
|
let serializable = docShell.failedChannel.securityInfo
|
|
|
|
.QueryInterface(Ci.nsITransportSecurityInfo)
|
|
|
|
.QueryInterface(Ci.nsISerializable);
|
|
|
|
|
|
|
|
let serializedSecurityInfo = serhelper.serializeToString(serializable);
|
|
|
|
|
|
|
|
sendAsyncMessage("Browser:SendSSLErrorReport", {
|
|
|
|
elementId: evt.target.id,
|
|
|
|
documentURI: contentDoc.documentURI,
|
|
|
|
location: contentDoc.location,
|
|
|
|
securityInfo: serializedSecurityInfo
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AboutNetErrorListener.init(this);
|
|
|
|
|
2013-07-06 00:55:00 +04:00
|
|
|
let AboutHomeListener = {
|
|
|
|
init: function(chromeGlobal) {
|
2014-08-19 04:27:35 +04:00
|
|
|
chromeGlobal.addEventListener('AboutHomeLoad', this, false, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
get isAboutHome() {
|
|
|
|
return content.document.documentURI.toLowerCase() == "about:home";
|
2013-07-06 00:55:00 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
2014-08-19 04:27:35 +04:00
|
|
|
if (!this.isAboutHome) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-06 00:55:00 +04:00
|
|
|
switch (aEvent.type) {
|
|
|
|
case "AboutHomeLoad":
|
|
|
|
this.onPageLoad();
|
|
|
|
break;
|
2014-08-19 04:27:35 +04:00
|
|
|
case "AboutHomeSearchEvent":
|
|
|
|
this.onSearch(aEvent);
|
|
|
|
break;
|
2014-11-24 13:40:22 +03:00
|
|
|
case "AboutHomeSearchPanel":
|
|
|
|
this.onOpenSearchPanel(aEvent);
|
|
|
|
break;
|
2014-08-19 04:27:35 +04:00
|
|
|
case "click":
|
|
|
|
this.onClick(aEvent);
|
|
|
|
break;
|
|
|
|
case "pagehide":
|
|
|
|
this.onPageHide(aEvent);
|
|
|
|
break;
|
2013-07-06 00:55:00 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
2014-08-19 04:27:35 +04:00
|
|
|
if (!this.isAboutHome) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-06 00:55:00 +04:00
|
|
|
switch (aMessage.name) {
|
|
|
|
case "AboutHome:Update":
|
|
|
|
this.onUpdate(aMessage.data);
|
|
|
|
break;
|
2014-08-14 23:48:00 +04:00
|
|
|
case "AboutHome:FocusInput":
|
|
|
|
this.onFocusInput();
|
|
|
|
break;
|
2013-07-06 00:55:00 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onUpdate: function(aData) {
|
|
|
|
let doc = content.document;
|
2014-09-24 02:48:52 +04:00
|
|
|
if (aData.showRestoreLastSession && !PrivateBrowsingUtils.isContentWindowPrivate(content))
|
2013-07-06 00:55:00 +04:00
|
|
|
doc.getElementById("launcher").setAttribute("session", "true");
|
|
|
|
|
|
|
|
// Inject search engine and snippets URL.
|
|
|
|
let docElt = doc.documentElement;
|
2013-08-30 20:20:22 +04:00
|
|
|
// set the following attributes BEFORE searchEngineName, which triggers to
|
2013-07-06 00:55:00 +04: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-26 01:14:55 +04:00
|
|
|
docElt.setAttribute("searchEngineName", aData.defaultEngineName);
|
2013-07-06 00:55:00 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onPageLoad: function() {
|
|
|
|
let doc = content.document;
|
2014-08-19 04:27:35 +04:00
|
|
|
if (doc.documentElement.hasAttribute("hasBrowserHandlers")) {
|
2013-07-06 00:55:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc.documentElement.setAttribute("hasBrowserHandlers", "true");
|
2014-08-19 04:27:35 +04:00
|
|
|
addMessageListener("AboutHome:Update", this);
|
|
|
|
addMessageListener("AboutHome:FocusInput", this);
|
|
|
|
addEventListener("click", this, true);
|
|
|
|
addEventListener("pagehide", this, true);
|
2013-07-06 00:55:00 +04:00
|
|
|
|
2014-11-24 13:40:22 +03:00
|
|
|
if (!Services.prefs.getBoolPref("browser.search.showOneOffButtons")) {
|
|
|
|
doc.documentElement.setAttribute("searchUIConfiguration", "oldsearchui");
|
|
|
|
}
|
|
|
|
|
2013-07-06 00:55:00 +04:00
|
|
|
sendAsyncMessage("AboutHome:RequestUpdate");
|
2014-08-19 04:27:35 +04:00
|
|
|
doc.addEventListener("AboutHomeSearchEvent", this, true, true);
|
2014-11-24 13:40:22 +03:00
|
|
|
doc.addEventListener("AboutHomeSearchPanel", this, true, true);
|
2013-07-06 00:55:00 +04: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-21 03:13:35 +04:00
|
|
|
if (ownerDoc.documentURI != "about:home") {
|
|
|
|
// This shouldn't happen, but we're being defensive.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-06 00:55:00 +04: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-11-24 13:40:22 +03:00
|
|
|
|
|
|
|
case "searchIcon":
|
|
|
|
sendAsyncMessage("AboutHome:OpenSearchPanel", null, { anchor: originalTarget });
|
|
|
|
break;
|
2013-07-06 00:55:00 +04:00
|
|
|
}
|
|
|
|
},
|
2014-08-14 23:48:00 +04:00
|
|
|
|
2014-08-19 04:27:35 +04:00
|
|
|
onPageHide: function(aEvent) {
|
2014-08-20 19:27:03 +04:00
|
|
|
if (aEvent.target.defaultView.frameElement) {
|
2014-08-19 04:27:35 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
removeMessageListener("AboutHome:Update", this);
|
|
|
|
removeEventListener("click", this, true);
|
|
|
|
removeEventListener("pagehide", this, true);
|
2014-08-20 19:27:03 +04:00
|
|
|
if (aEvent.target.documentElement) {
|
|
|
|
aEvent.target.documentElement.removeAttribute("hasBrowserHandlers");
|
2014-08-19 04:27:35 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearch: function(aEvent) {
|
|
|
|
sendAsyncMessage("AboutHome:Search", { searchData: aEvent.detail });
|
|
|
|
},
|
|
|
|
|
2014-11-24 13:40:22 +03:00
|
|
|
onOpenSearchPanel: function(aEvent) {
|
|
|
|
sendAsyncMessage("AboutHome:OpenSearchPanel");
|
|
|
|
},
|
|
|
|
|
2014-08-14 23:48:00 +04:00
|
|
|
onFocusInput: function () {
|
2014-08-19 04:27:35 +04:00
|
|
|
let searchInput = content.document.getElementById("searchText");
|
|
|
|
if (searchInput) {
|
|
|
|
searchInput.focus();
|
|
|
|
}
|
2014-08-14 23:48:00 +04:00
|
|
|
},
|
2013-07-06 00:55:00 +04:00
|
|
|
};
|
|
|
|
AboutHomeListener.init(this);
|
|
|
|
|
2014-12-30 18:44:34 +03:00
|
|
|
let AboutReaderListener = {
|
2015-03-13 06:06:37 +03:00
|
|
|
|
|
|
|
_articlePromise: null,
|
2014-12-30 18:44:34 +03:00
|
|
|
|
|
|
|
init: function() {
|
|
|
|
addEventListener("AboutReaderContentLoaded", this, false, true);
|
2015-03-18 20:35:53 +03:00
|
|
|
addEventListener("DOMContentLoaded", this, false);
|
2015-03-19 21:44:07 +03:00
|
|
|
addEventListener("pageshow", this, false);
|
2015-01-03 04:20:12 +03:00
|
|
|
addEventListener("pagehide", this, false);
|
2015-03-13 06:06:37 +03:00
|
|
|
addMessageListener("Reader:ParseDocument", this);
|
2014-12-30 18:44:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(message) {
|
|
|
|
switch (message.name) {
|
2015-03-13 06:06:37 +03:00
|
|
|
case "Reader:ParseDocument":
|
2015-03-17 19:23:19 +03:00
|
|
|
this._articlePromise = ReaderMode.parseDocument(content.document).catch(Cu.reportError);
|
2015-03-13 06:06:37 +03:00
|
|
|
content.document.location = "about:reader?url=" + encodeURIComponent(message.data.url);
|
2014-12-30 18:44:34 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get isAboutReader() {
|
|
|
|
return content.document.documentURI.startsWith("about:reader");
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
if (aEvent.originalTarget.defaultView != content) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "AboutReaderContentLoaded":
|
|
|
|
if (!this.isAboutReader) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content.document.body) {
|
2015-01-03 04:20:12 +03:00
|
|
|
// Update the toolbar icon to show the "reader active" icon.
|
|
|
|
sendAsyncMessage("Reader:UpdateReaderButton");
|
2015-03-13 06:06:37 +03:00
|
|
|
new AboutReader(global, content, this._articlePromise);
|
2015-03-25 01:44:28 +03:00
|
|
|
this._articlePromise = null;
|
2014-12-30 18:44:34 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-01-03 04:20:12 +03:00
|
|
|
case "pagehide":
|
|
|
|
sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: false });
|
|
|
|
break;
|
|
|
|
|
2015-03-19 21:44:07 +03:00
|
|
|
case "pageshow":
|
|
|
|
// If a page is loaded from the bfcache, we won't get a "DOMContentLoaded"
|
|
|
|
// event, so we need to rely on "pageshow" in this case.
|
|
|
|
if (!aEvent.persisted) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Fall through.
|
2015-03-18 20:35:53 +03:00
|
|
|
case "DOMContentLoaded":
|
2014-12-30 18:44:34 +03:00
|
|
|
if (!ReaderMode.isEnabledForParseOnLoad || this.isAboutReader) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-13 06:06:37 +03:00
|
|
|
let isArticle = ReaderMode.isProbablyReaderable(content.document);
|
|
|
|
sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: isArticle });
|
2014-12-30 18:44:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
AboutReaderListener.init();
|
2014-04-25 06:09:20 +04:00
|
|
|
|
2014-08-01 09:42:00 +04: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-25 06:09:20 +04:00
|
|
|
let ContentSearchMediator = {
|
|
|
|
|
|
|
|
whitelist: new Set([
|
2014-08-01 23:00:44 +04:00
|
|
|
"about:home",
|
2014-04-25 06:09:20 +04: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 23:00:44 +04:00
|
|
|
return this.whitelist.has(content.document.documentURI);
|
2014-04-25 06:09:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_sendMsg: function (type, data=null) {
|
|
|
|
sendAsyncMessage("ContentSearch", {
|
|
|
|
type: type,
|
|
|
|
data: data,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_fireEvent: function (type, data=null) {
|
2014-08-01 23:00:44 +04:00
|
|
|
let event = Cu.cloneInto({
|
2014-04-25 06:09:20 +04:00
|
|
|
detail: {
|
|
|
|
type: type,
|
|
|
|
data: data,
|
|
|
|
},
|
2014-08-01 23:00:44 +04:00
|
|
|
}, content);
|
|
|
|
content.dispatchEvent(new content.CustomEvent("ContentSearchService",
|
|
|
|
event));
|
2014-04-25 06:09:20 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
ContentSearchMediator.init(this);
|
|
|
|
|
2013-09-14 03:27:19 +04:00
|
|
|
// Lazily load the finder code
|
|
|
|
addMessageListener("Finder:Initialize", function () {
|
|
|
|
let {RemoteFinderListener} = Cu.import("resource://gre/modules/RemoteFinder.jsm", {});
|
|
|
|
new RemoteFinderListener(global);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-08-09 04:16:47 +04: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 23:27:35 +04:00
|
|
|
if (!event.isTrusted || event.defaultPrevented || event.button == 2) {
|
2013-08-09 04:16:47 +04:00
|
|
|
return;
|
2014-07-02 23:27:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let originalTarget = event.originalTarget;
|
|
|
|
let ownerDoc = originalTarget.ownerDocument;
|
2014-09-09 00:36:22 +04:00
|
|
|
if (!ownerDoc) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-02 23:27:35 +04:00
|
|
|
|
|
|
|
// 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")) {
|
2015-01-14 13:46:55 +03:00
|
|
|
this.onAboutNetError(event, ownerDoc.documentURI);
|
|
|
|
return;
|
2014-07-02 23:27:35 +04:00
|
|
|
}
|
2013-08-09 04:16:47 +04: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,
|
2015-03-05 10:29:55 +03:00
|
|
|
bookmark: false, referrerPolicy: ownerDoc.referrerPolicy };
|
2013-08-09 04:16:47 +04:00
|
|
|
|
|
|
|
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 23:27:35 +04:00
|
|
|
if (json.bookmark) {
|
2013-08-09 04:16:47 +04:00
|
|
|
event.preventDefault(); // Need to prevent the pageload.
|
2014-07-02 23:27:35 +04:00
|
|
|
}
|
2013-08-09 04:16:47 +04:00
|
|
|
}
|
|
|
|
}
|
2015-02-18 00:17:06 +03:00
|
|
|
json.noReferrer = BrowserUtils.linkHasNoReferrer(node)
|
2013-08-09 04:16:47 +04:00
|
|
|
|
|
|
|
sendAsyncMessage("Content:Click", json);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This might be middle mouse navigation.
|
2014-07-02 23:27:35 +04:00
|
|
|
if (event.button == 1) {
|
2013-08-09 04:16:47 +04:00
|
|
|
sendAsyncMessage("Content:Click", json);
|
2014-07-02 23:27:35 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onAboutCertError: function (targetElement, ownerDoc) {
|
2014-07-08 02:33:07 +04:00
|
|
|
let docshell = ownerDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell);
|
2014-10-02 08:17:13 +04:00
|
|
|
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
|
|
|
.getService(Ci.nsISerializationHelper);
|
|
|
|
let serializedSSLStatus = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
let serializable = docShell.failedChannel.securityInfo
|
|
|
|
.QueryInterface(Ci.nsISSLStatusProvider)
|
|
|
|
.SSLStatus
|
|
|
|
.QueryInterface(Ci.nsISerializable);
|
|
|
|
serializedSSLStatus = serhelper.serializeToString(serializable);
|
|
|
|
} catch (e) { }
|
|
|
|
|
2014-07-02 23:27:35 +04:00
|
|
|
sendAsyncMessage("Browser:CertExceptionError", {
|
|
|
|
location: ownerDoc.location.href,
|
|
|
|
elementId: targetElement.getAttribute("id"),
|
2014-07-08 02:33:07 +04:00
|
|
|
isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView),
|
2014-10-02 08:17:13 +04:00
|
|
|
sslStatusAsString: serializedSSLStatus
|
2014-07-02 23:27:35 +04: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)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-01-14 13:46:55 +03:00
|
|
|
onAboutNetError: function (event, documentURI) {
|
|
|
|
let elmId = event.originalTarget.getAttribute("id");
|
|
|
|
if (elmId != "errorTryAgain" || !/e=netOffline/.test(documentURI)) {
|
2014-07-02 23:27:35 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-01-14 13:46:55 +03:00
|
|
|
// browser front end will handle clearing offline mode and refreshing
|
|
|
|
// the page *if* we're in offline mode now. Otherwise let the error page
|
|
|
|
// handle the click.
|
|
|
|
if (Services.io.offline) {
|
|
|
|
event.preventDefault();
|
|
|
|
sendAsyncMessage("Browser:EnableOnlineMode", {});
|
|
|
|
}
|
2013-08-09 04:16:47 +04: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 11:57:26 +04:00
|
|
|
baseURI = node.ownerDocument.baseURIObject;
|
2013-08-09 04:16:47 +04: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 11:57:26 +04:00
|
|
|
// Note: makeURI() will throw if aUri is not a valid URI.
|
2014-08-21 19:42:42 +04:00
|
|
|
return [href ? BrowserUtils.makeURI(href, null, baseURI).spec : null, null];
|
2013-08-09 04:16:47 +04:00
|
|
|
}
|
|
|
|
};
|
2013-08-30 20:20:22 +04:00
|
|
|
ClickEventHandler.init();
|
2014-01-13 16:56:28 +04:00
|
|
|
|
2014-02-09 05:41:34 +04:00
|
|
|
ContentLinkHandler.init(this);
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
// TODO: Load this lazily so the JSM is run only if a relevant event/message fires.
|
|
|
|
let pluginContent = new PluginContent(global);
|
|
|
|
|
2014-01-13 16:56:28 +04:00
|
|
|
addEventListener("DOMWebNotificationClicked", function(event) {
|
|
|
|
sendAsyncMessage("DOMWebNotificationClicked", {});
|
|
|
|
}, false);
|
2014-03-12 07:13:45 +04: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-10 01:27:49 +04:00
|
|
|
return docShell.contentViewer;
|
2014-03-12 07:13:45 +04: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-17 02:02:33 +04:00
|
|
|
|
2014-05-20 00:33:41 +04: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-20 00:58:00 +04: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 22:44:10 +04:00
|
|
|
DOMFullscreenHandler.init();
|
2014-09-03 01:43:08 +04:00
|
|
|
|
2014-09-22 22:39:57 +04:00
|
|
|
ContentWebRTC.init();
|
2014-09-22 22:39:58 +04:00
|
|
|
addMessageListener("webrtc:Allow", ContentWebRTC);
|
|
|
|
addMessageListener("webrtc:Deny", ContentWebRTC);
|
2014-09-22 22:39:57 +04:00
|
|
|
addMessageListener("webrtc:StopSharing", ContentWebRTC);
|
2015-02-24 19:16:27 +03:00
|
|
|
addMessageListener("webrtc:StartBrowserSharing", () => {
|
|
|
|
let windowID = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
|
|
|
sendAsyncMessage("webrtc:response:StartBrowserSharing", {
|
|
|
|
windowID: windowID
|
|
|
|
});
|
|
|
|
});
|
2014-09-22 22:39:57 +04:00
|
|
|
|
2014-09-03 02:34:01 +04:00
|
|
|
function gKeywordURIFixup(fixupInfo) {
|
|
|
|
fixupInfo.QueryInterface(Ci.nsIURIFixupInfo);
|
|
|
|
|
|
|
|
// Ignore info from other docshells
|
|
|
|
let parent = fixupInfo.consumer.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeRootTreeItem;
|
|
|
|
if (parent != docShell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let data = {};
|
|
|
|
for (let f of Object.keys(fixupInfo)) {
|
|
|
|
if (f == "consumer" || typeof fixupInfo[f] == "function")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fixupInfo[f] && fixupInfo[f] instanceof Ci.nsIURI) {
|
|
|
|
data[f] = fixupInfo[f].spec;
|
|
|
|
} else {
|
|
|
|
data[f] = fixupInfo[f];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("Browser:URIFixup", data);
|
|
|
|
}
|
|
|
|
Services.obs.addObserver(gKeywordURIFixup, "keyword-uri-fixup", false);
|
|
|
|
addEventListener("unload", () => {
|
|
|
|
Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup");
|
|
|
|
}, false);
|
|
|
|
|
2014-09-03 01:43:08 +04: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);
|
|
|
|
},
|
2014-09-25 22:35:45 +04:00
|
|
|
|
|
|
|
// Check whether this URI should load in the current process
|
|
|
|
shouldLoadURI: function(aDocShell, aURI, aReferrer) {
|
|
|
|
if (!E10SUtils.shouldLoadURI(aDocShell, aURI, aReferrer)) {
|
|
|
|
E10SUtils.redirectLoad(aDocShell, aURI, aReferrer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
2014-09-03 01:43:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
|
|
|
let tabchild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsITabChild);
|
|
|
|
tabchild.webBrowserChrome = WebBrowserChrome;
|
|
|
|
}
|
2014-09-03 07:09:24 +04:00
|
|
|
|
|
|
|
addEventListener("pageshow", function(event) {
|
|
|
|
if (event.target == content.document) {
|
|
|
|
sendAsyncMessage("PageVisibility:Show", {
|
|
|
|
persisted: event.persisted,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-10-30 22:21:47 +03:00
|
|
|
|
2015-03-06 01:43:05 +03:00
|
|
|
let PageMetadataMessenger = {
|
2015-03-17 22:49:07 +03:00
|
|
|
init() {
|
2015-03-06 01:43:05 +03:00
|
|
|
addMessageListener("PageMetadata:GetPageData", this);
|
|
|
|
addMessageListener("PageMetadata:GetMicrodata", this);
|
2014-11-06 04:26:36 +03:00
|
|
|
},
|
2015-03-17 22:49:07 +03:00
|
|
|
receiveMessage(message) {
|
|
|
|
switch(message.name) {
|
2015-03-06 01:43:05 +03:00
|
|
|
case "PageMetadata:GetPageData": {
|
|
|
|
let result = PageMetadata.getData(content.document);
|
|
|
|
sendAsyncMessage("PageMetadata:PageDataResult", result);
|
2014-11-06 04:26:36 +03:00
|
|
|
break;
|
2015-03-06 01:43:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case "PageMetadata:GetMicrodata": {
|
2015-03-12 00:19:30 +03:00
|
|
|
let target = message.objects.target;
|
2015-03-06 01:43:05 +03:00
|
|
|
let result = PageMetadata.getMicrodata(content.document, target);
|
|
|
|
sendAsyncMessage("PageMetadata:MicrodataResult", result);
|
2014-11-06 04:26:36 +03:00
|
|
|
break;
|
2015-03-06 01:43:05 +03:00
|
|
|
}
|
2014-11-06 04:26:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-06 01:43:05 +03:00
|
|
|
PageMetadataMessenger.init();
|
2014-11-06 04:26:36 +03:00
|
|
|
|
2014-11-06 04:22:27 +03:00
|
|
|
addEventListener("ActivateSocialFeature", function (aEvent) {
|
|
|
|
let document = content.document;
|
|
|
|
if (PrivateBrowsingUtils.isContentWindowPrivate(content)) {
|
|
|
|
Cu.reportError("cannot use social providers in private windows");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let dwu = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
if (!dwu.isHandlingUserInput) {
|
|
|
|
Cu.reportError("attempt to activate provider without user input from " + document.nodePrincipal.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let node = aEvent.target;
|
|
|
|
let ownerDocument = node.ownerDocument;
|
|
|
|
let data = node.getAttribute("data-service");
|
|
|
|
if (data) {
|
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError("Social Service manifest parse error: " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Cu.reportError("Social Service manifest not available");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("Social:Activation", {
|
|
|
|
url: ownerDocument.location.href,
|
|
|
|
origin: ownerDocument.nodePrincipal.origin,
|
|
|
|
manifest: data
|
|
|
|
});
|
|
|
|
}, true, true);
|
|
|
|
|
2014-10-30 22:21:47 +03:00
|
|
|
addMessageListener("ContextMenu:SaveVideoFrameAsImage", (message) => {
|
|
|
|
let video = message.objects.target;
|
|
|
|
let canvas = content.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
canvas.width = video.videoWidth;
|
|
|
|
canvas.height = video.videoHeight;
|
|
|
|
|
|
|
|
let ctxDraw = canvas.getContext("2d");
|
|
|
|
ctxDraw.drawImage(video, 0, 0);
|
|
|
|
sendAsyncMessage("ContextMenu:SaveVideoFrameAsImage:Result", {
|
|
|
|
dataURL: canvas.toDataURL("image/jpeg", ""),
|
|
|
|
});
|
|
|
|
});
|
2015-02-19 09:37:00 +03:00
|
|
|
|
|
|
|
addMessageListener("ContextMenu:MediaCommand", (message) => {
|
|
|
|
let media = message.objects.element;
|
|
|
|
|
|
|
|
switch (message.data.command) {
|
|
|
|
case "play":
|
|
|
|
media.play();
|
|
|
|
break;
|
|
|
|
case "pause":
|
|
|
|
media.pause();
|
|
|
|
break;
|
|
|
|
case "mute":
|
|
|
|
media.muted = true;
|
|
|
|
break;
|
|
|
|
case "unmute":
|
|
|
|
media.muted = false;
|
|
|
|
break;
|
|
|
|
case "playbackRate":
|
|
|
|
media.playbackRate = message.data.data;
|
|
|
|
break;
|
|
|
|
case "hidecontrols":
|
|
|
|
media.removeAttribute("controls");
|
|
|
|
break;
|
|
|
|
case "showcontrols":
|
|
|
|
media.setAttribute("controls", "true");
|
|
|
|
break;
|
|
|
|
case "hidestats":
|
|
|
|
case "showstats":
|
|
|
|
let event = media.ownerDocument.createEvent("CustomEvent");
|
|
|
|
event.initCustomEvent("media-showStatistics", false, true,
|
|
|
|
message.data.command == "showstats");
|
|
|
|
media.dispatchEvent(event);
|
|
|
|
break;
|
2015-02-19 09:39:00 +03:00
|
|
|
case "fullscreen":
|
|
|
|
if (content.document.mozFullScreenEnabled)
|
|
|
|
media.mozRequestFullScreen();
|
|
|
|
break;
|
2015-02-19 09:37:00 +03:00
|
|
|
}
|
|
|
|
});
|
2015-03-05 00:27:35 +03:00
|
|
|
|
|
|
|
addMessageListener("ContextMenu:Canvas:ToDataURL", (message) => {
|
|
|
|
let dataURL = message.objects.target.toDataURL();
|
|
|
|
sendAsyncMessage("ContextMenu:Canvas:ToDataURL:Result", { dataURL });
|
|
|
|
});
|