nsIMessageListener

This article needs a technical review. How you can help.

This interface is used to receive messages sent using the nsIMessageBroadcaster, nsIMessageSender, or nsISyncMessageSender interfaces. Listeners are attached using the nsIMessageListenerManager interface.

Methods

void receiveMessage();

receiveMessage()

This is for JS only. This function receives a message from one of the three message-sending functions in the message manager framework:

The received message is an object with the following properties:

target

The target of the message. Either an element owning the message manager, or the message manager itself if no element owns it.

If the message was sent from a frame script using a nsIContentFrameMessageManager, then this property is the XUL <browser> element for the frame from which the message was sent.

name The message name. This is the first argument passed into the message-sending function.
sync True if the message was sent using sendSyncMessage, false otherwise.
data A structured clone of the message payload: the second argument passed into the message-sending function.
json Same as data. Deprecated.
objects An object whose properties are any cross process object wrappers exposed by the sender as the third argument to the message-sending function.
principal Principal for the window app.

Each listener is invoked with its own copy of the message parameter.

When the listener is called, 'this' value is the target of the message.

If the message is synchronous, the possible return value is returned as JSON (will be changed to use structured clones). When there are multiple listeners to synchronous messages, each listener's return value is sent back as an element in an array.  undefined return values show up as undefined values in the array.

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,