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 "RequestInit.h" | 6 #include "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" |
| 10 #include "bindings/core/v8/V8ArrayBufferView.h" |
9 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
10 #include "bindings/core/v8/V8Blob.h" | 12 #include "bindings/core/v8/V8Blob.h" |
11 #include "bindings/core/v8/V8FormData.h" | 13 #include "bindings/core/v8/V8FormData.h" |
12 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" | |
13 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" | |
14 #include "core/fileapi/Blob.h" | 14 #include "core/fileapi/Blob.h" |
15 #include "modules/serviceworkers/Headers.h" | 15 #include "modules/serviceworkers/Headers.h" |
16 #include "platform/blob/BlobData.h" | 16 #include "platform/blob/BlobData.h" |
17 #include "platform/network/FormData.h" | 17 #include "platform/network/FormData.h" |
18 #include "wtf/ArrayBuffer.h" | 18 #include "wtf/ArrayBuffer.h" |
19 | 19 |
20 namespace blink { | 20 namespace blink { |
21 | 21 |
22 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E
xceptionState& exceptionState) | 22 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E
xceptionState& exceptionState) |
23 { | 23 { |
24 DictionaryHelper::get(options, "method", method); | 24 DictionaryHelper::get(options, "method", method); |
25 DictionaryHelper::get(options, "headers", headers); | 25 DictionaryHelper::get(options, "headers", headers); |
26 if (!headers) { | 26 if (!headers) { |
27 Vector<Vector<String> > headersVector; | 27 Vector<Vector<String> > headersVector; |
28 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt
ate)) | 28 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt
ate)) |
29 headers = Headers::create(headersVector, exceptionState); | 29 headers = Headers::create(headersVector, exceptionState); |
30 else | 30 else |
31 DictionaryHelper::get(options, "headers", headersDictionary); | 31 DictionaryHelper::get(options, "headers", headersDictionary); |
32 } | 32 } |
33 DictionaryHelper::get(options, "mode", mode); | 33 DictionaryHelper::get(options, "mode", mode); |
34 DictionaryHelper::get(options, "credentials", credentials); | 34 DictionaryHelper::get(options, "credentials", credentials); |
35 | 35 |
36 v8::Local<v8::Value> body; | 36 v8::Local<v8::Value> body; |
37 if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() ||
body->IsNull()) | 37 if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() ||
body->IsNull()) |
38 return; | 38 return; |
39 OwnPtr<BlobData> blobData = BlobData::create(); | 39 OwnPtr<BlobData> blobData = BlobData::create(); |
40 v8::Isolate* isolate = toIsolate(context); | 40 v8::Isolate* isolate = toIsolate(context); |
41 if (body->IsArrayBuffer()) { | 41 if (body->IsArrayBuffer()) { |
42 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v8::Object>:
:Cast(body)); | 42 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v8::Objec
t>::Cast(body)); |
43 ASSERT(arrayBuffer); | 43 ASSERT(arrayBuffer); |
44 blobData->appendArrayBuffer(arrayBuffer); | 44 blobData->appendArrayBuffer(arrayBuffer->buffer()); |
45 } else if (body->IsArrayBufferView()) { | 45 } else if (body->IsArrayBufferView()) { |
46 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Handle<
v8::Object>::Cast(body)); | 46 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Hand
le<v8::Object>::Cast(body)); |
47 ASSERT(arrayBufferView); | 47 ASSERT(arrayBufferView); |
48 blobData->appendArrayBufferView(arrayBufferView); | 48 blobData->appendArrayBufferView(arrayBufferView->view()); |
49 } else if (V8Blob::hasInstance(body, isolate)) { | 49 } else if (V8Blob::hasInstance(body, isolate)) { |
50 Blob* blob = V8Blob::toImpl(v8::Handle<v8::Object>::Cast(body)); | 50 Blob* blob = V8Blob::toImpl(v8::Handle<v8::Object>::Cast(body)); |
51 ASSERT(blob); | 51 ASSERT(blob); |
52 blob->appendTo(*blobData); | 52 blob->appendTo(*blobData); |
53 blobData->setContentType(blob->type()); | 53 blobData->setContentType(blob->type()); |
54 } else if (V8FormData::hasInstance(body, isolate)) { | 54 } else if (V8FormData::hasInstance(body, isolate)) { |
55 DOMFormData* domFormData = V8FormData::toImpl(v8::Handle<v8::Object>::Ca
st(body)); | 55 DOMFormData* domFormData = V8FormData::toImpl(v8::Handle<v8::Object>::Ca
st(body)); |
56 ASSERT(domFormData); | 56 ASSERT(domFormData); |
57 RefPtr<FormData> httpBody = domFormData->createMultiPartFormData(); | 57 RefPtr<FormData> httpBody = domFormData->createMultiPartFormData(); |
58 for (size_t i = 0; i < httpBody->elements().size(); ++i) { | 58 for (size_t i = 0; i < httpBody->elements().size(); ++i) { |
(...skipping 23 matching lines...) Expand all Loading... |
82 blobData->appendText(stringValue, false); | 82 blobData->appendText(stringValue, false); |
83 blobData->setContentType("text/plain;charset=UTF-8"); | 83 blobData->setContentType("text/plain;charset=UTF-8"); |
84 } else { | 84 } else { |
85 return; | 85 return; |
86 } | 86 } |
87 const long long blobSize = blobData->length(); | 87 const long long blobSize = blobData->length(); |
88 bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize); | 88 bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize); |
89 } | 89 } |
90 | 90 |
91 } | 91 } |
OLD | NEW |