summaryrefslogtreecommitdiffstats
path: root/application/basilisk/modules/ContentLinkHandler.jsm
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
commitfc61780b35af913801d72086456f493f63197da6 (patch)
treef85891288a7bd988da9f0f15ae64e5c63f00d493 /application/basilisk/modules/ContentLinkHandler.jsm
parent69f7f9e5f1475891ce11cc4f431692f965b0cd30 (diff)
parent50d3e596bbe89c95615f96eb71f6bc5be737a1db (diff)
downloadUXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.gz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.lz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.xz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.zip
Merge commit '50d3e596bbe89c95615f96eb71f6bc5be737a1db' into Basilisk-releasev2018.07.18
# Conflicts: # browser/app/profile/firefox.js # browser/components/preferences/jar.mn
Diffstat (limited to 'application/basilisk/modules/ContentLinkHandler.jsm')
-rw-r--r--application/basilisk/modules/ContentLinkHandler.jsm147
1 files changed, 147 insertions, 0 deletions
diff --git a/application/basilisk/modules/ContentLinkHandler.jsm b/application/basilisk/modules/ContentLinkHandler.jsm
new file mode 100644
index 000000000..443cae2da
--- /dev/null
+++ b/application/basilisk/modules/ContentLinkHandler.jsm
@@ -0,0 +1,147 @@
+/* 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/. */
+
+"use strict";
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+
+this.EXPORTED_SYMBOLS = [ "ContentLinkHandler" ];
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
+ "resource:///modules/Feeds.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
+ "resource://gre/modules/BrowserUtils.jsm");
+
+const SIZES_TELEMETRY_ENUM = {
+ NO_SIZES: 0,
+ ANY: 1,
+ DIMENSION: 2,
+ INVALID: 3,
+};
+
+this.ContentLinkHandler = {
+ init: function(chromeGlobal) {
+ chromeGlobal.addEventListener("DOMLinkAdded", (event) => {
+ this.onLinkEvent(event, chromeGlobal);
+ }, false);
+ chromeGlobal.addEventListener("DOMLinkChanged", (event) => {
+ this.onLinkEvent(event, chromeGlobal);
+ }, false);
+ },
+
+ onLinkEvent: function(event, chromeGlobal) {
+ var link = event.originalTarget;
+ var rel = link.rel && link.rel.toLowerCase();
+ if (!link || !link.ownerDocument || !rel || !link.href)
+ return;
+
+ // Ignore sub-frames (bugs 305472, 479408).
+ let window = link.ownerGlobal;
+ if (window != window.top)
+ return;
+
+ var feedAdded = false;
+ var iconAdded = false;
+ var searchAdded = false;
+ var rels = {};
+ for (let relString of rel.split(/\s+/))
+ rels[relString] = true;
+
+ for (let relVal in rels) {
+ switch (relVal) {
+ case "feed":
+ case "alternate":
+ if (!feedAdded && event.type == "DOMLinkAdded") {
+ if (!rels.feed && rels.alternate && rels.stylesheet)
+ break;
+
+ if (Feeds.isValidFeed(link, link.ownerDocument.nodePrincipal, "feed" in rels)) {
+ chromeGlobal.sendAsyncMessage("Link:AddFeed",
+ {type: link.type,
+ href: link.href,
+ title: link.title});
+ feedAdded = true;
+ }
+ }
+ break;
+ case "icon":
+ if (iconAdded || !Services.prefs.getBoolPref("browser.chrome.site_icons"))
+ break;
+
+ var uri = this.getLinkIconURI(link);
+ if (!uri)
+ break;
+
+ // Telemetry probes for measuring the sizes attribute
+ // usage and available dimensions.
+ let sizeHistogramTypes = Services.telemetry.
+ getHistogramById("LINK_ICON_SIZES_ATTR_USAGE");
+ let sizeHistogramDimension = Services.telemetry.
+ getHistogramById("LINK_ICON_SIZES_ATTR_DIMENSION");
+ let sizesType;
+ if (link.sizes.length) {
+ for (let size of link.sizes) {
+ if (size.toLowerCase() == "any") {
+ sizesType = SIZES_TELEMETRY_ENUM.ANY;
+ break;
+ } else {
+ let re = /^([1-9][0-9]*)x[1-9][0-9]*$/i;
+ let values = re.exec(size);
+ if (values && values.length > 1) {
+ sizesType = SIZES_TELEMETRY_ENUM.DIMENSION;
+ sizeHistogramDimension.add(parseInt(values[1]));
+ } else {
+ sizesType = SIZES_TELEMETRY_ENUM.INVALID;
+ break;
+ }
+ }
+ }
+ } else {
+ sizesType = SIZES_TELEMETRY_ENUM.NO_SIZES;
+ }
+ sizeHistogramTypes.add(sizesType);
+
+ chromeGlobal.sendAsyncMessage(
+ "Link:SetIcon",
+ {url: uri.spec, loadingPrincipal: link.ownerDocument.nodePrincipal});
+ iconAdded = true;
+ break;
+ case "search":
+ if (!searchAdded && event.type == "DOMLinkAdded") {
+ var type = link.type && link.type.toLowerCase();
+ type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
+
+ let re = /^(?:https?|ftp):/i;
+ if (type == "application/opensearchdescription+xml" && link.title &&
+ re.test(link.href))
+ {
+ let engine = { title: link.title, href: link.href };
+ chromeGlobal.sendAsyncMessage("Link:AddSearch",
+ {engine: engine,
+ url: link.ownerDocument.documentURI});
+ searchAdded = true;
+ }
+ }
+ break;
+ }
+ }
+ },
+
+ getLinkIconURI: function(aLink) {
+ let targetDoc = aLink.ownerDocument;
+ var uri = BrowserUtils.makeURI(aLink.href, targetDoc.characterSet);
+ try {
+ uri.userPass = "";
+ } catch (e) {
+ // some URIs are immutable
+ }
+ return uri;
+ },
+};