From 9cb91f8a48f9467e448f88984c20b3429e8a2510 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Mon, 13 Jul 2015 22:52:06 -0500 Subject: Spyblock updated to 2.6.9.0 from upstream changes --- .../chrome/content/ui/ext/common.js | 159 +++++++++++++++++++++ .../chrome/content/ui/ext/content.js | 102 +++++++++++++ 2 files changed, 261 insertions(+) create mode 100644 data/extensions/spyblock@gnu.org/chrome/content/ui/ext/common.js create mode 100644 data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js (limited to 'data/extensions/spyblock@gnu.org/chrome/content/ui/ext') diff --git a/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/common.js b/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/common.js new file mode 100644 index 0000000..129f232 --- /dev/null +++ b/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/common.js @@ -0,0 +1,159 @@ +/* + * This file is part of Adblock Plus , + * 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 . + */ + +(function(global) +{ + const Ci = Components.interfaces; + + if (!global.ext) + global.ext = {}; + + var holder = { + get Page() + { + delete this.Page; + this.Page = (typeof require == "function" ? + require("ext_background").Page : + function() {}); + return this.Page; + } + }; + + var getSender = global.ext._getSender = function(origin) + { + if (origin instanceof Ci.nsIDOMXULElement) + return origin.messageManager; + else if (origin instanceof Ci.nsIMessageSender) + return origin; + else + return null; + }; + + var MessageProxy = global.ext._MessageProxy = function(messageManager, messageTarget) + { + this._messageManager = messageManager; + this._messageTarget = messageTarget; + this._callbacks = new Map(); + this._responseCallbackCounter = 0; + + this._handleRequest = this._handleRequest.bind(this); + this._handleResponse = this._handleResponse.bind(this); + this._messageManager.addMessageListener("AdblockPlus:Message", this._handleRequest); + this._messageManager.addMessageListener("AdblockPlus:Response", this._handleResponse); + }; + MessageProxy.prototype = { + _disconnect: function() + { + this._messageManager.removeMessageListener("AdblockPlus:Message", this._handleRequest); + this._messageManager.removeMessageListener("AdblockPlus:Response", this._handleResponse); + }, + + _sendResponse: function(sender, callbackId, message) + { + var response = { + callbackId: callbackId + }; + if (typeof response != "undefined") + response.payload = message; + sender.sendAsyncMessage("AdblockPlus:Response", response); + }, + + _handleRequest: function(message) + { + var sender = getSender(message.target); + var request = message.data; + + var sent = false; + var sendResponse; + if (sender && "callbackId" in request) + { + sendResponse = function(message) + { + this._sendResponse(sender, request.callbackId, message); + sent = true; + }.bind(this); + } + else + sendResponse = function() {}; + + var results = this._messageTarget._dispatch(request.payload, { + page: new holder.Page(sender) + }, sendResponse); + if (!sent && results.indexOf(true) == -1) + sendResponse(undefined); + }, + + _handleResponse: function(message) + { + var response = message.data; + var callback = this._callbacks.get(response.callbackId); + if (callback) + { + this._callbacks.delete(response.callbackId); + if ("payload" in response) + callback(response.payload); + } + }, + + sendMessage: function(message, responseCallback) + { + if (!(this._messageManager instanceof Ci.nsIMessageSender)) + throw new Error("Not implemented"); + + var request = { + payload: message + }; + if (responseCallback) + { + request.callbackId = ++this._responseCallbackCounter; + this._callbacks.set(request.callbackId, responseCallback); + } + + this._messageManager.sendAsyncMessage("AdblockPlus:Message", request); + } + }; + + var EventTarget = global.ext._EventTarget = function() + { + this._listeners = []; + }; + EventTarget.prototype = { + addListener: function(listener) + { + if (this._listeners.indexOf(listener) == -1) + this._listeners.push(listener); + }, + removeListener: function(listener) + { + var idx = this._listeners.indexOf(listener); + if (idx != -1) + this._listeners.splice(idx, 1); + }, + _dispatch: function() + { + var results = []; + + for (var i = 0; i < this._listeners.length; i++) + results.push(this._listeners[i].apply(null, arguments)); + + return results; + } + }; + + if (typeof exports == "object") + exports = global.ext; +})(this); diff --git a/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js b/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js new file mode 100644 index 0000000..db2d7e1 --- /dev/null +++ b/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js @@ -0,0 +1,102 @@ +/* + * This file is part of Adblock Plus , + * 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 . + */ + +(function(global) +{ + const Ci = Components.interfaces; + const Cu = Components.utils; + + if (!global.ext) + global.ext = {}; + + /* Message passing */ + global.ext.onMessage = new global.ext._EventTarget(); + + global.ext.backgroundPage = new global.ext._MessageProxy( + window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell) + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIContentFrameMessageManager), + global.ext.onMessage); + window.addEventListener("unload", function() + { + global.ext.backgroundPage._disconnect(); + }, false); + + /* i18n */ + global.ext.i18n = (function() + { + var Services = Cu.import("resource://gre/modules/Services.jsm", null).Services; + var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, ""); + + // Randomize URI to work around bug 719376 + var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/" + pageName + + ".properties?" + Math.random()); + + function getI18nMessage(key) + { + return { + "message": stringBundle.GetStringFromName(key) + }; + } + + function getText(message, args) + { + var text = message.message; + var placeholders = message.placeholders; + + if (!args || !placeholders) + return text; + + for (var key in placeholders) + { + var content = placeholders[key].content; + if (!content) + continue; + + var index = parseInt(content.slice(1), 10); + if (isNaN(index)) + continue; + + var replacement = args[index - 1]; + if (typeof replacement === "undefined") + continue; + + text = text.split("$" + key + "$").join(replacement); + } + return text; + } + + return { + getMessage: function(key, args) + { + try{ + var message = getI18nMessage(key); + return getText(message, args); + } + catch(e) + { + // Don't report errors for special strings, these are expected to be + // missing. + if (key[0] != "@") + Cu.reportError(e); + return ""; + } + } + }; + })(); +})(this); -- cgit v1.2.3