Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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: { |
| 132 blobData->appendFileSystemURL( | 142 auto fileLength = element.m_fileLength; |
| 133 element.m_fileSystemURL, element.m_fileStart, | 143 if (fileLength < 0) { |
| 134 element.m_fileLength, element.m_expectedFileModificationTime); | 144 if (!getFileSize(element.m_filename, fileLength)) { |
|
hiroshige
2017/03/02 20:38:21
m_filename is not valid for encodedFileSystemURL.
yhirano
2017/03/23 06:18:06
Thanks, you're right.
I talked with tzik@, and it
| |
| 145 m_formData = nullptr; | |
| 146 m_blobBytesConsumer = BytesConsumer::createErrored( | |
| 147 Error("Cannot determine a file size")); | |
| 148 return; | |
| 149 } | |
| 150 } | |
| 151 blobData->appendFileSystemURL(element.m_fileSystemURL, | |
| 152 element.m_fileStart, fileLength, | |
| 153 element.m_expectedFileModificationTime); | |
| 135 break; | 154 break; |
| 136 } | 155 } |
|
hiroshige
2017/03/02 20:38:21
nit: +2 indent. (Perhaps this is git cl format bug
yhirano
2017/03/23 06:18:06
Removed
| |
| 156 } | |
| 137 } | 157 } |
| 138 // Here we handle m_formData->boundary() as a C-style string. See | 158 // Here we handle m_formData->boundary() as a C-style string. See |
| 139 // FormDataEncoder::generateUniqueBoundaryString. | 159 // FormDataEncoder::generateUniqueBoundaryString. |
| 140 blobData->setContentType(AtomicString("multipart/form-data; boundary=") + | 160 blobData->setContentType(AtomicString("multipart/form-data; boundary=") + |
| 141 m_formData->boundary().data()); | 161 m_formData->boundary().data()); |
| 142 auto size = blobData->length(); | 162 auto size = blobData->length(); |
| 143 m_blobBytesConsumer = new BlobBytesConsumer( | 163 m_blobBytesConsumer = new BlobBytesConsumer( |
| 144 executionContext, BlobDataHandle::create(std::move(blobData), size)); | 164 executionContext, BlobDataHandle::create(std::move(blobData), size)); |
| 145 } | 165 } |
| 146 | 166 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 BytesConsumer* consumer) | 240 BytesConsumer* consumer) |
| 221 : m_impl(isSimple(formData.get()) | 241 : m_impl(isSimple(formData.get()) |
| 222 ? static_cast<BytesConsumer*>( | 242 ? static_cast<BytesConsumer*>( |
| 223 new SimpleFormDataBytesConsumer(std::move(formData))) | 243 new SimpleFormDataBytesConsumer(std::move(formData))) |
| 224 : static_cast<BytesConsumer*>( | 244 : static_cast<BytesConsumer*>( |
| 225 new ComplexFormDataBytesConsumer(executionContext, | 245 new ComplexFormDataBytesConsumer(executionContext, |
| 226 std::move(formData), | 246 std::move(formData), |
| 227 consumer))) {} | 247 consumer))) {} |
| 228 | 248 |
| 229 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |