| 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" |  | 
| 10 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" | 
| 11 #include "core/dom/ActiveDOMObject.h" | 10 #include "core/dom/ActiveDOMObject.h" | 
| 12 #include "core/dom/DOMArrayBuffer.h" |  | 
| 13 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" | 
| 14 #include "modules/fetch/FetchDataConsumerHandle.h" |  | 
| 15 #include "modules/fetch/FetchDataLoader.h" |  | 
| 16 #include "platform/blob/BlobData.h" |  | 
| 17 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" | 
| 18 #include "wtf/RefPtr.h" | 13 #include "wtf/text/WTFString.h" | 
| 19 | 14 | 
| 20 namespace blink { | 15 namespace blink { | 
| 21 | 16 | 
| 22 class BodyStreamBuffer; | 17 class BodyStreamBuffer; | 
| 23 class DrainingBodyStreamBuffer; | 18 class ExecutionContext; | 
| 24 class BodyStreamSource; |  | 
| 25 class DOMException; |  | 
| 26 class ReadableByteStream; | 19 class ReadableByteStream; | 
| 27 class ScriptState; | 20 class ScriptState; | 
| 28 | 21 | 
| 29 class MODULES_EXPORT Body | 22 class MODULES_EXPORT Body | 
| 30     : public GarbageCollectedFinalized<Body> | 23     : public GarbageCollectedFinalized<Body> | 
| 31     , public ScriptWrappable | 24     , public ScriptWrappable | 
| 32     , public ActiveDOMObject | 25     , public ActiveDOMObject { | 
| 33     , public FetchDataLoader::Client { | 26     WTF_MAKE_NONCOPYABLE(Body); | 
| 34     DEFINE_WRAPPERTYPEINFO(); | 27     DEFINE_WRAPPERTYPEINFO(); | 
| 35     USING_GARBAGE_COLLECTED_MIXIN(Body); | 28     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body); | 
| 36 public: | 29 public: | 
| 37     class ReadableStreamSource; |  | 
| 38     enum ResponseType { |  | 
| 39         ResponseUnknown, |  | 
| 40         ResponseAsArrayBuffer, |  | 
| 41         ResponseAsBlob, |  | 
| 42         ResponseAsFormData, |  | 
| 43         ResponseAsJSON, |  | 
| 44         ResponseAsText |  | 
| 45     }; |  | 
| 46     enum LockBodyOption { |  | 
| 47         LockBodyOptionNone, |  | 
| 48         // Setting "body passed" flag in addition to acquiring a lock. |  | 
| 49         PassBody, |  | 
| 50     }; |  | 
| 51     explicit Body(ExecutionContext*); | 30     explicit Body(ExecutionContext*); | 
| 52     ~Body() override { } | 31     ~Body() override { } | 
| 53 | 32 | 
| 54     ScriptPromise arrayBuffer(ScriptState*); | 33     ScriptPromise arrayBuffer(ScriptState*); | 
| 55     ScriptPromise blob(ScriptState*); | 34     ScriptPromise blob(ScriptState*); | 
| 56     ScriptPromise formData(ScriptState*); | 35     ScriptPromise formData(ScriptState*); | 
| 57     ScriptPromise json(ScriptState*); | 36     ScriptPromise json(ScriptState*); | 
| 58     ScriptPromise text(ScriptState*); | 37     ScriptPromise text(ScriptState*); | 
| 59     ReadableByteStream* body(); | 38     ReadableByteStream* body(); | 
|  | 39     virtual BodyStreamBuffer* bodyBuffer() = 0; | 
|  | 40     virtual const BodyStreamBuffer* bodyBuffer() const = 0; | 
| 60 | 41 | 
| 61     bool bodyUsed() const; | 42     bool bodyUsed(); | 
| 62     void lockBody(LockBodyOption = LockBodyOptionNone); | 43     void setBodyPassed() { m_bodyPassed = true; } | 
| 63 |  | 
| 64     // Creates a DrainingBodyStreamBuffer to access body data. |  | 
| 65     // Returns nullptr if underlying BodyStreamBuffer is null. |  | 
| 66     PassOwnPtr<DrainingBodyStreamBuffer> createDrainingStream(); |  | 
| 67 | 44 | 
| 68     // ActiveDOMObject override. | 45     // ActiveDOMObject override. | 
| 69     bool hasPendingActivity() const override; | 46     bool hasPendingActivity() const override; | 
| 70 | 47 | 
| 71     DECLARE_VIRTUAL_TRACE(); | 48     DEFINE_INLINE_VIRTUAL_TRACE() | 
| 72 | 49     { | 
| 73 protected: | 50         ActiveDOMObject::trace(visitor); | 
| 74     // Sets |m_stream| to a newly created stream from |buffer|. | 51     } | 
| 75     // |buffer| can be null. |  | 
| 76     // This is called when the underlying buffer is set/modified. |  | 
| 77     // TODO(hiroshige): Merge FetchRequest/ResponseData::buffer() and |  | 
| 78     // integrate Body::setBody(), Request/Response::refreshBody(), |  | 
| 79     // FetchRequestData::setBuffer() and |  | 
| 80     // FetchResponseData::replaceBodyStreamBuffer(). |  | 
| 81     void setBody(BodyStreamBuffer* /* buffer */); |  | 
| 82 | 52 | 
| 83 private: | 53 private: | 
| 84     ScriptPromise readAsync(ScriptState*, ResponseType); |  | 
| 85     void resolveWithEmptyDataSynchronously(); |  | 
| 86     void readAsyncFromDrainingBodyStreamBuffer(PassOwnPtr<DrainingBodyStreamBuff
     er>, const String& mimeType); |  | 
| 87     void resolveJSON(const String&); |  | 
| 88 |  | 
| 89     void didFetchDataLoadFinishedFromDrainingStream(); |  | 
| 90 |  | 
| 91     // FetchDataLoader::Client functions. |  | 
| 92     void didFetchDataLoadFailed() override; |  | 
| 93     void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) override; |  | 
| 94     void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer>) override; |  | 
| 95     void didFetchDataLoadedString(const String&) override; |  | 
| 96 |  | 
| 97     virtual String mimeType() const = 0; | 54     virtual String mimeType() const = 0; | 
| 98 | 55 | 
| 99     bool m_bodyUsed; | 56     bool m_bodyPassed; | 
| 100     ResponseType m_responseType; |  | 
| 101     RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |  | 
| 102     Member<ReadableStreamSource> m_streamSource; |  | 
| 103     Member<ReadableByteStream> m_stream; |  | 
| 104 }; | 57 }; | 
| 105 | 58 | 
| 106 } // namespace blink | 59 } // namespace blink | 
| 107 | 60 | 
| 108 #endif // Body_h | 61 #endif // Body_h | 
| OLD | NEW | 
|---|