| 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/FormData.h" | 15 #include "core/html/FormData.h" |
| 16 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 16 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 17 #include "modules/fetch/FetchFormDataConsumerHandle.h" | 17 #include "modules/fetch/FetchFormDataConsumerHandle.h" |
| 18 #include "modules/fetch/Headers.h" | 18 #include "modules/fetch/Headers.h" |
| 19 #include "platform/blob/BlobData.h" | 19 #include "platform/blob/BlobData.h" |
| 20 #include "platform/network/EncodedFormData.h" | 20 #include "platform/network/EncodedFormData.h" |
| 21 #include "platform/weborigin/ReferrerPolicy.h" | 21 #include "platform/weborigin/ReferrerPolicy.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E
xceptionState& exceptionState) | 25 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E
xceptionState& exceptionState) |
| 26 : isReferrerSet(false) | 26 : areAnyMembersSet(false) |
| 27 { | 27 { |
| 28 bool areAnyMembersSet = false; | |
| 29 | |
| 30 areAnyMembersSet = DictionaryHelper::get(options, "method", method) || areAn
yMembersSet; | 28 areAnyMembersSet = DictionaryHelper::get(options, "method", method) || areAn
yMembersSet; |
| 31 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers) || are
AnyMembersSet; | 29 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers) || are
AnyMembersSet; |
| 32 if (!headers) { | 30 if (!headers) { |
| 33 Vector<Vector<String>> headersVector; | 31 Vector<Vector<String>> headersVector; |
| 34 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt
ate)) { | 32 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt
ate)) { |
| 35 headers = Headers::create(headersVector, exceptionState); | 33 headers = Headers::create(headersVector, exceptionState); |
| 36 areAnyMembersSet = true; | 34 areAnyMembersSet = true; |
| 37 } else { | 35 } else { |
| 38 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers
Dictionary) || areAnyMembersSet; | 36 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers
Dictionary) || areAnyMembersSet; |
| 39 } | 37 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 // If any of init's members are present, unset request's | 52 // If any of init's members are present, unset request's |
| 55 // omit-Origin-header flag, set request's referrer to "client", | 53 // omit-Origin-header flag, set request's referrer to "client", |
| 56 // and request's referrer policy to the empty string. | 54 // and request's referrer policy to the empty string. |
| 57 // | 55 // |
| 58 // We need to use "about:client" instead of |clientReferrerString|, | 56 // We need to use "about:client" instead of |clientReferrerString|, |
| 59 // because "about:client" => |clientReferrerString| conversion is done | 57 // because "about:client" => |clientReferrerString| conversion is done |
| 60 // in Request::createRequestWithRequestOrString. | 58 // in Request::createRequestWithRequestOrString. |
| 61 referrer = Referrer("about:client", ReferrerPolicyDefault); | 59 referrer = Referrer("about:client", ReferrerPolicyDefault); |
| 62 if (isReferrerStringSet) | 60 if (isReferrerStringSet) |
| 63 referrer.referrer = referrerString; | 61 referrer.referrer = referrerString; |
| 64 isReferrerSet = true; | |
| 65 } | 62 } |
| 66 | 63 |
| 67 if (!isBodySet || v8Body->IsUndefined() || v8Body->IsNull()) | 64 if (!isBodySet || v8Body->IsUndefined() || v8Body->IsNull()) |
| 68 return; | 65 return; |
| 69 v8::Isolate* isolate = toIsolate(context); | 66 v8::Isolate* isolate = toIsolate(context); |
| 70 if (v8Body->IsArrayBuffer()) { | 67 if (v8Body->IsArrayBuffer()) { |
| 71 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc
al<v8::Object>::Cast(v8Body))); | 68 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc
al<v8::Object>::Cast(v8Body))); |
| 72 } else if (v8Body->IsArrayBufferView()) { | 69 } else if (v8Body->IsArrayBufferView()) { |
| 73 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8:
:Local<v8::Object>::Cast(v8Body))); | 70 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8:
:Local<v8::Object>::Cast(v8Body))); |
| 74 } else if (V8Blob::hasInstance(v8Body, isolate)) { | 71 } else if (V8Blob::hasInstance(v8Body, isolate)) { |
| 75 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj
ect>::Cast(v8Body))->blobDataHandle(); | 72 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj
ect>::Cast(v8Body))->blobDataHandle(); |
| 76 contentType = blobDataHandle->type(); | 73 contentType = blobDataHandle->type(); |
| 77 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea
se()); | 74 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea
se()); |
| 78 } else if (V8FormData::hasInstance(v8Body, isolate)) { | 75 } else if (V8FormData::hasInstance(v8Body, isolate)) { |
| 79 RefPtr<EncodedFormData> formData = V8FormData::toImpl(v8::Local<v8::Obje
ct>::Cast(v8Body))->encodeMultiPartFormData(); | 76 RefPtr<EncodedFormData> formData = V8FormData::toImpl(v8::Local<v8::Obje
ct>::Cast(v8Body))->encodeMultiPartFormData(); |
| 80 // Here we handle formData->boundary() as a C-style string. See | 77 // Here we handle formData->boundary() as a C-style string. See |
| 81 // FormDataEncoder::generateUniqueBoundaryString. | 78 // FormDataEncoder::generateUniqueBoundaryString. |
| 82 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin
g::ConstructFromLiteral) + formData->boundary().data(); | 79 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin
g::ConstructFromLiteral) + formData->boundary().data(); |
| 83 body = FetchFormDataConsumerHandle::create(context, formData.release()); | 80 body = FetchFormDataConsumerHandle::create(context, formData.release()); |
| 84 } else if (v8Body->IsString()) { | 81 } else if (v8Body->IsString()) { |
| 85 contentType = "text/plain;charset=UTF-8"; | 82 contentType = "text/plain;charset=UTF-8"; |
| 86 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body,
exceptionState)); | 83 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body,
exceptionState)); |
| 87 } | 84 } |
| 88 } | 85 } |
| 89 | 86 |
| 90 } | 87 } |
| OLD | NEW |