make it so we can stuff a value given to us by the user from a Prompt()

can be stuffed into the single signon database, just like a password
can be.  auth news needs this.  r=dp,alecf
This commit is contained in:
sspitzer%netscape.com 2000-02-01 08:43:48 +00:00
Родитель 220fc77db3
Коммит 40b08d3c88
4 изменённых файлов: 127 добавлений и 3 удалений

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

@ -186,6 +186,55 @@ si_CheckGetPassword
}
}
nsresult
si_CheckGetData
(PRUnichar ** data,
const PRUnichar * szMessage,
PRBool* checkValue)
{
nsresult res;
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
if (NS_FAILED(res)) {
return res;
}
PRInt32 buttonPressed = 1; /* in case user exits dialog by clickin X */
PRUnichar * prompt_string = Wallet_Localize("PromptForData");
PRUnichar * check_string = Wallet_Localize("SaveThisValue");
res = dialog->UniversalDialog(
NULL, /* title message */
prompt_string, /* title text in top line of window */
szMessage, /* this is the main message */
check_string, /* This is the checkbox message */
NULL, /* first button text, becomes OK by default */
NULL, /* second button text, becomes CANCEL by default */
NULL, /* third button text */
NULL, /* fourth button text */
NULL, /* first edit field label */
NULL, /* second edit field label */
data, /* first edit field initial and final value */
NULL, /* second edit field initial and final value */
NULL, /* icon: question mark by default */
checkValue, /* initial and final value of checkbox */
2, /* number of buttons */
1, /* number of edit fields */
0, /* is first edit field a password field */
&buttonPressed);
Recycle(prompt_string);
Recycle(check_string);
if (NS_FAILED(res)) {
return res;
}
if (buttonPressed == 0) {
return NS_OK;
} else {
return NS_ERROR_FAILURE; /* user pressed cancel */
}
}
nsresult
si_CheckGetUsernamePassword
(PRUnichar ** username,
@ -2496,7 +2545,8 @@ SINGSIGN_PromptUsernameAndPassword
PUBLIC nsresult
SINGSIGN_PromptPassword
(const PRUnichar *text, PRUnichar **pwd, const char *urlname,
nsIPrompt* dialog, PRBool *returnValue, PRBool strip) {
nsIPrompt* dialog, PRBool *returnValue, PRBool strip)
{
nsresult res;
nsAutoString password, username;
@ -2574,7 +2624,59 @@ SINGSIGN_PromptPassword
PUBLIC nsresult
SINGSIGN_Prompt
(const PRUnichar *text, const PRUnichar *defaultText, PRUnichar **resultText,
const char *urlname, nsIPrompt* dialog, PRBool *returnValue, PRBool strip) {
const char *urlname, nsIPrompt* dialog, PRBool *returnValue, PRBool strip)
{
nsresult res;
nsAutoString data, emptyUsername("");
/* do only the dialog if signon preference is not enabled */
if (!si_GetSignonRememberingPref()){
return dialog->Prompt(text, nsnull /* window title */, resultText, returnValue);
}
/* convert to a uri so we can parse out the hostname */
nsCOMPtr<nsIURL> uri;
nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), (void **) getter_AddRefs(uri));
uri->SetSpec((char *)urlname);
/* get host part of the uri */
char* host;
if (strip) {
res = uri->GetHost(&host);
if (NS_FAILED(res)) {
return res;
}
} else {
host = (nsAutoString(":") + urlname).ToNewCString();
}
/* get previous data used with this hostname */
si_RestoreOldSignonDataFromBrowser(host, PR_TRUE, emptyUsername, data);
/* return if data was found */
if (data.Length() != 0) {
*resultText = data.ToNewUnicode();
*returnValue = PR_TRUE;
PR_FREEIF(host);
return NS_OK;
}
/* no data found, get new data from user */
*resultText = data.ToNewUnicode();
PRBool checked = PR_TRUE;
res = si_CheckGetData(resultText, text, &checked);
if (NS_FAILED(res)) {
/* user pressed Cancel */
PR_FREEIF(*resultText);
PR_FREEIF(host);
return res;
}
if (checked) {
si_RememberSignonDataFromBrowser (host, emptyUsername, nsAutoString(*resultText));
}
/* cleanup and return */
PR_FREEIF(host);
return NS_OK;
}

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

@ -37,7 +37,8 @@ No = No
Never = Never
Confirm = Confirm
PromptForPassword = AutoFill Password
PromptForData = AutoFill Data
SaveTheseValues = Save these values
SaveThisValue = Save this value
UserName = User Name
Password = Password
Password = Password

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

@ -58,6 +58,16 @@ interface nsINetPrompt : nsISupports
in wstring title,
in wstring text,
out wstring pwd);
/**
* Puts up a prompt dialog with OK and Cancel buttons.
* @return true for OK, false for Cancel
*/
boolean prompt(
in string url,
in wstring title,
in wstring text,
out wstring pwd);
};

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

@ -2825,6 +2825,7 @@ NS_IMETHODIMP nsWebShellWindow::PromptUsernameAndPassword(const char *url, const
return wallet->PromptUsernameAndPasswordURL(text,user, pwd, url, prompter, _retval);
}
NS_IMETHODIMP nsWebShellWindow::PromptPassword(const char *url, const PRUnichar *title, const PRUnichar *text, PRUnichar **pwd, PRBool *_retval)
{
nsresult res;
@ -2836,3 +2837,13 @@ NS_IMETHODIMP nsWebShellWindow::PromptPassword(const char *url, const PRUnichar
return wallet->PromptPasswordURL(text, pwd, url, prompter, _retval);
}
NS_IMETHODIMP nsWebShellWindow::Prompt(const char *url, const PRUnichar *title, const PRUnichar *text, PRUnichar **value, PRBool *_retval)
{
nsresult res;
NS_WITH_SERVICE(nsIWalletService, wallet, kWalletServiceCID, &res);
if (NS_FAILED(res)) {
return Prompt(text, title, value, _retval);
}
nsCOMPtr<nsIPrompt> prompter = this;
return wallet->PromptURL(text, nsnull, value, url, prompter, _retval);
}