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 FetchBodyStream_h |
6 #define FetchBodyStream_h | 6 #define FetchBodyStream_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/RefCounted.h" | 16 #include "wtf/RefCounted.h" |
17 #include "wtf/RefPtr.h" | 17 #include "wtf/RefPtr.h" |
18 | 18 |
19 namespace WebCore { | 19 namespace WebCore { |
20 | 20 |
21 class ScriptState; | 21 class ScriptState; |
22 | 22 |
23 // FIXME: Oilpan: when the implementation stops using | |
24 // ActiveDOMObject::(un)setPendingActivity, derive from | |
25 // RefCountedWillBeGarbageCollectedFinalized instead. | |
26 class FetchBodyStream FINAL | 23 class FetchBodyStream FINAL |
27 : public RefCountedWillBeRefCountedGarbageCollected<FetchBodyStream> | 24 : public RefCountedWillBeGarbageCollectedFinalized<FetchBodyStream> |
28 , public ScriptWrappable | 25 , public ScriptWrappable |
29 , public ActiveDOMObject | 26 , public ActiveDOMObject |
30 , public FileReaderLoaderClient { | 27 , public FileReaderLoaderClient { |
31 public: | 28 public: |
32 enum ResponseType { | 29 enum ResponseType { |
33 ResponseAsArrayBuffer, | 30 ResponseAsArrayBuffer, |
34 ResponseAsBlob, | 31 ResponseAsBlob, |
35 ResponseAsFormData, | 32 ResponseAsFormData, |
36 ResponseAsJSON, | 33 ResponseAsJSON, |
37 ResponseAsText | 34 ResponseAsText |
38 }; | 35 }; |
39 | 36 |
40 static PassRefPtrWillBeRawPtr<FetchBodyStream> create(ExecutionContext*, Pas
sRefPtr<BlobDataHandle>); | 37 static PassRefPtrWillBeRawPtr<FetchBodyStream> create(ExecutionContext*, Pas
sRefPtr<BlobDataHandle>); |
41 ~FetchBodyStream() { } | 38 ~FetchBodyStream() { } |
42 | 39 |
43 ScriptPromise asArrayBuffer(ScriptState*); | 40 ScriptPromise asArrayBuffer(ScriptState*); |
44 ScriptPromise asBlob(ScriptState*); | 41 ScriptPromise asBlob(ScriptState*); |
45 ScriptPromise asFormData(ScriptState*); | 42 ScriptPromise asFormData(ScriptState*); |
46 ScriptPromise asJSON(ScriptState*); | 43 ScriptPromise asJSON(ScriptState*); |
47 ScriptPromise asText(ScriptState*); | 44 ScriptPromise asText(ScriptState*); |
48 | 45 |
49 // ActiveDOMObject override. | 46 // ActiveDOMObject override. |
50 virtual void stop() OVERRIDE; | 47 virtual void stop() OVERRIDE; |
| 48 virtual bool hasPendingActivity() const OVERRIDE; |
51 | 49 |
52 void trace(Visitor*) { } | 50 void trace(Visitor*) { } |
53 | 51 |
54 private: | 52 private: |
55 FetchBodyStream(ExecutionContext*, PassRefPtr<BlobDataHandle>); | 53 FetchBodyStream(ExecutionContext*, PassRefPtr<BlobDataHandle>); |
56 ScriptPromise readAsync(ScriptState*, ResponseType); | 54 ScriptPromise readAsync(ScriptState*, ResponseType); |
57 void resolveJSON(); | 55 void resolveJSON(); |
58 | 56 |
59 // FileReaderLoaderClient functions. | 57 // FileReaderLoaderClient functions. |
60 virtual void didStartLoading() OVERRIDE; | 58 virtual void didStartLoading() OVERRIDE; |
61 virtual void didReceiveData() OVERRIDE; | 59 virtual void didReceiveData() OVERRIDE; |
62 virtual void didFinishLoading() OVERRIDE; | 60 virtual void didFinishLoading() OVERRIDE; |
63 virtual void didFail(FileError::ErrorCode) OVERRIDE; | 61 virtual void didFail(FileError::ErrorCode) OVERRIDE; |
64 | 62 |
65 RefPtr<BlobDataHandle> m_blobDataHandle; | 63 RefPtr<BlobDataHandle> m_blobDataHandle; |
66 OwnPtr<FileReaderLoader> m_loader; | 64 OwnPtr<FileReaderLoader> m_loader; |
67 bool m_hasRead; | 65 bool m_hasRead; |
68 ResponseType m_responseType; | 66 ResponseType m_responseType; |
69 RefPtr<ScriptPromiseResolver> m_resolver; | 67 RefPtr<ScriptPromiseResolver> m_resolver; |
70 }; | 68 }; |
71 | 69 |
72 } // namespace WebCore | 70 } // namespace WebCore |
73 | 71 |
74 #endif // FetchBodyStream_h | 72 #endif // FetchBodyStream_h |
OLD | NEW |