| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/resource_request_body.h" | 5 #include "content/common/resource_request_body.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/common/page_state_serialization.h" | 8 #include "content/common/page_state_serialization.h" |
| 9 | 9 |
| 10 using blink::WebHTTPBody; | 10 using blink::WebHTTPBody; |
| 11 using blink::WebString; | 11 using blink::WebString; |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 ResourceRequestBody::ResourceRequestBody() | 15 ResourceRequestBody::ResourceRequestBody() |
| 16 : identifier_(0) { | 16 : identifier_(0) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 void ResourceRequestBody::AppendExplodedHTTPBodyElement( | |
| 20 const ExplodedHttpBodyElement& element) { | |
| 21 // Note: this code is based on GetRequestBodyForWebURLRequest (in | |
| 22 // web_url_request_util.cc). The other function transforms a | |
| 23 // blink::WebHTTPBody into a ResourceRequestBody. This function is used to | |
| 24 // transform an ExplodedHttpBody into a ResourceRequestBody. | |
| 25 switch (element.type) { | |
| 26 case WebHTTPBody::Element::TypeData: | |
| 27 if (!element.data.empty()) { | |
| 28 // Blink sometimes gives empty data to append. These aren't | |
| 29 // necessary so they are just optimized out here. | |
| 30 AppendBytes(element.data.data(), static_cast<int>(element.data.size())); | |
| 31 } | |
| 32 break; | |
| 33 case WebHTTPBody::Element::TypeFile: | |
| 34 if (element.file_length == -1) { | |
| 35 AppendFileRange( | |
| 36 base::FilePath::FromUTF16Unsafe(element.file_path.string()), 0, | |
| 37 std::numeric_limits<uint64_t>::max(), base::Time()); | |
| 38 } else { | |
| 39 AppendFileRange( | |
| 40 base::FilePath::FromUTF16Unsafe(element.file_path.string()), | |
| 41 static_cast<uint64_t>(element.file_start), | |
| 42 static_cast<uint64_t>(element.file_length), | |
| 43 base::Time::FromDoubleT(element.file_modification_time)); | |
| 44 } | |
| 45 break; | |
| 46 case WebHTTPBody::Element::TypeFileSystemURL: { | |
| 47 GURL file_system_url = element.filesystem_url; | |
| 48 DCHECK(file_system_url.SchemeIsFileSystem()); | |
| 49 AppendFileSystemFileRange( | |
| 50 file_system_url, static_cast<uint64_t>(element.file_start), | |
| 51 static_cast<uint64_t>(element.file_length), | |
| 52 base::Time::FromDoubleT(element.file_modification_time)); | |
| 53 break; | |
| 54 } | |
| 55 case WebHTTPBody::Element::TypeBlob: | |
| 56 AppendBlob(element.blob_uuid); | |
| 57 break; | |
| 58 default: | |
| 59 NOTREACHED(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { | 19 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { |
| 64 if (bytes_len > 0) { | 20 if (bytes_len > 0) { |
| 65 elements_.push_back(Element()); | 21 elements_.push_back(Element()); |
| 66 elements_.back().SetToBytes(bytes, bytes_len); | 22 elements_.back().SetToBytes(bytes, bytes_len); |
| 67 } | 23 } |
| 68 } | 24 } |
| 69 | 25 |
| 70 void ResourceRequestBody::AppendFileRange( | 26 void ResourceRequestBody::AppendFileRange( |
| 71 const base::FilePath& file_path, | 27 const base::FilePath& file_path, |
| 72 uint64_t offset, | 28 uint64_t offset, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 const base::Time& expected_modification_time) { | 45 const base::Time& expected_modification_time) { |
| 90 elements_.push_back(Element()); | 46 elements_.push_back(Element()); |
| 91 elements_.back().SetToFileSystemUrlRange(url, offset, length, | 47 elements_.back().SetToFileSystemUrlRange(url, offset, length, |
| 92 expected_modification_time); | 48 expected_modification_time); |
| 93 } | 49 } |
| 94 | 50 |
| 95 ResourceRequestBody::~ResourceRequestBody() { | 51 ResourceRequestBody::~ResourceRequestBody() { |
| 96 } | 52 } |
| 97 | 53 |
| 98 } // namespace content | 54 } // namespace content |
| OLD | NEW |