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> |
11 | 11 |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "content/common/resource_request_body_impl.h" | 18 #include "content/public/common/resource_request_body.h" |
19 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
20 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
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 AppendDataToRequestBody( | 31 void AppendDataToRequestBody( |
32 const scoped_refptr<ResourceRequestBodyImpl>& request_body, | 32 const scoped_refptr<ResourceRequestBody>& request_body, |
33 const char* data, | 33 const char* data, |
34 int data_length) { | 34 int data_length) { |
35 request_body->AppendBytes(data, data_length); | 35 request_body->AppendBytes(data, data_length); |
36 } | 36 } |
37 | 37 |
38 void AppendFileRangeToRequestBody( | 38 void AppendFileRangeToRequestBody( |
39 const scoped_refptr<ResourceRequestBodyImpl>& request_body, | 39 const scoped_refptr<ResourceRequestBody>& request_body, |
40 const base::NullableString16& file_path, | 40 const base::NullableString16& file_path, |
41 int file_start, | 41 int file_start, |
42 int file_length, | 42 int file_length, |
43 double file_modification_time) { | 43 double file_modification_time) { |
44 request_body->AppendFileRange( | 44 request_body->AppendFileRange( |
45 base::FilePath::FromUTF16Unsafe(file_path.string()), | 45 base::FilePath::FromUTF16Unsafe(file_path.string()), |
46 static_cast<uint64_t>(file_start), static_cast<uint64_t>(file_length), | 46 static_cast<uint64_t>(file_start), static_cast<uint64_t>(file_length), |
47 base::Time::FromDoubleT(file_modification_time)); | 47 base::Time::FromDoubleT(file_modification_time)); |
48 } | 48 } |
49 | 49 |
50 void AppendURLRangeToRequestBody( | 50 void AppendURLRangeToRequestBody( |
51 const scoped_refptr<ResourceRequestBodyImpl>& request_body, | 51 const scoped_refptr<ResourceRequestBody>& request_body, |
52 const GURL& url, | 52 const GURL& url, |
53 int file_start, | 53 int file_start, |
54 int file_length, | 54 int file_length, |
55 double file_modification_time) { | 55 double file_modification_time) { |
56 request_body->AppendFileSystemFileRange( | 56 request_body->AppendFileSystemFileRange( |
57 url, static_cast<uint64_t>(file_start), | 57 url, static_cast<uint64_t>(file_start), |
58 static_cast<uint64_t>(file_length), | 58 static_cast<uint64_t>(file_length), |
59 base::Time::FromDoubleT(file_modification_time)); | 59 base::Time::FromDoubleT(file_modification_time)); |
60 } | 60 } |
61 | 61 |
62 void AppendBlobToRequestBody( | 62 void AppendBlobToRequestBody( |
63 const scoped_refptr<ResourceRequestBodyImpl>& request_body, | 63 const scoped_refptr<ResourceRequestBody>& request_body, |
64 const std::string& uuid) { | 64 const std::string& uuid) { |
65 request_body->AppendBlob(uuid); | 65 request_body->AppendBlob(uuid); |
66 } | 66 } |
67 | 67 |
68 //---------------------------------------------------------------------------- | 68 //---------------------------------------------------------------------------- |
69 | 69 |
70 void AppendReferencedFilesFromHttpBody( | 70 void AppendReferencedFilesFromHttpBody( |
71 const std::vector<ResourceRequestBodyImpl::Element>& elements, | 71 const std::vector<ResourceRequestBody::Element>& elements, |
72 std::vector<base::NullableString16>* referenced_files) { | 72 std::vector<base::NullableString16>* referenced_files) { |
73 for (size_t i = 0; i < elements.size(); ++i) { | 73 for (size_t i = 0; i < elements.size(); ++i) { |
74 if (elements[i].type() == ResourceRequestBodyImpl::Element::TYPE_FILE) | 74 if (elements[i].type() == ResourceRequestBody::Element::TYPE_FILE) |
75 referenced_files->push_back( | 75 referenced_files->push_back( |
76 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false)); | 76 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false)); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 bool AppendReferencedFilesFromDocumentState( | 80 bool AppendReferencedFilesFromDocumentState( |
81 const std::vector<base::NullableString16>& document_state, | 81 const std::vector<base::NullableString16>& document_state, |
82 std::vector<base::NullableString16>* referenced_files) { | 82 std::vector<base::NullableString16>* referenced_files) { |
83 if (document_state.empty()) | 83 if (document_state.empty()) |
84 return true; | 84 return true; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 void ReadStringVector(SerializeObject* obj, | 386 void ReadStringVector(SerializeObject* obj, |
387 std::vector<base::NullableString16>* result) { | 387 std::vector<base::NullableString16>* result) { |
388 size_t num_elements = | 388 size_t num_elements = |
389 ReadAndValidateVectorSize(obj, sizeof(base::NullableString16)); | 389 ReadAndValidateVectorSize(obj, sizeof(base::NullableString16)); |
390 | 390 |
391 result->resize(num_elements); | 391 result->resize(num_elements); |
392 for (size_t i = 0; i < num_elements; ++i) | 392 for (size_t i = 0; i < num_elements; ++i) |
393 (*result)[i] = ReadString(obj); | 393 (*result)[i] = ReadString(obj); |
394 } | 394 } |
395 | 395 |
396 void WriteResourceRequestBody(const ResourceRequestBodyImpl& request_body, | 396 void WriteResourceRequestBody(const ResourceRequestBody& request_body, |
397 SerializeObject* obj) { | 397 SerializeObject* obj) { |
398 WriteAndValidateVectorSize(*request_body.elements(), obj); | 398 WriteAndValidateVectorSize(*request_body.elements(), obj); |
399 for (const auto& element : *request_body.elements()) { | 399 for (const auto& element : *request_body.elements()) { |
400 switch (element.type()) { | 400 switch (element.type()) { |
401 case ResourceRequestBodyImpl::Element::TYPE_BYTES: | 401 case ResourceRequestBody::Element::TYPE_BYTES: |
402 WriteInteger(blink::WebHTTPBody::Element::kTypeData, obj); | 402 WriteInteger(blink::WebHTTPBody::Element::kTypeData, obj); |
403 WriteData(element.bytes(), static_cast<int>(element.length()), obj); | 403 WriteData(element.bytes(), static_cast<int>(element.length()), obj); |
404 break; | 404 break; |
405 case ResourceRequestBodyImpl::Element::TYPE_FILE: | 405 case ResourceRequestBody::Element::TYPE_FILE: |
406 WriteInteger(blink::WebHTTPBody::Element::kTypeFile, obj); | 406 WriteInteger(blink::WebHTTPBody::Element::kTypeFile, obj); |
407 WriteString( | 407 WriteString( |
408 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj); | 408 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj); |
409 WriteInteger64(static_cast<int64_t>(element.offset()), obj); | 409 WriteInteger64(static_cast<int64_t>(element.offset()), obj); |
410 WriteInteger64(static_cast<int64_t>(element.length()), obj); | 410 WriteInteger64(static_cast<int64_t>(element.length()), obj); |
411 WriteReal(element.expected_modification_time().ToDoubleT(), obj); | 411 WriteReal(element.expected_modification_time().ToDoubleT(), obj); |
412 break; | 412 break; |
413 case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM: | 413 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: |
414 WriteInteger(blink::WebHTTPBody::Element::kTypeFileSystemURL, obj); | 414 WriteInteger(blink::WebHTTPBody::Element::kTypeFileSystemURL, obj); |
415 WriteGURL(element.filesystem_url(), obj); | 415 WriteGURL(element.filesystem_url(), obj); |
416 WriteInteger64(static_cast<int64_t>(element.offset()), obj); | 416 WriteInteger64(static_cast<int64_t>(element.offset()), obj); |
417 WriteInteger64(static_cast<int64_t>(element.length()), obj); | 417 WriteInteger64(static_cast<int64_t>(element.length()), obj); |
418 WriteReal(element.expected_modification_time().ToDoubleT(), obj); | 418 WriteReal(element.expected_modification_time().ToDoubleT(), obj); |
419 break; | 419 break; |
420 case ResourceRequestBodyImpl::Element::TYPE_BLOB: | 420 case ResourceRequestBody::Element::TYPE_BLOB: |
421 WriteInteger(blink::WebHTTPBody::Element::kTypeBlob, obj); | 421 WriteInteger(blink::WebHTTPBody::Element::kTypeBlob, obj); |
422 WriteStdString(element.blob_uuid(), obj); | 422 WriteStdString(element.blob_uuid(), obj); |
423 break; | 423 break; |
424 case ResourceRequestBodyImpl::Element::TYPE_BYTES_DESCRIPTION: | 424 case ResourceRequestBody::Element::TYPE_BYTES_DESCRIPTION: |
425 case ResourceRequestBodyImpl::Element::TYPE_DISK_CACHE_ENTRY: | 425 case ResourceRequestBody::Element::TYPE_DISK_CACHE_ENTRY: |
426 default: | 426 default: |
427 NOTREACHED(); | 427 NOTREACHED(); |
428 continue; | 428 continue; |
429 } | 429 } |
430 } | 430 } |
431 WriteInteger64(request_body.identifier(), obj); | 431 WriteInteger64(request_body.identifier(), obj); |
432 } | 432 } |
433 | 433 |
434 void ReadResourceRequestBody( | 434 void ReadResourceRequestBody( |
435 SerializeObject* obj, | 435 SerializeObject* obj, |
436 const scoped_refptr<ResourceRequestBodyImpl>& request_body) { | 436 const scoped_refptr<ResourceRequestBody>& request_body) { |
437 int num_elements = ReadInteger(obj); | 437 int num_elements = ReadInteger(obj); |
438 for (int i = 0; i < num_elements; ++i) { | 438 for (int i = 0; i < num_elements; ++i) { |
439 int type = ReadInteger(obj); | 439 int type = ReadInteger(obj); |
440 if (type == blink::WebHTTPBody::Element::kTypeData) { | 440 if (type == blink::WebHTTPBody::Element::kTypeData) { |
441 const void* data; | 441 const void* data; |
442 int length = -1; | 442 int length = -1; |
443 ReadData(obj, &data, &length); | 443 ReadData(obj, &data, &length); |
444 if (length >= 0) { | 444 if (length >= 0) { |
445 AppendDataToRequestBody(request_body, static_cast<const char*>(data), | 445 AppendDataToRequestBody(request_body, static_cast<const char*>(data), |
446 length); | 446 length); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 480 |
481 WriteResourceRequestBody(*http_body.request_body, obj); | 481 WriteResourceRequestBody(*http_body.request_body, obj); |
482 WriteBoolean(http_body.contains_passwords, obj); | 482 WriteBoolean(http_body.contains_passwords, obj); |
483 } | 483 } |
484 | 484 |
485 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { | 485 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { |
486 // An initial boolean indicates if we have an HTTP body. | 486 // An initial boolean indicates if we have an HTTP body. |
487 if (!ReadBoolean(obj)) | 487 if (!ReadBoolean(obj)) |
488 return; | 488 return; |
489 | 489 |
490 http_body->request_body = new ResourceRequestBodyImpl(); | 490 http_body->request_body = new ResourceRequestBody(); |
491 ReadResourceRequestBody(obj, http_body->request_body); | 491 ReadResourceRequestBody(obj, http_body->request_body); |
492 | 492 |
493 if (obj->version >= 12) | 493 if (obj->version >= 12) |
494 http_body->contains_passwords = ReadBoolean(obj); | 494 http_body->contains_passwords = ReadBoolean(obj); |
495 } | 495 } |
496 | 496 |
497 // Writes the ExplodedFrameState data into the SerializeObject object for | 497 // Writes the ExplodedFrameState data into the SerializeObject object for |
498 // serialization. | 498 // serialization. |
499 void WriteFrameState( | 499 void WriteFrameState( |
500 const ExplodedFrameState& state, SerializeObject* obj, bool is_top) { | 500 const ExplodedFrameState& state, SerializeObject* obj, bool is_top) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 bool DecodePageStateWithDeviceScaleFactorForTesting( | 774 bool DecodePageStateWithDeviceScaleFactorForTesting( |
775 const std::string& encoded, | 775 const std::string& encoded, |
776 float device_scale_factor, | 776 float device_scale_factor, |
777 ExplodedPageState* exploded) { | 777 ExplodedPageState* exploded) { |
778 g_device_scale_factor_for_testing = device_scale_factor; | 778 g_device_scale_factor_for_testing = device_scale_factor; |
779 bool rv = DecodePageState(encoded, exploded); | 779 bool rv = DecodePageState(encoded, exploded); |
780 g_device_scale_factor_for_testing = 0.0; | 780 g_device_scale_factor_for_testing = 0.0; |
781 return rv; | 781 return rv; |
782 } | 782 } |
783 | 783 |
784 scoped_refptr<ResourceRequestBodyImpl> DecodeResourceRequestBody( | 784 scoped_refptr<ResourceRequestBody> DecodeResourceRequestBody(const char* data, |
785 const char* data, | 785 size_t size) { |
786 size_t size) { | 786 scoped_refptr<ResourceRequestBody> result = new ResourceRequestBody(); |
787 scoped_refptr<ResourceRequestBodyImpl> result = new ResourceRequestBodyImpl(); | |
788 SerializeObject obj(data, static_cast<int>(size)); | 787 SerializeObject obj(data, static_cast<int>(size)); |
789 ReadResourceRequestBody(&obj, result); | 788 ReadResourceRequestBody(&obj, result); |
790 // Please see the EncodeResourceRequestBody() function below for information | 789 // Please see the EncodeResourceRequestBody() function below for information |
791 // about why the contains_sensitive_info() field is being explicitly | 790 // about why the contains_sensitive_info() field is being explicitly |
792 // deserialized. | 791 // deserialized. |
793 result->set_contains_sensitive_info(ReadBoolean(&obj)); | 792 result->set_contains_sensitive_info(ReadBoolean(&obj)); |
794 return obj.parse_error ? nullptr : result; | 793 return obj.parse_error ? nullptr : result; |
795 } | 794 } |
796 | 795 |
797 std::string EncodeResourceRequestBody( | 796 std::string EncodeResourceRequestBody( |
798 const ResourceRequestBodyImpl& resource_request_body) { | 797 const ResourceRequestBody& resource_request_body) { |
799 SerializeObject obj; | 798 SerializeObject obj; |
800 obj.version = kCurrentVersion; | 799 obj.version = kCurrentVersion; |
801 WriteResourceRequestBody(resource_request_body, &obj); | 800 WriteResourceRequestBody(resource_request_body, &obj); |
802 // EncodeResourceRequestBody() is different from WriteResourceRequestBody() | 801 // EncodeResourceRequestBody() is different from WriteResourceRequestBody() |
803 // because it covers additional data (e.g.|contains_sensitive_info|) which | 802 // because it covers additional data (e.g.|contains_sensitive_info|) which |
804 // is marshaled between native code and java. WriteResourceRequestBody() | 803 // is marshaled between native code and java. WriteResourceRequestBody() |
805 // serializes data which needs to be saved out to disk. | 804 // serializes data which needs to be saved out to disk. |
806 WriteBoolean(resource_request_body.contains_sensitive_info(), &obj); | 805 WriteBoolean(resource_request_body.contains_sensitive_info(), &obj); |
807 return obj.GetAsString(); | 806 return obj.GetAsString(); |
808 } | 807 } |
809 | 808 |
810 #endif | 809 #endif |
811 | 810 |
812 } // namespace content | 811 } // namespace content |
OLD | NEW |