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

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

Issue 2704443007: Count Response construction with ReadableStream (Closed)
Patch Set: fix Created 3 years, 10 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 <memory>
7 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8ArrayBuffer.h" 11 #include "bindings/core/v8/V8ArrayBuffer.h"
11 #include "bindings/core/v8/V8ArrayBufferView.h" 12 #include "bindings/core/v8/V8ArrayBufferView.h"
12 #include "bindings/core/v8/V8Binding.h" 13 #include "bindings/core/v8/V8Binding.h"
13 #include "bindings/core/v8/V8Blob.h" 14 #include "bindings/core/v8/V8Blob.h"
14 #include "bindings/core/v8/V8FormData.h" 15 #include "bindings/core/v8/V8FormData.h"
15 #include "bindings/core/v8/V8HiddenValue.h" 16 #include "bindings/core/v8/V8HiddenValue.h"
16 #include "bindings/core/v8/V8URLSearchParams.h" 17 #include "bindings/core/v8/V8URLSearchParams.h"
17 #include "bindings/modules/v8/ByteStringSequenceSequenceOrDictionaryOrHeaders.h" 18 #include "bindings/modules/v8/ByteStringSequenceSequenceOrDictionaryOrHeaders.h"
18 #include "core/dom/DOMArrayBuffer.h" 19 #include "core/dom/DOMArrayBuffer.h"
19 #include "core/dom/DOMArrayBufferView.h" 20 #include "core/dom/DOMArrayBufferView.h"
20 #include "core/dom/URLSearchParams.h" 21 #include "core/dom/URLSearchParams.h"
21 #include "core/fileapi/Blob.h" 22 #include "core/fileapi/Blob.h"
23 #include "core/frame/UseCounter.h"
22 #include "core/html/FormData.h" 24 #include "core/html/FormData.h"
23 #include "core/streams/ReadableStreamOperations.h" 25 #include "core/streams/ReadableStreamOperations.h"
24 #include "modules/fetch/BlobBytesConsumer.h" 26 #include "modules/fetch/BlobBytesConsumer.h"
25 #include "modules/fetch/BodyStreamBuffer.h" 27 #include "modules/fetch/BodyStreamBuffer.h"
26 #include "modules/fetch/FormDataBytesConsumer.h" 28 #include "modules/fetch/FormDataBytesConsumer.h"
27 #include "modules/fetch/ResponseInit.h" 29 #include "modules/fetch/ResponseInit.h"
28 #include "platform/loader/fetch/FetchUtils.h" 30 #include "platform/loader/fetch/FetchUtils.h"
29 #include "platform/network/EncodedFormData.h" 31 #include "platform/network/EncodedFormData.h"
30 #include "platform/network/HTTPHeaderMap.h" 32 #include "platform/network/HTTPHeaderMap.h"
31 #include "platform/network/NetworkUtils.h" 33 #include "platform/network/NetworkUtils.h"
32 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" 34 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
33 #include "wtf/RefPtr.h" 35 #include "wtf/RefPtr.h"
34 #include <memory>
35 36
36 namespace blink { 37 namespace blink {
37 38
38 namespace { 39 namespace {
39 40
40 FetchResponseData* createFetchResponseDataFromWebResponse( 41 FetchResponseData* createFetchResponseDataFromWebResponse(
41 ScriptState* scriptState, 42 ScriptState* scriptState,
42 const WebServiceWorkerResponse& webResponse) { 43 const WebServiceWorkerResponse& webResponse) {
43 FetchResponseData* response = nullptr; 44 FetchResponseData* response = nullptr;
44 if (webResponse.status() > 0) 45 if (webResponse.status() > 0)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 new FormDataBytesConsumer(executionContext, formData.release())); 166 new FormDataBytesConsumer(executionContext, formData.release()));
166 } else if (V8URLSearchParams::hasInstance(body, isolate)) { 167 } else if (V8URLSearchParams::hasInstance(body, isolate)) {
167 RefPtr<EncodedFormData> formData = 168 RefPtr<EncodedFormData> formData =
168 V8URLSearchParams::toImpl(body.As<v8::Object>())->toEncodedFormData(); 169 V8URLSearchParams::toImpl(body.As<v8::Object>())->toEncodedFormData();
169 bodyBuffer = new BodyStreamBuffer( 170 bodyBuffer = new BodyStreamBuffer(
170 scriptState, 171 scriptState,
171 new FormDataBytesConsumer(executionContext, formData.release())); 172 new FormDataBytesConsumer(executionContext, formData.release()));
172 contentType = "application/x-www-form-urlencoded;charset=UTF-8"; 173 contentType = "application/x-www-form-urlencoded;charset=UTF-8";
173 } else if (ReadableStreamOperations::isReadableStream(scriptState, 174 } else if (ReadableStreamOperations::isReadableStream(scriptState,
174 bodyValue)) { 175 bodyValue)) {
176 UseCounter::count(executionContext,
177 UseCounter::FetchResponseConstructionWithStream);
175 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue); 178 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue);
176 } else { 179 } else {
177 String string = toUSVString(isolate, body, exceptionState); 180 String string = toUSVString(isolate, body, exceptionState);
178 if (exceptionState.hadException()) 181 if (exceptionState.hadException())
179 return nullptr; 182 return nullptr;
180 bodyBuffer = 183 bodyBuffer =
181 new BodyStreamBuffer(scriptState, new FormDataBytesConsumer(string)); 184 new BodyStreamBuffer(scriptState, new FormDataBytesConsumer(string));
182 contentType = "text/plain;charset=UTF-8"; 185 contentType = "text/plain;charset=UTF-8";
183 } 186 }
184 return create(scriptState, bodyBuffer, contentType, init, exceptionState); 187 return create(scriptState, bodyBuffer, contentType, init, exceptionState);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); 460 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer);
458 } 461 }
459 462
460 DEFINE_TRACE(Response) { 463 DEFINE_TRACE(Response) {
461 Body::trace(visitor); 464 Body::trace(visitor);
462 visitor->trace(m_response); 465 visitor->trace(m_response);
463 visitor->trace(m_headers); 466 visitor->trace(m_headers);
464 } 467 }
465 468
466 } // namespace blink 469 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/Body.cpp ('k') | third_party/WebKit/Source/modules/fetch/Response.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698