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 "modules/fetch/FetchBlobDataConsumerHandle.h" | |
16 #include "modules/fetch/FetchFormDataConsumerHandle.h" | |
15 #include "modules/fetch/Headers.h" | 17 #include "modules/fetch/Headers.h" |
16 #include "platform/blob/BlobData.h" | 18 #include "platform/blob/BlobData.h" |
17 #include "platform/network/FormData.h" | 19 #include "platform/network/FormData.h" |
18 | 20 |
19 namespace blink { | 21 namespace blink { |
20 | 22 |
21 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState) | 23 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState) |
22 { | 24 { |
23 DictionaryHelper::get(options, "method", method); | 25 DictionaryHelper::get(options, "method", method); |
24 DictionaryHelper::get(options, "headers", headers); | 26 DictionaryHelper::get(options, "headers", headers); |
25 if (!headers) { | 27 if (!headers) { |
26 Vector<Vector<String>> headersVector; | 28 Vector<Vector<String>> headersVector; |
27 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt ate)) | 29 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt ate)) |
28 headers = Headers::create(headersVector, exceptionState); | 30 headers = Headers::create(headersVector, exceptionState); |
29 else | 31 else |
30 DictionaryHelper::get(options, "headers", headersDictionary); | 32 DictionaryHelper::get(options, "headers", headersDictionary); |
31 } | 33 } |
32 DictionaryHelper::get(options, "mode", mode); | 34 DictionaryHelper::get(options, "mode", mode); |
33 DictionaryHelper::get(options, "credentials", credentials); | 35 DictionaryHelper::get(options, "credentials", credentials); |
34 DictionaryHelper::get(options, "redirect", redirect); | 36 DictionaryHelper::get(options, "redirect", redirect); |
35 | 37 |
36 v8::Local<v8::Value> body; | 38 v8::Local<v8::Value> v8Body; |
37 if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() || body->IsNull()) | 39 if (!DictionaryHelper::get(options, "body", v8Body) || v8Body->IsUndefined() || v8Body->IsNull()) |
38 return; | 40 return; |
39 OwnPtr<BlobData> blobData = BlobData::create(); | 41 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.
| |
40 v8::Isolate* isolate = toIsolate(context); | 42 v8::Isolate* isolate = toIsolate(context); |
41 if (body->IsArrayBuffer()) { | 43 if (v8Body->IsArrayBuffer()) { |
42 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Local<v8::Object >::Cast(body)); | 44 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc al<v8::Object>::Cast(v8Body))); |
43 ASSERT(arrayBuffer); | 45 } else if (v8Body->IsArrayBufferView()) { |
44 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength()); | 46 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8: :Local<v8::Object>::Cast(v8Body))); |
45 } else if (body->IsArrayBufferView()) { | 47 } else if (V8Blob::hasInstance(v8Body, isolate)) { |
46 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Loca l<v8::Object>::Cast(body)); | 48 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj ect>::Cast(v8Body))->blobDataHandle(); |
47 ASSERT(arrayBufferView); | 49 contentType = blobDataHandle->type(); |
48 blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferView->b yteLength()); | 50 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea se()); |
49 } else if (V8Blob::hasInstance(body, isolate)) { | 51 } else if (V8FormData::hasInstance(v8Body, isolate)) { |
50 Blob* blob = V8Blob::toImpl(v8::Local<v8::Object>::Cast(body)); | 52 RefPtr<FormData> formData = V8FormData::toImpl(v8::Local<v8::Object>::Ca st(v8Body))->createMultiPartFormData(); |
51 ASSERT(blob); | 53 // Here we handle formData->boundary() as a C-style string. See |
52 blob->appendTo(*blobData); | 54 // FormDataBuilder::generateUniqueBoundaryString. |
53 blobData->setContentType(blob->type()); | 55 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin g::ConstructFromLiteral) + formData->boundary().data(); |
54 } else if (V8FormData::hasInstance(body, isolate)) { | 56 body = FetchFormDataConsumerHandle::create(context, formData.release()); |
55 DOMFormData* domFormData = V8FormData::toImpl(v8::Local<v8::Object>::Cas t(body)); | 57 } else if (v8Body->IsString()) { |
56 ASSERT(domFormData); | 58 contentType = "text/plain;charset=UTF-8"; |
57 RefPtr<FormData> httpBody = domFormData->createMultiPartFormData(); | 59 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); |
58 for (size_t i = 0; i < httpBody->elements().size(); ++i) { | |
59 const FormDataElement& element = httpBody->elements()[i]; | |
60 switch (element.m_type) { | |
61 case FormDataElement::data: { | |
62 blobData->appendBytes(element.m_data.data(), element.m_data.size ()); | |
63 break; | |
64 } | |
65 case FormDataElement::encodedFile: | |
66 blobData->appendFile(element.m_filename, element.m_fileStart, el ement.m_fileLength, element.m_expectedFileModificationTime); | |
67 break; | |
68 case FormDataElement::encodedBlob: | |
69 if (element.m_optionalBlobDataHandle) | |
70 blobData->appendBlob(element.m_optionalBlobDataHandle, 0, el ement.m_optionalBlobDataHandle->size()); | |
71 break; | |
72 case FormDataElement::encodedFileSystemURL: | |
73 blobData->appendFileSystemURL(element.m_fileSystemURL, element.m _fileStart, element.m_fileLength, element.m_expectedFileModificationTime); | |
74 break; | |
75 default: | |
76 ASSERT_NOT_REACHED(); | |
77 } | |
78 } | |
79 blobData->setContentType(AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data()); | |
80 } else if (body->IsString()) { | |
81 String stringValue(toUSVString(isolate, body, exceptionState)); | |
82 blobData->appendText(stringValue, false); | |
83 blobData->setContentType("text/plain;charset=UTF-8"); | |
84 } else { | |
85 return; | |
86 } | 60 } |
87 const long long blobSize = blobData->length(); | |
88 bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize); | |
89 } | 61 } |
90 | 62 |
91 } | 63 } |
OLD | NEW |