Unreviewed, rolling out r220271.
[WebKit.git] / Source / WebCore / Modules / fetch / FetchBodyOwner.h
index 3a698ea..5b631d7 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef FetchBodyOwner_h
-#define FetchBodyOwner_h
-
-#if ENABLE(FETCH_API)
+#pragma once
 
 #include "ActiveDOMObject.h"
 #include "FetchBody.h"
+#include "FetchHeaders.h"
 #include "FetchLoader.h"
 #include "FetchLoaderClient.h"
+#include "FetchResponseSource.h"
 
 namespace WebCore {
 
 class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject {
 public:
-    FetchBodyOwner(ScriptExecutionContext&, FetchBody&&);
+    FetchBodyOwner(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&);
 
     // Exposed Body API
-    bool isDisturbed() const { return m_body.isDisturbed(); }
-    void arrayBuffer(DeferredWrapper&& promise) { m_body.arrayBuffer(*this, WTFMove(promise)); }
-    void blob(DeferredWrapper&& promise) { m_body.blob(*this, WTFMove(promise)); }
-    void formData(DeferredWrapper&& promise) { m_body.formData(*this, WTFMove(promise)); }
-    void json(DeferredWrapper&& promise) { m_body.json(*this, WTFMove(promise)); }
-    void text(DeferredWrapper&& promise) { m_body.text(*this, WTFMove(promise)); }
+    // FIXME: Missing body attribute returning a ReadableStream.
+    bool bodyUsed() const { return isDisturbed(); }
+    void arrayBuffer(Ref<DeferredPromise>&&);
+    void blob(Ref<DeferredPromise>&&);
+    void formData(Ref<DeferredPromise>&&);
+    void json(Ref<DeferredPromise>&&);
+    void text(Ref<DeferredPromise>&&);
+
+    bool isDisturbed() const { return m_isDisturbed; };
+    bool isDisturbedOrLocked() const;
 
-    void loadBlob(Blob&, FetchLoader::Type);
+    void loadBlob(const Blob&, FetchBodyConsumer*);
 
     bool isActive() const { return !!m_blobLoader; }
 
+protected:
+    const FetchBody& body() const { return *m_body; }
+    FetchBody& body() { return *m_body; }
+    bool isBodyNull() const { return !m_body; }
+    void cloneBody(const FetchBodyOwner&);
+
+    void extractBody(ScriptExecutionContext&, FetchBody::Init&&);
+    void updateContentType();
+    void consumeOnceLoadingFinished(FetchBodyConsumer::Type, Ref<DeferredPromise>&&);
+
+    void setBody(FetchBody&& body) { m_body = WTFMove(body); }
+
+    // ActiveDOMObject API
+    void stop() override;
+
+    void setDisturbed() { m_isDisturbed = true; }
+
 private:
     // Blob loading routines
-    void loadedBlobAsText(String&&);
-    void loadedBlobAsArrayBuffer(RefPtr<ArrayBuffer>&& buffer) { m_body.loadedAsArrayBuffer(WTFMove(buffer)); }
-    void blobLoadingSucceeded() { finishBlobLoading(); }
+    void blobChunk(const char*, size_t);
+    void blobLoadingSucceeded();
     void blobLoadingFailed();
     void finishBlobLoading();
 
-    // ActiveDOMObject API
-    void stop() override;
-
     struct BlobLoader final : FetchLoaderClient {
         BlobLoader(FetchBodyOwner&);
 
         // FetchLoaderClient API
-        void didFinishLoadingAsText(String&& text) final { owner.loadedBlobAsText(WTFMove(text)); }
-        void didFinishLoadingAsArrayBuffer(RefPtr<ArrayBuffer>&& buffer) final { owner.loadedBlobAsArrayBuffer(WTFMove(buffer)); }
         void didReceiveResponse(const ResourceResponse&) final;
-        void didFail() final { owner.blobLoadingFailed(); };
+        void didReceiveData(const char* data, size_t size) final { owner.blobChunk(data, size); }
+        void didFail() final;
         void didSucceed() final { owner.blobLoadingSucceeded(); }
 
         FetchBodyOwner& owner;
@@ -80,14 +95,16 @@ private:
     };
 
 protected:
-    FetchBody m_body;
+    std::optional<FetchBody> m_body;
+    String m_contentType;
+    bool m_isDisturbed { false };
+#if ENABLE(STREAMS_API)
+    RefPtr<FetchResponseSource> m_readableStreamSource;
+#endif
+    Ref<FetchHeaders> m_headers;
 
 private:
-    Optional<BlobLoader> m_blobLoader;
+    std::optional<BlobLoader> m_blobLoader;
 };
 
 } // namespace WebCore
-
-#endif // ENABLE(FETCH_API)
-
-#endif // FetchBodyOwner_h