Changeset 1069

Show
Ignore:
Timestamp:
2008-09-08 09:19:36 (2 months ago)
Author:
MaierMan
Message:

Relocate makeObserver

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/chrome/content/common/internalFunctions.js

    r1047 r1069  
    400400} 
    401401 
    402 var makeObserver = DTA_makeObserver; 
    403  
    404402/** 
    405403 * Encapulates all stringbundles of the current document and provides unified 
  • trunk/chrome/content/common/overlayFunctions.js

    r1067 r1069  
    607607        return null; 
    608608} 
    609  
    610 /** 
    611  * Tiny helper to "convert" given object into a weak observer. Object must still 
    612  * implement .observe() 
    613  *  
    614  * @author Nils 
    615  * @param obj 
    616  *          Object to convert 
    617  */ 
    618 function DTA_makeObserver(obj) { 
    619         // nsiSupports 
    620         let __QueryInterface = obj.QueryInterface; 
    621         obj.QueryInterface = function(iid) { 
    622                 try { 
    623                         if ( 
    624                                 iid.equals(Components.interfaces.nsISupports) 
    625                                 || iid.equals(Components.interfaces.nsISupportsWeakReference) 
    626                                 || iid.equals(Components.interfaces.nsIWeakReference) 
    627                                 || iid.equals(Components.interfaces.nsIObserver) 
    628                         ) { 
    629                                 return obj; 
    630                         } 
    631                         if (__QueryInterface) { 
    632                                 debug("calling original: " + iid); 
    633                                 return __QueryInterface.call(this, iid); 
    634                         } 
    635                         throw Components.results.NS_ERROR_NO_INTERFACE; 
    636                 } 
    637                 catch (ex) { 
    638                         debug("requested interface not available: " + iid); 
    639                         throw ex; 
    640                 } 
    641         }; 
    642         // nsiWeakReference 
    643         obj.QueryReferent = function(iid) { 
    644                 return obj.QueryInterface(iid); 
    645         }; 
    646         // nsiSupportsWeakReference 
    647         obj.GetWeakReference = function() { 
    648                 return obj; 
    649         };       
    650 } 
  • trunk/chrome/content/dta/manager.js

    r1066 r1069  
    139139                } 
    140140                 
    141                 makeObserver(this); 
     141                Preferences.makeObserver(this); 
    142142                this._observes.forEach( 
    143143                        function(topic) { 
  • trunk/chrome/content/dta/manager/alertservice.js

    r719 r1069  
    4343                        try { 
    4444                                this._service = Serv('@mozilla.org/alerts-service;1', 'nsIAlertsService'); 
    45                                 makeObserver(this); 
     45                                Preferences.makeObserver(this); 
    4646                                this._available = true; 
    4747                        } 
  • trunk/chrome/content/dta/manager/prefs.js

    r1066 r1069  
    7171 
    7272        init: function() { 
    73                 makeObserver(this); 
    74  
    7573                try { 
    7674                        this._resetConnPrefs(); 
  • trunk/chrome/content/dta/select.js

    r1062 r1069  
    801801        // * filterManager 
    802802        registerObserver: function() { 
    803                 makeObserver(this); 
     803                Preferences.makeObserver(this); 
    804804                try { 
    805805                        var os = Cc["@mozilla.org/observer-service;1"] 
  • trunk/chrome/content/integration/toolbarButtons.js

    r993 r1069  
    4343                        } 
    4444                ); 
    45                 DTA_makeObserver(this); 
    4645                DTA_preferences.addObserver("extensions.dta.sm.", this); 
    4746                this._refresh(); 
  • trunk/chrome/content/preferences/prefs.js

    r1066 r1069  
    202202                registerObserver: function() { 
    203203                        try { 
    204                                 makeObserver(this); 
     204                                Preferences.makeObserver(this); 
    205205                                var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); 
    206206                                os.addObserver(this, 'DTA:filterschanged', true); 
  • trunk/modules/preferences.jsm

    r995 r1069  
    5050        'resetAllExt', 
    5151        'addObserver', 
    52         'removeObserver' 
     52        'removeObserver', 
     53        'makeObserver' 
    5354]; 
    5455 
     
    189190 
    190191function addObserver(branch, obj) { 
     192        makeObserver(obj); 
    191193        prefs.QueryInterface(nsIPrefBranch2).addObserver(branch, obj, true); 
    192194} 
     
    195197        prefs.QueryInterface(nsIPrefBranch2).removeObserver(branch, obj); 
    196198} 
     199 
     200function makeObserver(obj) { 
     201        try { 
     202                if ( 
     203                        obj.QueryInterface(Ci.nsISupportsWeakReference) 
     204                        && obj.QueryInterface(Ci.nsIObserver) 
     205                ) { 
     206                        return; 
     207                } 
     208        } 
     209        catch (ex) { 
     210                // fall-through 
     211        } 
     212        let __QueryInterface = obj.QueryInterface; 
     213        obj.QueryInterface = function(iid) { 
     214                try { 
     215                        if ( 
     216                                iid.equals(Components.interfaces.nsISupports) 
     217                                || iid.equals(Components.interfaces.nsISupportsWeakReference) 
     218                                || iid.equals(Components.interfaces.nsIWeakReference) 
     219                                || iid.equals(Components.interfaces.nsIObserver) 
     220                        ) { 
     221                                return obj; 
     222                        } 
     223                        if (__QueryInterface) { 
     224                                debug("calling original: " + iid); 
     225                                return __QueryInterface.call(this, iid); 
     226                        } 
     227                        throw Components.results.NS_ERROR_NO_INTERFACE; 
     228                } 
     229                catch (ex) { 
     230                        debug("requested interface not available: " + iid); 
     231                        throw ex; 
     232                } 
     233        }; 
     234        // nsiWeakReference 
     235        obj.QueryReferent = function(iid) { 
     236                return obj.QueryInterface(iid); 
     237        }; 
     238        // nsiSupportsWeakReference 
     239        obj.GetWeakReference = function() { 
     240                return obj; 
     241        };       
     242}