| 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 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 |
| OLD | NEW |