Bug 551851 - Add Services.jsm goodness to login manager. r=zpao, r=vlad

This commit is contained in:
Justin Dolske 2010-03-11 18:25:00 -08:00
parent 6958a34b67
commit b624180ee3
5 changed files with 35 additions and 136 deletions

View File

@ -40,6 +40,7 @@ const Ci = Components.interfaces;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
function LoginManagerCrypto_SDR() {
this.init();
@ -52,14 +53,6 @@ LoginManagerCrypto_SDR.prototype = {
classID : Components.ID("{dc6c2976-0f73-4f1f-b9ff-3d72b4e28309}"),
QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManagerCrypto]),
__logService : null, // Console logging service, used for debugging.
get _logService() {
if (!this.__logService)
this.__logService = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
return this.__logService;
},
__decoderRing : null, // nsSecretDecoderRing service
get _decoderRing() {
if (!this.__decoderRing)
@ -82,14 +75,6 @@ LoginManagerCrypto_SDR.prototype = {
this.__utfConverter = null;
},
__observerService : null,
get _observerService() {
if (!this.__observerService)
this.__observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
return this.__observerService;
},
_debug : false, // mirrors signon.debug
@ -102,15 +87,13 @@ LoginManagerCrypto_SDR.prototype = {
if (!this._debug)
return;
dump("PwMgr cryptoSDR: " + message + "\n");
this._logService.logStringMessage("PwMgr cryptoSDR: " + message);
Services.console.logStringMessage("PwMgr cryptoSDR: " + message);
},
init : function () {
// Connect to the correct preferences branch.
this._prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
this._prefBranch = this._prefBranch.getBranch("signon.");
this._prefBranch = Services.prefs.getBranch("signon.");
this._prefBranch.QueryInterface(Ci.nsIPrefBranch2);
this._debug = this._prefBranch.getBoolPref("debug");

View File

@ -40,6 +40,7 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
function LoginManager() {
this.init();
@ -57,24 +58,6 @@ LoginManager.prototype = {
/* ---------- private memebers ---------- */
__logService : null, // Console logging service, used for debugging.
get _logService() {
if (!this.__logService)
this.__logService = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
return this.__logService;
},
__ioService: null, // IO service for string -> nsIURI conversion
get _ioService() {
if (!this.__ioService)
this.__ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
return this.__ioService;
},
__formFillService : null, // FormFillController, for username autocompleting
get _formFillService() {
if (!this.__formFillService)
@ -85,15 +68,6 @@ LoginManager.prototype = {
},
__observerService : null, // Observer Service, for notifications
get _observerService() {
if (!this.__observerService)
this.__observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
return this.__observerService;
},
__storage : null, // Storage component which contains the saved logins
get _storage() {
if (!this.__storage) {
@ -173,8 +147,7 @@ LoginManager.prototype = {
this._observer._pwmgr = this;
// Preferences. Add observer so we get notified of changes.
this._prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).getBranch("signon.");
this._prefBranch = Services.prefs.getBranch("signon.");
this._prefBranch.QueryInterface(Ci.nsIPrefBranch2);
this._prefBranch.addObserver("", this._observer, false);
@ -190,8 +163,8 @@ LoginManager.prototype = {
// Form submit observer checks forms for new logins and pw changes.
this._observerService.addObserver(this._observer, "earlyformsubmit", false);
this._observerService.addObserver(this._observer, "xpcom-shutdown", false);
Services.obs.addObserver(this._observer, "earlyformsubmit", false);
Services.obs.addObserver(this._observer, "xpcom-shutdown", false);
// WebProgressListener for getting notification of new doc loads.
var progress = Cc["@mozilla.org/docloaderservice;1"].
@ -212,7 +185,7 @@ LoginManager.prototype = {
if (!this._debug)
return;
dump("Login Manager: " + message + "\n");
this._logService.logStringMessage("Login Manager: " + message);
Services.console.logStringMessage("Login Manager: " + message);
},
@ -960,7 +933,7 @@ LoginManager.prototype = {
_getPasswordOrigin : function (uriString, allowJS) {
var realm = "";
try {
var uri = this._ioService.newURI(uriString, null, null);
var uri = Services.io.newURI(uriString, null, null);
if (allowJS && uri.scheme == "javascript")
return "javascript:"
@ -971,7 +944,7 @@ LoginManager.prototype = {
// it's not the default. (We never want "http://foo.com:80")
var port = uri.port;
if (port != -1) {
var handler = this._ioService.getProtocolHandler(uri.scheme);
var handler = Services.io.getProtocolHandler(uri.scheme);
if (port != handler.defaultPort)
realm += ":" + port;
}
@ -1192,13 +1165,13 @@ LoginManager.prototype = {
// For when autofillForm is false, but we still have the information
// to fill a form, we notify observers.
didntFillReason = "noAutofillForms";
this._observerService.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
Services.obs.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
this.log("autofillForms=false but form can be filled; notified observers");
} else if (selectedLogin && isFormDisabled) {
// For when autocomplete is off, but we still have the information
// to fill a form, we notify observers.
didntFillReason = "autocompleteOff";
this._observerService.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
Services.obs.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
this.log("autocomplete=off but form can be filled; notified observers");
}
@ -1259,9 +1232,7 @@ LoginManager.prototype = {
formInfo.setProperty("foundLogins", foundLogins.concat());
formInfo.setPropertyAsInterface("selectedLogin", selectedLogin);
this._observerService.notifyObservers(formInfo,
"passwordmgr-found-logins",
null);
Services.obs.notifyObservers(formInfo, "passwordmgr-found-logins", null);
},
/*

View File

@ -41,6 +41,7 @@ const Ci = Components.interfaces;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
/*
* LoginManagerPromptFactory
@ -51,9 +52,7 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
* [embedding/components/windowwatcher/src/nsPrompt.cpp]
*/
function LoginManagerPromptFactory() {
var observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
observerService.addObserver(this, "quit-application-granted", true);
Services.obs.addObserver(this, "quit-application-granted", true);
}
LoginManagerPromptFactory.prototype = {
@ -67,22 +66,6 @@ LoginManagerPromptFactory.prototype = {
_asyncPrompts : {},
_asyncPromptInProgress : false,
__logService : null, // Console logging service, used for debugging.
get _logService() {
if (!this.__logService)
this.__logService = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
return this.__logService;
},
__threadManager: null,
get _threadManager() {
if (!this.__threadManager)
this.__threadManager = Cc["@mozilla.org/thread-manager;1"].
getService(Ci.nsIThreadManager);
return this.__threadManager;
},
observe : function (subject, topic, data) {
if (topic == "quit-application-granted") {
var asyncPrompts = this._asyncPrompts;
@ -101,8 +84,7 @@ LoginManagerPromptFactory.prototype = {
},
getPrompt : function (aWindow, aIID) {
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).getBranch("signon.");
var prefBranch = Services.prefs.getBranch("signon.");
this._debug = prefBranch.getBoolPref("debug");
var prompt = new LoginManagerPrompter().QueryInterface(aIID);
@ -164,7 +146,7 @@ LoginManagerPromptFactory.prototype = {
}
}
this._threadManager.mainThread.dispatch(runnable, Ci.nsIThread.DISPATCH_NORMAL);
Services.tm.mainThread.dispatch(runnable, Ci.nsIThread.DISPATCH_NORMAL);
this.log("_doAsyncPrompt:run dispatched");
},
@ -173,7 +155,7 @@ LoginManagerPromptFactory.prototype = {
return;
dump("Pwmgr PromptFactory: " + message + "\n");
this._logService.logStringMessage("Pwmgr PrompFactory: " + message);
Services.console.logStringMessage("Pwmgr PrompFactory: " + message);
}
}; // end of LoginManagerPromptFactory implementation
@ -221,14 +203,6 @@ LoginManagerPrompter.prototype = {
return this.__pwmgr;
},
__logService : null, // Console logging service, used for debugging.
get _logService() {
if (!this.__logService)
this.__logService = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
return this.__logService;
},
__promptService : null, // Prompt service for user interaction
get _promptService() {
if (!this.__promptService)
@ -269,24 +243,13 @@ LoginManagerPrompter.prototype = {
},
__ioService: null, // IO service for string -> nsIURI conversion
get _ioService() {
if (!this.__ioService)
this.__ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
return this.__ioService;
},
__ellipsis : null,
get _ellipsis() {
if (!this.__ellipsis) {
this.__ellipsis = "\u2026";
try {
var prefSvc = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
this.__ellipsis = prefSvc.getComplexValue("intl.ellipsis",
Ci.nsIPrefLocalizedString).data;
this.__ellipsis = Services.prefs.getComplexValue(
"intl.ellipsis", Ci.nsIPrefLocalizedString).data;
} catch (e) { }
}
return this.__ellipsis;
@ -316,7 +279,7 @@ LoginManagerPrompter.prototype = {
return;
dump("Pwmgr Prompter: " + message + "\n");
this._logService.logStringMessage("Pwmgr Prompter: " + message);
Services.console.logStringMessage("Pwmgr Prompter: " + message);
},
@ -535,7 +498,7 @@ LoginManagerPrompter.prototype = {
if (httpRealm.test(aRealmString))
return [null, null, null];
var uri = this._ioService.newURI(aRealmString, null, null);
var uri = Services.io.newURI(aRealmString, null, null);
var pathname = "";
if (uri.path != "/")
@ -733,8 +696,7 @@ LoginManagerPrompter.prototype = {
this._window = aWindow;
this._factory = aFactory || null;
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).getBranch("signon.");
var prefBranch = Services.prefs.getBranch("signon.");
this._debug = prefBranch.getBoolPref("debug");
this.log("===== initialized =====");
},
@ -1239,7 +1201,7 @@ LoginManagerPrompter.prototype = {
if (aURI instanceof Ci.nsIURI) {
uri = aURI;
} else {
uri = this._ioService.newURI(aURI, null, null);
uri = Services.io.newURI(aURI, null, null);
}
var scheme = uri.scheme;
@ -1249,7 +1211,7 @@ LoginManagerPrompter.prototype = {
// it's not the default. (We never want "http://foo.com:80")
port = uri.port;
if (port != -1) {
var handler = this._ioService.getProtocolHandler(scheme);
var handler = Services.io.getProtocolHandler(scheme);
if (port != handler.defaultPort)
hostname += ":" + port;
}
@ -1273,7 +1235,7 @@ LoginManagerPrompter.prototype = {
var idnService = Cc["@mozilla.org/network/idn-service;1"].
getService(Ci.nsIIDNService);
try {
var uri = this._ioService.newURI(aURIString, null, null);
var uri = Services.io.newURI(aURIString, null, null);
var baseDomain = eTLDService.getBaseDomain(uri);
displayHost = idnService.convertToDisplayIDN(baseDomain, {});
} catch (e) {

View File

@ -48,6 +48,7 @@ const ENCTYPE_BASE64 = 0;
const ENCTYPE_SDR = 1;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
function LoginManagerStorage_mozStorage() { };
@ -58,14 +59,6 @@ LoginManagerStorage_mozStorage.prototype = {
classID : Components.ID("{8c2023b9-175c-477e-9761-44ae7b549756}"),
QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManagerStorage]),
__logService : null, // Console logging service, used for debugging.
get _logService() {
if (!this.__logService)
this.__logService = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
return this.__logService;
},
__crypto : null, // nsILoginManagerCrypto service
get _crypto() {
if (!this.__crypto)
@ -77,9 +70,7 @@ LoginManagerStorage_mozStorage.prototype = {
__profileDir: null, // nsIFile for the user's profile dir
get _profileDir() {
if (!this.__profileDir)
this.__profileDir = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("ProfD", Ci.nsIFile);
this.__profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
return this.__profileDir;
},
@ -99,14 +90,6 @@ LoginManagerStorage_mozStorage.prototype = {
return this.__uuidService;
},
__observerService : null,
get _observerService() {
if (!this.__observerService)
this.__observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
return this.__observerService;
},
// The current database schema.
_dbSchema: {
@ -168,7 +151,7 @@ LoginManagerStorage_mozStorage.prototype = {
if (!this._debug)
return;
dump("PwMgr mozStorage: " + message + "\n");
this._logService.logStringMessage("PwMgr mozStorage: " + message);
Services.console.logStringMessage("PwMgr mozStorage: " + message);
},
@ -199,11 +182,7 @@ LoginManagerStorage_mozStorage.prototype = {
this._dbStmts = [];
// Connect to the correct preferences branch.
this._prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
this._prefBranch = this._prefBranch.getBranch("signon.");
this._prefBranch.QueryInterface(Ci.nsIPrefBranch2);
this._prefBranch = Services.prefs.getBranch("signon.");
this._debug = this._prefBranch.getBoolPref("debug");
let isFirstRun;
@ -747,7 +726,7 @@ LoginManagerStorage_mozStorage.prototype = {
createInstance(Ci.nsISupportsString);
dataObject.data = data;
}
this._observerService.notifyObservers(dataObject, "passwordmgr-storage-changed", changeType);
Services.obs.notifyObservers(dataObject, "passwordmgr-storage-changed", changeType);
},

View File

@ -108,3 +108,7 @@ XPCOMUtils.defineLazyServiceGetter(Services, "ww",
XPCOMUtils.defineLazyServiceGetter(Services, "tm",
"@mozilla.org/thread-manager;1",
"nsIThreadManager");
XPCOMUtils.defineLazyServiceGetter(Services, "console",
"@mozilla.org/consoleservice;1",
"nsIConsoleService");