nsIPrefBranch2
From MDC
nsIPrefBranch2 interface allows clients to observe changes to pref values.
Contents |
nsIPrefBranch2 is defined in modules/libpref/public/nsIPrefBranch2.idl. It is scriptable and
has been frozen since Mozilla 1.8.
Inherits from: nsIPrefBranch
[edit] Method overview
void addObserver(in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak);
|
void removeObserver(in string aDomain, in nsIObserver aObserver);
|
[edit] Methods
[edit] addObserver()
Add a preference change observer. On preference changes, the following arguments will be passed to the nsIObserver.observe method:
aSubject - The nsIPrefBranch object (this).
aTopic - The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
aData - The name of the preference which has changed, relative to the "root" of the aSubject branch.
aSubject.get*Pref(aData) will get the new value of the modified preference. For example, if your observer is registered with addObserver("bar.", ...) on a branch with root "foo.", modifying the preference "foo.bar.baz" will trigger the observer, and aData parameter will be "bar.baz".
void addObserver( in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak );
[edit] Parameters
- aDomain
- The preference on which to listen for changes. This can be the name of an entire branch to observe. e.g. Holding the "root"
prefbranchand callingaddObserver("foo.bar.", ...)will observe changes tofoo.bar.bazandfoo.bar.bzip.
- aObserver
- The object to be notified if the preference changes.
- aHoldWeak
Trueholds a weak reference toaObserver. The object must implement thensISupportsWeakReferenceinterface or this will fail.Falseholds a strong reference toaObserver.
[edit] removeObserver()
Remove a preference change observer.
removeObserver method on the same nsIPrefBranch2 instance on which you called addObserver method in order to remove aObserver; otherwise, the observer will not be removed. void removeObserver(
in string aDomain,
in nsIObserver aObserver
);
[edit] Parameters
- aDomain
- The preference which is being observed for changes.
- aObserver
- An observer previously registered with addObserver.