| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/RequestInit.h" | 6 #include "modules/fetch/RequestInit.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "bindings/core/v8/V8ArrayBuffer.h" | 9 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 10 #include "bindings/core/v8/V8ArrayBufferView.h" | 10 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "bindings/core/v8/V8Blob.h" | 12 #include "bindings/core/v8/V8Blob.h" |
| 13 #include "bindings/core/v8/V8FormData.h" | 13 #include "bindings/core/v8/V8FormData.h" |
| 14 #include "core/fileapi/Blob.h" | 14 #include "core/fileapi/Blob.h" |
| 15 #include "core/html/DOMFormData.h" |
| 15 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 16 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 16 #include "modules/fetch/FetchFormDataConsumerHandle.h" | 17 #include "modules/fetch/FetchFormDataConsumerHandle.h" |
| 17 #include "modules/fetch/Headers.h" | 18 #include "modules/fetch/Headers.h" |
| 18 #include "platform/blob/BlobData.h" | 19 #include "platform/blob/BlobData.h" |
| 19 #include "platform/network/FormData.h" | 20 #include "platform/network/FormData.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E
xceptionState& exceptionState) | 24 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E
xceptionState& exceptionState) |
| 25 : opaque(false) |
| 24 { | 26 { |
| 25 DictionaryHelper::get(options, "method", method); | 27 DictionaryHelper::get(options, "method", method); |
| 26 DictionaryHelper::get(options, "headers", headers); | 28 DictionaryHelper::get(options, "headers", headers); |
| 27 if (!headers) { | 29 if (!headers) { |
| 28 Vector<Vector<String>> headersVector; | 30 Vector<Vector<String>> headersVector; |
| 29 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt
ate)) | 31 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt
ate)) |
| 30 headers = Headers::create(headersVector, exceptionState); | 32 headers = Headers::create(headersVector, exceptionState); |
| 31 else | 33 else |
| 32 DictionaryHelper::get(options, "headers", headersDictionary); | 34 DictionaryHelper::get(options, "headers", headersDictionary); |
| 33 } | 35 } |
| 34 DictionaryHelper::get(options, "mode", mode); | 36 DictionaryHelper::get(options, "mode", mode); |
| 35 DictionaryHelper::get(options, "credentials", credentials); | 37 DictionaryHelper::get(options, "credentials", credentials); |
| 36 DictionaryHelper::get(options, "redirect", redirect); | 38 DictionaryHelper::get(options, "redirect", redirect); |
| 37 DictionaryHelper::get(options, "integrity", integrity); | 39 DictionaryHelper::get(options, "integrity", integrity); |
| 38 | 40 |
| 39 v8::Local<v8::Value> v8Body; | 41 v8::Local<v8::Value> v8Body; |
| 40 if (!DictionaryHelper::get(options, "body", v8Body) || v8Body->IsUndefined()
|| v8Body->IsNull()) | 42 if (!DictionaryHelper::get(options, "body", v8Body) || v8Body->IsUndefined()
|| v8Body->IsNull()) |
| 41 return; | 43 return; |
| 42 v8::Isolate* isolate = toIsolate(context); | 44 v8::Isolate* isolate = toIsolate(context); |
| 43 if (v8Body->IsArrayBuffer()) { | 45 if (v8Body->IsArrayBuffer()) { |
| 44 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc
al<v8::Object>::Cast(v8Body))); | 46 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc
al<v8::Object>::Cast(v8Body))); |
| 45 } else if (v8Body->IsArrayBufferView()) { | 47 } else if (v8Body->IsArrayBufferView()) { |
| 46 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8:
:Local<v8::Object>::Cast(v8Body))); | 48 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8:
:Local<v8::Object>::Cast(v8Body))); |
| 47 } else if (V8Blob::hasInstance(v8Body, isolate)) { | 49 } else if (V8Blob::hasInstance(v8Body, isolate)) { |
| 48 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj
ect>::Cast(v8Body))->blobDataHandle(); | 50 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj
ect>::Cast(v8Body))->blobDataHandle(); |
| 49 contentType = blobDataHandle->type(); | 51 contentType = blobDataHandle->type(); |
| 50 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea
se()); | 52 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea
se()); |
| 51 } else if (V8FormData::hasInstance(v8Body, isolate)) { | 53 } else if (V8FormData::hasInstance(v8Body, isolate)) { |
| 52 RefPtr<FormData> formData = V8FormData::toImpl(v8::Local<v8::Object>::Ca
st(v8Body))->createMultiPartFormData(); | 54 DOMFormData* domFormData = V8FormData::toImpl(v8::Local<v8::Object>::Cas
t(v8Body)); |
| 55 opaque = domFormData->opaque(); |
| 56 |
| 57 RefPtr<FormData> formData = domFormData->createMultiPartFormData(); |
| 53 // Here we handle formData->boundary() as a C-style string. See | 58 // Here we handle formData->boundary() as a C-style string. See |
| 54 // FormDataBuilder::generateUniqueBoundaryString. | 59 // FormDataBuilder::generateUniqueBoundaryString. |
| 55 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin
g::ConstructFromLiteral) + formData->boundary().data(); | 60 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin
g::ConstructFromLiteral) + formData->boundary().data(); |
| 56 body = FetchFormDataConsumerHandle::create(context, formData.release()); | 61 body = FetchFormDataConsumerHandle::create(context, formData.release()); |
| 57 } else if (v8Body->IsString()) { | 62 } else if (v8Body->IsString()) { |
| 58 contentType = "text/plain;charset=UTF-8"; | 63 contentType = "text/plain;charset=UTF-8"; |
| 59 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body,
exceptionState)); | 64 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body,
exceptionState)); |
| 60 } | 65 } |
| 61 } | 66 } |
| 62 | 67 |
| 63 } | 68 } |
| OLD | NEW |