| 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/dom/DOMArrayBuffer.h" | 12 #include "core/dom/DOMArrayBuffer.h" |
| 13 #include "core/fileapi/FileReaderLoader.h" | |
| 14 #include "core/fileapi/FileReaderLoaderClient.h" | |
| 15 #include "modules/ModulesExport.h" | 13 #include "modules/ModulesExport.h" |
| 14 #include "modules/fetch/FetchDataConsumerHandle.h" |
| 15 #include "modules/fetch/FetchDataLoader.h" |
| 16 #include "platform/blob/BlobData.h" | 16 #include "platform/blob/BlobData.h" |
| 17 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
| 18 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 class BodyStreamBuffer; | 22 class BodyStreamBuffer; |
| 23 class BodyStreamSource; | 23 class BodyStreamSource; |
| 24 class DOMException; | 24 class DOMException; |
| 25 class ReadableByteStream; | 25 class ReadableByteStream; |
| 26 class ScriptState; | 26 class ScriptState; |
| 27 | 27 |
| 28 class MODULES_EXPORT Body | 28 class MODULES_EXPORT Body |
| 29 : public GarbageCollectedFinalized<Body> | 29 : public GarbageCollectedFinalized<Body> |
| 30 , public ScriptWrappable | 30 , public ScriptWrappable |
| 31 , public ActiveDOMObject | 31 , public ActiveDOMObject |
| 32 , public FileReaderLoaderClient { | 32 , public FetchDataLoader::Client { |
| 33 DEFINE_WRAPPERTYPEINFO(); | 33 DEFINE_WRAPPERTYPEINFO(); |
| 34 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body); | 34 USING_GARBAGE_COLLECTED_MIXIN(Body); |
| 35 public: | 35 public: |
| 36 class ReadableStreamSource; | 36 class ReadableStreamSource; |
| 37 enum ResponseType { | 37 enum ResponseType { |
| 38 ResponseUnknown, | 38 ResponseUnknown, |
| 39 ResponseAsArrayBuffer, | 39 ResponseAsArrayBuffer, |
| 40 ResponseAsBlob, | 40 ResponseAsBlob, |
| 41 ResponseAsFormData, | 41 ResponseAsFormData, |
| 42 ResponseAsJSON, | 42 ResponseAsJSON, |
| 43 ResponseAsText | 43 ResponseAsText |
| 44 }; | 44 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 BodyStreamBuffer* bufferForTest() const { return buffer(); } | 89 BodyStreamBuffer* bufferForTest() const { return buffer(); } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 class BlobHandleReceiver; | 92 class BlobHandleReceiver; |
| 93 | 93 |
| 94 void pullSource(); | 94 void pullSource(); |
| 95 void readAllFromStream(); | 95 void readAllFromStream(); |
| 96 ScriptPromise readAsync(ScriptState*, ResponseType); | 96 ScriptPromise readAsync(ScriptState*, ResponseType); |
| 97 void readAsyncFromBlob(PassRefPtr<BlobDataHandle>); | 97 void readAsyncFromBlob(PassRefPtr<BlobDataHandle>); |
| 98 void readAsyncFromFetchDataConsumerHandle(FetchDataConsumerHandle*, const St
ring& mimeType); |
| 98 void resolveJSON(const String&); | 99 void resolveJSON(const String&); |
| 99 | 100 |
| 100 // FileReaderLoaderClient functions. | 101 // FetchDataLoader::Client functions. |
| 101 virtual void didStartLoading() override; | 102 void didFetchDataLoadFailed() override; |
| 102 virtual void didReceiveData() override; | 103 void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) override; |
| 103 virtual void didFinishLoading() override; | 104 void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer>) override; |
| 104 virtual void didFail(FileError::ErrorCode) override; | 105 void didFetchDataLoadedString(const String&) override; |
| 105 | 106 |
| 106 void didBlobHandleReceiveError(DOMException*); | 107 void didBlobHandleReceiveError(DOMException*); |
| 107 | 108 |
| 108 // We use BlobDataHandle or BodyStreamBuffer as data container of the Body. | 109 // We use BlobDataHandle or BodyStreamBuffer as data container of the Body. |
| 109 // BodyStreamBuffer is used only when the Response object is created by | 110 // BodyStreamBuffer is used only when the Response object is created by |
| 110 // fetch() API. | 111 // fetch() API. |
| 111 // FIXME: We should seek a cleaner way to handle the data. | 112 // FIXME: We should seek a cleaner way to handle the data. |
| 112 virtual PassRefPtr<BlobDataHandle> blobDataHandle() const = 0; | 113 virtual PassRefPtr<BlobDataHandle> blobDataHandle() const = 0; |
| 113 virtual BodyStreamBuffer* buffer() const = 0; | 114 virtual BodyStreamBuffer* buffer() const = 0; |
| 114 virtual String mimeType() const = 0; | 115 virtual String mimeType() const = 0; |
| 115 | 116 |
| 116 void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>); | 117 void didFinishLoadingViaStream(PassRefPtr<DOMArrayBuffer>); |
| 117 | 118 |
| 118 OwnPtr<FileReaderLoader> m_loader; | 119 Member<FetchDataLoader> m_fetchDataLoader; |
| 119 bool m_bodyUsed; | 120 bool m_bodyUsed; |
| 120 ResponseType m_responseType; | 121 ResponseType m_responseType; |
| 121 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; | 122 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
| 122 Member<ReadableStreamSource> m_streamSource; | 123 Member<ReadableStreamSource> m_streamSource; |
| 123 Member<ReadableByteStream> m_stream; | 124 Member<ReadableByteStream> m_stream; |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 } // namespace blink | 127 } // namespace blink |
| 127 | 128 |
| 128 #endif // Body_h | 129 #endif // Body_h |
| OLD | NEW |