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