OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/password_manager/core/browser/password_form_manager.h" | 5 #include "components/password_manager/core/browser/password_form_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 password_manager_(password_manager), | 116 password_manager_(password_manager), |
117 preferred_match_(nullptr), | 117 preferred_match_(nullptr), |
118 is_ignorable_change_password_form_(false), | 118 is_ignorable_change_password_form_(false), |
119 is_possible_change_password_form_without_username_( | 119 is_possible_change_password_form_without_username_( |
120 observed_form.IsPossibleChangePasswordFormWithoutUsername()), | 120 observed_form.IsPossibleChangePasswordFormWithoutUsername()), |
121 state_(PRE_MATCHING_PHASE), | 121 state_(PRE_MATCHING_PHASE), |
122 client_(client), | 122 client_(client), |
123 manager_action_(kManagerActionNone), | 123 manager_action_(kManagerActionNone), |
124 user_action_(kUserActionNone), | 124 user_action_(kUserActionNone), |
125 submit_result_(kSubmitResultNotSubmitted), | 125 submit_result_(kSubmitResultNotSubmitted), |
126 form_type_(kFormTypeUnspecified) { | 126 form_type_(kFormTypeUnspecified), |
| 127 need_to_refetch_(false) { |
127 DCHECK_EQ(observed_form.scheme == PasswordForm::SCHEME_HTML, | 128 DCHECK_EQ(observed_form.scheme == PasswordForm::SCHEME_HTML, |
128 driver != nullptr); | 129 driver != nullptr); |
129 if (driver) | 130 if (driver) |
130 drivers_.push_back(driver); | 131 drivers_.push_back(driver); |
131 } | 132 } |
132 | 133 |
133 PasswordFormManager::~PasswordFormManager() { | 134 PasswordFormManager::~PasswordFormManager() { |
134 UMA_HISTOGRAM_ENUMERATION( | 135 UMA_HISTOGRAM_ENUMERATION( |
135 "PasswordManager.ActionsTakenV3", GetActionsTaken(), kMaxNumActionsTaken); | 136 "PasswordManager.ActionsTakenV3", GetActionsTaken(), kMaxNumActionsTaken); |
136 if (submit_result_ == kSubmitResultNotSubmitted) { | 137 if (submit_result_ == kSubmitResultNotSubmitted) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 form_structure.FormSignature()); | 303 form_structure.FormSignature()); |
303 } | 304 } |
304 base::string16 password_to_save = pending_credentials_.password_value; | 305 base::string16 password_to_save = pending_credentials_.password_value; |
305 pending_credentials_ = credentials_to_update; | 306 pending_credentials_ = credentials_to_update; |
306 pending_credentials_.password_value = password_to_save; | 307 pending_credentials_.password_value = password_to_save; |
307 pending_credentials_.preferred = true; | 308 pending_credentials_.preferred = true; |
308 is_new_login_ = false; | 309 is_new_login_ = false; |
309 UpdateLogin(); | 310 UpdateLogin(); |
310 } | 311 } |
311 | 312 |
312 void PasswordFormManager::FetchDataFromPasswordStore( | 313 void PasswordFormManager::FetchDataFromPasswordStore() { |
313 PasswordStore::AuthorizationPromptPolicy prompt_policy) { | |
314 if (state_ == MATCHING_PHASE) { | 314 if (state_ == MATCHING_PHASE) { |
315 // There is currently a password store query in progress. Remember the | 315 // There is currently a password store query in progress, need to re-fetch |
316 // prompt policy for when the store results are back and another store query | 316 // store results later. |
317 // might be issued. | 317 need_to_refetch_ = true; |
318 next_prompt_policy_.reset( | |
319 new PasswordStore::AuthorizationPromptPolicy(prompt_policy)); | |
320 return; | 318 return; |
321 } | 319 } |
322 | 320 |
323 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 321 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
324 if (password_manager_util::IsLoggingActive(client_)) { | 322 if (password_manager_util::IsLoggingActive(client_)) { |
325 logger.reset( | 323 logger.reset( |
326 new BrowserSavePasswordProgressLogger(client_->GetLogManager())); | 324 new BrowserSavePasswordProgressLogger(client_->GetLogManager())); |
327 logger->LogMessage(Logger::STRING_FETCH_LOGINS_METHOD); | 325 logger->LogMessage(Logger::STRING_FETCH_LOGINS_METHOD); |
328 logger->LogNumber(Logger::STRING_FORM_MANAGER_STATE, state_); | 326 logger->LogNumber(Logger::STRING_FORM_MANAGER_STATE, state_); |
329 } | 327 } |
330 | 328 |
331 provisionally_saved_form_.reset(); | 329 provisionally_saved_form_.reset(); |
332 state_ = MATCHING_PHASE; | 330 state_ = MATCHING_PHASE; |
333 | 331 |
334 PasswordStore* password_store = client_->GetPasswordStore(); | 332 PasswordStore* password_store = client_->GetPasswordStore(); |
335 if (!password_store) { | 333 if (!password_store) { |
336 if (logger) | 334 if (logger) |
337 logger->LogMessage(Logger::STRING_NO_STORE); | 335 logger->LogMessage(Logger::STRING_NO_STORE); |
338 NOTREACHED(); | 336 NOTREACHED(); |
339 return; | 337 return; |
340 } | 338 } |
341 password_store->GetLogins(observed_form_, prompt_policy, this); | 339 password_store->GetLogins(observed_form_, this); |
342 | 340 |
343 // The statistics isn't needed on mobile, only on desktop. Let's save some | 341 // The statistics isn't needed on mobile, only on desktop. Let's save some |
344 // processor cycles. | 342 // processor cycles. |
345 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 343 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
346 // The statistics is needed for the "Save password?" bubble. | 344 // The statistics is needed for the "Save password?" bubble. |
347 password_store->GetSiteStats(observed_form_.origin.GetOrigin(), this); | 345 password_store->GetSiteStats(observed_form_.origin.GetOrigin(), this); |
348 #endif | 346 #endif |
349 } | 347 } |
350 | 348 |
351 bool PasswordFormManager::HasCompletedMatching() const { | 349 bool PasswordFormManager::HasCompletedMatching() const { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 return; | 521 return; |
524 | 522 |
525 manager_action_ = kManagerActionAutofilled; | 523 manager_action_ = kManagerActionAutofilled; |
526 password_manager_->AutofillHttpAuth(best_matches_, *preferred_match_); | 524 password_manager_->AutofillHttpAuth(best_matches_, *preferred_match_); |
527 } | 525 } |
528 | 526 |
529 void PasswordFormManager::OnGetPasswordStoreResults( | 527 void PasswordFormManager::OnGetPasswordStoreResults( |
530 ScopedVector<PasswordForm> results) { | 528 ScopedVector<PasswordForm> results) { |
531 DCHECK_EQ(state_, MATCHING_PHASE); | 529 DCHECK_EQ(state_, MATCHING_PHASE); |
532 | 530 |
533 if (next_prompt_policy_) { | 531 if (need_to_refetch_) { |
534 // The received results are no longer up-to-date, need to re-request. | 532 // The received results are no longer up-to-date, need to re-request. |
535 state_ = PRE_MATCHING_PHASE; | 533 state_ = PRE_MATCHING_PHASE; |
536 FetchDataFromPasswordStore(*next_prompt_policy_); | 534 FetchDataFromPasswordStore(); |
537 next_prompt_policy_.reset(); | 535 need_to_refetch_ = false; |
538 return; | 536 return; |
539 } | 537 } |
540 | 538 |
541 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 539 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
542 if (password_manager_util::IsLoggingActive(client_)) { | 540 if (password_manager_util::IsLoggingActive(client_)) { |
543 logger.reset( | 541 logger.reset( |
544 new BrowserSavePasswordProgressLogger(client_->GetLogManager())); | 542 new BrowserSavePasswordProgressLogger(client_->GetLogManager())); |
545 logger->LogMessage(Logger::STRING_ON_GET_STORE_RESULTS_METHOD); | 543 logger->LogMessage(Logger::STRING_ON_GET_STORE_RESULTS_METHOD); |
546 logger->LogNumber(Logger::STRING_NUMBER_RESULTS, results.size()); | 544 logger->LogNumber(Logger::STRING_NUMBER_RESULTS, results.size()); |
547 } | 545 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 | 658 |
661 UpdateMetadataForUsage(pending_credentials_); | 659 UpdateMetadataForUsage(pending_credentials_); |
662 | 660 |
663 client_->GetStoreResultFilter()->ReportFormUsed(pending_credentials_); | 661 client_->GetStoreResultFilter()->ReportFormUsed(pending_credentials_); |
664 | 662 |
665 // Check to see if this form is a candidate for password generation. | 663 // Check to see if this form is a candidate for password generation. |
666 // Do not send votes on change password forms, since they were already sent in | 664 // Do not send votes on change password forms, since they were already sent in |
667 // Update() method. | 665 // Update() method. |
668 if (has_generated_password_) { | 666 if (has_generated_password_) { |
669 UploadGeneratedVote(); | 667 UploadGeneratedVote(); |
670 } else if (!observed_form_.IsPossibleChangePasswordForm()) | 668 } else if (!observed_form_.IsPossibleChangePasswordForm()) { |
671 SendAutofillVotes(observed_form_, &pending_credentials_); | 669 SendAutofillVotes(observed_form_, &pending_credentials_); |
| 670 } |
672 | 671 |
673 UpdatePreferredLoginState(password_store); | 672 UpdatePreferredLoginState(password_store); |
674 | 673 |
675 bool password_was_updated = false; | 674 bool password_was_updated = false; |
676 // Update the new preferred login. | 675 // Update the new preferred login. |
677 if (!selected_username_.empty()) { | 676 if (!selected_username_.empty()) { |
678 // Username has changed. We set this selected username as the real | 677 // Username has changed. We set this selected username as the real |
679 // username. Given that |username_value| is part of the Sync and | 678 // username. Given that |username_value| is part of the Sync and |
680 // PasswordStore primary key, the old primary key must be supplied. | 679 // PasswordStore primary key, the old primary key must be supplied. |
681 PasswordForm old_primary_key(pending_credentials_); | 680 PasswordForm old_primary_key(pending_credentials_); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 ->IsPossibleChangePasswordFormWithoutUsername() || | 1071 ->IsPossibleChangePasswordFormWithoutUsername() || |
1073 provisionally_saved_form_->username_element.empty())) { | 1072 provisionally_saved_form_->username_element.empty())) { |
1074 PasswordForm* best_update_match = FindBestMatchForUpdatePassword( | 1073 PasswordForm* best_update_match = FindBestMatchForUpdatePassword( |
1075 provisionally_saved_form_->password_value); | 1074 provisionally_saved_form_->password_value); |
1076 | 1075 |
1077 retry_password_form_password_update_ = | 1076 retry_password_form_password_update_ = |
1078 provisionally_saved_form_->username_element.empty() && | 1077 provisionally_saved_form_->username_element.empty() && |
1079 provisionally_saved_form_->new_password_element.empty(); | 1078 provisionally_saved_form_->new_password_element.empty(); |
1080 | 1079 |
1081 is_new_login_ = false; | 1080 is_new_login_ = false; |
1082 if (best_update_match) | 1081 if (best_update_match) { |
1083 pending_credentials_ = *best_update_match; | 1082 pending_credentials_ = *best_update_match; |
1084 else if (has_generated_password_) { | 1083 } else if (has_generated_password_) { |
1085 // If a password was generated and we didn't find match we have to save it | 1084 // If a password was generated and we didn't find match we have to save it |
1086 // in separate entry since we have to store it but we don't know where. | 1085 // in separate entry since we have to store it but we don't know where. |
1087 CreatePendingCredentialsForNewCredentials(); | 1086 CreatePendingCredentialsForNewCredentials(); |
1088 is_new_login_ = true; | 1087 is_new_login_ = true; |
1089 } else { | 1088 } else { |
1090 // We don't care about |pending_credentials_| if we didn't find the best | 1089 // We don't care about |pending_credentials_| if we didn't find the best |
1091 // match, since the user will select the correct one. | 1090 // match, since the user will select the correct one. |
1092 pending_credentials_.origin = provisionally_saved_form_->origin; | 1091 pending_credentials_.origin = provisionally_saved_form_->origin; |
1093 } | 1092 } |
1094 } else { | 1093 } else { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 continue; | 1350 continue; |
1352 } | 1351 } |
1353 password_store->RemoveLogin(*credential_to_delete->second); | 1352 password_store->RemoveLogin(*credential_to_delete->second); |
1354 if (credential_to_delete->second.get() == preferred_match_) | 1353 if (credential_to_delete->second.get() == preferred_match_) |
1355 preferred_match_ = nullptr; | 1354 preferred_match_ = nullptr; |
1356 best_matches_.erase(credential_to_delete); | 1355 best_matches_.erase(credential_to_delete); |
1357 } | 1356 } |
1358 } | 1357 } |
1359 | 1358 |
1360 } // namespace password_manager | 1359 } // namespace password_manager |
OLD | NEW |