[Pkg-mozext-commits] [adblock-plus] 54/74: Issue 1730 - Fixed abp:subscribe functionality with e10s
David Prévot
taffit at moszumanska.debian.org
Tue Aug 11 12:07:10 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 0d3cdc940d0a1d4fb098f857b51f7c1097a2117f
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon Jul 20 16:20:25 2015 +0200
Issue 1730 - Fixed abp:subscribe functionality with e10s
---
chrome/content/subscribeLinkHandler.js | 106 +++++++++++++++++++++++++++++++
lib/appSupport.js | 112 +--------------------------------
lib/ui.js | 94 +++++++--------------------
lib/utils.js | 2 -
4 files changed, 130 insertions(+), 184 deletions(-)
diff --git a/chrome/content/subscribeLinkHandler.js b/chrome/content/subscribeLinkHandler.js
new file mode 100644
index 0000000..04e6f76
--- /dev/null
+++ b/chrome/content/subscribeLinkHandler.js
@@ -0,0 +1,106 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2015 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/appSupport.js b/lib/appSupport.js
index 461b4c2..12307fe 100644
--- a/lib/appSupport.js
+++ b/lib/appSupport.js
@@ -212,48 +212,6 @@ exports.removeBrowserLocationListeners = function removeBrowserLocationListeners
progressListeners.delete(window);
};
-/**
- * Maps windows to a list of click listeners.
- */
-let clickListeners = new WeakMap();
-
-/**
- * Makes sure that a function is called whenever the user clicks inside the
- * browser's content area.
- */
-exports.addBrowserClickListener = function addBrowserClickListener(/**Window*/ window, /**Function*/ callback)
-{
- let browser = (exports.getBrowser ? exports.getBrowser(window) : null);
- if (browser)
- {
- browser.addEventListener("click", callback, true);
-
- if (clickListeners.has(window))
- clickListeners.get(window).push(callback);
- else
- clickListeners.set(window, [callback]);
- }
-};
-
-/**
- * Removes all click listeners registered for a window, to be called on
- * cleanup.
- */
-exports.removeBrowserClickListeners = function removeBrowserClickListeners(/**Window*/ window)
-{
- if (!clickListeners.has(window))
- return;
-
- let browser = (exports.getBrowser ? exports.getBrowser(window) : null);
- if (browser)
- {
- let listeners = clickListeners.get(window);
- for (let i = 0; i < listeners.length; i++)
- browser.removeEventListener("click", listeners[i], true);
- }
- clickListeners.delete(window);
-};
-
let {application} = require("info");
switch (application)
{
@@ -359,7 +317,7 @@ switch (application)
return (browser ? browser.currentURI : null);
}
};
-
+
// for Seamonkey we have to ignore same document flag because of
// bug #1035171 (https://bugzilla.mozilla.org/show_bug.cgi?id=1035171)
let origAddBrowserLocationListener = exports.addBrowserLocationListener;
@@ -617,40 +575,6 @@ switch (application)
progressListeners.delete(window);
};
- exports.addBrowserClickListener = function addBrowserClickListener(/**Window*/ window, /**Function*/ callback)
- {
- if (clickListeners.has(window))
- {
- clickListeners.get(window).callbacks.push(callback);
- return;
- }
-
- let callbacks = [callback];
- let listener = new BrowserChangeListener(window, function(oldBrowser, newBrowser)
- {
- if (oldBrowser)
- for (let i = 0; i < callbacks.length; i++)
- oldBrowser.removeEventListener("click", callbacks[i], true);
- if (newBrowser)
- for (let i = 0; i < callbacks.length; i++)
- newBrowser.addEventListener("click", callbacks[i], true);
- });
- listener.callbacks = callbacks;
-
- clickListeners.set(window, listener);
- };
-
- exports.removeBrowserClickListeners = function removeBrowserClickListeners(/**Window*/ window)
- {
- if (!clickListeners.has(window))
- return;
-
- let listener = clickListeners.get(window);
- listener.detach();
-
- clickListeners.delete(window);
- };
-
// Make sure to close/reopen list of blockable items when the user changes tabs
let {WindowObserver} = require("windowObserver");
new WindowObserver({
@@ -806,40 +730,6 @@ switch (application)
progressListeners.delete(window);
};
- exports.addBrowserClickListener = function ffn_addBrowserClickListener(/**Window*/ window, /**Function*/ callback)
- {
- if (clickListeners.has(window))
- {
- clickListeners.get(window).callbacks.push(callback);
- return;
- }
-
- let callbacks = [callback];
- let listener = new BrowserChangeListener(window, function(oldBrowser, newBrowser)
- {
- if (oldBrowser)
- for (let i = 0; i < callbacks.length; i++)
- oldBrowser.removeEventListener("click", callbacks[i], true);
- if (newBrowser)
- for (let i = 0; i < callbacks.length; i++)
- newBrowser.addEventListener("click", callbacks[i], true);
- });
- listener.callbacks = callbacks;
-
- clickListeners.set(window, listener);
- };
-
- exports.removeBrowserClickListeners = function ffn_removeBrowserClickListeners(/**Window*/ window)
- {
- if (!clickListeners.has(window))
- return;
-
- let listener = clickListeners.get(window);
- listener.detach();
-
- clickListeners.delete(window);
- };
-
let {Filter} = require("filterClasses");
let {Prefs} = require("prefs");
let {Policy} = require("contentPolicy");
diff --git a/lib/ui.js b/lib/ui.js
index d2c6327..365ac3c 100644
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -459,6 +459,22 @@ let UI = exports.UI =
Services.obs.removeObserver(documentCreationObserver, "content-document-global-created", false);
});
+ // 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);
+ });
+
// Execute first-run actions if a window is open already, otherwise it
// will happen in applyToWindow() when a window is opened.
this.firstRunActions(this.currentWindow);
@@ -542,7 +558,7 @@ let UI = exports.UI =
*/
applyToWindow: function(/**Window*/ window, /**Boolean*/ noDelay)
{
- let {delayInitialization, isKnownWindow, getBrowser, addBrowserLocationListener, addBrowserClickListener} = require("appSupport");
+ let {delayInitialization, isKnownWindow, getBrowser, addBrowserLocationListener} = require("appSupport");
if (window.document.documentElement.id == "CustomizeToolbarWindow" || isKnownWindow(window))
{
// Add style processing instruction
@@ -593,7 +609,6 @@ let UI = exports.UI =
this.updateIconState(window, window.document.getElementById("abp-status"));
this.updateIconState(window, window.document.getElementById("abp-toolbarbutton"));
}.bind(this));
- addBrowserClickListener(window, this.onBrowserClick.bind(this, window));
let notificationPanel = window.document.getElementById("abp-notification");
notificationPanel.addEventListener("command", function(event)
@@ -628,7 +643,7 @@ let UI = exports.UI =
*/
removeFromWindow: function(/**Window*/ window)
{
- let {isKnownWindow, removeBrowserLocationListeners, removeBrowserClickListeners} = require("appSupport");
+ let {isKnownWindow, removeBrowserLocationListeners} = require("appSupport");
if (window.document.documentElement.id == "CustomizeToolbarWindow" || isKnownWindow(window))
{
// Remove style processing instruction
@@ -663,7 +678,6 @@ let UI = exports.UI =
window.removeEventListener("popupshowing", this.onPopupShowing, false);
window.removeEventListener("keypress", this.onKeyPress, false);
removeBrowserLocationListeners(window);
- removeBrowserClickListeners(window);
},
/**
@@ -923,74 +937,12 @@ let UI = exports.UI =
},
/**
- * Handles clicks inside the browser's content area, will intercept clicks on
- * abp: links as well as links to subscribe.adblockplus.org.
+ * Called whenever subscribeLinkHandler.js intercepts clicks on abp: links
+ * as well as links to subscribe.adblockplus.org.
*/
- onBrowserClick: function (/**Window*/ window, /**Event*/ event)
+ subscribeLinkClicked: function(message)
{
- // 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;
- }
- }
+ let {title, url, mainSubscriptionTitle, mainSubscriptionURL} = message.data;
if (!url)
return;
@@ -1028,7 +980,7 @@ let UI = exports.UI =
mainSubscriptionURL = mainSubscriptionURL.spec;
}
- this.openSubscriptionDialog(window, url, title, mainSubscriptionURL, mainSubscriptionTitle);
+ this.openSubscriptionDialog(this.currentWindow, url, title, mainSubscriptionURL, mainSubscriptionTitle);
},
/**
diff --git a/lib/utils.js b/lib/utils.js
index ea8ac7b..c78693f 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -597,8 +597,6 @@ XPCOMUtils.defineLazyServiceGetter(Utils, "windowWatcher", "@mozilla.org/embedco
XPCOMUtils.defineLazyServiceGetter(Utils, "chromeRegistry", "@mozilla.org/chrome/chrome-registry;1", "nsIXULChromeRegistry");
XPCOMUtils.defineLazyServiceGetter(Utils, "systemPrincipal", "@mozilla.org/systemprincipal;1", "nsIPrincipal");
XPCOMUtils.defineLazyServiceGetter(Utils, "dateFormatter", "@mozilla.org/intl/scriptabledateformat;1", "nsIScriptableDateFormat");
-XPCOMUtils.defineLazyServiceGetter(Utils, "childMessageManager", "@mozilla.org/childprocessmessagemanager;1", "nsISyncMessageSender");
-XPCOMUtils.defineLazyServiceGetter(Utils, "parentMessageManager", "@mozilla.org/parentprocessmessagemanager;1", "nsIFrameMessageManager");
XPCOMUtils.defineLazyServiceGetter(Utils, "httpProtocol", "@mozilla.org/network/protocol;1?name=http", "nsIHttpProtocolHandler");
XPCOMUtils.defineLazyServiceGetter(Utils, "clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard");
XPCOMUtils.defineLazyServiceGetter(Utils, "clipboardHelper", "@mozilla.org/widget/clipboardhelper;1", "nsIClipboardHelper");
--
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