| 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_kwallet_x.h" | 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 22 #include "chrome/grit/chromium_strings.h" | 22 #include "chrome/grit/chromium_strings.h" |
| 23 #include "components/autofill/core/common/password_form.h" | 23 #include "components/autofill/core/common/password_form.h" |
| 24 #include "components/password_manager/core/browser/password_manager_util.h" | 24 #include "components/password_manager/core/browser/password_manager_util.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "dbus/bus.h" | 26 #include "dbus/bus.h" |
| 27 #include "dbus/message.h" | 27 #include "dbus/message.h" |
| 28 #include "dbus/object_path.h" | 28 #include "dbus/object_path.h" |
| 29 #include "dbus/object_proxy.h" | 29 #include "dbus/object_proxy.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "url/origin.h" |
| 31 | 32 |
| 32 using autofill::PasswordForm; | 33 using autofill::PasswordForm; |
| 33 using content::BrowserThread; | 34 using content::BrowserThread; |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // In case the fields in the pickle ever change, version them so we can try to | 38 // In case the fields in the pickle ever change, version them so we can try to |
| 38 // read old pickles. (Note: do not eat old pickles past the expiration date.) | 39 // read old pickles. (Note: do not eat old pickles past the expiration date.) |
| 39 const int kPickleVersion = 7; | 40 const int kPickleVersion = 7; |
| 40 | 41 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (!iter->ReadString(&url_string)) { | 78 if (!iter->ReadString(&url_string)) { |
| 78 if (!warn_only) | 79 if (!warn_only) |
| 79 LOG(ERROR) << "Failed to deserialize URL."; | 80 LOG(ERROR) << "Failed to deserialize URL."; |
| 80 *url = GURL(); | 81 *url = GURL(); |
| 81 return false; | 82 return false; |
| 82 } | 83 } |
| 83 *url = GURL(url_string); | 84 *url = GURL(url_string); |
| 84 return true; | 85 return true; |
| 85 } | 86 } |
| 86 | 87 |
| 88 // Convenience function to read a url::Origin from a Pickle. Assumes the origin |
| 89 // has been written as a UTF-8 string. Returns true on success. |
| 90 bool ReadOrigin(base::PickleIterator* iter, |
| 91 bool warn_only, |
| 92 url::Origin* origin) { |
| 93 std::string origin_string; |
| 94 if (!iter->ReadString(&origin_string)) { |
| 95 if (!warn_only) |
| 96 LOG(ERROR) << "Failed to deserialize Origin."; |
| 97 *origin = url::Origin(); |
| 98 return false; |
| 99 } |
| 100 *origin = url::Origin(GURL(origin_string)); |
| 101 return true; |
| 102 } |
| 103 |
| 87 void LogDeserializationWarning(int version, | 104 void LogDeserializationWarning(int version, |
| 88 std::string signon_realm, | 105 std::string signon_realm, |
| 89 bool warn_only) { | 106 bool warn_only) { |
| 90 if (warn_only) { | 107 if (warn_only) { |
| 91 LOG(WARNING) << "Failed to deserialize version " << version | 108 LOG(WARNING) << "Failed to deserialize version " << version |
| 92 << " KWallet entry (realm: " << signon_realm | 109 << " KWallet entry (realm: " << signon_realm |
| 93 << ") with native architecture size; will try alternate " | 110 << ") with native architecture size; will try alternate " |
| 94 << "size."; | 111 << "size."; |
| 95 } else { | 112 } else { |
| 96 LOG(ERROR) << "Failed to deserialize version " << version | 113 LOG(ERROR) << "Failed to deserialize version " << version |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (!iter.ReadInt64(&date_synced)) { | 209 if (!iter.ReadInt64(&date_synced)) { |
| 193 LogDeserializationWarning(version, signon_realm, false); | 210 LogDeserializationWarning(version, signon_realm, false); |
| 194 return false; | 211 return false; |
| 195 } | 212 } |
| 196 form->date_synced = base::Time::FromInternalValue(date_synced); | 213 form->date_synced = base::Time::FromInternalValue(date_synced); |
| 197 } | 214 } |
| 198 | 215 |
| 199 if (version > 3) { | 216 if (version > 3) { |
| 200 if (!iter.ReadString16(&form->display_name) || | 217 if (!iter.ReadString16(&form->display_name) || |
| 201 !ReadGURL(&iter, warn_only, &form->icon_url) || | 218 !ReadGURL(&iter, warn_only, &form->icon_url) || |
| 202 !ReadGURL(&iter, warn_only, &form->federation_url) || | 219 !ReadOrigin(&iter, warn_only, &form->federation_origin) || |
| 203 !iter.ReadBool(&form->skip_zero_click)) { | 220 !iter.ReadBool(&form->skip_zero_click)) { |
| 204 LogDeserializationWarning(version, signon_realm, false); | 221 LogDeserializationWarning(version, signon_realm, false); |
| 205 return false; | 222 return false; |
| 206 } | 223 } |
| 207 } | 224 } |
| 208 | 225 |
| 209 if (version > 4) { | 226 if (version > 4) { |
| 210 form->date_created = base::Time::FromInternalValue(date_created); | 227 form->date_created = base::Time::FromInternalValue(date_created); |
| 211 } else { | 228 } else { |
| 212 form->date_created = base::Time::FromTimeT(date_created); | 229 form->date_created = base::Time::FromTimeT(date_created); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 pickle->WriteBool(form->ssl_valid); | 268 pickle->WriteBool(form->ssl_valid); |
| 252 pickle->WriteBool(form->preferred); | 269 pickle->WriteBool(form->preferred); |
| 253 pickle->WriteBool(form->blacklisted_by_user); | 270 pickle->WriteBool(form->blacklisted_by_user); |
| 254 pickle->WriteInt64(form->date_created.ToInternalValue()); | 271 pickle->WriteInt64(form->date_created.ToInternalValue()); |
| 255 pickle->WriteInt(form->type); | 272 pickle->WriteInt(form->type); |
| 256 pickle->WriteInt(form->times_used); | 273 pickle->WriteInt(form->times_used); |
| 257 autofill::SerializeFormData(form->form_data, pickle); | 274 autofill::SerializeFormData(form->form_data, pickle); |
| 258 pickle->WriteInt64(form->date_synced.ToInternalValue()); | 275 pickle->WriteInt64(form->date_synced.ToInternalValue()); |
| 259 pickle->WriteString16(form->display_name); | 276 pickle->WriteString16(form->display_name); |
| 260 pickle->WriteString(form->icon_url.spec()); | 277 pickle->WriteString(form->icon_url.spec()); |
| 261 pickle->WriteString(form->federation_url.spec()); | 278 pickle->WriteString(form->federation_origin.Serialize()); |
| 262 pickle->WriteBool(form->skip_zero_click); | 279 pickle->WriteBool(form->skip_zero_click); |
| 263 pickle->WriteInt(form->generation_upload_status); | 280 pickle->WriteInt(form->generation_upload_status); |
| 264 } | 281 } |
| 265 } | 282 } |
| 266 | 283 |
| 267 // Moves the content of |second| to the end of |first|. | 284 // Moves the content of |second| to the end of |first|. |
| 268 void AppendSecondToFirst(ScopedVector<autofill::PasswordForm>* first, | 285 void AppendSecondToFirst(ScopedVector<autofill::PasswordForm>* first, |
| 269 ScopedVector<autofill::PasswordForm> second) { | 286 ScopedVector<autofill::PasswordForm> second) { |
| 270 first->reserve(first->size() + second.size()); | 287 first->reserve(first->size() + second.size()); |
| 271 first->insert(first->end(), second.begin(), second.end()); | 288 first->insert(first->end(), second.begin(), second.end()); |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 } | 1071 } |
| 1055 | 1072 |
| 1056 return handle; | 1073 return handle; |
| 1057 } | 1074 } |
| 1058 | 1075 |
| 1059 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { | 1076 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { |
| 1060 // Originally, the folder name was always just "Chrome Form Data". | 1077 // Originally, the folder name was always just "Chrome Form Data". |
| 1061 // Now we use it to distinguish passwords for different profiles. | 1078 // Now we use it to distinguish passwords for different profiles. |
| 1062 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); | 1079 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); |
| 1063 } | 1080 } |
| OLD | NEW |