From f4e76aabec0318d7fef48e2b4c8253e841c30437 Mon Sep 17 00:00:00 2001 From: "rflint%ryanflint.com" Date: Sat, 23 Jun 2007 04:04:50 +0000 Subject: [PATCH] Bug 385524 - Reduce boilerplate code in passwordmgr. r=gavin/dolske git-svn-id: svn://10.0.0.236/trunk@228615 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/passwordmgr/src/nsLoginInfo.js | 68 ++--------- .../passwordmgr/src/nsLoginManager.js | 108 +++--------------- .../passwordmgr/src/nsLoginManagerPrompter.js | 75 ++---------- .../passwordmgr/src/storage-Legacy.js | 67 ++--------- 4 files changed, 43 insertions(+), 275 deletions(-) diff --git a/mozilla/toolkit/components/passwordmgr/src/nsLoginInfo.js b/mozilla/toolkit/components/passwordmgr/src/nsLoginInfo.js index d4ccdbc1a18..9841f6caf5f 100644 --- a/mozilla/toolkit/components/passwordmgr/src/nsLoginInfo.js +++ b/mozilla/toolkit/components/passwordmgr/src/nsLoginInfo.js @@ -38,17 +38,16 @@ const Cc = Components.classes; const Ci = Components.interfaces; +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + function nsLoginInfo() {} nsLoginInfo.prototype = { - QueryInterface : function (iid) { - var interfaces = [Ci.nsILoginInfo, Ci.nsISupports]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, - + classDescription : "LoginInfo", + contractID : "@mozilla.org/login-manager/loginInfo;1", + classID : Components.ID("{0f2f347c-1e4f-40cc-8efd-792dea70a85e}"), + QueryInterface: XPCOMUtils.generateQI([Ci.nsILoginInfo]), hostname : null, formSubmitURL : null, @@ -104,58 +103,7 @@ nsLoginInfo.prototype = { }; // end of nsLoginInfo implementation - - - -// Boilerplate code for component registration... -var gModule = { - registerSelf: function(componentManager, fileSpec, location, type) { - componentManager = componentManager.QueryInterface( - Ci.nsIComponentRegistrar); - for each (var obj in this._objects) - componentManager.registerFactoryLocation(obj.CID, - obj.className, obj.contractID, - fileSpec, location, type); - }, - - unregisterSelf: function (componentManager, location, type) { - for each (var obj in this._objects) - componentManager.unregisterFactoryLocation(obj.CID, location); - }, - - getClassObject: function(componentManager, cid, iid) { - if (!iid.equals(Ci.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - for (var key in this._objects) { - if (cid.equals(this._objects[key].CID)) - return this._objects[key].factory; - } - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - _objects: { - service: { - CID : Components.ID("{0f2f347c-1e4f-40cc-8efd-792dea70a85e}"), - contractID : "@mozilla.org/login-manager/loginInfo;1", - className : "LoginInfo", - factory : LoginInfoFactory = { - createInstance: function(aOuter, aIID) { - if (aOuter != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - var svc = new nsLoginInfo(); - return svc.QueryInterface(aIID); - } - } - } - }, - - canUnload: function(componentManager) { - return true; - } -}; - +var component = [nsLoginInfo]; function NSGetModule(compMgr, fileSpec) { - return gModule; + return XPCOMUtils.generateModule(component); } diff --git a/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js b/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js index e643fd19db9..253d168baa2 100644 --- a/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js +++ b/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js @@ -38,19 +38,19 @@ const Cc = Components.classes; const Ci = Components.interfaces; +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + function LoginManager() { this.init(); } LoginManager.prototype = { - QueryInterface : function (iid) { - const interfaces = [Ci.nsILoginManager, - Ci.nsISupports, Ci.nsISupportsWeakReference]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + classDescription: "LoginManager", + contractID: "@mozilla.org/login-manager;1", + classID: Components.ID("{cb9e0de8-3598-4ed7-857b-827f011ad5d8}"), + QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManager, + Ci.nsISupportsWeakReference]), /* ---------- private memebers ---------- */ @@ -220,13 +220,9 @@ LoginManager.prototype = { _observer : { _pwmgr : null, - QueryInterface : function (iid) { - const interfaces = [Ci.nsIObserver, Ci.nsIFormSubmitObserver, - Ci.nsISupports, Ci.nsISupportsWeakReference]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver, + Ci.nsIFormSubmitObserver, + Ci.nsISupportsWeakReference]), // nsFormSubmitObserver @@ -279,13 +275,8 @@ LoginManager.prototype = { _pwmgr : null, _domEventListener : null, - QueryInterface : function (iid) { - const interfaces = [Ci.nsIWebProgressListener, - Ci.nsISupports, Ci.nsISupportsWeakReference]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + QueryInterface : XPCOMUtils.generateQI([Ci.nsIWebProgressListener, + Ci.nsISupportsWeakReference]), onStateChange : function (aWebProgress, aRequest, @@ -339,13 +330,8 @@ LoginManager.prototype = { _domEventListener : { _pwmgr : null, - QueryInterface : function (iid) { - const interfaces = [Ci.nsIDOMEventListener, - Ci.nsISupports, Ci.nsISupportsWeakReference]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + QueryInterface : XPCOMUtils.generateQI([Ci.nsIDOMEventListener, + Ci.nsISupportsWeakReference]), handleEvent : function (event) { @@ -1334,13 +1320,8 @@ function UserAutoCompleteResult (aSearchString, matchingLogins) { } UserAutoCompleteResult.prototype = { - QueryInterface : function (iid) { - const interfaces = [Ci.nsIAutoCompleteResult, - Ci.nsISupports, Ci.nsISupportsWeakReference]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + QueryInterface : XPCOMUtils.generateQI([Ci.nsIAutoCompleteResult, + Ci.nsISupportsWeakReference]), // private logins : null, @@ -1384,60 +1365,7 @@ UserAutoCompleteResult.prototype = { }, }; - - - -// Boilerplate code for component registration... -var gModule = { - registerSelf: function (componentManager, fileSpec, location, type) { - componentManager = componentManager.QueryInterface( - Ci.nsIComponentRegistrar); - for each (var obj in this._objects) - componentManager.registerFactoryLocation(obj.CID, - obj.className, obj.contractID, - fileSpec, location, type); - }, - - unregisterSelf: function (componentManager, location, type) { - for each (var obj in this._objects) - componentManager.unregisterFactoryLocation(obj.CID, location); - }, - - getClassObject: function (componentManager, cid, iid) { - if (!iid.equals(Ci.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - for (var key in this._objects) { - if (cid.equals(this._objects[key].CID)) - return this._objects[key].factory; - } - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - _objects: { - service: { - CID : Components.ID("{cb9e0de8-3598-4ed7-857b-827f011ad5d8}"), - contractID : "@mozilla.org/login-manager;1", - className : "LoginManager", - factory : LoginManagerFactory = { - createInstance: function (aOuter, aIID) { - if (aOuter != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - var svc = new LoginManager(); - - return svc.QueryInterface(aIID); - } - } - } - }, - - canUnload: function (componentManager) { - return true; - } -}; - +var component = [LoginManager]; function NSGetModule (compMgr, fileSpec) { - return gModule; + return XPCOMUtils.generateModule(component); } diff --git a/mozilla/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js b/mozilla/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js index d62971099f8..090711447b0 100644 --- a/mozilla/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js +++ b/mozilla/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js @@ -38,6 +38,8 @@ const Cc = Components.classes; const Ci = Components.interfaces; +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + /* * LoginManagerPromptFactory * @@ -50,12 +52,10 @@ function LoginManagerPromptFactory() {} LoginManagerPromptFactory.prototype = { - QueryInterface : function (iid) { - const interfaces = [Ci.nsIPromptFactory, Ci.nsISupports]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + classDescription : "LoginManagerPromptFactory", + contractID : "@mozilla.org/passwordmanager/authpromptfactory;1", + classID : Components.ID("{447fc780-1d28-412a-91a1-466d48129c65}"), + QueryInterface : XPCOMUtils.generateQI([Ci.nsIPromptFactory]), _promptService : null, _pwmgr : null, @@ -106,13 +106,7 @@ LoginManagerPromptFactory.prototype = { function LoginManagerPrompter() {} LoginManagerPrompter.prototype = { - QueryInterface : function (iid) { - var interfaces = [Ci.nsIAuthPrompt2, Ci.nsISupports]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, - + QueryInterface : XPCOMUtils.generateQI([Ci.nsIAuthPrompt2]), __logService : null, // Console logging service, used for debugging. get _logService() { @@ -360,58 +354,7 @@ LoginManagerPrompter.prototype = { } }; // end of LoginManagerPrompter implementation - - - -// Boilerplate code... -var gModule = { - registerSelf: function(componentManager, fileSpec, location, type) { - componentManager = componentManager.QueryInterface( - Ci.nsIComponentRegistrar); - for each (var obj in this._objects) - componentManager.registerFactoryLocation(obj.CID, - obj.className, obj.contractID, - fileSpec, location, type); - }, - - unregisterSelf: function (componentManager, location, type) { - for each (var obj in this._objects) - componentManager.unregisterFactoryLocation(obj.CID, location); - }, - - getClassObject: function(componentManager, cid, iid) { - if (!iid.equals(Ci.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - for (var key in this._objects) { - if (cid.equals(this._objects[key].CID)) - return this._objects[key].factory; - } - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - _objects: { - service: { - CID : Components.ID("{447fc780-1d28-412a-91a1-466d48129c65}"), - contractID : "@mozilla.org/passwordmanager/authpromptfactory;1", - className : "LoginManagerPromptFactory", - factory : LoginManagerPromptFactory_Factory = { - createInstance: function (aOuter, aIID) { - if (aOuter != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - return new LoginManagerPromptFactory().QueryInterface(aIID); - } - } - } - }, - - canUnload: function(componentManager) { - return true; - } -}; - +var component = [LoginManagerPromptFactory]; function NSGetModule(compMgr, fileSpec) { - return gModule; + return XPCOMUtils.generateModule(component); } diff --git a/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js b/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js index b0ad68f6a46..d6651b93e99 100644 --- a/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js +++ b/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js @@ -38,16 +38,16 @@ const Cc = Components.classes; const Ci = Components.interfaces; +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + function LoginManagerStorage_legacy() { }; LoginManagerStorage_legacy.prototype = { - QueryInterface : function (iid) { - const interfaces = [Ci.nsILoginManagerStorage, Ci.nsISupports]; - if (!interfaces.some( function(v) { return iid.equals(v) } )) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; - }, + classDescription : "LoginManagerStorage_legacy", + contractID : "@mozilla.org/login-manager/storage/legacy;1", + classID : Components.ID("{e09e4ca6-276b-4bb4-8b71-0635a3a2a007}"), + QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManagerStorage]), __logService : null, // Console logging service, used for debugging. get _logService() { @@ -678,58 +678,7 @@ LoginManagerStorage_legacy.prototype = { }; // end of nsLoginManagerStorage_legacy implementation - - - -// Boilerplate code for component registration... -var gModule = { - registerSelf: function(componentManager, fileSpec, location, type) { - componentManager = componentManager.QueryInterface( - Ci.nsIComponentRegistrar); - for each (var obj in this._objects) - componentManager.registerFactoryLocation(obj.CID, - obj.className, obj.contractID, - fileSpec, location, type); - }, - - unregisterSelf: function (componentManager, location, type) { - for each (var obj in this._objects) - componentManager.unregisterFactoryLocation(obj.CID, location); - }, - - getClassObject: function(componentManager, cid, iid) { - if (!iid.equals(Ci.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - for (var key in this._objects) { - if (cid.equals(this._objects[key].CID)) - return this._objects[key].factory; - } - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - _objects: { - service: { - CID : Components.ID("{e09e4ca6-276b-4bb4-8b71-0635a3a2a007}"), - contractID : "@mozilla.org/login-manager/storage/legacy;1", - className : "LoginManagerStorage_legacy", - factory : aFactory = { - createInstance: function(aOuter, aIID) { - if (aOuter != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - var svc = new LoginManagerStorage_legacy(); - return svc.QueryInterface(aIID); - } - } - } - }, - - canUnload: function(componentManager) { - return true; - } -}; - +var component = [LoginManagerStorage_legacy]; function NSGetModule(compMgr, fileSpec) { - return gModule; + return XPCOMUtils.generateModule(component); }