| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/native_backend_libsecret.h" | 5 #include "chrome/browser/password_manager/native_backend_libsecret.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <libsecret/secret.h> | 10 #include <libsecret/secret.h> |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 std::string GetProfileSpecificAppString(LocalProfileId id) { | 157 std::string GetProfileSpecificAppString(LocalProfileId id) { |
| 158 // Originally, the application string was always just "chrome" and used only | 158 // Originally, the application string was always just "chrome" and used only |
| 159 // so that we had *something* to search for since GNOME Keyring won't search | 159 // so that we had *something* to search for since GNOME Keyring won't search |
| 160 // for nothing. Now we use it to distinguish passwords for different profiles. | 160 // for nothing. Now we use it to distinguish passwords for different profiles. |
| 161 return base::StringPrintf("%s-%d", kLibsecretAppString, id); | 161 return base::StringPrintf("%s-%d", kLibsecretAppString, id); |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace | 164 } // namespace |
| 165 | 165 |
| 166 NativeBackendLibsecret::NativeBackendLibsecret(LocalProfileId id) | 166 NativeBackendLibsecret::NativeBackendLibsecret(LocalProfileId id) |
| 167 : app_string_(GetProfileSpecificAppString(id)) { | 167 : app_string_(GetProfileSpecificAppString(id)), |
| 168 } | 168 ensured_keyring_unlocked_(false) {} |
| 169 | 169 |
| 170 NativeBackendLibsecret::~NativeBackendLibsecret() { | 170 NativeBackendLibsecret::~NativeBackendLibsecret() { |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool NativeBackendLibsecret::Init() { | 173 bool NativeBackendLibsecret::Init() { |
| 174 return LibsecretLoader::EnsureLibsecretLoaded(); | 174 return LibsecretLoader::EnsureLibsecretLoaded(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 password_manager::PasswordStoreChangeList NativeBackendLibsecret::AddLogin( | 177 password_manager::PasswordStoreChangeList NativeBackendLibsecret::AddLogin( |
| 178 const PasswordForm& form) { | 178 const PasswordForm& form) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 bool NativeBackendLibsecret::GetLogins( | 301 bool NativeBackendLibsecret::GetLogins( |
| 302 const PasswordStore::FormDigest& form, | 302 const PasswordStore::FormDigest& form, |
| 303 ScopedVector<autofill::PasswordForm>* forms) { | 303 ScopedVector<autofill::PasswordForm>* forms) { |
| 304 return GetLoginsList(&form, ALL_LOGINS, forms); | 304 return GetLoginsList(&form, ALL_LOGINS, forms); |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool NativeBackendLibsecret::AddUpdateLoginSearch( | 307 bool NativeBackendLibsecret::AddUpdateLoginSearch( |
| 308 const autofill::PasswordForm& lookup_form, | 308 const autofill::PasswordForm& lookup_form, |
| 309 ScopedVector<autofill::PasswordForm>* forms) { | 309 ScopedVector<autofill::PasswordForm>* forms) { |
| 310 if (!ensured_keyring_unlocked_) { |
| 311 LibsecretLoader::EnsureKeyringUnlocked(); |
| 312 ensured_keyring_unlocked_ = true; |
| 313 } |
| 314 |
| 310 LibsecretAttributesBuilder attrs; | 315 LibsecretAttributesBuilder attrs; |
| 311 attrs.Append("origin_url", lookup_form.origin.spec()); | 316 attrs.Append("origin_url", lookup_form.origin.spec()); |
| 312 attrs.Append("username_element", UTF16ToUTF8(lookup_form.username_element)); | 317 attrs.Append("username_element", UTF16ToUTF8(lookup_form.username_element)); |
| 313 attrs.Append("username_value", UTF16ToUTF8(lookup_form.username_value)); | 318 attrs.Append("username_value", UTF16ToUTF8(lookup_form.username_value)); |
| 314 attrs.Append("password_element", UTF16ToUTF8(lookup_form.password_element)); | 319 attrs.Append("password_element", UTF16ToUTF8(lookup_form.password_element)); |
| 315 attrs.Append("signon_realm", lookup_form.signon_realm); | 320 attrs.Append("signon_realm", lookup_form.signon_realm); |
| 316 attrs.Append("application", app_string_); | 321 attrs.Append("application", app_string_); |
| 317 | 322 |
| 318 GError* error = nullptr; | 323 GError* error = nullptr; |
| 319 GList* found = LibsecretLoader::secret_service_search_sync( | 324 GList* found = LibsecretLoader::secret_service_search_sync( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 406 |
| 402 bool NativeBackendLibsecret::GetAllLogins( | 407 bool NativeBackendLibsecret::GetAllLogins( |
| 403 ScopedVector<autofill::PasswordForm>* forms) { | 408 ScopedVector<autofill::PasswordForm>* forms) { |
| 404 return GetLoginsList(nullptr, ALL_LOGINS, forms); | 409 return GetLoginsList(nullptr, ALL_LOGINS, forms); |
| 405 } | 410 } |
| 406 | 411 |
| 407 bool NativeBackendLibsecret::GetLoginsList( | 412 bool NativeBackendLibsecret::GetLoginsList( |
| 408 const PasswordStore::FormDigest* lookup_form, | 413 const PasswordStore::FormDigest* lookup_form, |
| 409 GetLoginsListOptions options, | 414 GetLoginsListOptions options, |
| 410 ScopedVector<autofill::PasswordForm>* forms) { | 415 ScopedVector<autofill::PasswordForm>* forms) { |
| 416 if (!ensured_keyring_unlocked_) { |
| 417 LibsecretLoader::EnsureKeyringUnlocked(); |
| 418 ensured_keyring_unlocked_ = true; |
| 419 } |
| 420 |
| 411 LibsecretAttributesBuilder attrs; | 421 LibsecretAttributesBuilder attrs; |
| 412 attrs.Append("application", app_string_); | 422 attrs.Append("application", app_string_); |
| 413 if (options != ALL_LOGINS) | 423 if (options != ALL_LOGINS) |
| 414 attrs.Append("blacklisted_by_user", options == BLACKLISTED_LOGINS); | 424 attrs.Append("blacklisted_by_user", options == BLACKLISTED_LOGINS); |
| 415 if (lookup_form && | 425 if (lookup_form && |
| 416 !password_manager::ShouldPSLDomainMatchingApply( | 426 !password_manager::ShouldPSLDomainMatchingApply( |
| 417 password_manager::GetRegistryControlledDomain( | 427 password_manager::GetRegistryControlledDomain( |
| 418 GURL(lookup_form->signon_realm))) && | 428 GURL(lookup_form->signon_realm))) && |
| 419 lookup_form->scheme != PasswordForm::SCHEME_HTML) | 429 lookup_form->scheme != PasswordForm::SCHEME_HTML) |
| 420 attrs.Append("signon_realm", lookup_form->signon_realm); | 430 attrs.Append("signon_realm", lookup_form->signon_realm); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 if (lookup_form) { | 570 if (lookup_form) { |
| 561 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", | 571 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", |
| 562 allow_psl_match | 572 allow_psl_match |
| 563 ? psl_domain_match_metric | 573 ? psl_domain_match_metric |
| 564 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, | 574 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, |
| 565 password_manager::PSL_DOMAIN_MATCH_COUNT); | 575 password_manager::PSL_DOMAIN_MATCH_COUNT); |
| 566 } | 576 } |
| 567 g_list_free(found); | 577 g_list_free(found); |
| 568 return forms; | 578 return forms; |
| 569 } | 579 } |
| OLD | NEW |