2014-12-09 21:56:17 +01:00
|
|
|
/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
|
2014-11-24 20:00:27 +01:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2014-12-02 08:35:25 +01:00
|
|
|
let appName = 'ublock';
|
|
|
|
let listeners = {};
|
2014-12-09 21:56:17 +01:00
|
|
|
let frameModule = Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
|
2014-12-02 08:35:25 +01:00
|
|
|
|
2014-12-09 21:56:17 +01:00
|
|
|
this.ublock_addMessageListener = function(id, fn) {
|
|
|
|
ublock_removeMessageListener(id);
|
2014-12-02 08:35:25 +01:00
|
|
|
listeners[id] = function(msg) {
|
|
|
|
fn(msg.data);
|
|
|
|
};
|
|
|
|
addMessageListener(id, listeners[id]);
|
|
|
|
};
|
|
|
|
|
2014-12-09 21:56:17 +01:00
|
|
|
this.ublock_removeMessageListener = function(id) {
|
2014-12-02 08:35:25 +01:00
|
|
|
if (listeners[id]) {
|
|
|
|
removeMessageListener(id, listeners[id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete listeners[id];
|
|
|
|
};
|
2014-11-24 20:00:27 +01:00
|
|
|
|
2014-12-07 20:51:49 +01:00
|
|
|
addMessageListener(appName + ':broadcast', function(msg) {
|
2014-12-02 08:35:25 +01:00
|
|
|
for (let id in listeners) {
|
|
|
|
listeners[id](msg);
|
|
|
|
}
|
2014-11-24 20:00:27 +01:00
|
|
|
});
|