Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/glue/glue_serialize.h" | 5 #include "webkit/glue/glue_serialize.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 if (obj->version >= 4) | 289 if (obj->version >= 4) |
| 290 http_body.setIdentifier(ReadInteger64(obj)); | 290 http_body.setIdentifier(ReadInteger64(obj)); |
| 291 | 291 |
| 292 return http_body; | 292 return http_body; |
| 293 } | 293 } |
| 294 | 294 |
| 295 // Writes the HistoryItem data into the SerializeObject object for | 295 // Writes the HistoryItem data into the SerializeObject object for |
| 296 // serialization. | 296 // serialization. |
| 297 void WriteHistoryItem( | 297 void WriteHistoryItem( |
| 298 const WebHistoryItem& item, SerializeObject* obj) { | 298 const WebHistoryItem& item, SerializeObject* obj) { |
| 299 // If the history item is not valid, then just return. | |
| 300 if (item.IsNull()) | |
| 301 return; | |
| 302 | |
| 299 // WARNING: This data may be persisted for later use. As such, care must be | 303 // WARNING: This data may be persisted for later use. As such, care must be |
| 300 // taken when changing the serialized format. If a new field needs to be | 304 // taken when changing the serialized format. If a new field needs to be |
| 301 // written, only adding at the end will make it easier to deal with loading | 305 // written, only adding at the end will make it easier to deal with loading |
| 302 // older versions. Similarly, this should NOT save fields with sensitive | 306 // older versions. Similarly, this should NOT save fields with sensitive |
| 303 // data, such as password fields. | 307 // data, such as password fields. |
| 304 WriteInteger(kVersion, obj); | 308 WriteInteger(kVersion, obj); |
| 305 WriteString(item.urlString(), obj); | 309 WriteString(item.urlString(), obj); |
| 306 WriteString(item.originalURLString(), obj); | 310 WriteString(item.originalURLString(), obj); |
| 307 WriteString(item.target(), obj); | 311 WriteString(item.target(), obj); |
| 308 WriteString(item.parent(), obj); | 312 WriteString(item.parent(), obj); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 321 WriteInteger64(item.itemSequenceNumber(), obj); | 325 WriteInteger64(item.itemSequenceNumber(), obj); |
| 322 if (kVersion >= 6) | 326 if (kVersion >= 6) |
| 323 WriteInteger64(item.documentSequenceNumber(), obj); | 327 WriteInteger64(item.documentSequenceNumber(), obj); |
| 324 if (kVersion >= 7) { | 328 if (kVersion >= 7) { |
| 325 bool has_state_object = !item.stateObject().isNull(); | 329 bool has_state_object = !item.stateObject().isNull(); |
| 326 WriteBoolean(has_state_object, obj); | 330 WriteBoolean(has_state_object, obj); |
| 327 if (has_state_object) | 331 if (has_state_object) |
| 328 WriteString(item.stateObject().toString(), obj); | 332 WriteString(item.stateObject().toString(), obj); |
| 329 } | 333 } |
| 330 | 334 |
| 335 WriteFormData(item.httpBody(), obj); | |
| 336 WriteString(item.httpContentType(), obj); | |
| 337 | |
| 331 // Yes, the referrer is written twice. This is for backwards | 338 // Yes, the referrer is written twice. This is for backwards |
| 332 // compatibility with the format. | 339 // compatibility with the format. |
| 333 WriteFormData(item.httpBody(), obj); | |
| 334 WriteString(item.httpContentType(), obj); | |
| 335 WriteString(item.referrer(), obj); | 340 WriteString(item.referrer(), obj); |
| 336 | 341 |
| 337 // Subitems | 342 // Write subitems, making sure that we skip any NULL items (which |
| 338 const WebVector<WebHistoryItem>& children = item.children(); | 343 // can occur with corrupted input), and adjust the item count to |
| 339 WriteInteger(static_cast<int>(children.size()), obj); | 344 // match. |
| 340 for (size_t i = 0, c = children.size(); i < c; ++i) | 345 const WebVector<WebHistoryItem>& child_vector = item.children(); |
| 341 WriteHistoryItem(children[i], obj); | 346 int real_size = static_cast<int>(child_vector.size()); |
| 347 for (size_t i = 0, size = child_vector.size(); i < size; ++i) { | |
| 348 if (child_vector[i].IsNull()) | |
| 349 real_size--; | |
| 350 } | |
| 351 | |
| 352 if (real_size > 0) { | |
| 353 WriteInteger(real_size, obj); | |
|
sky
2011/05/18 22:39:07
Move this to before the if and nuke the else.
| |
| 354 for (size_t i = 0, size = child_vector.size(); i < size; ++i) { | |
| 355 if (!child_vector[i].IsNull()) | |
| 356 WriteHistoryItem(child_vector[i], obj); | |
| 357 } | |
| 358 } else { | |
| 359 WriteInteger(0, obj); | |
| 360 } | |
| 342 } | 361 } |
| 343 | 362 |
| 344 // Creates a new HistoryItem tree based on the serialized string. | 363 // Creates a new HistoryItem tree based on the serialized string. |
| 345 // Assumes the data is in the format returned by WriteHistoryItem. | 364 // Assumes the data is in the format returned by WriteHistoryItem. |
| 346 WebHistoryItem ReadHistoryItem( | 365 WebHistoryItem ReadHistoryItem( |
| 347 const SerializeObject* obj, | 366 const SerializeObject* obj, |
| 348 bool include_form_data, | 367 bool include_form_data, |
| 349 bool include_scroll_offset) { | 368 bool include_scroll_offset) { |
| 350 // See note in WriteHistoryItem. on this. | 369 // See note in WriteHistoryItem. on this. |
| 351 obj->version = ReadInteger(obj); | 370 obj->version = ReadInteger(obj); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 kVersion = version; | 517 kVersion = version; |
| 499 | 518 |
| 500 SerializeObject obj; | 519 SerializeObject obj; |
| 501 WriteHistoryItem(item, &obj); | 520 WriteHistoryItem(item, &obj); |
| 502 *serialized_item = obj.GetAsString(); | 521 *serialized_item = obj.GetAsString(); |
| 503 | 522 |
| 504 kVersion = real_version; | 523 kVersion = real_version; |
| 505 } | 524 } |
| 506 | 525 |
| 507 } // namespace webkit_glue | 526 } // namespace webkit_glue |
| OLD | NEW |