dom/base/nsIMessageManager.idlScriptable
This interface enables clients to listen for messages sent using the nsIMessageBroadcaster, nsIMessageSender, or nsISyncMessageSender interfaces.
1.0
66
Introduced
Gecko 17
Inherits from: nsISupports Last changed in Gecko 41 (Firefox 41 / Thunderbird 41 / SeaMonkey 2.38)

Implemented by: @mozilla.org/globalmessagemanager;1. To access this service, use:

var globalMM = Components.classes["@mozilla.org/globalmessagemanager;1"]
               .getService(Components.interfaces.nsIMessageListenerManager);

Method overview

void addMessageListener(in AString messageName,
                        in nsIMessageListener listener,
                        [optional] in boolean listenWhenClosed)
void removeMessageListener(in AString messageName,
                           in nsIMessageListener listener);
void addWeakMessageListener(in AString messageName,
                            in nsIMessageListener listener);
void removeWeakMessageListener(in AString messageName,
                               in nsIMessageListener listener);

Methods

addMessageListener()

Register listener to receive messageName.  All listener callbacks for a particular message are invoked when that message is received. The message manager holds a strong reference to listener. If the same listener registers twice for the same message, the second registration is ignored.

void addMessageListener(in AString messageName,
                        in nsIMessageListener listener,
                        [optional] in boolean listenWhenClosed);

Parameters

messageName
A string indicating the name of the message to listen for.
listener
An nsIMessageListener to invoke when a message is received. See nsIMessageListener for details of the message syntax.
listenWhenClosed
Specify true to receive messages during the short period after a frame has been removed from the DOM and before its frame script has finished unloading; this is false by default. This parameter only has an effect for frame message managers in the main process. An alternative method to listen for death of frame script is to use a message-manager-disconnect  observer; see Observer Notifications :: Message Manager.

removeMessageListener()

Undo an addMessageListener() call; that is, calling this causes listener to stop being invoked when the specified message is received.

void removeMessageListener(in AString messageName,
                           in nsIMessageListener listener);

removeMessageListener() does not remove a message listener added via addWeakMessageListener(); use removeWeakMessageListener() for that.

Parameters

messageName
The name of the message whose listener is to be removed.
listener
An nsIMessageListener representing the listener to remove.

addWeakMessageListener()

This is just like addMessageListener(), except that the message manager holds a weak reference to listener.

void addWeakMessageListener(in AString messageName,
                            in nsIMessageListener listener);

If you have two weak message listeners for the same message, they may be called in any order.

Parameters

messageName
A string indicating the name of the message to listen for.
listener
An nsIMessageListener to invoke when a message is received. See nsIMessageListener for details of the message syntax.

removeWeakMessageListener()

Undo an addWeakMessageListener() call. That is, calling this causes the listener to no longer be invoked when messageName is received.

void removeWeakMessageListener(in AString messageName,
                               in nsIMessageListener listener);

removeWeakMessageListener() does not remove a message listener added via addMessageListener(); use removeMessageListener() for that.

Parameters

messageName
The name of the message whose listener is to be removed.
listener
An nsIMessageListener representing the listener to remove.