summaryrefslogtreecommitdiff
path: root/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js')
-rw-r--r--data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js116
1 files changed, 48 insertions, 68 deletions
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
index db2d7e1..366325a 100644
--- a/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js
+++ b/data/extensions/spyblock@gnu.org/chrome/content/ui/ext/content.js
@@ -1,6 +1,6 @@
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-2015 Eyeo GmbH
+ * Copyright (C) 2006-2017 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
@@ -17,86 +17,66 @@
(function(global)
{
+ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
- if (!global.ext)
- global.ext = {};
-
- /* Message passing */
- global.ext.onMessage = new global.ext._EventTarget();
+ var Services = Cu.import("resource://gre/modules/Services.jsm", {}).Services;
- 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()
+ function require(/**String*/ module)
{
- global.ext.backgroundPage._disconnect();
- }, false);
+ var result = {};
+ result.wrappedJSObject = result;
+ Services.obs.notifyObservers(result, "adblockplus-require", module);
+ return result.exports;
+ }
- /* i18n */
- global.ext.i18n = (function()
+ function getOuterWindowID()
{
- 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)
+ if (!getOuterWindowID.result)
{
- return {
- "message": stringBundle.GetStringFromName(key)
- };
+ getOuterWindowID.result = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils)
+ .outerWindowID;
}
+ return getOuterWindowID.result;
+ }
- 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;
+ const Port = require("messaging").Port;
- var index = parseInt(content.slice(1), 10);
- if (isNaN(index))
- continue;
+ if (!global.ext)
+ global.ext = {};
- var replacement = args[index - 1];
- if (typeof replacement === "undefined")
- continue;
+ /* Message passing */
+ var port = new Port(Cc["@mozilla.org/childprocessmessagemanager;1"]
+ .getService(Ci.nsIMessageSender));
+ window.addEventListener("unload", function()
+ {
+ try
+ {
+ port.emit("ext_disconnect", getOuterWindowID());
+ }
+ catch (e)
+ {
+ // This is expected to fail if Adblock Plus was disabled/uninstalled with
+ // the page still open.
+ }
+ port.disconnect();
+ }, false);
- text = text.split("$" + key + "$").join(replacement);
- }
- return text;
+ global.ext.onMessage = new global.ext._EventTarget(port, getOuterWindowID());
+ global.ext.backgroundPage = {
+ sendMessage: function(payload, responseCallback)
+ {
+ var message = {
+ senderID: getOuterWindowID(),
+ payload
+ };
+ if (typeof responseCallback == "function")
+ port.emitWithResponse("ext_message", message).then(responseCallback);
+ else
+ port.emit("ext_message", message);
}
+ };
- 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);