From 9317615bc727fad063edac2456c117de9979fd97 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Thu, 8 Jan 2015 21:18:05 +0100 Subject: [PATCH] Firefox: improvements for content scripts --- platform/firefox/frameScript.js | 48 +++------------------------------ 1 file changed, 4 insertions(+), 44 deletions(-) diff --git a/platform/firefox/frameScript.js b/platform/firefox/frameScript.js index 5b9eadc..c97e9ac 100644 --- a/platform/firefox/frameScript.js +++ b/platform/firefox/frameScript.js @@ -19,51 +19,11 @@ Home: https://github.com/gorhill/uBlock */ -/* globals addMessageListener, removeMessageListener */ - -/******************************************************************************/ - -// https://bugzil.la/673569 - -(function(frameScriptContext) { - -'use strict'; - -/******************************************************************************/ - -let appName = Components.stack.filename.match(/:\/\/([^\/]+)/)[1]; -let listeners = {}; - -Components.utils['import'](Components.stack.filename.replace('Script', 'Module'), {}); - -/******************************************************************************/ - -frameScriptContext[appName + '_addMessageListener'] = function(id, fn) { - frameScriptContext[appName + '_removeMessageListener'](id); - listeners[id] = function(msg) { - fn(msg.data); - }; - addMessageListener(id, listeners[id]); -}; - -frameScriptContext[appName + '_removeMessageListener'] = function(id) { - if ( listeners[id] ) { - removeMessageListener(id, listeners[id]); - } - - delete listeners[id]; -}; - -/******************************************************************************/ - -addMessageListener(appName + ':broadcast', function(msg) { - for ( let id in listeners ) { - listeners[id](msg); - } -}); - /******************************************************************************/ -})(this); +Components.utils.import( + Components.stack.filename.replace('Script', 'Module'), + null +); /******************************************************************************/