| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/page_state_serialization.h" | 5 #include "content/common/page_state_serialization.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 double file_modification_time) { | 51 double file_modification_time) { |
| 52 ExplodedHttpBodyElement element; | 52 ExplodedHttpBodyElement element; |
| 53 element.type = WebKit::WebHTTPBody::Element::TypeFileSystemURL; | 53 element.type = WebKit::WebHTTPBody::Element::TypeFileSystemURL; |
| 54 element.filesystem_url = url; | 54 element.filesystem_url = url; |
| 55 element.file_start = file_start; | 55 element.file_start = file_start; |
| 56 element.file_length = file_length; | 56 element.file_length = file_length; |
| 57 element.file_modification_time = file_modification_time; | 57 element.file_modification_time = file_modification_time; |
| 58 http_body->elements.push_back(element); | 58 http_body->elements.push_back(element); |
| 59 } | 59 } |
| 60 | 60 |
| 61 #ifdef USE_BLOB_UUIDS | |
| 62 void AppendBlobToHttpBody(ExplodedHttpBody* http_body, | 61 void AppendBlobToHttpBody(ExplodedHttpBody* http_body, |
| 63 const std::string& uuid) { | 62 const std::string& uuid) { |
| 64 ExplodedHttpBodyElement element; | 63 ExplodedHttpBodyElement element; |
| 65 element.type = WebKit::WebHTTPBody::Element::TypeBlob; | 64 element.type = WebKit::WebHTTPBody::Element::TypeBlob; |
| 66 element.blob_uuid = uuid; | 65 element.blob_uuid = uuid; |
| 67 http_body->elements.push_back(element); | 66 http_body->elements.push_back(element); |
| 68 } | 67 } |
| 69 #else | |
| 70 void DeprecatedAppendBlobToHttpBody(ExplodedHttpBody* http_body, | |
| 71 const GURL& url) { | |
| 72 ExplodedHttpBodyElement element; | |
| 73 element.type = WebKit::WebHTTPBody::Element::TypeBlob; | |
| 74 element.deprecated_blob_url = url; | |
| 75 http_body->elements.push_back(element); | |
| 76 } | |
| 77 #endif | |
| 78 | 68 |
| 79 //---------------------------------------------------------------------------- | 69 //---------------------------------------------------------------------------- |
| 80 | 70 |
| 81 void AppendReferencedFilesFromHttpBody( | 71 void AppendReferencedFilesFromHttpBody( |
| 82 const std::vector<ExplodedHttpBodyElement>& elements, | 72 const std::vector<ExplodedHttpBodyElement>& elements, |
| 83 std::vector<base::NullableString16>* referenced_files) { | 73 std::vector<base::NullableString16>* referenced_files) { |
| 84 for (size_t i = 0; i < elements.size(); ++i) { | 74 for (size_t i = 0; i < elements.size(); ++i) { |
| 85 if (elements[i].type == WebKit::WebHTTPBody::Element::TypeFile) | 75 if (elements[i].type == WebKit::WebHTTPBody::Element::TypeFile) |
| 86 referenced_files->push_back(elements[i].file_path); | 76 referenced_files->push_back(elements[i].file_path); |
| 87 } | 77 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // 12: Adds support for contains_passwords in HTTP body | 185 // 12: Adds support for contains_passwords in HTTP body |
| 196 // 13: Adds support for URL (FileSystem URL) | 186 // 13: Adds support for URL (FileSystem URL) |
| 197 // 14: Adds list of referenced files, version written only for first item. | 187 // 14: Adds list of referenced files, version written only for first item. |
| 198 // 15: Removes a bunch of values we defined but never used. | 188 // 15: Removes a bunch of values we defined but never used. |
| 199 // 16: Switched from blob urls to blob uuids. | 189 // 16: Switched from blob urls to blob uuids. |
| 200 // | 190 // |
| 201 // NOTE: If the version is -1, then the pickle contains only a URL string. | 191 // NOTE: If the version is -1, then the pickle contains only a URL string. |
| 202 // See ReadPageState. | 192 // See ReadPageState. |
| 203 // | 193 // |
| 204 const int kMinVersion = 11; | 194 const int kMinVersion = 11; |
| 205 #ifdef USE_BLOB_UUIDS | |
| 206 // This is not used yet, if a version bump is needed in advance of | |
| 207 // this becoming used, bump both values by one and fixup the comment | |
| 208 // and change the test for '16' in ReadHttpBody(). | |
| 209 // -- michaeln | |
| 210 const int kCurrentVersion = 16; | 195 const int kCurrentVersion = 16; |
| 211 #else | |
| 212 const int kCurrentVersion = 15; | |
| 213 #endif | |
| 214 | 196 |
| 215 // A bunch of convenience functions to read/write to SerializeObjects. The | 197 // A bunch of convenience functions to read/write to SerializeObjects. The |
| 216 // de-serializers assume the input data will be in the correct format and fall | 198 // de-serializers assume the input data will be in the correct format and fall |
| 217 // back to returning safe defaults when not. | 199 // back to returning safe defaults when not. |
| 218 | 200 |
| 219 void WriteData(const void* data, int length, SerializeObject* obj) { | 201 void WriteData(const void* data, int length, SerializeObject* obj) { |
| 220 obj->pickle.WriteData(static_cast<const char*>(data), length); | 202 obj->pickle.WriteData(static_cast<const char*>(data), length); |
| 221 } | 203 } |
| 222 | 204 |
| 223 void ReadData(SerializeObject* obj, const void** data, int* length) { | 205 void ReadData(SerializeObject* obj, const void** data, int* length) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 WriteInteger64(element.file_length, obj); | 419 WriteInteger64(element.file_length, obj); |
| 438 WriteReal(element.file_modification_time, obj); | 420 WriteReal(element.file_modification_time, obj); |
| 439 } else if (element.type == | 421 } else if (element.type == |
| 440 WebKit::WebHTTPBody::Element::TypeFileSystemURL) { | 422 WebKit::WebHTTPBody::Element::TypeFileSystemURL) { |
| 441 WriteGURL(element.filesystem_url, obj); | 423 WriteGURL(element.filesystem_url, obj); |
| 442 WriteInteger64(element.file_start, obj); | 424 WriteInteger64(element.file_start, obj); |
| 443 WriteInteger64(element.file_length, obj); | 425 WriteInteger64(element.file_length, obj); |
| 444 WriteReal(element.file_modification_time, obj); | 426 WriteReal(element.file_modification_time, obj); |
| 445 } else { | 427 } else { |
| 446 DCHECK(element.type == WebKit::WebHTTPBody::Element::TypeBlob); | 428 DCHECK(element.type == WebKit::WebHTTPBody::Element::TypeBlob); |
| 447 #ifdef USE_BLOB_UUIDS | |
| 448 WriteStdString(element.blob_uuid, obj); | 429 WriteStdString(element.blob_uuid, obj); |
| 449 #else | |
| 450 WriteGURL(element.deprecated_blob_url, obj); | |
| 451 #endif | |
| 452 } | 430 } |
| 453 } | 431 } |
| 454 WriteInteger64(http_body.identifier, obj); | 432 WriteInteger64(http_body.identifier, obj); |
| 455 WriteBoolean(http_body.contains_passwords, obj); | 433 WriteBoolean(http_body.contains_passwords, obj); |
| 456 } | 434 } |
| 457 | 435 |
| 458 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { | 436 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { |
| 459 // An initial boolean indicates if we have an HTTP body. | 437 // An initial boolean indicates if we have an HTTP body. |
| 460 if (!ReadBoolean(obj)) | 438 if (!ReadBoolean(obj)) |
| 461 return; | 439 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 481 AppendFileRangeToHttpBody(http_body, file_path, file_start, file_length, | 459 AppendFileRangeToHttpBody(http_body, file_path, file_start, file_length, |
| 482 file_modification_time); | 460 file_modification_time); |
| 483 } else if (type == WebKit::WebHTTPBody::Element::TypeFileSystemURL) { | 461 } else if (type == WebKit::WebHTTPBody::Element::TypeFileSystemURL) { |
| 484 GURL url = ReadGURL(obj); | 462 GURL url = ReadGURL(obj); |
| 485 int64 file_start = ReadInteger64(obj); | 463 int64 file_start = ReadInteger64(obj); |
| 486 int64 file_length = ReadInteger64(obj); | 464 int64 file_length = ReadInteger64(obj); |
| 487 double file_modification_time = ReadReal(obj); | 465 double file_modification_time = ReadReal(obj); |
| 488 AppendURLRangeToHttpBody(http_body, url, file_start, file_length, | 466 AppendURLRangeToHttpBody(http_body, url, file_start, file_length, |
| 489 file_modification_time); | 467 file_modification_time); |
| 490 } else if (type == WebKit::WebHTTPBody::Element::TypeBlob) { | 468 } else if (type == WebKit::WebHTTPBody::Element::TypeBlob) { |
| 491 #ifdef USE_BLOB_UUIDS | |
| 492 if (obj->version >= 16) { | 469 if (obj->version >= 16) { |
| 493 std::string blob_uuid = ReadStdString(obj); | 470 std::string blob_uuid = ReadStdString(obj); |
| 494 AppendBlobToHttpBody(http_body, blob_uuid); | 471 AppendBlobToHttpBody(http_body, blob_uuid); |
| 495 } else { | 472 } else { |
| 496 ReadGURL(obj); // Skip the obsolete blob url value. | 473 ReadGURL(obj); // Skip the obsolete blob url value. |
| 497 } | 474 } |
| 498 #else | |
| 499 GURL blob_url = ReadGURL(obj); | |
| 500 DeprecatedAppendBlobToHttpBody(http_body, blob_url); | |
| 501 #endif | |
| 502 } | 475 } |
| 503 } | 476 } |
| 504 http_body->identifier = ReadInteger64(obj); | 477 http_body->identifier = ReadInteger64(obj); |
| 505 | 478 |
| 506 if (obj->version >= 12) | 479 if (obj->version >= 12) |
| 507 http_body->contains_passwords = ReadBoolean(obj); | 480 http_body->contains_passwords = ReadBoolean(obj); |
| 508 } | 481 } |
| 509 | 482 |
| 510 // Writes the ExplodedFrameState data into the SerializeObject object for | 483 // Writes the ExplodedFrameState data into the SerializeObject object for |
| 511 // serialization. | 484 // serialization. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 float device_scale_factor, | 697 float device_scale_factor, |
| 725 ExplodedPageState* exploded) { | 698 ExplodedPageState* exploded) { |
| 726 g_device_scale_factor_for_testing = device_scale_factor; | 699 g_device_scale_factor_for_testing = device_scale_factor; |
| 727 bool rv = DecodePageState(encoded, exploded); | 700 bool rv = DecodePageState(encoded, exploded); |
| 728 g_device_scale_factor_for_testing = 0.0; | 701 g_device_scale_factor_for_testing = 0.0; |
| 729 return rv; | 702 return rv; |
| 730 } | 703 } |
| 731 #endif | 704 #endif |
| 732 | 705 |
| 733 } // namespace content | 706 } // namespace content |
| OLD | NEW |