Chromium Code Reviews| 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 "bindings/core/v8/V8URLSearchParams.h" | 14 #include "bindings/core/v8/V8URLSearchParams.h" |
| 15 #include "bindings/modules/v8/V8PasswordCredential.h" | |
| 16 #include "core/dom/URLSearchParams.h" | |
| 15 #include "core/fileapi/Blob.h" | 17 #include "core/fileapi/Blob.h" |
| 16 #include "core/html/FormData.h" | 18 #include "core/html/FormData.h" |
| 19 #include "modules/credentialmanager/PasswordCredential.h" | |
| 17 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 20 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 18 #include "modules/fetch/FetchFormDataConsumerHandle.h" | 21 #include "modules/fetch/FetchFormDataConsumerHandle.h" |
| 19 #include "modules/fetch/Headers.h" | 22 #include "modules/fetch/Headers.h" |
| 23 #include "platform/NotImplemented.h" | |
|
horo
2015/11/18 05:14:09
remove
Mike West
2015/11/18 09:12:51
Done.
| |
| 20 #include "platform/blob/BlobData.h" | 24 #include "platform/blob/BlobData.h" |
| 21 #include "platform/network/EncodedFormData.h" | 25 #include "platform/network/EncodedFormData.h" |
| 22 #include "platform/weborigin/ReferrerPolicy.h" | 26 #include "platform/weborigin/ReferrerPolicy.h" |
| 23 | 27 |
| 24 namespace blink { | 28 namespace blink { |
| 25 | 29 |
| 26 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState) | 30 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState) |
| 27 : areAnyMembersSet(false) | 31 : areAnyMembersSet(false) |
| 32 , isCredentialRequest(false) | |
| 28 { | 33 { |
| 29 areAnyMembersSet = DictionaryHelper::get(options, "method", method) || areAn yMembersSet; | 34 areAnyMembersSet = DictionaryHelper::get(options, "method", method) || areAn yMembersSet; |
| 30 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers) || are AnyMembersSet; | 35 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers) || are AnyMembersSet; |
| 31 if (!headers) { | 36 if (!headers) { |
| 32 Vector<Vector<String>> headersVector; | 37 Vector<Vector<String>> headersVector; |
| 33 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt ate)) { | 38 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt ate)) { |
| 34 headers = Headers::create(headersVector, exceptionState); | 39 headers = Headers::create(headersVector, exceptionState); |
| 35 areAnyMembersSet = true; | 40 areAnyMembersSet = true; |
| 36 } else { | 41 } else { |
| 37 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers Dictionary) || areAnyMembersSet; | 42 areAnyMembersSet = DictionaryHelper::get(options, "headers", headers Dictionary) || areAnyMembersSet; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 } else if (V8FormData::hasInstance(v8Body, isolate)) { | 81 } else if (V8FormData::hasInstance(v8Body, isolate)) { |
| 77 RefPtr<EncodedFormData> formData = V8FormData::toImpl(v8::Local<v8::Obje ct>::Cast(v8Body))->encodeMultiPartFormData(); | 82 RefPtr<EncodedFormData> formData = V8FormData::toImpl(v8::Local<v8::Obje ct>::Cast(v8Body))->encodeMultiPartFormData(); |
| 78 // Here we handle formData->boundary() as a C-style string. See | 83 // Here we handle formData->boundary() as a C-style string. See |
| 79 // FormDataEncoder::generateUniqueBoundaryString. | 84 // FormDataEncoder::generateUniqueBoundaryString. |
| 80 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin g::ConstructFromLiteral) + formData->boundary().data(); | 85 contentType = AtomicString("multipart/form-data; boundary=", AtomicStrin g::ConstructFromLiteral) + formData->boundary().data(); |
| 81 body = FetchFormDataConsumerHandle::create(context, formData.release()); | 86 body = FetchFormDataConsumerHandle::create(context, formData.release()); |
| 82 } else if (V8URLSearchParams::hasInstance(v8Body, isolate)) { | 87 } else if (V8URLSearchParams::hasInstance(v8Body, isolate)) { |
| 83 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(v8::Local<v 8::Object>::Cast(v8Body))->encodeFormData(); | 88 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(v8::Local<v 8::Object>::Cast(v8Body))->encodeFormData(); |
| 84 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8", AtomicString::ConstructFromLiteral); | 89 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8", AtomicString::ConstructFromLiteral); |
| 85 body = FetchFormDataConsumerHandle::create(context, formData.release()); | 90 body = FetchFormDataConsumerHandle::create(context, formData.release()); |
| 91 } else if (V8PasswordCredential::hasInstance(v8Body, isolate)) { | |
| 92 // See https://w3c.github.io/webappsec-credential-management/#monkey-pat ching-fetch-4 | |
| 93 // and https://w3c.github.io/webappsec-credential-management/#monkey-pat ching-fetch-3 | |
| 94 isCredentialRequest = true; | |
| 95 PasswordCredential* credential = V8PasswordCredential::toImpl(v8::Local< v8::Object>::Cast(v8Body)); | |
| 96 | |
| 97 RefPtr<EncodedFormData> encodedData = credential->encodeFormData(); | |
| 98 if (encodedData->boundary().isEmpty()) | |
| 99 contentType = AtomicString("application/x-www-form-urlencoded;charse t=UTF-8", AtomicString::ConstructFromLiteral); | |
| 100 else | |
| 101 contentType = AtomicString("multipart/form-data; boundary=", AtomicS tring::ConstructFromLiteral) + encodedData->boundary().data(); | |
| 102 body = FetchFormDataConsumerHandle::create(context, encodedData.release( )); | |
| 86 } else if (v8Body->IsString()) { | 103 } else if (v8Body->IsString()) { |
| 87 contentType = "text/plain;charset=UTF-8"; | 104 contentType = "text/plain;charset=UTF-8"; |
| 88 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); | 105 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); |
| 89 } | 106 } |
| 90 } | 107 } |
| 91 | 108 |
| 92 } | 109 } |
| OLD | NEW |