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 <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 {"times_used", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, | 112 {"times_used", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, |
113 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 113 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
114 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 114 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
115 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 115 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
116 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 116 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
117 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, | 117 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, |
118 // This field is always "chrome-profile_id" so that we can search for it. | 118 // This field is always "chrome-profile_id" so that we can search for it. |
119 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 119 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
120 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; | 120 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; |
121 | 121 |
122 char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) { | 122 std::string GetStringFromAttributes(GHashTable* attrs, const char* keyname) { |
vabr (Chromium)
2015/01/29 14:10:34
I would suggest still returning char* and carefull
dvadym
2015/01/29 14:21:40
Done.
| |
123 return static_cast<char*>(g_hash_table_lookup(attrs, keyname)); | 123 gpointer value = g_hash_table_lookup(attrs, keyname); |
124 return value ? std::string(static_cast<char*>(value)) : std::string(); | |
124 } | 125 } |
125 | 126 |
126 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { | 127 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { |
127 char* value = static_cast<char*>(g_hash_table_lookup(attrs, keyname)); | 128 gpointer value = g_hash_table_lookup(attrs, keyname); |
129 if (value == NULL) | |
vabr (Chromium)
2015/01/29 14:10:34
nit: NULL -> nullptr
dvadym
2015/01/29 14:21:40
Done.
| |
130 return uint32_t(); | |
128 uint32_t result; | 131 uint32_t result; |
129 bool value_ok = base::StringToUint(value, &result); | 132 bool value_ok = base::StringToUint(static_cast<char*>(value), &result); |
130 DCHECK(value_ok); | 133 DCHECK(value_ok); |
131 return result; | 134 return result; |
132 } | 135 } |
133 | 136 |
134 // Convert the attributes into a new PasswordForm. | 137 // Convert the attributes into a new PasswordForm. |
135 // Note: does *not* get the actual password, as that is not a key attribute! | 138 // Note: does *not* get the actual password, as that is not a key attribute! |
136 // Returns nullptr if the attributes are for the wrong application. | 139 // Returns nullptr if the attributes are for the wrong application. |
137 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) { | 140 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) { |
138 base::StringPiece app_value = GetStringFromAttributes(attrs, "application"); | 141 std::string app_string = GetStringFromAttributes(attrs, "application"); |
vabr (Chromium)
2015/01/29 14:10:34
Please do not convert to std::string, that harms p
dvadym
2015/01/29 14:21:39
Done.
| |
142 base::StringPiece app_value = app_string; | |
139 if (!app_value.starts_with(kLibsecretAppString)) | 143 if (!app_value.starts_with(kLibsecretAppString)) |
140 return scoped_ptr<PasswordForm>(); | 144 return scoped_ptr<PasswordForm>(); |
141 | 145 |
142 scoped_ptr<PasswordForm> form(new PasswordForm()); | 146 scoped_ptr<PasswordForm> form(new PasswordForm()); |
143 form->origin = GURL(GetStringFromAttributes(attrs, "origin_url")); | 147 form->origin = GURL(GetStringFromAttributes(attrs, "origin_url")); |
144 form->action = GURL(GetStringFromAttributes(attrs, "action_url")); | 148 form->action = GURL(GetStringFromAttributes(attrs, "action_url")); |
145 form->username_element = | 149 form->username_element = |
146 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_element")); | 150 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_element")); |
147 form->username_value = | 151 form->username_value = |
148 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_value")); | 152 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_value")); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 return true; | 586 return true; |
583 } | 587 } |
584 | 588 |
585 std::string NativeBackendLibsecret::GetProfileSpecificAppString( | 589 std::string NativeBackendLibsecret::GetProfileSpecificAppString( |
586 LocalProfileId id) { | 590 LocalProfileId id) { |
587 // Originally, the application string was always just "chrome" and used only | 591 // Originally, the application string was always just "chrome" and used only |
588 // so that we had *something* to search for since GNOME Keyring won't search | 592 // so that we had *something* to search for since GNOME Keyring won't search |
589 // for nothing. Now we use it to distinguish passwords for different profiles. | 593 // for nothing. Now we use it to distinguish passwords for different profiles. |
590 return base::StringPrintf("%s-%d", kLibsecretAppString, id); | 594 return base::StringPrintf("%s-%d", kLibsecretAppString, id); |
591 } | 595 } |
OLD | NEW |