OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/http_body_conversions.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "base/files/file_path.h" | |
10 #include "base/strings/nullable_string16.h" | |
11 #include "base/time/time.h" | |
12 #include "third_party/WebKit/public/platform/WebData.h" | |
13 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | |
14 #include "third_party/WebKit/public/platform/WebString.h" | |
15 | |
16 using blink::WebData; | |
17 using blink::WebHTTPBody; | |
18 using blink::WebString; | |
19 | |
20 namespace content { | |
21 | |
22 void ConvertToHttpBodyElement(const WebHTTPBody::Element& input, | |
23 ResourceRequestBody::Element* output) { | |
24 switch (input.type) { | |
25 case WebHTTPBody::Element::TypeData: | |
26 output->SetToBytes(input.data.data(), input.data.size()); | |
27 break; | |
28 case WebHTTPBody::Element::TypeFile: | |
29 output->SetToFilePathRange( | |
30 base::FilePath::FromUTF8Unsafe(input.filePath.utf8()), | |
31 static_cast<uint64_t>(input.fileStart), | |
32 static_cast<uint64_t>(input.fileLength), | |
33 base::Time::FromDoubleT(input.modificationTime)); | |
34 break; | |
35 case WebHTTPBody::Element::TypeFileSystemURL: | |
36 output->SetToFileSystemUrlRange( | |
37 input.fileSystemURL, static_cast<uint64_t>(input.fileStart), | |
38 static_cast<uint64_t>(input.fileLength), | |
39 base::Time::FromDoubleT(input.modificationTime)); | |
40 break; | |
41 case WebHTTPBody::Element::TypeBlob: | |
42 output->SetToBlob(input.blobUUID.utf8()); | |
43 break; | |
44 default: | |
45 output->SetToEmptyBytes(); | |
46 NOTREACHED(); | |
47 break; | |
48 } | |
49 } | |
50 | |
51 void AppendHttpBodyElement(const ResourceRequestBody::Element& element, | |
52 WebHTTPBody* http_body) { | |
53 switch (element.type()) { | |
54 case storage::DataElement::TYPE_BYTES: | |
55 http_body->appendData(WebData(element.bytes(), element.length())); | |
56 break; | |
57 case storage::DataElement::TYPE_FILE: | |
58 http_body->appendFileRange( | |
59 element.path().AsUTF16Unsafe(), element.offset(), | |
60 (element.length() != std::numeric_limits<uint64_t>::max()) | |
61 ? element.length() | |
62 : -1, | |
63 element.expected_modification_time().ToDoubleT()); | |
64 break; | |
65 case storage::DataElement::TYPE_FILE_FILESYSTEM: | |
66 http_body->appendFileSystemURLRange( | |
67 element.filesystem_url(), element.offset(), | |
68 (element.length() != std::numeric_limits<uint64_t>::max()) | |
69 ? element.length() | |
70 : -1, | |
71 element.expected_modification_time().ToDoubleT()); | |
72 break; | |
73 case storage::DataElement::TYPE_BLOB: | |
74 http_body->appendBlob(WebString::fromUTF8(element.blob_uuid())); | |
75 break; | |
76 case storage::DataElement::TYPE_BYTES_DESCRIPTION: | |
77 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: | |
78 default: | |
79 NOTREACHED(); | |
80 break; | |
81 } | |
82 } | |
83 | |
84 } // namespace content | |
OLD | NEW |