| 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_manager.h" | 5 #include "components/password_manager/core/browser/password_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (form_manager) { | 231 if (form_manager) { |
| 232 form_manager->set_generation_element(generation_element); | 232 form_manager->set_generation_element(generation_element); |
| 233 form_manager->set_is_manual_generation(is_manually_triggered); | 233 form_manager->set_is_manual_generation(is_manually_triggered); |
| 234 form_manager->set_generation_popup_was_shown(true); | 234 form_manager->set_generation_popup_was_shown(true); |
| 235 return; | 235 return; |
| 236 } | 236 } |
| 237 | 237 |
| 238 // If there is no corresponding PasswordFormManager, we create one. This is | 238 // If there is no corresponding PasswordFormManager, we create one. This is |
| 239 // not the common case, and should only happen when there is a bug in our | 239 // not the common case, and should only happen when there is a bug in our |
| 240 // ability to detect forms. | 240 // ability to detect forms. |
| 241 auto manager = base::MakeRefCounted<PasswordFormManager>( | 241 auto manager = base::MakeUnique<PasswordFormManager>( |
| 242 this, client_, driver->AsWeakPtr(), form, | 242 this, client_, driver->AsWeakPtr(), form, |
| 243 base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())), | 243 base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())), |
| 244 nullptr); | 244 nullptr); |
| 245 pending_login_managers_.push_back(std::move(manager)); | 245 pending_login_managers_.push_back(std::move(manager)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void PasswordManager::SaveGenerationFieldDetectedByClassifier( | 248 void PasswordManager::SaveGenerationFieldDetectedByClassifier( |
| 249 const autofill::PasswordForm& form, | 249 const autofill::PasswordForm& form, |
| 250 const base::string16& generation_field) { | 250 const base::string16& generation_field) { |
| 251 if (!client_->IsSavingAndFillingEnabledForCurrentPage()) | 251 if (!client_->IsSavingAndFillingEnabledForCurrentPage()) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 // If we didn't find a manager, this means a form was submitted without | 344 // If we didn't find a manager, this means a form was submitted without |
| 345 // first loading the page containing the form. Don't offer to save | 345 // first loading the page containing the form. Don't offer to save |
| 346 // passwords in this case. | 346 // passwords in this case. |
| 347 if (matched_manager_it == pending_login_managers_.end()) { | 347 if (matched_manager_it == pending_login_managers_.end()) { |
| 348 RecordFailure(NO_MATCHING_FORM, form.origin, logger.get()); | 348 RecordFailure(NO_MATCHING_FORM, form.origin, logger.get()); |
| 349 return; | 349 return; |
| 350 } | 350 } |
| 351 | 351 |
| 352 // Copy ownership of the manager from |pending_login_managers_| to | 352 std::unique_ptr<PasswordFormManager> manager; |
| 353 // Transfer ownership of the manager from |pending_login_managers_| to |
| 353 // |manager|. | 354 // |manager|. |
| 354 scoped_refptr<PasswordFormManager> manager(*matched_manager_it); | 355 manager.swap(*matched_manager_it); |
| 356 pending_login_managers_.erase(matched_manager_it); |
| 355 | 357 |
| 356 PasswordForm submitted_form(form); | 358 PasswordForm submitted_form(form); |
| 357 submitted_form.preferred = true; | 359 submitted_form.preferred = true; |
| 358 if (logger) { | 360 if (logger) { |
| 359 logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVED_FORM, | 361 logger->LogPasswordForm(Logger::STRING_PROVISIONALLY_SAVED_FORM, |
| 360 submitted_form); | 362 submitted_form); |
| 361 } | 363 } |
| 362 PasswordFormManager::OtherPossibleUsernamesAction action = | 364 PasswordFormManager::OtherPossibleUsernamesAction action = |
| 363 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; | 365 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; |
| 364 if (OtherPossibleUsernamesEnabled()) | 366 if (OtherPossibleUsernamesEnabled()) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 403 } |
| 402 | 404 |
| 403 void PasswordManager::UpdateFormManagers() { | 405 void PasswordManager::UpdateFormManagers() { |
| 404 for (const auto& form_manager : pending_login_managers_) { | 406 for (const auto& form_manager : pending_login_managers_) { |
| 405 form_manager->form_fetcher()->Fetch(); | 407 form_manager->form_fetcher()->Fetch(); |
| 406 } | 408 } |
| 407 } | 409 } |
| 408 | 410 |
| 409 void PasswordManager::DropFormManagers() { | 411 void PasswordManager::DropFormManagers() { |
| 410 pending_login_managers_.clear(); | 412 pending_login_managers_.clear(); |
| 411 provisional_save_manager_ = nullptr; | 413 provisional_save_manager_.reset(); |
| 412 all_visible_forms_.clear(); | 414 all_visible_forms_.clear(); |
| 413 } | 415 } |
| 414 | 416 |
| 415 bool PasswordManager::IsPasswordFieldDetectedOnPage() { | 417 bool PasswordManager::IsPasswordFieldDetectedOnPage() { |
| 416 return !pending_login_managers_.empty(); | 418 return !pending_login_managers_.empty(); |
| 417 } | 419 } |
| 418 | 420 |
| 419 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure, | 421 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure, |
| 420 const GURL& form_origin, | 422 const GURL& form_origin, |
| 421 BrowserSavePasswordProgressLogger* logger) { | 423 BrowserSavePasswordProgressLogger* logger) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // are password change forms. | 560 // are password change forms. |
| 559 if (iter->username_element.empty()) { | 561 if (iter->username_element.empty()) { |
| 560 UMA_HISTOGRAM_BOOLEAN( | 562 UMA_HISTOGRAM_BOOLEAN( |
| 561 "PasswordManager.EmptyUsernames." | 563 "PasswordManager.EmptyUsernames." |
| 562 "FormWithoutUsernameFieldIsPasswordChangeForm", | 564 "FormWithoutUsernameFieldIsPasswordChangeForm", |
| 563 !iter->new_password_element.empty()); | 565 !iter->new_password_element.empty()); |
| 564 } | 566 } |
| 565 | 567 |
| 566 if (logger) | 568 if (logger) |
| 567 logger->LogFormSignatures(Logger::STRING_ADDING_SIGNATURE, *iter); | 569 logger->LogFormSignatures(Logger::STRING_ADDING_SIGNATURE, *iter); |
| 568 auto manager = base::MakeRefCounted<PasswordFormManager>( | 570 auto manager = base::MakeUnique<PasswordFormManager>( |
| 569 this, client_, | 571 this, client_, |
| 570 (driver ? driver->AsWeakPtr() : base::WeakPtr<PasswordManagerDriver>()), | 572 (driver ? driver->AsWeakPtr() : base::WeakPtr<PasswordManagerDriver>()), |
| 571 *iter, base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())), | 573 *iter, base::WrapUnique(new FormSaverImpl(client_->GetPasswordStore())), |
| 572 nullptr); | 574 nullptr); |
| 573 pending_login_managers_.push_back(std::move(manager)); | 575 pending_login_managers_.push_back(std::move(manager)); |
| 574 } | 576 } |
| 575 | 577 |
| 576 if (logger) { | 578 if (logger) { |
| 577 logger->LogNumber(Logger::STRING_NEW_NUMBER_LOGIN_MANAGERS, | 579 logger->LogNumber(Logger::STRING_NEW_NUMBER_LOGIN_MANAGERS, |
| 578 pending_login_managers_.size()); | 580 pending_login_managers_.size()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 594 return false; | 596 return false; |
| 595 } | 597 } |
| 596 | 598 |
| 597 if (provisional_save_manager_->form_fetcher()->GetState() == | 599 if (provisional_save_manager_->form_fetcher()->GetState() == |
| 598 FormFetcher::State::WAITING) { | 600 FormFetcher::State::WAITING) { |
| 599 // We have a provisional save manager, but it didn't finish matching yet. | 601 // We have a provisional save manager, but it didn't finish matching yet. |
| 600 // We just give up. | 602 // We just give up. |
| 601 RecordFailure(MATCHING_NOT_COMPLETE, | 603 RecordFailure(MATCHING_NOT_COMPLETE, |
| 602 provisional_save_manager_->observed_form().origin, | 604 provisional_save_manager_->observed_form().origin, |
| 603 logger.get()); | 605 logger.get()); |
| 604 provisional_save_manager_ = nullptr; | 606 provisional_save_manager_.reset(); |
| 605 return false; | 607 return false; |
| 606 } | 608 } |
| 607 return true; | 609 return true; |
| 608 } | 610 } |
| 609 | 611 |
| 610 bool PasswordManager::ShouldBlockPasswordForSameOriginButDifferentScheme( | 612 bool PasswordManager::ShouldBlockPasswordForSameOriginButDifferentScheme( |
| 611 const PasswordForm& form) const { | 613 const PasswordForm& form) const { |
| 612 const GURL& old_origin = main_frame_url_.GetOrigin(); | 614 const GURL& old_origin = main_frame_url_.GetOrigin(); |
| 613 const GURL& new_origin = form.origin.GetOrigin(); | 615 const GURL& new_origin = form.origin.GetOrigin(); |
| 614 return old_origin.host_piece() == new_origin.host_piece() && | 616 return old_origin.host_piece() == new_origin.host_piece() && |
| (...skipping 26 matching lines...) Expand all Loading... |
| 641 | 643 |
| 642 if (!CanProvisionalManagerSave()) | 644 if (!CanProvisionalManagerSave()) |
| 643 return; | 645 return; |
| 644 | 646 |
| 645 // If the server throws an internal error, access denied page, page not | 647 // If the server throws an internal error, access denied page, page not |
| 646 // found etc. after a login attempt, we do not save the credentials. | 648 // found etc. after a login attempt, we do not save the credentials. |
| 647 if (client_->WasLastNavigationHTTPError()) { | 649 if (client_->WasLastNavigationHTTPError()) { |
| 648 if (logger) | 650 if (logger) |
| 649 logger->LogMessage(Logger::STRING_DECISION_DROP); | 651 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 650 provisional_save_manager_->LogSubmitFailed(); | 652 provisional_save_manager_->LogSubmitFailed(); |
| 651 provisional_save_manager_ = nullptr; | 653 provisional_save_manager_.reset(); |
| 652 return; | 654 return; |
| 653 } | 655 } |
| 654 | 656 |
| 655 if (logger) { | 657 if (logger) { |
| 656 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS, | 658 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS, |
| 657 visible_forms.size()); | 659 visible_forms.size()); |
| 658 } | 660 } |
| 659 | 661 |
| 660 // Record all visible forms from the frame. | 662 // Record all visible forms from the frame. |
| 661 all_visible_forms_.insert(all_visible_forms_.end(), | 663 all_visible_forms_.insert(all_visible_forms_.end(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 678 if (provisional_save_manager_ | 680 if (provisional_save_manager_ |
| 679 ->is_possible_change_password_form_without_username() && | 681 ->is_possible_change_password_form_without_username() && |
| 680 AreAllFieldsEmpty(all_visible_forms_[i])) | 682 AreAllFieldsEmpty(all_visible_forms_[i])) |
| 681 continue; | 683 continue; |
| 682 provisional_save_manager_->LogSubmitFailed(); | 684 provisional_save_manager_->LogSubmitFailed(); |
| 683 if (logger) { | 685 if (logger) { |
| 684 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, | 686 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, |
| 685 all_visible_forms_[i]); | 687 all_visible_forms_[i]); |
| 686 logger->LogMessage(Logger::STRING_DECISION_DROP); | 688 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 687 } | 689 } |
| 688 provisional_save_manager_ = nullptr; | 690 provisional_save_manager_.reset(); |
| 689 // Clear all_visible_forms_ once we found the match. | 691 // Clear all_visible_forms_ once we found the match. |
| 690 all_visible_forms_.clear(); | 692 all_visible_forms_.clear(); |
| 691 return; | 693 return; |
| 692 } | 694 } |
| 693 } | 695 } |
| 694 } else { | 696 } else { |
| 695 if (logger) | 697 if (logger) |
| 696 logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVED_FORM_IS_NOT_HTML); | 698 logger->LogMessage(Logger::STRING_PROVISIONALLY_SAVED_FORM_IS_NOT_HTML); |
| 697 } | 699 } |
| 698 | 700 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 747 } |
| 746 | 748 |
| 747 if (base::FeatureList::IsEnabled(features::kDropSyncCredential)) { | 749 if (base::FeatureList::IsEnabled(features::kDropSyncCredential)) { |
| 748 DCHECK(provisional_save_manager_->submitted_form()); | 750 DCHECK(provisional_save_manager_->submitted_form()); |
| 749 if (!client_->GetStoreResultFilter()->ShouldSave( | 751 if (!client_->GetStoreResultFilter()->ShouldSave( |
| 750 *provisional_save_manager_->submitted_form())) { | 752 *provisional_save_manager_->submitted_form())) { |
| 751 provisional_save_manager_->WipeStoreCopyIfOutdated(); | 753 provisional_save_manager_->WipeStoreCopyIfOutdated(); |
| 752 RecordFailure(SYNC_CREDENTIAL, | 754 RecordFailure(SYNC_CREDENTIAL, |
| 753 provisional_save_manager_->observed_form().origin, | 755 provisional_save_manager_->observed_form().origin, |
| 754 logger.get()); | 756 logger.get()); |
| 755 provisional_save_manager_ = nullptr; | 757 provisional_save_manager_.reset(); |
| 756 return; | 758 return; |
| 757 } | 759 } |
| 758 } | 760 } |
| 759 | 761 |
| 760 provisional_save_manager_->LogSubmitPassed(); | 762 provisional_save_manager_->LogSubmitPassed(); |
| 761 | 763 |
| 762 RecordWhetherTargetDomainDiffers(main_frame_url_, client_->GetMainFrameURL()); | 764 RecordWhetherTargetDomainDiffers(main_frame_url_, client_->GetMainFrameURL()); |
| 763 | 765 |
| 764 if (ShouldPromptUserToSavePassword()) { | 766 if (ShouldPromptUserToSavePassword()) { |
| 765 bool empty_password = | 767 bool empty_password = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 785 provisional_save_manager_->Save(); | 787 provisional_save_manager_->Save(); |
| 786 | 788 |
| 787 if (!provisional_save_manager_->IsNewLogin()) { | 789 if (!provisional_save_manager_->IsNewLogin()) { |
| 788 client_->NotifySuccessfulLoginWithExistingPassword( | 790 client_->NotifySuccessfulLoginWithExistingPassword( |
| 789 provisional_save_manager_->pending_credentials()); | 791 provisional_save_manager_->pending_credentials()); |
| 790 } | 792 } |
| 791 | 793 |
| 792 if (provisional_save_manager_->has_generated_password()) { | 794 if (provisional_save_manager_->has_generated_password()) { |
| 793 client_->AutomaticPasswordSave(std::move(provisional_save_manager_)); | 795 client_->AutomaticPasswordSave(std::move(provisional_save_manager_)); |
| 794 } else { | 796 } else { |
| 795 provisional_save_manager_ = nullptr; | 797 provisional_save_manager_.reset(); |
| 796 } | 798 } |
| 797 } | 799 } |
| 798 } | 800 } |
| 799 | 801 |
| 800 bool PasswordManager::OtherPossibleUsernamesEnabled() const { | 802 bool PasswordManager::OtherPossibleUsernamesEnabled() const { |
| 801 return false; | 803 return false; |
| 802 } | 804 } |
| 803 | 805 |
| 804 void PasswordManager::Autofill( | 806 void PasswordManager::Autofill( |
| 805 password_manager::PasswordManagerDriver* driver, | 807 password_manager::PasswordManagerDriver* driver, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 current_match_result = result; | 945 current_match_result = result; |
| 944 } else if (result > current_match_result) { | 946 } else if (result > current_match_result) { |
| 945 matched_manager = login_manager.get(); | 947 matched_manager = login_manager.get(); |
| 946 current_match_result = result; | 948 current_match_result = result; |
| 947 } | 949 } |
| 948 } | 950 } |
| 949 return matched_manager; | 951 return matched_manager; |
| 950 } | 952 } |
| 951 | 953 |
| 952 } // namespace password_manager | 954 } // namespace password_manager |
| OLD | NEW |