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