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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 PasswordStore::AuthorizationPromptPolicy prompt_policy) { | 369 PasswordStore::AuthorizationPromptPolicy prompt_policy) { |
370 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | 370 DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
371 state_ = MATCHING_PHASE; | 371 state_ = MATCHING_PHASE; |
372 | 372 |
373 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 373 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
374 if (client_->IsLoggingActive()) { | 374 if (client_->IsLoggingActive()) { |
375 logger.reset(new BrowserSavePasswordProgressLogger(client_)); | 375 logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
376 logger->LogMessage(Logger::STRING_FETCH_LOGINS_METHOD); | 376 logger->LogMessage(Logger::STRING_FETCH_LOGINS_METHOD); |
377 } | 377 } |
378 | 378 |
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 std::vector<autofill::PasswordForm*> dummy_results; | |
388 OnGetPasswordStoreResults(dummy_results); | |
389 return; | |
390 } | |
391 | |
392 PasswordStore* password_store = client_->GetPasswordStore(); | 379 PasswordStore* password_store = client_->GetPasswordStore(); |
393 if (!password_store) { | 380 if (!password_store) { |
394 if (logger) | 381 if (logger) |
395 logger->LogMessage(Logger::STRING_NO_STORE); | 382 logger->LogMessage(Logger::STRING_NO_STORE); |
396 NOTREACHED(); | 383 NOTREACHED(); |
397 return; | 384 return; |
398 } | 385 } |
399 password_store->GetLogins(observed_form_, prompt_policy, this); | 386 password_store->GetLogins(observed_form_, prompt_policy, this); |
400 } | 387 } |
401 | 388 |
402 bool PasswordFormManager::HasCompletedMatching() const { | 389 bool PasswordFormManager::HasCompletedMatching() const { |
403 return state_ == POST_MATCHING_PHASE; | 390 return state_ == POST_MATCHING_PHASE; |
404 } | 391 } |
405 | 392 |
406 bool PasswordFormManager::IsIgnorableChangePasswordForm() const { | 393 bool PasswordFormManager::IsIgnorableChangePasswordForm( |
407 bool is_change_password_form = !observed_form_.new_password_element.empty() && | 394 const autofill::PasswordForm& candidate) const { |
408 !observed_form_.password_element.empty(); | 395 bool is_change_password_form = !candidate.new_password_element.empty() && |
409 bool is_username_certainly_correct = observed_form_.username_marked_by_site; | 396 !candidate.password_element.empty(); |
410 return is_change_password_form && !is_username_certainly_correct; | 397 return is_change_password_form && !candidate.username_marked_by_site && |
398 !HasMatchingCredentialsInStore(candidate); | |
411 } | 399 } |
412 | 400 |
413 void PasswordFormManager::OnRequestDone( | 401 void PasswordFormManager::OnRequestDone( |
414 const std::vector<PasswordForm*>& logins_result) { | 402 const std::vector<PasswordForm*>& logins_result) { |
415 // Note that the result gets deleted after this call completes, but we own | 403 // Note that the result gets deleted after this call completes, but we own |
416 // the PasswordForm objects pointed to by the result vector, thus we keep | 404 // the PasswordForm objects pointed to by the result vector, thus we keep |
417 // copies to a minimum here. | 405 // copies to a minimum here. |
418 | 406 |
419 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 407 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
420 if (client_->IsLoggingActive()) { | 408 if (client_->IsLoggingActive()) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 // (1) we are in Incognito mode, (2) the ACTION paths don't match, | 532 // (1) we are in Incognito mode, (2) the ACTION paths don't match, |
545 // or (3) if it matched using public suffix domain matching. | 533 // or (3) if it matched using public suffix domain matching. |
546 bool wait_for_username = client_->IsOffTheRecord() || | 534 bool wait_for_username = client_->IsOffTheRecord() || |
547 observed_form_.action.GetWithEmptyPath() != | 535 observed_form_.action.GetWithEmptyPath() != |
548 preferred_match_->action.GetWithEmptyPath() || | 536 preferred_match_->action.GetWithEmptyPath() || |
549 preferred_match_->IsPublicSuffixMatch(); | 537 preferred_match_->IsPublicSuffixMatch(); |
550 if (wait_for_username) | 538 if (wait_for_username) |
551 manager_action_ = kManagerActionNone; | 539 manager_action_ = kManagerActionNone; |
552 else | 540 else |
553 manager_action_ = kManagerActionAutofilled; | 541 manager_action_ = kManagerActionAutofilled; |
542 | |
543 // Do not autofill on sign-up or change password forms (until we have some | |
vabr (Chromium)
2015/02/10 18:54:56
Could you move the whole added block above line 53
Pritam Nikam
2015/02/19 11:18:47
Done.
| |
544 // working change password functionality). | |
545 if (!observed_form_.new_password_element.empty()) { | |
546 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | |
vabr (Chromium)
2015/02/10 18:54:56
You only need the |logger| in the if-block below,
Pritam Nikam
2015/02/19 11:18:47
Done.
| |
547 if (client_->IsLoggingActive()) { | |
548 logger.reset(new BrowserSavePasswordProgressLogger(client_)); | |
549 logger->LogMessage(Logger::STRING_FORM_NOT_AUTOFILLED); | |
550 } | |
551 client_->AutofillResultsComputed(); | |
vabr (Chromium)
2015/02/10 18:54:57
Remove this line. AutofillResultsComputed has alre
Pritam Nikam
2015/02/19 11:18:47
Done.
| |
552 return; | |
553 } | |
554 | |
554 password_manager_->Autofill(driver.get(), observed_form_, best_matches_, | 555 password_manager_->Autofill(driver.get(), observed_form_, best_matches_, |
555 *preferred_match_, wait_for_username); | 556 *preferred_match_, wait_for_username); |
556 } | 557 } |
557 | 558 |
558 void PasswordFormManager::OnGetPasswordStoreResults( | 559 void PasswordFormManager::OnGetPasswordStoreResults( |
559 const std::vector<autofill::PasswordForm*>& results) { | 560 const std::vector<autofill::PasswordForm*>& results) { |
560 DCHECK_EQ(state_, MATCHING_PHASE); | 561 DCHECK_EQ(state_, MATCHING_PHASE); |
561 | 562 |
562 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 563 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
563 if (client_->IsLoggingActive()) { | 564 if (client_->IsLoggingActive()) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 if (has_generated_password_) | 862 if (has_generated_password_) |
862 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); | 863 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); |
863 } | 864 } |
864 | 865 |
865 void PasswordFormManager::SubmitFailed() { | 866 void PasswordFormManager::SubmitFailed() { |
866 submit_result_ = kSubmitResultFailed; | 867 submit_result_ = kSubmitResultFailed; |
867 if (has_generated_password_) | 868 if (has_generated_password_) |
868 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); | 869 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); |
869 } | 870 } |
870 | 871 |
872 bool PasswordFormManager::HasMatchingCredentialsInStore( | |
873 const autofill::PasswordForm& candidate) const { | |
874 for (auto match : best_matches_) { | |
875 if (match.second->username_value == candidate.username_value && | |
876 match.second->password_value == candidate.password_value) | |
877 return true; | |
878 } | |
879 return false; | |
880 } | |
881 | |
871 } // namespace password_manager | 882 } // namespace password_manager |
OLD | NEW |