1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 17:19:38 +02:00
uBlock/platform/firefox/frameScript.js
2015-01-13 07:29:01 +01:00

38 lines
917 B
JavaScript

/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
(function(frameScriptContext) {
'use strict';
let appName;
let listeners = {};
try { throw new Error; } catch (ex) {
appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
}
Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
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);