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 163bc71bf973bf47f5b237cb6ba36c014fb74b8e..ecaa1504905901097c982bfab673a15a38d0363f 100644 |
--- a/components/password_manager/core/browser/password_form_manager.cc |
+++ b/components/password_manager/core/browser/password_form_manager.cc |
@@ -282,6 +282,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); |
@@ -844,6 +854,22 @@ void PasswordFormManager::CreatePendingCredentials() { |
// credential. |
selected_username_ = provisionally_saved_form_->username_value; |
is_new_login_ = false; |
+ } else if (client_->IsPasswordUpdateUIEnabled() && |
+ !provisionally_saved_form_->new_password_element.empty() && |
+ provisionally_saved_form_->username_value.empty()) { |
+ // This is password change form without username. If username is present |
+ // processing of password change form is almost the same as usual sign-in |
+ // forms. |
+ PasswordFormMap::const_iterator best_password_match_it = |
+ FindBestMatchForPasswordChange( |
+ provisionally_saved_form_->password_value); |
+ |
+ if (best_password_match_it != best_matches_.end()) { |
+ pending_credentials_ = *best_password_match_it->second; |
vasilii
2015/06/03 18:32:02
You found the credential with |provisionally_saved
dvadym
2015/06/19 15:27:29
It was implemented earlier, so I just need to use
|
+ } |
+ pending_credentials_.is_password_change_form_without_username = true; |
+ // We don't care about |pending_credentials| if we didn't find best match, |
+ // since the user will select the correct one. |
} else { |
// User typed in a new, unknown username. |
user_action_ = kUserActionOverrideUsernameAndPassword; |
@@ -860,11 +886,12 @@ void PasswordFormManager::CreatePendingCredentials() { |
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 (!provisionally_saved_form_->new_password_element.empty()) { |
+ // 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. |
pending_credentials_.password_element.clear(); |
pending_credentials_.new_password_element.clear(); |
} |
@@ -878,6 +905,7 @@ void PasswordFormManager::CreatePendingCredentials() { |
pending_credentials_.action = observed_form_.action; |
pending_credentials_.password_value = password_to_save; |
+ |
vabr (Chromium)
2015/06/03 16:33:26
nit: Any particular reason to introduce this blank
dvadym
2015/06/19 15:27:29
Done.
|
pending_credentials_.preferred = provisionally_saved_form_->preferred; |
if (user_action_ == kUserActionOverridePassword && |
@@ -946,6 +974,31 @@ int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
return score; |
} |
+PasswordFormMap::const_iterator |
+PasswordFormManager::FindBestMatchForPasswordChange( |
+ const base::string16& password) { |
+ if (password.empty()) { |
+ if (best_matches_.size() == 1) { |
+ // In case when there is no old password on the form and the user has only |
+ // 1 credentials, consider this as the same credentials. |
vabr (Chromium)
2015/06/03 16:33:26
nit: credentials -> credential
(or alternatively "
dvadym
2015/06/19 15:27:29
Changed to piece of credentials
|
+ return best_matches_.begin(); |
+ } else { |
vasilii
2015/06/03 18:32:02
We don't write "else" after "return".
dvadym
2015/06/19 15:27:29
Done.
|
+ return best_matches_.end(); |
vabr (Chromium)
2015/06/03 16:33:26
Why exactly end()?
Also what if best_matches_ is e
dvadym
2015/06/19 15:27:29
.end() is returned in order to comply with standar
vabr (Chromium)
2015/06/19 18:03:16
Acknowledged.
|
+ } |
+ } |
+ PasswordFormMap::const_iterator best_password_match_it = best_matches_.end(); |
+ for (auto it = best_matches_.cbegin(); it != best_matches_.cend(); ++it) { |
vasilii
2015/06/03 18:32:02
What is the reason to go backwards?
dvadym
2015/06/19 15:27:29
It would be rbegin() and rend() for going backward
|
+ if (it->second->password_value == password) { |
+ if (best_password_match_it != best_matches_.end()) { |
+ // Found the second credentials with the same password, do nothing. |
vabr (Chromium)
2015/06/03 16:33:26
nit: credential
dvadym
2015/06/19 15:27:29
Done.
|
+ return best_matches_.end(); |
+ } |
+ best_password_match_it = it; |
+ } |
+ } |
+ return best_password_match_it; |
+} |
+ |
void PasswordFormManager::SubmitPassed() { |
submit_result_ = kSubmitResultPassed; |
if (has_generated_password_) |