From efb4b98986a9aec548b23007c91639dfebed827b Mon Sep 17 00:00:00 2001 From: Deathamns Date: Mon, 24 Nov 2014 20:00:27 +0100 Subject: [PATCH] Initial Firefox port (base, messaging, locales) --- platform/firefox/frameScript.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 platform/firefox/frameScript.js diff --git a/platform/firefox/frameScript.js b/platform/firefox/frameScript.js new file mode 100644 index 0000000..30dd94a --- /dev/null +++ b/platform/firefox/frameScript.js @@ -0,0 +1,32 @@ +/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener, content */ + +(function() { + +'use strict'; + +var + app_name = 'ublock', + app_baseURI = 'chrome://' + app_name + '/content/js/', + listeners = {}, + _addMessageListener = function(id, fn) { + _removeMessageListener(id); + listeners[id] = function(msg) { + fn(msg.data); + }; + addMessageListener(id, listeners[id]); + }, + _removeMessageListener = function(id) { + if (listeners[id]) { + removeMessageListener(id, listeners[id]); + } + + delete listeners[id]; + }; + +addMessageListener('µBlock:broadcast', function(msg) { + for (var id in listeners) { + listeners[id](msg.data); + } +}); + +})(); \ No newline at end of file