2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-05-16 03:02:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2008-03-02 04:24:24 -08:00
|
|
|
const Cr = Components.results;
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-06-30 18:41:33 -07:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-03-11 18:25:00 -08:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2007-06-30 18:41:33 -07:00
|
|
|
|
2007-05-16 03:02:45 -07:00
|
|
|
/*
|
|
|
|
* LoginManagerPromptFactory
|
|
|
|
*
|
|
|
|
* Implements nsIPromptFactory
|
|
|
|
*
|
2010-06-16 17:06:17 -07:00
|
|
|
* Invoked by [toolkit/components/prompts/src/nsPrompter.js]
|
2007-05-16 03:02:45 -07:00
|
|
|
*/
|
2009-07-20 11:29:41 -07:00
|
|
|
function LoginManagerPromptFactory() {
|
2010-03-11 18:25:00 -08:00
|
|
|
Services.obs.addObserver(this, "quit-application-granted", true);
|
2010-08-02 16:02:20 -07:00
|
|
|
Services.obs.addObserver(this, "passwordmgr-crypto-login", true);
|
|
|
|
Services.obs.addObserver(this, "passwordmgr-crypto-loginCanceled", true);
|
2009-07-20 11:29:41 -07:00
|
|
|
}
|
2007-05-16 03:02:45 -07:00
|
|
|
|
|
|
|
LoginManagerPromptFactory.prototype = {
|
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
classID : Components.ID("{749e62f4-60ae-4569-a8a2-de78b649660e}"),
|
2009-07-20 11:29:41 -07:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|
|
|
|
2010-02-18 13:43:20 -08:00
|
|
|
_debug : false,
|
2009-07-20 11:29:41 -07:00
|
|
|
_asyncPrompts : {},
|
|
|
|
_asyncPromptInProgress : false,
|
|
|
|
|
|
|
|
observe : function (subject, topic, data) {
|
2010-08-02 16:02:20 -07:00
|
|
|
this.log("Observed: " + topic);
|
2009-07-20 11:29:41 -07:00
|
|
|
if (topic == "quit-application-granted") {
|
2010-08-02 16:02:20 -07:00
|
|
|
this._cancelPendingPrompts();
|
|
|
|
} else if (topic == "passwordmgr-crypto-login") {
|
|
|
|
// Start processing the deferred prompters.
|
|
|
|
this._doAsyncPrompt();
|
|
|
|
} else if (topic == "passwordmgr-crypto-loginCanceled") {
|
|
|
|
// User canceled a Master Password prompt, so go ahead and cancel
|
|
|
|
// all pending auth prompts to avoid nagging over and over.
|
|
|
|
this._cancelPendingPrompts();
|
2009-07-20 11:29:41 -07:00
|
|
|
}
|
|
|
|
},
|
2007-05-16 03:02:45 -07:00
|
|
|
|
|
|
|
getPrompt : function (aWindow, aIID) {
|
2010-03-11 18:25:00 -08:00
|
|
|
var prefBranch = Services.prefs.getBranch("signon.");
|
2010-02-18 13:43:20 -08:00
|
|
|
this._debug = prefBranch.getBoolPref("debug");
|
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
var prompt = new LoginManagerPrompter().QueryInterface(aIID);
|
2009-07-20 11:29:41 -07:00
|
|
|
prompt.init(aWindow, this);
|
2007-08-31 15:29:55 -07:00
|
|
|
return prompt;
|
2010-02-18 13:43:20 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_doAsyncPrompt : function() {
|
|
|
|
if (this._asyncPromptInProgress) {
|
|
|
|
this.log("_doAsyncPrompt bypassed, already in progress");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the first prompt key we have in the queue
|
|
|
|
var hashKey = null;
|
|
|
|
for (hashKey in this._asyncPrompts)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!hashKey) {
|
|
|
|
this.log("_doAsyncPrompt:run bypassed, no prompts in the queue");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-02 16:02:20 -07:00
|
|
|
// If login manger has logins for this host, defer prompting if we're
|
|
|
|
// already waiting on a master password entry.
|
|
|
|
var prompt = this._asyncPrompts[hashKey];
|
|
|
|
var prompter = prompt.prompter;
|
|
|
|
var [hostname, httpRealm] = prompter._getAuthTarget(prompt.channel, prompt.authInfo);
|
|
|
|
var hasLogins = (prompter._pwmgr.countLogins(hostname, null, httpRealm) > 0);
|
|
|
|
if (hasLogins && prompter._pwmgr.uiBusy) {
|
|
|
|
this.log("_doAsyncPrompt:run bypassed, master password UI busy");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-18 13:43:20 -08:00
|
|
|
this._asyncPromptInProgress = true;
|
2010-08-02 16:02:20 -07:00
|
|
|
prompt.inProgress = true;
|
|
|
|
|
2010-02-18 13:43:20 -08:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var runnable = {
|
|
|
|
run : function() {
|
|
|
|
var ok = false;
|
|
|
|
try {
|
|
|
|
self.log("_doAsyncPrompt:run - performing the prompt for '" + hashKey + "'");
|
2010-08-02 16:02:20 -07:00
|
|
|
ok = prompter.promptAuth(prompt.channel,
|
|
|
|
prompt.level,
|
|
|
|
prompt.authInfo);
|
2010-02-18 13:43:20 -08:00
|
|
|
} catch (e) {
|
|
|
|
Components.utils.reportError("LoginManagerPrompter: " +
|
|
|
|
"_doAsyncPrompt:run: " + e + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete self._asyncPrompts[hashKey];
|
2010-08-02 16:02:20 -07:00
|
|
|
prompt.inProgress = false;
|
2010-02-18 13:43:20 -08:00
|
|
|
self._asyncPromptInProgress = false;
|
|
|
|
|
|
|
|
for each (var consumer in prompt.consumers) {
|
|
|
|
if (!consumer.callback)
|
|
|
|
// Not having a callback means that consumer didn't provide it
|
|
|
|
// or canceled the notification
|
|
|
|
continue;
|
|
|
|
|
|
|
|
self.log("Calling back to " + consumer.callback + " ok=" + ok);
|
|
|
|
try {
|
|
|
|
if (ok)
|
|
|
|
consumer.callback.onAuthAvailable(consumer.context, prompt.authInfo);
|
|
|
|
else
|
|
|
|
consumer.callback.onAuthCancelled(consumer.context, true);
|
|
|
|
} catch (e) { /* Throw away exceptions caused by callback */ }
|
|
|
|
}
|
|
|
|
self._doAsyncPrompt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 18:25:00 -08:00
|
|
|
Services.tm.mainThread.dispatch(runnable, Ci.nsIThread.DISPATCH_NORMAL);
|
2010-02-18 13:43:20 -08:00
|
|
|
this.log("_doAsyncPrompt:run dispatched");
|
|
|
|
},
|
|
|
|
|
2010-08-02 16:02:20 -07:00
|
|
|
|
|
|
|
_cancelPendingPrompts : function() {
|
|
|
|
this.log("Canceling all pending prompts...");
|
|
|
|
var asyncPrompts = this._asyncPrompts;
|
|
|
|
this.__proto__._asyncPrompts = {};
|
|
|
|
|
|
|
|
for each (var prompt in asyncPrompts) {
|
|
|
|
// Watch out! If this prompt is currently prompting, let it handle
|
|
|
|
// notifying the callbacks of success/failure, since it's already
|
|
|
|
// asking the user for input. Reusing a callback can be crashy.
|
|
|
|
if (prompt.inProgress) {
|
|
|
|
this.log("skipping a prompt in progress");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for each (var consumer in prompt.consumers) {
|
|
|
|
if (!consumer.callback)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
this.log("Canceling async auth prompt callback " + consumer.callback);
|
|
|
|
try {
|
|
|
|
consumer.callback.onAuthCancelled(consumer.context, true);
|
|
|
|
} catch (e) { /* Just ignore exceptions from the callback */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2010-02-18 13:43:20 -08:00
|
|
|
log : function (message) {
|
|
|
|
if (!this._debug)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dump("Pwmgr PromptFactory: " + message + "\n");
|
2010-03-11 18:25:00 -08:00
|
|
|
Services.console.logStringMessage("Pwmgr PrompFactory: " + message);
|
2007-05-16 03:02:45 -07:00
|
|
|
}
|
|
|
|
}; // end of LoginManagerPromptFactory implementation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ==================== LoginManagerPrompter ==================== */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LoginManagerPrompter
|
|
|
|
*
|
2008-03-02 04:24:24 -08:00
|
|
|
* Implements interfaces for prompting the user to enter/save/change auth info.
|
|
|
|
*
|
|
|
|
* nsIAuthPrompt: Used by SeaMonkey, Thunderbird, but not Firefox.
|
|
|
|
*
|
|
|
|
* nsIAuthPrompt2: Is invoked by a channel for protocol-based authentication
|
|
|
|
* (eg HTTP Authenticate, FTP login).
|
|
|
|
*
|
|
|
|
* nsILoginManagerPrompter: Used by Login Manager for saving/changing logins
|
|
|
|
* found in HTML forms.
|
2007-05-16 03:02:45 -07:00
|
|
|
*/
|
2007-08-31 15:29:55 -07:00
|
|
|
function LoginManagerPrompter() {}
|
2007-08-09 11:59:06 -07:00
|
|
|
|
2007-05-16 03:02:45 -07:00
|
|
|
LoginManagerPrompter.prototype = {
|
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
classID : Components.ID("{8aa66d77-1bbb-45a6-991e-b8f47751c291}"),
|
2008-03-02 04:24:24 -08:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAuthPrompt,
|
|
|
|
Ci.nsIAuthPrompt2,
|
|
|
|
Ci.nsILoginManagerPrompter]),
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2009-07-20 11:29:41 -07:00
|
|
|
_factory : null,
|
2007-08-31 15:29:55 -07:00
|
|
|
_window : null,
|
2007-11-19 20:51:40 -08:00
|
|
|
_debug : false, // mirrors signon.debug
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
__pwmgr : null, // Password Manager service
|
|
|
|
get _pwmgr() {
|
|
|
|
if (!this.__pwmgr)
|
|
|
|
this.__pwmgr = Cc["@mozilla.org/login-manager;1"].
|
|
|
|
getService(Ci.nsILoginManager);
|
|
|
|
return this.__pwmgr;
|
|
|
|
},
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
__promptService : null, // Prompt service for user interaction
|
|
|
|
get _promptService() {
|
|
|
|
if (!this.__promptService)
|
|
|
|
this.__promptService =
|
|
|
|
Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService2);
|
|
|
|
return this.__promptService;
|
|
|
|
},
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
__strBundle : null, // String bundle for L10N
|
|
|
|
get _strBundle() {
|
|
|
|
if (!this.__strBundle) {
|
|
|
|
var bunService = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService);
|
|
|
|
this.__strBundle = bunService.createBundle(
|
|
|
|
"chrome://passwordmgr/locale/passwordmgr.properties");
|
|
|
|
if (!this.__strBundle)
|
|
|
|
throw "String bundle for Login Manager not present!";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.__strBundle;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
__ellipsis : null,
|
|
|
|
get _ellipsis() {
|
|
|
|
if (!this.__ellipsis) {
|
|
|
|
this.__ellipsis = "\u2026";
|
|
|
|
try {
|
2010-03-11 18:25:00 -08:00
|
|
|
this.__ellipsis = Services.prefs.getComplexValue(
|
|
|
|
"intl.ellipsis", Ci.nsIPrefLocalizedString).data;
|
2008-10-30 23:28:39 -07:00
|
|
|
} catch (e) { }
|
|
|
|
}
|
|
|
|
return this.__ellipsis;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2008-10-20 15:28:43 -07:00
|
|
|
// Whether we are in private browsing mode
|
|
|
|
get _inPrivateBrowsing() {
|
|
|
|
// The Private Browsing service might not be available.
|
|
|
|
try {
|
|
|
|
var pbs = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService);
|
|
|
|
return pbs.privateBrowsingEnabled;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-05-16 03:02:45 -07:00
|
|
|
/*
|
|
|
|
* log
|
|
|
|
*
|
|
|
|
* Internal function for logging debug messages to the Error Console window.
|
|
|
|
*/
|
|
|
|
log : function (message) {
|
|
|
|
if (!this._debug)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dump("Pwmgr Prompter: " + message + "\n");
|
2010-03-11 18:25:00 -08:00
|
|
|
Services.console.logStringMessage("Pwmgr Prompter: " + message);
|
2007-05-16 03:02:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
|
2008-03-02 04:24:24 -08:00
|
|
|
/* ---------- nsIAuthPrompt prompts ---------- */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt
|
|
|
|
*
|
|
|
|
* Wrapper around the prompt service prompt. Saving random fields here
|
|
|
|
* doesn't really make sense and therefore isn't implemented.
|
|
|
|
*/
|
|
|
|
prompt : function (aDialogTitle, aText, aPasswordRealm,
|
|
|
|
aSavePassword, aDefaultText, aResult) {
|
|
|
|
if (aSavePassword != Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER)
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
this.log("===== prompt() called =====");
|
|
|
|
|
|
|
|
if (aDefaultText) {
|
|
|
|
aResult.value = aDefaultText;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._promptService.prompt(this._window,
|
|
|
|
aDialogTitle, aText, aResult, null, {});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* promptUsernameAndPassword
|
|
|
|
*
|
|
|
|
* Looks up a username and password in the database. Will prompt the user
|
|
|
|
* with a dialog, even if a username and password are found.
|
|
|
|
*/
|
|
|
|
promptUsernameAndPassword : function (aDialogTitle, aText, aPasswordRealm,
|
|
|
|
aSavePassword, aUsername, aPassword) {
|
2008-03-18 11:08:54 -07:00
|
|
|
this.log("===== promptUsernameAndPassword() called =====");
|
|
|
|
|
2008-03-02 04:24:24 -08:00
|
|
|
if (aSavePassword == Ci.nsIAuthPrompt.SAVE_PASSWORD_FOR_SESSION)
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2008-03-02 13:03:37 -08:00
|
|
|
var selectedLogin = null;
|
2008-03-02 04:24:24 -08:00
|
|
|
var checkBox = { value : false };
|
|
|
|
var checkBoxLabel = null;
|
2008-03-18 11:08:54 -07:00
|
|
|
var [hostname, realm, unused] = this._getRealmInfo(aPasswordRealm);
|
2008-03-02 04:24:24 -08:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// If hostname is null, we can't save this login.
|
|
|
|
if (hostname) {
|
2008-10-20 15:28:43 -07:00
|
|
|
var canRememberLogin;
|
|
|
|
if (this._inPrivateBrowsing)
|
|
|
|
canRememberLogin = false;
|
|
|
|
else
|
|
|
|
canRememberLogin = (aSavePassword ==
|
2008-03-18 11:08:54 -07:00
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY) &&
|
|
|
|
this._pwmgr.getLoginSavingEnabled(hostname);
|
|
|
|
|
|
|
|
// if checkBoxLabel is null, the checkbox won't be shown at all.
|
|
|
|
if (canRememberLogin)
|
|
|
|
checkBoxLabel = this._getLocalizedString("rememberPassword");
|
|
|
|
|
|
|
|
// Look for existing logins.
|
|
|
|
var foundLogins = this._pwmgr.findLogins({}, hostname, null,
|
|
|
|
realm);
|
|
|
|
|
|
|
|
// XXX Like the original code, we can't deal with multiple
|
|
|
|
// account selection. (bug 227632)
|
|
|
|
if (foundLogins.length > 0) {
|
|
|
|
selectedLogin = foundLogins[0];
|
2008-03-02 04:24:24 -08:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// If the caller provided a username, try to use it. If they
|
|
|
|
// provided only a password, this will try to find a password-only
|
|
|
|
// login (or return null if none exists).
|
|
|
|
if (aUsername.value)
|
|
|
|
selectedLogin = this._repickSelectedLogin(foundLogins,
|
|
|
|
aUsername.value);
|
|
|
|
|
|
|
|
if (selectedLogin) {
|
|
|
|
checkBox.value = true;
|
|
|
|
aUsername.value = selectedLogin.username;
|
|
|
|
// If the caller provided a password, prefer it.
|
|
|
|
if (!aPassword.value)
|
|
|
|
aPassword.value = selectedLogin.password;
|
|
|
|
}
|
2008-03-02 04:24:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var ok = this._promptService.promptUsernameAndPassword(this._window,
|
|
|
|
aDialogTitle, aText, aUsername, aPassword,
|
|
|
|
checkBoxLabel, checkBox);
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
if (!ok || !checkBox.value || !hostname)
|
2008-03-10 17:14:10 -07:00
|
|
|
return ok;
|
2008-03-02 04:24:24 -08:00
|
|
|
|
2008-09-07 00:12:34 -07:00
|
|
|
if (!aPassword.value) {
|
|
|
|
this.log("No password entered, so won't offer to save.");
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
// XXX We can't prompt with multiple logins yet (bug 227632), so
|
|
|
|
// the entered login might correspond to an existing login
|
|
|
|
// other than the one we originally selected.
|
|
|
|
selectedLogin = this._repickSelectedLogin(foundLogins, aUsername.value);
|
|
|
|
|
|
|
|
// If we didn't find an existing login, or if the username
|
|
|
|
// changed, save as a new login.
|
|
|
|
if (!selectedLogin) {
|
|
|
|
// add as new
|
2008-03-18 11:08:54 -07:00
|
|
|
this.log("New login seen for " + realm);
|
2009-12-28 20:39:00 -08:00
|
|
|
var newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
newLogin.init(hostname, null, realm,
|
|
|
|
aUsername.value, aPassword.value, "", "");
|
2008-03-10 17:14:10 -07:00
|
|
|
this._pwmgr.addLogin(newLogin);
|
|
|
|
} else if (aPassword.value != selectedLogin.password) {
|
|
|
|
// update password
|
2008-03-18 11:08:54 -07:00
|
|
|
this.log("Updating password for " + realm);
|
2009-12-28 20:39:00 -08:00
|
|
|
this._updateLogin(selectedLogin, aPassword.value);
|
2008-03-10 17:14:10 -07:00
|
|
|
} else {
|
|
|
|
this.log("Login unchanged, no further action needed.");
|
2009-12-28 20:39:00 -08:00
|
|
|
this._updateLogin(selectedLogin);
|
2008-03-02 04:24:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* promptPassword
|
|
|
|
*
|
|
|
|
* If a password is found in the database for the password realm, it is
|
|
|
|
* returned straight away without displaying a dialog.
|
|
|
|
*
|
|
|
|
* If a password is not found in the database, the user will be prompted
|
|
|
|
* with a dialog with a text field and ok/cancel buttons. If the user
|
|
|
|
* allows it, then the password will be saved in the database.
|
|
|
|
*/
|
|
|
|
promptPassword : function (aDialogTitle, aText, aPasswordRealm,
|
2008-03-18 11:08:54 -07:00
|
|
|
aSavePassword, aPassword) {
|
|
|
|
this.log("===== promptPassword called() =====");
|
|
|
|
|
2008-03-02 04:24:24 -08:00
|
|
|
if (aSavePassword == Ci.nsIAuthPrompt.SAVE_PASSWORD_FOR_SESSION)
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
var checkBox = { value : false };
|
|
|
|
var checkBoxLabel = null;
|
2008-03-18 11:08:54 -07:00
|
|
|
var [hostname, realm, username] = this._getRealmInfo(aPasswordRealm);
|
|
|
|
|
2009-01-15 05:16:34 -08:00
|
|
|
username = decodeURIComponent(username);
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// If hostname is null, we can't save this login.
|
2008-10-20 15:28:43 -07:00
|
|
|
if (hostname && !this._inPrivateBrowsing) {
|
2008-03-18 11:08:54 -07:00
|
|
|
var canRememberLogin = (aSavePassword ==
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY) &&
|
|
|
|
this._pwmgr.getLoginSavingEnabled(hostname);
|
2010-05-18 14:29:09 -07:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// if checkBoxLabel is null, the checkbox won't be shown at all.
|
|
|
|
if (canRememberLogin)
|
|
|
|
checkBoxLabel = this._getLocalizedString("rememberPassword");
|
2010-05-18 14:29:09 -07:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
if (!aPassword.value) {
|
|
|
|
// Look for existing logins.
|
|
|
|
var foundLogins = this._pwmgr.findLogins({}, hostname, null,
|
|
|
|
realm);
|
2010-05-18 14:29:09 -07:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// XXX Like the original code, we can't deal with multiple
|
|
|
|
// account selection (bug 227632). We can deal with finding the
|
|
|
|
// account based on the supplied username - but in this case we'll
|
|
|
|
// just return the first match.
|
|
|
|
for (var i = 0; i < foundLogins.length; ++i) {
|
|
|
|
if (foundLogins[i].username == username) {
|
|
|
|
aPassword.value = foundLogins[i].password;
|
|
|
|
// wallet returned straight away, so this mimics that code
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-02 04:24:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
var ok = this._promptService.promptPassword(this._window, aDialogTitle,
|
|
|
|
aText, aPassword,
|
|
|
|
checkBoxLabel, checkBox);
|
|
|
|
|
2008-09-07 00:12:34 -07:00
|
|
|
if (ok && checkBox.value && hostname && aPassword.value) {
|
2008-03-02 04:24:24 -08:00
|
|
|
var newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
2008-03-18 11:08:54 -07:00
|
|
|
newLogin.init(hostname, null, realm, username,
|
2008-03-02 04:24:24 -08:00
|
|
|
aPassword.value, "", "");
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
this.log("New login seen for " + realm);
|
2008-03-02 04:24:24 -08:00
|
|
|
|
|
|
|
this._pwmgr.addLogin(newLogin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
},
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
/* ---------- nsIAuthPrompt helpers ---------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given aRealmString, such as "http://user@example.com/foo", returns an
|
|
|
|
* array of:
|
|
|
|
* - the formatted hostname
|
|
|
|
* - the realm (hostname + path)
|
|
|
|
* - the username, if present
|
|
|
|
*
|
|
|
|
* If aRealmString is in the format produced by NS_GetAuthKey for HTTP[S]
|
|
|
|
* channels, e.g. "example.com:80 (httprealm)", null is returned for all
|
|
|
|
* arguments to let callers know the login can't be saved because we don't
|
|
|
|
* know whether it's http or https.
|
|
|
|
*/
|
|
|
|
_getRealmInfo : function (aRealmString) {
|
|
|
|
var httpRealm = /^.+ \(.+\)$/;
|
|
|
|
if (httpRealm.test(aRealmString))
|
|
|
|
return [null, null, null];
|
|
|
|
|
2010-03-11 18:25:00 -08:00
|
|
|
var uri = Services.io.newURI(aRealmString, null, null);
|
2008-03-18 11:08:54 -07:00
|
|
|
var pathname = "";
|
|
|
|
|
|
|
|
if (uri.path != "/")
|
|
|
|
pathname = uri.path;
|
2008-03-02 04:24:24 -08:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
var formattedHostname = this._getFormattedHostname(uri);
|
2008-03-02 04:24:24 -08:00
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
return [formattedHostname, formattedHostname + pathname, uri.username];
|
|
|
|
},
|
2008-03-02 04:24:24 -08:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
/* ---------- nsIAuthPrompt2 prompts ---------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-05-16 03:02:45 -07:00
|
|
|
/*
|
|
|
|
* promptAuth
|
|
|
|
*
|
|
|
|
* Implementation of nsIAuthPrompt2.
|
|
|
|
*
|
|
|
|
* nsIChannel aChannel
|
|
|
|
* int aLevel
|
|
|
|
* nsIAuthInformation aAuthInfo
|
|
|
|
*/
|
2007-08-31 15:29:55 -07:00
|
|
|
promptAuth : function (aChannel, aLevel, aAuthInfo) {
|
2007-05-16 03:02:45 -07:00
|
|
|
var selectedLogin = null;
|
2007-08-31 15:29:55 -07:00
|
|
|
var checkbox = { value : false };
|
2007-05-16 03:02:45 -07:00
|
|
|
var checkboxLabel = null;
|
2007-10-24 14:23:50 -07:00
|
|
|
var epicfail = false;
|
2010-04-06 15:28:00 -07:00
|
|
|
var canAutologin = false;
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-10-24 14:23:50 -07:00
|
|
|
try {
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-10-24 14:23:50 -07:00
|
|
|
this.log("===== promptAuth called =====");
|
|
|
|
|
|
|
|
// If the user submits a login but it fails, we need to remove the
|
|
|
|
// notification bar that was displayed. Conveniently, the user will
|
|
|
|
// be prompted for authentication again, which brings us here.
|
2010-09-09 19:08:26 -07:00
|
|
|
this._removeLoginNotifications();
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
var [hostname, httpRealm] = this._getAuthTarget(aChannel, aAuthInfo);
|
2007-05-16 03:02:45 -07:00
|
|
|
|
|
|
|
|
2007-10-24 14:23:50 -07:00
|
|
|
// Looks for existing logins to prefill the prompt with.
|
|
|
|
var foundLogins = this._pwmgr.findLogins({},
|
2007-08-31 15:29:55 -07:00
|
|
|
hostname, null, httpRealm);
|
2008-05-02 00:44:24 -07:00
|
|
|
this.log("found " + foundLogins.length + " matching logins.");
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-11-19 20:51:40 -08:00
|
|
|
// XXX Can't select from multiple accounts yet. (bug 227632)
|
2007-10-24 14:23:50 -07:00
|
|
|
if (foundLogins.length > 0) {
|
|
|
|
selectedLogin = foundLogins[0];
|
|
|
|
this._SetAuthInfo(aAuthInfo, selectedLogin.username,
|
|
|
|
selectedLogin.password);
|
2010-04-06 15:28:00 -07:00
|
|
|
|
|
|
|
// Allow automatic proxy login
|
|
|
|
if (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY &&
|
|
|
|
!(aAuthInfo.flags & Ci.nsIAuthInformation.PREVIOUS_FAILED) &&
|
|
|
|
Services.prefs.getBoolPref("signon.autologin.proxy") &&
|
|
|
|
!this._inPrivateBrowsing) {
|
|
|
|
|
|
|
|
this.log("Autologin enabled, skipping auth prompt.");
|
|
|
|
canAutologin = true;
|
|
|
|
}
|
|
|
|
|
2007-10-24 14:23:50 -07:00
|
|
|
checkbox.value = true;
|
|
|
|
}
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-10-24 14:23:50 -07:00
|
|
|
var canRememberLogin = this._pwmgr.getLoginSavingEnabled(hostname);
|
2008-10-20 15:28:43 -07:00
|
|
|
if (this._inPrivateBrowsing)
|
|
|
|
canRememberLogin = false;
|
2010-09-09 19:08:26 -07:00
|
|
|
|
2007-10-24 14:23:50 -07:00
|
|
|
// if checkboxLabel is null, the checkbox won't be shown at all.
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyBox = this._getNotifyBox();
|
2007-10-24 14:23:50 -07:00
|
|
|
if (canRememberLogin && !notifyBox)
|
|
|
|
checkboxLabel = this._getLocalizedString("rememberPassword");
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore any errors and display the prompt anyway.
|
|
|
|
epicfail = true;
|
|
|
|
Components.utils.reportError("LoginManagerPrompter: " +
|
|
|
|
"Epic fail in promptAuth: " + e + "\n");
|
|
|
|
}
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2010-04-06 15:28:00 -07:00
|
|
|
var ok = canAutologin ||
|
|
|
|
this._promptService.promptAuth(this._window,
|
|
|
|
aChannel, aLevel, aAuthInfo,
|
|
|
|
checkboxLabel, checkbox);
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
// If there's a notification box, use it to allow the user to
|
|
|
|
// determine if the login should be saved. If there isn't a
|
|
|
|
// notification box, only save the login if the user set the
|
|
|
|
// checkbox to do so.
|
|
|
|
var rememberLogin = notifyBox ? canRememberLogin : checkbox.value;
|
|
|
|
if (!ok || !rememberLogin || epicfail)
|
2007-10-24 14:23:50 -07:00
|
|
|
return ok;
|
|
|
|
|
|
|
|
try {
|
2008-02-03 14:11:26 -08:00
|
|
|
var [username, password] = this._GetAuthInfo(aAuthInfo);
|
|
|
|
|
2008-09-07 00:12:34 -07:00
|
|
|
if (!password) {
|
|
|
|
this.log("No password entered, so won't offer to save.");
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
// XXX We can't prompt with multiple logins yet (bug 227632), so
|
|
|
|
// the entered login might correspond to an existing login
|
|
|
|
// other than the one we originally selected.
|
|
|
|
selectedLogin = this._repickSelectedLogin(foundLogins, username);
|
|
|
|
|
|
|
|
// If we didn't find an existing login, or if the username
|
|
|
|
// changed, save as a new login.
|
|
|
|
if (!selectedLogin) {
|
|
|
|
this.log("New login seen for " + username +
|
|
|
|
" @ " + hostname + " (" + httpRealm + ")");
|
2009-12-28 20:39:00 -08:00
|
|
|
|
|
|
|
var newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
newLogin.init(hostname, null, httpRealm,
|
|
|
|
username, password, "", "");
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyObj = this._getPopupNote() || notifyBox;
|
|
|
|
if (notifyObj)
|
|
|
|
this._showSaveLoginNotification(notifyObj, newLogin);
|
2008-03-10 17:14:10 -07:00
|
|
|
else
|
|
|
|
this._pwmgr.addLogin(newLogin);
|
|
|
|
|
|
|
|
} else if (password != selectedLogin.password) {
|
|
|
|
|
|
|
|
this.log("Updating password for " + username +
|
|
|
|
" @ " + hostname + " (" + httpRealm + ")");
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyObj = this._getPopupNote() || notifyBox;
|
|
|
|
if (notifyObj)
|
|
|
|
this._showChangeLoginNotification(notifyObj,
|
2009-12-28 20:39:00 -08:00
|
|
|
selectedLogin, password);
|
2008-10-12 20:05:11 -07:00
|
|
|
else
|
2009-12-28 20:39:00 -08:00
|
|
|
this._updateLogin(selectedLogin, password);
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
this.log("Login unchanged, no further action needed.");
|
2009-12-28 20:39:00 -08:00
|
|
|
this._updateLogin(selectedLogin);
|
2007-05-16 03:02:45 -07:00
|
|
|
}
|
2007-10-24 14:23:50 -07:00
|
|
|
} catch (e) {
|
|
|
|
Components.utils.reportError("LoginManagerPrompter: " +
|
|
|
|
"Fail2 in promptAuth: " + e + "\n");
|
2007-05-16 03:02:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
},
|
|
|
|
|
2009-07-20 11:29:41 -07:00
|
|
|
asyncPromptAuth : function (aChannel, aCallback, aContext, aLevel, aAuthInfo) {
|
|
|
|
var cancelable = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.log("===== asyncPromptAuth called =====");
|
|
|
|
|
|
|
|
// If the user submits a login but it fails, we need to remove the
|
|
|
|
// notification bar that was displayed. Conveniently, the user will
|
|
|
|
// be prompted for authentication again, which brings us here.
|
2010-09-09 19:08:26 -07:00
|
|
|
this._removeLoginNotifications();
|
2009-07-20 11:29:41 -07:00
|
|
|
|
|
|
|
cancelable = this._newAsyncPromptConsumer(aCallback, aContext);
|
|
|
|
|
|
|
|
var [hostname, httpRealm] = this._getAuthTarget(aChannel, aAuthInfo);
|
|
|
|
|
|
|
|
var hashKey = aLevel + "|" + hostname + "|" + httpRealm;
|
|
|
|
this.log("Async prompt key = " + hashKey);
|
|
|
|
var asyncPrompt = this._factory._asyncPrompts[hashKey];
|
|
|
|
if (asyncPrompt) {
|
|
|
|
this.log("Prompt bound to an existing one in the queue, callback = " + aCallback);
|
|
|
|
asyncPrompt.consumers.push(cancelable);
|
|
|
|
return cancelable;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.log("Adding new prompt to the queue, callback = " + aCallback);
|
|
|
|
asyncPrompt = {
|
|
|
|
consumers: [cancelable],
|
|
|
|
channel: aChannel,
|
|
|
|
authInfo: aAuthInfo,
|
2010-02-18 13:43:20 -08:00
|
|
|
level: aLevel,
|
2010-08-02 16:02:20 -07:00
|
|
|
inProgress : false,
|
2010-02-18 13:43:20 -08:00
|
|
|
prompter: this
|
2009-07-20 11:29:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this._factory._asyncPrompts[hashKey] = asyncPrompt;
|
2010-02-18 13:43:20 -08:00
|
|
|
this._factory._doAsyncPrompt();
|
2009-07-20 11:29:41 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError("LoginManagerPrompter: " +
|
|
|
|
"asyncPromptAuth: " + e + "\nFalling back to promptAuth\n");
|
|
|
|
// Fail the prompt operation to let the consumer fall back
|
|
|
|
// to synchronous promptAuth method
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cancelable;
|
2007-05-16 03:02:45 -07:00
|
|
|
},
|
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- nsILoginManagerPrompter prompts ---------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init
|
|
|
|
*
|
|
|
|
*/
|
2009-07-20 11:29:41 -07:00
|
|
|
init : function (aWindow, aFactory) {
|
2007-08-31 15:29:55 -07:00
|
|
|
this._window = aWindow;
|
2009-07-20 11:29:41 -07:00
|
|
|
this._factory = aFactory || null;
|
2007-11-19 20:51:40 -08:00
|
|
|
|
2010-03-11 18:25:00 -08:00
|
|
|
var prefBranch = Services.prefs.getBranch("signon.");
|
2007-11-19 20:51:40 -08:00
|
|
|
this._debug = prefBranch.getBoolPref("debug");
|
2007-08-31 15:29:55 -07:00
|
|
|
this.log("===== initialized =====");
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* promptToSavePassword
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
promptToSavePassword : function (aLogin) {
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyObj = this._getPopupNote() || this._getNotifyBox();
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
if (notifyObj)
|
|
|
|
this._showSaveLoginNotification(notifyObj, aLogin);
|
2007-08-31 15:29:55 -07:00
|
|
|
else
|
|
|
|
this._showSaveLoginDialog(aLogin);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2008-02-24 22:17:13 -08:00
|
|
|
/*
|
|
|
|
* _showLoginNotification
|
|
|
|
*
|
|
|
|
* Displays a notification bar.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
_showLoginNotification : function (aNotifyBox, aName, aText, aButtons) {
|
|
|
|
var oldBar = aNotifyBox.getNotificationWithValue(aName);
|
|
|
|
const priority = aNotifyBox.PRIORITY_INFO_MEDIUM;
|
|
|
|
|
|
|
|
this.log("Adding new " + aName + " notification bar");
|
|
|
|
var newBar = aNotifyBox.appendNotification(
|
|
|
|
aText, aName,
|
|
|
|
"chrome://mozapps/skin/passwordmgr/key.png",
|
|
|
|
priority, aButtons);
|
|
|
|
|
|
|
|
// The page we're going to hasn't loaded yet, so we want to persist
|
|
|
|
// across the first location change.
|
|
|
|
newBar.persistence++;
|
|
|
|
|
|
|
|
// Sites like Gmail perform a funky redirect dance before you end up
|
|
|
|
// at the post-authentication page. I don't see a good way to
|
|
|
|
// heuristically determine when to ignore such location changes, so
|
|
|
|
// we'll try ignoring location changes based on a time interval.
|
|
|
|
newBar.timeout = Date.now() + 20000; // 20 seconds
|
|
|
|
|
|
|
|
if (oldBar) {
|
|
|
|
this.log("(...and removing old " + aName + " notification bar)");
|
|
|
|
aNotifyBox.removeNotification(oldBar);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
/*
|
|
|
|
* _showSaveLoginNotification
|
|
|
|
*
|
2010-09-21 01:25:47 -07:00
|
|
|
* Displays a notification bar or a popup notification, to allow the user
|
2010-09-09 19:08:26 -07:00
|
|
|
* to save the specified login. This allows the user to see the results of
|
2007-08-31 15:29:55 -07:00
|
|
|
* their login, and only save a login which they know worked.
|
|
|
|
*
|
2010-09-09 19:08:26 -07:00
|
|
|
* @param aNotifyObj
|
|
|
|
* A notification box or a popup notification.
|
2007-08-31 15:29:55 -07:00
|
|
|
*/
|
2010-09-09 19:08:26 -07:00
|
|
|
_showSaveLoginNotification : function (aNotifyObj, aLogin) {
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
// Ugh. We can't use the strings from the popup window, because they
|
|
|
|
// have the access key marked in the string (eg "Mo&zilla"), along
|
|
|
|
// with some weird rules for handling access keys that do not occur
|
|
|
|
// in the string, for L10N. See commonDialog.js's setLabelForNode().
|
|
|
|
var neverButtonText =
|
2010-09-14 16:18:04 -07:00
|
|
|
this._getLocalizedString("notifyBarNeverRememberButtonText");
|
2007-08-31 15:29:55 -07:00
|
|
|
var neverButtonAccessKey =
|
2010-09-14 16:18:04 -07:00
|
|
|
this._getLocalizedString("notifyBarNeverRememberButtonAccessKey");
|
2007-08-31 15:29:55 -07:00
|
|
|
var rememberButtonText =
|
2010-09-14 16:18:04 -07:00
|
|
|
this._getLocalizedString("notifyBarRememberPasswordButtonText");
|
2007-08-31 15:29:55 -07:00
|
|
|
var rememberButtonAccessKey =
|
2010-09-14 16:18:04 -07:00
|
|
|
this._getLocalizedString("notifyBarRememberPasswordButtonAccessKey");
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
var displayHost = this._getShortDisplayHost(aLogin.hostname);
|
|
|
|
var notificationText;
|
|
|
|
if (aLogin.username) {
|
2008-11-03 19:24:14 -08:00
|
|
|
var displayUser = this._sanitizeUsername(aLogin.username);
|
2008-10-30 23:28:39 -07:00
|
|
|
notificationText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"rememberPasswordMsg",
|
2010-09-14 16:18:04 -07:00
|
|
|
[displayUser, displayHost]);
|
2008-10-30 23:28:39 -07:00
|
|
|
} else {
|
|
|
|
notificationText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"rememberPasswordMsgNoUsername",
|
2010-09-14 16:18:04 -07:00
|
|
|
[displayHost]);
|
2008-10-30 23:28:39 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
// The callbacks in |buttons| have a closure to access the variables
|
|
|
|
// in scope here; set one to |this._pwmgr| so we can get back to pwmgr
|
|
|
|
// without a getService() call.
|
|
|
|
var pwmgr = this._pwmgr;
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// Notification is a PopupNotification
|
|
|
|
if (aNotifyObj == this._getPopupNote()) {
|
2007-08-31 15:29:55 -07:00
|
|
|
// "Remember" button
|
2010-09-09 19:08:26 -07:00
|
|
|
var mainAction = {
|
2007-08-31 15:29:55 -07:00
|
|
|
label: rememberButtonText,
|
|
|
|
accessKey: rememberButtonAccessKey,
|
2010-09-09 19:08:26 -07:00
|
|
|
callback: function(aNotifyObj, aButton) {
|
2007-08-31 15:29:55 -07:00
|
|
|
pwmgr.addLogin(aLogin);
|
2012-05-28 21:31:48 -07:00
|
|
|
browser.focus();
|
2007-08-31 15:29:55 -07:00
|
|
|
}
|
2010-09-09 19:08:26 -07:00
|
|
|
};
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
var secondaryActions = [
|
|
|
|
// "Never for this site" button
|
|
|
|
{
|
|
|
|
label: neverButtonText,
|
|
|
|
accessKey: neverButtonAccessKey,
|
|
|
|
callback: function(aNotifyObj, aButton) {
|
|
|
|
pwmgr.setLoginSavingEnabled(aLogin.hostname, false);
|
2012-05-28 21:31:48 -07:00
|
|
|
browser.focus();
|
2010-09-09 19:08:26 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
}
|
2010-09-09 19:08:26 -07:00
|
|
|
];
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyWin = this._getNotifyWindow();
|
|
|
|
var chromeWin = this._getChromeWindow(notifyWin).wrappedJSObject;
|
|
|
|
var browser = chromeWin.gBrowser.
|
|
|
|
getBrowserForDocument(this._window.top.document);
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
aNotifyObj.show(browser, "password-save", notificationText,
|
|
|
|
"password-notification-icon", mainAction,
|
2010-10-11 20:32:59 -07:00
|
|
|
secondaryActions, { timeout: Date.now() + 10000,
|
|
|
|
persistWhileVisible: true });
|
2010-09-09 19:08:26 -07:00
|
|
|
} else {
|
2010-09-14 16:18:04 -07:00
|
|
|
var notNowButtonText =
|
|
|
|
this._getLocalizedString("notifyBarNotNowButtonText");
|
|
|
|
var notNowButtonAccessKey =
|
|
|
|
this._getLocalizedString("notifyBarNotNowButtonAccessKey");
|
2010-09-09 19:08:26 -07:00
|
|
|
var buttons = [
|
|
|
|
// "Remember" button
|
|
|
|
{
|
|
|
|
label: rememberButtonText,
|
|
|
|
accessKey: rememberButtonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotifyObj, aButton) {
|
|
|
|
pwmgr.addLogin(aLogin);
|
|
|
|
}
|
|
|
|
},
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// "Never for this site" button
|
|
|
|
{
|
|
|
|
label: neverButtonText,
|
|
|
|
accessKey: neverButtonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotifyObj, aButton) {
|
|
|
|
pwmgr.setLoginSavingEnabled(aLogin.hostname, false);
|
|
|
|
}
|
|
|
|
},
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// "Not now" button
|
|
|
|
{
|
|
|
|
label: notNowButtonText,
|
|
|
|
accessKey: notNowButtonAccessKey,
|
|
|
|
popup: null,
|
2010-09-21 01:25:47 -07:00
|
|
|
callback: function() { /* NOP */ }
|
2010-09-09 19:08:26 -07:00
|
|
|
}
|
|
|
|
];
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
this._showLoginNotification(aNotifyObj, "password-save",
|
|
|
|
notificationText, buttons);
|
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-10-12 20:05:11 -07:00
|
|
|
* _removeLoginNotifications
|
2007-08-31 15:29:55 -07:00
|
|
|
*
|
|
|
|
*/
|
2010-09-09 19:08:26 -07:00
|
|
|
_removeLoginNotifications : function () {
|
|
|
|
var popupNote = this._getPopupNote();
|
|
|
|
if (popupNote)
|
|
|
|
popupNote = popupNote.getNotification("password-save");
|
|
|
|
if (popupNote)
|
|
|
|
popupNote.remove();
|
2008-10-12 20:05:11 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyBox = this._getNotifyBox();
|
|
|
|
if (notifyBox) {
|
|
|
|
var oldBar = notifyBox.getNotificationWithValue("password-save");
|
|
|
|
if (oldBar) {
|
|
|
|
this.log("Removing save-password notification bar.");
|
|
|
|
notifyBox.removeNotification(oldBar);
|
|
|
|
}
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
oldBar = notifyBox.getNotificationWithValue("password-change");
|
|
|
|
if (oldBar) {
|
|
|
|
this.log("Removing change-password notification bar.");
|
|
|
|
notifyBox.removeNotification(oldBar);
|
|
|
|
}
|
2008-10-12 20:05:11 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _showSaveLoginDialog
|
|
|
|
*
|
|
|
|
* Called when we detect a new login in a form submission,
|
|
|
|
* asks the user what to do.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
_showSaveLoginDialog : function (aLogin) {
|
|
|
|
const buttonFlags = Ci.nsIPrompt.BUTTON_POS_1_DEFAULT +
|
|
|
|
(Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
|
|
|
|
(Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1) +
|
|
|
|
(Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_2);
|
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
var displayHost = this._getShortDisplayHost(aLogin.hostname);
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
var dialogText;
|
|
|
|
if (aLogin.username) {
|
2008-11-03 19:24:14 -08:00
|
|
|
var displayUser = this._sanitizeUsername(aLogin.username);
|
2008-10-30 23:28:39 -07:00
|
|
|
dialogText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"rememberPasswordMsg",
|
2011-09-08 12:36:35 -07:00
|
|
|
[displayUser, displayHost]);
|
2008-10-30 23:28:39 -07:00
|
|
|
} else {
|
|
|
|
dialogText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"rememberPasswordMsgNoUsername",
|
2011-09-08 12:36:35 -07:00
|
|
|
[displayHost]);
|
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
var dialogTitle = this._getLocalizedString(
|
|
|
|
"savePasswordTitle");
|
|
|
|
var neverButtonText = this._getLocalizedString(
|
|
|
|
"neverForSiteButtonText");
|
|
|
|
var rememberButtonText = this._getLocalizedString(
|
|
|
|
"rememberButtonText");
|
|
|
|
var notNowButtonText = this._getLocalizedString(
|
|
|
|
"notNowButtonText");
|
|
|
|
|
|
|
|
this.log("Prompting user to save/ignore login");
|
|
|
|
var userChoice = this._promptService.confirmEx(this._window,
|
|
|
|
dialogTitle, dialogText,
|
|
|
|
buttonFlags, rememberButtonText,
|
|
|
|
notNowButtonText, neverButtonText,
|
|
|
|
null, {});
|
|
|
|
// Returns:
|
|
|
|
// 0 - Save the login
|
|
|
|
// 1 - Ignore the login this time
|
|
|
|
// 2 - Never save logins for this site
|
|
|
|
if (userChoice == 2) {
|
|
|
|
this.log("Disabling " + aLogin.hostname + " logins by request.");
|
|
|
|
this._pwmgr.setLoginSavingEnabled(aLogin.hostname, false);
|
|
|
|
} else if (userChoice == 0) {
|
|
|
|
this.log("Saving login for " + aLogin.hostname);
|
2007-10-25 08:57:38 -07:00
|
|
|
this._pwmgr.addLogin(aLogin);
|
2007-08-31 15:29:55 -07:00
|
|
|
} else {
|
|
|
|
// userChoice == 1 --> just ignore the login.
|
|
|
|
this.log("Ignoring login.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* promptToChangePassword
|
|
|
|
*
|
|
|
|
* Called when we think we detect a password change for an existing
|
|
|
|
* login, when the form being submitted contains multiple password
|
|
|
|
* fields.
|
|
|
|
*
|
|
|
|
*/
|
2007-09-04 19:07:43 -07:00
|
|
|
promptToChangePassword : function (aOldLogin, aNewLogin) {
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyObj = this._getPopupNote() || this._getNotifyBox();
|
2008-02-24 22:17:13 -08:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
if (notifyObj)
|
|
|
|
this._showChangeLoginNotification(notifyObj, aOldLogin,
|
|
|
|
aNewLogin.password);
|
2008-02-24 22:17:13 -08:00
|
|
|
else
|
2009-12-28 20:39:00 -08:00
|
|
|
this._showChangeLoginDialog(aOldLogin, aNewLogin.password);
|
2008-02-24 22:17:13 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _showChangeLoginNotification
|
|
|
|
*
|
2010-09-09 19:08:26 -07:00
|
|
|
* Shows the Change Password notification bar or popup notification.
|
2008-02-24 22:17:13 -08:00
|
|
|
*
|
2010-09-09 19:08:26 -07:00
|
|
|
* @param aNotifyObj
|
|
|
|
* A notification box or a popup notification.
|
2008-02-24 22:17:13 -08:00
|
|
|
*/
|
2010-09-09 19:08:26 -07:00
|
|
|
_showChangeLoginNotification : function (aNotifyObj, aOldLogin, aNewPassword) {
|
2008-02-24 22:17:13 -08:00
|
|
|
var notificationText;
|
2012-04-05 14:42:58 -07:00
|
|
|
if (aOldLogin.username) {
|
|
|
|
var displayUser = this._sanitizeUsername(aOldLogin.username);
|
2008-02-24 22:17:13 -08:00
|
|
|
notificationText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"updatePasswordMsg",
|
2012-04-05 14:42:58 -07:00
|
|
|
[displayUser]);
|
|
|
|
} else {
|
2008-02-24 22:17:13 -08:00
|
|
|
notificationText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"updatePasswordMsgNoUser");
|
2012-04-05 14:42:58 -07:00
|
|
|
}
|
2008-02-24 22:17:13 -08:00
|
|
|
|
|
|
|
var changeButtonText =
|
2010-09-14 16:18:04 -07:00
|
|
|
this._getLocalizedString("notifyBarUpdateButtonText");
|
2008-02-24 22:17:13 -08:00
|
|
|
var changeButtonAccessKey =
|
2010-09-14 16:18:04 -07:00
|
|
|
this._getLocalizedString("notifyBarUpdateButtonAccessKey");
|
2008-02-24 22:17:13 -08:00
|
|
|
|
|
|
|
// The callbacks in |buttons| have a closure to access the variables
|
|
|
|
// in scope here; set one to |this._pwmgr| so we can get back to pwmgr
|
|
|
|
// without a getService() call.
|
2009-12-28 20:39:00 -08:00
|
|
|
var self = this;
|
2008-02-24 22:17:13 -08:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// Notification is a PopupNotification
|
|
|
|
if (aNotifyObj == this._getPopupNote()) {
|
2008-02-24 22:17:13 -08:00
|
|
|
// "Yes" button
|
2010-09-09 19:08:26 -07:00
|
|
|
var mainAction = {
|
2008-02-24 22:17:13 -08:00
|
|
|
label: changeButtonText,
|
|
|
|
accessKey: changeButtonAccessKey,
|
|
|
|
popup: null,
|
2010-09-09 19:08:26 -07:00
|
|
|
callback: function(aNotifyObj, aButton) {
|
2009-12-28 20:39:00 -08:00
|
|
|
self._updateLogin(aOldLogin, aNewPassword);
|
2008-02-24 22:17:13 -08:00
|
|
|
}
|
2010-09-09 19:08:26 -07:00
|
|
|
};
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyWin = this._getNotifyWindow();
|
|
|
|
var chromeWin = this._getChromeWindow(notifyWin).wrappedJSObject;
|
|
|
|
var browser = chromeWin.gBrowser.
|
|
|
|
getBrowserForDocument(this._window.top.document);
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
aNotifyObj.show(browser, "password-change", notificationText,
|
|
|
|
"password-notification-icon", mainAction,
|
2010-10-11 20:32:59 -07:00
|
|
|
null, { timeout: Date.now() + 10000,
|
|
|
|
persistWhileVisible: true });
|
2010-09-09 19:08:26 -07:00
|
|
|
} else {
|
2010-09-14 16:18:04 -07:00
|
|
|
var dontChangeButtonText =
|
|
|
|
this._getLocalizedString("notifyBarDontChangeButtonText");
|
|
|
|
var dontChangeButtonAccessKey =
|
|
|
|
this._getLocalizedString("notifyBarDontChangeButtonAccessKey");
|
2010-09-09 19:08:26 -07:00
|
|
|
var buttons = [
|
|
|
|
// "Yes" button
|
|
|
|
{
|
|
|
|
label: changeButtonText,
|
|
|
|
accessKey: changeButtonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotifyObj, aButton) {
|
|
|
|
self._updateLogin(aOldLogin, aNewPassword);
|
|
|
|
}
|
|
|
|
},
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// "No" button
|
|
|
|
{
|
|
|
|
label: dontChangeButtonText,
|
|
|
|
accessKey: dontChangeButtonAccessKey,
|
|
|
|
popup: null,
|
|
|
|
callback: function(aNotifyObj, aButton) {
|
|
|
|
// do nothing
|
|
|
|
}
|
2008-02-24 22:17:13 -08:00
|
|
|
}
|
2010-09-09 19:08:26 -07:00
|
|
|
];
|
2010-09-21 01:25:47 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
this._showLoginNotification(aNotifyObj, "password-change",
|
|
|
|
notificationText, buttons);
|
|
|
|
}
|
2008-02-24 22:17:13 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _showChangeLoginDialog
|
|
|
|
*
|
|
|
|
* Shows the Change Password dialog.
|
|
|
|
*
|
|
|
|
*/
|
2009-12-28 20:39:00 -08:00
|
|
|
_showChangeLoginDialog : function (aOldLogin, aNewPassword) {
|
2007-08-31 15:29:55 -07:00
|
|
|
const buttonFlags = Ci.nsIPrompt.STD_YES_NO_BUTTONS;
|
|
|
|
|
2007-09-20 18:52:44 -07:00
|
|
|
var dialogText;
|
|
|
|
if (aOldLogin.username)
|
|
|
|
dialogText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"updatePasswordMsg",
|
2007-09-04 19:07:43 -07:00
|
|
|
[aOldLogin.username]);
|
2007-09-20 18:52:44 -07:00
|
|
|
else
|
|
|
|
dialogText = this._getLocalizedString(
|
2011-11-28 13:02:47 -08:00
|
|
|
"updatePasswordMsgNoUser");
|
2007-09-20 18:52:44 -07:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
var dialogTitle = this._getLocalizedString(
|
|
|
|
"passwordChangeTitle");
|
|
|
|
|
|
|
|
// returns 0 for yes, 1 for no.
|
2007-09-04 19:07:43 -07:00
|
|
|
var ok = !this._promptService.confirmEx(this._window,
|
2007-08-31 15:29:55 -07:00
|
|
|
dialogTitle, dialogText, buttonFlags,
|
|
|
|
null, null, null,
|
|
|
|
null, {});
|
2007-09-04 19:07:43 -07:00
|
|
|
if (ok) {
|
|
|
|
this.log("Updating password for user " + aOldLogin.username);
|
2009-12-28 20:39:00 -08:00
|
|
|
this._updateLogin(aOldLogin, aNewPassword);
|
2007-09-04 19:07:43 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* promptToChangePasswordWithUsernames
|
|
|
|
*
|
|
|
|
* Called when we detect a password change in a form submission, but we
|
|
|
|
* don't know which existing login (username) it's for. Asks the user
|
|
|
|
* to select a username and confirm the password change.
|
|
|
|
*
|
2007-09-04 19:07:43 -07:00
|
|
|
* Note: The caller doesn't know the username for aNewLogin, so this
|
|
|
|
* function fills in .username and .usernameField with the values
|
|
|
|
* from the login selected by the user.
|
2010-09-21 01:25:47 -07:00
|
|
|
*
|
2007-09-04 19:07:43 -07:00
|
|
|
* Note; XPCOM stupidity: |count| is just |logins.length|.
|
2007-08-31 15:29:55 -07:00
|
|
|
*/
|
2007-09-04 19:07:43 -07:00
|
|
|
promptToChangePasswordWithUsernames : function (logins, count, aNewLogin) {
|
2007-08-31 15:29:55 -07:00
|
|
|
const buttonFlags = Ci.nsIPrompt.STD_YES_NO_BUTTONS;
|
|
|
|
|
2007-09-04 19:07:43 -07:00
|
|
|
var usernames = logins.map(function (l) l.username);
|
2007-08-31 15:29:55 -07:00
|
|
|
var dialogText = this._getLocalizedString("userSelectText");
|
|
|
|
var dialogTitle = this._getLocalizedString("passwordChangeTitle");
|
2007-09-04 19:07:43 -07:00
|
|
|
var selectedIndex = { value: null };
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
// If user selects ok, outparam.value is set to the index
|
|
|
|
// of the selected username.
|
|
|
|
var ok = this._promptService.select(this._window,
|
|
|
|
dialogTitle, dialogText,
|
|
|
|
usernames.length, usernames,
|
|
|
|
selectedIndex);
|
2007-09-04 19:07:43 -07:00
|
|
|
if (ok) {
|
2009-12-28 20:39:00 -08:00
|
|
|
// Now that we know which login to use, modify its password.
|
2007-09-04 19:07:43 -07:00
|
|
|
var selectedLogin = logins[selectedIndex.value];
|
|
|
|
this.log("Updating password for user " + selectedLogin.username);
|
2009-12-28 20:39:00 -08:00
|
|
|
this._updateLogin(selectedLogin, aNewLogin.password);
|
2007-09-04 19:07:43 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- Internal Methods ---------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-28 20:39:00 -08:00
|
|
|
/*
|
|
|
|
* _updateLogin
|
|
|
|
*/
|
|
|
|
_updateLogin : function (login, newPassword) {
|
|
|
|
var now = Date.now();
|
|
|
|
var propBag = Cc["@mozilla.org/hash-property-bag;1"].
|
|
|
|
createInstance(Ci.nsIWritablePropertyBag);
|
|
|
|
if (newPassword) {
|
|
|
|
propBag.setProperty("password", newPassword);
|
|
|
|
// Explicitly set the password change time here (even though it would
|
|
|
|
// be changed automatically), to ensure that it's exactly the same
|
|
|
|
// value as timeLastUsed.
|
|
|
|
propBag.setProperty("timePasswordChanged", now);
|
|
|
|
}
|
|
|
|
propBag.setProperty("timeLastUsed", now);
|
|
|
|
propBag.setProperty("timesUsedIncrement", 1);
|
|
|
|
this._pwmgr.modifyLogin(login, propBag);
|
|
|
|
},
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
/*
|
2010-09-09 19:08:26 -07:00
|
|
|
* _getChromeWindow
|
2007-08-31 15:29:55 -07:00
|
|
|
*
|
2010-09-09 19:08:26 -07:00
|
|
|
* Given a content DOM window, returns the chrome window it's in.
|
2007-08-31 15:29:55 -07:00
|
|
|
*/
|
2010-09-09 19:08:26 -07:00
|
|
|
_getChromeWindow: function (aWindow) {
|
|
|
|
var chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler.ownerDocument.defaultView;
|
|
|
|
return chromeWin;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _getNotifyWindow
|
|
|
|
*/
|
|
|
|
_getNotifyWindow: function () {
|
2008-08-11 16:31:57 -07:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
try {
|
|
|
|
// Get topmost window, in case we're in a frame.
|
2010-09-09 19:08:26 -07:00
|
|
|
var notifyWin = this._window.top;
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
// Some sites pop up a temporary login window, when disappears
|
|
|
|
// upon submission of credentials. We want to put the notification
|
|
|
|
// bar in the opener window if this seems to be happening.
|
2010-09-09 19:08:26 -07:00
|
|
|
if (notifyWin.opener) {
|
|
|
|
var chromeDoc = this._getChromeWindow(notifyWin).
|
|
|
|
document.documentElement;
|
|
|
|
var webnav = notifyWin.
|
|
|
|
QueryInterface(Ci.nsIInterfaceRequestor).
|
|
|
|
getInterface(Ci.nsIWebNavigation);
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2008-02-09 22:08:29 -08:00
|
|
|
// Check to see if the current window was opened with chrome
|
|
|
|
// disabled, and if so use the opener window. But if the window
|
|
|
|
// has been used to visit other pages (ie, has a history),
|
|
|
|
// assume it'll stick around and *don't* use the opener.
|
2011-05-08 11:14:16 -07:00
|
|
|
if (chromeDoc.hasAttribute("chromehidden") &&
|
2008-02-09 22:08:29 -08:00
|
|
|
webnav.sessionHistory.count == 1) {
|
2007-08-31 15:29:55 -07:00
|
|
|
this.log("Using opener window for notification bar.");
|
2010-09-09 19:08:26 -07:00
|
|
|
notifyWin = notifyWin.opener;
|
2007-08-31 15:29:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
return notifyWin;
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
// If any errors happen, just assume no notification box.
|
|
|
|
this.log("Unable to get notify window");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _getPopupNote
|
|
|
|
*
|
|
|
|
* Returns the popup notification to this prompter,
|
|
|
|
* or null if there isn't one available.
|
|
|
|
*/
|
|
|
|
_getPopupNote : function () {
|
|
|
|
let popupNote = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let notifyWin = this._getNotifyWindow();
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2008-08-11 16:31:57 -07:00
|
|
|
// Get the chrome window for the content window we're using.
|
|
|
|
// .wrappedJSObject needed here -- see bug 422974 comment 5.
|
2010-09-09 19:08:26 -07:00
|
|
|
let chromeWin = this._getChromeWindow(notifyWin).wrappedJSObject;
|
|
|
|
|
|
|
|
popupNote = chromeWin.PopupNotifications;
|
|
|
|
} catch (e) {
|
|
|
|
this.log("Popup notifications not available on window");
|
|
|
|
}
|
|
|
|
|
|
|
|
return popupNote;
|
|
|
|
},
|
2007-08-31 15:29:55 -07:00
|
|
|
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
/*
|
|
|
|
* _getNotifyBox
|
|
|
|
*
|
|
|
|
* Returns the notification box to this prompter, or null if there isn't
|
|
|
|
* a notification box available.
|
|
|
|
*/
|
|
|
|
_getNotifyBox : function () {
|
|
|
|
let notifyBox = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let notifyWin = this._getNotifyWindow();
|
|
|
|
|
|
|
|
// Get the chrome window for the content window we're using.
|
|
|
|
// .wrappedJSObject needed here -- see bug 422974 comment 5.
|
|
|
|
let chromeWin = this._getChromeWindow(notifyWin).wrappedJSObject;
|
|
|
|
|
|
|
|
notifyBox = chromeWin.getNotificationBox(notifyWin);
|
2007-08-31 15:29:55 -07:00
|
|
|
} catch (e) {
|
2010-09-09 19:08:26 -07:00
|
|
|
this.log("Notification bars not available on window");
|
2007-08-31 15:29:55 -07:00
|
|
|
}
|
|
|
|
|
2008-08-11 16:31:57 -07:00
|
|
|
return notifyBox;
|
2007-08-31 15:29:55 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
/*
|
|
|
|
* _repickSelectedLogin
|
|
|
|
*
|
|
|
|
* The user might enter a login that isn't the one we prefilled, but
|
|
|
|
* is the same as some other existing login. So, pick a login with a
|
|
|
|
* matching username, or return null.
|
|
|
|
*/
|
|
|
|
_repickSelectedLogin : function (foundLogins, username) {
|
|
|
|
for (var i = 0; i < foundLogins.length; i++)
|
|
|
|
if (foundLogins[i].username == username)
|
|
|
|
return foundLogins[i];
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
/*
|
2007-12-14 13:14:56 -08:00
|
|
|
* _getLocalizedString
|
2007-08-31 15:29:55 -07:00
|
|
|
*
|
|
|
|
* Can be called as:
|
2007-12-14 13:14:56 -08:00
|
|
|
* _getLocalizedString("key1");
|
2007-08-31 15:29:55 -07:00
|
|
|
* _getLocalizedString("key2", ["arg1"]);
|
|
|
|
* _getLocalizedString("key3", ["arg1", "arg2"]);
|
|
|
|
* (etc)
|
|
|
|
*
|
|
|
|
* Returns the localized string for the specified key,
|
|
|
|
* formatted if required.
|
|
|
|
*
|
2010-09-21 01:25:47 -07:00
|
|
|
*/
|
2007-08-31 15:29:55 -07:00
|
|
|
_getLocalizedString : function (key, formatArgs) {
|
|
|
|
if (formatArgs)
|
|
|
|
return this._strBundle.formatStringFromName(
|
|
|
|
key, formatArgs, formatArgs.length);
|
|
|
|
else
|
|
|
|
return this._strBundle.GetStringFromName(key);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2008-11-03 19:24:14 -08:00
|
|
|
/*
|
|
|
|
* _sanitizeUsername
|
|
|
|
*
|
|
|
|
* Sanitizes the specified username, by stripping quotes and truncating if
|
|
|
|
* it's too long. This helps prevent an evil site from messing with the
|
|
|
|
* "save password?" prompt too much.
|
|
|
|
*/
|
|
|
|
_sanitizeUsername : function (username) {
|
|
|
|
if (username.length > 30) {
|
|
|
|
username = username.substring(0, 30);
|
|
|
|
username += this._ellipsis;
|
|
|
|
}
|
|
|
|
return username.replace(/['"]/g, "");
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
/*
|
|
|
|
* _getFormattedHostname
|
|
|
|
*
|
2008-03-02 04:24:24 -08:00
|
|
|
* The aURI parameter may either be a string uri, or an nsIURI instance.
|
|
|
|
*
|
2007-12-05 13:16:33 -08:00
|
|
|
* Returns the hostname to use in a nsILoginInfo object (for example,
|
|
|
|
* "http://example.com").
|
2007-05-16 03:02:45 -07:00
|
|
|
*/
|
2007-12-05 13:16:33 -08:00
|
|
|
_getFormattedHostname : function (aURI) {
|
2008-03-02 04:24:24 -08:00
|
|
|
var uri;
|
|
|
|
if (aURI instanceof Ci.nsIURI) {
|
|
|
|
uri = aURI;
|
|
|
|
} else {
|
2010-03-11 18:25:00 -08:00
|
|
|
uri = Services.io.newURI(aURI, null, null);
|
2008-03-02 04:24:24 -08:00
|
|
|
}
|
|
|
|
var scheme = uri.scheme;
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2008-03-02 04:24:24 -08:00
|
|
|
var hostname = scheme + "://" + uri.host;
|
2007-12-05 13:16:33 -08:00
|
|
|
|
|
|
|
// If the URI explicitly specified a port, only include it when
|
|
|
|
// it's not the default. (We never want "http://foo.com:80")
|
2008-03-02 04:24:24 -08:00
|
|
|
port = uri.port;
|
2007-12-05 13:16:33 -08:00
|
|
|
if (port != -1) {
|
2010-03-11 18:25:00 -08:00
|
|
|
var handler = Services.io.getProtocolHandler(scheme);
|
2007-12-05 13:16:33 -08:00
|
|
|
if (port != handler.defaultPort)
|
|
|
|
hostname += ":" + port;
|
|
|
|
}
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
return hostname;
|
2007-05-16 03:02:45 -07:00
|
|
|
},
|
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* _getShortDisplayHost
|
|
|
|
*
|
|
|
|
* Converts a login's hostname field (a URL) to a short string for
|
|
|
|
* prompting purposes. Eg, "http://foo.com" --> "foo.com", or
|
|
|
|
* "ftp://www.site.co.uk" --> "site.co.uk".
|
|
|
|
*/
|
|
|
|
_getShortDisplayHost: function (aURIString) {
|
|
|
|
var displayHost;
|
|
|
|
|
|
|
|
var eTLDService = Cc["@mozilla.org/network/effective-tld-service;1"].
|
|
|
|
getService(Ci.nsIEffectiveTLDService);
|
|
|
|
var idnService = Cc["@mozilla.org/network/idn-service;1"].
|
|
|
|
getService(Ci.nsIIDNService);
|
|
|
|
try {
|
2010-03-11 18:25:00 -08:00
|
|
|
var uri = Services.io.newURI(aURIString, null, null);
|
2008-10-30 23:28:39 -07:00
|
|
|
var baseDomain = eTLDService.getBaseDomain(uri);
|
|
|
|
displayHost = idnService.convertToDisplayIDN(baseDomain, {});
|
|
|
|
} catch (e) {
|
|
|
|
this.log("_getShortDisplayHost couldn't process " + aURIString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!displayHost)
|
|
|
|
displayHost = aURIString;
|
|
|
|
|
|
|
|
return displayHost;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
/*
|
|
|
|
* _getAuthTarget
|
|
|
|
*
|
|
|
|
* Returns the hostname and realm for which authentication is being
|
|
|
|
* requested, in the format expected to be used with nsILoginInfo.
|
|
|
|
*/
|
|
|
|
_getAuthTarget : function (aChannel, aAuthInfo) {
|
|
|
|
var hostname, realm;
|
|
|
|
|
|
|
|
// If our proxy is demanding authentication, don't use the
|
|
|
|
// channel's actual destination.
|
|
|
|
if (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY) {
|
|
|
|
this.log("getAuthTarget is for proxy auth");
|
|
|
|
if (!(aChannel instanceof Ci.nsIProxiedChannel))
|
2007-05-16 03:02:45 -07:00
|
|
|
throw "proxy auth needs nsIProxiedChannel";
|
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
var info = aChannel.proxyInfo;
|
2007-05-16 03:02:45 -07:00
|
|
|
if (!info)
|
|
|
|
throw "proxy auth needs nsIProxyInfo";
|
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
// Proxies don't have a scheme, but we'll use "moz-proxy://"
|
|
|
|
// so that it's more obvious what the login is for.
|
2007-08-31 15:29:55 -07:00
|
|
|
var idnService = Cc["@mozilla.org/network/idn-service;1"].
|
|
|
|
getService(Ci.nsIIDNService);
|
2007-12-05 13:16:33 -08:00
|
|
|
hostname = "moz-proxy://" +
|
|
|
|
idnService.convertUTF8toACE(info.host) +
|
|
|
|
":" + info.port;
|
|
|
|
realm = aAuthInfo.realm;
|
|
|
|
if (!realm)
|
|
|
|
realm = hostname;
|
|
|
|
|
|
|
|
return [hostname, realm];
|
2007-05-16 03:02:45 -07:00
|
|
|
}
|
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
hostname = this._getFormattedHostname(aChannel.URI);
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
// If a HTTP WWW-Authenticate header specified a realm, that value
|
|
|
|
// will be available here. If it wasn't set or wasn't HTTP, we'll use
|
|
|
|
// the formatted hostname instead.
|
|
|
|
realm = aAuthInfo.realm;
|
|
|
|
if (!realm)
|
|
|
|
realm = hostname;
|
2007-05-16 03:02:45 -07:00
|
|
|
|
2007-12-05 13:16:33 -08:00
|
|
|
return [hostname, realm];
|
2007-05-16 03:02:45 -07:00
|
|
|
},
|
|
|
|
|
2008-02-03 14:11:26 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns [username, password] as extracted from aAuthInfo (which
|
|
|
|
* holds this info after having prompted the user).
|
|
|
|
*
|
|
|
|
* If the authentication was for a Windows domain, we'll prepend the
|
|
|
|
* return username with the domain. (eg, "domain\user")
|
|
|
|
*/
|
|
|
|
_GetAuthInfo : function (aAuthInfo) {
|
|
|
|
var username, password;
|
|
|
|
|
|
|
|
var flags = aAuthInfo.flags;
|
2008-02-26 12:52:58 -08:00
|
|
|
if (flags & Ci.nsIAuthInformation.NEED_DOMAIN && aAuthInfo.domain)
|
2008-02-03 14:11:26 -08:00
|
|
|
username = aAuthInfo.domain + "\\" + aAuthInfo.username;
|
|
|
|
else
|
|
|
|
username = aAuthInfo.username;
|
|
|
|
|
|
|
|
password = aAuthInfo.password;
|
|
|
|
|
|
|
|
return [username, password];
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2007-05-16 03:02:45 -07:00
|
|
|
/**
|
|
|
|
* Given a username (possibly in DOMAIN\user form) and password, parses the
|
|
|
|
* domain out of the username if necessary and sets domain, username and
|
|
|
|
* password on the auth information object.
|
|
|
|
*/
|
|
|
|
_SetAuthInfo : function (aAuthInfo, username, password) {
|
|
|
|
var flags = aAuthInfo.flags;
|
|
|
|
if (flags & Ci.nsIAuthInformation.NEED_DOMAIN) {
|
|
|
|
// Domain is separated from username by a backslash
|
|
|
|
var idx = username.indexOf("\\");
|
|
|
|
if (idx == -1) {
|
|
|
|
aAuthInfo.username = username;
|
|
|
|
} else {
|
|
|
|
aAuthInfo.domain = username.substring(0, idx);
|
|
|
|
aAuthInfo.username = username.substring(idx+1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aAuthInfo.username = username;
|
|
|
|
}
|
|
|
|
aAuthInfo.password = password;
|
2009-07-20 11:29:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_newAsyncPromptConsumer : function(aCallback, aContext) {
|
|
|
|
return {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICancelable]),
|
|
|
|
callback: aCallback,
|
|
|
|
context: aContext,
|
|
|
|
cancel: function() {
|
|
|
|
this.callback.onAuthCancelled(this.context, false);
|
|
|
|
this.callback = null;
|
|
|
|
this.context = null;
|
|
|
|
}
|
|
|
|
}
|
2007-05-16 03:02:45 -07:00
|
|
|
}
|
2007-08-31 15:29:55 -07:00
|
|
|
|
2007-05-16 03:02:45 -07:00
|
|
|
}; // end of LoginManagerPrompter implementation
|
|
|
|
|
2008-02-27 21:13:49 -08:00
|
|
|
|
2007-08-31 15:29:55 -07:00
|
|
|
var component = [LoginManagerPromptFactory, LoginManagerPrompter];
|
2010-06-22 09:59:15 -07:00
|
|
|
var NSGetFactory = XPCOMUtils.generateNSGetFactory(component);
|