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/native_backend_gnome_x.h" | 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gnome-keyring.h> | 8 #include <gnome-keyring.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "components/autofill/core/common/password_form.h" | 25 #include "components/autofill/core/common/password_form.h" |
26 #include "components/password_manager/core/browser/psl_matching_helper.h" | 26 #include "components/password_manager/core/browser/psl_matching_helper.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 | 28 |
29 using autofill::PasswordForm; | 29 using autofill::PasswordForm; |
30 using base::UTF8ToUTF16; | 30 using base::UTF8ToUTF16; |
31 using base::UTF16ToUTF8; | 31 using base::UTF16ToUTF8; |
32 using content::BrowserThread; | 32 using content::BrowserThread; |
33 | 33 |
| 34 namespace { |
| 35 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); |
| 36 } |
| 37 |
34 #define GNOME_KEYRING_DEFINE_POINTER(name) \ | 38 #define GNOME_KEYRING_DEFINE_POINTER(name) \ |
35 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; | 39 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; |
36 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) | 40 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) |
37 #undef GNOME_KEYRING_DEFINE_POINTER | 41 #undef GNOME_KEYRING_DEFINE_POINTER |
38 | 42 |
39 bool GnomeKeyringLoader::keyring_loaded = false; | 43 bool GnomeKeyringLoader::keyring_loaded = false; |
40 | 44 |
41 #if defined(DLOPEN_GNOME_KEYRING) | 45 #if defined(DLOPEN_GNOME_KEYRING) |
42 | 46 |
43 #define GNOME_KEYRING_FUNCTION_INFO(name) \ | 47 #define GNOME_KEYRING_FUNCTION_INFO(name) \ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); | 128 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); |
125 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); | 129 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); |
126 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); | 130 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); |
127 form->signon_realm = string_attr_map["signon_realm"]; | 131 form->signon_realm = string_attr_map["signon_realm"]; |
128 form->ssl_valid = uint_attr_map["ssl_valid"]; | 132 form->ssl_valid = uint_attr_map["ssl_valid"]; |
129 form->preferred = uint_attr_map["preferred"]; | 133 form->preferred = uint_attr_map["preferred"]; |
130 int64 date_created = 0; | 134 int64 date_created = 0; |
131 bool date_ok = base::StringToInt64(string_attr_map["date_created"], | 135 bool date_ok = base::StringToInt64(string_attr_map["date_created"], |
132 &date_created); | 136 &date_created); |
133 DCHECK(date_ok); | 137 DCHECK(date_ok); |
134 form->date_created = base::Time::FromTimeT(date_created); | 138 // In the past |date_created| was stored as time_t. Currently is stored as |
| 139 // base::Time's internal value. We need to distinguish, which format the |
| 140 // number in |date_created| was stored in. We use the fact that |
| 141 // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an |
| 142 // unlikely date back in 17th century, and anything above |
| 143 // kMaxPossibleTimeTValue clearly must be in the internal value format. |
| 144 form->date_created = date_created < kMaxPossibleTimeTValue |
| 145 ? base::Time::FromTimeT(date_created) |
| 146 : base::Time::FromInternalValue(date_created); |
135 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; | 147 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; |
136 form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]); | 148 form->type = static_cast<PasswordForm::Type>(uint_attr_map["type"]); |
137 form->times_used = uint_attr_map["times_used"]; | 149 form->times_used = uint_attr_map["times_used"]; |
138 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); | 150 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); |
139 int64 date_synced = 0; | 151 int64 date_synced = 0; |
140 base::StringToInt64(string_attr_map["date_synced"], &date_synced); | 152 base::StringToInt64(string_attr_map["date_synced"], &date_synced); |
141 form->date_synced = base::Time::FromInternalValue(date_synced); | 153 form->date_synced = base::Time::FromInternalValue(date_synced); |
142 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); | 154 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); |
143 form->avatar_url = GURL(string_attr_map["avatar_url"]); | 155 form->avatar_url = GURL(string_attr_map["avatar_url"]); |
144 form->federation_url = GURL(string_attr_map["federation_url"]); | 156 form->federation_url = GURL(string_attr_map["federation_url"]); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // matching is used to find a result, then the results signon realm, origin | 322 // matching is used to find a result, then the results signon realm, origin |
311 // and action are stored are replaced by those of |lookup_form_|. | 323 // and action are stored are replaced by those of |lookup_form_|. |
312 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the | 324 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the |
313 // found logins to those which indeed PSL-match the look-up. And finally, | 325 // found logins to those which indeed PSL-match the look-up. And finally, |
314 // |lookup_form_| set to NULL means that PSL matching is not required. | 326 // |lookup_form_| set to NULL means that PSL matching is not required. |
315 scoped_ptr<PasswordForm> lookup_form_; | 327 scoped_ptr<PasswordForm> lookup_form_; |
316 }; | 328 }; |
317 | 329 |
318 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { | 330 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
320 time_t date_created = form.date_created.ToTimeT(); | 332 int64 date_created = form.date_created.ToInternalValue(); |
321 // If we are asked to save a password with 0 date, use the current time. | 333 // If we are asked to save a password with 0 date, use the current time. |
322 // We don't want to actually save passwords as though on January 1, 1970. | 334 // We don't want to actually save passwords as though on January 1, 1601. |
323 if (!date_created) | 335 if (!date_created) |
324 date_created = time(NULL); | 336 date_created = base::Time::Now().ToInternalValue(); |
325 int64 date_synced = form.date_synced.ToInternalValue(); | 337 int64 date_synced = form.date_synced.ToInternalValue(); |
326 gnome_keyring_store_password( | 338 gnome_keyring_store_password( |
327 &kGnomeSchema, | 339 &kGnomeSchema, |
328 NULL, // Default keyring. | 340 NULL, // Default keyring. |
329 form.origin.spec().c_str(), // Display name. | 341 form.origin.spec().c_str(), // Display name. |
330 UTF16ToUTF8(form.password_value).c_str(), | 342 UTF16ToUTF8(form.password_value).c_str(), |
331 OnOperationDone, | 343 OnOperationDone, |
332 this, // data | 344 this, // data |
333 NULL, // destroy_data | 345 NULL, // destroy_data |
334 "origin_url", form.origin.spec().c_str(), | 346 "origin_url", form.origin.spec().c_str(), |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 } | 801 } |
790 return ok; | 802 return ok; |
791 } | 803 } |
792 | 804 |
793 std::string NativeBackendGnome::GetProfileSpecificAppString() const { | 805 std::string NativeBackendGnome::GetProfileSpecificAppString() const { |
794 // Originally, the application string was always just "chrome" and used only | 806 // Originally, the application string was always just "chrome" and used only |
795 // so that we had *something* to search for since GNOME Keyring won't search | 807 // so that we had *something* to search for since GNOME Keyring won't search |
796 // for nothing. Now we use it to distinguish passwords for different profiles. | 808 // for nothing. Now we use it to distinguish passwords for different profiles. |
797 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); | 809 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); |
798 } | 810 } |
OLD | NEW |