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.

29 lines
740 B

  1. /* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
  2. 'use strict';
  3. let appName = 'ublock';
  4. let listeners = {};
  5. let frameModule = Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
  6. this.ublock_addMessageListener = function(id, fn) {
  7. ublock_removeMessageListener(id);
  8. listeners[id] = function(msg) {
  9. fn(msg.data);
  10. };
  11. addMessageListener(id, listeners[id]);
  12. };
  13. this.ublock_removeMessageListener = function(id) {
  14. if (listeners[id]) {
  15. removeMessageListener(id, listeners[id]);
  16. }
  17. delete listeners[id];
  18. };
  19. addMessageListener(appName + ':broadcast', function(msg) {
  20. for (let id in listeners) {
  21. listeners[id](msg);
  22. }
  23. });