[Pkg-mozext-commits] [adblock-plus] 52/87: Issue 3851 - Implement subscribe link handling via process scripts
David Prévot
taffit at moszumanska.debian.org
Sat Apr 30 17:59:07 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 335413cec097bc71c85a50c5f777d85db66a1e07
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon Apr 18 17:36:19 2016 +0200
Issue 3851 - Implement subscribe link handling via process scripts
---
chrome/content/subscribeLinkHandler.js | 106 -----------------------------
lib/child/main.js | 1 +
lib/child/subscribeLinks.js | 118 +++++++++++++++++++++++++++++++++
lib/ui.js | 22 ++----
4 files changed, 124 insertions(+), 123 deletions(-)
diff --git a/chrome/content/subscribeLinkHandler.js b/chrome/content/subscribeLinkHandler.js
deleted file mode 100644
index ca99b6a..0000000
--- a/chrome/content/subscribeLinkHandler.js
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-2016 Eyeo GmbH
- *
- * Adblock Plus is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * Adblock Plus is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
- */
-
-(function()
-{
- addEventListener("click", onClick, false);
- addMessageListener("AdblockPlus:Shutdown", onShutdown);
-
- function onShutdown(message)
- {
- if (message.data == Components.stack.filename)
- {
- removeEventListener("click", onClick, false);
- removeMessageListener("AdblockPlus:Shutdown", onShutdown);
- }
- }
-
- function onClick(event)
- {
- // Ignore right-clicks
- if (event.button == 2)
- return;
-
- // Search the link associated with the click
- let link = event.target;
- while (!(link instanceof content.HTMLAnchorElement))
- {
- link = link.parentNode;
-
- if (!link)
- return;
- }
-
- let queryString = null;
- if (link.protocol == "http:" || link.protocol == "https:")
- {
- if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
- queryString = link.search.substr(1);
- }
- else
- {
- // Firefox doesn't populate the "search" property for links with
- // non-standard URL schemes so we need to extract the query string
- // manually
- let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
- if (match)
- queryString = match[1];
- }
-
- if (!queryString)
- return;
-
- // This is our link - make sure the browser doesn't handle it
- event.preventDefault();
- event.stopPropagation();
-
- // Decode URL parameters
- let title = null;
- let url = null;
- let mainSubscriptionTitle = null;
- let mainSubscriptionURL = null;
- for (let param of queryString.split("&"))
- {
- let parts = param.split("=", 2);
- if (parts.length != 2 || !/\S/.test(parts[1]))
- continue;
- switch (parts[0])
- {
- case "title":
- title = decodeURIComponent(parts[1]);
- break;
- case "location":
- url = decodeURIComponent(parts[1]);
- break;
- case "requiresTitle":
- mainSubscriptionTitle = decodeURIComponent(parts[1]);
- break;
- case "requiresLocation":
- mainSubscriptionURL = decodeURIComponent(parts[1]);
- break;
- }
- }
-
- sendAsyncMessage("AdblockPlus:SubscribeLink", {
- title: title,
- url: url,
- mainSubscriptionTitle: mainSubscriptionTitle,
- mainSubscriptionURL: mainSubscriptionURL
- });
- }
-})();
-
diff --git a/lib/child/main.js b/lib/child/main.js
index f971968..3fa4d93 100644
--- a/lib/child/main.js
+++ b/lib/child/main.js
@@ -20,3 +20,4 @@ require("child/contentPolicy");
require("child/contextMenu");
require("child/dataCollector");
require("child/cssProperties");
+require("child/subscribeLinks");
diff --git a/lib/child/subscribeLinks.js b/lib/child/subscribeLinks.js
new file mode 100644
index 0000000..df1662e
--- /dev/null
+++ b/lib/child/subscribeLinks.js
@@ -0,0 +1,118 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+let {port} = require("messaging");
+
+Services.obs.addObserver(onContentWindow, "content-document-global-created",
+ false);
+onShutdown.add(() =>
+{
+ Services.obs.removeObserver(onContentWindow,
+ "content-document-global-created");
+});
+
+function onContentWindow(subject, topic, data)
+{
+ if (subject instanceof Ci.nsIDOMWindow && subject.top == subject)
+ {
+ let eventTarget = subject.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShell)
+ .chromeEventHandler;
+ if (eventTarget)
+ eventTarget.addEventListener("click", onClick, true);
+ }
+}
+
+function onClick(event)
+{
+ if (onShutdown.done)
+ return;
+
+ // Ignore right-clicks
+ if (event.button == 2)
+ return;
+
+ // Search the link associated with the click
+ let link = event.target;
+ while (!(link instanceof Ci.nsIDOMHTMLAnchorElement))
+ {
+ link = link.parentNode;
+
+ if (!link)
+ return;
+ }
+
+ let queryString = null;
+ if (link.protocol == "http:" || link.protocol == "https:")
+ {
+ if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
+ queryString = link.search.substr(1);
+ }
+ else
+ {
+ // Firefox doesn't populate the "search" property for links with
+ // non-standard URL schemes so we need to extract the query string
+ // manually
+ let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
+ if (match)
+ queryString = match[1];
+ }
+
+ if (!queryString)
+ return;
+
+ // This is our link - make sure the browser doesn't handle it
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Decode URL parameters
+ let title = null;
+ let url = null;
+ let mainSubscriptionTitle = null;
+ let mainSubscriptionURL = null;
+ for (let param of queryString.split("&"))
+ {
+ let parts = param.split("=", 2);
+ if (parts.length != 2 || !/\S/.test(parts[1]))
+ continue;
+ switch (parts[0])
+ {
+ case "title":
+ title = decodeURIComponent(parts[1]);
+ break;
+ case "location":
+ url = decodeURIComponent(parts[1]);
+ break;
+ case "requiresTitle":
+ mainSubscriptionTitle = decodeURIComponent(parts[1]);
+ break;
+ case "requiresLocation":
+ mainSubscriptionURL = decodeURIComponent(parts[1]);
+ break;
+ }
+ }
+
+ port.emit("subscribeLinkClick", {
+ title: title,
+ url: url,
+ mainSubscriptionTitle: mainSubscriptionTitle,
+ mainSubscriptionURL: mainSubscriptionURL
+ });
+}
diff --git a/lib/ui.js b/lib/ui.js
index ab97cdd..6240969 100644
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -19,6 +19,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
let {Utils} = require("utils");
+let {port} = require("messaging");
let {Prefs} = require("prefs");
let {Policy} = require("contentPolicy");
let {FilterStorage} = require("filterStorage");
@@ -445,21 +446,8 @@ let UI = exports.UI =
// Add "anti-adblock messages" notification
initAntiAdblockNotification();
- // Frame script URL has to be randomized due to caching
- // (see https://bugzilla.mozilla.org/show_bug.cgi?id=1051238)
- let frameScript = "chrome://adblockplus/content/subscribeLinkHandler.js?" + Math.random();
-
// Initialize subscribe link handling
- let callback = this.subscribeLinkClicked.bind(this);
- let messageManager = Cc["@mozilla.org/globalmessagemanager;1"]
- .getService(Ci.nsIMessageListenerManager);
- messageManager.loadFrameScript(frameScript, true);
- messageManager.addMessageListener("AdblockPlus:SubscribeLink", callback);
- onShutdown.add(() => {
- messageManager.broadcastAsyncMessage("AdblockPlus:Shutdown", frameScript);
- messageManager.removeDelayedFrameScript(frameScript);
- messageManager.removeMessageListener("AdblockPlus:SubscribeLink", callback);
- });
+ port.on("subscribeLinkClick", data => this.subscribeLinkClicked(data));
// Execute first-run actions if a window is open already, otherwise it
// will happen in applyToWindow() when a window is opened.
@@ -931,12 +919,12 @@ let UI = exports.UI =
},
/**
- * Called whenever subscribeLinkHandler.js intercepts clicks on abp: links
+ * Called whenever child/subscribeLinks module intercepts clicks on abp: links
* as well as links to subscribe.adblockplus.org.
*/
- subscribeLinkClicked: function(message)
+ subscribeLinkClicked: function({title, url,
+ mainSubscriptionTitle, mainSubscriptionURL})
{
- let {title, url, mainSubscriptionTitle, mainSubscriptionURL} = message.data;
if (!url)
return;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list