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. */
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var {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");
|
2015-08-13 12:12:02 +03:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2013-06-20 03:30:53 +04:00
|
|
|
|
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");
|
2015-03-06 01:43:05 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PageMetadata",
|
|
|
|
"resource://gre/modules/PageMetadata.jsm");
|
2015-03-05 00:27:35 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUIUtils",
|
|
|
|
"resource:///modules/PlacesUIUtils.jsm");
|
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();
|
|
|
|
});
|
2015-08-13 10:37:02 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
|
|
|
|
"resource:///modules/Feeds.jsm");
|
2015-07-09 00:18:38 +03: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
|
|
|
|
2014-12-16 19:21:11 +03:00
|
|
|
addMessageListener("ContextMenu:DoCustomCommand", function(message) {
|
|
|
|
PageMenuChild.executeMenu(message.data);
|
|
|
|
});
|
|
|
|
|
2015-05-13 17:34:14 +03:00
|
|
|
addMessageListener("RemoteLogins:fillForm", function(message) {
|
|
|
|
LoginManagerContent.receiveMessage(message, content);
|
|
|
|
});
|
2014-06-28 22:09:45 +04:00
|
|
|
addEventListener("DOMFormHasPassword", function(event) {
|
2015-05-13 17:34:14 +03:00
|
|
|
LoginManagerContent.onDOMFormHasPassword(event, content);
|
2014-06-28 22:09:45 +04:00
|
|
|
InsecurePasswordUtils.checkForInsecurePasswords(event.target);
|
2015-05-13 17:34:14 +03:00
|
|
|
});
|
2015-06-29 10:11:22 +03:00
|
|
|
addEventListener("DOMInputPasswordAdded", function(event) {
|
|
|
|
LoginManagerContent.onDOMInputPasswordAdded(event, content);
|
|
|
|
});
|
2015-05-13 17:34:14 +03:00
|
|
|
addEventListener("pageshow", function(event) {
|
|
|
|
LoginManagerContent.onPageShow(event, content);
|
2014-06-28 22:09:45 +04:00
|
|
|
});
|
|
|
|
addEventListener("DOMAutoComplete", function(event) {
|
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
addEventListener("blur", function(event) {
|
|
|
|
LoginManagerContent.onUsernameInput(event);
|
|
|
|
});
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var handleContentContextMenu = function (event) {
|
2014-11-17 21:58:13 +03: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;
|
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;
|
2015-10-23 14:48:59 +03:00
|
|
|
let docLocation = doc.location ? doc.location.href : undefined;
|
2015-02-21 03:22:39 +03:00
|
|
|
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-04-01 20:38:24 +03:00
|
|
|
let frameOuterWindowID = doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.outerWindowID;
|
2015-08-25 05:06:00 +03:00
|
|
|
let loginFillInfo = LoginManagerContent.getFieldContext(event.target);
|
2015-02-21 03:22:39 +03:00
|
|
|
|
2015-06-06 01:25:24 +03:00
|
|
|
// get referrer attribute from clicked link and parse it
|
|
|
|
// if per element referrer is enabled, the element referrer overrules
|
|
|
|
// the document wide referrer
|
|
|
|
if (Services.prefs.getBoolPref("network.http.enablePerElementReferrer")) {
|
|
|
|
let referrerAttrValue = Services.netUtils.parseAttributePolicyString(event.target.
|
2015-12-03 04:02:55 +03:00
|
|
|
getAttribute("referrerpolicy"));
|
2015-06-06 01:25:24 +03:00
|
|
|
if (referrerAttrValue !== Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT) {
|
|
|
|
referrerPolicy = referrerAttrValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 09:36:38 +03:00
|
|
|
let disableSetDesktopBg = null;
|
2015-03-31 20:59:06 +03:00
|
|
|
// Media related cache info parent needs for saving
|
|
|
|
let contentType = null;
|
|
|
|
let contentDisposition = null;
|
|
|
|
if (event.target.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
|
|
|
event.target instanceof Ci.nsIImageLoadingContent &&
|
|
|
|
event.target.currentURI) {
|
2015-06-16 09:36:38 +03:00
|
|
|
disableSetDesktopBg = disableSetDesktopBackground(event.target);
|
|
|
|
|
2015-03-31 20:59:06 +03:00
|
|
|
try {
|
2016-02-04 01:22:33 +03:00
|
|
|
let imageCache =
|
2015-04-30 22:42:43 +03:00
|
|
|
Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
|
|
|
|
.getImgCacheForDocument(doc);
|
2015-03-31 20:59:06 +03:00
|
|
|
let props =
|
2015-10-26 23:03:26 +03:00
|
|
|
imageCache.findEntryProperties(event.target.currentURI, doc);
|
2015-04-30 22:42:43 +03:00
|
|
|
try {
|
2015-03-31 20:59:06 +03:00
|
|
|
contentType = props.get("type", Ci.nsISupportsCString).data;
|
2015-04-30 22:42:43 +03:00
|
|
|
} catch(e) {}
|
|
|
|
try {
|
|
|
|
contentDisposition =
|
|
|
|
props.get("content-disposition", Ci.nsISupportsCString).data;
|
|
|
|
} catch(e) {}
|
|
|
|
} catch(e) {}
|
2015-03-31 20:59:06 +03:00
|
|
|
}
|
|
|
|
|
2015-04-29 15:38:42 +03:00
|
|
|
let selectionInfo = BrowserUtils.getSelectionDetails(content);
|
|
|
|
|
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
|
|
|
|
2015-04-22 03:09:14 +03:00
|
|
|
// Set the event target first as the copy image command needs it to
|
|
|
|
// determine what was context-clicked on. Then, update the state of the
|
|
|
|
// commands on the context menu.
|
|
|
|
docShell.contentViewer.QueryInterface(Ci.nsIContentViewerEdit)
|
|
|
|
.setCommandNode(event.target);
|
|
|
|
event.target.ownerDocument.defaultView.updateCommands("contentcontextmenu");
|
|
|
|
|
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-06-24 04:17:47 +03:00
|
|
|
sendRpcMessage("contextmenu",
|
|
|
|
{ editFlags, spellInfo, customMenuItems, addonInfo,
|
|
|
|
principal, docLocation, charSet, baseURI, referrer,
|
|
|
|
referrerPolicy, contentType, contentDisposition,
|
2015-08-25 05:06:00 +03:00
|
|
|
frameOuterWindowID, selectionInfo, disableSetDesktopBg,
|
|
|
|
loginFillInfo, },
|
2015-06-24 04:17:47 +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,
|
2015-03-31 20:59:06 +03:00
|
|
|
contentType: contentType,
|
|
|
|
contentDisposition: contentDisposition,
|
2015-04-29 15:38:42 +03:00
|
|
|
selectionInfo: selectionInfo,
|
2015-06-16 09:36:38 +03:00
|
|
|
disableSetDesktopBackground: disableSetDesktopBg,
|
2015-08-25 05:06:00 +03:00
|
|
|
loginFillInfo,
|
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);
|
|
|
|
|
2015-06-10 16:18:17 +03:00
|
|
|
// Values for telemtery bins: see TLS_ERROR_REPORT_UI in Histograms.json
|
|
|
|
const TLS_ERROR_REPORT_TELEMETRY_UI_SHOWN = 0;
|
|
|
|
const TLS_ERROR_REPORT_TELEMETRY_EXPANDED = 1;
|
|
|
|
const TLS_ERROR_REPORT_TELEMETRY_SUCCESS = 6;
|
|
|
|
const TLS_ERROR_REPORT_TELEMETRY_FAILURE = 7;
|
|
|
|
|
2016-01-13 17:29:54 +03:00
|
|
|
var AboutCertErrorListener = {
|
|
|
|
init(chromeGlobal) {
|
|
|
|
addMessageListener("AboutCertErrorDetails", this);
|
|
|
|
chromeGlobal.addEventListener("AboutCertErrorLoad", this, false, true);
|
|
|
|
chromeGlobal.addEventListener("AboutCertErrorSetAutomatic", this, false, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
get isAboutCertError() {
|
|
|
|
return content.document.documentURI.startsWith("about:certerror");
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent(event) {
|
|
|
|
if (!this.isAboutCertError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
case "AboutCertErrorLoad":
|
|
|
|
this.onLoad(event);
|
|
|
|
break;
|
|
|
|
case "AboutCertErrorSetAutomatic":
|
|
|
|
this.onSetAutomatic(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage(msg) {
|
|
|
|
if (!this.isAboutCertError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (msg.name) {
|
|
|
|
case "AboutCertErrorDetails":
|
|
|
|
this.onDetails(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad(event) {
|
|
|
|
let originalTarget = event.originalTarget;
|
|
|
|
let ownerDoc = originalTarget.ownerDocument;
|
|
|
|
ClickEventHandler.onAboutCertError(originalTarget, ownerDoc);
|
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
// Set up the TLS Error Reporting UI - reports are sent automatically
|
|
|
|
// (from nsHttpChannel::OnStopRequest) if the user has previously enabled
|
|
|
|
// automatic sending of reports. The UI ensures that a report is sent
|
|
|
|
// for the certificate error currently displayed if the user enables it
|
|
|
|
// here.
|
2016-01-13 17:29:54 +03:00
|
|
|
let automatic = Services.prefs.getBoolPref("security.ssl.errorReporting.automatic");
|
|
|
|
content.dispatchEvent(new content.CustomEvent("AboutCertErrorOptions", {
|
|
|
|
detail: JSON.stringify({
|
|
|
|
enabled: Services.prefs.getBoolPref("security.ssl.errorReporting.enabled"),
|
|
|
|
automatic,
|
|
|
|
})
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
onDetails(msg) {
|
|
|
|
let div = content.document.getElementById("certificateErrorText");
|
|
|
|
div.textContent = msg.data.info;
|
|
|
|
},
|
|
|
|
|
|
|
|
onSetAutomatic(event) {
|
|
|
|
sendAsyncMessage("Browser:SetSSLErrorReportAuto", {
|
|
|
|
automatic: event.detail
|
|
|
|
});
|
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
// if we're enabling reports, send a report for this failure
|
|
|
|
if (event.detail) {
|
|
|
|
let doc = content.document;
|
|
|
|
let location = doc.location.href;
|
2016-01-13 17:29:54 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
|
|
|
.getService(Ci.nsISerializationHelper);
|
2016-01-13 17:29:54 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let serializable = docShell.failedChannel.securityInfo
|
|
|
|
.QueryInterface(Ci.nsITransportSecurityInfo)
|
|
|
|
.QueryInterface(Ci.nsISerializable);
|
2016-01-13 17:29:54 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let serializedSecurityInfo = serhelper.serializeToString(serializable);
|
2016-01-13 17:29:54 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
sendAsyncMessage("Browser:SendSSLErrorReport", {
|
|
|
|
documentURI: doc.documentURI,
|
|
|
|
location: {hostname: doc.location.hostname, port: doc.location.port},
|
|
|
|
securityInfo: serializedSecurityInfo
|
|
|
|
});
|
2016-01-13 17:29:54 +03:00
|
|
|
}
|
2016-02-01 14:18:50 +03:00
|
|
|
},
|
2016-01-13 17:29:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
AboutCertErrorListener.init(this);
|
|
|
|
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var AboutNetErrorListener = {
|
2014-10-30 14:52:00 +03:00
|
|
|
init: function(chromeGlobal) {
|
|
|
|
chromeGlobal.addEventListener('AboutNetErrorLoad', this, false, true);
|
|
|
|
chromeGlobal.addEventListener('AboutNetErrorSetAutomatic', this, false, true);
|
2015-10-17 03:38:31 +03:00
|
|
|
chromeGlobal.addEventListener('AboutNetErrorOverride', this, false, true);
|
2014-10-30 14:52:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
2015-10-17 03:38:31 +03:00
|
|
|
case "AboutNetErrorOverride":
|
|
|
|
this.onOverride(aEvent);
|
|
|
|
break;
|
2014-10-30 14:52:00 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPageLoad: function(evt) {
|
|
|
|
let automatic = Services.prefs.getBoolPref("security.ssl.errorReporting.automatic");
|
|
|
|
content.dispatchEvent(new content.CustomEvent("AboutNetErrorOptions", {
|
2016-02-01 14:18:50 +03:00
|
|
|
detail: JSON.stringify({
|
|
|
|
enabled: Services.prefs.getBoolPref("security.ssl.errorReporting.enabled"),
|
|
|
|
automatic: automatic
|
|
|
|
})
|
|
|
|
}));
|
2015-06-10 16:18:17 +03:00
|
|
|
|
|
|
|
sendAsyncMessage("Browser:SSLErrorReportTelemetry",
|
|
|
|
{reportStatus: TLS_ERROR_REPORT_TELEMETRY_UI_SHOWN});
|
2014-10-30 14:52:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onSetAutomatic: function(evt) {
|
|
|
|
sendAsyncMessage("Browser:SetSSLErrorReportAuto", {
|
2016-02-01 14:18:50 +03:00
|
|
|
automatic: evt.detail
|
|
|
|
});
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
// if we're enabling reports, send a report for this failure
|
|
|
|
if (evt.detail) {
|
|
|
|
let contentDoc = content.document;
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let location = contentDoc.location.href;
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
|
|
|
.getService(Ci.nsISerializationHelper);
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let serializable = docShell.failedChannel.securityInfo
|
|
|
|
.QueryInterface(Ci.nsITransportSecurityInfo)
|
|
|
|
.QueryInterface(Ci.nsISerializable);
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
let serializedSecurityInfo = serhelper.serializeToString(serializable);
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
sendAsyncMessage("Browser:SendSSLErrorReport", {
|
|
|
|
documentURI: contentDoc.documentURI,
|
|
|
|
location: {
|
|
|
|
hostname: contentDoc.location.hostname,
|
|
|
|
port: contentDoc.location.port
|
|
|
|
},
|
|
|
|
securityInfo: serializedSecurityInfo
|
|
|
|
});
|
2014-10-30 14:52:00 +03:00
|
|
|
|
2016-02-01 14:18:50 +03:00
|
|
|
}
|
2015-10-17 03:38:31 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onOverride: function(evt) {
|
|
|
|
let contentDoc = content.document;
|
|
|
|
let location = contentDoc.location;
|
|
|
|
|
|
|
|
sendAsyncMessage("Browser:OverrideWeakCrypto", {
|
|
|
|
documentURI: contentDoc.documentURI,
|
|
|
|
location: {hostname: location.hostname, port: location.port}
|
|
|
|
});
|
2014-10-30 14:52:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AboutNetErrorListener.init(this);
|
|
|
|
|
2014-08-01 09:42:00 +04:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var ClickEventHandler = {
|
2013-08-09 04:16:47 +04:00
|
|
|
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
|
|
|
|
2015-11-12 20:27:38 +03:00
|
|
|
let [href, node, principal] = this._hrefAndLinkNodeForClickEvent(event);
|
2013-08-09 04:16:47 +04:00
|
|
|
|
2015-06-06 01:25:24 +03:00
|
|
|
// get referrer attribute from clicked link and parse it
|
|
|
|
// if per element referrer is enabled, the element referrer overrules
|
|
|
|
// the document wide referrer
|
|
|
|
let referrerPolicy = ownerDoc.referrerPolicy;
|
|
|
|
if (Services.prefs.getBoolPref("network.http.enablePerElementReferrer") &&
|
|
|
|
node) {
|
|
|
|
let referrerAttrValue = Services.netUtils.parseAttributePolicyString(node.
|
2015-12-03 04:02:55 +03:00
|
|
|
getAttribute("referrerpolicy"));
|
2015-06-06 01:25:24 +03:00
|
|
|
if (referrerAttrValue !== Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT) {
|
|
|
|
referrerPolicy = referrerAttrValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 04:16:47 +04:00
|
|
|
let json = { button: event.button, shiftKey: event.shiftKey,
|
|
|
|
ctrlKey: event.ctrlKey, metaKey: event.metaKey,
|
|
|
|
altKey: event.altKey, href: null, title: null,
|
2015-06-06 01:25:24 +03:00
|
|
|
bookmark: false, referrerPolicy: referrerPolicy };
|
2013-08-09 04:16:47 +04:00
|
|
|
|
|
|
|
if (href) {
|
2015-05-22 21:01:55 +03:00
|
|
|
try {
|
2015-11-12 20:27:38 +03:00
|
|
|
BrowserUtils.urlSecurityCheck(href, principal);
|
2015-05-22 21:01:55 +03:00
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-09 04:16:47 +04:00
|
|
|
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);
|
2015-11-25 18:30:27 +03:00
|
|
|
let serializedSecurityInfo = "";
|
2014-10-02 08:17:13 +04:00
|
|
|
|
|
|
|
try {
|
|
|
|
let serializable = docShell.failedChannel.securityInfo
|
2015-11-25 18:30:27 +03:00
|
|
|
.QueryInterface(Ci.nsITransportSecurityInfo)
|
2014-10-02 08:17:13 +04:00
|
|
|
.QueryInterface(Ci.nsISerializable);
|
2015-11-25 18:30:27 +03:00
|
|
|
|
|
|
|
serializedSecurityInfo = serhelper.serializeToString(serializable);
|
2014-10-02 08:17:13 +04:00
|
|
|
} 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),
|
2015-11-25 18:30:27 +03:00
|
|
|
securityInfoAsString: serializedSecurityInfo
|
2014-07-02 23:27:35 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onAboutBlocked: function (targetElement, ownerDoc) {
|
2015-04-22 12:01:37 +03:00
|
|
|
var reason = 'phishing';
|
|
|
|
if (/e=malwareBlocked/.test(ownerDoc.documentURI)) {
|
|
|
|
reason = 'malware';
|
|
|
|
} else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {
|
|
|
|
reason = 'unwanted';
|
2015-11-21 07:24:50 +03:00
|
|
|
} else if (/e=forbiddenBlocked/.test(ownerDoc.documentURI)) {
|
|
|
|
reason = 'forbidden';
|
2015-04-22 12:01:37 +03:00
|
|
|
}
|
2014-07-02 23:27:35 +04:00
|
|
|
sendAsyncMessage("Browser:SiteBlockedError", {
|
|
|
|
location: ownerDoc.location.href,
|
2015-04-22 12:01:37 +03:00
|
|
|
reason: reason,
|
2014-07-02 23:27:35 +04:00
|
|
|
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");
|
2015-12-03 01:16:51 +03:00
|
|
|
if (elmId == "returnButton") {
|
|
|
|
sendAsyncMessage("Browser:SSLErrorGoBack", {});
|
|
|
|
return;
|
|
|
|
}
|
2015-01-14 13:46:55 +03:00
|
|
|
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.
|
2015-11-12 20:27:38 +03:00
|
|
|
* @return [href, linkNode, linkPrincipal].
|
2013-08-09 04:16:47 +04:00
|
|
|
*
|
|
|
|
* @note linkNode will be null if the click wasn't on an anchor
|
2015-11-12 20:27:38 +03:00
|
|
|
* element. This includes SVG links, because callers expect |node|
|
|
|
|
* to behave like an <a> element, which SVG links (XLink) don't.
|
2013-08-09 04:16:47 +04:00
|
|
|
*/
|
|
|
|
_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)
|
2015-11-12 20:27:38 +03:00
|
|
|
return [node.href, node, node.ownerDocument.nodePrincipal];
|
2013-08-09 04:16:47 +04:00
|
|
|
|
|
|
|
// If there is no linkNode, try simple XLink.
|
|
|
|
let href, baseURI;
|
|
|
|
node = event.target;
|
|
|
|
while (node && !href) {
|
2015-12-04 18:21:43 +03:00
|
|
|
if (node.nodeType == content.Node.ELEMENT_NODE &&
|
2015-12-02 17:10:39 +03:00
|
|
|
(node.localName == "a" ||
|
|
|
|
node.namespaceURI == "http://www.w3.org/1998/Math/MathML")) {
|
2013-08-09 04:16:47 +04:00
|
|
|
href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href");
|
2015-11-23 23:33:30 +03:00
|
|
|
if (href) {
|
2013-09-30 11:57:26 +04:00
|
|
|
baseURI = node.ownerDocument.baseURIObject;
|
2015-11-23 23:33:30 +03:00
|
|
|
break;
|
|
|
|
}
|
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.
|
2015-11-12 20:27:38 +03:00
|
|
|
return [href ? BrowserUtils.makeURI(href, null, baseURI).spec : null, null,
|
|
|
|
node && node.ownerDocument.nodePrincipal];
|
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.
|
2015-09-15 21:19:45 +03:00
|
|
|
var pluginContent = new PluginContent(global);
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2014-01-13 16:56:28 +04:00
|
|
|
addEventListener("DOMWebNotificationClicked", function(event) {
|
|
|
|
sendAsyncMessage("DOMWebNotificationClicked", {});
|
|
|
|
}, false);
|
2014-03-12 07:13:45 +04:00
|
|
|
|
2015-07-23 18:30:27 +03:00
|
|
|
addEventListener("DOMServiceWorkerFocusClient", function(event) {
|
|
|
|
sendAsyncMessage("DOMServiceWorkerFocusClient", {});
|
|
|
|
}, false);
|
|
|
|
|
2014-09-22 22:39:57 +04:00
|
|
|
ContentWebRTC.init();
|
2015-08-07 22:22:30 +03:00
|
|
|
addMessageListener("rtcpeer:Allow", ContentWebRTC);
|
|
|
|
addMessageListener("rtcpeer:Deny", ContentWebRTC);
|
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 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-09-15 21:19:45 +03:00
|
|
|
var PageMetadataMessenger = {
|
2015-03-17 22:49:07 +03:00
|
|
|
init() {
|
2015-03-06 01:43:05 +03:00
|
|
|
addMessageListener("PageMetadata:GetPageData", this);
|
2016-01-29 21:58:45 +03:00
|
|
|
addMessageListener("PageMetadata:GetMicroformats", 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": {
|
2016-01-29 21:58:45 +03:00
|
|
|
let target = message.objects.target;
|
|
|
|
let result = PageMetadata.getData(content.document, target);
|
2015-03-06 01:43:05 +03:00
|
|
|
sendAsyncMessage("PageMetadata:PageDataResult", result);
|
2014-11-06 04:26:36 +03:00
|
|
|
break;
|
2015-03-06 01:43:05 +03:00
|
|
|
}
|
2016-01-29 21:58:45 +03:00
|
|
|
case "PageMetadata:GetMicroformats": {
|
2015-03-12 00:19:30 +03:00
|
|
|
let target = message.objects.target;
|
2016-01-29 21:58:45 +03:00
|
|
|
let result = PageMetadata.getMicroformats(content.document, target);
|
|
|
|
sendAsyncMessage("PageMetadata:MicroformatsResult", 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 });
|
|
|
|
});
|
2015-03-21 03:13:57 +03:00
|
|
|
|
|
|
|
addMessageListener("ContextMenu:ReloadFrame", (message) => {
|
|
|
|
message.objects.target.ownerDocument.location.reload();
|
|
|
|
});
|
2015-03-21 17:15:26 +03:00
|
|
|
|
|
|
|
addMessageListener("ContextMenu:ReloadImage", (message) => {
|
|
|
|
let image = message.objects.target;
|
|
|
|
if (image instanceof Ci.nsIImageLoadingContent)
|
|
|
|
image.forceReload();
|
|
|
|
});
|
2015-03-05 00:27:35 +03:00
|
|
|
|
|
|
|
addMessageListener("ContextMenu:BookmarkFrame", (message) => {
|
|
|
|
let frame = message.objects.target.ownerDocument;
|
|
|
|
sendAsyncMessage("ContextMenu:BookmarkFrame:Result",
|
|
|
|
{ title: frame.title,
|
|
|
|
description: PlacesUIUtils.getDescriptionFromDocument(frame) });
|
|
|
|
});
|
2015-05-25 17:41:34 +03:00
|
|
|
|
|
|
|
addMessageListener("ContextMenu:SearchFieldBookmarkData", (message) => {
|
|
|
|
let node = message.objects.target;
|
|
|
|
|
|
|
|
let charset = node.ownerDocument.characterSet;
|
|
|
|
|
|
|
|
let formBaseURI = BrowserUtils.makeURI(node.form.baseURI,
|
|
|
|
charset);
|
|
|
|
|
|
|
|
let formURI = BrowserUtils.makeURI(node.form.getAttribute("action"),
|
|
|
|
charset,
|
|
|
|
formBaseURI);
|
|
|
|
|
|
|
|
let spec = formURI.spec;
|
|
|
|
|
|
|
|
let isURLEncoded =
|
|
|
|
(node.form.method.toUpperCase() == "POST"
|
|
|
|
&& (node.form.enctype == "application/x-www-form-urlencoded" ||
|
|
|
|
node.form.enctype == ""));
|
|
|
|
|
|
|
|
let title = node.ownerDocument.title;
|
|
|
|
let description = PlacesUIUtils.getDescriptionFromDocument(node.ownerDocument);
|
|
|
|
|
|
|
|
let formData = [];
|
|
|
|
|
|
|
|
function escapeNameValuePair(aName, aValue, aIsFormUrlEncoded) {
|
|
|
|
if (aIsFormUrlEncoded)
|
|
|
|
return escape(aName + "=" + aValue);
|
|
|
|
else
|
|
|
|
return escape(aName) + "=" + escape(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let el of node.form.elements) {
|
|
|
|
if (!el.type) // happens with fieldsets
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (el == node) {
|
|
|
|
formData.push((isURLEncoded) ? escapeNameValuePair(el.name, "%s", true) :
|
|
|
|
// Don't escape "%s", just append
|
|
|
|
escapeNameValuePair(el.name, "", false) + "%s");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let type = el.type.toLowerCase();
|
|
|
|
|
|
|
|
if (((el instanceof content.HTMLInputElement && el.mozIsTextField(true)) ||
|
|
|
|
type == "hidden" || type == "textarea") ||
|
|
|
|
((type == "checkbox" || type == "radio") && el.checked)) {
|
|
|
|
formData.push(escapeNameValuePair(el.name, el.value, isURLEncoded));
|
|
|
|
} else if (el instanceof content.HTMLSelectElement && el.selectedIndex >= 0) {
|
|
|
|
for (let j=0; j < el.options.length; j++) {
|
|
|
|
if (el.options[j].selected)
|
|
|
|
formData.push(escapeNameValuePair(el.name, el.options[j].value,
|
|
|
|
isURLEncoded));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let postData;
|
|
|
|
|
|
|
|
if (isURLEncoded)
|
|
|
|
postData = formData.join("&");
|
|
|
|
else {
|
|
|
|
let separator = spec.includes("?") ? "&" : "?";
|
|
|
|
spec += separator + formData.join("&");
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAsyncMessage("ContextMenu:SearchFieldBookmarkData:Result",
|
|
|
|
{ spec, title, description, postData, charset });
|
|
|
|
});
|
2015-06-16 09:36:38 +03:00
|
|
|
|
2015-09-26 04:14:43 +03:00
|
|
|
addMessageListener("Bookmarks:GetPageDetails", (message) => {
|
|
|
|
let doc = content.document;
|
|
|
|
let isErrorPage = /^about:(neterror|certerror|blocked)/.test(doc.documentURI);
|
|
|
|
sendAsyncMessage("Bookmarks:GetPageDetails:Result",
|
|
|
|
{ isErrorPage: isErrorPage,
|
|
|
|
description: PlacesUIUtils.getDescriptionFromDocument(doc) });
|
|
|
|
});
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var LightWeightThemeWebInstallListener = {
|
2015-07-14 21:42:02 +03:00
|
|
|
_previewWindow: null,
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
addEventListener("InstallBrowserTheme", this, false, true);
|
|
|
|
addEventListener("PreviewBrowserTheme", this, false, true);
|
|
|
|
addEventListener("ResetBrowserThemePreview", this, false, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function (event) {
|
|
|
|
switch (event.type) {
|
|
|
|
case "InstallBrowserTheme": {
|
|
|
|
sendAsyncMessage("LightWeightThemeWebInstaller:Install", {
|
|
|
|
baseURI: event.target.baseURI,
|
|
|
|
themeData: event.target.getAttribute("data-browsertheme"),
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "PreviewBrowserTheme": {
|
|
|
|
sendAsyncMessage("LightWeightThemeWebInstaller:Preview", {
|
|
|
|
baseURI: event.target.baseURI,
|
|
|
|
themeData: event.target.getAttribute("data-browsertheme"),
|
|
|
|
});
|
|
|
|
this._previewWindow = event.target.ownerDocument.defaultView;
|
|
|
|
this._previewWindow.addEventListener("pagehide", this, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "pagehide": {
|
|
|
|
sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview");
|
|
|
|
this._resetPreviewWindow();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "ResetBrowserThemePreview": {
|
|
|
|
if (this._previewWindow) {
|
|
|
|
sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview",
|
|
|
|
{baseURI: event.target.baseURI});
|
|
|
|
this._resetPreviewWindow();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_resetPreviewWindow: function () {
|
|
|
|
this._previewWindow.removeEventListener("pagehide", this, true);
|
|
|
|
this._previewWindow = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LightWeightThemeWebInstallListener.init();
|
|
|
|
|
2015-06-16 09:36:38 +03:00
|
|
|
function disableSetDesktopBackground(aTarget) {
|
|
|
|
// Disable the Set as Desktop Background menu item if we're still trying
|
|
|
|
// to load the image or the load failed.
|
|
|
|
if (!(aTarget instanceof Ci.nsIImageLoadingContent))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (("complete" in aTarget) && !aTarget.complete)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (aTarget.currentURI.schemeIs("javascript"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
let request = aTarget.QueryInterface(Ci.nsIImageLoadingContent)
|
|
|
|
.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
|
|
|
if (!request)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
addMessageListener("ContextMenu:SetAsDesktopBackground", (message) => {
|
|
|
|
let target = message.objects.target;
|
|
|
|
|
|
|
|
// Paranoia: check disableSetDesktopBackground again, in case the
|
|
|
|
// image changed since the context menu was initiated.
|
|
|
|
let disable = disableSetDesktopBackground(target);
|
|
|
|
|
|
|
|
if (!disable) {
|
|
|
|
try {
|
|
|
|
BrowserUtils.urlSecurityCheck(target.currentURI.spec, target.ownerDocument.nodePrincipal);
|
|
|
|
let canvas = content.document.createElement("canvas");
|
|
|
|
canvas.width = target.naturalWidth;
|
|
|
|
canvas.height = target.naturalHeight;
|
|
|
|
let ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawImage(target, 0, 0);
|
|
|
|
let dataUrl = canvas.toDataURL();
|
|
|
|
sendAsyncMessage("ContextMenu:SetAsDesktopBackground:Result",
|
|
|
|
{ dataUrl });
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
disable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disable)
|
|
|
|
sendAsyncMessage("ContextMenu:SetAsDesktopBackground:Result", { disable });
|
|
|
|
});
|
2015-07-09 00:18:38 +03:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var PageInfoListener = {
|
2015-07-09 00:18:38 +03:00
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
init: function() {
|
|
|
|
addMessageListener("PageInfo:getData", this);
|
2015-07-09 00:18:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(message) {
|
2015-08-13 10:37:02 +03:00
|
|
|
let strings = message.data.strings;
|
|
|
|
let window;
|
|
|
|
let document;
|
2015-07-09 00:18:38 +03:00
|
|
|
|
|
|
|
let frameOuterWindowID = message.data.frameOuterWindowID;
|
|
|
|
|
|
|
|
// If inside frame then get the frame's window and document.
|
|
|
|
if (frameOuterWindowID) {
|
2015-08-13 10:37:02 +03:00
|
|
|
window = Services.wm.getOuterWindowWithId(frameOuterWindowID);
|
|
|
|
document = window.document;
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-08-13 10:37:02 +03:00
|
|
|
window = content.window;
|
|
|
|
document = content.document;
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
|
2016-01-20 03:21:49 +03:00
|
|
|
let imageElement = message.objects.imageElement;
|
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
let pageInfoData = {metaViewRows: this.getMetaInfo(document),
|
|
|
|
docInfo: this.getDocumentInfo(document),
|
|
|
|
feeds: this.getFeedsInfo(document, strings),
|
2016-01-20 03:21:49 +03:00
|
|
|
windowInfo: this.getWindowInfo(window),
|
|
|
|
imageInfo: this.getImageInfo(imageElement)};
|
|
|
|
|
2015-07-09 00:18:38 +03:00
|
|
|
sendAsyncMessage("PageInfo:data", pageInfoData);
|
|
|
|
|
|
|
|
// Separate step so page info dialog isn't blank while waiting for this to finish.
|
2015-08-13 12:12:02 +03:00
|
|
|
this.getMediaInfo(document, window, strings);
|
2015-07-09 00:18:38 +03:00
|
|
|
},
|
|
|
|
|
2016-01-20 03:21:49 +03:00
|
|
|
getImageInfo: function(imageElement) {
|
|
|
|
let imageInfo = null;
|
|
|
|
if (imageElement) {
|
|
|
|
imageInfo = {
|
|
|
|
currentSrc: imageElement.currentSrc,
|
|
|
|
width: imageElement.width,
|
|
|
|
height: imageElement.height,
|
|
|
|
imageText: imageElement.title || imageElement.alt
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return imageInfo;
|
|
|
|
},
|
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
getMetaInfo: function(document) {
|
2015-07-09 00:18:38 +03:00
|
|
|
let metaViewRows = [];
|
|
|
|
|
|
|
|
// Get the meta tags from the page.
|
2015-08-13 10:37:02 +03:00
|
|
|
let metaNodes = document.getElementsByTagName("meta");
|
2015-07-09 00:18:38 +03:00
|
|
|
|
|
|
|
for (let metaNode of metaNodes) {
|
|
|
|
metaViewRows.push([metaNode.name || metaNode.httpEquiv || metaNode.getAttribute("property"),
|
|
|
|
metaNode.content]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return metaViewRows;
|
|
|
|
},
|
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
getWindowInfo: function(window) {
|
2015-07-09 00:18:38 +03:00
|
|
|
let windowInfo = {};
|
2015-08-13 10:37:02 +03:00
|
|
|
windowInfo.isTopWindow = window == window.top;
|
2015-07-09 00:18:38 +03:00
|
|
|
|
|
|
|
let hostName = null;
|
|
|
|
try {
|
2015-08-13 10:37:02 +03:00
|
|
|
hostName = window.location.host;
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
catch (exception) { }
|
|
|
|
|
|
|
|
windowInfo.hostName = hostName;
|
|
|
|
return windowInfo;
|
|
|
|
},
|
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
getDocumentInfo: function(document) {
|
2015-07-09 00:18:38 +03:00
|
|
|
let docInfo = {};
|
2015-08-13 10:37:02 +03:00
|
|
|
docInfo.title = document.title;
|
|
|
|
docInfo.location = document.location.toString();
|
|
|
|
docInfo.referrer = document.referrer;
|
|
|
|
docInfo.compatMode = document.compatMode;
|
|
|
|
docInfo.contentType = document.contentType;
|
|
|
|
docInfo.characterSet = document.characterSet;
|
|
|
|
docInfo.lastModified = document.lastModified;
|
2015-07-09 00:18:38 +03:00
|
|
|
|
|
|
|
let documentURIObject = {};
|
2015-08-13 10:37:02 +03:00
|
|
|
documentURIObject.spec = document.documentURIObject.spec;
|
|
|
|
documentURIObject.originCharset = document.documentURIObject.originCharset;
|
2015-07-09 00:18:38 +03:00
|
|
|
docInfo.documentURIObject = documentURIObject;
|
|
|
|
|
|
|
|
docInfo.isContentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate(content);
|
|
|
|
|
|
|
|
return docInfo;
|
|
|
|
},
|
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
getFeedsInfo: function(document, strings) {
|
2015-07-09 00:18:38 +03:00
|
|
|
let feeds = [];
|
|
|
|
// Get the feeds from the page.
|
2015-08-13 10:37:02 +03:00
|
|
|
let linkNodes = document.getElementsByTagName("link");
|
2015-07-09 00:18:38 +03:00
|
|
|
let length = linkNodes.length;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
let link = linkNodes[i];
|
|
|
|
if (!link.href) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let rel = link.rel && link.rel.toLowerCase();
|
|
|
|
let rels = {};
|
|
|
|
|
|
|
|
if (rel) {
|
2015-10-18 19:27:39 +03:00
|
|
|
for (let relVal of rel.split(/\s+/)) {
|
2015-07-09 00:18:38 +03:00
|
|
|
rels[relVal] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rels.feed || (link.type && rels.alternate && !rels.stylesheet)) {
|
2015-08-13 10:37:02 +03:00
|
|
|
let type = Feeds.isValidFeed(link, document.nodePrincipal, "feed" in rels);
|
2015-07-09 00:18:38 +03:00
|
|
|
if (type) {
|
2015-08-13 10:37:02 +03:00
|
|
|
type = strings[type] || strings["application/rss+xml"];
|
2015-07-09 00:18:38 +03:00
|
|
|
feeds.push([link.title, type, link.href]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return feeds;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Only called once to get the media tab's media elements from the content page.
|
2015-08-13 09:57:17 +03:00
|
|
|
getMediaInfo: function(document, window, strings)
|
2015-07-09 00:18:38 +03:00
|
|
|
{
|
2015-08-13 09:57:17 +03:00
|
|
|
let frameList = this.goThroughFrames(document, window);
|
2015-08-13 12:12:02 +03:00
|
|
|
Task.spawn(() => this.processFrames(document, frameList, strings));
|
2015-07-09 00:18:38 +03:00
|
|
|
},
|
|
|
|
|
2015-08-13 09:57:17 +03:00
|
|
|
goThroughFrames: function(document, window)
|
2015-07-09 00:18:38 +03:00
|
|
|
{
|
2015-08-13 09:57:17 +03:00
|
|
|
let frameList = [document];
|
|
|
|
if (window && window.frames.length > 0) {
|
|
|
|
let num = window.frames.length;
|
2015-07-09 00:18:38 +03:00
|
|
|
for (let i = 0; i < num; i++) {
|
2015-08-13 10:37:02 +03:00
|
|
|
// Recurse through the frames.
|
2015-08-13 09:57:17 +03:00
|
|
|
frameList.concat(this.goThroughFrames(window.frames[i].document,
|
|
|
|
window.frames[i]));
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-13 09:57:17 +03:00
|
|
|
return frameList;
|
2015-07-09 00:18:38 +03:00
|
|
|
},
|
|
|
|
|
2015-08-13 12:12:02 +03:00
|
|
|
processFrames: function*(document, frameList, strings)
|
2015-07-09 00:18:38 +03:00
|
|
|
{
|
2015-08-13 12:12:02 +03:00
|
|
|
let nodeCount = 0;
|
2015-08-13 09:57:17 +03:00
|
|
|
for (let doc of frameList) {
|
|
|
|
let iterator = doc.createTreeWalker(doc, content.NodeFilter.SHOW_ELEMENT);
|
2015-07-09 00:18:38 +03:00
|
|
|
|
2015-08-13 12:12:02 +03:00
|
|
|
// Goes through all the elements on the doc. imageViewRows takes only the media elements.
|
2015-08-13 09:57:17 +03:00
|
|
|
while (iterator.nextNode()) {
|
|
|
|
let mediaNode = this.getMediaNode(document, strings, iterator.currentNode);
|
|
|
|
|
|
|
|
if (mediaNode) {
|
2015-08-13 12:12:02 +03:00
|
|
|
sendAsyncMessage("PageInfo:mediaData",
|
|
|
|
{imageViewRow: mediaNode, isComplete: false});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++nodeCount % 500 == 0) {
|
|
|
|
// setTimeout every 500 elements so we don't keep blocking the content process.
|
|
|
|
yield new Promise(resolve => setTimeout(resolve, 10));
|
2015-08-13 09:57:17 +03:00
|
|
|
}
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-13 12:12:02 +03:00
|
|
|
// Send that page info media fetching has finished.
|
|
|
|
sendAsyncMessage("PageInfo:mediaData", {isComplete: true});
|
2015-07-09 00:18:38 +03:00
|
|
|
},
|
|
|
|
|
2015-08-13 09:57:17 +03:00
|
|
|
getMediaNode: function(document, strings, elem)
|
2015-07-09 00:18:38 +03:00
|
|
|
{
|
|
|
|
// Check for images defined in CSS (e.g. background, borders), any node may have multiple.
|
|
|
|
let computedStyle = elem.ownerDocument.defaultView.getComputedStyle(elem, "");
|
2015-08-13 09:57:17 +03:00
|
|
|
let mediaElement = null;
|
2015-07-09 00:18:38 +03:00
|
|
|
|
|
|
|
let addImage = (url, type, alt, elem, isBg) => {
|
2015-08-13 09:57:17 +03:00
|
|
|
let element = this.serializeElementInfo(document, url, type, alt, elem, isBg);
|
|
|
|
mediaElement = [url, type, alt, element, isBg];
|
2015-07-09 00:18:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (computedStyle) {
|
|
|
|
let addImgFunc = (label, val) => {
|
|
|
|
if (val.primitiveType == content.CSSPrimitiveValue.CSS_URI) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(val.getStringValue(), label, strings.notSet, elem, true);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
else if (val.primitiveType == content.CSSPrimitiveValue.CSS_STRING) {
|
|
|
|
// This is for -moz-image-rect.
|
|
|
|
// TODO: Reimplement once bug 714757 is fixed.
|
|
|
|
let strVal = val.getStringValue();
|
|
|
|
if (strVal.search(/^.*url\(\"?/) > -1) {
|
|
|
|
let url = strVal.replace(/^.*url\(\"?/,"").replace(/\"?\).*$/,"");
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(url, label, strings.notSet, elem, true);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (val.cssValueType == content.CSSValue.CSS_VALUE_LIST) {
|
|
|
|
// Recursively resolve multiple nested CSS value lists.
|
|
|
|
for (let i = 0; i < val.length; i++) {
|
|
|
|
addImgFunc(label, val.item(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-13 09:57:17 +03:00
|
|
|
addImgFunc(strings.mediaBGImg, computedStyle.getPropertyCSSValue("background-image"));
|
|
|
|
addImgFunc(strings.mediaBorderImg, computedStyle.getPropertyCSSValue("border-image-source"));
|
|
|
|
addImgFunc(strings.mediaListImg, computedStyle.getPropertyCSSValue("list-style-image"));
|
|
|
|
addImgFunc(strings.mediaCursor, computedStyle.getPropertyCSSValue("cursor"));
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// One swi^H^H^Hif-else to rule them all.
|
|
|
|
if (elem instanceof content.HTMLImageElement) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.src, strings.mediaImg,
|
|
|
|
(elem.hasAttribute("alt")) ? elem.alt : strings.notSet, elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
else if (elem instanceof content.SVGImageElement) {
|
|
|
|
try {
|
|
|
|
// Note: makeURLAbsolute will throw if either the baseURI is not a valid URI
|
|
|
|
// or the URI formed from the baseURI and the URL is not a valid URI.
|
|
|
|
let href = makeURLAbsolute(elem.baseURI, elem.href.baseVal);
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(href, strings.mediaImg, "", elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
} catch (e) { }
|
|
|
|
}
|
|
|
|
else if (elem instanceof content.HTMLVideoElement) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.currentSrc, strings.mediaVideo, "", elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
else if (elem instanceof content.HTMLAudioElement) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.currentSrc, strings.mediaAudio, "", elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
else if (elem instanceof content.HTMLLinkElement) {
|
|
|
|
if (elem.rel && /\bicon\b/i.test(elem.rel)) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.href, strings.mediaLink, "", elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (elem instanceof content.HTMLInputElement || elem instanceof content.HTMLButtonElement) {
|
|
|
|
if (elem.type.toLowerCase() == "image") {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.src, strings.mediaInput,
|
|
|
|
(elem.hasAttribute("alt")) ? elem.alt : strings.notSet, elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (elem instanceof content.HTMLObjectElement) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.data, strings.mediaObject, this.getValueText(elem), elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
else if (elem instanceof content.HTMLEmbedElement) {
|
2015-08-13 09:57:17 +03:00
|
|
|
addImage(elem.src, strings.mediaEmbed, "", elem, false);
|
2015-07-09 00:18:38 +03:00
|
|
|
}
|
|
|
|
|
2015-08-13 09:57:17 +03:00
|
|
|
return mediaElement;
|
2015-07-09 00:18:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up a JSON element object with all the instanceOf and other infomation that
|
|
|
|
* makePreview in pageInfo.js uses to figure out how to display the preview.
|
|
|
|
*/
|
|
|
|
|
2015-08-13 09:57:17 +03:00
|
|
|
serializeElementInfo: function(document, url, type, alt, item, isBG)
|
2015-07-09 00:18:38 +03:00
|
|
|
{
|
|
|
|
let result = {};
|
|
|
|
|
|
|
|
let imageText;
|
|
|
|
if (!isBG &&
|
|
|
|
!(item instanceof content.SVGImageElement) &&
|
2015-08-13 09:57:17 +03:00
|
|
|
!(document instanceof content.ImageDocument)) {
|
2015-07-09 00:18:38 +03:00
|
|
|
imageText = item.title || item.alt;
|
|
|
|
|
|
|
|
if (!imageText && !(item instanceof content.HTMLImageElement)) {
|
|
|
|
imageText = this.getValueText(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.imageText = imageText;
|
|
|
|
result.longDesc = item.longDesc;
|
|
|
|
result.numFrames = 1;
|
|
|
|
|
|
|
|
if (item instanceof content.HTMLObjectElement ||
|
|
|
|
item instanceof content.HTMLEmbedElement ||
|
|
|
|
item instanceof content.HTMLLinkElement) {
|
|
|
|
result.mimeType = item.type;
|
|
|
|
}
|
|
|
|
|
2015-10-05 22:22:38 +03:00
|
|
|
if (!result.mimeType && !isBG && item instanceof Ci.nsIImageLoadingContent) {
|
2015-07-09 00:18:38 +03:00
|
|
|
// Interface for image loading content.
|
2015-10-05 22:22:38 +03:00
|
|
|
let imageRequest = item.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
2015-07-09 00:18:38 +03:00
|
|
|
if (imageRequest) {
|
|
|
|
result.mimeType = imageRequest.mimeType;
|
|
|
|
let image = !(imageRequest.imageStatus & imageRequest.STATUS_ERROR) && imageRequest.image;
|
|
|
|
if (image) {
|
|
|
|
result.numFrames = image.numFrames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 10:37:02 +03:00
|
|
|
// If we have a data url, get the MIME type from the url.
|
2015-07-09 00:18:38 +03:00
|
|
|
if (!result.mimeType && url.startsWith("data:")) {
|
|
|
|
let dataMimeType = /^data:(image\/[^;,]+)/i.exec(url);
|
|
|
|
if (dataMimeType)
|
|
|
|
result.mimeType = dataMimeType[1].toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
result.HTMLLinkElement = item instanceof content.HTMLLinkElement;
|
|
|
|
result.HTMLInputElement = item instanceof content.HTMLInputElement;
|
|
|
|
result.HTMLImageElement = item instanceof content.HTMLImageElement;
|
|
|
|
result.HTMLObjectElement = item instanceof content.HTMLObjectElement;
|
|
|
|
result.SVGImageElement = item instanceof content.SVGImageElement;
|
|
|
|
result.HTMLVideoElement = item instanceof content.HTMLVideoElement;
|
|
|
|
result.HTMLAudioElement = item instanceof content.HTMLAudioElement;
|
|
|
|
|
2015-10-05 22:22:38 +03:00
|
|
|
if (isBG) {
|
|
|
|
// Items that are showing this image as a background
|
|
|
|
// image might not necessarily have a width or height,
|
|
|
|
// so we'll dynamically generate an image and send up the
|
|
|
|
// natural dimensions.
|
|
|
|
let img = content.document.createElement("img");
|
|
|
|
img.src = url;
|
|
|
|
result.naturalWidth = img.naturalWidth;
|
|
|
|
result.naturalHeight = img.naturalHeight;
|
|
|
|
} else {
|
|
|
|
// Otherwise, we can use the current width and height
|
|
|
|
// of the image.
|
2015-07-09 00:18:38 +03:00
|
|
|
result.width = item.width;
|
|
|
|
result.height = item.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item instanceof content.SVGImageElement) {
|
|
|
|
result.SVGImageElementWidth = item.width.baseVal.value;
|
|
|
|
result.SVGImageElementHeight = item.height.baseVal.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.baseURI = item.baseURI;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
//******** Other Misc Stuff
|
|
|
|
// Modified from the Links Panel v2.3, http://segment7.net/mozilla/links/links.html
|
|
|
|
// parse a node to extract the contents of the node
|
|
|
|
getValueText: function(node)
|
|
|
|
{
|
|
|
|
|
|
|
|
let valueText = "";
|
|
|
|
|
|
|
|
// Form input elements don't generally contain information that is useful to our callers, so return nothing.
|
|
|
|
if (node instanceof content.HTMLInputElement ||
|
|
|
|
node instanceof content.HTMLSelectElement ||
|
|
|
|
node instanceof content.HTMLTextAreaElement) {
|
|
|
|
return valueText;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise recurse for each child.
|
|
|
|
let length = node.childNodes.length;
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
let childNode = node.childNodes[i];
|
|
|
|
let nodeType = childNode.nodeType;
|
|
|
|
|
|
|
|
// Text nodes are where the goods are.
|
|
|
|
if (nodeType == content.Node.TEXT_NODE) {
|
|
|
|
valueText += " " + childNode.nodeValue;
|
|
|
|
}
|
|
|
|
// And elements can have more text inside them.
|
|
|
|
else if (nodeType == content.Node.ELEMENT_NODE) {
|
|
|
|
// Images are special, we want to capture the alt text as if the image weren't there.
|
|
|
|
if (childNode instanceof content.HTMLImageElement) {
|
|
|
|
valueText += " " + this.getAltText(childNode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
valueText += " " + this.getValueText(childNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.stripWS(valueText);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Copied from the Links Panel v2.3, http://segment7.net/mozilla/links/links.html.
|
|
|
|
// Traverse the tree in search of an img or area element and grab its alt tag.
|
|
|
|
getAltText: function(node)
|
|
|
|
{
|
|
|
|
let altText = "";
|
|
|
|
|
|
|
|
if (node.alt) {
|
|
|
|
return node.alt;
|
|
|
|
}
|
|
|
|
let length = node.childNodes.length;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
if ((altText = this.getAltText(node.childNodes[i]) != undefined)) { // stupid js warning...
|
|
|
|
return altText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
|
|
|
|
// Copied from the Links Panel v2.3, http://segment7.net/mozilla/links/links.html.
|
|
|
|
// Strip leading and trailing whitespace, and replace multiple consecutive whitespace characters with a single space.
|
|
|
|
stripWS: function(text)
|
|
|
|
{
|
|
|
|
let middleRE = /\s+/g;
|
|
|
|
let endRE = /(^\s+)|(\s+$)/g;
|
|
|
|
|
|
|
|
text = text.replace(middleRE, " ");
|
|
|
|
return text.replace(endRE, "");
|
|
|
|
}
|
|
|
|
};
|
2015-10-26 23:03:26 +03:00
|
|
|
PageInfoListener.init();
|