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

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

Issue 2227403002: Remove blink::ReadableStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 4 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
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 "bindings/core/v8/V8URLSearchParams.h"
17 #include "core/dom/DOMArrayBuffer.h" 17 #include "core/dom/DOMArrayBuffer.h"
18 #include "core/dom/DOMArrayBufferView.h" 18 #include "core/dom/DOMArrayBufferView.h"
19 #include "core/dom/URLSearchParams.h" 19 #include "core/dom/URLSearchParams.h"
20 #include "core/fileapi/Blob.h" 20 #include "core/fileapi/Blob.h"
21 #include "core/html/FormData.h" 21 #include "core/html/FormData.h"
22 #include "core/streams/ReadableStreamOperations.h" 22 #include "core/streams/ReadableStreamOperations.h"
23 #include "modules/fetch/BodyStreamBuffer.h" 23 #include "modules/fetch/BodyStreamBuffer.h"
24 #include "modules/fetch/DataConsumerHandleUtil.h" 24 #include "modules/fetch/DataConsumerHandleUtil.h"
25 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 25 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
26 #include "modules/fetch/FetchFormDataConsumerHandle.h" 26 #include "modules/fetch/FetchFormDataConsumerHandle.h"
27 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" 27 #include "modules/fetch/ReadableStreamDataConsumerHandle.h"
28 #include "modules/fetch/ResponseInit.h" 28 #include "modules/fetch/ResponseInit.h"
29 #include "platform/RuntimeEnabledFeatures.h"
30 #include "platform/network/EncodedFormData.h" 29 #include "platform/network/EncodedFormData.h"
31 #include "platform/network/HTTPHeaderMap.h" 30 #include "platform/network/HTTPHeaderMap.h"
32 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" 31 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
33 #include "wtf/RefPtr.h" 32 #include "wtf/RefPtr.h"
34 #include <memory> 33 #include <memory>
35 34
36 namespace blink { 35 namespace blink {
37 36
38 namespace { 37 namespace {
39 38
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } else if (V8FormData::hasInstance(body, isolate)) { 141 } else if (V8FormData::hasInstance(body, isolate)) {
143 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object >())->encodeMultiPartFormData(); 142 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object >())->encodeMultiPartFormData();
144 // Here we handle formData->boundary() as a C-style string. See 143 // Here we handle formData->boundary() as a C-style string. See
145 // FormDataEncoder::generateUniqueBoundaryString. 144 // FormDataEncoder::generateUniqueBoundaryString.
146 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data(); 145 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data();
147 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release())); 146 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release()));
148 } else if (V8URLSearchParams::hasInstance(body, isolate)) { 147 } else if (V8URLSearchParams::hasInstance(body, isolate)) {
149 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(body.As<v8: :Object>())->toEncodedFormData(); 148 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(body.As<v8: :Object>())->toEncodedFormData();
150 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release())); 149 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release()));
151 contentType = "application/x-www-form-urlencoded;charset=UTF-8"; 150 contentType = "application/x-www-form-urlencoded;charset=UTF-8";
152 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { 151 } else if (ReadableStreamOperations::isReadableStream(scriptState, bodyValue )) {
153 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { 152 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue);
154 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue);
155 } else {
156 std::unique_ptr<FetchDataConsumerHandle> bodyHandle;
157 reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState);
158 if (exceptionState.hadException()) {
159 reader = ScriptValue();
160 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn expectedErrorDataConsumerHandle());
161 exceptionState.clearException();
162 } else {
163 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat e, reader);
164 }
165 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle) );
166 }
167 } else { 153 } else {
168 String string = toUSVString(isolate, body, exceptionState); 154 String string = toUSVString(isolate, body, exceptionState);
169 if (exceptionState.hadException()) 155 if (exceptionState.hadException())
170 return nullptr; 156 return nullptr;
171 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(string)); 157 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(string));
172 contentType = "text/plain;charset=UTF-8"; 158 contentType = "text/plain;charset=UTF-8";
173 } 159 }
174 Response* response = create(scriptState, bodyBuffer, contentType, ResponseIn it(init, exceptionState), exceptionState); 160 Response* response = create(scriptState, bodyBuffer, contentType, ResponseIn it(init, exceptionState), exceptionState);
175 if (!exceptionState.hadException() && !reader.isEmpty()) { 161 if (!exceptionState.hadException() && !reader.isEmpty()) {
176 // Add a hidden reference so that the weak persistent in the 162 // Add a hidden reference so that the weak persistent in the
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 438 }
453 439
454 DEFINE_TRACE(Response) 440 DEFINE_TRACE(Response)
455 { 441 {
456 Body::trace(visitor); 442 Body::trace(visitor);
457 visitor->trace(m_response); 443 visitor->trace(m_response);
458 visitor->trace(m_headers); 444 visitor->trace(m_headers);
459 } 445 }
460 446
461 } // namespace blink 447 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698