Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/password_manager/password_store_mac.cc

Issue 2818035: Don't re-store deleted passwords on form submit on the Mac (Closed)
Patch Set: Address comments Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/password_manager/password_store_mac.h" 5 #include "chrome/browser/password_manager/password_store_mac.h"
6 #include "chrome/browser/password_manager/password_store_mac_internal.h" 6 #include "chrome/browser/password_manager/password_store_mac_internal.h"
7 7
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 PasswordForm* form = new PasswordForm(); 497 PasswordForm* form = new PasswordForm();
498 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, 498 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_,
499 keychain_item, 499 keychain_item,
500 form); 500 form);
501 keychain_->Free(keychain_item); 501 keychain_->Free(keychain_item);
502 return form; 502 return form;
503 } 503 }
504 return NULL; 504 return NULL;
505 } 505 }
506 506
507 bool MacKeychainPasswordFormAdapter::HasPasswordsMergeableWithForm(
508 const PasswordForm& query_form) {
509 std::string username = UTF16ToUTF8(query_form.username_value);
510 std::vector<SecKeychainItemRef> matches =
511 MatchingKeychainItems(query_form.signon_realm, query_form.scheme,
512 NULL, username.c_str());
513 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin();
514 i != matches.end(); ++i) {
515 keychain_->Free(*i);
516 }
517
518 return matches.size() != 0;
519 }
520
507 std::vector<PasswordForm*> 521 std::vector<PasswordForm*>
508 MacKeychainPasswordFormAdapter::GetAllPasswordFormPasswords() { 522 MacKeychainPasswordFormAdapter::GetAllPasswordFormPasswords() {
509 SecAuthenticationType supported_auth_types[] = { 523 SecAuthenticationType supported_auth_types[] = {
510 kSecAuthenticationTypeHTMLForm, 524 kSecAuthenticationTypeHTMLForm,
511 kSecAuthenticationTypeHTTPBasic, 525 kSecAuthenticationTypeHTTPBasic,
512 kSecAuthenticationTypeHTTPDigest, 526 kSecAuthenticationTypeHTTPDigest,
513 }; 527 };
514 528
515 std::vector<SecKeychainItemRef> matches; 529 std::vector<SecKeychainItemRef> matches;
516 for (unsigned int i = 0; i < arraysize(supported_auth_types); ++i) { 530 for (unsigned int i = 0; i < arraysize(supported_auth_types); ++i) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); 769 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form));
756 NotificationService::current()->Notify( 770 NotificationService::current()->Notify(
757 NotificationType::LOGINS_CHANGED, 771 NotificationType::LOGINS_CHANGED,
758 NotificationService::AllSources(), 772 NotificationService::AllSources(),
759 Details<PasswordStoreChangeList>(&changes)); 773 Details<PasswordStoreChangeList>(&changes));
760 } 774 }
761 } 775 }
762 } 776 }
763 777
764 void PasswordStoreMac::UpdateLoginImpl(const PasswordForm& form) { 778 void PasswordStoreMac::UpdateLoginImpl(const PasswordForm& form) {
779 int update_count = 0;
780 if (!login_metadata_db_->UpdateLogin(form, &update_count))
781 return;
782
783 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get());
784 if (update_count == 0 &&
785 !keychain_adapter.HasPasswordsMergeableWithForm(form)) {
786 // If the password isn't in either the DB or the keychain, then it must have
787 // been deleted after autofill happened, and should not be re-added.
788 return;
789 }
790
765 // The keychain add will update if there is a collision and add if there 791 // The keychain add will update if there is a collision and add if there
766 // isn't, which is the behavior we want, so there's no separate update call. 792 // isn't, which is the behavior we want, so there's no separate update call.
767 if (AddToKeychainIfNecessary(form)) { 793 if (AddToKeychainIfNecessary(form)) {
768 int update_count = 0; 794 PasswordStoreChangeList changes;
769 if (login_metadata_db_->UpdateLogin(form, &update_count)) { 795 if (update_count == 0) {
770 // Update will catch any database entries that we already had, but we 796 if (login_metadata_db_->AddLogin(form)) {
771 // could also be updating a keychain-only form, in which case we need to 797 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD,
772 // add.
773 PasswordStoreChangeList changes;
774 if (update_count == 0) {
775 if (login_metadata_db_->AddLogin(form)) {
776 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD,
777 form));
778 }
779 } else {
780 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE,
781 form)); 798 form));
782 } 799 }
783 if (!changes.empty()) { 800 } else {
784 NotificationService::current()->Notify( 801 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE,
785 NotificationType::LOGINS_CHANGED, 802 form));
786 NotificationService::AllSources(), 803 }
787 Details<PasswordStoreChangeList>(&changes)); 804 if (!changes.empty()) {
788 } 805 NotificationService::current()->Notify(
806 NotificationType::LOGINS_CHANGED,
807 NotificationService::AllSources(),
808 Details<PasswordStoreChangeList>(&changes));
789 } 809 }
790 } 810 }
791 } 811 }
792 812
793 void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) { 813 void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) {
794 if (login_metadata_db_->RemoveLogin(form)) { 814 if (login_metadata_db_->RemoveLogin(form)) {
795 // See if we own a Keychain item associated with this item. We can do an 815 // See if we own a Keychain item associated with this item. We can do an
796 // exact search rather than messing around with trying to do fuzzy matching 816 // exact search rather than messing around with trying to do fuzzy matching
797 // because passwords that we created will always have an exact-match 817 // because passwords that we created will always have an exact-match
798 // database entry. 818 // database entry.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); 1002 owned_keychain_adapter.SetFindsOnlyOwnedItems(true);
983 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); 1003 for (std::vector<PasswordForm*>::const_iterator i = forms.begin();
984 i != forms.end(); ++i) { 1004 i != forms.end(); ++i) {
985 owned_keychain_adapter.RemovePassword(**i); 1005 owned_keychain_adapter.RemovePassword(**i);
986 } 1006 }
987 } 1007 }
988 1008
989 void PasswordStoreMac::CreateNotificationService() { 1009 void PasswordStoreMac::CreateNotificationService() {
990 notification_service_.reset(new NotificationService); 1010 notification_service_.reset(new NotificationService);
991 } 1011 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store.h ('k') | chrome/browser/password_manager/password_store_mac_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698