| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 26 float g_device_scale_factor_for_testing = 0.0; | 26 float g_device_scale_factor_for_testing = 0.0; |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 //----------------------------------------------------------------------------- | 29 //----------------------------------------------------------------------------- |
| 30 | 30 |
| 31 void AppendDataToHttpBody(ExplodedHttpBody* http_body, const char* data, | 31 void AppendDataToHttpBody(ExplodedHttpBody* http_body, const char* data, |
| 32 int data_length) { | 32 int data_length) { |
| 33 ExplodedHttpBodyElement element; | 33 http_body->request_body->AppendBytes(data, data_length); |
| 34 element.SetToBytes(data, data_length); | |
| 35 http_body->elements.push_back(element); | |
| 36 } | 34 } |
| 37 | 35 |
| 38 void AppendFileRangeToHttpBody(ExplodedHttpBody* http_body, | 36 void AppendFileRangeToHttpBody(ExplodedHttpBody* http_body, |
| 39 const base::NullableString16& file_path, | 37 const base::NullableString16& file_path, |
| 40 int file_start, | 38 int file_start, |
| 41 int file_length, | 39 int file_length, |
| 42 double file_modification_time) { | 40 double file_modification_time) { |
| 43 ExplodedHttpBodyElement element; | 41 http_body->request_body->AppendFileRange( |
| 44 element.SetToFilePathRange( | |
| 45 base::FilePath::FromUTF16Unsafe(file_path.string()), | 42 base::FilePath::FromUTF16Unsafe(file_path.string()), |
| 46 static_cast<uint64_t>(file_start), static_cast<uint64_t>(file_length), | 43 static_cast<uint64_t>(file_start), static_cast<uint64_t>(file_length), |
| 47 base::Time::FromDoubleT(file_modification_time)); | 44 base::Time::FromDoubleT(file_modification_time)); |
| 48 http_body->elements.push_back(element); | |
| 49 } | 45 } |
| 50 | 46 |
| 51 void AppendURLRangeToHttpBody(ExplodedHttpBody* http_body, | 47 void AppendURLRangeToHttpBody(ExplodedHttpBody* http_body, |
| 52 const GURL& url, | 48 const GURL& url, |
| 53 int file_start, | 49 int file_start, |
| 54 int file_length, | 50 int file_length, |
| 55 double file_modification_time) { | 51 double file_modification_time) { |
| 56 ExplodedHttpBodyElement element; | 52 http_body->request_body->AppendFileSystemFileRange( |
| 57 element.SetToFileSystemUrlRange( | |
| 58 url, static_cast<uint64_t>(file_start), | 53 url, static_cast<uint64_t>(file_start), |
| 59 static_cast<uint64_t>(file_length), | 54 static_cast<uint64_t>(file_length), |
| 60 base::Time::FromDoubleT(file_modification_time)); | 55 base::Time::FromDoubleT(file_modification_time)); |
| 61 http_body->elements.push_back(element); | |
| 62 } | 56 } |
| 63 | 57 |
| 64 void AppendBlobToHttpBody(ExplodedHttpBody* http_body, | 58 void AppendBlobToHttpBody(ExplodedHttpBody* http_body, |
| 65 const std::string& uuid) { | 59 const std::string& uuid) { |
| 66 ExplodedHttpBodyElement element; | 60 http_body->request_body->AppendBlob(uuid); |
| 67 element.SetToBlob(uuid); | |
| 68 http_body->elements.push_back(element); | |
| 69 } | 61 } |
| 70 | 62 |
| 71 //---------------------------------------------------------------------------- | 63 //---------------------------------------------------------------------------- |
| 72 | 64 |
| 73 void AppendReferencedFilesFromHttpBody( | 65 void AppendReferencedFilesFromHttpBody( |
| 74 const std::vector<ExplodedHttpBodyElement>& elements, | 66 const std::vector<ResourceRequestBody::Element>& elements, |
| 75 std::vector<base::NullableString16>* referenced_files) { | 67 std::vector<base::NullableString16>* referenced_files) { |
| 76 for (size_t i = 0; i < elements.size(); ++i) { | 68 for (size_t i = 0; i < elements.size(); ++i) { |
| 77 if (elements[i].type() == ExplodedHttpBodyElement::TYPE_FILE) | 69 if (elements[i].type() == ResourceRequestBody::Element::TYPE_FILE) |
| 78 referenced_files->push_back( | 70 referenced_files->push_back( |
| 79 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false)); | 71 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false)); |
| 80 } | 72 } |
| 81 } | 73 } |
| 82 | 74 |
| 83 bool AppendReferencedFilesFromDocumentState( | 75 bool AppendReferencedFilesFromDocumentState( |
| 84 const std::vector<base::NullableString16>& document_state, | 76 const std::vector<base::NullableString16>& document_state, |
| 85 std::vector<base::NullableString16>* referenced_files) { | 77 std::vector<base::NullableString16>* referenced_files) { |
| 86 if (document_state.empty()) | 78 if (document_state.empty()) |
| 87 return true; | 79 return true; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 index += value_size; | 125 index += value_size; |
| 134 } | 126 } |
| 135 } | 127 } |
| 136 | 128 |
| 137 return true; | 129 return true; |
| 138 } | 130 } |
| 139 | 131 |
| 140 bool RecursivelyAppendReferencedFiles( | 132 bool RecursivelyAppendReferencedFiles( |
| 141 const ExplodedFrameState& frame_state, | 133 const ExplodedFrameState& frame_state, |
| 142 std::vector<base::NullableString16>* referenced_files) { | 134 std::vector<base::NullableString16>* referenced_files) { |
| 143 if (!frame_state.http_body.is_null) { | 135 if (frame_state.http_body.request_body != nullptr) { |
| 144 AppendReferencedFilesFromHttpBody(frame_state.http_body.elements, | 136 AppendReferencedFilesFromHttpBody( |
| 145 referenced_files); | 137 *frame_state.http_body.request_body->elements(), referenced_files); |
| 146 } | 138 } |
| 147 | 139 |
| 148 if (!AppendReferencedFilesFromDocumentState(frame_state.document_state, | 140 if (!AppendReferencedFilesFromDocumentState(frame_state.document_state, |
| 149 referenced_files)) | 141 referenced_files)) |
| 150 return false; | 142 return false; |
| 151 | 143 |
| 152 for (size_t i = 0; i < frame_state.children.size(); ++i) { | 144 for (size_t i = 0; i < frame_state.children.size(); ++i) { |
| 153 if (!RecursivelyAppendReferencedFiles(frame_state.children[i], | 145 if (!RecursivelyAppendReferencedFiles(frame_state.children[i], |
| 154 referenced_files)) | 146 referenced_files)) |
| 155 return false; | 147 return false; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 size_t num_elements = | 382 size_t num_elements = |
| 391 ReadAndValidateVectorSize(obj, sizeof(base::NullableString16)); | 383 ReadAndValidateVectorSize(obj, sizeof(base::NullableString16)); |
| 392 | 384 |
| 393 result->resize(num_elements); | 385 result->resize(num_elements); |
| 394 for (size_t i = 0; i < num_elements; ++i) | 386 for (size_t i = 0; i < num_elements; ++i) |
| 395 (*result)[i] = ReadString(obj); | 387 (*result)[i] = ReadString(obj); |
| 396 } | 388 } |
| 397 | 389 |
| 398 // Writes an ExplodedHttpBody object into a SerializeObject for serialization. | 390 // Writes an ExplodedHttpBody object into a SerializeObject for serialization. |
| 399 void WriteHttpBody(const ExplodedHttpBody& http_body, SerializeObject* obj) { | 391 void WriteHttpBody(const ExplodedHttpBody& http_body, SerializeObject* obj) { |
| 400 WriteBoolean(!http_body.is_null, obj); | 392 bool is_null = http_body.request_body == nullptr; |
| 401 | 393 WriteBoolean(!is_null, obj); |
| 402 if (http_body.is_null) | 394 if (is_null) |
| 403 return; | 395 return; |
| 404 | 396 |
| 405 WriteAndValidateVectorSize(http_body.elements, obj); | 397 WriteAndValidateVectorSize(*http_body.request_body->elements(), obj); |
| 406 for (size_t i = 0; i < http_body.elements.size(); ++i) { | 398 for (const auto& element : *http_body.request_body->elements()) { |
| 407 const ExplodedHttpBodyElement& element = http_body.elements[i]; | |
| 408 switch (element.type()) { | 399 switch (element.type()) { |
| 409 case ExplodedHttpBodyElement::TYPE_BYTES: | 400 case ResourceRequestBody::Element::TYPE_BYTES: |
| 410 WriteInteger(blink::WebHTTPBody::Element::TypeData, obj); | 401 WriteInteger(blink::WebHTTPBody::Element::TypeData, obj); |
| 411 WriteData(element.bytes(), static_cast<int>(element.length()), obj); | 402 WriteData(element.bytes(), static_cast<int>(element.length()), obj); |
| 412 break; | 403 break; |
| 413 case ExplodedHttpBodyElement::TYPE_FILE: | 404 case ResourceRequestBody::Element::TYPE_FILE: |
| 414 WriteInteger(blink::WebHTTPBody::Element::TypeFile, obj); | 405 WriteInteger(blink::WebHTTPBody::Element::TypeFile, obj); |
| 415 WriteString( | 406 WriteString( |
| 416 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj); | 407 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj); |
| 417 WriteInteger64(static_cast<int64_t>(element.offset()), obj); | 408 WriteInteger64(static_cast<int64_t>(element.offset()), obj); |
| 418 WriteInteger64(static_cast<int64_t>(element.length()), obj); | 409 WriteInteger64(static_cast<int64_t>(element.length()), obj); |
| 419 WriteReal(element.expected_modification_time().ToDoubleT(), obj); | 410 WriteReal(element.expected_modification_time().ToDoubleT(), obj); |
| 420 break; | 411 break; |
| 421 case ExplodedHttpBodyElement::TYPE_FILE_FILESYSTEM: | 412 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: |
| 422 WriteInteger(blink::WebHTTPBody::Element::TypeFileSystemURL, obj); | 413 WriteInteger(blink::WebHTTPBody::Element::TypeFileSystemURL, obj); |
| 423 WriteGURL(element.filesystem_url(), obj); | 414 WriteGURL(element.filesystem_url(), obj); |
| 424 WriteInteger64(static_cast<int64_t>(element.offset()), obj); | 415 WriteInteger64(static_cast<int64_t>(element.offset()), obj); |
| 425 WriteInteger64(static_cast<int64_t>(element.length()), obj); | 416 WriteInteger64(static_cast<int64_t>(element.length()), obj); |
| 426 WriteReal(element.expected_modification_time().ToDoubleT(), obj); | 417 WriteReal(element.expected_modification_time().ToDoubleT(), obj); |
| 427 break; | 418 break; |
| 428 case ExplodedHttpBodyElement::TYPE_BLOB: | 419 case ResourceRequestBody::Element::TYPE_BLOB: |
| 429 WriteInteger(blink::WebHTTPBody::Element::TypeBlob, obj); | 420 WriteInteger(blink::WebHTTPBody::Element::TypeBlob, obj); |
| 430 WriteStdString(element.blob_uuid(), obj); | 421 WriteStdString(element.blob_uuid(), obj); |
| 431 break; | 422 break; |
| 432 case ExplodedHttpBodyElement::TYPE_BYTES_DESCRIPTION: | 423 case ResourceRequestBody::Element::TYPE_BYTES_DESCRIPTION: |
| 433 case ExplodedHttpBodyElement::TYPE_DISK_CACHE_ENTRY: | 424 case ResourceRequestBody::Element::TYPE_DISK_CACHE_ENTRY: |
| 434 default: | 425 default: |
| 435 NOTREACHED(); | 426 NOTREACHED(); |
| 436 continue; | 427 continue; |
| 437 } | 428 } |
| 438 } | 429 } |
| 439 WriteInteger64(http_body.identifier, obj); | 430 WriteInteger64(http_body.request_body->identifier(), obj); |
| 440 WriteBoolean(http_body.contains_passwords, obj); | 431 WriteBoolean(http_body.contains_passwords, obj); |
| 441 } | 432 } |
| 442 | 433 |
| 443 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { | 434 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { |
| 444 // An initial boolean indicates if we have an HTTP body. | 435 // An initial boolean indicates if we have an HTTP body. |
| 445 if (!ReadBoolean(obj)) | 436 if (!ReadBoolean(obj)) |
| 446 return; | 437 return; |
| 447 http_body->is_null = false; | |
| 448 | 438 |
| 439 http_body->request_body = new ResourceRequestBody(); |
| 449 int num_elements = ReadInteger(obj); | 440 int num_elements = ReadInteger(obj); |
| 450 | |
| 451 for (int i = 0; i < num_elements; ++i) { | 441 for (int i = 0; i < num_elements; ++i) { |
| 452 int type = ReadInteger(obj); | 442 int type = ReadInteger(obj); |
| 453 if (type == blink::WebHTTPBody::Element::TypeData) { | 443 if (type == blink::WebHTTPBody::Element::TypeData) { |
| 454 const void* data; | 444 const void* data; |
| 455 int length = -1; | 445 int length = -1; |
| 456 ReadData(obj, &data, &length); | 446 ReadData(obj, &data, &length); |
| 457 if (length >= 0) { | 447 if (length >= 0) { |
| 458 AppendDataToHttpBody(http_body, static_cast<const char*>(data), | 448 AppendDataToHttpBody(http_body, static_cast<const char*>(data), |
| 459 length); | 449 length); |
| 460 } | 450 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 474 file_modification_time); | 464 file_modification_time); |
| 475 } else if (type == blink::WebHTTPBody::Element::TypeBlob) { | 465 } else if (type == blink::WebHTTPBody::Element::TypeBlob) { |
| 476 if (obj->version >= 16) { | 466 if (obj->version >= 16) { |
| 477 std::string blob_uuid = ReadStdString(obj); | 467 std::string blob_uuid = ReadStdString(obj); |
| 478 AppendBlobToHttpBody(http_body, blob_uuid); | 468 AppendBlobToHttpBody(http_body, blob_uuid); |
| 479 } else { | 469 } else { |
| 480 ReadGURL(obj); // Skip the obsolete blob url value. | 470 ReadGURL(obj); // Skip the obsolete blob url value. |
| 481 } | 471 } |
| 482 } | 472 } |
| 483 } | 473 } |
| 484 http_body->identifier = ReadInteger64(obj); | 474 http_body->request_body->set_identifier(ReadInteger64(obj)); |
| 485 | 475 |
| 486 if (obj->version >= 12) | 476 if (obj->version >= 12) |
| 487 http_body->contains_passwords = ReadBoolean(obj); | 477 http_body->contains_passwords = ReadBoolean(obj); |
| 488 } | 478 } |
| 489 | 479 |
| 490 // Writes the ExplodedFrameState data into the SerializeObject object for | 480 // Writes the ExplodedFrameState data into the SerializeObject object for |
| 491 // serialization. | 481 // serialization. |
| 492 void WriteFrameState( | 482 void WriteFrameState( |
| 493 const ExplodedFrameState& state, SerializeObject* obj, bool is_top) { | 483 const ExplodedFrameState& state, SerializeObject* obj, bool is_top) { |
| 494 // WARNING: This data may be persisted for later use. As such, care must be | 484 // WARNING: This data may be persisted for later use. As such, care must be |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 659 |
| 670 // De-dupe | 660 // De-dupe |
| 671 state->referenced_files.erase( | 661 state->referenced_files.erase( |
| 672 std::unique(state->referenced_files.begin(), | 662 std::unique(state->referenced_files.begin(), |
| 673 state->referenced_files.end()), | 663 state->referenced_files.end()), |
| 674 state->referenced_files.end()); | 664 state->referenced_files.end()); |
| 675 } | 665 } |
| 676 | 666 |
| 677 } // namespace | 667 } // namespace |
| 678 | 668 |
| 679 ExplodedHttpBody::ExplodedHttpBody() | 669 ExplodedHttpBody::ExplodedHttpBody() : contains_passwords(false) {} |
| 680 : identifier(0), | |
| 681 contains_passwords(false), | |
| 682 is_null(true) { | |
| 683 } | |
| 684 | 670 |
| 685 ExplodedHttpBody::~ExplodedHttpBody() { | 671 ExplodedHttpBody::~ExplodedHttpBody() { |
| 686 } | 672 } |
| 687 | 673 |
| 688 ExplodedFrameState::ExplodedFrameState() | 674 ExplodedFrameState::ExplodedFrameState() |
| 689 : scroll_restoration_type(blink::WebHistoryScrollRestorationAuto), | 675 : scroll_restoration_type(blink::WebHistoryScrollRestorationAuto), |
| 690 item_sequence_number(0), | 676 item_sequence_number(0), |
| 691 document_sequence_number(0), | 677 document_sequence_number(0), |
| 692 page_scale_factor(0.0), | 678 page_scale_factor(0.0), |
| 693 referrer_policy(blink::WebReferrerPolicyDefault) { | 679 referrer_policy(blink::WebReferrerPolicyDefault) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 } | 726 } |
| 741 | 727 |
| 742 bool EncodePageState(const ExplodedPageState& exploded, std::string* encoded) { | 728 bool EncodePageState(const ExplodedPageState& exploded, std::string* encoded) { |
| 743 SerializeObject obj; | 729 SerializeObject obj; |
| 744 obj.version = kCurrentVersion; | 730 obj.version = kCurrentVersion; |
| 745 WritePageState(exploded, &obj); | 731 WritePageState(exploded, &obj); |
| 746 *encoded = obj.GetAsString(); | 732 *encoded = obj.GetAsString(); |
| 747 return true; | 733 return true; |
| 748 } | 734 } |
| 749 | 735 |
| 750 bool GeneratePostData(const ExplodedHttpBody& exploded, | |
| 751 ResourceRequestBody* http_body) { | |
| 752 if (exploded.is_null) | |
| 753 return false; | |
| 754 | |
| 755 http_body->set_identifier(exploded.identifier); | |
| 756 for (auto element : exploded.elements) | |
| 757 http_body->elements_mutable()->push_back(element); | |
| 758 | |
| 759 return true; | |
| 760 } | |
| 761 | |
| 762 #if defined(OS_ANDROID) | 736 #if defined(OS_ANDROID) |
| 763 bool DecodePageStateWithDeviceScaleFactorForTesting( | 737 bool DecodePageStateWithDeviceScaleFactorForTesting( |
| 764 const std::string& encoded, | 738 const std::string& encoded, |
| 765 float device_scale_factor, | 739 float device_scale_factor, |
| 766 ExplodedPageState* exploded) { | 740 ExplodedPageState* exploded) { |
| 767 g_device_scale_factor_for_testing = device_scale_factor; | 741 g_device_scale_factor_for_testing = device_scale_factor; |
| 768 bool rv = DecodePageState(encoded, exploded); | 742 bool rv = DecodePageState(encoded, exploded); |
| 769 g_device_scale_factor_for_testing = 0.0; | 743 g_device_scale_factor_for_testing = 0.0; |
| 770 return rv; | 744 return rv; |
| 771 } | 745 } |
| 772 #endif | 746 #endif |
| 773 | 747 |
| 774 } // namespace content | 748 } // namespace content |
| OLD | NEW |