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 #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 virtual ~Body() { } | |
29 enum ResponseType { | 30 enum ResponseType { |
30 ResponseAsArrayBuffer, | 31 ResponseAsArrayBuffer, |
31 ResponseAsBlob, | 32 ResponseAsBlob, |
32 ResponseAsFormData, | 33 ResponseAsFormData, |
33 ResponseAsJSON, | 34 ResponseAsJSON, |
34 ResponseAsText | 35 ResponseAsText |
35 }; | 36 }; |
36 | 37 |
37 static FetchBodyStream* create(ExecutionContext*, PassRefPtr<BlobDataHandle> ); | 38 ScriptPromise arrayBuffer(ScriptState*); |
39 ScriptPromise blob(ScriptState*); | |
40 ScriptPromise formData(ScriptState*); | |
41 ScriptPromise json(ScriptState*); | |
42 ScriptPromise text(ScriptState*); | |
38 | 43 |
39 ScriptPromise asArrayBuffer(ScriptState*); | 44 bool bodyUsed(); |
yhirano
2014/09/09 09:31:49
+const
horo
2014/09/10 06:18:44
Done.
| |
40 ScriptPromise asBlob(ScriptState*); | |
41 ScriptPromise asFormData(ScriptState*); | |
42 ScriptPromise asJSON(ScriptState*); | |
43 ScriptPromise asText(ScriptState*); | |
44 | 45 |
45 // ActiveDOMObject override. | 46 // ActiveDOMObject override. |
46 virtual void stop() OVERRIDE; | 47 virtual void stop() OVERRIDE; |
47 virtual bool hasPendingActivity() const OVERRIDE; | 48 virtual bool hasPendingActivity() const OVERRIDE; |
48 | 49 |
49 void trace(Visitor*) { } | 50 virtual void trace(Visitor*) { } |
51 | |
52 protected: | |
53 Body(ExecutionContext*); | |
yhirano
2014/09/09 09:31:49
You don't have to hide the constructor because we
jsbell
2014/09/09 22:04:25
single arg constructor should have 'explicit' qual
horo
2014/09/10 06:18:44
Done.
horo
2014/09/10 06:18:44
Done.
| |
50 | 54 |
51 private: | 55 private: |
52 FetchBodyStream(ExecutionContext*, PassRefPtr<BlobDataHandle>); | |
53 ScriptPromise readAsync(ScriptState*, ResponseType); | 56 ScriptPromise readAsync(ScriptState*, ResponseType); |
54 void resolveJSON(); | 57 void resolveJSON(); |
55 | 58 |
56 // FileReaderLoaderClient functions. | 59 // FileReaderLoaderClient functions. |
57 virtual void didStartLoading() OVERRIDE; | 60 virtual void didStartLoading() OVERRIDE; |
58 virtual void didReceiveData() OVERRIDE; | 61 virtual void didReceiveData() OVERRIDE; |
59 virtual void didFinishLoading() OVERRIDE; | 62 virtual void didFinishLoading() OVERRIDE; |
60 virtual void didFail(FileError::ErrorCode) OVERRIDE; | 63 virtual void didFail(FileError::ErrorCode) OVERRIDE; |
61 | 64 |
62 RefPtr<BlobDataHandle> m_blobDataHandle; | 65 virtual PassRefPtr<BlobDataHandle> blobDataHandle() = 0; |
66 | |
63 OwnPtr<FileReaderLoader> m_loader; | 67 OwnPtr<FileReaderLoader> m_loader; |
64 bool m_hasRead; | 68 bool m_bodyUsed; |
65 ResponseType m_responseType; | 69 ResponseType m_responseType; |
66 RefPtr<ScriptPromiseResolver> m_resolver; | 70 RefPtr<ScriptPromiseResolver> m_resolver; |
67 }; | 71 }; |
68 | 72 |
69 } // namespace blink | 73 } // namespace blink |
70 | 74 |
71 #endif // FetchBodyStream_h | 75 #endif // Body_h |
OLD | NEW |