Title: [197778] trunk/Source/WebCore
Revision
197778
Author
youenn.fab...@crf.canon.fr
Date
2016-03-08 10:09:40 -0800 (Tue, 08 Mar 2016)

Log Message

[Fetch API] Commonalize handling of FetchBody by FetchRequest and FetchResponse
https://bugs.webkit.org/show_bug.cgi?id=154959

Reviewed by Darin Adler.

Introducing FetchBodyOwner class as base class of FetchRequest and FetchResponse.
This class is an ActiveDOMObject and is responsible of handling the Body API implemented by Request and Response.

Covered by existing tests.

* Modules/fetch/FetchBodyOwner.h: Added.
(WebCore::FetchBodyOwner::isDisturbed):
(WebCore::FetchBodyOwner::arrayBuffer):
(WebCore::FetchBodyOwner::formData):
(WebCore::FetchBodyOwner::blob):
(WebCore::FetchBodyOwner::json):
(WebCore::FetchBodyOwner::text):
(WebCore::FetchBodyOwner::body):
(WebCore::FetchBodyOwner::FetchBodyOwner):
* Modules/fetch/FetchRequest.h:
(WebCore::FetchRequest::FetchRequest):
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::FetchResponse):
* Modules/fetch/FetchResponse.h:
* WebCore.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197777 => 197778)


--- trunk/Source/WebCore/ChangeLog	2016-03-08 18:06:08 UTC (rev 197777)
+++ trunk/Source/WebCore/ChangeLog	2016-03-08 18:09:40 UTC (rev 197778)
@@ -1,3 +1,31 @@
+2016-03-08  Youenn Fablet  <youenn.fab...@crf.canon.fr>
+
+        [Fetch API] Commonalize handling of FetchBody by FetchRequest and FetchResponse
+        https://bugs.webkit.org/show_bug.cgi?id=154959
+
+        Reviewed by Darin Adler.
+
+        Introducing FetchBodyOwner class as base class of FetchRequest and FetchResponse.
+        This class is an ActiveDOMObject and is responsible of handling the Body API implemented by Request and Response.
+
+        Covered by existing tests.
+
+        * Modules/fetch/FetchBodyOwner.h: Added.
+        (WebCore::FetchBodyOwner::isDisturbed):
+        (WebCore::FetchBodyOwner::arrayBuffer):
+        (WebCore::FetchBodyOwner::formData):
+        (WebCore::FetchBodyOwner::blob):
+        (WebCore::FetchBodyOwner::json):
+        (WebCore::FetchBodyOwner::text):
+        (WebCore::FetchBodyOwner::body):
+        (WebCore::FetchBodyOwner::FetchBodyOwner):
+        * Modules/fetch/FetchRequest.h:
+        (WebCore::FetchRequest::FetchRequest):
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::FetchResponse):
+        * Modules/fetch/FetchResponse.h:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2016-03-08  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed, fix 32-bit build after r197726.

Copied: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (from rev 197777, trunk/Source/WebCore/Modules/fetch/FetchRequest.h) (0 => 197778)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2016-03-08 18:09:40 UTC (rev 197778)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Canon Inc. nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL CANON INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FetchBodyOwner_h
+#define FetchBodyOwner_h
+
+#if ENABLE(FETCH_API)
+
+#include "ActiveDOMObject.h"
+#include "FetchBody.h"
+
+namespace WebCore {
+
+class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject {
+public:
+    FetchBodyOwner(ScriptExecutionContext&, FetchBody&&);
+
+    // Exposed Body API
+    bool isDisturbed() const { return m_body.isDisturbed(); }
+    void arrayBuffer(FetchBody::ArrayBufferPromise&& promise) { m_body.arrayBuffer(WTFMove(promise)); }
+    void formData(FetchBody::FormDataPromise&& promise) { m_body.formData(WTFMove(promise)); }
+    void blob(FetchBody::BlobPromise&& promise) { m_body.blob(WTFMove(promise)); }
+    void json(JSC::ExecState& state, FetchBody::JSONPromise&& promise) { m_body.json(state, WTFMove(promise)); }
+    void text(FetchBody::TextPromise&& promise) { m_body.text(WTFMove(promise)); }
+
+protected:
+    FetchBody m_body;
+};
+
+inline FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext& context, FetchBody&& body)
+    : ActiveDOMObject(&context)
+    , m_body(WTFMove(body))
+{
+    suspendIfNeeded();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FETCH_API)
+
+#endif // FetchBodyOwner_h

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.h (197777 => 197778)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.h	2016-03-08 18:06:08 UTC (rev 197777)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.h	2016-03-08 18:09:40 UTC (rev 197778)
@@ -31,8 +31,7 @@
 
 #if ENABLE(FETCH_API)
 
-#include "ActiveDOMObject.h"
-#include "FetchBody.h"
+#include "FetchBodyOwner.h"
 #include "FetchHeaders.h"
 #include "FetchOptions.h"
 #include "ResourceRequest.h"
@@ -44,7 +43,7 @@
 
 typedef int ExceptionCode;
 
-class FetchRequest final : public RefCounted<FetchRequest>, public ActiveDOMObject {
+class FetchRequest final : public FetchBodyOwner {
 public:
     static RefPtr<FetchRequest> create(ScriptExecutionContext&, FetchRequest*, const Dictionary&, ExceptionCode&);
     static RefPtr<FetchRequest> create(ScriptExecutionContext&, const String&, const Dictionary&, ExceptionCode&);
@@ -66,14 +65,6 @@
 
     RefPtr<FetchRequest> clone(ScriptExecutionContext*, ExceptionCode&);
 
-    // Body API
-    bool isDisturbed() const { return m_body.isDisturbed(); }
-    void arrayBuffer(FetchBody::ArrayBufferPromise&& promise) { m_body.arrayBuffer(WTFMove(promise)); }
-    void formData(FetchBody::FormDataPromise&& promise) { m_body.formData(WTFMove(promise)); }
-    void blob(FetchBody::BlobPromise&& promise) { m_body.blob(WTFMove(promise)); }
-    void json(JSC::ExecState& state, FetchBody::JSONPromise&& promise) { m_body.json(state, WTFMove(promise)); }
-    void text(FetchBody::TextPromise&& promise) { m_body.text(WTFMove(promise)); }
-
     struct InternalRequest {
         ResourceRequest request;
         FetchOptions options;
@@ -81,8 +72,6 @@
         String integrity;
     };
 
-    FetchBody& body() { return m_body; }
-
 private:
     FetchRequest(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
 
@@ -90,18 +79,15 @@
     const char* activeDOMObjectName() const final;
     bool canSuspendForDocumentSuspension() const final;
 
-    FetchBody m_body;
     Ref<FetchHeaders> m_headers;
     InternalRequest m_internalRequest;
 };
 
 inline FetchRequest::FetchRequest(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
-    : ActiveDOMObject(&context)
-    , m_body(WTFMove(body))
+    : FetchBodyOwner(context, WTFMove(body))
     , m_headers(WTFMove(headers))
     , m_internalRequest(WTFMove(internalRequest))
 {
-    suspendIfNeeded();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (197777 => 197778)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2016-03-08 18:06:08 UTC (rev 197777)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2016-03-08 18:09:40 UTC (rev 197778)
@@ -109,13 +109,11 @@
 }
 
 FetchResponse::FetchResponse(ScriptExecutionContext& context, Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
-    : ActiveDOMObject(&context)
+    : FetchBodyOwner(context, WTFMove(body))
     , m_type(type)
     , m_response(WTFMove(response))
-    , m_body(WTFMove(body))
     , m_headers(WTFMove(headers))
 {
-    suspendIfNeeded();
 }
 
 RefPtr<FetchResponse> FetchResponse::clone(ScriptExecutionContext* context, ExceptionCode& ec)

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (197777 => 197778)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2016-03-08 18:06:08 UTC (rev 197777)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2016-03-08 18:09:40 UTC (rev 197778)
@@ -31,8 +31,7 @@
 
 #if ENABLE(FETCH_API)
 
-#include "ActiveDOMObject.h"
-#include "FetchBody.h"
+#include "FetchBodyOwner.h"
 #include "FetchHeaders.h"
 #include "ResourceResponse.h"
 
@@ -46,7 +45,7 @@
 
 typedef int ExceptionCode;
 
-class FetchResponse final : public RefCounted<FetchResponse>, public ActiveDOMObject {
+class FetchResponse final : public FetchBodyOwner {
 public:
     static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
     static Ref<FetchResponse> error(ScriptExecutionContext*);
@@ -66,14 +65,6 @@
     FetchHeaders& headers() { return m_headers; }
     RefPtr<FetchResponse> clone(ScriptExecutionContext*, ExceptionCode&);
 
-    // Body API
-    bool isDisturbed() const { return m_body.isDisturbed(); }
-    void arrayBuffer(FetchBody::ArrayBufferPromise&& promise) { m_body.arrayBuffer(WTFMove(promise)); }
-    void formData(FetchBody::FormDataPromise&& promise) { m_body.formData(WTFMove(promise)); }
-    void blob(FetchBody::BlobPromise&& promise) { m_body.blob(WTFMove(promise)); }
-    void json(JSC::ExecState& state, FetchBody::JSONPromise&& promise) { m_body.json(state, WTFMove(promise)); }
-    void text(FetchBody::TextPromise&& promise) { m_body.text(WTFMove(promise)); }
-
 private:
     enum class Type { Basic, Cors, Default, Error, Opaque, OpaqueRedirect };
 
@@ -85,7 +76,6 @@
 
     Type m_type;
     ResourceResponse m_response;
-    FetchBody m_body;
     Ref<FetchHeaders> m_headers;
     bool m_isLocked = false;
     bool m_isRedirected = false;

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (197777 => 197778)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-03-08 18:06:08 UTC (rev 197777)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-03-08 18:09:40 UTC (rev 197778)
@@ -9005,6 +9005,7 @@
 		4138D3331244054800323D33 /* EventContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventContext.h; sourceTree = "<group>"; };
 		4138D3341244054800323D33 /* EventContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventContext.cpp; sourceTree = "<group>"; };
 		413C2C331BC29A7B0075204C /* JSDOMConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMConstructor.h; sourceTree = "<group>"; };
+		4147E2B21C88337F00A7E715 /* FetchBodyOwner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchBodyOwner.h; sourceTree = "<group>"; };
 		415071551685067300C3C7B3 /* SelectorFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorFilter.cpp; sourceTree = "<group>"; };
 		415071561685067300C3C7B3 /* SelectorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorFilter.h; sourceTree = "<group>"; };
 		4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderThumbElement.h; sourceTree = "<group>"; };
@@ -16827,6 +16828,7 @@
 				41F54F7D1C50C4F600338488 /* FetchBody.cpp */,
 				41F54F7E1C50C4F600338488 /* FetchBody.h */,
 				41F54F7F1C50C4F600338488 /* FetchBody.idl */,
+ 				4147E2B21C88337F00A7E715 /* FetchBodyOwner.h */,
 				41F54F821C50C4F600338488 /* FetchHeaders.cpp */,
 				41F54F831C50C4F600338488 /* FetchHeaders.h */,
 				41F54F841C50C4F600338488 /* FetchHeaders.idl */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to