| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/mac/mac_logging.h" | 15 #include "base/mac/mac_logging.h" |
| 16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "chrome/browser/password_manager/login_database.h" | 21 #include "chrome/browser/password_manager/login_database.h" |
| 22 #include "chrome/browser/password_manager/password_store_change.h" | 22 #include "chrome/browser/password_manager/password_store_change.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "crypto/apple_keychain.h" | 25 #include "crypto/apple_keychain.h" |
| 26 | 26 |
| 27 using crypto::AppleKeychain; | 27 using crypto::AppleKeychain; |
| 28 using webkit::forms::PasswordForm; | 28 using content::PasswordForm; |
| 29 | 29 |
| 30 // Utility class to handle the details of constructing and running a keychain | 30 // Utility class to handle the details of constructing and running a keychain |
| 31 // search from a set of attributes. | 31 // search from a set of attributes. |
| 32 class KeychainSearch { | 32 class KeychainSearch { |
| 33 public: | 33 public: |
| 34 explicit KeychainSearch(const AppleKeychain& keychain); | 34 explicit KeychainSearch(const AppleKeychain& keychain); |
| 35 ~KeychainSearch(); | 35 ~KeychainSearch(); |
| 36 | 36 |
| 37 // Sets up a keycahin search based on an non "null" (NULL for char*, | 37 // Sets up a keycahin search based on an non "null" (NULL for char*, |
| 38 // The appropriate "Any" entry for other types) arguments. | 38 // The appropriate "Any" entry for other types) arguments. |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin() + 1; | 637 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin() + 1; |
| 638 i != matches.end(); ++i) { | 638 i != matches.end(); ++i) { |
| 639 keychain_->Free(*i); | 639 keychain_->Free(*i); |
| 640 } | 640 } |
| 641 return matches[0]; | 641 return matches[0]; |
| 642 } | 642 } |
| 643 | 643 |
| 644 std::vector<SecKeychainItemRef> | 644 std::vector<SecKeychainItemRef> |
| 645 MacKeychainPasswordFormAdapter::MatchingKeychainItems( | 645 MacKeychainPasswordFormAdapter::MatchingKeychainItems( |
| 646 const std::string& signon_realm, | 646 const std::string& signon_realm, |
| 647 webkit::forms::PasswordForm::Scheme scheme, | 647 content::PasswordForm::Scheme scheme, |
| 648 const char* path, const char* username) { | 648 const char* path, const char* username) { |
| 649 std::vector<SecKeychainItemRef> matches; | 649 std::vector<SecKeychainItemRef> matches; |
| 650 | 650 |
| 651 std::string server; | 651 std::string server; |
| 652 std::string security_domain; | 652 std::string security_domain; |
| 653 int port; | 653 int port; |
| 654 bool is_secure; | 654 bool is_secure; |
| 655 if (!ExtractSignonRealmComponents(signon_realm, &server, &port, | 655 if (!ExtractSignonRealmComponents(signon_realm, &server, &port, |
| 656 &is_secure, &security_domain)) { | 656 &is_secure, &security_domain)) { |
| 657 // TODO(stuartmorgan): Proxies will currently fail here, since their | 657 // TODO(stuartmorgan): Proxies will currently fail here, since their |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 } | 882 } |
| 883 content::NotificationService::current()->Notify( | 883 content::NotificationService::current()->Notify( |
| 884 chrome::NOTIFICATION_LOGINS_CHANGED, | 884 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 885 content::Source<PasswordStore>(this), | 885 content::Source<PasswordStore>(this), |
| 886 content::Details<PasswordStoreChangeList>(&changes)); | 886 content::Details<PasswordStoreChangeList>(&changes)); |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 } | 889 } |
| 890 | 890 |
| 891 void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request, | 891 void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request, |
| 892 const webkit::forms::PasswordForm& form) { | 892 const content::PasswordForm& form) { |
| 893 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); | 893 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); |
| 894 std::vector<PasswordForm*> keychain_forms = | 894 std::vector<PasswordForm*> keychain_forms = |
| 895 keychain_adapter.PasswordsFillingForm(form); | 895 keychain_adapter.PasswordsFillingForm(form); |
| 896 | 896 |
| 897 std::vector<PasswordForm*> database_forms; | 897 std::vector<PasswordForm*> database_forms; |
| 898 login_metadata_db_->GetLogins(form, &database_forms); | 898 login_metadata_db_->GetLogins(form, &database_forms); |
| 899 | 899 |
| 900 std::vector<PasswordForm*>& merged_forms = request->value; | 900 std::vector<PasswordForm*>& merged_forms = request->value; |
| 901 internal_keychain_helpers::MergePasswordForms(&keychain_forms, | 901 internal_keychain_helpers::MergePasswordForms(&keychain_forms, |
| 902 &database_forms, | 902 &database_forms, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 | 955 |
| 956 bool PasswordStoreMac::AddToKeychainIfNecessary(const PasswordForm& form) { | 956 bool PasswordStoreMac::AddToKeychainIfNecessary(const PasswordForm& form) { |
| 957 if (form.blacklisted_by_user) { | 957 if (form.blacklisted_by_user) { |
| 958 return true; | 958 return true; |
| 959 } | 959 } |
| 960 MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get()); | 960 MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get()); |
| 961 return keychainAdapter.AddPassword(form); | 961 return keychainAdapter.AddPassword(form); |
| 962 } | 962 } |
| 963 | 963 |
| 964 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( | 964 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( |
| 965 const webkit::forms::PasswordForm& form) { | 965 const content::PasswordForm& form) { |
| 966 bool has_match = false; | 966 bool has_match = false; |
| 967 std::vector<PasswordForm*> database_forms; | 967 std::vector<PasswordForm*> database_forms; |
| 968 login_metadata_db_->GetLogins(form, &database_forms); | 968 login_metadata_db_->GetLogins(form, &database_forms); |
| 969 for (std::vector<PasswordForm*>::iterator i = database_forms.begin(); | 969 for (std::vector<PasswordForm*>::iterator i = database_forms.begin(); |
| 970 i != database_forms.end(); ++i) { | 970 i != database_forms.end(); ++i) { |
| 971 if (internal_keychain_helpers::FormsMatchForMerge(form, **i) && | 971 if (internal_keychain_helpers::FormsMatchForMerge(form, **i) && |
| 972 (*i)->origin == form.origin) { | 972 (*i)->origin == form.origin) { |
| 973 has_match = true; | 973 has_match = true; |
| 974 break; | 974 break; |
| 975 } | 975 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1013 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1014 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); | 1014 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); |
| 1015 i != forms.end(); ++i) { | 1015 i != forms.end(); ++i) { |
| 1016 owned_keychain_adapter.RemovePassword(**i); | 1016 owned_keychain_adapter.RemovePassword(**i); |
| 1017 } | 1017 } |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 void PasswordStoreMac::CreateNotificationService() { | 1020 void PasswordStoreMac::CreateNotificationService() { |
| 1021 notification_service_.reset(content::NotificationService::Create()); | 1021 notification_service_.reset(content::NotificationService::Create()); |
| 1022 } | 1022 } |
| OLD | NEW |