Visit Mozilla.org

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" prefbranch and calling addObserver("foo.bar.", ...) will observe changes to foo.bar.baz and foo.bar.bzip.
aObserver
The object to be notified if the preference changes.
aHoldWeak
True holds a weak reference to aObserver. The object must implement the nsISupportsWeakReference interface or this will fail. False holds a strong reference to aObserver.

[edit] removeObserver()

Remove a preference change observer.

Note: You must call 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.