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

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

Issue 795323003: Move Fetch API releted code to modules/fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 | « Source/modules/modules.gypi ('k') | Source/modules/serviceworkers/Body.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef Body_h
6 #define Body_h
7
8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptWrappable.h"
11 #include "core/dom/ActiveDOMObject.h"
12 #include "core/fileapi/FileReaderLoader.h"
13 #include "core/fileapi/FileReaderLoaderClient.h"
14 #include "core/streams/ReadableStreamImpl.h"
15 #include "platform/blob/BlobData.h"
16 #include "platform/heap/Handle.h"
17 #include "wtf/RefPtr.h"
18
19 namespace blink {
20
21 class BodyStreamBuffer;
22 class ScriptState;
23
24 class Body
25 : public GarbageCollectedFinalized<Body>
26 , public ScriptWrappable
27 , public ActiveDOMObject
28 , public FileReaderLoaderClient {
29 DEFINE_WRAPPERTYPEINFO();
30 public:
31 explicit Body(ExecutionContext*);
32 virtual ~Body() { }
33 enum ResponseType {
34 ResponseUnknown,
35 ResponseAsArrayBuffer,
36 ResponseAsBlob,
37 ResponseAsFormData,
38 ResponseAsJSON,
39 ResponseAsText
40 };
41
42 ScriptPromise arrayBuffer(ScriptState*);
43 ScriptPromise blob(ScriptState*);
44 ScriptPromise formData(ScriptState*);
45 ScriptPromise json(ScriptState*);
46 ScriptPromise text(ScriptState*);
47 ReadableStream* body();
48
49 // Sets the bodyUsed flag to true. This signifies that the contents of the
50 // body have been consumed and cannot be accessed again.
51 void setBodyUsed();
52 bool bodyUsed() const;
53
54 bool streamAccessed() const;
55
56 // ActiveDOMObject override.
57 virtual void stop() override;
58 virtual bool hasPendingActivity() const override;
59
60 virtual void trace(Visitor*);
61
62 protected:
63 // Copy constructor for clone() implementations
64 explicit Body(const Body&);
65
66 private:
67 class ReadableStreamSource;
68 class BlobHandleReceiver;
69
70 void pullSource();
71 void readAllFromStream(ScriptState*);
72 ScriptPromise readAsync(ScriptState*, ResponseType);
73 void readAsyncFromBlob(PassRefPtr<BlobDataHandle>);
74 void resolveJSON(const String&);
75
76 // FileReaderLoaderClient functions.
77 virtual void didStartLoading() override;
78 virtual void didReceiveData() override;
79 virtual void didFinishLoading() override;
80 virtual void didFail(FileError::ErrorCode) override;
81
82 void didBlobHandleReceiveError(PassRefPtrWillBeRawPtr<DOMException>);
83
84 // We use BlobDataHandle or BodyStreamBuffer as data container of the Body.
85 // BodyStreamBuffer is used only when the Response object is created by
86 // fetch() API.
87 // FIXME: We should seek a cleaner way to handle the data.
88 virtual PassRefPtr<BlobDataHandle> blobDataHandle() const = 0;
89 virtual BodyStreamBuffer* buffer() const = 0;
90 virtual String contentTypeForBuffer() const = 0;
91
92 void didFinishLoadingViaStream(DOMArrayBuffer*);
93
94 OwnPtr<FileReaderLoader> m_loader;
95 bool m_bodyUsed;
96 bool m_streamAccessed;
97 ResponseType m_responseType;
98 RefPtr<ScriptPromiseResolver> m_resolver;
99 Member<ReadableStreamSource> m_streamSource;
100 Member<ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>> m_ stream;
101 };
102
103 } // namespace blink
104
105 #endif // Body_h
OLDNEW
« no previous file with comments | « Source/modules/modules.gypi ('k') | Source/modules/serviceworkers/Body.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698