Chromium Code Reviews| Index: Source/modules/fetch/RequestInit.cpp |
| diff --git a/Source/modules/fetch/RequestInit.cpp b/Source/modules/fetch/RequestInit.cpp |
| index 31b13a3ca1b9ef0f460f60188e78bf925c96901c..b0c315bf6c818de48e49671ca7f77e325a962141 100644 |
| --- a/Source/modules/fetch/RequestInit.cpp |
| +++ b/Source/modules/fetch/RequestInit.cpp |
| @@ -12,6 +12,8 @@ |
| #include "bindings/core/v8/V8Blob.h" |
| #include "bindings/core/v8/V8FormData.h" |
| #include "core/fileapi/Blob.h" |
| +#include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| +#include "modules/fetch/FetchFormDataConsumerHandle.h" |
| #include "modules/fetch/Headers.h" |
| #include "platform/blob/BlobData.h" |
| #include "platform/network/FormData.h" |
| @@ -33,59 +35,29 @@ RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E |
| DictionaryHelper::get(options, "credentials", credentials); |
| DictionaryHelper::get(options, "redirect", redirect); |
| - v8::Local<v8::Value> body; |
| - if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() || body->IsNull()) |
| + v8::Local<v8::Value> v8Body; |
| + if (!DictionaryHelper::get(options, "body", v8Body) || v8Body->IsUndefined() || v8Body->IsNull()) |
| return; |
| - OwnPtr<BlobData> blobData = BlobData::create(); |
| + RefPtr<FormData> formData = FormData::create(); |
|
brucedawson
2015/08/19 16:45:28
This variable declaration appears to have no value
yhirano
2015/08/20 02:16:49
Thank you! I will fix it.
|
| v8::Isolate* isolate = toIsolate(context); |
| - if (body->IsArrayBuffer()) { |
| - DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Local<v8::Object>::Cast(body)); |
| - ASSERT(arrayBuffer); |
| - blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength()); |
| - } else if (body->IsArrayBufferView()) { |
| - DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Local<v8::Object>::Cast(body)); |
| - ASSERT(arrayBufferView); |
| - blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferView->byteLength()); |
| - } else if (V8Blob::hasInstance(body, isolate)) { |
| - Blob* blob = V8Blob::toImpl(v8::Local<v8::Object>::Cast(body)); |
| - ASSERT(blob); |
| - blob->appendTo(*blobData); |
| - blobData->setContentType(blob->type()); |
| - } else if (V8FormData::hasInstance(body, isolate)) { |
| - DOMFormData* domFormData = V8FormData::toImpl(v8::Local<v8::Object>::Cast(body)); |
| - ASSERT(domFormData); |
| - RefPtr<FormData> httpBody = domFormData->createMultiPartFormData(); |
| - for (size_t i = 0; i < httpBody->elements().size(); ++i) { |
| - const FormDataElement& element = httpBody->elements()[i]; |
| - switch (element.m_type) { |
| - case FormDataElement::data: { |
| - blobData->appendBytes(element.m_data.data(), element.m_data.size()); |
| - break; |
| - } |
| - case FormDataElement::encodedFile: |
| - blobData->appendFile(element.m_filename, element.m_fileStart, element.m_fileLength, element.m_expectedFileModificationTime); |
| - break; |
| - case FormDataElement::encodedBlob: |
| - if (element.m_optionalBlobDataHandle) |
| - blobData->appendBlob(element.m_optionalBlobDataHandle, 0, element.m_optionalBlobDataHandle->size()); |
| - break; |
| - case FormDataElement::encodedFileSystemURL: |
| - blobData->appendFileSystemURL(element.m_fileSystemURL, element.m_fileStart, element.m_fileLength, element.m_expectedFileModificationTime); |
| - break; |
| - default: |
| - ASSERT_NOT_REACHED(); |
| - } |
| - } |
| - blobData->setContentType(AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data()); |
| - } else if (body->IsString()) { |
| - String stringValue(toUSVString(isolate, body, exceptionState)); |
| - blobData->appendText(stringValue, false); |
| - blobData->setContentType("text/plain;charset=UTF-8"); |
| - } else { |
| - return; |
| + if (v8Body->IsArrayBuffer()) { |
| + body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Local<v8::Object>::Cast(v8Body))); |
| + } else if (v8Body->IsArrayBufferView()) { |
| + body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8::Local<v8::Object>::Cast(v8Body))); |
| + } else if (V8Blob::hasInstance(v8Body, isolate)) { |
| + RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Object>::Cast(v8Body))->blobDataHandle(); |
| + contentType = blobDataHandle->type(); |
| + body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.release()); |
| + } else if (V8FormData::hasInstance(v8Body, isolate)) { |
| + RefPtr<FormData> formData = V8FormData::toImpl(v8::Local<v8::Object>::Cast(v8Body))->createMultiPartFormData(); |
| + // Here we handle formData->boundary() as a C-style string. See |
| + // FormDataBuilder::generateUniqueBoundaryString. |
| + contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + formData->boundary().data(); |
| + body = FetchFormDataConsumerHandle::create(context, formData.release()); |
| + } else if (v8Body->IsString()) { |
| + contentType = "text/plain;charset=UTF-8"; |
| + body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); |
| } |
| - const long long blobSize = blobData->length(); |
| - bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize); |
| } |
| } |