Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: third_party/WebKit/Source/modules/fetch/Response.cpp

Issue 2163273002: [Fetch] Accept URLSearchParams in Response constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: var => const, an => a, -TODO Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-content.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/Response.h" 5 #include "modules/fetch/Response.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8ArrayBuffer.h" 10 #include "bindings/core/v8/V8ArrayBuffer.h"
11 #include "bindings/core/v8/V8ArrayBufferView.h" 11 #include "bindings/core/v8/V8ArrayBufferView.h"
12 #include "bindings/core/v8/V8Binding.h" 12 #include "bindings/core/v8/V8Binding.h"
13 #include "bindings/core/v8/V8Blob.h" 13 #include "bindings/core/v8/V8Blob.h"
14 #include "bindings/core/v8/V8FormData.h" 14 #include "bindings/core/v8/V8FormData.h"
15 #include "bindings/core/v8/V8HiddenValue.h" 15 #include "bindings/core/v8/V8HiddenValue.h"
16 #include "bindings/core/v8/V8URLSearchParams.h"
16 #include "core/dom/DOMArrayBuffer.h" 17 #include "core/dom/DOMArrayBuffer.h"
17 #include "core/dom/DOMArrayBufferView.h" 18 #include "core/dom/DOMArrayBufferView.h"
19 #include "core/dom/URLSearchParams.h"
18 #include "core/fileapi/Blob.h" 20 #include "core/fileapi/Blob.h"
19 #include "core/html/FormData.h" 21 #include "core/html/FormData.h"
20 #include "core/streams/ReadableStreamOperations.h" 22 #include "core/streams/ReadableStreamOperations.h"
21 #include "modules/fetch/BodyStreamBuffer.h" 23 #include "modules/fetch/BodyStreamBuffer.h"
22 #include "modules/fetch/DataConsumerHandleUtil.h" 24 #include "modules/fetch/DataConsumerHandleUtil.h"
23 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 25 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
24 #include "modules/fetch/FetchFormDataConsumerHandle.h" 26 #include "modules/fetch/FetchFormDataConsumerHandle.h"
25 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" 27 #include "modules/fetch/ReadableStreamDataConsumerHandle.h"
26 #include "modules/fetch/ResponseInit.h" 28 #include "modules/fetch/ResponseInit.h"
27 #include "platform/RuntimeEnabledFeatures.h" 29 #include "platform/RuntimeEnabledFeatures.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } else if (body->IsArrayBuffer()) { 138 } else if (body->IsArrayBuffer()) {
137 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBuffer::toImpl(body.As<v8::Object>()))); 139 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBuffer::toImpl(body.As<v8::Object>())));
138 } else if (body->IsArrayBufferView()) { 140 } else if (body->IsArrayBufferView()) {
139 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBufferView::toImpl(body.As<v8::Object>()))); 141 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBufferView::toImpl(body.As<v8::Object>())));
140 } else if (V8FormData::hasInstance(body, isolate)) { 142 } else if (V8FormData::hasInstance(body, isolate)) {
141 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object >())->encodeMultiPartFormData(); 143 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object >())->encodeMultiPartFormData();
142 // Here we handle formData->boundary() as a C-style string. See 144 // Here we handle formData->boundary() as a C-style string. See
143 // FormDataEncoder::generateUniqueBoundaryString. 145 // FormDataEncoder::generateUniqueBoundaryString.
144 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data(); 146 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data();
145 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release())); 147 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release()));
148 } else if (V8URLSearchParams::hasInstance(body, isolate)) {
149 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(body.As<v8: :Object>())->toEncodedFormData();
150 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release()));
151 contentType = "application/x-www-form-urlencoded;charset=UTF-8";
146 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { 152 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) {
147 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { 153 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) {
148 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue); 154 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue);
149 } else { 155 } else {
150 std::unique_ptr<FetchDataConsumerHandle> bodyHandle; 156 std::unique_ptr<FetchDataConsumerHandle> bodyHandle;
151 reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState); 157 reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState);
152 if (exceptionState.hadException()) { 158 if (exceptionState.hadException()) {
153 reader = ScriptValue(); 159 reader = ScriptValue();
154 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn expectedErrorDataConsumerHandle()); 160 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn expectedErrorDataConsumerHandle());
155 exceptionState.clearException(); 161 exceptionState.clearException();
156 } else { 162 } else {
157 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat e, reader); 163 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat e, reader);
158 } 164 }
159 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle) ); 165 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle) );
160 } 166 }
161 } else { 167 } else {
162 String string = toUSVString(isolate, body, exceptionState); 168 String string = toUSVString(isolate, body, exceptionState);
163 if (exceptionState.hadException()) 169 if (exceptionState.hadException())
164 return nullptr; 170 return nullptr;
165 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(string)); 171 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(string));
166 contentType = "text/plain;charset=UTF-8"; 172 contentType = "text/plain;charset=UTF-8";
167 } 173 }
168 // TODO(yhirano): Add the URLSearchParams case.
169 Response* response = create(scriptState, bodyBuffer, contentType, ResponseIn it(init, exceptionState), exceptionState); 174 Response* response = create(scriptState, bodyBuffer, contentType, ResponseIn it(init, exceptionState), exceptionState);
170 if (!exceptionState.hadException() && !reader.isEmpty()) { 175 if (!exceptionState.hadException() && !reader.isEmpty()) {
171 // Add a hidden reference so that the weak persistent in the 176 // Add a hidden reference so that the weak persistent in the
172 // ReadableStreamDataConsumerHandle will be valid as long as the 177 // ReadableStreamDataConsumerHandle will be valid as long as the
173 // Response is valid. 178 // Response is valid.
174 v8::Local<v8::Value> wrapper = toV8(response, scriptState); 179 v8::Local<v8::Value> wrapper = toV8(response, scriptState);
175 if (wrapper.IsEmpty()) { 180 if (wrapper.IsEmpty()) {
176 exceptionState.throwTypeError("Cannot create a Response wrapper"); 181 exceptionState.throwTypeError("Cannot create a Response wrapper");
177 return nullptr; 182 return nullptr;
178 } 183 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 452 }
448 453
449 DEFINE_TRACE(Response) 454 DEFINE_TRACE(Response)
450 { 455 {
451 Body::trace(visitor); 456 Body::trace(visitor);
452 visitor->trace(m_response); 457 visitor->trace(m_response);
453 visitor->trace(m_headers); 458 visitor->trace(m_headers);
454 } 459 }
455 460
456 } // namespace blink 461 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-content.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698