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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 else | 31 else |
32 DictionaryHelper::get(options, "headers", headersDictionary); | 32 DictionaryHelper::get(options, "headers", headersDictionary); |
33 } | 33 } |
34 DictionaryHelper::get(options, "mode", mode); | 34 DictionaryHelper::get(options, "mode", mode); |
35 DictionaryHelper::get(options, "credentials", credentials); | 35 DictionaryHelper::get(options, "credentials", credentials); |
36 DictionaryHelper::get(options, "redirect", redirect); | 36 DictionaryHelper::get(options, "redirect", redirect); |
37 | 37 |
38 v8::Local<v8::Value> v8Body; | 38 v8::Local<v8::Value> v8Body; |
39 if (!DictionaryHelper::get(options, "body", v8Body) || v8Body->IsUndefined()
|| v8Body->IsNull()) | 39 if (!DictionaryHelper::get(options, "body", v8Body) || v8Body->IsUndefined()
|| v8Body->IsNull()) |
40 return; | 40 return; |
41 RefPtr<FormData> formData = FormData::create(); | |
42 v8::Isolate* isolate = toIsolate(context); | 41 v8::Isolate* isolate = toIsolate(context); |
43 if (v8Body->IsArrayBuffer()) { | 42 if (v8Body->IsArrayBuffer()) { |
44 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc
al<v8::Object>::Cast(v8Body))); | 43 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc
al<v8::Object>::Cast(v8Body))); |
45 } else if (v8Body->IsArrayBufferView()) { | 44 } else if (v8Body->IsArrayBufferView()) { |
46 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8:
:Local<v8::Object>::Cast(v8Body))); | 45 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8:
:Local<v8::Object>::Cast(v8Body))); |
47 } else if (V8Blob::hasInstance(v8Body, isolate)) { | 46 } else if (V8Blob::hasInstance(v8Body, isolate)) { |
48 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj
ect>::Cast(v8Body))->blobDataHandle(); | 47 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj
ect>::Cast(v8Body))->blobDataHandle(); |
49 contentType = blobDataHandle->type(); | 48 contentType = blobDataHandle->type(); |
50 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea
se()); | 49 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea
se()); |
51 } else if (V8FormData::hasInstance(v8Body, isolate)) { | 50 } else if (V8FormData::hasInstance(v8Body, isolate)) { |
52 RefPtr<FormData> formData = V8FormData::toImpl(v8::Local<v8::Object>::Ca
st(v8Body))->createMultiPartFormData(); | 51 RefPtr<FormData> formData = V8FormData::toImpl(v8::Local<v8::Object>::Ca
st(v8Body))->createMultiPartFormData(); |
53 // Here we handle formData->boundary() as a C-style string. See | 52 // Here we handle formData->boundary() as a C-style string. See |
54 // FormDataBuilder::generateUniqueBoundaryString. | 53 // FormDataBuilder::generateUniqueBoundaryString. |
55 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin
g::ConstructFromLiteral) + formData->boundary().data(); | 54 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin
g::ConstructFromLiteral) + formData->boundary().data(); |
56 body = FetchFormDataConsumerHandle::create(context, formData.release()); | 55 body = FetchFormDataConsumerHandle::create(context, formData.release()); |
57 } else if (v8Body->IsString()) { | 56 } else if (v8Body->IsString()) { |
58 contentType = "text/plain;charset=UTF-8"; | 57 contentType = "text/plain;charset=UTF-8"; |
59 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body,
exceptionState)); | 58 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body,
exceptionState)); |
60 } | 59 } |
61 } | 60 } |
62 | 61 |
63 } | 62 } |
OLD | NEW |