Unreviewed, rolling out r220271.
[WebKit.git] / Source / WebCore / Modules / fetch / FetchBodyOwner.h
index a60b1ad..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"
@@ -41,26 +39,35 @@ 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;
+    // 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>&&);
 
-    void arrayBuffer(DeferredWrapper&&);
-    void blob(DeferredWrapper&&);
-    void formData(DeferredWrapper&&);
-    void json(DeferredWrapper&&);
-    void text(DeferredWrapper&&);
+    bool isDisturbed() const { return m_isDisturbed; };
+    bool isDisturbedOrLocked() const;
 
-    void loadBlob(Blob&, FetchBodyConsumer*);
+    void loadBlob(const Blob&, FetchBodyConsumer*);
 
     bool isActive() const { return !!m_blobLoader; }
 
-    FetchBody::Type bodyType() const { return m_body.type(); }
-
 protected:
-    const FetchBody& body() const { return m_body; }
-    FetchBody& body() { return m_body; }
+    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;
@@ -88,18 +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