Changeset 866

Show
Ignore:
Timestamp:
2008-03-09 01:22:05 (10 months ago)
Author:
MaierMan
Message:

Simplify Service/Component code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/components/debugService.js

    r743 r866  
    4141const FileStream = new Components.Constructor('@mozilla.org/network/file-output-stream;1', 'nsIFileOutputStream', 'init'); 
    4242const ScriptError = new Components.Constructor('@mozilla.org/scripterror;1', 'nsIScriptError', 'init'); 
    43   
     43 
     44function include(uri) { 
     45        Cc["@mozilla.org/moz/jssubscript-loader;1"] 
     46                .getService(Ci.mozIJSSubScriptLoader) 
     47                .loadSubScript(uri); 
     48
     49include("chrome://dta/content/common/module.js"); 
     50 
    4451var DebugService = { 
    45         // nsIClassInfo 
    46         classID: Components.ID("{0B82FEBB-59A1-41d7-B31D-D5A686E11A69}"), 
    47         contractID: "@downthemall.net/debug-service;1", 
    48         classDescription: "DownThemAll! Debug Service", 
    49         implementationLanguage: 0x02, 
    50         flags: (1 << 0) | (1 << 2), // SINGLETON | MAIN_THREAD_ONLY 
    51         classIDNoAlloc: this.classID, 
    52         getHelperForLanguage: function() { 
    53                 return null; 
    54         }, 
    55         getInterfaces: function(count) { 
    56                 // XXX 
    57                 count.value = 0; 
    58                 return null; 
    59         }, 
    60  
    61         implementsIID: function DS_implementID(iid) { 
    62                         return [ 
    63                                 Ci.nsISupports, 
    64                                 Ci.nsISupportsWeakReference, 
    65                                 Ci.nsIWeakReference, 
    66                                 Ci.nsIObserver, 
    67                                 Ci.nsIClassInfo, 
    68                                 Ci.nsIFactory, 
    69                                 Ci.dtaIDebugService 
    70                         ].some(function(e) { return iid.equals(e); }); 
    71         }, 
    72         // nsiSupports 
    73         QueryInterface: function DS_QI(iid) { 
    74                 if (this.implementsIID(iid)) { 
    75                         return this; 
    76                 } 
    77                 throw res.NS_ERROR_NO_INTERFACE; 
    78         }, 
    79  
    80         // nsiWeakReference 
    81         QueryReferent: function DS_QR(iid) { 
    82                 return this; 
    83         }, 
    84  
    85         // nsiSupportsWeakReference 
    86         GetWeakReference: function DS_GWR() { 
    87                 return this; 
    88         }, 
    89  
    90         // nsIFactory 
    91         createInstance: function (outer, iid) { 
    92                 if (outer != null) { 
    93                         throw res.NS_ERROR_NO_AGGREGATION; 
    94                 } 
    95                 if (this.implementsIID(iid)) { 
    96                         this._init();            
    97                         return this; 
    98                 } 
    99                 throw res.NS_ERROR_INVALID_ARG; 
    100         }, 
    101  
    10252        // nsIObserver 
    10353        observe: function DS_observe(subject, topic, prefName) { 
     
    10555        }, 
    10656         
    107         _init: function DS__init() { 
     57        init: function DS_init() { 
    10858                this._cs = Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService); 
    10959                this._pb = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch2); 
     
    12272                        // No-Op 
    12373                } 
    124                 this._init = new Function()
     74                delete this.init
    12575        }, 
    12676        get file() { 
     
    14292                return String(value).replace(/\b(\d)\b/g, "0$1"); 
    14393        }, 
    144         _log: function DS__dump(msg, e) { 
     94        _log: function DS__log(msg, e) { 
    14595                try { 
    14696                        if (msg == "" && typeof(e) != "object") { 
     
    187137                        } 
    188138                         
    189                         var f = new FileStream(this._file, 0x04 | 0x08 | 0x10, 0664, 0); 
     139                        var f = new FileStream(this.file, 0x04 | 0x08 | 0x10, 0664, 0); 
    190140                        f.write(text, text.length); 
    191141                        f.close(); 
     
    209159                        throw res.NS_ERROR_FAILURE; 
    210160                } 
    211         }, 
    212  
    213         _firstTime: true, 
    214         registerSelf: function DS_registerSelf(compMgr, fileSpec, location, type) { 
    215                 try { 
    216                         error("registering"); 
    217                          
    218                         if (!this._firstTime) { 
    219                                 return; 
    220                         } 
    221                         this._firstTime = false; 
    222          
    223                         compMgr.QueryInterface(Ci.nsIComponentRegistrar) 
    224                                 .registerFactoryLocation( 
    225                                         this.classID, 
    226                                         this.classDescription, 
    227                                         this.contractID, 
    228                                         fileSpec, 
    229                                         location, 
    230                                         type 
    231                                 ); 
    232                 } 
    233                 catch (ex) { 
    234                         error(ex); 
    235                 } 
    236         }, 
    237         unregisterSelf: function DS_unregisterSelf(compMgr, fileSpec, location) { 
    238                 compMgr.QueryInterface(Ci.nsIComponentRegistrar) 
    239                         .unregisterFactoryLocation( 
    240                                 this.classID, 
    241                                 fileSpec 
    242                         ); 
    243         }, 
    244         getClassObject: function DS_getClassObject(compMgr, cid, iid) { 
    245                 if (cid.equals(this.classID)) { 
    246                         return this; 
    247                 } 
    248                 throw Components.results.NS_ERROR_NO_INTERFACE; 
    249         }, 
    250         canUnload: function DS_canUnload(compMgr) { 
    251                 return true; 
    252161        } 
    253162}; 
     163implementComponent( 
     164        DebugService, 
     165        Components.ID("{0B82FEBB-59A1-41d7-B31D-D5A686E11A69}"), 
     166        "@downthemall.net/debug-service;1", 
     167        "DownThemAll! Debug Service", 
     168        [Ci.nsIObserver, Ci.dtaIDebugService] 
     169); 
    254170 
    255171// entrypoint 
    256172function NSGetModule(compMgr, fileSpec) { 
    257         return DebugService
     173        return new ServiceModule(DebugService, false)
    258174} 
  • trunk/components/filterManager.js

    r860 r866  
    3535 * ***** END LICENSE BLOCK ***** */ 
    3636 
    37 const CC = Components.classes; 
    38 const CI = Components.interfaces; 
     37const Cc = Components.classes; 
     38const Ci = Components.interfaces; 
     39const Cr = Components.results; 
     40 
    3941const Exception = Components.Exception; 
    4042 
     
    4446const NS_ERROR_INVALID_ARG = Components.results.NS_ERROR_INVALID_ARG; 
    4547 
    46 const LINK_FILTER = CI.dtaIFilter.LINK_FILTER; 
    47 const IMAGE_FILTER = CI.dtaIFilter.IMAGE_FILTER; 
     48const LINK_FILTER = Ci.dtaIFilter.LINK_FILTER; 
     49const IMAGE_FILTER = Ci.dtaIFilter.IMAGE_FILTER; 
    4850 
    4951function include(uri) { 
    50         CC["@mozilla.org/moz/jssubscript-loader;1"] 
    51                 .getService(CI.mozIJSSubScriptLoader) 
     52        Cc["@mozilla.org/moz/jssubscript-loader;1"] 
     53                .getService(Ci.mozIJSSubScriptLoader) 
    5254                .loadSubScript(uri); 
    5355} 
    54  
    55 function debug(str, ex) { 
    56         try { 
    57                 var DTA_Debug = Components.classes['@downthemall.net/debug-service;1'] 
    58                         .getService(Components.interfaces.dtaIDebugService); 
    59                 debug = function(str, ex) { 
    60                         if (ex) { 
    61                                 DTA_Debug.log(str, ex); 
    62                         } 
    63                         else { 
    64                                 DTA_Debug.logString(str); 
    65                         } 
    66                 } 
    67                 debug(str, ex); 
    68         } 
    69         catch (ex) { 
    70                 Components.utils.reportError(str + ": " + ex); 
    71         } 
    72 
     56include("chrome://dta/content/common/module.js"); 
    7357 
    7458// no not create DTA_Filter yourself, managed by DTA_FilterManager 
     
    7862} 
    7963Filter.prototype = { 
    80  
    81         LINK_FILTER: (1 << 0), 
    82         IMAGE_FILTER: (1 << 1), 
    83  
    84         _modified: false, 
    85         _regs: [], 
    86  
    87         // nsIClassInfo 
    88         classID: Components.ID("{1CF86DC0-33A7-43b3-BDDE-7ADC3B35D114}"), 
    89         contractID: "@downthemall.net/filter;2", 
    90         classDescription: "DownThemAll! Filter", 
    91         implementationLanguage: 0x02, 
    92         flags: (1 << 2), // MAIN_THREAD_ONLY 
    93         classIDNoAlloc: this.classID, 
    94         getHelperForLanguage: function() { 
    95                 return null; 
    96         }, 
    97         getInterfaces: function(count) { 
    98                 // XXX 
    99                 count.value = 0; 
    100                 return null; 
    101         }, 
    102  
    103         QueryInterface: function F_QI(iid) { 
    104                 if ( 
    105                         iid.equals(CI.nsISupports) 
    106                         || iid.equals(CI.nsIClassInfo) 
    107                         || iid.equals(CI.dtaIFilter) 
    108                 ) { 
    109                         return this; 
    110                 } 
    111                 throw NS_ERROR_NO_INTERFACE; 
    112         }, 
    113  
    11464        // exported 
    11565        get id() { 
     
    304254                var rv = this._prefs.getComplexValue( 
    305255                        pref, 
    306                         CI.nsISupportsString 
     256                        Ci.nsISupportsString 
    307257                ); 
    308258                return rv.data; 
     
    310260 
    311261        setMultiBytePref: function F_setMultiBytePref(pref, value) { 
    312                 var str = CC["@mozilla.org/supports-string;1"] 
    313                         .createInstance(CI.nsISupportsString); 
     262                var str = Cc["@mozilla.org/supports-string;1"] 
     263                        .createInstance(Ci.nsISupportsString); 
    314264                str.data = value; 
    315265                this._prefs.setComplexValue( 
    316266                        pref, 
    317                         CI.nsISupportsString, 
     267                        Ci.nsISupportsString, 
    318268                        str 
    319269                ); 
     
    326276        } 
    327277}; 
     278implementComponent( 
     279        Filter.prototype, 
     280        Components.ID("{1CF86DC0-33A7-43b3-BDDE-7ADC3B35D114}"), 
     281        "@downthemall.net/filter;2", 
     282        "DownThemAll! Filter", 
     283        [Ci.dtaIFilter] 
     284); 
    328285 
    329286function FilterEnumerator(filters) { 
     
    334291        QueryInterface: function FE_QI(iid) { 
    335292                if ( 
    336                         iid.equals(Components.intefaces.nsISupports) 
    337                         || iid.equals(Components.intefaces.nsISimpleEnumerator) 
     293                        iid.equals(Ci.nsISupports) 
     294                        || iid.equals(Ci.nsISimpleEnumerator) 
    338295                ) { 
    339296                        return this; 
     
    354311// XXX: reload() should be called delayed when we observe changes (as many changes might come in) 
    355312var FilterManager = { 
    356  
    357         // nsIClassInfo 
    358         classID: Components.ID("{435FC5E5-D4F0-47a1-BDC1-F325B78188F3}"), 
    359         contractID: "@downthemall.net/filtermanager;2", 
    360         classDescription: "DownThemAll! Filtermanager", 
    361         implementationLanguage: 0x02, 
    362         flags: (1 << 0) | (1 << 2), // SINGLETON | MAIN_THREAD_ONLY 
    363         classIDNoAlloc: this.classID, 
    364         getHelperForLanguage: function() { 
    365                 return null; 
    366         }, 
    367         getInterfaces: function(count) { 
    368                 // XXX 
    369                 count.value = 0; 
    370                 return null; 
    371         }, 
    372  
    373         implementsIID: function FM_implementID(iid) { 
    374                 return [ 
    375                         CI.nsISupports, 
    376                         CI.nsISupportsWeakReference, 
    377                         CI.nsIWeakReference, 
    378                         CI.nsIObserver, 
    379                         CI.nsIClassInfo, 
    380                         CI.nsITimerCallback, 
    381                         this.classID 
    382                 ].some(function(e) { return iid.equals(e); }); 
    383         }, 
    384  
    385313        _done: true, 
    386314        _mustReload: true, 
    387         _prefs: CC['@mozilla.org/preferences-service;1'] 
    388                 .getService(CI.nsIPrefService) 
     315         
     316        _prefs: Cc['@mozilla.org/preferences-service;1'] 
     317                .getService(Ci.nsIPrefService) 
    389318                .getBranch("extensions.dta.filters."), 
    390         _timer: CC['@mozilla.org/timer;1'] 
    391                         .createInstance(CI.nsITimer), 
     319         
     320        _timer: Cc['@mozilla.org/timer;1'] 
     321                        .createInstance(Ci.nsITimer), 
    392322 
    393323        _init: function FM_init() { 
    394                 this._prefs = this._prefs.QueryInterface(CI.nsIPrefBranch2); 
     324                this._prefs = this._prefs.QueryInterface(Ci.nsIPrefBranch2); 
    395325 
    396326                // load those localized labels for default filters. 
    397327                this._localizedLabels = {}; 
    398                 var b = CC['@mozilla.org/intl/stringbundle;1'] 
    399                         .getService(CI.nsIStringBundleService) 
     328                var b = Cc['@mozilla.org/intl/stringbundle;1'] 
     329                        .getService(Ci.nsIStringBundleService) 
    400330                        .createBundle("chrome://dta/locale/filters.properties"); 
    401331                var e = b.getSimpleEnumeration(); 
    402332                while (e.hasMoreElements()) { 
    403                         var prop = e.getNext().QueryInterface(CI.nsIPropertyElement); 
     333                        var prop = e.getNext().QueryInterface(Ci.nsIPropertyElement); 
    404334                        this._localizedLabels[prop.key] = prop.value; 
    405335                } 
     
    482412 
    483413                // notify all observers 
    484                 var observerService = CC["@mozilla.org/observer-service;1"] 
    485                         .getService(CI.nsIObserverService); 
     414                var observerService = Cc["@mozilla.org/observer-service;1"] 
     415                        .getService(Ci.nsIObserverService); 
    486416                observerService.notifyObservers(this, 'DTA:filterschanged', null); 
    487417        }, 
     
    504434                        return this._filters[id]; 
    505435                } 
    506                 throw new Components.Exception("invalid filter specified: " + id); 
     436                throw new Exception("invalid filter specified: " + id); 
    507437        }, 
    508438 
     
    515445                // we will use unique ids for user-supplied filters. 
    516446                // no need to keep track of the actual number of filters or an index. 
    517                 var uuid = CC["@mozilla.org/uuid-generator;1"] 
    518                         .getService(CI.nsIUUIDGenerator) 
     447                var uuid = Cc["@mozilla.org/uuid-generator;1"] 
     448                        .getService(Ci.nsIUUIDGenerator) 
    519449                        .generateUUID(); 
    520450 
     
    570500        }, 
    571501 
    572                 // nsiSupports 
    573         QueryInterface: function FM_QI(iid) { 
    574                 if (this.implementsIID(iid)) { 
    575                         return this; 
    576                 } 
    577                 throw NS_ERROR_NO_INTERFACE; 
    578         }, 
    579  
    580         // nsiWeakReference 
    581         QueryReferent: function FM_QR(iid) { 
    582                 return this; 
    583         }, 
    584  
    585         // nsiSupportsWeakReference 
    586         GetWeakReference: function FM_GWR() { 
    587                 return this; 
    588         }, 
    589  
    590502        // nsIObserver 
    591503        observe: function FM_observe(subject, topic, prefName) { 
     
    611523                this.reload(); 
    612524        } 
    613  
    614525}; 
     526implementComponent( 
     527        FilterManager, 
     528        Components.ID("{435FC5E5-D4F0-47a1-BDC1-F325B78188F3}"), 
     529        "@downthemall.net/filtermanager;2", 
     530        "DownThemAll! Filtermanager", 
     531        [Ci.nsITimerCallback, Ci.nsIObserver, Ci.dtaIFilterManager] 
     532); 
    615533FilterManager._init(); 
    616  
    617 var Module = { 
    618         _firstTime: true, 
    619  
    620         registerSelf: function M_registerSelf(compMgr, fileSpec, location, type) { 
    621                 if (!this._firstTime) { 
    622                         return; 
    623                 } 
    624                 this._firstTime = false; 
    625  
    626                 compMgr.QueryInterface(CI.nsIComponentRegistrar) 
    627                         .registerFactoryLocation( 
    628                                 FilterManager.classID, 
    629                                 FilterManager.classDescription, 
    630                                 FilterManager.contractID, 
    631                                 fileSpec, 
    632                                 location, 
    633                                 type 
    634                         ); 
    635                 CC['@mozilla.org/categorymanager;1'] 
    636                         .getService(CI.nsICategoryManager) 
    637                         .addCategoryEntry('app-startup', FilterManager.contractID, FilterManager.contractID, true, true, null); 
    638         }, 
    639         unregisterSelf: function(compMgr, fileSpec, location) { 
    640                 compMgr.QueryInterface(CI.nsIComponentRegistrar) 
    641                         .unregisterFactoryLocation( 
    642                                 FileManager.classID, 
    643                                 fileSpec 
    644                         ); 
    645                 CC['@mozilla.org/categorymanager;1'] 
    646                         .getService(CI.nsICategoryManager) 
    647                         .deleteCategoryEntry('app-startup', FileManager.contractID, true); 
    648         }, 
    649         getClassObject: function (compMgr, cid, iid) { 
    650                 if (cid.equals(FilterManager.classID)) { 
    651                         return this; 
    652                 } 
    653                 throw NS_ERROR_NO_INTERFACE; 
    654         }, 
    655         canUnload: function(compMgr) { 
    656                 return true; 
    657         }, 
    658  
    659         // nsIFactory 
    660         QueryInterface : function(aIID) { 
    661                 if (aIID.equals(CI.nsIFactory)) { 
    662                         return this; 
    663                 } 
    664  
    665                 return NS_ERROR_NO_INTERFACE; 
    666         }, 
    667         createInstance: function (outer, iid) { 
    668                 if (outer != null) { 
    669                         throw NS_ERROR_NO_AGGREGATION; 
    670                 } 
    671                 if (FilterManager.implementsIID(iid)) { 
    672                         return FilterManager; 
    673                 } 
    674                 throw NS_ERROR_INVALID_ARG; 
    675         } 
    676 } 
    677534 
    678535// entrypoint 
    679536function NSGetModule(compMgr, fileSpec) { 
    680         return Module
     537        return new ServiceModule(FilterManager, true)
    681538} 
  • trunk/components/migrationService.js

    r751 r866  
    3535 * ***** END LICENSE BLOCK ***** */ 
    3636 
     37 
     38const Cc = Components.classes; 
     39const Ci = Components.interfaces; 
     40 
    3741function include(uri) { 
    38         CC["@mozilla.org/moz/jssubscript-loader;1"] 
    39                 .getService(CI.mozIJSSubScriptLoader) 
     42        Cc["@mozilla.org/moz/jssubscript-loader;1"] 
     43                .getService(Ci.mozIJSSubScriptLoader) 
    4044                .loadSubScript(uri); 
    4145} 
    42   
    43 const CC = Components.classes; 
    44 const CI = Components.interfaces; 
    45 const error = Components.utils.reportError; 
     46include("chrome://dta/content/common/module.js"); 
     47 
    4648 
    4749var MigrationService = { 
    48  
    49         // nsIClassInfo 
    50         classID: Components.ID("{F66539C8-2590-4e69-B189-F9F8595A7670}"), 
    51         contractID: "@downthemall.net/migration-service;1", 
    52         classDescription: "DownThemAll! Migration Service", 
    53         implementationLanguage: 0x02, 
    54         flags: (1 << 0) | (1 << 2), // SINGLETON | MAIN_THREAD_ONLY 
    55         classIDNoAlloc: this.classID, 
    56         getHelperForLanguage: function() { 
    57                 return null; 
    58         }, 
    59         getInterfaces: function(count) { 
    60                 // XXX 
    61                 count.value = 0; 
    62                 return null; 
    63         }, 
    64  
    65         implementsIID: function FM_implementID(iid) { 
    66                         return [ 
    67                                 CI.nsISupports, 
    68                                 CI.nsISupportsWeakReference, 
    69                                 CI.nsIWeakReference, 
    70                                 CI.nsIObserver, 
    71                                 CI.nsIClassInfo 
    72                         ].some(function(e) { return iid.equals(e); }); 
    73         }, 
    74  
    7550        _init: function MM_init() { 
    7651    // observer registration 
    77     CC['@mozilla.org/observer-service;1'] 
    78                         .getService(CI.nsIObserverService) 
     52    Cc['@mozilla.org/observer-service;1'] 
     53                        .getService(Ci.nsIObserverService) 
    7954                        .addObserver(this, "final-ui-startup", true); 
    8055        }, 
     
    8560                 
    8661                try { 
    87                         DTA_debug.logString("current " + DTA_VERSION); 
     62                        debug("current " + DTA_VERSION); 
    8863                        var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"] 
    8964                                .getService(Components.interfaces.nsIVersionComparator); 
     
    9368                                return; 
    9469                        } 
    95                         DTA_debug.logString("MigrationManager: migration started"); 
     70                        debug.logString("MigrationManager: migration started"); 
    9671                        if (vc.compare(lastVersion, "1.0a1") < 0) { 
    9772                                this._execute(['Prefs', 'DropDowns', 'Filters', 'Remove']); 
     
    11287                } 
    11388                catch(ex) { 
    114                         DTA_debug.log("MigrationManager:", ex); 
     89                        debug("MigrationManager:", ex); 
    11590                        try { 
    11691                                DTA_preferences.resetDTA("version"); 
     
    137112        // pre-1.0: convert prefs 
    138113        _migratePrefs: function MM_migratePrefs() { 
    139                 DTA_debug.logString("migrating prefs"); 
     114                debug("migrating prefs"); 
    140115                const toMigrate = [ 
    141116                        ['context.infophrases', 'infophrases', true], 
     
    183158        // pre 1.0: migrate Filters 
    184159        _migrateFilters: function MM_migrateFilters() { 
    185                 DTA_debug.log("migrating filters"); 
     160                debug("migrating filters"); 
    186161                const defFilters = [ 
    187162                        "/\./", "/\\./", '/(\\.*)/', 
     
    193168                        "/\\/[^\\/\\?]+\\.png$/" 
    194169                ]; 
    195                 const LINK_FILTER = CI.dtaIFilter.LINK_FILTER; 
    196                 const IMAGE_FILTER = CI.dtaIFilter.IMAGE_FILTER; 
    197                 const prefs = CC['@mozilla.org/preferences-service;1'] 
     170                const LINK_FILTER = Ci.dtaIFilter.LINK_FILTER; 
     171                const IMAGE_FILTER = Ci.dtaIFilter.IMAGE_FILTER; 
     172                const prefs = Cc['@mozilla.org/preferences-service;1'] 
    198173                        .getService(Components.interfaces.nsIPrefService) 
    199174                        .getBranch("extensions.dta.context.") 
     
    230205        // pre 1.0: dropdown history 
    231206        _migrateDropDowns: function MM_migrateDropdowns() { 
    232                 DTA_debug.logString("migrating dropdowns"); 
     207                debug("migrating dropdowns"); 
    233208                ['renaming', 'filter', 'directory'].forEach( 
    234209                        function(e) { 
     
    255230        }, 
    256231         
    257                 // nsiSupports 
    258         QueryInterface: function MM_QI(iid) { 
    259                 if (this.implementsIID(iid)) { 
    260                         return this; 
    261                 } 
    262                 throw Components.results.NS_ERROR_NO_INTERFACE; 
    263         }, 
    264  
    265         // nsiWeakReference 
    266         QueryReferent: function MM_QR(iid) { 
    267                 return this; 
    268         }, 
    269  
    270         // nsiSupportsWeakReference 
    271         GetWeakReference: function MM_GWR() { 
    272                 return this; 
    273         }, 
    274  
    275232        // nsIObserver 
    276233        observe: function MM_observe(subject, topic, prefName) { 
     
    280237        } 
    281238}; 
     239implementComponent( 
     240        MigrationService, 
     241        Components.ID("{F66539C8-2590-4e69-B189-F9F8595A7670}"), 
     242        "@downthemall.net/migration-service;1", 
     243        "DownThemAll! Migration Service", 
     244        [Ci.nsIObserver] 
     245); 
    282246MigrationService._init(); 
    283  
    284 var Module = { 
    285         _firstTime: true, 
    286  
    287         registerSelf: function M_registerSelf(compMgr, fileSpec, location, type) { 
    288                 if (!this._firstTime) { 
    289                         return; 
    290                 } 
    291                 this._firstTime = false; 
    292  
    293                 compMgr.QueryInterface(CI.nsIComponentRegistrar) 
    294                         .registerFactoryLocation( 
    295                                 MigrationService.classID, 
    296                                 MigrationService.classDescription, 
    297                                 MigrationService.contractID, 
    298                                 fileSpec, 
    299                                 location, 
    300                                 type 
    301                         ); 
    302                 CC['@mozilla.org/categorymanager;1'] 
    303                         .getService(CI.nsICategoryManager) 
    304                         .addCategoryEntry('app-startup', MigrationService.contractID, MigrationService.contractID, true, true, null); 
    305         }, 
    306         unregisterSelf: function(compMgr, fileSpec, location) { 
    307                 compMgr.QueryInterface(CI.nsIComponentRegistrar) 
    308                         .unregisterFactoryLocation( 
    309                                 MigrationService.classID, 
    310                                 fileSpec 
    311                         ); 
    312                 CC['@mozilla.org/categorymanager;1'] 
    313                         .getService(CI.nsICategoryManager) 
    314                         .deleteCategoryEntry('app-startup', MigrationService.contractID, true); 
    315         }, 
    316         getClassObject: function (compMgr, cid, iid) { 
    317                 if (cid.equals(MigrationService.classID)) { 
    318                         return this; 
    319                 } 
    320                 throw Components.results.NS_ERROR_NO_INTERFACE; 
    321         }, 
    322         canUnload: function(compMgr) { 
    323                 return true; 
    324         }, 
    325  
    326         // nsIFactory 
    327         QueryInterface : function(aIID) { 
    328                 if (aIID.equals(CI.nsIFactory)) { 
    329                         return this; 
    330                 } 
    331  
    332                 return Components.results.NS_ERROR_NO_INTERFACE; 
    333         }, 
    334         createInstance: function (outer, iid) { 
    335                 if (outer != null) { 
    336                         throw Components.results.NS_ERROR_NO_AGGREGATION; 
    337                 } 
    338                 if (MigrationService.implementsIID(iid)) { 
    339                         return MigrationService; 
    340                 } 
    341                 throw Components.results.NS_ERROR_INVALID_ARG; 
    342         } 
    343 } 
    344247 
    345248// entrypoint 
    346249function NSGetModule(compMgr, fileSpec) { 
    347         return Module
     250        return new ServiceModule(MigrationService, true)
    348251}