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

Side by Side Diff: Source/modules/fetch/Body.h

Issue 1053503002: [Fetch] Response.clone should tee the body stream. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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 #ifndef Body_h 5 #ifndef Body_h
6 #define Body_h 6 #define Body_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptWrappable.h" 10 #include "bindings/core/v8/ScriptWrappable.h"
11 #include "core/dom/ActiveDOMObject.h" 11 #include "core/dom/ActiveDOMObject.h"
12 #include "core/dom/DOMArrayBuffer.h" 12 #include "core/dom/DOMArrayBuffer.h"
13 #include "core/fileapi/FileReaderLoader.h" 13 #include "core/fileapi/FileReaderLoader.h"
14 #include "core/fileapi/FileReaderLoaderClient.h" 14 #include "core/fileapi/FileReaderLoaderClient.h"
15 #include "platform/blob/BlobData.h" 15 #include "platform/blob/BlobData.h"
16 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
17 #include "wtf/RefPtr.h" 17 #include "wtf/RefPtr.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 class BodyStreamBuffer; 21 class BodyStreamBuffer;
22 class ReadableByteStream; 22 class ReadableByteStream;
23 class ReadableByteStreamReader;
24 class ScriptState; 23 class ScriptState;
25 24
26 class Body 25 class Body
27 : public GarbageCollectedFinalized<Body> 26 : public GarbageCollectedFinalized<Body>
28 , public ScriptWrappable 27 , public ScriptWrappable
29 , public ActiveDOMObject 28 , public ActiveDOMObject
30 , public FileReaderLoaderClient { 29 , public FileReaderLoaderClient {
31 DEFINE_WRAPPERTYPEINFO(); 30 DEFINE_WRAPPERTYPEINFO();
32 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body); 31 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body);
33 public: 32 public:
34 enum ResponseType { 33 enum ResponseType {
35 ResponseUnknown, 34 ResponseUnknown,
36 ResponseAsArrayBuffer, 35 ResponseAsArrayBuffer,
37 ResponseAsBlob, 36 ResponseAsBlob,
38 ResponseAsFormData, 37 ResponseAsFormData,
39 ResponseAsJSON, 38 ResponseAsJSON,
40 ResponseAsText 39 ResponseAsText
41 }; 40 };
41 enum LockBodyOption {
42 LockBodyOptionNone,
43 // Setting "body passed" flag in addition to acquiring a lock.
44 PassBody,
45 };
42 explicit Body(ExecutionContext*); 46 explicit Body(ExecutionContext*);
43 virtual ~Body() { } 47 virtual ~Body() { }
44 48
45 ScriptPromise arrayBuffer(ScriptState*); 49 ScriptPromise arrayBuffer(ScriptState*);
46 ScriptPromise blob(ScriptState*); 50 ScriptPromise blob(ScriptState*);
47 ScriptPromise formData(ScriptState*); 51 ScriptPromise formData(ScriptState*);
48 ScriptPromise json(ScriptState*); 52 ScriptPromise json(ScriptState*);
49 ScriptPromise text(ScriptState*); 53 ScriptPromise text(ScriptState*);
50 ReadableByteStream* body(); 54 ReadableByteStream* body();
51 55
52 // Sets the bodyUsed flag to true. This signifies that the contents of the
53 // body have been consumed and cannot be accessed again.
54 void setBodyUsed();
55 bool bodyUsed() const; 56 bool bodyUsed() const;
57 void lockBody(LockBodyOption = LockBodyOptionNone);
56 58
57 bool streamAccessed() const; 59 bool streamAccessed() const;
60 void refreshBody();
58 61
59 // Creates a new BodyStreamBuffer to drain the data from the ReadableStream. 62 // Creates a new BodyStreamBuffer to drain the data from the ReadableStream.
60 BodyStreamBuffer* createDrainingStream(); 63 BodyStreamBuffer* createDrainingStream();
61 64
62 // ActiveDOMObject override. 65 // ActiveDOMObject override.
63 virtual void stop() override; 66 virtual void stop() override;
64 virtual bool hasPendingActivity() const override; 67 virtual bool hasPendingActivity() const override;
65 68
66 DECLARE_VIRTUAL_TRACE(); 69 DECLARE_VIRTUAL_TRACE();
67 70
(...skipping 26 matching lines...) Expand all
94 virtual String mimeType() const = 0; 97 virtual String mimeType() const = 0;
95 98
96 void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>); 99 void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>);
97 100
98 OwnPtr<FileReaderLoader> m_loader; 101 OwnPtr<FileReaderLoader> m_loader;
99 bool m_bodyUsed; 102 bool m_bodyUsed;
100 ResponseType m_responseType; 103 ResponseType m_responseType;
101 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; 104 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
102 Member<ReadableStreamSource> m_streamSource; 105 Member<ReadableStreamSource> m_streamSource;
103 Member<ReadableByteStream> m_stream; 106 Member<ReadableByteStream> m_stream;
104 Member<ReadableByteStreamReader> m_streamReader;
105 }; 107 };
106 108
107 } // namespace blink 109 } // namespace blink
108 110
109 #endif // Body_h 111 #endif // Body_h
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/fetch/script-tests/stream-reader.js ('k') | Source/modules/fetch/Body.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698