Followup for Bug 226735: replace modal pre-submit save password dialog with post-submit bar. r=gavin

This commit is contained in:
dolske%mozilla.com 2007-09-05 02:07:43 +00:00
Родитель 15e1abb04d
Коммит 1370011fe1
3 изменённых файлов: 81 добавлений и 45 удалений

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

@ -43,15 +43,59 @@ interface nsIDOMWindow;
[scriptable, uuid(68b3cb59-51b8-4c57-bd7f-b2ce955a593d)]
interface nsILoginManagerPrompter : nsISupports {
/**
* Initialize the prompter. Must be called before using other interfaces.
*
* @param aWindow
* The in which the user is doing some login-related action that's
* resulting in a need to prompt them for something. The prompt
* will be associated with this window (or, if a notification bar
* is being used, topmost opener in some cases).
*/
void init(in nsIDOMWindow aWindow);
/**
* Ask the user if they want to save a login (Yes, Never, Not Now)
*
* @param aLogin
* The login to be saved.
*/
void promptToSavePassword(in nsILoginInfo aLogin);
void promptToChangePassword(in AString aUsername);
/**
* Ask the user if they want to change a login's password. If the
* user consents, modifyLogin() will be called.
*
* @param aOldLogin
* The existing login (with the old password).
* @param aNewLogin
* The new login.
*/
void promptToChangePassword(in nsILoginInfo aOldLogin,
in nsILoginInfo aNewLogin);
/**
* Ask the user if they want to change the password for one of
* multiple logins, when the caller can't determine exactly which
* login should be changed. If the user consents, modifyLogin() will
* be called.
*
* @param logins
* An array of existing logins.
* @param count
* (length of the array)
* @param aNewLogin
* The new login.
*
* Note: Because the caller does not know the username of the login
* to be changed, aNewLogin.username and aNewLogin.usernameField
* will be set (using the user's selection) before modifyLogin()
* is called.
*/
void promptToChangePasswordWithUsernames(
[array, size_is(count)] in nsILoginInfo logins,
in PRUint32 count,
[array, size_is(count)] in wstring usernames);
in nsILoginInfo aNewLogin);
};
%{C++

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

@ -781,7 +781,6 @@ LoginManager.prototype = {
// logins to update the password for.
if (!usernameField && oldPasswordField) {
var ok, username;
var logins = this.findLogins({}, hostname, formSubmitURL, null);
// XXX we could be smarter here: look for a login matching the
@ -802,32 +801,16 @@ LoginManager.prototype = {
var prompter = getPrompter(win);
if (logins.length == 1) {
username = logins[0].username;
ok = prompter.promptToChangePassword(username);
var oldLogin = logins[0];
formLogin.username = oldLogin.username;
formLogin.usernameField = oldLogin.usernameField;
prompter.promptToChangePassword(oldLogin, formLogin);
} else {
var usernames = logins.map(function (l) l.username);
[ok, username] = prompter.promptToChangePasswordWithUsernames(
usernames);
prompter.promptToChangePasswordWithUsernames(
logins, logins.length, formLogin);
}
if (!ok)
return;
// Now that we know the desired username, find that login and
// update the info in our formLogin representation.
this.log("Updating password for username " + username);
var existingLogin;
logins.some(function(l) {
existingLogin = l;
return (l.username == username);
});
formLogin.username = username;
formLogin.usernameField = existingLogin.usernameField;
this.modifyLogin(existingLogin, formLogin);
return;
}

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

@ -458,24 +458,25 @@ LoginManagerPrompter.prototype = {
* login, when the form being submitted contains multiple password
* fields.
*
* Return values:
* true - Update the stored password
* false - Do not update the stored password
*/
promptToChangePassword : function (aUsername) {
promptToChangePassword : function (aOldLogin, aNewLogin) {
const buttonFlags = Ci.nsIPrompt.STD_YES_NO_BUTTONS;
var dialogText = this._getLocalizedString(
"passwordChangeText", [aUsername]);
"passwordChangeText",
[aOldLogin.username]);
var dialogTitle = this._getLocalizedString(
"passwordChangeTitle");
// returns 0 for yes, 1 for no.
var result = this._promptService.confirmEx(this._window,
var ok = !this._promptService.confirmEx(this._window,
dialogTitle, dialogText, buttonFlags,
null, null, null,
null, {});
return !result;
if (ok) {
this.log("Updating password for user " + aOldLogin.username);
this._pwmgr.modifyLogin(aOldLogin, aNewLogin);
}
},
@ -486,20 +487,19 @@ LoginManagerPrompter.prototype = {
* don't know which existing login (username) it's for. Asks the user
* to select a username and confirm the password change.
*
* Returns multiple parameters:
* [0] - User's response to the dialog
* true = Update the stored password
* false = Do not update the stored password
* [1] - The username selected
* (null if [0] is false)
*
* 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.
*
* Note; XPCOM stupidity: |count| is just |logins.length|.
*/
promptToChangePasswordWithUsernames : function (usernames) {
promptToChangePasswordWithUsernames : function (logins, count, aNewLogin) {
const buttonFlags = Ci.nsIPrompt.STD_YES_NO_BUTTONS;
var usernames = logins.map(function (l) l.username);
var dialogText = this._getLocalizedString("userSelectText");
var dialogTitle = this._getLocalizedString("passwordChangeTitle");
var selectedUser = null, selectedIndex = { value: null };
var selectedIndex = { value: null };
// If user selects ok, outparam.value is set to the index
// of the selected username.
@ -507,10 +507,19 @@ LoginManagerPrompter.prototype = {
dialogTitle, dialogText,
usernames.length, usernames,
selectedIndex);
if (ok)
selectedUser = usernames[selectedIndex.value];
if (ok) {
// Now that we know which login to change the password for,
// update the missing username info in the aNewLogin.
return [ok, selectedUser];
var selectedLogin = logins[selectedIndex.value];
this.log("Updating password for user " + selectedLogin.username);
aNewLogin.username = selectedLogin.username;
aNewLogin.usernameField = selectedLogin.usernameField;
this._pwmgr.modifyLogin(selectedLogin, aNewLogin);
}
},