2014-12-10 09:56:17 +13:00
|
|
|
/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
|
2014-11-25 08:00:27 +13:00
|
|
|
|
2014-12-17 01:44:34 +13:00
|
|
|
(function(frameScriptContext) {
|
|
|
|
|
2014-11-25 08:00:27 +13:00
|
|
|
'use strict';
|
|
|
|
|
2014-12-17 01:44:34 +13:00
|
|
|
let appName;
|
2014-12-02 20:35:25 +13:00
|
|
|
let listeners = {};
|
|
|
|
|
2014-12-17 01:44:34 +13:00
|
|
|
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);
|
2014-12-02 20:35:25 +13:00
|
|
|
listeners[id] = function(msg) {
|
|
|
|
fn(msg.data);
|
|
|
|
};
|
|
|
|
addMessageListener(id, listeners[id]);
|
|
|
|
};
|
|
|
|
|
2014-12-17 01:44:34 +13:00
|
|
|
frameScriptContext[appName + '_removeMessageListener'] = function(id) {
|
2014-12-02 20:35:25 +13:00
|
|
|
if (listeners[id]) {
|
|
|
|
removeMessageListener(id, listeners[id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete listeners[id];
|
|
|
|
};
|
2014-11-25 08:00:27 +13:00
|
|
|
|
2014-12-08 08:51:49 +13:00
|
|
|
addMessageListener(appName + ':broadcast', function(msg) {
|
2014-12-02 20:35:25 +13:00
|
|
|
for (let id in listeners) {
|
|
|
|
listeners[id](msg);
|
|
|
|
}
|
2014-11-25 08:00:27 +13:00
|
|
|
});
|
2014-12-17 01:44:34 +13:00
|
|
|
|
|
|
|
})(this);
|