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/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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "modules/fetch/DataConsumerHandleUtil.h" | 22 #include "modules/fetch/DataConsumerHandleUtil.h" |
23 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 23 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
24 #include "modules/fetch/FetchFormDataConsumerHandle.h" | 24 #include "modules/fetch/FetchFormDataConsumerHandle.h" |
25 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" | 25 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
26 #include "modules/fetch/ResponseInit.h" | 26 #include "modules/fetch/ResponseInit.h" |
27 #include "platform/RuntimeEnabledFeatures.h" | 27 #include "platform/RuntimeEnabledFeatures.h" |
28 #include "platform/network/EncodedFormData.h" | 28 #include "platform/network/EncodedFormData.h" |
29 #include "platform/network/HTTPHeaderMap.h" | 29 #include "platform/network/HTTPHeaderMap.h" |
30 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" | 30 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" |
31 #include "wtf/RefPtr.h" | 31 #include "wtf/RefPtr.h" |
32 #include <memory> | |
33 | 32 |
34 namespace blink { | 33 namespace blink { |
35 | 34 |
36 namespace { | 35 namespace { |
37 | 36 |
38 FetchResponseData* createFetchResponseDataFromWebResponse(ScriptState* scriptSta
te, const WebServiceWorkerResponse& webResponse) | 37 FetchResponseData* createFetchResponseDataFromWebResponse(ScriptState* scriptSta
te, const WebServiceWorkerResponse& webResponse) |
39 { | 38 { |
40 FetchResponseData* response = nullptr; | 39 FetchResponseData* response = nullptr; |
41 if (webResponse.status() > 0) | 40 if (webResponse.status() > 0) |
42 response = FetchResponseData::create(); | 41 response = FetchResponseData::create(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } else if (V8FormData::hasInstance(body, isolate)) { | 139 } else if (V8FormData::hasInstance(body, isolate)) { |
141 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object
>())->encodeMultiPartFormData(); | 140 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object
>())->encodeMultiPartFormData(); |
142 // Here we handle formData->boundary() as a C-style string. See | 141 // Here we handle formData->boundary() as a C-style string. See |
143 // FormDataEncoder::generateUniqueBoundaryString. | 142 // FormDataEncoder::generateUniqueBoundaryString. |
144 contentType = AtomicString("multipart/form-data; boundary=") + formData-
>boundary().data(); | 143 contentType = AtomicString("multipart/form-data; boundary=") + formData-
>boundary().data(); |
145 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand
le::create(executionContext, formData.release())); | 144 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand
le::create(executionContext, formData.release())); |
146 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab
led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { | 145 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab
led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { |
147 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 146 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
148 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue); | 147 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue); |
149 } else { | 148 } else { |
150 std::unique_ptr<FetchDataConsumerHandle> bodyHandle; | 149 OwnPtr<FetchDataConsumerHandle> bodyHandle; |
151 reader = ReadableStreamOperations::getReader(scriptState, bodyValue,
exceptionState); | 150 reader = ReadableStreamOperations::getReader(scriptState, bodyValue,
exceptionState); |
152 if (exceptionState.hadException()) { | 151 if (exceptionState.hadException()) { |
153 reader = ScriptValue(); | 152 reader = ScriptValue(); |
154 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn
expectedErrorDataConsumerHandle()); | 153 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn
expectedErrorDataConsumerHandle()); |
155 exceptionState.clearException(); | 154 exceptionState.clearException(); |
156 } else { | 155 } else { |
157 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat
e, reader); | 156 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat
e, reader); |
158 } | 157 } |
159 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle)
); | 158 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle)
); |
160 } | 159 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 447 } |
449 | 448 |
450 DEFINE_TRACE(Response) | 449 DEFINE_TRACE(Response) |
451 { | 450 { |
452 Body::trace(visitor); | 451 Body::trace(visitor); |
453 visitor->trace(m_response); | 452 visitor->trace(m_response); |
454 visitor->trace(m_headers); | 453 visitor->trace(m_headers); |
455 } | 454 } |
456 | 455 |
457 } // namespace blink | 456 } // namespace blink |
OLD | NEW |