| 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 "modules/fetch/RequestInit.h" | 5 #include "modules/fetch/RequestInit.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 9 #include "bindings/core/v8/V8ArrayBufferView.h" | 9 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| 11 #include "bindings/core/v8/V8Blob.h" | 11 #include "bindings/core/v8/V8Blob.h" |
| 12 #include "bindings/core/v8/V8FormData.h" | 12 #include "bindings/core/v8/V8FormData.h" |
| 13 #include "bindings/core/v8/V8URLSearchParams.h" | 13 #include "bindings/core/v8/V8URLSearchParams.h" |
| 14 #include "bindings/modules/v8/ByteStringSequenceSequenceOrByteStringByteStringRe
cordOrHeaders.h" |
| 14 #include "bindings/modules/v8/V8PasswordCredential.h" | 15 #include "bindings/modules/v8/V8PasswordCredential.h" |
| 15 #include "core/dom/URLSearchParams.h" | 16 #include "core/dom/URLSearchParams.h" |
| 16 #include "core/fileapi/Blob.h" | 17 #include "core/fileapi/Blob.h" |
| 17 #include "core/html/FormData.h" | 18 #include "core/html/FormData.h" |
| 18 #include "modules/fetch/BlobBytesConsumer.h" | 19 #include "modules/fetch/BlobBytesConsumer.h" |
| 19 #include "modules/fetch/FormDataBytesConsumer.h" | 20 #include "modules/fetch/FormDataBytesConsumer.h" |
| 20 #include "modules/fetch/Headers.h" | 21 #include "modules/fetch/Headers.h" |
| 21 #include "platform/RuntimeEnabledFeatures.h" | 22 #include "platform/RuntimeEnabledFeatures.h" |
| 22 #include "platform/blob/BlobData.h" | 23 #include "platform/blob/BlobData.h" |
| 23 #include "platform/network/EncodedFormData.h" | 24 #include "platform/network/EncodedFormData.h" |
| 24 #include "platform/weborigin/ReferrerPolicy.h" | 25 #include "platform/weborigin/ReferrerPolicy.h" |
| 25 | 26 |
| 26 namespace blink { | 27 namespace blink { |
| 27 | 28 |
| 28 // TODO(yiyix): Verify if any DictionaryHelper::get should be replaced with | 29 // TODO(yiyix): Verify if any DictionaryHelper::get should be replaced with |
| 29 // DictionaryHelper::getWithUndefinedCheck. | 30 // DictionaryHelper::getWithUndefinedCheck. |
| 30 RequestInit::RequestInit(ExecutionContext* context, | 31 RequestInit::RequestInit(ExecutionContext* context, |
| 31 const Dictionary& options, | 32 const Dictionary& options, |
| 32 ExceptionState& exception_state) | 33 ExceptionState& exception_state) |
| 33 : are_any_members_set(false) { | 34 : are_any_members_set(false) { |
| 34 are_any_members_set |= DictionaryHelper::Get(options, "method", method); | 35 are_any_members_set |= DictionaryHelper::Get(options, "method", method); |
| 35 are_any_members_set |= DictionaryHelper::Get(options, "headers", headers); | 36 |
| 36 if (!headers) { | 37 // From https://github.com/whatwg/fetch/issues/479: |
| 37 Vector<Vector<String>> headers_vector; | 38 // - undefined is the same as "this member has not been passed". |
| 38 if (DictionaryHelper::Get(options, "headers", headers_vector, | 39 // - {} means "the list of headers is empty", so the member has been set. |
| 39 exception_state)) { | 40 // - null is an invalid value for both sequences and records, but it is not |
| 40 headers = Headers::Create(headers_vector, exception_state); | 41 // the same as undefined: a value has been set, even if invalid, and will |
| 41 are_any_members_set = true; | 42 // throw a TypeError later when it gets converted to a HeadersInit object. |
| 42 } else { | 43 v8::Local<v8::Value> v8_headers; |
| 43 are_any_members_set |= | 44 bool is_header_set = DictionaryHelper::Get(options, "headers", v8_headers) && |
| 44 DictionaryHelper::Get(options, "headers", headers_dictionary); | 45 !v8_headers->IsUndefined(); |
| 45 } | 46 are_any_members_set |= is_header_set; |
| 46 } | 47 |
| 47 are_any_members_set |= DictionaryHelper::Get(options, "mode", mode); | 48 are_any_members_set |= DictionaryHelper::Get(options, "mode", mode); |
| 48 are_any_members_set |= DictionaryHelper::Get(options, "redirect", redirect); | 49 are_any_members_set |= DictionaryHelper::Get(options, "redirect", redirect); |
| 49 AtomicString referrer_string; | 50 AtomicString referrer_string; |
| 50 bool is_referrer_string_set = DictionaryHelper::GetWithUndefinedCheck( | 51 bool is_referrer_string_set = DictionaryHelper::GetWithUndefinedCheck( |
| 51 options, "referrer", referrer_string); | 52 options, "referrer", referrer_string); |
| 52 are_any_members_set |= is_referrer_string_set; | 53 are_any_members_set |= is_referrer_string_set; |
| 53 are_any_members_set |= DictionaryHelper::Get(options, "integrity", integrity); | 54 are_any_members_set |= DictionaryHelper::Get(options, "integrity", integrity); |
| 54 AtomicString referrer_policy_string; | 55 AtomicString referrer_policy_string; |
| 55 bool is_referrer_policy_set = | 56 bool is_referrer_policy_set = |
| 56 DictionaryHelper::Get(options, "referrerPolicy", referrer_policy_string); | 57 DictionaryHelper::Get(options, "referrerPolicy", referrer_policy_string); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 referrer.referrer_policy = | 95 referrer.referrer_policy = |
| 95 kReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin; | 96 kReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin; |
| 96 } else { | 97 } else { |
| 97 exception_state.ThrowTypeError("Invalid referrer policy"); | 98 exception_state.ThrowTypeError("Invalid referrer policy"); |
| 98 return; | 99 return; |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 v8::Isolate* isolate = ToIsolate(context); | 104 v8::Isolate* isolate = ToIsolate(context); |
| 105 |
| 106 if (is_header_set) { |
| 107 ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders |
| 108 headers_init; |
| 109 V8ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders::toImpl( |
| 110 isolate, v8_headers, headers_init, |
| 111 UnionTypeConversionMode::kNotNullable, exception_state); |
| 112 if (exception_state.HadException()) |
| 113 return; |
| 114 headers = Headers::Create(headers_init, exception_state); |
| 115 if (exception_state.HadException()) |
| 116 return; |
| 117 } |
| 118 |
| 104 if (is_credential_set) { | 119 if (is_credential_set) { |
| 105 if (V8PasswordCredential::hasInstance(v8_credential, isolate)) { | 120 if (V8PasswordCredential::hasInstance(v8_credential, isolate)) { |
| 106 // TODO(mkwst): According to the spec, we'd serialize this once we touch | 121 // TODO(mkwst): According to the spec, we'd serialize this once we touch |
| 107 // the network. We're serializing it here, ahead of time, because lifetime | 122 // the network. We're serializing it here, ahead of time, because lifetime |
| 108 // issues around ResourceRequest make it pretty difficult to pass a | 123 // issues around ResourceRequest make it pretty difficult to pass a |
| 109 // PasswordCredential around at the platform level, and the hop between | 124 // PasswordCredential around at the platform level, and the hop between |
| 110 // the browser and renderer processes to deal with service workers is | 125 // the browser and renderer processes to deal with service workers is |
| 111 // equally painful. There should be no developer-visible difference in | 126 // equally painful. There should be no developer-visible difference in |
| 112 // behavior with this option, except that the `Content-Type` header will | 127 // behavior with this option, except that the `Content-Type` header will |
| 113 // be set early. That seems reasonable. | 128 // be set early. That seems reasonable. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 AtomicString("application/x-www-form-urlencoded;charset=UTF-8"); | 166 AtomicString("application/x-www-form-urlencoded;charset=UTF-8"); |
| 152 body = new FormDataBytesConsumer(context, form_data.Release()); | 167 body = new FormDataBytesConsumer(context, form_data.Release()); |
| 153 } else if (v8_body->IsString()) { | 168 } else if (v8_body->IsString()) { |
| 154 content_type = "text/plain;charset=UTF-8"; | 169 content_type = "text/plain;charset=UTF-8"; |
| 155 body = new FormDataBytesConsumer( | 170 body = new FormDataBytesConsumer( |
| 156 ToUSVString(isolate, v8_body, exception_state)); | 171 ToUSVString(isolate, v8_body, exception_state)); |
| 157 } | 172 } |
| 158 } | 173 } |
| 159 | 174 |
| 160 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |