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