| 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 "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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // This version checks and reads v1 and v2 correctly. | 61 // This version checks and reads v1 and v2 correctly. |
| 62 // 4: Adds support for storing FormData::identifier(). | 62 // 4: Adds support for storing FormData::identifier(). |
| 63 // 5: Adds support for empty FormData | 63 // 5: Adds support for empty FormData |
| 64 // 6: Adds support for documentSequenceNumbers | 64 // 6: Adds support for documentSequenceNumbers |
| 65 // 7: Adds support for stateObject | 65 // 7: Adds support for stateObject |
| 66 // 8: Adds support for file range and modification time | 66 // 8: Adds support for file range and modification time |
| 67 // 9: Adds support for itemSequenceNumbers | 67 // 9: Adds support for itemSequenceNumbers |
| 68 // 10: Adds support for blob | 68 // 10: Adds support for blob |
| 69 // 11: Adds support for pageScaleFactor | 69 // 11: Adds support for pageScaleFactor |
| 70 // 12: Adds support for hasPasswordData in HTTP body | 70 // 12: Adds support for hasPasswordData in HTTP body |
| 71 // 13: Adds support for URL (FileSystem URL) |
| 71 // Should be const, but unit tests may modify it. | 72 // Should be const, but unit tests may modify it. |
| 72 // | 73 // |
| 73 // NOTE: If the version is -1, then the pickle contains only a URL string. | 74 // NOTE: If the version is -1, then the pickle contains only a URL string. |
| 74 // See CreateHistoryStateForURL. | 75 // See CreateHistoryStateForURL. |
| 75 // | 76 // |
| 76 int kVersion = 12; | 77 int kVersion = 13; |
| 77 | 78 |
| 78 // A bunch of convenience functions to read/write to SerializeObjects. | 79 // A bunch of convenience functions to read/write to SerializeObjects. |
| 79 // The serializers assume the input data is in the correct format and so does | 80 // The serializers assume the input data is in the correct format and so does |
| 80 // no error checking. | 81 // no error checking. |
| 81 inline void WriteData(const void* data, int length, SerializeObject* obj) { | 82 inline void WriteData(const void* data, int length, SerializeObject* obj) { |
| 82 obj->pickle.WriteData(static_cast<const char*>(data), length); | 83 obj->pickle.WriteData(static_cast<const char*>(data), length); |
| 83 } | 84 } |
| 84 | 85 |
| 85 inline void ReadData(const SerializeObject* obj, const void** data, | 86 inline void ReadData(const SerializeObject* obj, const void** data, |
| 86 int* length) { | 87 int* length) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 for (size_t i = 0; http_body.elementAt(i, element); ++i) { | 252 for (size_t i = 0; http_body.elementAt(i, element); ++i) { |
| 252 WriteInteger(element.type, obj); | 253 WriteInteger(element.type, obj); |
| 253 if (element.type == WebHTTPBody::Element::TypeData) { | 254 if (element.type == WebHTTPBody::Element::TypeData) { |
| 254 WriteData(element.data.data(), static_cast<int>(element.data.size()), | 255 WriteData(element.data.data(), static_cast<int>(element.data.size()), |
| 255 obj); | 256 obj); |
| 256 } else if (element.type == WebHTTPBody::Element::TypeFile) { | 257 } else if (element.type == WebHTTPBody::Element::TypeFile) { |
| 257 WriteString(element.filePath, obj); | 258 WriteString(element.filePath, obj); |
| 258 WriteInteger64(element.fileStart, obj); | 259 WriteInteger64(element.fileStart, obj); |
| 259 WriteInteger64(element.fileLength, obj); | 260 WriteInteger64(element.fileLength, obj); |
| 260 WriteReal(element.modificationTime, obj); | 261 WriteReal(element.modificationTime, obj); |
| 262 } else if (element.type == WebHTTPBody::Element::TypeURL) { |
| 263 WriteGURL(element.url, obj); |
| 264 WriteInteger64(element.fileStart, obj); |
| 265 WriteInteger64(element.fileLength, obj); |
| 266 WriteReal(element.modificationTime, obj); |
| 261 } else { | 267 } else { |
| 262 WriteGURL(element.blobURL, obj); | 268 WriteGURL(element.url, obj); |
| 263 } | 269 } |
| 264 } | 270 } |
| 265 WriteInteger64(http_body.identifier(), obj); | 271 WriteInteger64(http_body.identifier(), obj); |
| 266 WriteBoolean(http_body.containsPasswordData(), obj); | 272 WriteBoolean(http_body.containsPasswordData(), obj); |
| 267 } | 273 } |
| 268 | 274 |
| 269 WebHTTPBody ReadFormData(const SerializeObject* obj) { | 275 WebHTTPBody ReadFormData(const SerializeObject* obj) { |
| 270 // In newer versions, an initial boolean indicates if we have form data. | 276 // In newer versions, an initial boolean indicates if we have form data. |
| 271 if (obj->version >= 5 && !ReadBoolean(obj)) | 277 if (obj->version >= 5 && !ReadBoolean(obj)) |
| 272 return WebHTTPBody(); | 278 return WebHTTPBody(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 292 long long file_start = 0; | 298 long long file_start = 0; |
| 293 long long file_length = -1; | 299 long long file_length = -1; |
| 294 double modification_time = 0.0; | 300 double modification_time = 0.0; |
| 295 if (obj->version >= 8) { | 301 if (obj->version >= 8) { |
| 296 file_start = ReadInteger64(obj); | 302 file_start = ReadInteger64(obj); |
| 297 file_length = ReadInteger64(obj); | 303 file_length = ReadInteger64(obj); |
| 298 modification_time = ReadReal(obj); | 304 modification_time = ReadReal(obj); |
| 299 } | 305 } |
| 300 http_body.appendFileRange(file_path, file_start, file_length, | 306 http_body.appendFileRange(file_path, file_start, file_length, |
| 301 modification_time); | 307 modification_time); |
| 308 } else if (type == WebHTTPBody::Element::TypeURL) { |
| 309 GURL url = ReadGURL(obj); |
| 310 long long file_start = 0; |
| 311 long long file_length = -1; |
| 312 double modification_time = 0.0; |
| 313 file_start = ReadInteger64(obj); |
| 314 file_length = ReadInteger64(obj); |
| 315 modification_time = ReadReal(obj); |
| 316 http_body.appendURLRange(url, file_start, file_length, |
| 317 modification_time); |
| 302 } else if (obj->version >= 10) { | 318 } else if (obj->version >= 10) { |
| 303 GURL blob_url = ReadGURL(obj); | 319 GURL blob_url = ReadGURL(obj); |
| 304 http_body.appendBlob(blob_url); | 320 http_body.appendBlob(blob_url); |
| 305 } | 321 } |
| 306 } | 322 } |
| 307 if (obj->version >= 4) | 323 if (obj->version >= 4) |
| 308 http_body.setIdentifier(ReadInteger64(obj)); | 324 http_body.setIdentifier(ReadInteger64(obj)); |
| 309 | 325 |
| 310 if (obj->version >= 12) | 326 if (obj->version >= 12) |
| 311 http_body.setContainsPasswordData(ReadBoolean(obj)); | 327 http_body.setContainsPasswordData(ReadBoolean(obj)); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 *serialized_item = obj.GetAsString(); | 593 *serialized_item = obj.GetAsString(); |
| 578 | 594 |
| 579 kVersion = real_version; | 595 kVersion = real_version; |
| 580 } | 596 } |
| 581 | 597 |
| 582 int HistoryItemCurrentVersion() { | 598 int HistoryItemCurrentVersion() { |
| 583 return kVersion; | 599 return kVersion; |
| 584 } | 600 } |
| 585 | 601 |
| 586 } // namespace webkit_glue | 602 } // namespace webkit_glue |
| OLD | NEW |