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

This commit is contained in:
rflint@ryanflint.com 2007-06-22 21:04:50 -07:00
Родитель 883f3a00c3
Коммит 005081129f
4 изменённых файлов: 43 добавлений и 275 удалений

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

@ -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);
}

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

@ -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);
}

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

@ -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);
}

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

@ -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);
}