Bug 385524 - Reduce boilerplate code in passwordmgr. r=gavin/dolske

This commit is contained in:
rflint%ryanflint.com 2007-06-23 04:04:50 +00:00
Родитель 59d52c6f16
Коммит 2ca0301603
4 изменённых файлов: 43 добавлений и 275 удалений

Просмотреть файл

@ -38,17 +38,16 @@
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function nsLoginInfo() {} function nsLoginInfo() {}
nsLoginInfo.prototype = { nsLoginInfo.prototype = {
QueryInterface : function (iid) { classDescription : "LoginInfo",
var interfaces = [Ci.nsILoginInfo, Ci.nsISupports]; contractID : "@mozilla.org/login-manager/loginInfo;1",
if (!interfaces.some( function(v) { return iid.equals(v) } )) classID : Components.ID("{0f2f347c-1e4f-40cc-8efd-792dea70a85e}"),
throw Components.results.NS_ERROR_NO_INTERFACE; QueryInterface: XPCOMUtils.generateQI([Ci.nsILoginInfo]),
return this;
},
hostname : null, hostname : null,
formSubmitURL : null, formSubmitURL : null,
@ -104,58 +103,7 @@ nsLoginInfo.prototype = {
}; // end of nsLoginInfo implementation }; // end of nsLoginInfo implementation
var component = [nsLoginInfo];
// 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;
}
};
function NSGetModule(compMgr, fileSpec) { function NSGetModule(compMgr, fileSpec) {
return gModule; return XPCOMUtils.generateModule(component);
} }

Просмотреть файл

@ -38,19 +38,19 @@
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function LoginManager() { function LoginManager() {
this.init(); this.init();
} }
LoginManager.prototype = { LoginManager.prototype = {
QueryInterface : function (iid) { classDescription: "LoginManager",
const interfaces = [Ci.nsILoginManager, contractID: "@mozilla.org/login-manager;1",
Ci.nsISupports, Ci.nsISupportsWeakReference]; classID: Components.ID("{cb9e0de8-3598-4ed7-857b-827f011ad5d8}"),
if (!interfaces.some( function(v) { return iid.equals(v) } )) QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManager,
throw Components.results.NS_ERROR_NO_INTERFACE; Ci.nsISupportsWeakReference]),
return this;
},
/* ---------- private memebers ---------- */ /* ---------- private memebers ---------- */
@ -220,13 +220,9 @@ LoginManager.prototype = {
_observer : { _observer : {
_pwmgr : null, _pwmgr : null,
QueryInterface : function (iid) { QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver,
const interfaces = [Ci.nsIObserver, Ci.nsIFormSubmitObserver, Ci.nsIFormSubmitObserver,
Ci.nsISupports, Ci.nsISupportsWeakReference]; Ci.nsISupportsWeakReference]),
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
// nsFormSubmitObserver // nsFormSubmitObserver
@ -279,13 +275,8 @@ LoginManager.prototype = {
_pwmgr : null, _pwmgr : null,
_domEventListener : null, _domEventListener : null,
QueryInterface : function (iid) { QueryInterface : XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
const interfaces = [Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]),
Ci.nsISupports, Ci.nsISupportsWeakReference];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
onStateChange : function (aWebProgress, aRequest, onStateChange : function (aWebProgress, aRequest,
@ -339,13 +330,8 @@ LoginManager.prototype = {
_domEventListener : { _domEventListener : {
_pwmgr : null, _pwmgr : null,
QueryInterface : function (iid) { QueryInterface : XPCOMUtils.generateQI([Ci.nsIDOMEventListener,
const interfaces = [Ci.nsIDOMEventListener, Ci.nsISupportsWeakReference]),
Ci.nsISupports, Ci.nsISupportsWeakReference];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
handleEvent : function (event) { handleEvent : function (event) {
@ -1334,13 +1320,8 @@ function UserAutoCompleteResult (aSearchString, matchingLogins) {
} }
UserAutoCompleteResult.prototype = { UserAutoCompleteResult.prototype = {
QueryInterface : function (iid) { QueryInterface : XPCOMUtils.generateQI([Ci.nsIAutoCompleteResult,
const interfaces = [Ci.nsIAutoCompleteResult, Ci.nsISupportsWeakReference]),
Ci.nsISupports, Ci.nsISupportsWeakReference];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
// private // private
logins : null, logins : null,
@ -1384,60 +1365,7 @@ UserAutoCompleteResult.prototype = {
}, },
}; };
var component = [LoginManager];
// 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;
}
};
function NSGetModule (compMgr, fileSpec) { function NSGetModule (compMgr, fileSpec) {
return gModule; return XPCOMUtils.generateModule(component);
} }

Просмотреть файл

@ -38,6 +38,8 @@
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
/* /*
* LoginManagerPromptFactory * LoginManagerPromptFactory
* *
@ -50,12 +52,10 @@ function LoginManagerPromptFactory() {}
LoginManagerPromptFactory.prototype = { LoginManagerPromptFactory.prototype = {
QueryInterface : function (iid) { classDescription : "LoginManagerPromptFactory",
const interfaces = [Ci.nsIPromptFactory, Ci.nsISupports]; contractID : "@mozilla.org/passwordmanager/authpromptfactory;1",
if (!interfaces.some( function(v) { return iid.equals(v) } )) classID : Components.ID("{447fc780-1d28-412a-91a1-466d48129c65}"),
throw Components.results.NS_ERROR_NO_INTERFACE; QueryInterface : XPCOMUtils.generateQI([Ci.nsIPromptFactory]),
return this;
},
_promptService : null, _promptService : null,
_pwmgr : null, _pwmgr : null,
@ -106,13 +106,7 @@ LoginManagerPromptFactory.prototype = {
function LoginManagerPrompter() {} function LoginManagerPrompter() {}
LoginManagerPrompter.prototype = { LoginManagerPrompter.prototype = {
QueryInterface : function (iid) { QueryInterface : XPCOMUtils.generateQI([Ci.nsIAuthPrompt2]),
var interfaces = [Ci.nsIAuthPrompt2, Ci.nsISupports];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
__logService : null, // Console logging service, used for debugging. __logService : null, // Console logging service, used for debugging.
get _logService() { get _logService() {
@ -360,58 +354,7 @@ LoginManagerPrompter.prototype = {
} }
}; // end of LoginManagerPrompter implementation }; // end of LoginManagerPrompter implementation
var component = [LoginManagerPromptFactory];
// 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;
}
};
function NSGetModule(compMgr, fileSpec) { function NSGetModule(compMgr, fileSpec) {
return gModule; return XPCOMUtils.generateModule(component);
} }

Просмотреть файл

@ -38,16 +38,16 @@
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function LoginManagerStorage_legacy() { }; function LoginManagerStorage_legacy() { };
LoginManagerStorage_legacy.prototype = { LoginManagerStorage_legacy.prototype = {
QueryInterface : function (iid) { classDescription : "LoginManagerStorage_legacy",
const interfaces = [Ci.nsILoginManagerStorage, Ci.nsISupports]; contractID : "@mozilla.org/login-manager/storage/legacy;1",
if (!interfaces.some( function(v) { return iid.equals(v) } )) classID : Components.ID("{e09e4ca6-276b-4bb4-8b71-0635a3a2a007}"),
throw Components.results.NS_ERROR_NO_INTERFACE; QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManagerStorage]),
return this;
},
__logService : null, // Console logging service, used for debugging. __logService : null, // Console logging service, used for debugging.
get _logService() { get _logService() {
@ -678,58 +678,7 @@ LoginManagerStorage_legacy.prototype = {
}; // end of nsLoginManagerStorage_legacy implementation }; // end of nsLoginManagerStorage_legacy implementation
var component = [LoginManagerStorage_legacy];
// 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;
}
};
function NSGetModule(compMgr, fileSpec) { function NSGetModule(compMgr, fileSpec) {
return gModule; return XPCOMUtils.generateModule(component);
} }