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 24 matching lines...) Expand all Loading... | |
1104 RemoveDatabaseForms(&database_forms); | 1104 RemoveDatabaseForms(&database_forms); |
1105 NotifyLoginsChanged(FormsToRemoveChangeList(database_forms.get())); | 1105 NotifyLoginsChanged(FormsToRemoveChangeList(database_forms.get())); |
1106 } | 1106 } |
1107 | 1107 |
1108 return matched_forms.Pass(); | 1108 return matched_forms.Pass(); |
1109 } | 1109 } |
1110 | 1110 |
1111 void PasswordStoreMac::GetBlacklistLoginsImpl( | 1111 void PasswordStoreMac::GetBlacklistLoginsImpl( |
1112 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | 1112 scoped_ptr<PasswordStore::GetLoginsRequest> request) { |
1113 ScopedVector<autofill::PasswordForm> obtained_forms; | 1113 ScopedVector<autofill::PasswordForm> obtained_forms; |
1114 FillBlacklistLogins(&obtained_forms); | 1114 FillBlacklistLogins(&obtained_forms); |
engedy
2015/03/11 19:25:35
Need to check return value and clear forms on fail
vabr (Chromium)
2015/03/12 15:30:51
Done.
| |
1115 request->NotifyConsumerWithResults(obtained_forms.Pass()); | 1115 request->NotifyConsumerWithResults(obtained_forms.Pass()); |
1116 } | 1116 } |
1117 | 1117 |
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); |
engedy
2015/03/11 19:25:35
Need to check return value and clear forms on fail
vabr (Chromium)
2015/03/12 15:30:51
Done.
| |
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_EQ(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) { |
1147 DCHECK(thread_->message_loop() == base::MessageLoop::current()); | 1148 DCHECK_EQ(thread_->message_loop(), base::MessageLoop::current()); |
1148 return login_metadata_db_ && login_metadata_db_->GetBlacklistLogins(forms); | 1149 return login_metadata_db_ && login_metadata_db_->GetBlacklistLogins(forms); |
1149 } | 1150 } |
1150 | 1151 |
1151 bool PasswordStoreMac::AddToKeychainIfNecessary(const PasswordForm& form) { | 1152 bool PasswordStoreMac::AddToKeychainIfNecessary(const PasswordForm& form) { |
1152 if (form.blacklisted_by_user) { | 1153 if (form.blacklisted_by_user) { |
1153 return true; | 1154 return true; |
1154 } | 1155 } |
1155 MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get()); | 1156 MacKeychainPasswordFormAdapter keychainAdapter(keychain_.get()); |
1156 return keychainAdapter.AddPassword(form); | 1157 return keychainAdapter.AddPassword(form); |
1157 } | 1158 } |
1158 | 1159 |
1159 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( | 1160 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( |
1160 const autofill::PasswordForm& form) { | 1161 const autofill::PasswordForm& form) { |
1161 DCHECK(login_metadata_db_); | 1162 DCHECK(login_metadata_db_); |
1162 bool has_match = false; | 1163 bool has_match = false; |
1163 ScopedVector<autofill::PasswordForm> database_forms; | 1164 ScopedVector<autofill::PasswordForm> database_forms; |
1164 login_metadata_db_->GetLogins(form, &database_forms); | 1165 if (!login_metadata_db_->GetLogins(form, &database_forms)) |
1166 return false; | |
1165 for (const autofill::PasswordForm* db_form : database_forms) { | 1167 for (const autofill::PasswordForm* db_form : database_forms) { |
1166 // Below we filter out forms with non-empty original_signon_realm, because | 1168 // 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. | 1169 // those signal fuzzy matches, and we are only interested in exact ones. |
1168 if (db_form->original_signon_realm.empty() && | 1170 if (db_form->original_signon_realm.empty() && |
1169 internal_keychain_helpers::FormsMatchForMerge( | 1171 internal_keychain_helpers::FormsMatchForMerge( |
1170 form, *db_form, internal_keychain_helpers::STRICT_FORM_MATCH) && | 1172 form, *db_form, internal_keychain_helpers::STRICT_FORM_MATCH) && |
1171 db_form->origin == form.origin) { | 1173 db_form->origin == form.origin) { |
1172 has_match = true; | 1174 has_match = true; |
1173 break; | 1175 break; |
1174 } | 1176 } |
(...skipping 22 matching lines...) Expand all Loading... | |
1197 owned_keychain_adapter.RemovePassword(**i); | 1199 owned_keychain_adapter.RemovePassword(**i); |
1198 } | 1200 } |
1199 } | 1201 } |
1200 | 1202 |
1201 void PasswordStoreMac::CleanOrphanedForms( | 1203 void PasswordStoreMac::CleanOrphanedForms( |
1202 ScopedVector<autofill::PasswordForm>* orphaned_forms) { | 1204 ScopedVector<autofill::PasswordForm>* orphaned_forms) { |
1203 DCHECK(orphaned_forms); | 1205 DCHECK(orphaned_forms); |
1204 DCHECK(login_metadata_db_); | 1206 DCHECK(login_metadata_db_); |
1205 | 1207 |
1206 ScopedVector<autofill::PasswordForm> database_forms; | 1208 ScopedVector<autofill::PasswordForm> database_forms; |
1207 login_metadata_db_->GetAutofillableLogins(&database_forms); | 1209 if (!login_metadata_db_->GetAutofillableLogins(&database_forms)) |
1210 return; | |
1208 | 1211 |
1209 // Filter forms with corresponding Keychain entry out of |database_forms|. | 1212 // Filter forms with corresponding Keychain entry out of |database_forms|. |
1210 ScopedVector<PasswordForm> forms_with_keychain_entry; | 1213 ScopedVector<PasswordForm> forms_with_keychain_entry; |
1211 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 1214 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
1212 &forms_with_keychain_entry); | 1215 &forms_with_keychain_entry); |
1213 | 1216 |
1214 // Clean up any orphaned database entries. | 1217 // Clean up any orphaned database entries. |
1215 RemoveDatabaseForms(&database_forms); | 1218 RemoveDatabaseForms(&database_forms); |
1216 | 1219 |
1217 // Move the orphaned DB forms to the output parameter. | 1220 // Move the orphaned DB forms to the output parameter. |
1218 AppendSecondToFirst(orphaned_forms, &database_forms); | 1221 AppendSecondToFirst(orphaned_forms, &database_forms); |
1219 } | 1222 } |
OLD | NEW |