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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FormDataBytesConsumer.cpp

Issue 2710033003: Add unknown file size handling in ComplexFormDataBytesConsumer (Closed)
Patch Set: fix Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/filesystem/form-reading-from-file.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "modules/fetch/FormDataBytesConsumer.h" 5 #include "modules/fetch/FormDataBytesConsumer.h"
6 6
7 #include "core/dom/DOMArrayBuffer.h" 7 #include "core/dom/DOMArrayBuffer.h"
8 #include "core/dom/DOMArrayBufferView.h" 8 #include "core/dom/DOMArrayBufferView.h"
9 #include "modules/fetch/BlobBytesConsumer.h" 9 #include "modules/fetch/BlobBytesConsumer.h"
10 #include "platform/blob/BlobData.h" 10 #include "platform/blob/BlobData.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 m_blobBytesConsumer = consumer; 111 m_blobBytesConsumer = consumer;
112 return; 112 return;
113 } 113 }
114 114
115 std::unique_ptr<BlobData> blobData = BlobData::create(); 115 std::unique_ptr<BlobData> blobData = BlobData::create();
116 for (const auto& element : m_formData->elements()) { 116 for (const auto& element : m_formData->elements()) {
117 switch (element.m_type) { 117 switch (element.m_type) {
118 case FormDataElement::data: 118 case FormDataElement::data:
119 blobData->appendBytes(element.m_data.data(), element.m_data.size()); 119 blobData->appendBytes(element.m_data.data(), element.m_data.size());
120 break; 120 break;
121 case FormDataElement::encodedFile: 121 case FormDataElement::encodedFile: {
122 auto fileLength = element.m_fileLength;
123 if (fileLength < 0) {
124 if (!getFileSize(element.m_filename, fileLength)) {
125 m_formData = nullptr;
126 m_blobBytesConsumer = BytesConsumer::createErrored(
127 Error("Cannot determine a file size"));
128 return;
129 }
130 }
122 blobData->appendFile(element.m_filename, element.m_fileStart, 131 blobData->appendFile(element.m_filename, element.m_fileStart,
123 element.m_fileLength, 132 fileLength,
124 element.m_expectedFileModificationTime); 133 element.m_expectedFileModificationTime);
125 break; 134 break;
135 }
126 case FormDataElement::encodedBlob: 136 case FormDataElement::encodedBlob:
127 if (element.m_optionalBlobDataHandle) 137 if (element.m_optionalBlobDataHandle)
128 blobData->appendBlob(element.m_optionalBlobDataHandle, 0, 138 blobData->appendBlob(element.m_optionalBlobDataHandle, 0,
129 element.m_optionalBlobDataHandle->size()); 139 element.m_optionalBlobDataHandle->size());
130 break; 140 break;
131 case FormDataElement::encodedFileSystemURL: 141 case FormDataElement::encodedFileSystemURL:
142 if (element.m_fileLength < 0) {
143 m_formData = nullptr;
144 m_blobBytesConsumer = BytesConsumer::createErrored(
145 Error("Cannot determine a file size"));
146 return;
147 }
132 blobData->appendFileSystemURL( 148 blobData->appendFileSystemURL(
133 element.m_fileSystemURL, element.m_fileStart, 149 element.m_fileSystemURL, element.m_fileStart,
134 element.m_fileLength, element.m_expectedFileModificationTime); 150 element.m_fileLength, element.m_expectedFileModificationTime);
135 break; 151 break;
136 } 152 }
137 } 153 }
138 // Here we handle m_formData->boundary() as a C-style string. See 154 // Here we handle m_formData->boundary() as a C-style string. See
139 // FormDataEncoder::generateUniqueBoundaryString. 155 // FormDataEncoder::generateUniqueBoundaryString.
140 blobData->setContentType(AtomicString("multipart/form-data; boundary=") + 156 blobData->setContentType(AtomicString("multipart/form-data; boundary=") +
141 m_formData->boundary().data()); 157 m_formData->boundary().data());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 BytesConsumer* consumer) 236 BytesConsumer* consumer)
221 : m_impl(isSimple(formData.get()) 237 : m_impl(isSimple(formData.get())
222 ? static_cast<BytesConsumer*>( 238 ? static_cast<BytesConsumer*>(
223 new SimpleFormDataBytesConsumer(std::move(formData))) 239 new SimpleFormDataBytesConsumer(std::move(formData)))
224 : static_cast<BytesConsumer*>( 240 : static_cast<BytesConsumer*>(
225 new ComplexFormDataBytesConsumer(executionContext, 241 new ComplexFormDataBytesConsumer(executionContext,
226 std::move(formData), 242 std::move(formData),
227 consumer))) {} 243 consumer))) {}
228 244
229 } // namespace blink 245 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/filesystem/form-reading-from-file.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698