nsISupports
Last changed in Gecko 0.9.6 The XPCOM nsObserverService
implements this interface to provide global notifications for a variety of subsystems.
Implemented by @mozilla.org/observer-service;1
as a service:
var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService);
void addObserver( in nsIObserver anObserver, in string aTopic, in boolean ownsWeak); |
nsISimpleEnumerator enumerateObservers( in string aTopic ); |
void notifyObservers( in nsISupports aSubject, in string aTopic, in wstring someData ); |
void removeObserver( in nsIObserver anObserver, in string aTopic ); |
Registers a given listener for a notifications regarding the specified topic. See nsIObserver
for a JavaScript example.
void addObserver( in nsIObserver anObserver, in string aTopic, in boolean ownsWeak );
anObserver
nsIObserver
object which will receive notifications.aTopic
ownsWeak
false
, the nsIObserverService
will hold a strong reference to anObserver
. If set to true
and anObserver
supports the nsISupportsWeakReference
interface, a weak reference will be held. Otherwise an error will be returned. (In most cases, you should use false
.)Called to enumerate all observers registered for a particular topic.
nsISimpleEnumerator enumerateObservers( in string aTopic );
aTopic
Returns an enumeration of all registered listeners. See nsISimpleEnumerator
.
This method is called to notify all observers for a particular topic. See Example.
void notifyObservers( in nsISupports aSubject, in string aTopic, in wstring someData );
aSubject
null
.aTopic
null
.someData
null
.This method is called to unregister an observer for a particular topic.
void removeObserver( in nsIObserver anObserver, in string aTopic );
anObserver
nsIObserver
instance to remove.aTopic
null
.This notifies all nsIObserver
s watching the "myTopicID" topic with an additional data parameter.
Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService) .notifyObservers(null, "myTopicID", "someAdditionalInformationPassedAs'Data'Parameter");
nsObserverService
nsIObserver
documentation.