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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1055 } | 1055 } |
1056 return changes; | 1056 return changes; |
1057 } | 1057 } |
1058 | 1058 |
1059 ScopedVector<autofill::PasswordForm> PasswordStoreMac::FillMatchingLogins( | 1059 ScopedVector<autofill::PasswordForm> PasswordStoreMac::FillMatchingLogins( |
1060 const autofill::PasswordForm& form, | 1060 const autofill::PasswordForm& form, |
1061 AuthorizationPromptPolicy prompt_policy) { | 1061 AuthorizationPromptPolicy prompt_policy) { |
1062 chrome::ScopedSecKeychainSetUserInteractionAllowed user_interaction_allowed( | 1062 chrome::ScopedSecKeychainSetUserInteractionAllowed user_interaction_allowed( |
1063 prompt_policy == ALLOW_PROMPT); | 1063 prompt_policy == ALLOW_PROMPT); |
1064 | 1064 |
1065 if (!login_metadata_db_) | 1065 ScopedVector<PasswordForm> database_forms; |
1066 if (!login_metadata_db_ || | |
1067 !login_metadata_db_->GetLogins(form, &database_forms)) { | |
1066 return ScopedVector<autofill::PasswordForm>(); | 1068 return ScopedVector<autofill::PasswordForm>(); |
1067 | 1069 } |
1068 ScopedVector<PasswordForm> database_forms; | |
1069 login_metadata_db_->GetLogins(form, &database_forms); | |
1070 | 1070 |
1071 // Let's gather all signon realms we want to match with keychain entries. | 1071 // Let's gather all signon realms we want to match with keychain entries. |
1072 std::set<std::string> realm_set; | 1072 std::set<std::string> realm_set; |
1073 realm_set.insert(form.signon_realm); | 1073 realm_set.insert(form.signon_realm); |
1074 for (const autofill::PasswordForm* db_form : database_forms) { | 1074 for (const autofill::PasswordForm* db_form : database_forms) { |
1075 // TODO(vabr): We should not be getting different schemes here. | 1075 // TODO(vabr): We should not be getting different schemes here. |
1076 // http://crbug.com/340112 | 1076 // http://crbug.com/340112 |
1077 if (form.scheme != db_form->scheme) | 1077 if (form.scheme != db_form->scheme) |
1078 continue; // Forms with different schemes never match. | 1078 continue; // Forms with different schemes never match. |
1079 const std::string& original_singon_realm(db_form->original_signon_realm); | 1079 const std::string& original_singon_realm(db_form->original_signon_realm); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1118 void PasswordStoreMac::GetAutofillableLoginsImpl( | 1118 void PasswordStoreMac::GetAutofillableLoginsImpl( |
1119 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | 1119 scoped_ptr<PasswordStore::GetLoginsRequest> request) { |
1120 ScopedVector<autofill::PasswordForm> obtained_forms; | 1120 ScopedVector<autofill::PasswordForm> obtained_forms; |
1121 FillAutofillableLogins(&obtained_forms); | 1121 FillAutofillableLogins(&obtained_forms); |
1122 request->NotifyConsumerWithResults(obtained_forms.Pass()); | 1122 request->NotifyConsumerWithResults(obtained_forms.Pass()); |
1123 } | 1123 } |
1124 | 1124 |
1125 bool PasswordStoreMac::FillAutofillableLogins( | 1125 bool PasswordStoreMac::FillAutofillableLogins( |
1126 ScopedVector<autofill::PasswordForm>* forms) { | 1126 ScopedVector<autofill::PasswordForm>* forms) { |
1127 DCHECK(thread_->message_loop() == base::MessageLoop::current()); | 1127 DCHECK(thread_->message_loop() == base::MessageLoop::current()); |
1128 forms->clear(); | |
1128 | 1129 |
1129 ScopedVector<PasswordForm> database_forms; | 1130 ScopedVector<PasswordForm> database_forms; |
1130 if (!login_metadata_db_ || | 1131 if (!login_metadata_db_ || |
1131 !login_metadata_db_->GetAutofillableLogins(&database_forms)) | 1132 !login_metadata_db_->GetAutofillableLogins(&database_forms)) |
1132 return false; | 1133 return false; |
1133 | 1134 |
1134 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 1135 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
1135 forms); | 1136 forms); |
1136 | 1137 |
1137 if (!database_forms.empty()) { | 1138 if (!database_forms.empty()) { |
1138 RemoveDatabaseForms(&database_forms); | 1139 RemoveDatabaseForms(&database_forms); |
1139 NotifyLoginsChanged(FormsToRemoveChangeList(database_forms.get())); | 1140 NotifyLoginsChanged(FormsToRemoveChangeList(database_forms.get())); |
1140 } | 1141 } |
1141 | 1142 |
1142 return true; | 1143 return true; |
1143 } | 1144 } |
1144 | 1145 |
1145 bool PasswordStoreMac::FillBlacklistLogins( | 1146 bool PasswordStoreMac::FillBlacklistLogins( |
1146 ScopedVector<autofill::PasswordForm>* forms) { | 1147 ScopedVector<autofill::PasswordForm>* forms) { |
1148 forms->clear(); | |
engedy
2015/03/09 13:33:18
nit: Sorry, I was meaning to say after the DCHECK.
vabr (Chromium)
2015/03/09 17:44:15
Done.
I agree that preconditions-checking DCHECK s
| |
1147 DCHECK(thread_->message_loop() == base::MessageLoop::current()); | 1149 DCHECK(thread_->message_loop() == base::MessageLoop::current()); |
1148 return login_metadata_db_ && login_metadata_db_->GetBlacklistLogins(forms); | 1150 return login_metadata_db_ && login_metadata_db_->GetBlacklistLogins(forms); |
1149 } | 1151 } |
1150 | 1152 |
1151 bool PasswordStoreMac::AddToKeychainIfNecessary(const PasswordForm& form) { | 1153 bool PasswordStoreMac::AddToKeychainIfNecessary(const PasswordForm& form) { |
1152 if (form.blacklisted_by_user) { | 1154 if (form.blacklisted_by_user) { |
1153 return true; | 1155 return true; |
1154 } | 1156 } |
1155 MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get()); | 1157 MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get()); |
1156 return keychainAdapter.AddPassword(form); | 1158 return keychainAdapter.AddPassword(form); |
1157 } | 1159 } |
1158 | 1160 |
1159 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( | 1161 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( |
1160 const autofill::PasswordForm& form) { | 1162 const autofill::PasswordForm& form) { |
1161 DCHECK(login_metadata_db_); | 1163 DCHECK(login_metadata_db_); |
1162 bool has_match = false; | 1164 bool has_match = false; |
1163 ScopedVector<autofill::PasswordForm> database_forms; | 1165 ScopedVector<autofill::PasswordForm> database_forms; |
1164 login_metadata_db_->GetLogins(form, &database_forms); | 1166 if (!login_metadata_db_->GetLogins(form, &database_forms)) |
1167 return false; | |
1165 for (const autofill::PasswordForm* db_form : database_forms) { | 1168 for (const autofill::PasswordForm* db_form : database_forms) { |
1166 // Below we filter out forms with non-empty original_signon_realm, because | 1169 // Below we filter out forms with non-empty original_signon_realm, because |
1167 // those signal fuzzy matches, and we are only interested in exact ones. | 1170 // those signal fuzzy matches, and we are only interested in exact ones. |
1168 if (db_form->original_signon_realm.empty() && | 1171 if (db_form->original_signon_realm.empty() && |
1169 internal_keychain_helpers::FormsMatchForMerge( | 1172 internal_keychain_helpers::FormsMatchForMerge( |
1170 form, *db_form, internal_keychain_helpers::STRICT_FORM_MATCH) && | 1173 form, *db_form, internal_keychain_helpers::STRICT_FORM_MATCH) && |
1171 db_form->origin == form.origin) { | 1174 db_form->origin == form.origin) { |
1172 has_match = true; | 1175 has_match = true; |
1173 break; | 1176 break; |
1174 } | 1177 } |
(...skipping 22 matching lines...) Expand all Loading... | |
1197 owned_keychain_adapter.RemovePassword(**i); | 1200 owned_keychain_adapter.RemovePassword(**i); |
1198 } | 1201 } |
1199 } | 1202 } |
1200 | 1203 |
1201 void PasswordStoreMac::CleanOrphanedForms( | 1204 void PasswordStoreMac::CleanOrphanedForms( |
1202 ScopedVector<autofill::PasswordForm>* orphaned_forms) { | 1205 ScopedVector<autofill::PasswordForm>* orphaned_forms) { |
1203 DCHECK(orphaned_forms); | 1206 DCHECK(orphaned_forms); |
1204 DCHECK(login_metadata_db_); | 1207 DCHECK(login_metadata_db_); |
1205 | 1208 |
1206 ScopedVector<autofill::PasswordForm> database_forms; | 1209 ScopedVector<autofill::PasswordForm> database_forms; |
1207 login_metadata_db_->GetAutofillableLogins(&database_forms); | 1210 if (!login_metadata_db_->GetAutofillableLogins(&database_forms)) |
1211 return; | |
1208 | 1212 |
1209 // Filter forms with corresponding Keychain entry out of |database_forms|. | 1213 // Filter forms with corresponding Keychain entry out of |database_forms|. |
1210 ScopedVector<PasswordForm> forms_with_keychain_entry; | 1214 ScopedVector<PasswordForm> forms_with_keychain_entry; |
1211 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 1215 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
1212 &forms_with_keychain_entry); | 1216 &forms_with_keychain_entry); |
1213 | 1217 |
1214 // Clean up any orphaned database entries. | 1218 // Clean up any orphaned database entries. |
1215 RemoveDatabaseForms(&database_forms); | 1219 RemoveDatabaseForms(&database_forms); |
1216 | 1220 |
1217 // Move the orphaned DB forms to the output parameter. | 1221 // Move the orphaned DB forms to the output parameter. |
1218 AppendSecondToFirst(orphaned_forms, &database_forms); | 1222 AppendSecondToFirst(orphaned_forms, &database_forms); |
1219 } | 1223 } |
OLD | NEW |