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 f6738f8c8622ff88b0c6dfbfbbbc60c8a71cf752..f1ad08ccf15c74e79f7011facc194cd56aa7d1ac 100644 |
--- a/components/password_manager/core/browser/password_form_manager.cc |
+++ b/components/password_manager/core/browser/password_form_manager.cc |
@@ -290,6 +290,16 @@ void PasswordFormManager::Save() { |
UpdateLogin(); |
} |
+void PasswordFormManager::Update( |
+ const autofill::PasswordForm& credentials_to_update) { |
+ base::string16 password_to_save = pending_credentials_.password_value; |
+ pending_credentials_ = credentials_to_update; |
+ pending_credentials_.password_value = password_to_save; |
+ pending_credentials_.preferred = true; |
+ is_new_login_ = false; |
+ UpdateLogin(); |
+} |
+ |
void PasswordFormManager::FetchMatchingLoginsFromPasswordStore( |
PasswordStore::AuthorizationPromptPolicy prompt_policy) { |
DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
@@ -861,6 +871,17 @@ void PasswordFormManager::CreatePendingCredentials() { |
// credential. |
selected_username_ = provisionally_saved_form_->username_value; |
is_new_login_ = false; |
+ } else if (client_->IsUpdatePasswordUIEnabled() && |
+ provisionally_saved_form_ |
+ ->IsPossibleChangePasswordFormWithoutUsername()) { |
+ PasswordForm* best_update_match = FindBestMatchForUpdatePassword( |
+ provisionally_saved_form_->password_value); |
+ |
+ if (best_update_match) { |
+ pending_credentials_ = *best_update_match; |
+ } |
+ // We don't care about |pending_credentials_| if we didn't find the best |
+ // match, since the user will select the correct one. |
} else { |
// User typed in a new, unknown username. |
user_action_ = kUserActionOverrideUsernameAndPassword; |
@@ -965,6 +986,29 @@ int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
return score; |
} |
+PasswordForm* PasswordFormManager::FindBestMatchForUpdatePassword( |
+ const base::string16& password) { |
vasilii
2015/07/23 15:15:13
Can it be a const method?
dvadym
2015/07/24 16:42:40
Thanks, changed to const
|
+ if (password.empty()) { |
+ if (best_matches_.size() == 1) { |
+ // In case when there is no old password on the form and the user has only |
+ // one piece of credentials, consider it the same as is being saved. |
+ return best_matches_.begin()->second; |
+ } |
+ return nullptr; |
+ } |
+ PasswordFormMap::const_iterator best_password_match_it = best_matches_.end(); |
+ for (auto it = best_matches_.begin(); it != best_matches_.end(); ++it) { |
+ if (it->second->password_value == password) { |
+ if (best_password_match_it != best_matches_.end()) { |
+ // Found the second credential with the same password, do nothing. |
vabr (Chromium)
2015/07/24 08:24:29
nit: the second -> a second
dvadym
2015/07/24 16:42:40
Done.
|
+ return nullptr; |
+ } |
+ best_password_match_it = it; |
+ } |
+ } |
+ return best_password_match_it->second; |
vasilii
2015/07/23 15:15:13
real danger: best_matches_.end()->second
dvadym
2015/07/24 16:42:40
Thanks, added checking on .end()
|
+} |
+ |
void PasswordFormManager::SubmitPassed() { |
submit_result_ = kSubmitResultPassed; |
if (has_generated_password_) |