You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
917 B

  1. /* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
  2. (function(frameScriptContext) {
  3. 'use strict';
  4. let appName;
  5. let listeners = {};
  6. try { throw new Error; } catch (ex) {
  7. appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
  8. }
  9. Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
  10. frameScriptContext[appName + '_addMessageListener'] = function(id, fn) {
  11. frameScriptContext[appName + '_removeMessageListener'](id);
  12. listeners[id] = function(msg) {
  13. fn(msg.data);
  14. };
  15. addMessageListener(id, listeners[id]);
  16. };
  17. frameScriptContext[appName + '_removeMessageListener'] = function(id) {
  18. if (listeners[id]) {
  19. removeMessageListener(id, listeners[id]);
  20. }
  21. delete listeners[id];
  22. };
  23. addMessageListener(appName + ':broadcast', function(msg) {
  24. for (let id in listeners) {
  25. listeners[id](msg);
  26. }
  27. });
  28. })(this);