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

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

Issue 555443002: [Fetch API] Put body members directly on Response/Request (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated yhirano's comment Created 6 years, 3 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
« 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
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 FetchBodyStream_h 5 #ifndef Body_h
6 #define FetchBodyStream_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/fileapi/FileReaderLoader.h" 12 #include "core/fileapi/FileReaderLoader.h"
13 #include "core/fileapi/FileReaderLoaderClient.h" 13 #include "core/fileapi/FileReaderLoaderClient.h"
14 #include "platform/blob/BlobData.h" 14 #include "platform/blob/BlobData.h"
15 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
16 #include "wtf/RefPtr.h" 16 #include "wtf/RefPtr.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 class ScriptState; 20 class ScriptState;
21 21
22 class FetchBodyStream FINAL 22 class Body
23 : public GarbageCollectedFinalized<FetchBodyStream> 23 : public GarbageCollectedFinalized<Body>
24 , public ScriptWrappable 24 , public ScriptWrappable
25 , public ActiveDOMObject 25 , public ActiveDOMObject
26 , public FileReaderLoaderClient { 26 , public FileReaderLoaderClient {
27 DEFINE_WRAPPERTYPEINFO(); 27 DEFINE_WRAPPERTYPEINFO();
28 public: 28 public:
29 explicit Body(ExecutionContext*);
30 virtual ~Body() { }
29 enum ResponseType { 31 enum ResponseType {
30 ResponseAsArrayBuffer, 32 ResponseAsArrayBuffer,
31 ResponseAsBlob, 33 ResponseAsBlob,
32 ResponseAsFormData, 34 ResponseAsFormData,
33 ResponseAsJSON, 35 ResponseAsJSON,
34 ResponseAsText 36 ResponseAsText
35 }; 37 };
36 38
37 static FetchBodyStream* create(ExecutionContext*, PassRefPtr<BlobDataHandle> ); 39 ScriptPromise arrayBuffer(ScriptState*);
40 ScriptPromise blob(ScriptState*);
41 ScriptPromise formData(ScriptState*);
42 ScriptPromise json(ScriptState*);
43 ScriptPromise text(ScriptState*);
38 44
39 ScriptPromise asArrayBuffer(ScriptState*); 45 bool bodyUsed() const;
40 ScriptPromise asBlob(ScriptState*);
41 ScriptPromise asFormData(ScriptState*);
42 ScriptPromise asJSON(ScriptState*);
43 ScriptPromise asText(ScriptState*);
44 46
45 // ActiveDOMObject override. 47 // ActiveDOMObject override.
46 virtual void stop() OVERRIDE; 48 virtual void stop() OVERRIDE;
47 virtual bool hasPendingActivity() const OVERRIDE; 49 virtual bool hasPendingActivity() const OVERRIDE;
48 50
49 void trace(Visitor*) { } 51 virtual void trace(Visitor*) { }
50 52
51 private: 53 private:
52 FetchBodyStream(ExecutionContext*, PassRefPtr<BlobDataHandle>);
53 ScriptPromise readAsync(ScriptState*, ResponseType); 54 ScriptPromise readAsync(ScriptState*, ResponseType);
54 void resolveJSON(); 55 void resolveJSON();
55 56
56 // FileReaderLoaderClient functions. 57 // FileReaderLoaderClient functions.
57 virtual void didStartLoading() OVERRIDE; 58 virtual void didStartLoading() OVERRIDE;
58 virtual void didReceiveData() OVERRIDE; 59 virtual void didReceiveData() OVERRIDE;
59 virtual void didFinishLoading() OVERRIDE; 60 virtual void didFinishLoading() OVERRIDE;
60 virtual void didFail(FileError::ErrorCode) OVERRIDE; 61 virtual void didFail(FileError::ErrorCode) OVERRIDE;
61 62
62 RefPtr<BlobDataHandle> m_blobDataHandle; 63 virtual PassRefPtr<BlobDataHandle> blobDataHandle() = 0;
64
63 OwnPtr<FileReaderLoader> m_loader; 65 OwnPtr<FileReaderLoader> m_loader;
64 bool m_hasRead; 66 bool m_bodyUsed;
65 ResponseType m_responseType; 67 ResponseType m_responseType;
66 RefPtr<ScriptPromiseResolver> m_resolver; 68 RefPtr<ScriptPromiseResolver> m_resolver;
67 }; 69 };
68 70
69 } // namespace blink 71 } // namespace blink
70 72
71 #endif // FetchBodyStream_h 73 #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