Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: content/common/page_state_serialization.cc

Issue 2038813003: Making ResourceRequestBody part of //content's public API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h" 18 #include "content/common/resource_request_body_impl.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
(...skipping 27 matching lines...) Expand all
56 } 56 }
57 57
58 void AppendBlobToHttpBody(ExplodedHttpBody* http_body, 58 void AppendBlobToHttpBody(ExplodedHttpBody* http_body,
59 const std::string& uuid) { 59 const std::string& uuid) {
60 http_body->request_body->AppendBlob(uuid); 60 http_body->request_body->AppendBlob(uuid);
61 } 61 }
62 62
63 //---------------------------------------------------------------------------- 63 //----------------------------------------------------------------------------
64 64
65 void AppendReferencedFilesFromHttpBody( 65 void AppendReferencedFilesFromHttpBody(
66 const std::vector<ResourceRequestBody::Element>& elements, 66 const std::vector<ResourceRequestBodyImpl::Element>& elements,
67 std::vector<base::NullableString16>* referenced_files) { 67 std::vector<base::NullableString16>* referenced_files) {
68 for (size_t i = 0; i < elements.size(); ++i) { 68 for (size_t i = 0; i < elements.size(); ++i) {
69 if (elements[i].type() == ResourceRequestBody::Element::TYPE_FILE) 69 if (elements[i].type() == ResourceRequestBodyImpl::Element::TYPE_FILE)
70 referenced_files->push_back( 70 referenced_files->push_back(
71 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false)); 71 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false));
72 } 72 }
73 } 73 }
74 74
75 bool AppendReferencedFilesFromDocumentState( 75 bool AppendReferencedFilesFromDocumentState(
76 const std::vector<base::NullableString16>& document_state, 76 const std::vector<base::NullableString16>& document_state,
77 std::vector<base::NullableString16>* referenced_files) { 77 std::vector<base::NullableString16>* referenced_files) {
78 if (document_state.empty()) 78 if (document_state.empty())
79 return true; 79 return true;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // Writes an ExplodedHttpBody object into a SerializeObject for serialization. 390 // Writes an ExplodedHttpBody object into a SerializeObject for serialization.
391 void WriteHttpBody(const ExplodedHttpBody& http_body, SerializeObject* obj) { 391 void WriteHttpBody(const ExplodedHttpBody& http_body, SerializeObject* obj) {
392 bool is_null = http_body.request_body == nullptr; 392 bool is_null = http_body.request_body == nullptr;
393 WriteBoolean(!is_null, obj); 393 WriteBoolean(!is_null, obj);
394 if (is_null) 394 if (is_null)
395 return; 395 return;
396 396
397 WriteAndValidateVectorSize(*http_body.request_body->elements(), obj); 397 WriteAndValidateVectorSize(*http_body.request_body->elements(), obj);
398 for (const auto& element : *http_body.request_body->elements()) { 398 for (const auto& element : *http_body.request_body->elements()) {
399 switch (element.type()) { 399 switch (element.type()) {
400 case ResourceRequestBody::Element::TYPE_BYTES: 400 case ResourceRequestBodyImpl::Element::TYPE_BYTES:
401 WriteInteger(blink::WebHTTPBody::Element::TypeData, obj); 401 WriteInteger(blink::WebHTTPBody::Element::TypeData, obj);
402 WriteData(element.bytes(), static_cast<int>(element.length()), obj); 402 WriteData(element.bytes(), static_cast<int>(element.length()), obj);
403 break; 403 break;
404 case ResourceRequestBody::Element::TYPE_FILE: 404 case ResourceRequestBodyImpl::Element::TYPE_FILE:
405 WriteInteger(blink::WebHTTPBody::Element::TypeFile, obj); 405 WriteInteger(blink::WebHTTPBody::Element::TypeFile, obj);
406 WriteString( 406 WriteString(
407 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj); 407 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj);
408 WriteInteger64(static_cast<int64_t>(element.offset()), obj); 408 WriteInteger64(static_cast<int64_t>(element.offset()), obj);
409 WriteInteger64(static_cast<int64_t>(element.length()), obj); 409 WriteInteger64(static_cast<int64_t>(element.length()), obj);
410 WriteReal(element.expected_modification_time().ToDoubleT(), obj); 410 WriteReal(element.expected_modification_time().ToDoubleT(), obj);
411 break; 411 break;
412 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: 412 case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM:
413 WriteInteger(blink::WebHTTPBody::Element::TypeFileSystemURL, obj); 413 WriteInteger(blink::WebHTTPBody::Element::TypeFileSystemURL, obj);
414 WriteGURL(element.filesystem_url(), obj); 414 WriteGURL(element.filesystem_url(), obj);
415 WriteInteger64(static_cast<int64_t>(element.offset()), obj); 415 WriteInteger64(static_cast<int64_t>(element.offset()), obj);
416 WriteInteger64(static_cast<int64_t>(element.length()), obj); 416 WriteInteger64(static_cast<int64_t>(element.length()), obj);
417 WriteReal(element.expected_modification_time().ToDoubleT(), obj); 417 WriteReal(element.expected_modification_time().ToDoubleT(), obj);
418 break; 418 break;
419 case ResourceRequestBody::Element::TYPE_BLOB: 419 case ResourceRequestBodyImpl::Element::TYPE_BLOB:
420 WriteInteger(blink::WebHTTPBody::Element::TypeBlob, obj); 420 WriteInteger(blink::WebHTTPBody::Element::TypeBlob, obj);
421 WriteStdString(element.blob_uuid(), obj); 421 WriteStdString(element.blob_uuid(), obj);
422 break; 422 break;
423 case ResourceRequestBody::Element::TYPE_BYTES_DESCRIPTION: 423 case ResourceRequestBodyImpl::Element::TYPE_BYTES_DESCRIPTION:
424 case ResourceRequestBody::Element::TYPE_DISK_CACHE_ENTRY: 424 case ResourceRequestBodyImpl::Element::TYPE_DISK_CACHE_ENTRY:
425 default: 425 default:
426 NOTREACHED(); 426 NOTREACHED();
427 continue; 427 continue;
428 } 428 }
429 } 429 }
430 WriteInteger64(http_body.request_body->identifier(), obj); 430 WriteInteger64(http_body.request_body->identifier(), obj);
431 WriteBoolean(http_body.contains_passwords, obj); 431 WriteBoolean(http_body.contains_passwords, obj);
432 } 432 }
433 433
434 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { 434 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) {
435 // An initial boolean indicates if we have an HTTP body. 435 // An initial boolean indicates if we have an HTTP body.
436 if (!ReadBoolean(obj)) 436 if (!ReadBoolean(obj))
437 return; 437 return;
438 438
439 http_body->request_body = new ResourceRequestBody(); 439 http_body->request_body = new ResourceRequestBodyImpl();
440 int num_elements = ReadInteger(obj); 440 int num_elements = ReadInteger(obj);
441 for (int i = 0; i < num_elements; ++i) { 441 for (int i = 0; i < num_elements; ++i) {
442 int type = ReadInteger(obj); 442 int type = ReadInteger(obj);
443 if (type == blink::WebHTTPBody::Element::TypeData) { 443 if (type == blink::WebHTTPBody::Element::TypeData) {
444 const void* data; 444 const void* data;
445 int length = -1; 445 int length = -1;
446 ReadData(obj, &data, &length); 446 ReadData(obj, &data, &length);
447 if (length >= 0) { 447 if (length >= 0) {
448 AppendDataToHttpBody(http_body, static_cast<const char*>(data), 448 AppendDataToHttpBody(http_body, static_cast<const char*>(data),
449 length); 449 length);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 float device_scale_factor, 739 float device_scale_factor,
740 ExplodedPageState* exploded) { 740 ExplodedPageState* exploded) {
741 g_device_scale_factor_for_testing = device_scale_factor; 741 g_device_scale_factor_for_testing = device_scale_factor;
742 bool rv = DecodePageState(encoded, exploded); 742 bool rv = DecodePageState(encoded, exploded);
743 g_device_scale_factor_for_testing = 0.0; 743 g_device_scale_factor_for_testing = 0.0;
744 return rv; 744 return rv;
745 } 745 }
746 #endif 746 #endif
747 747
748 } // namespace content 748 } // namespace content
OLDNEW
« no previous file with comments | « content/common/page_state_serialization.h ('k') | content/common/page_state_serialization_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698