Chromium Code Reviews| 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 "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 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 | 611 |
| 612 std::vector<PasswordForm*> MacKeychainPasswordFormAdapter::PasswordsFillingForm( | 612 std::vector<PasswordForm*> MacKeychainPasswordFormAdapter::PasswordsFillingForm( |
| 613 const std::string& signon_realm, | 613 const std::string& signon_realm, |
| 614 PasswordForm::Scheme scheme) { | 614 PasswordForm::Scheme scheme) { |
| 615 std::vector<SecKeychainItemRef> keychain_items = | 615 std::vector<SecKeychainItemRef> keychain_items = |
| 616 MatchingKeychainItems(signon_realm, scheme, NULL, NULL); | 616 MatchingKeychainItems(signon_realm, scheme, NULL, NULL); |
| 617 | 617 |
| 618 return ConvertKeychainItemsToForms(&keychain_items); | 618 return ConvertKeychainItemsToForms(&keychain_items); |
| 619 } | 619 } |
| 620 | 620 |
| 621 PasswordForm* MacKeychainPasswordFormAdapter::PasswordExactlyMatchingForm( | 621 scoped_ptr<PasswordForm> MacKeychainPasswordFormAdapter:: |
| 622 const PasswordForm& query_form) { | 622 PasswordExactlyMatchingForm(const PasswordForm& query_form) { |
| 623 SecKeychainItemRef keychain_item = KeychainItemForForm(query_form); | 623 SecKeychainItemRef keychain_item = KeychainItemForForm(query_form); |
| 624 if (keychain_item) { | 624 if (keychain_item) { |
| 625 PasswordForm* form = new PasswordForm(); | 625 scoped_ptr<PasswordForm> form(new PasswordForm); |
| 626 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, | 626 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, |
| 627 keychain_item, | 627 keychain_item, |
| 628 form, | 628 form.get(), |
| 629 true); | 629 true); |
| 630 keychain_->Free(keychain_item); | 630 keychain_->Free(keychain_item); |
| 631 return form; | 631 return form.Pass(); |
| 632 } | 632 } |
| 633 return NULL; | 633 return scoped_ptr<PasswordForm>(); |
| 634 } | 634 } |
| 635 | 635 |
| 636 bool MacKeychainPasswordFormAdapter::HasPasswordsMergeableWithForm( | 636 bool MacKeychainPasswordFormAdapter::HasPasswordsMergeableWithForm( |
| 637 const PasswordForm& query_form) { | 637 const PasswordForm& query_form) { |
| 638 std::string username = base::UTF16ToUTF8(query_form.username_value); | 638 std::string username = base::UTF16ToUTF8(query_form.username_value); |
| 639 std::vector<SecKeychainItemRef> matches = | 639 std::vector<SecKeychainItemRef> matches = |
| 640 MatchingKeychainItems(query_form.signon_realm, query_form.scheme, | 640 MatchingKeychainItems(query_form.signon_realm, query_form.scheme, |
| 641 NULL, username.c_str()); | 641 NULL, username.c_str()); |
| 642 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin(); | 642 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin(); |
| 643 i != matches.end(); ++i) { | 643 i != matches.end(); ++i) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 935 if (login_metadata_db_->RemoveLogin(form)) { | 935 if (login_metadata_db_->RemoveLogin(form)) { |
| 936 // See if we own a Keychain item associated with this item. We can do an | 936 // See if we own a Keychain item associated with this item. We can do an |
| 937 // exact search rather than messing around with trying to do fuzzy matching | 937 // exact search rather than messing around with trying to do fuzzy matching |
| 938 // because passwords that we created will always have an exact-match | 938 // because passwords that we created will always have an exact-match |
| 939 // database entry. | 939 // database entry. |
| 940 // (If a user does lose their profile but not their keychain we'll treat the | 940 // (If a user does lose their profile but not their keychain we'll treat the |
| 941 // entries we find like other imported entries anyway, so it's reasonable to | 941 // entries we find like other imported entries anyway, so it's reasonable to |
| 942 // handle deletes on them the way we would for an imported item.) | 942 // handle deletes on them the way we would for an imported item.) |
| 943 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); | 943 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); |
| 944 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 944 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 945 PasswordForm* owned_password_form = | 945 if (owned_keychain_adapter.PasswordExactlyMatchingForm(form)) { |
|
Ilya Sherman
2014/08/12 00:31:51
Hmm, could the method be changed to instead just r
vasilii
2014/08/12 09:17:37
The returned value is used in unit tests. With boo
Ilya Sherman
2014/08/12 17:21:25
Hmm, why do the tests need more information that t
vasilii
2014/08/13 09:56:46
Done.
| |
| 946 owned_keychain_adapter.PasswordExactlyMatchingForm(form); | |
| 947 if (owned_password_form) { | |
| 948 // If we don't have other forms using it (i.e., a form differing only by | 946 // If we don't have other forms using it (i.e., a form differing only by |
| 949 // the names of the form elements), delete the keychain entry. | 947 // the names of the form elements), delete the keychain entry. |
| 950 if (!DatabaseHasFormMatchingKeychainForm(form)) { | 948 if (!DatabaseHasFormMatchingKeychainForm(form)) { |
| 951 owned_keychain_adapter.RemovePassword(form); | 949 owned_keychain_adapter.RemovePassword(form); |
| 952 } | 950 } |
| 953 } | 951 } |
| 954 | 952 |
| 955 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 953 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 956 } | 954 } |
| 957 return changes; | 955 return changes; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 | 1151 |
| 1154 ScopedVector<PasswordForm> merged_forms; | 1152 ScopedVector<PasswordForm> merged_forms; |
| 1155 merged_forms.get() = internal_keychain_helpers::GetPasswordsForForms( | 1153 merged_forms.get() = internal_keychain_helpers::GetPasswordsForForms( |
| 1156 *keychain_, &database_forms); | 1154 *keychain_, &database_forms); |
| 1157 | 1155 |
| 1158 // Clean up any orphaned database entries. | 1156 // Clean up any orphaned database entries. |
| 1159 RemoveDatabaseForms(database_forms); | 1157 RemoveDatabaseForms(database_forms); |
| 1160 | 1158 |
| 1161 forms->insert(forms->end(), database_forms.begin(), database_forms.end()); | 1159 forms->insert(forms->end(), database_forms.begin(), database_forms.end()); |
| 1162 } | 1160 } |
| OLD | NEW |