This article needs a technical review. How you can help.
nsIMessageBroadcaster
, nsIMessageSender
, or nsISyncMessageSender
interfaces.
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, |
void removeMessageListener(in AString messageName, |
void addWeakMessageListener(in AString messageName, |
void removeWeakMessageListener(in AString messageName, |
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. SeensIMessageListener
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 isfalse
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 amessage-manager-disconnect
observer; see Observer Notifications :: Message Manager.
removeMessageListener()
Undo an
call; that is, calling this causes addMessageListener()
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
; use addWeakMessageListener()
for that.removeWeakMessageListener
()
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
, except that the message manager holds a weak reference to addMessageListener()
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. SeensIMessageListener
for details of the message syntax.
removeWeakMessageListener()
Undo an
call. That is, calling this causes the addWeakMessageListener()
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
; use addMessageListener()
for that.removeMessageListener
()
Parameters
messageName
- The name of the message whose listener is to be removed.
listener
- An
nsIMessageListener
representing the listener to remove.