| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 const PasswordForm& form_b, | 471 const PasswordForm& form_b, |
| 472 FormMatchStrictness strictness) { | 472 FormMatchStrictness strictness) { |
| 473 // We never merge blacklist entries between our store and the Keychain, | 473 // We never merge blacklist entries between our store and the Keychain, |
| 474 // and federated logins should not be stored in the Keychain at all. | 474 // and federated logins should not be stored in the Keychain at all. |
| 475 if (form_a.blacklisted_by_user || form_b.blacklisted_by_user || | 475 if (form_a.blacklisted_by_user || form_b.blacklisted_by_user || |
| 476 !form_a.federation_url.is_empty() || !form_b.federation_url.is_empty()) { | 476 !form_a.federation_url.is_empty() || !form_b.federation_url.is_empty()) { |
| 477 return false; | 477 return false; |
| 478 } | 478 } |
| 479 bool equal_realm = form_a.signon_realm == form_b.signon_realm; | 479 bool equal_realm = form_a.signon_realm == form_b.signon_realm; |
| 480 if (strictness == FUZZY_FORM_MATCH) { | 480 if (strictness == FUZZY_FORM_MATCH) { |
| 481 equal_realm |= (!form_a.original_signon_realm.empty()) && | 481 equal_realm |= form_a.is_public_suffix_match; |
| 482 form_a.original_signon_realm == form_b.signon_realm; | |
| 483 } | 482 } |
| 484 return form_a.scheme == form_b.scheme && equal_realm && | 483 return form_a.scheme == form_b.scheme && equal_realm && |
| 485 form_a.username_value == form_b.username_value; | 484 form_a.username_value == form_b.username_value; |
| 486 } | 485 } |
| 487 | 486 |
| 488 // Moves entries from |forms| that represent either blacklisted or federated | 487 // Moves entries from |forms| that represent either blacklisted or federated |
| 489 // logins into |extracted|. These two types are stored only in the LoginDatabase | 488 // logins into |extracted|. These two types are stored only in the LoginDatabase |
| 490 // and do not have corresponding Keychain entries. | 489 // and do not have corresponding Keychain entries. |
| 491 void ExtractNonKeychainForms(ScopedVector<autofill::PasswordForm>* forms, | 490 void ExtractNonKeychainForms(ScopedVector<autofill::PasswordForm>* forms, |
| 492 ScopedVector<autofill::PasswordForm>* extracted) { | 491 ScopedVector<autofill::PasswordForm>* extracted) { |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 } | 1175 } |
| 1177 | 1176 |
| 1178 // Let's gather all signon realms we want to match with keychain entries. | 1177 // Let's gather all signon realms we want to match with keychain entries. |
| 1179 std::set<std::string> realm_set; | 1178 std::set<std::string> realm_set; |
| 1180 realm_set.insert(form.signon_realm); | 1179 realm_set.insert(form.signon_realm); |
| 1181 for (const autofill::PasswordForm* db_form : database_forms) { | 1180 for (const autofill::PasswordForm* db_form : database_forms) { |
| 1182 // TODO(vabr): We should not be getting different schemes here. | 1181 // TODO(vabr): We should not be getting different schemes here. |
| 1183 // http://crbug.com/340112 | 1182 // http://crbug.com/340112 |
| 1184 if (form.scheme != db_form->scheme) | 1183 if (form.scheme != db_form->scheme) |
| 1185 continue; // Forms with different schemes never match. | 1184 continue; // Forms with different schemes never match. |
| 1186 const std::string& original_singon_realm(db_form->original_signon_realm); | 1185 if (db_form->is_public_suffix_match) |
| 1187 if (!original_singon_realm.empty()) | 1186 realm_set.insert(db_form->signon_realm); |
| 1188 realm_set.insert(original_singon_realm); | |
| 1189 } | 1187 } |
| 1190 ScopedVector<autofill::PasswordForm> keychain_forms; | 1188 ScopedVector<autofill::PasswordForm> keychain_forms; |
| 1191 for (std::set<std::string>::const_iterator realm = realm_set.begin(); | 1189 for (std::set<std::string>::const_iterator realm = realm_set.begin(); |
| 1192 realm != realm_set.end(); ++realm) { | 1190 realm != realm_set.end(); ++realm) { |
| 1193 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); | 1191 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); |
| 1194 ScopedVector<autofill::PasswordForm> temp_keychain_forms = | 1192 ScopedVector<autofill::PasswordForm> temp_keychain_forms = |
| 1195 keychain_adapter.PasswordsFillingForm(*realm, form.scheme); | 1193 keychain_adapter.PasswordsFillingForm(*realm, form.scheme); |
| 1196 AppendSecondToFirst(&keychain_forms, &temp_keychain_forms); | 1194 AppendSecondToFirst(&keychain_forms, &temp_keychain_forms); |
| 1197 } | 1195 } |
| 1198 | 1196 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 } | 1268 } |
| 1271 | 1269 |
| 1272 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( | 1270 bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( |
| 1273 const autofill::PasswordForm& form) { | 1271 const autofill::PasswordForm& form) { |
| 1274 DCHECK(login_metadata_db_); | 1272 DCHECK(login_metadata_db_); |
| 1275 bool has_match = false; | 1273 bool has_match = false; |
| 1276 ScopedVector<autofill::PasswordForm> database_forms; | 1274 ScopedVector<autofill::PasswordForm> database_forms; |
| 1277 if (!login_metadata_db_->GetLogins(form, &database_forms)) | 1275 if (!login_metadata_db_->GetLogins(form, &database_forms)) |
| 1278 return false; | 1276 return false; |
| 1279 for (const autofill::PasswordForm* db_form : database_forms) { | 1277 for (const autofill::PasswordForm* db_form : database_forms) { |
| 1280 // Below we filter out forms with non-empty original_signon_realm, because | 1278 // Below we filter out fuzzy matched forms because we are only interested |
| 1281 // those signal fuzzy matches, and we are only interested in exact ones. | 1279 // in exact ones. |
| 1282 if (db_form->original_signon_realm.empty() && | 1280 if (!db_form->is_public_suffix_match && |
| 1283 internal_keychain_helpers::FormsMatchForMerge( | 1281 internal_keychain_helpers::FormsMatchForMerge( |
| 1284 form, *db_form, internal_keychain_helpers::STRICT_FORM_MATCH) && | 1282 form, *db_form, internal_keychain_helpers::STRICT_FORM_MATCH) && |
| 1285 db_form->origin == form.origin) { | 1283 db_form->origin == form.origin) { |
| 1286 has_match = true; | 1284 has_match = true; |
| 1287 break; | 1285 break; |
| 1288 } | 1286 } |
| 1289 } | 1287 } |
| 1290 return has_match; | 1288 return has_match; |
| 1291 } | 1289 } |
| 1292 | 1290 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 ScopedVector<PasswordForm> forms_with_keychain_entry; | 1323 ScopedVector<PasswordForm> forms_with_keychain_entry; |
| 1326 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 1324 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
| 1327 &forms_with_keychain_entry); | 1325 &forms_with_keychain_entry); |
| 1328 | 1326 |
| 1329 // Clean up any orphaned database entries. | 1327 // Clean up any orphaned database entries. |
| 1330 RemoveDatabaseForms(&database_forms); | 1328 RemoveDatabaseForms(&database_forms); |
| 1331 | 1329 |
| 1332 // Move the orphaned DB forms to the output parameter. | 1330 // Move the orphaned DB forms to the output parameter. |
| 1333 AppendSecondToFirst(orphaned_forms, &database_forms); | 1331 AppendSecondToFirst(orphaned_forms, &database_forms); |
| 1334 } | 1332 } |
| OLD | NEW |