Chromium Code Reviews| 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 // TODO(lukasza): Dedupe wrt GetRequestBodyForWebURLRequest. | |
|
Łukasz Anforowicz
2016/05/25 00:26:18
More deduplication coming soon - I didn't realize
Łukasz Anforowicz
2016/05/25 21:00:25
Just as an FYI - I am working on this in https://c
| |
| 52 void AppendHttpBodyElement(const ResourceRequestBody::Element& element, | |
| 53 WebHTTPBody* http_body) { | |
| 54 switch (element.type()) { | |
| 55 case storage::DataElement::TYPE_BYTES: | |
| 56 http_body->appendData(WebData(element.bytes(), element.length())); | |
| 57 break; | |
| 58 case storage::DataElement::TYPE_FILE: | |
| 59 http_body->appendFileRange( | |
| 60 element.path().AsUTF16Unsafe(), element.offset(), | |
| 61 (element.length() != std::numeric_limits<uint64_t>::max()) | |
| 62 ? element.length() | |
| 63 : -1, | |
| 64 element.expected_modification_time().ToDoubleT()); | |
| 65 break; | |
| 66 case storage::DataElement::TYPE_FILE_FILESYSTEM: | |
| 67 http_body->appendFileSystemURLRange( | |
| 68 element.filesystem_url(), element.offset(), | |
| 69 (element.length() != std::numeric_limits<uint64_t>::max()) | |
| 70 ? element.length() | |
| 71 : -1, | |
| 72 element.expected_modification_time().ToDoubleT()); | |
| 73 break; | |
| 74 case storage::DataElement::TYPE_BLOB: | |
| 75 http_body->appendBlob(WebString::fromUTF8(element.blob_uuid())); | |
| 76 break; | |
| 77 case storage::DataElement::TYPE_BYTES_DESCRIPTION: | |
| 78 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: | |
| 79 default: | |
| 80 NOTREACHED(); | |
| 81 break; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 } // namespace content | |
| OLD | NEW |