| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 event, SUBMISSION_EVENT_ENUM_COUNT); | 61 event, SUBMISSION_EVENT_ENUM_COUNT); |
| 62 } | 62 } |
| 63 | 63 |
| 64 PasswordForm CopyAndModifySSLValidity(const PasswordForm& orig, | 64 PasswordForm CopyAndModifySSLValidity(const PasswordForm& orig, |
| 65 bool ssl_valid) { | 65 bool ssl_valid) { |
| 66 PasswordForm result(orig); | 66 PasswordForm result(orig); |
| 67 result.ssl_valid = ssl_valid; | 67 result.ssl_valid = ssl_valid; |
| 68 return result; | 68 return result; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Returns true if user-typed username and password field values match with one |
| 72 // of the password form within |credentials| map; otherwise false. |
| 73 bool DoesUsenameAndPasswordMatchCredentials( |
| 74 const base::string16& typed_username, |
| 75 const base::string16& typed_password, |
| 76 const autofill::PasswordFormMap& credentials) { |
| 77 for (auto match : credentials) { |
| 78 if (match.second->username_value == typed_username && |
| 79 match.second->password_value == typed_password) |
| 80 return true; |
| 81 } |
| 82 return false; |
| 83 } |
| 84 |
| 71 } // namespace | 85 } // namespace |
| 72 | 86 |
| 73 PasswordFormManager::PasswordFormManager( | 87 PasswordFormManager::PasswordFormManager( |
| 74 PasswordManager* password_manager, | 88 PasswordManager* password_manager, |
| 75 PasswordManagerClient* client, | 89 PasswordManagerClient* client, |
| 76 const base::WeakPtr<PasswordManagerDriver>& driver, | 90 const base::WeakPtr<PasswordManagerDriver>& driver, |
| 77 const PasswordForm& observed_form, | 91 const PasswordForm& observed_form, |
| 78 bool ssl_valid) | 92 bool ssl_valid) |
| 79 : best_matches_deleter_(&best_matches_), | 93 : best_matches_deleter_(&best_matches_), |
| 80 observed_form_(CopyAndModifySSLValidity(observed_form, ssl_valid)), | 94 observed_form_(CopyAndModifySSLValidity(observed_form, ssl_valid)), |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 PasswordStore::AuthorizationPromptPolicy prompt_policy) { | 383 PasswordStore::AuthorizationPromptPolicy prompt_policy) { |
| 370 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | 384 DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
| 371 state_ = MATCHING_PHASE; | 385 state_ = MATCHING_PHASE; |
| 372 | 386 |
| 373 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 387 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| 374 if (client_->IsLoggingActive()) { | 388 if (client_->IsLoggingActive()) { |
| 375 logger.reset(new BrowserSavePasswordProgressLogger(client_)); | 389 logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| 376 logger->LogMessage(Logger::STRING_FETCH_LOGINS_METHOD); | 390 logger->LogMessage(Logger::STRING_FETCH_LOGINS_METHOD); |
| 377 } | 391 } |
| 378 | 392 |
| 379 // Do not autofill on sign-up or change password forms (until we have some | |
| 380 // working change password functionality). | |
| 381 if (!observed_form_.new_password_element.empty()) { | |
| 382 if (logger) | |
| 383 logger->LogMessage(Logger::STRING_FORM_NOT_AUTOFILLED); | |
| 384 client_->AutofillResultsComputed(); | |
| 385 // There is no point in looking for the credentials in the store when they | |
| 386 // won't be autofilled, so pretend there were none. | |
| 387 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm>()); | |
| 388 return; | |
| 389 } | |
| 390 | |
| 391 PasswordStore* password_store = client_->GetPasswordStore(); | 393 PasswordStore* password_store = client_->GetPasswordStore(); |
| 392 if (!password_store) { | 394 if (!password_store) { |
| 393 if (logger) | 395 if (logger) |
| 394 logger->LogMessage(Logger::STRING_NO_STORE); | 396 logger->LogMessage(Logger::STRING_NO_STORE); |
| 395 NOTREACHED(); | 397 NOTREACHED(); |
| 396 return; | 398 return; |
| 397 } | 399 } |
| 398 password_store->GetLogins(observed_form_, prompt_policy, this); | 400 password_store->GetLogins(observed_form_, prompt_policy, this); |
| 399 } | 401 } |
| 400 | 402 |
| 401 bool PasswordFormManager::HasCompletedMatching() const { | 403 bool PasswordFormManager::HasCompletedMatching() const { |
| 402 return state_ == POST_MATCHING_PHASE; | 404 return state_ == POST_MATCHING_PHASE; |
| 403 } | 405 } |
| 404 | 406 |
| 405 bool PasswordFormManager::IsIgnorableChangePasswordForm() const { | 407 bool PasswordFormManager::IsIgnorableChangePasswordForm( |
| 408 const base::string16& typed_username, |
| 409 const base::string16& typed_password) const { |
| 406 bool is_change_password_form = !observed_form_.new_password_element.empty() && | 410 bool is_change_password_form = !observed_form_.new_password_element.empty() && |
| 407 !observed_form_.password_element.empty(); | 411 !observed_form_.password_element.empty(); |
| 408 bool is_username_certainly_correct = observed_form_.username_marked_by_site; | 412 return is_change_password_form && !observed_form_.username_marked_by_site && |
| 409 return is_change_password_form && !is_username_certainly_correct; | 413 !DoesUsenameAndPasswordMatchCredentials(typed_username, typed_password, |
| 414 best_matches_); |
| 410 } | 415 } |
| 411 | 416 |
| 412 void PasswordFormManager::OnRequestDone( | 417 void PasswordFormManager::OnRequestDone( |
| 413 ScopedVector<PasswordForm> logins_result) { | 418 ScopedVector<PasswordForm> logins_result) { |
| 414 const size_t logins_result_size = logins_result.size(); | 419 const size_t logins_result_size = logins_result.size(); |
| 415 | 420 |
| 416 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 421 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
| 417 if (client_->IsLoggingActive()) { | 422 if (client_->IsLoggingActive()) { |
| 418 logger.reset(new BrowserSavePasswordProgressLogger(client_)); | 423 logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
| 419 logger->LogMessage(Logger::STRING_ON_REQUEST_DONE_METHOD); | 424 logger->LogMessage(Logger::STRING_ON_REQUEST_DONE_METHOD); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 | 534 |
| 530 if (!driver || manager_action_ == kManagerActionBlacklisted) | 535 if (!driver || manager_action_ == kManagerActionBlacklisted) |
| 531 return; | 536 return; |
| 532 | 537 |
| 533 // Allow generation for any non-blacklisted form. | 538 // Allow generation for any non-blacklisted form. |
| 534 driver->AllowPasswordGenerationForForm(observed_form_); | 539 driver->AllowPasswordGenerationForForm(observed_form_); |
| 535 | 540 |
| 536 if (best_matches_.empty()) | 541 if (best_matches_.empty()) |
| 537 return; | 542 return; |
| 538 | 543 |
| 544 // Do not autofill on sign-up or change password forms (until we have some |
| 545 // working change password functionality). |
| 546 if (!observed_form_.new_password_element.empty()) { |
| 547 if (client_->IsLoggingActive()) { |
| 548 BrowserSavePasswordProgressLogger logger(client_); |
| 549 logger.LogMessage(Logger::PROCESS_FRAME_METHOD); |
| 550 logger.LogMessage(Logger::STRING_FORM_NOT_AUTOFILLED); |
| 551 } |
| 552 return; |
| 553 } |
| 554 |
| 539 // Proceed to autofill. | 555 // Proceed to autofill. |
| 540 // Note that we provide the choices but don't actually prefill a value if: | 556 // Note that we provide the choices but don't actually prefill a value if: |
| 541 // (1) we are in Incognito mode, (2) the ACTION paths don't match, | 557 // (1) we are in Incognito mode, (2) the ACTION paths don't match, |
| 542 // or (3) if it matched using public suffix domain matching. | 558 // or (3) if it matched using public suffix domain matching. |
| 543 bool wait_for_username = client_->IsOffTheRecord() || | 559 bool wait_for_username = client_->IsOffTheRecord() || |
| 544 observed_form_.action.GetWithEmptyPath() != | 560 observed_form_.action.GetWithEmptyPath() != |
| 545 preferred_match_->action.GetWithEmptyPath() || | 561 preferred_match_->action.GetWithEmptyPath() || |
| 546 preferred_match_->IsPublicSuffixMatch(); | 562 preferred_match_->IsPublicSuffixMatch(); |
| 547 if (wait_for_username) | 563 if (wait_for_username) |
| 548 manager_action_ = kManagerActionNone; | 564 manager_action_ = kManagerActionNone; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); | 889 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); |
| 874 } | 890 } |
| 875 | 891 |
| 876 void PasswordFormManager::SubmitFailed() { | 892 void PasswordFormManager::SubmitFailed() { |
| 877 submit_result_ = kSubmitResultFailed; | 893 submit_result_ = kSubmitResultFailed; |
| 878 if (has_generated_password_) | 894 if (has_generated_password_) |
| 879 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); | 895 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); |
| 880 } | 896 } |
| 881 | 897 |
| 882 } // namespace password_manager | 898 } // namespace password_manager |
| OLD | NEW |