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 } | 31 } |
32 DictionaryHelper::get(options, "mode", mode); | 32 DictionaryHelper::get(options, "mode", mode); |
33 DictionaryHelper::get(options, "credentials", credentials); | 33 DictionaryHelper::get(options, "credentials", credentials); |
34 | 34 |
35 v8::Local<v8::Value> body; | 35 v8::Local<v8::Value> body; |
36 if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() ||
body->IsNull()) | 36 if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() ||
body->IsNull()) |
37 return; | 37 return; |
38 OwnPtr<BlobData> blobData = BlobData::create(); | 38 OwnPtr<BlobData> blobData = BlobData::create(); |
39 v8::Isolate* isolate = toIsolate(context); | 39 v8::Isolate* isolate = toIsolate(context); |
40 if (body->IsArrayBuffer()) { | 40 if (body->IsArrayBuffer()) { |
41 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v8::Objec
t>::Cast(body)); | 41 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Local<v8::Object
>::Cast(body)); |
42 ASSERT(arrayBuffer); | 42 ASSERT(arrayBuffer); |
43 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength()); | 43 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength()); |
44 } else if (body->IsArrayBufferView()) { | 44 } else if (body->IsArrayBufferView()) { |
45 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Hand
le<v8::Object>::Cast(body)); | 45 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Loca
l<v8::Object>::Cast(body)); |
46 ASSERT(arrayBufferView); | 46 ASSERT(arrayBufferView); |
47 blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferView->b
yteLength()); | 47 blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferView->b
yteLength()); |
48 } else if (V8Blob::hasInstance(body, isolate)) { | 48 } else if (V8Blob::hasInstance(body, isolate)) { |
49 Blob* blob = V8Blob::toImpl(v8::Handle<v8::Object>::Cast(body)); | 49 Blob* blob = V8Blob::toImpl(v8::Local<v8::Object>::Cast(body)); |
50 ASSERT(blob); | 50 ASSERT(blob); |
51 blob->appendTo(*blobData); | 51 blob->appendTo(*blobData); |
52 blobData->setContentType(blob->type()); | 52 blobData->setContentType(blob->type()); |
53 } else if (V8FormData::hasInstance(body, isolate)) { | 53 } else if (V8FormData::hasInstance(body, isolate)) { |
54 DOMFormData* domFormData = V8FormData::toImpl(v8::Handle<v8::Object>::Ca
st(body)); | 54 DOMFormData* domFormData = V8FormData::toImpl(v8::Local<v8::Object>::Cas
t(body)); |
55 ASSERT(domFormData); | 55 ASSERT(domFormData); |
56 RefPtr<FormData> httpBody = domFormData->createMultiPartFormData(); | 56 RefPtr<FormData> httpBody = domFormData->createMultiPartFormData(); |
57 for (size_t i = 0; i < httpBody->elements().size(); ++i) { | 57 for (size_t i = 0; i < httpBody->elements().size(); ++i) { |
58 const FormDataElement& element = httpBody->elements()[i]; | 58 const FormDataElement& element = httpBody->elements()[i]; |
59 switch (element.m_type) { | 59 switch (element.m_type) { |
60 case FormDataElement::data: { | 60 case FormDataElement::data: { |
61 blobData->appendBytes(element.m_data.data(), element.m_data.size
()); | 61 blobData->appendBytes(element.m_data.data(), element.m_data.size
()); |
62 break; | 62 break; |
63 } | 63 } |
64 case FormDataElement::encodedFile: | 64 case FormDataElement::encodedFile: |
(...skipping 16 matching lines...) Expand all Loading... |
81 blobData->appendText(stringValue, false); | 81 blobData->appendText(stringValue, false); |
82 blobData->setContentType("text/plain;charset=UTF-8"); | 82 blobData->setContentType("text/plain;charset=UTF-8"); |
83 } else { | 83 } else { |
84 return; | 84 return; |
85 } | 85 } |
86 const long long blobSize = blobData->length(); | 86 const long long blobSize = blobData->length(); |
87 bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize); | 87 bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize); |
88 } | 88 } |
89 | 89 |
90 } | 90 } |
OLD | NEW |