B2G/gecko/toolkit/components/exthelper/extApplication.js
/**
   * Add a preference observer.
   *
   * @param aPrefs the nsIPrefBranch onto which we'll install our listener.
   * @param aDomain the domain our listener will watch (a string).
   * @param aEvent the event to listen to (you probably want "change").
   * @param aListener the function to call back when the event fires.  This
   *                  function will receive an EventData argument.
   */
Add a preference observer.
@param aPrefs the nsIPrefBranch onto which we'll install our listener.
@param aDomain the domain our listener will watch (a string).
@param aEvent the event to listen to (you probably want "change").
@param aListener the function to call back when the event fires.  This
function will receive an EventData argument.
Add a preference observer . @param aPrefs the nsIPrefBranch onto which we ' ll install our listener . @param aDomain the domain our listener will watch ( a string ) . @param aEvent the event to listen to ( you probably want " change " ) . @param aListener the function to call back when the event fires . This function will receive an EventData argument .
function po_al(aPrefs, aDomain, aEvent, aListener) {
    var root = aPrefs.root;
    if (!this._observersDict[root]) {
      this._observersDict[root] = {};
    }
    var observer = this._observersDict[root][aDomain];
    if (!observer) {
      observer = {
        events: new Events(),
        observe: function po_observer_obs(aSubject, aTopic, aData) {
          this.events.dispatch("change", aData);
        },
        QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                               Ci.nsISupportsWeakReference])
      };
      observer.prefBranch = aPrefs;
      observer.prefBranch.addObserver(aDomain, observer,  true);
      this._observersDict[root][aDomain] = observer;
    }
    observer.events.addListener(aEvent, aListener);
  }
function po_al ( aPrefs , aDomain , aEvent , aListener ) { var root = aPrefs . root ; if ( ! this . _observersDict [ root ] ) { this . _observersDict [ root ] = { } ; } var observer = this . _observersDict [ root ] [ aDomain ] ; if ( ! observer ) { observer = { events : new Events ( ) , observe : function po_observer_obs ( aSubject , aTopic , aData ) { this . events . dispatch ( "change" , aData ) ; } , QueryInterface : XPCOMUtils . generateQI ( [ Ci . nsIObserver , Ci . nsISupportsWeakReference ] ) } ; observer . prefBranch = aPrefs ; observer . prefBranch . addObserver ( aDomain , observer , true ) ; this . _observersDict [ root ] [ aDomain ] = observer ; } observer . events . addListener ( aEvent , aListener ) ; }
Add a preference observer.
Add a preference observer .
/* ownsWeak = */ // Notice that the prefBranch keeps a weak reference to the observer; // it's this._observersDict which keeps the observer alive.