Add ServiceWorker to WebProcess plumbery for FormData fetch responses
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2017 19:28:03 +0000 (19:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2017 19:28:03 +0000 (19:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179694

Patch by Youenn Fablet <youenn@apple.com> on 2017-11-15
Reviewed by Alex Christensen.

Source/WebCore:

No observable changes since we are not actually loading FormData right now.

* workers/service/context/ServiceWorkerFetch.cpp:
(WebCore::ServiceWorkerFetch::processResponse):
* workers/service/context/ServiceWorkerFetch.h:

Source/WebKit:

Added plumbery from Service Worker up to Web Process to pass form data response bodies.
A follow-up patch should read the data from Network Process and send it to the ResourceLoader.

* Platform/IPC/FormDataReference.h: Added.
(IPC::FormDataReference::FormDataReference):
(IPC::FormDataReference::takeData):
(IPC::FormDataReference::encode const):
(IPC::FormDataReference::decode):
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::didReceiveFetchFormData):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::didReceiveFetchFormData):
* StorageProcess/StorageProcess.h:
* StorageProcess/StorageProcess.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Storage/ServiceWorkerClientFetch.cpp:
(WebKit::ServiceWorkerClientFetch::didReceiveFormData):
* WebProcess/Storage/ServiceWorkerClientFetch.h:
* WebProcess/Storage/ServiceWorkerClientFetch.messages.in:
* WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp:
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveFormData):
* WebProcess/Storage/WebServiceWorkerFetchTaskClient.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224889 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp
Source/WebCore/workers/service/context/ServiceWorkerFetch.h
Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/FormDataReference.h [new file with mode: 0644]
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/StorageProcess/StorageProcess.cpp
Source/WebKit/StorageProcess/StorageProcess.h
Source/WebKit/StorageProcess/StorageProcess.messages.in
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in
Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp
Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h

index 652c8e7..9215735 100644 (file)
@@ -1,3 +1,16 @@
+2017-11-15  Youenn Fablet  <youenn@apple.com>
+
+        Add ServiceWorker to WebProcess plumbery for FormData fetch responses
+        https://bugs.webkit.org/show_bug.cgi?id=179694
+
+        Reviewed by Alex Christensen.
+
+        No observable changes since we are not actually loading FormData right now.
+
+        * workers/service/context/ServiceWorkerFetch.cpp:
+        (WebCore::ServiceWorkerFetch::processResponse):
+        * workers/service/context/ServiceWorkerFetch.h:
+
 2017-11-15  Jer Noble  <jer.noble@apple.com>
 
         Add a compile-time-checked string literal initializer for FourCC.
index baff4f3..9368be6 100644 (file)
@@ -75,8 +75,8 @@ static void processResponse(Ref<Client>&& client, FetchResponse* response)
     }
 
     auto body = response->consumeBody();
-    WTF::switchOn(body, [] (Ref<FormData>&) {
-        // FIXME: Support FormData response bodies.
+    WTF::switchOn(body, [&] (Ref<FormData>& formData) {
+        client->didReceiveFormData(WTFMove(formData));
     }, [&] (Ref<SharedBuffer>& buffer) {
         client->didReceiveData(WTFMove(buffer));
     }, [] (std::nullptr_t&) {
index a20341c..fde9089 100644 (file)
@@ -34,6 +34,7 @@ namespace WebCore {
 class FetchEvent;
 struct FetchOptions;
 class FetchResponse;
+class FormData;
 class ResourceRequest;
 class ResourceResponse;
 class SharedBuffer;
@@ -46,6 +47,7 @@ public:
 
     virtual void didReceiveResponse(const ResourceResponse&) = 0;
     virtual void didReceiveData(Ref<SharedBuffer>&&) = 0;
+    virtual void didReceiveFormData(Ref<FormData>&&) = 0;
     virtual void didFail() = 0;
     virtual void didFinish() = 0;
     virtual void didNotHandle() = 0;
index 9a93b45..82f34f1 100644 (file)
@@ -1,3 +1,34 @@
+2017-11-15  Youenn Fablet  <youenn@apple.com>
+
+        Add ServiceWorker to WebProcess plumbery for FormData fetch responses
+        https://bugs.webkit.org/show_bug.cgi?id=179694
+
+        Reviewed by Alex Christensen.
+
+        Added plumbery from Service Worker up to Web Process to pass form data response bodies.
+        A follow-up patch should read the data from Network Process and send it to the ResourceLoader.
+
+        * Platform/IPC/FormDataReference.h: Added.
+        (IPC::FormDataReference::FormDataReference):
+        (IPC::FormDataReference::takeData):
+        (IPC::FormDataReference::encode const):
+        (IPC::FormDataReference::decode):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::didReceiveFetchFormData):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::didReceiveFetchFormData):
+        * StorageProcess/StorageProcess.h:
+        * StorageProcess/StorageProcess.messages.in:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Storage/ServiceWorkerClientFetch.cpp:
+        (WebKit::ServiceWorkerClientFetch::didReceiveFormData):
+        * WebProcess/Storage/ServiceWorkerClientFetch.h:
+        * WebProcess/Storage/ServiceWorkerClientFetch.messages.in:
+        * WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp:
+        (WebKit::WebServiceWorkerFetchTaskClient::didReceiveFormData):
+        * WebProcess/Storage/WebServiceWorkerFetchTaskClient.h:
+
 2017-11-15  Alex Christensen  <achristensen@webkit.org>
 
         Move a compiled WKContentRuleList to its destination before calling mmap
diff --git a/Source/WebKit/Platform/IPC/FormDataReference.h b/Source/WebKit/Platform/IPC/FormDataReference.h
new file mode 100644 (file)
index 0000000..cd9da6a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 APPLE INC. OR 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.
+ */
+
+#pragma once
+
+#include "Decoder.h"
+#include "Encoder.h"
+#include <WebCore/FormData.h>
+#include <wtf/Vector.h>
+
+namespace IPC {
+
+class FormDataReference {
+public:
+    FormDataReference() = default;
+
+    explicit FormDataReference(Ref<WebCore::FormData>&& data)
+        : m_data(WTFMove(data))
+    {
+    }
+
+    Ref<WebCore::FormData> takeData() { return m_data.releaseNonNull(); }
+
+    void encode(Encoder& encoder) const { encoder << *m_data; }
+    static std::optional<FormDataReference> decode(Decoder& decoder)
+    {
+        auto formData = WebCore::FormData::decode(decoder);
+        if (!formData)
+            return std::nullopt;
+        return FormDataReference { formData.releaseNonNull() };
+    }
+
+private:
+    RefPtr<WebCore::FormData> m_data;
+};
+
+} // namespace IPC
index 79632cc..b7a9029 100644 (file)
@@ -128,6 +128,11 @@ void WebSWServerConnection::didReceiveFetchData(uint64_t fetchIdentifier, const
     m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveData { data, encodedDataLength }, fetchIdentifier);
 }
 
+void WebSWServerConnection::didReceiveFetchFormData(uint64_t fetchIdentifier, const IPC::FormDataReference& formData)
+{
+    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveFormData { formData }, fetchIdentifier);
+}
+
 void WebSWServerConnection::didFinishFetch(uint64_t fetchIdentifier)
 {
     m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidFinish { }, fetchIdentifier);
index b5f4b96..2fdef3c 100644 (file)
 #include <WebCore/SWServer.h>
 #include <pal/SessionID.h>
 
+namespace IPC {
+class FormDataReference;
+}
+
 namespace WebCore {
 struct ExceptionData;
 struct ServiceWorkerClientData;
@@ -53,6 +57,7 @@ public:
 
     void didReceiveFetchResponse(uint64_t fetchIdentifier, const WebCore::ResourceResponse&);
     void didReceiveFetchData(uint64_t fetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
+    void didReceiveFetchFormData(uint64_t fetchIdentifier, const IPC::FormDataReference&);
     void didFinishFetch(uint64_t fetchIdentifier);
     void didFailFetch(uint64_t fetchIdentifier);
     void didNotHandleFetch(uint64_t fetchIdentifier);
index 6f13ebf..3baae7e 100644 (file)
@@ -434,6 +434,12 @@ void StorageProcess::didReceiveFetchData(uint64_t serverConnectionIdentifier, ui
         connection->didReceiveFetchData(fetchIdentifier, data, encodedDataLength);
 }
 
+void StorageProcess::didReceiveFetchFormData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const IPC::FormDataReference& formData)
+{
+    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
+        connection->didReceiveFetchFormData(fetchIdentifier, formData);
+}
+
 void StorageProcess::didFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
 {
     if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
index 591b583..6373129 100644 (file)
 #include <wtf/CrossThreadTask.h>
 #include <wtf/Function.h>
 
+namespace IPC {
+class FormDataReference;
+}
+
 namespace WebCore {
 class SWServer;
 struct SecurityOriginData;
@@ -122,6 +126,7 @@ private:
 
     void didReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const WebCore::ResourceResponse&);
     void didReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
+    void didReceiveFetchFormData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const IPC::FormDataReference&);
     void didFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
     void didFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
     void didNotHandleFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
index 0574902..66f29cd 100644 (file)
@@ -42,6 +42,7 @@ messages -> StorageProcess LegacyReceiver {
     DidFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     DidReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ResourceResponse response)
     DidReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, IPC::DataReference data, int64_t encodedDataLength)
+    DidReceiveFetchFormData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, IPC::FormDataReference data)
     DidFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     PostMessageToServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier destinationIdentifier, IPC::DataReference message, WebCore::ServiceWorkerIdentifier sourceIdentifier, String sourceOrigin)
 #endif
index 08de3c3..a6eaf43 100644 (file)
                414DEDC51F9E4BEC0047C40D /* ServiceWorkerFrameLoaderClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerFrameLoaderClient.cpp; sourceTree = "<group>"; };
                414DEDD51F9EDDDF0047C40D /* ServiceWorkerProcessProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerProcessProxy.h; sourceTree = "<group>"; };
                414DEDD61F9EDDE00047C40D /* ServiceWorkerProcessProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerProcessProxy.cpp; sourceTree = "<group>"; };
+               4151E5C31FBB90A900E47E2D /* FormDataReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormDataReference.h; sourceTree = "<group>"; };
                41897ECB1F415D5C0016FA42 /* WebCacheStorageConnection.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebCacheStorageConnection.messages.in; sourceTree = "<group>"; };
                41897ECC1F415D5C0016FA42 /* WebCacheStorageProvider.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebCacheStorageProvider.cpp; sourceTree = "<group>"; };
                41897ECD1F415D5C0016FA42 /* WebCacheStorageConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCacheStorageConnection.h; sourceTree = "<group>"; };
                                BC032D9E10F437D10058C15A /* Decoder.h */,
                                BC032D9F10F437D10058C15A /* Encoder.cpp */,
                                BC032DA010F437D10058C15A /* Encoder.h */,
+                               4151E5C31FBB90A900E47E2D /* FormDataReference.h */,
                                C0CE72AC1247E78D00BC0EC4 /* HandleMessage.h */,
                                1AC4C82816B876A90069DCCD /* MessageFlags.h */,
                                1A3EED11161A53D600AEB4F5 /* MessageReceiver.h */,
index 928bc32..6e1c3f9 100644 (file)
@@ -85,6 +85,11 @@ void ServiceWorkerClientFetch::didReceiveData(const IPC::DataReference& data, in
     m_loader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, DataPayloadBytes);
 }
 
+void ServiceWorkerClientFetch::didReceiveFormData(const IPC::FormDataReference&)
+{
+    // FIXME: Implement form data reading.
+}
+
 void ServiceWorkerClientFetch::didFinish()
 {
     ASSERT(!m_callback);
index 68de12b..b82b589 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "FormDataReference.h"
 #include "MessageReceiver.h"
 #include "MessageSender.h"
 #include <WebCore/ResourceLoader.h>
@@ -56,6 +57,7 @@ private:
 
     void didReceiveResponse(WebCore::ResourceResponse&&);
     void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength);
+    void didReceiveFormData(const IPC::FormDataReference&);
     void didFinish();
     void didFail();
     void didNotHandle();
index 40dda87..ae44f5b 100644 (file)
@@ -25,6 +25,7 @@
 messages -> ServiceWorkerClientFetch {
     DidReceiveResponse(WebCore::ResourceResponse response)
     DidReceiveData(IPC::DataReference data, int64_t encodedDataLength)
+    DidReceiveFormData(IPC::FormDataReference data)
     DidFinish()
     DidFail()
     DidNotHandle()
index 853cfde..8f709f2 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(SERVICE_WORKER)
 
 #include "DataReference.h"
+#include "FormDataReference.h"
 #include "StorageProcessMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include <WebCore/ResourceResponse.h>
@@ -66,6 +67,14 @@ void WebServiceWorkerFetchTaskClient::didReceiveData(Ref<SharedBuffer>&& buffer)
     m_connection->send(Messages::StorageProcess::DidReceiveFetchData { m_serverConnectionIdentifier, m_fetchTaskIdentifier, dataReference, static_cast<int64_t>(buffer->size()) }, 0);
 }
 
+void WebServiceWorkerFetchTaskClient::didReceiveFormData(Ref<FormData>&& formData)
+{
+    if (!m_connection)
+        return;
+
+    m_connection->send(Messages::StorageProcess::DidReceiveFetchFormData { m_serverConnectionIdentifier, m_fetchTaskIdentifier, IPC::FormDataReference { WTFMove(formData) } }, 0);
+}
+
 void WebServiceWorkerFetchTaskClient::didFail()
 {
     if (!m_connection)
index 5b1ec4f..6fb318c 100644 (file)
@@ -46,6 +46,7 @@ private:
 
     void didReceiveResponse(const WebCore::ResourceResponse&) final;
     void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
+    void didReceiveFormData(Ref<WebCore::FormData>&&) final;
     void didFail() final;
     void didFinish() final;
     void didNotHandle() final;