Index: components/password_manager/core/browser/password_form_manager.cc |
diff --git a/components/password_manager/core/browser/password_form_manager.cc b/components/password_manager/core/browser/password_form_manager.cc |
index 5f7d21fe499d74f674d9b1950df562abe54acdb1..5affbf9523789dfa8e5332a8db51923459541de9 100644 |
--- a/components/password_manager/core/browser/password_form_manager.cc |
+++ b/components/password_manager/core/browser/password_form_manager.cc |
@@ -218,7 +218,8 @@ bool PasswordFormManager::HasValidPasswordForm() { |
if (observed_form_.scheme != PasswordForm::SCHEME_HTML) |
return true; |
return !observed_form_.username_element.empty() && |
- !observed_form_.password_element.empty(); |
+ (!observed_form_.password_element.empty() || |
+ !observed_form_.new_password_element.empty()); |
} |
void PasswordFormManager::ProvisionallySave( |
@@ -227,6 +228,13 @@ void PasswordFormManager::ProvisionallySave( |
DCHECK_EQ(state_, POST_MATCHING_PHASE); |
DCHECK(DoesManage(credentials, ACTION_MATCH_NOT_REQUIRED)); |
+ // If this was a sign-up or change password form, we want to persist the new |
+ // password; if this was a login form, then the current password (which might |
+ // be "new" in the sense that we see these credentials for the first time, or |
+ // when the stored password was long out-of-date). |
+ base::string16 password_to_save(credentials.new_password_element.empty() ? |
+ credentials.password_value : credentials.new_password_value); |
+ |
// Make sure the important fields stay the same as the initially observed or |
// autofilled ones, as they may have changed if the user experienced a login |
// failure. |
@@ -244,7 +252,7 @@ void PasswordFormManager::ProvisionallySave( |
user_action_ = kUserActionChoosePslMatch; |
// Check to see if we're using a known username but a new password. |
- if (pending_credentials_.password_value != credentials.password_value) |
+ if (pending_credentials_.password_value != password_to_save) |
user_action_ = kUserActionOverridePassword; |
} else if (action == ALLOW_OTHER_POSSIBLE_USERNAMES && |
UpdatePendingCredentialsIfOtherPossibleUsername( |
@@ -262,6 +270,20 @@ void PasswordFormManager::ProvisionallySave( |
pending_credentials_.username_value = credentials.username_value; |
pending_credentials_.other_possible_usernames = |
credentials.other_possible_usernames; |
+ |
+ // The password value will be filled in later, remove any garbage for now. |
+ pending_credentials_.password_value.clear(); |
+ pending_credentials_.new_password_value.clear(); |
+ |
+ // If this was a sign-up or change password form, the names of the elements |
+ // are likely different than those on a login form, so do not bother saving |
+ // them. We will fill them with meaningful values in UpdateLogin() when the |
+ // user goes onto a real login form for the first time. |
+ if (!credentials.new_password_element.empty()) { |
+ pending_credentials_.username_element.clear(); |
+ pending_credentials_.password_element.clear(); |
+ pending_credentials_.new_password_element.clear(); |
+ } |
} |
pending_credentials_.action = credentials.action; |
@@ -271,7 +293,7 @@ void PasswordFormManager::ProvisionallySave( |
if (pending_credentials_.action.is_empty()) |
pending_credentials_.action = observed_form_.action; |
- pending_credentials_.password_value = credentials.password_value; |
+ pending_credentials_.password_value = password_to_save; |
pending_credentials_.preferred = credentials.preferred; |
if (user_action_ == kUserActionOverridePassword && |
@@ -444,13 +466,12 @@ void PasswordFormManager::OnGetPasswordStoreResults( |
} |
bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { |
- // Ignore change password forms until we have some change password |
- // functionality |
- if (observed_form_.old_password_element.length() != 0) { |
+ // Ignore change passwords until we have some change password functionality. |
+ if (!observed_form_.password_element.empty() && |
+ !observed_form_.new_password_element.empty()) { |
return true; |
} |
- // Don't match an invalid SSL form with one saved under secure |
- // circumstances. |
+ // Don't match an invalid SSL form with one saved under secure circumstances. |
if (form.ssl_valid && !observed_form_.ssl_valid) { |
return true; |
} |
@@ -574,9 +595,10 @@ void PasswordFormManager::UpdateLogin() { |
copy.origin = observed_form_.origin; |
copy.action = observed_form_.action; |
password_store->AddLogin(copy); |
- } else if (pending_credentials_.password_element.empty() || |
- pending_credentials_.username_element.empty() || |
- pending_credentials_.submit_element.empty()) { |
+ } else if (observed_form_.new_password_element.empty() && |
+ (pending_credentials_.password_element.empty() || |
+ pending_credentials_.username_element.empty() || |
+ pending_credentials_.submit_element.empty())) { |
// password_element and username_element can't be updated because they are |
// part of Sync and PasswordStore primary key. Thus, we must delete the old |
// one and add again. |