📄 nsforecastfox.js
字号:
* @param Component name. ******************************************************************************/function ServiceBase(aName){ this._name = aName; this._ifaces = [this.interfaceID, Ci.ffIService, Ci.nsIClassInfo, Ci.nsISupports]; this._bundle = getBundle(); this._branch = getBranch(false, null); }ServiceBase.prototype = { _name: null, _ifaces: null, _error: null, _bundle: null, _branch: null, //////////////////////////////// // nsISupports QueryInterface: function ServiceBase_QueryInterface(aIID) { var ifaces = this.getInterfaces({}); for (var i=0; i<ifaces.length; i++) { if (aIID.equals(ifaces[i])) return this; } throw Cr.NS_ERROR_NO_INTERFACE; }, //////////////////////////////// // nsIClassInfo getInterfaces: function ServiceBase_getInterfaces(aCount) { aCount.value = this._ifaces.length; return this._ifaces; }, getHelperForLanguage: function ServiceBase_getHelperForLanguage(aLanguage) { return null; }, get contractID() { return gComponents[this._name].contractID; }, get classID() { return gComponents[this._name].classID; }, get classDescription() { return gComponents[this._name].className; }, get implementationLanguage() { return Ci.nsIProgrammingLanguage.JAVASCRIPT; }, get flags() { return Ci.nsIClassInfo.SINGLETON; }, //////////////////////////////// // ffIService /** * Initialize the component. Called by the manager service. Returns false * if component could not be loaded. Chech the lastError property for * more information. */ start: function ServiceBase_start() { return true; }, /** * Destroy the component. Called by the manager service. This may be * called prior to start so it needs to be safe. */ stop: function ServiceBase_stop() {}, /** * Last error that occurred. */ get lastError() { return this._error; }, /** * The default string bundle. */ get bundle() { return this._bundle; }, /** * The default user prefernce branch. */ get branch() { return this._branch; }, //////////////////////////////// // Internal Functions /** * Helper property to get the main interface. */ get interfaceID() { return gComponents[this._name].interfaceID; } }; /****************************************************************************** * Make a component factory used in getClassObject of nsIModule interface. * * @param Component constructor. * @return an nsIFactory object. *****************************************************************************/ function makeFactory(aConstructor){ var factory = { QueryInterface: function factory_QueryInterface(aIID) { if (!aIID.equals(Ci.nsISupports) && !aIID.equals(Ci.nsIFactory)) throw Cr.NS_ERROR_NO_INTERFACE; return this; }, createInstance: function factory_createInstance(aOuter, aIID) { if (aOuter != null) throw Cr.NS_ERROR_NO_AGGREGATION; return (new aConstructor()).QueryInterface(aIID); }, lockFactory: function factory_lockFactory(aLock) { throw Cr.NS_ERROR_NOT_IMPLEMENTED; } }; //return the factory object return factory; }/****************************************************************************** * Load a components script. * * @param URL of the script file to load. *****************************************************************************/ function loadScript(aURL){ //get script loader var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. getService(Ci.mozIJSSubScriptLoader); //load the script loader.loadSubScript(aURL, null);} /****************************************************************************** * Registration data *****************************************************************************/var gComponents = { ErrorItem: { classID: Components.ID("{05B9426A-EC5D-4327-99B9-7926AD8491A1}"), className: "Forecastfox Error Item", contractID: "@ensolis.com/forecastfox/error-item;1", interfaceID: Ci.ffIErrorItem, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/utilities/error-item.js", constructor: "ErrorItem" }, DiskService: { classID: Components.ID("{4386D2C0-560C-45f9-A55F-413FEE243F3D}"), className: "Forecastfox Disk I/O Service", contractID: "@ensolis.com/forecastfox/disk-service;1", interfaceID: Ci.ffIDiskService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/utilities/disk-service.js", constructor: "DiskService" }, PingService: { classID: Components.ID("{0FF66E5D-62B3-4ed2-BF9B-21FCA2CBD357}"), className: "Forecastfox Ping Service", contractID: "@ensolis.com/forecastfox/ping-service;1", interfaceID: Ci.ffIPingService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/utilities/ping-service.js", constructor: "PingService" }, ResolverItem: { classID: Components.ID("{0B770FA3-40C6-4a37-806E-6A47E0FFADAE}"), className: "Forecastfox Namespace Resolver Item", contractID: "@ensolis.com/forecastfox/resolver-item;1", interfaceID: Ci.nsIDOMXPathNSResolver, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/parser/resolver-item.js", constructor: "ResolverItem" }, ConverterItem: { classID: Components.ID("{A8102480-27EA-432a-AC68-5161B3E45CC0}"), className: "Forecastfox Converter Item", contractID: "@ensolis.com/forecastfox/converter-item;1", interfaceID: Ci.ffIConverterItem, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/parser/converter-item.js", constructor: "ConverterItem" }, ConverterService: { classID: Components.ID("{0DEC2682-40DB-4b51-A1E5-085991D800D9}"), className: "Forecastfox Converter Service", contractID: "@ensolis.com/forecastfox/converter-service;1", interfaceID: Ci.ffIConverterService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/parser/converter-service.js", constructor: "ConverterService" }, ParserItem: { classID: Components.ID("{FC48D906-4F00-4ee0-A035-DEE0CE5AFB9D}"), className: "Forecastfox Parser Item", contractID: "@ensolis.com/forecastfox/parser-item;1", interfaceID: Ci.ffIParserItem, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/parser/parser-item.js", constructor: "ParserItem" }, ParserService: { classID: Components.ID("{1CE4E984-6F2A-4ac8-BE74-8E47C0F4B445}"), className: "Forecastfox Parser Service", contractID: "@ensolis.com/forecastfox/parser-service;1", interfaceID: Ci.ffIParserService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/parser/parser-service.js", constructor: "ParserService" }, ProfileItem: { classID: Components.ID("{F41536F9-D435-42fe-A362-32217C972418}"), className: "Forecastfox Profile Item", contractID: "@ensolis.com/forecastfox/profile-item;1", interfaceID: Ci.ffIProfileItem, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/profiles/profile-item.js", constructor: "ProfileItem" }, ProfileService: { classID: Components.ID("{01F8B6C4-F9E1-4dc8-A980-5A9985CD4111}"), className: "Forecastfox Profile Service", contractID: "@ensolis.com/forecastfox/profile-service;1", interfaceID: Ci.ffIProfileService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/profiles/profile-service.js", constructor: "ProfileService" }, MigratorService: { classID: Components.ID("{E938FEBC-166F-498c-A35E-654BB0E2DE7E}"), className: "Forecastfox Migrator Service", contractID: "@ensolis.com/forecastfox/migrator-service;1", interfaceID: Ci.ffIMigratorService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/profiles/migrator-service.js", constructor: "MigratorService" }, IconItem: { classID: Components.ID("{B1DB225E-C16C-452f-B042-F917732D9C2E}"), className: "Forecastfox Icon Item", contractID: "@ensolis.com/forecastfox/icon-item;1", interfaceID: Ci.ffIIconItem, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/icons/icon-item.js", constructor: "IconItem" }, PackItem: { classID: Components.ID("{0666DE3E-4F11-4e0f-9154-894DAA76CC6E}"), className: "Forecastfox Pack Item", contractID: "@ensolis.com/forecastfox/pack-item;1", interfaceID: Ci.ffIPackItem, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/icons/pack-item.js", constructor: "PackItem" }, PackService: { classID: Components.ID("{0AC191C4-F5C5-4590-B95D-46602B430598}"), className: "Forecastfox Icon Pack Service", contractID: "@ensolis.com/forecastfox/pack-service;1", interfaceID: Ci.ffIPackService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/icons/pack-service.js", constructor: "PackService" }, WebService: { classID: Components.ID("{9172437D-0D7D-4f86-B3E9-0D57AAFA541C}"), className: "Forecastfox Web Service", contractID: "@ensolis.com/forecastfox/web-service;1", interfaceID: Ci.ffIWebService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/icons/web-service.js", constructor: "WebService", category: "JavaScript global property", entry: "forecastfox" }, ManagerService: { classID: Components.ID("{5ADF9E4D-EAA6-4223-853D-D932060094E0}"), className: "Forecastfox Manager Service", contractID: "@ensolis.com/forecastfox/manager-service;1", interfaceID: Ci.ffIManagerService, scriptLoaded: false, scriptURL: "chrome://forecastfox/content/utilities/manager-service.js", constructor: "ManagerService" } };/****************************************************************************** * Object that implements the nsIModule interface *****************************************************************************/var gModule = { registerSelf: function gModule_registerSelf(aCompMgr, aFileSpec, aLocation, aType) { //get the component registrar var compMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar); //get the category manager var catMgr = Cc["@mozilla.org/categorymanager;1"]. getService(Ci.nsICategoryManager); //loop through components registration data for (var name in gComponents) { var comp = gComponents[name]; //register factory location compMgr.registerFactoryLocation(comp.classID, comp.className, comp.contractID, aFileSpec, aLocation, aType); //register category if (comp.hasOwnProperty("category")) catMgr.addCategoryEntry(comp.category, comp.entry, comp.contractID, true, true); } }, unregisterSelf: function gModule_unregisterSelf(aCompMgr, aLocation, aType) { //get the component registrar var compMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar); //get the category manager var catMgr = Cc["@mozilla.org/categorymanager;1"]. getService(Ci.nsICategoryManager); //loop through components registration data for (var name in gComponents) { var comp = gComponents[name]; //unregister factory location compMgr.unregisterFactoryLocation(comp.classID, aLocation); //unregister category if (comp.hasOwnProperty("category")) catMgr.deleteCategoryEntry(comp.category, comp.entry, comp.contractID, true); } }, getClassObject: function gModule_getClassObject(aCompMgr, aCID, aIID) { //throw if not requesting a factory if (!aIID.equals(Ci.nsIFactory)) throw Cr.NS_ERROR_NOT_IMPLEMENTED; //loop through components registration data for (var name in gComponents) { var comp = gComponents[name]; //component matches if (aCID.equals(comp.classID)) { //load the script if it isn't loaded if (!comp.scriptLoaded) { loadScript(comp.scriptURL); comp.scriptLoaded = true; } //return factory return makeFactory(eval(comp.constructor)); } } //throw if not found throw Cr.NS_ERROR_NO_INTERFACE; }, canUnload: function gModule_canUnload(compMgr) { return true; }};/****************************************************************************** * Module entry point *****************************************************************************/function NSGetModule(compMgr, fileSpec) { return gModule;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -