Opened 4 years ago

Last modified 4 years ago

#3499 closed change

Create a clean messaging API for internal use — at Initial Version

Reported by: trev Assignee: trev
Priority: P3 Milestone: Adblock-Plus-2.7.3-for-Firefox
Module: Adblock-Plus-for-Firefox Keywords:
Cc: sebastian, sergz Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Ross Verified working: yes
Review URL(s):



For our E10S support, we are currently using message manager directly. This results in overly complicated code however: message names have to avoid conflicts with other extensions, message handlers have to be removed explicitly, response handling has to be implemented explicitly, messaging code is duplicated for the first-run page.

What to change

Create a clean internal API in the messaging module:

  • Port constructor binds a communication port to a message manager.
  • port instance is the default port (communicating with the parent for process scripts, broadcasting to all children for the parent).
  • Port.disconnect() shuts down the port (done automatically for the default port when the extension is shut down).
  • Port.on() adds a handler for a particular message (message names are specific to Adblock Plus and won't conflict with other extensions).
  • removes a handler.
  • Port.emit() sends/broadcasts an asynchronous message, if provided the response callback will be triggered with the response.
  • Port.emitSync() sends a synchronous message, response is returned from the function.

Message handlers have three parameters: payload (the data sent by the sender), sender (a Port instance) and sendResponse (callback to be called with the response). The handler has to return true if it wants to use the callback asynchronously, otherwise it will expire when the function returns.

Change History (0)

Note: See TracTickets for help on using tickets.