If a page prefills a username field with a username that we have a saved login for, go ahead and prefill the saved password. Bug 229652.

This commit is contained in:
bryner%brianryner.com 2004-07-29 08:22:05 +00:00
parent 1a8b51b957
commit a5c2b3fcf0

View File

@ -809,6 +809,7 @@ nsPasswordManager::OnStateChange(nsIWebProgress* aWebProgress,
nsCOMPtr<nsIForm> form = do_QueryInterface(formNode); nsCOMPtr<nsIForm> form = do_QueryInterface(formNode);
SignonDataEntry* firstMatch = nsnull; SignonDataEntry* firstMatch = nsnull;
PRBool attachedToInput = PR_FALSE;
nsCOMPtr<nsIDOMHTMLInputElement> userField, passField; nsCOMPtr<nsIDOMHTMLInputElement> userField, passField;
nsCOMPtr<nsIDOMHTMLInputElement> temp; nsCOMPtr<nsIDOMHTMLInputElement> temp;
nsAutoString fieldType; nsAutoString fieldType;
@ -887,35 +888,56 @@ nsPasswordManager::OnStateChange(nsIWebProgress* aWebProgress,
continue; continue;
} }
if (firstMatch || !oldUserValue.IsEmpty() || !oldPassValue.IsEmpty()) { if (!oldUserValue.IsEmpty()) {
// We've found more than one possible signon for this form, or // The page has prefilled a username.
// the fields were already populated using the value attribute. // If it matches any of our saved usernames, prefill the password
// for that username. If there are multiple saved usernames,
// we will also attach the autocomplete listener.
nsAutoString userValue;
if (NS_FAILED(DecryptData(e->userValue, userValue)))
goto done;
if (userValue.Equals(oldUserValue)) {
nsAutoString passValue;
if (NS_FAILED(DecryptData(e->passValue, passValue)))
goto done;
passField->SetValue(passValue);
}
}
if (firstMatch && !attachedToInput) {
// We've found more than one possible signon for this form.
// Listen for blur and autocomplete events on the username field so // Listen for blur and autocomplete events on the username field so
// that we can attempt to prefill the password after the user has // that we can attempt to prefill the password after the user has
// entered the username. // entered the username.
AttachToInput(userField); AttachToInput(userField);
firstMatch = nsnull; attachedToInput = PR_TRUE;
break; // on to the next form
} else { } else {
firstMatch = e; firstMatch = e;
} }
} }
if (firstMatch) { if (firstMatch && !attachedToInput) {
nsAutoString buffer; nsAutoString buffer;
if (NS_SUCCEEDED(DecryptData(firstMatch->userValue, buffer))) { if (NS_FAILED(DecryptData(firstMatch->userValue, buffer)))
userField->SetValue(buffer); goto done;
if (NS_SUCCEEDED(DecryptData(firstMatch->passValue, buffer))) userField->SetValue(buffer);
passField->SetValue(buffer);
}
if (NS_FAILED(DecryptData(firstMatch->passValue, buffer)))
goto done;
passField->SetValue(buffer);
AttachToInput(userField); AttachToInput(userField);
} }
} }
done:
nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(domDoc); nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(domDoc);
targ->AddEventListener(NS_LITERAL_STRING("unload"), targ->AddEventListener(NS_LITERAL_STRING("unload"),
NS_STATIC_CAST(nsIDOMLoadListener*, this), PR_FALSE); NS_STATIC_CAST(nsIDOMLoadListener*, this), PR_FALSE);