| 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 Body_h | 5 #ifndef Body_h |
| 6 #define Body_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 "core/streams/ReadableStreamImpl.h" | 14 #include "core/streams/ReadableStreamImpl.h" |
| 15 #include "platform/blob/BlobData.h" | 15 #include "platform/blob/BlobData.h" |
| 16 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
| 17 #include "wtf/RefPtr.h" | 17 #include "wtf/RefPtr.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 class BodyStreamBuffer; |
| 21 class ScriptState; | 22 class ScriptState; |
| 22 | 23 |
| 23 class Body | 24 class Body |
| 24 : public GarbageCollectedFinalized<Body> | 25 : public GarbageCollectedFinalized<Body> |
| 25 , public ScriptWrappable | 26 , public ScriptWrappable |
| 26 , public ActiveDOMObject | 27 , public ActiveDOMObject |
| 27 , public FileReaderLoaderClient { | 28 , public FileReaderLoaderClient { |
| 28 DEFINE_WRAPPERTYPEINFO(); | 29 DEFINE_WRAPPERTYPEINFO(); |
| 29 public: | 30 public: |
| 30 explicit Body(ExecutionContext*); | 31 explicit Body(ExecutionContext*); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 43 ScriptPromise formData(ScriptState*); | 44 ScriptPromise formData(ScriptState*); |
| 44 ScriptPromise json(ScriptState*); | 45 ScriptPromise json(ScriptState*); |
| 45 ScriptPromise text(ScriptState*); | 46 ScriptPromise text(ScriptState*); |
| 46 ReadableStream* body(); | 47 ReadableStream* body(); |
| 47 | 48 |
| 48 // Sets the bodyUsed flag to true. This signifies that the contents of the | 49 // Sets the bodyUsed flag to true. This signifies that the contents of the |
| 49 // body have been consumed and cannot be accessed again. | 50 // body have been consumed and cannot be accessed again. |
| 50 void setBodyUsed(); | 51 void setBodyUsed(); |
| 51 bool bodyUsed() const; | 52 bool bodyUsed() const; |
| 52 | 53 |
| 54 bool streamAccessed() const; |
| 55 |
| 53 // ActiveDOMObject override. | 56 // ActiveDOMObject override. |
| 54 virtual void stop() override; | 57 virtual void stop() override; |
| 55 virtual bool hasPendingActivity() const override; | 58 virtual bool hasPendingActivity() const override; |
| 56 | 59 |
| 57 virtual void trace(Visitor*); | 60 virtual void trace(Visitor*); |
| 58 | 61 |
| 59 protected: | 62 protected: |
| 60 // Copy constructor for clone() implementations | 63 // Copy constructor for clone() implementations |
| 61 explicit Body(const Body&); | 64 explicit Body(const Body&); |
| 62 | 65 |
| 63 private: | 66 private: |
| 64 class ReadableStreamSource; | 67 class ReadableStreamSource; |
| 68 class BlobHandleResolver; |
| 69 |
| 65 void pullSource(); | 70 void pullSource(); |
| 66 void readAllFromStream(ScriptState*); | 71 void readAllFromStream(ScriptState*); |
| 67 ScriptPromise readAsync(ScriptState*, ResponseType); | 72 ScriptPromise readAsync(ScriptState*, ResponseType); |
| 73 void readAsyncFromBlob(PassRefPtr<BlobDataHandle>); |
| 68 void resolveJSON(const String&); | 74 void resolveJSON(const String&); |
| 69 | 75 |
| 70 // FileReaderLoaderClient functions. | 76 // FileReaderLoaderClient functions. |
| 71 virtual void didStartLoading() override; | 77 virtual void didStartLoading() override; |
| 72 virtual void didReceiveData() override; | 78 virtual void didReceiveData() override; |
| 73 virtual void didFinishLoading() override; | 79 virtual void didFinishLoading() override; |
| 74 virtual void didFail(FileError::ErrorCode) override; | 80 virtual void didFail(FileError::ErrorCode) override; |
| 75 | 81 |
| 76 virtual PassRefPtr<BlobDataHandle> blobDataHandle() = 0; | 82 void didBlobHandleResolveError(PassRefPtrWillBeRawPtr<DOMException>); |
| 83 |
| 84 virtual PassRefPtr<BlobDataHandle> blobDataHandle() const = 0; |
| 85 virtual BodyStreamBuffer* buffer() const = 0; |
| 86 virtual String contentType() const = 0; |
| 77 | 87 |
| 78 void didFinishLoadingViaStream(DOMArrayBuffer*); | 88 void didFinishLoadingViaStream(DOMArrayBuffer*); |
| 79 | 89 |
| 80 OwnPtr<FileReaderLoader> m_loader; | 90 OwnPtr<FileReaderLoader> m_loader; |
| 81 bool m_bodyUsed; | 91 bool m_bodyUsed; |
| 82 bool m_streamAccessed; | 92 bool m_streamAccessed; |
| 83 ResponseType m_responseType; | 93 ResponseType m_responseType; |
| 84 RefPtr<ScriptPromiseResolver> m_resolver; | 94 RefPtr<ScriptPromiseResolver> m_resolver; |
| 85 Member<ReadableStreamSource> m_streamSource; | 95 Member<ReadableStreamSource> m_streamSource; |
| 86 Member<ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>> m_
stream; | 96 Member<ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>> m_
stream; |
| 87 }; | 97 }; |
| 88 | 98 |
| 89 } // namespace blink | 99 } // namespace blink |
| 90 | 100 |
| 91 #endif // Body_h | 101 #endif // Body_h |
| OLD | NEW |