Title: [241695] releases/WebKitGTK/webkit-2.24/Source
Revision
241695
Author
carlo...@webkit.org
Date
2019-02-18 08:15:22 -0800 (Mon, 18 Feb 2019)

Log Message

Merge r241603 - Make ServiceWorkerClientFetch closer to WebResourceLoader
https://bugs.webkit.org/show_bug.cgi?id=194651

Reviewed by Alex Christensen.

Source/WebCore:

Check for redirection response and if so call a specific client API.
Ensure ServiceWorkerFetch::Client gets called in the service worker thread proxy
so that its m_connection is only accessed on that thread.

Covered by existing tests.

* platform/network/FormData.h:
* platform/network/ResourceErrorBase.h:
* workers/service/context/ServiceWorkerFetch.cpp:
(WebCore::ServiceWorkerFetch::processResponse):
* workers/service/context/ServiceWorkerFetch.h:
* workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::cancelFetch):
(WebCore::ServiceWorkerThreadProxy::continueDidReceiveFetchResponse):
* workers/service/context/ServiceWorkerThreadProxy.h:

Source/WebKit:

The goal of this refactoring is to, at some point use the regular network process load path for service worker loads.
This should simplify things and allow less IPC exchanges, for instance in the case of fetch not handled by service worker.

Introduce two IPC messages for supporting redirect responses and allow the didReceiveResponse/continueDidReceiveResponse
handshake for navigation loads.

This makes ServiceWorker having to buffer load information for this particular case.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::didReceiveFetchRedirectResponse):
(WebKit::NetworkProcess::didReceiveFetchResponse):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::continueDidReceiveFetchResponse):
(WebKit::WebSWServerConnection::didReceiveFetchRedirectResponse):
(WebKit::WebSWServerConnection::didReceiveFetchResponse):
* NetworkProcess/ServiceWorker/WebSWServerConnection.h:
* NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
* WebProcess/Storage/ServiceWorkerClientFetch.cpp:
(WebKit::ServiceWorkerClientFetch::start):
(WebKit::ServiceWorkerClientFetch::didReceiveRedirectResponse):
(WebKit::ServiceWorkerClientFetch::didReceiveResponse):
(WebKit::ServiceWorkerClientFetch::didReceiveData):
(WebKit::ServiceWorkerClientFetch::didFinish):
(WebKit::ServiceWorkerClientFetch::didFail):
(WebKit::ServiceWorkerClientFetch::didNotHandle):
(WebKit::ServiceWorkerClientFetch::cancel):
* WebProcess/Storage/ServiceWorkerClientFetch.h:
* WebProcess/Storage/ServiceWorkerClientFetch.messages.in:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::startFetch):
(WebKit::WebSWClientConnection::cancelFetch):
(WebKit::WebSWClientConnection::continueDidReceiveFetchResponse):
* WebProcess/Storage/WebSWClientConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::continueDidReceiveFetchResponse):
(WebKit::WebSWContextManagerConnection::startFetch):
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:
* WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp:
(WebKit::WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveRedirection):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveResponse):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveData):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveFormDataAndFinish):
(WebKit::WebServiceWorkerFetchTaskClient::didFail):
(WebKit::WebServiceWorkerFetchTaskClient::didFinish):
(WebKit::WebServiceWorkerFetchTaskClient::continueDidReceiveResponse):
* WebProcess/Storage/WebServiceWorkerFetchTaskClient.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog	2019-02-18 16:15:22 UTC (rev 241695)
@@ -1,5 +1,28 @@
 2019-02-15  Youenn Fablet  <you...@apple.com>
 
+        Make ServiceWorkerClientFetch closer to WebResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=194651
+
+        Reviewed by Alex Christensen.
+
+        Check for redirection response and if so call a specific client API.
+        Ensure ServiceWorkerFetch::Client gets called in the service worker thread proxy
+        so that its m_connection is only accessed on that thread.
+
+        Covered by existing tests.
+
+        * platform/network/FormData.h:
+        * platform/network/ResourceErrorBase.h:
+        * workers/service/context/ServiceWorkerFetch.cpp:
+        (WebCore::ServiceWorkerFetch::processResponse):
+        * workers/service/context/ServiceWorkerFetch.h:
+        * workers/service/context/ServiceWorkerThreadProxy.cpp:
+        (WebCore::ServiceWorkerThreadProxy::cancelFetch):
+        (WebCore::ServiceWorkerThreadProxy::continueDidReceiveFetchResponse):
+        * workers/service/context/ServiceWorkerThreadProxy.h:
+
+2019-02-15  Youenn Fablet  <you...@apple.com>
+
         Make navigator.mediaDevices SecureContext
         https://bugs.webkit.org/show_bug.cgi?id=194666
 

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/platform/network/FormData.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/platform/network/FormData.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/platform/network/FormData.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -210,7 +210,7 @@
     // FIXME: Both these functions perform a deep copy of m_elements, but differ in handling of other data members.
     // How much of that is intentional? We need better names that explain the difference.
     Ref<FormData> copy() const;
-    Ref<FormData> isolatedCopy() const;
+    WEBCORE_EXPORT Ref<FormData> isolatedCopy() const;
 
     template<typename Encoder>
     void encode(Encoder&) const;

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/platform/network/ResourceErrorBase.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/platform/network/ResourceErrorBase.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/platform/network/ResourceErrorBase.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -38,7 +38,7 @@
 
 class ResourceErrorBase {
 public:
-    ResourceError isolatedCopy() const;
+    WEBCORE_EXPORT ResourceError isolatedCopy() const;
 
     const String& domain() const { lazyInit(); return m_domain; }
     int errorCode() const { lazyInit(); return m_errorCode; }

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -51,8 +51,6 @@
     }
     auto response = WTFMove(result.value());
 
-    client->didReceiveResponse(response->resourceResponse());
-
     auto loadingError = response->loadingError();
     if (!loadingError.isNull()) {
         client->didFail(loadingError);
@@ -59,6 +57,14 @@
         return;
     }
 
+    auto resourceResponse = response->resourceResponse();
+    if (resourceResponse.isRedirection() && resourceResponse.httpHeaderFields().contains(HTTPHeaderName::Location)) {
+        client->didReceiveRedirection(resourceResponse);
+        return;
+    }
+
+    client->didReceiveResponse(resourceResponse);
+
     if (response->isBodyReceivedByChunk()) {
         response->consumeBodyReceivedByChunk([client = WTFMove(client)] (auto&& result) mutable {
             if (result.hasException()) {

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerFetch.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerFetch.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerFetch.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -44,10 +44,11 @@
 class SharedBuffer;
 
 namespace ServiceWorkerFetch {
-class Client : public ThreadSafeRefCounted<Client> {
+class Client : public ThreadSafeRefCounted<Client, WTF::DestructionThread::Main> {
 public:
     virtual ~Client() = default;
 
+    virtual void didReceiveRedirection(const ResourceResponse&) = 0;
     virtual void didReceiveResponse(const ResourceResponse&) = 0;
     virtual void didReceiveData(Ref<SharedBuffer>&&) = 0;
     virtual void didReceiveFormDataAndFinish(Ref<FormData>&&) = 0;
@@ -55,6 +56,7 @@
     virtual void didFinish() = 0;
     virtual void didNotHandle() = 0;
     virtual void cancel() = 0;
+    virtual void continueDidReceiveResponse() = 0;
 };
 
 void dispatchFetchEvent(Ref<Client>&&, ServiceWorkerGlobalScope&, Optional<ServiceWorkerClientIdentifier>, ResourceRequest&&, String&& referrer, FetchOptions&&);

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -200,10 +200,26 @@
 
 void ServiceWorkerThreadProxy::cancelFetch(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier)
 {
-    if (auto client = m_ongoingFetchTasks.take(std::make_pair(connectionIdentifier, fetchIdentifier)))
-        client.value()->cancel();
+    auto client = m_ongoingFetchTasks.take(std::make_pair(connectionIdentifier, fetchIdentifier));
+    if (!client)
+        return;
+
+    postTaskForModeToWorkerGlobalScope([client = WTFMove(client.value())] (ScriptExecutionContext&) {
+        client->cancel();
+    }, WorkerRunLoop::defaultMode());
 }
 
+void ServiceWorkerThreadProxy::continueDidReceiveFetchResponse(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier)
+{
+    auto client = m_ongoingFetchTasks.get(std::make_pair(connectionIdentifier, fetchIdentifier));
+    if (!client)
+        return;
+
+    postTaskForModeToWorkerGlobalScope([client = makeRef(*client)] (ScriptExecutionContext&) {
+        client->continueDidReceiveResponse();
+    }, WorkerRunLoop::defaultMode());
+}
+
 void ServiceWorkerThreadProxy::removeFetch(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier)
 {
     m_ongoingFetchTasks.remove(std::make_pair(connectionIdentifier, fetchIdentifier));

Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -73,6 +73,7 @@
 
     WEBCORE_EXPORT void startFetch(SWServerConnectionIdentifier, FetchIdentifier, Ref<ServiceWorkerFetch::Client>&&, Optional<ServiceWorkerClientIdentifier>&&, ResourceRequest&&, String&& referrer, FetchOptions&&);
     WEBCORE_EXPORT void cancelFetch(SWServerConnectionIdentifier, FetchIdentifier);
+    WEBCORE_EXPORT void continueDidReceiveFetchResponse(SWServerConnectionIdentifier, FetchIdentifier);
     WEBCORE_EXPORT void removeFetch(SWServerConnectionIdentifier, FetchIdentifier);
 
 private:

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog	2019-02-18 16:15:22 UTC (rev 241695)
@@ -1,3 +1,61 @@
+2019-02-15  Youenn Fablet  <you...@apple.com>
+
+        Make ServiceWorkerClientFetch closer to WebResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=194651
+
+        Reviewed by Alex Christensen.
+
+        The goal of this refactoring is to, at some point use the regular network process load path for service worker loads.
+        This should simplify things and allow less IPC exchanges, for instance in the case of fetch not handled by service worker.
+
+        Introduce two IPC messages for supporting redirect responses and allow the didReceiveResponse/continueDidReceiveResponse
+        handshake for navigation loads.
+
+        This makes ServiceWorker having to buffer load information for this particular case.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::didReceiveFetchRedirectResponse):
+        (WebKit::NetworkProcess::didReceiveFetchResponse):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::continueDidReceiveFetchResponse):
+        (WebKit::WebSWServerConnection::didReceiveFetchRedirectResponse):
+        (WebKit::WebSWServerConnection::didReceiveFetchResponse):
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
+        * WebProcess/Storage/ServiceWorkerClientFetch.cpp:
+        (WebKit::ServiceWorkerClientFetch::start):
+        (WebKit::ServiceWorkerClientFetch::didReceiveRedirectResponse):
+        (WebKit::ServiceWorkerClientFetch::didReceiveResponse):
+        (WebKit::ServiceWorkerClientFetch::didReceiveData):
+        (WebKit::ServiceWorkerClientFetch::didFinish):
+        (WebKit::ServiceWorkerClientFetch::didFail):
+        (WebKit::ServiceWorkerClientFetch::didNotHandle):
+        (WebKit::ServiceWorkerClientFetch::cancel):
+        * WebProcess/Storage/ServiceWorkerClientFetch.h:
+        * WebProcess/Storage/ServiceWorkerClientFetch.messages.in:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::startFetch):
+        (WebKit::WebSWClientConnection::cancelFetch):
+        (WebKit::WebSWClientConnection::continueDidReceiveFetchResponse):
+        * WebProcess/Storage/WebSWClientConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::continueDidReceiveFetchResponse):
+        (WebKit::WebSWContextManagerConnection::startFetch):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+        * WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp:
+        (WebKit::WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient):
+        (WebKit::WebServiceWorkerFetchTaskClient::didReceiveRedirection):
+        (WebKit::WebServiceWorkerFetchTaskClient::didReceiveResponse):
+        (WebKit::WebServiceWorkerFetchTaskClient::didReceiveData):
+        (WebKit::WebServiceWorkerFetchTaskClient::didReceiveFormDataAndFinish):
+        (WebKit::WebServiceWorkerFetchTaskClient::didFail):
+        (WebKit::WebServiceWorkerFetchTaskClient::didFinish):
+        (WebKit::WebServiceWorkerFetchTaskClient::continueDidReceiveResponse):
+        * WebProcess/Storage/WebServiceWorkerFetchTaskClient.h:
+
 2019-02-15  Alex Christensen  <achristen...@webkit.org>
 
         Update IPC code generator unit test expectations after r241595

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -2170,12 +2170,18 @@
         connection->didNotHandleFetch(fetchIdentifier);
 }
 
-void NetworkProcess::didReceiveFetchResponse(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const WebCore::ResourceResponse& response)
+void NetworkProcess::didReceiveFetchRedirectResponse(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const WebCore::ResourceResponse& response)
 {
     if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
-        connection->didReceiveFetchResponse(fetchIdentifier, response);
+        connection->didReceiveFetchRedirectResponse(fetchIdentifier, response);
 }
 
+void NetworkProcess::didReceiveFetchResponse(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const WebCore::ResourceResponse& response, bool needsContinueDidReceiveResponseMessage)
+{
+    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
+        connection->didReceiveFetchResponse(fetchIdentifier, response, needsContinueDidReceiveResponseMessage);
+}
+
 void NetworkProcess::didReceiveFetchData(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const IPC::DataReference& data, int64_t encodedDataLength)
 {
     if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -398,7 +398,8 @@
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    void didReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceResponse&);
+    void didReceiveFetchRedirectResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceResponse&);
+    void didReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceResponse&, bool needsContinueDidReceiveResponseMessage);
     void didReceiveFetchData(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
     void didReceiveFetchFormData(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const IPC::FormDataReference&);
     void didFinishFetch(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier);

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2019-02-18 16:15:22 UTC (rev 241695)
@@ -149,7 +149,8 @@
 #if ENABLE(SERVICE_WORKER)
     DidNotHandleFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier)
     DidFailFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceError error)
-    DidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceResponse response)
+    DidReceiveFetchRedirectResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceResponse response)
+    DidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceResponse response, bool needsContinueDidReceiveResponseMessage)
     DidReceiveFetchData(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, IPC::SharedBufferDataReference data, int64_t encodedDataLength)
     DidReceiveFetchFormData(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, IPC::FormDataReference data)
     DidFinishFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier)

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -139,6 +139,19 @@
     });
 }
 
+void WebSWServerConnection::continueDidReceiveFetchResponse(ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, FetchIdentifier fetchIdentifier)
+{
+    auto* worker = server().activeWorkerFromRegistrationID(serviceWorkerRegistrationIdentifier);
+    if (!worker || !worker->isRunning())
+        return;
+
+    auto serviceWorkerIdentifier = worker->identifier();
+    server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = makeWeakPtr(this), this, serviceWorkerIdentifier, fetchIdentifier](auto* contextConnection) mutable {
+        if (weakThis && contextConnection)
+            sendToContextProcess(*contextConnection, Messages::WebSWContextManagerConnection::ContinueDidReceiveFetchResponse { this->identifier(), serviceWorkerIdentifier, fetchIdentifier });
+    });
+}
+
 void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer)
 {
     auto* worker = server().activeWorkerFromRegistrationID(serviceWorkerRegistrationIdentifier);
@@ -230,11 +243,16 @@
     server().scheduleJob(WTFMove(jobData));
 }
 
-void WebSWServerConnection::didReceiveFetchResponse(FetchIdentifier fetchIdentifier, const ResourceResponse& response)
+void WebSWServerConnection::didReceiveFetchRedirectResponse(FetchIdentifier fetchIdentifier, const ResourceResponse& response)
 {
-    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveResponse { response }, fetchIdentifier.toUInt64());
+    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveRedirectResponse { response }, fetchIdentifier.toUInt64());
 }
 
+void WebSWServerConnection::didReceiveFetchResponse(FetchIdentifier fetchIdentifier, const ResourceResponse& response, bool needsContinueDidReceiveResponseMessage)
+{
+    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveResponse { response, needsContinueDidReceiveResponseMessage }, fetchIdentifier.toUInt64());
+}
+
 void WebSWServerConnection::didReceiveFetchData(FetchIdentifier fetchIdentifier, const IPC::DataReference& data, int64_t encodedDataLength)
 {
     m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveData { data, encodedDataLength }, fetchIdentifier.toUInt64());

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -63,7 +63,8 @@
 
     PAL::SessionID sessionID() const { return m_sessionID; }
 
-    void didReceiveFetchResponse(WebCore::FetchIdentifier, const WebCore::ResourceResponse&);
+    void didReceiveFetchRedirectResponse(WebCore::FetchIdentifier, const WebCore::ResourceResponse&);
+    void didReceiveFetchResponse(WebCore::FetchIdentifier, const WebCore::ResourceResponse&, bool needsContinueDidReceiveResponseMessage);
     void didReceiveFetchData(WebCore::FetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
     void didReceiveFetchFormData(WebCore::FetchIdentifier, const IPC::FormDataReference&);
     void didFinishFetch(WebCore::FetchIdentifier);
@@ -91,6 +92,7 @@
 
     void startFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer);
     void cancelFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier);
+    void continueDidReceiveFetchResponse(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier);
 
     void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL);
     void getRegistrations(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL);

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in	2019-02-18 16:15:22 UTC (rev 241695)
@@ -31,6 +31,7 @@
 
     StartFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer)
     CancelFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier)
+    ContinueDidReceiveFetchResponse(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier)
 
     PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientIdentifier source)
 

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -70,9 +70,6 @@
 
     auto referrer = request.httpReferrer();
 
-    m_didFail = false;
-    m_didFinish = false;
-
     // We are intercepting fetch calls after going through the HTTP layer, which may add some specific headers.
     cleanHTTPRequestHeadersForAccessControl(request, options.httpHeadersToKeep);
 
@@ -79,8 +76,6 @@
     ASSERT(options.serviceWorkersMode != ServiceWorkersMode::None);
     m_serviceWorkerRegistrationIdentifier = options.serviceWorkerRegistrationIdentifier.value();
     m_connection->startFetch(m_identifier, m_serviceWorkerRegistrationIdentifier, request, options, referrer);
-
-    m_redirectionStatus = RedirectionStatus::None;
 }
 
 // https://fetch.spec.whatwg.org/#http-fetch step 3.3
@@ -104,43 +99,54 @@
     return WTF::nullopt;
 }
 
-void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response)
+void ServiceWorkerClientFetch::didReceiveRedirectResponse(ResourceResponse&& response)
 {
-    m_isCheckingResponse = true;
     callOnMainThread([this, protectedThis = makeRef(*this), response = WTFMove(response)]() mutable {
-        if (!m_loader) {
-            m_isCheckingResponse = false;
+        if (!m_loader)
             return;
-        }
 
         if (auto error = validateResponse(response)) {
-            m_isCheckingResponse = false;
             m_loader->didFail(error.value());
             ASSERT(!m_loader);
             if (auto callback = WTFMove(m_callback))
                 callback(Result::Succeeded);
+
             return;
         }
         response.setSource(ResourceResponse::Source::ServiceWorker);
 
-        if (response.isRedirection() && response.httpHeaderFields().contains(HTTPHeaderName::Location)) {
-            m_isCheckingResponse = false;
-            continueLoadingAfterCheckingResponse();
-            m_redirectionStatus = RedirectionStatus::Receiving;
-            m_loader->willSendRequest(m_loader->request().redirectedRequest(response, m_shouldClearReferrerOnHTTPSToHTTPRedirect), response, [protectedThis = makeRef(*this), this](ResourceRequest&& request) {
-                if (request.isNull() || !m_callback)
-                    return;
+        m_loader->willSendRequest(m_loader->request().redirectedRequest(response, m_shouldClearReferrerOnHTTPSToHTTPRedirect), response, [protectedThis = makeRef(*this), this](ResourceRequest&& request) {
+            if (!m_loader || request.isNull()) {
+                if (auto callback = WTFMove(m_callback))
+                    callback(Result::Succeeded);
+                return;
+            }
+            ASSERT(request == m_loader->request());
+            start();
+        });
+    });
+}
 
-                ASSERT(request == m_loader->request());
-                if (m_redirectionStatus == RedirectionStatus::Received) {
-                    start();
-                    return;
-                }
-                m_redirectionStatus = RedirectionStatus::Following;
-            });
+void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response, bool needsContinueDidReceiveResponseMessage)
+{
+    callOnMainThread([this, protectedThis = makeRef(*this), response = WTFMove(response), needsContinueDidReceiveResponseMessage]() mutable {
+        if (!m_loader)
             return;
+
+        if (auto error = validateResponse(response)) {
+            m_loader->didFail(error.value());
+            ASSERT(!m_loader);
+            if (auto callback = WTFMove(m_callback))
+                callback(Result::Succeeded);
+
+            return;
         }
+        response.setSource(ResourceResponse::Source::ServiceWorker);
+        ASSERT(!response.isRedirection() || !response.httpHeaderFields().contains(HTTPHeaderName::Location));
 
+        if (auto callback = WTFMove(m_callback))
+            callback(Result::Succeeded);
+
         // In case of main resource and mime type is the default one, we set it to text/html to pass more service worker WPT tests.
         // FIXME: We should refine our MIME type sniffing strategy for synthetic responses.
         if (m_loader->originalRequest().requester() == ResourceRequest::Requester::Main) {
@@ -154,11 +160,16 @@
         if (response.url().isNull())
             response.setURL(m_loader->request().url());
 
+        if (!needsContinueDidReceiveResponseMessage) {
+            m_loader->didReceiveResponse(response, [] { });
+            return;
+        }
+
         m_loader->didReceiveResponse(response, [this, protectedThis = WTFMove(protectedThis)] {
-            m_isCheckingResponse = false;
-            continueLoadingAfterCheckingResponse();
-            if (auto callback = WTFMove(m_callback))
-                callback(Result::Succeeded);
+            if (!m_loader)
+                return;
+
+            m_connection->continueDidReceiveFetchResponse(m_identifier, m_serviceWorkerRegistrationIdentifier);
         });
     });
 }
@@ -166,23 +177,13 @@
 void ServiceWorkerClientFetch::didReceiveData(const IPC::DataReference& dataReference, int64_t encodedDataLength)
 {
     auto* data = "" char*>(dataReference.data());
-    if (!m_buffer) {
-        m_buffer = SharedBuffer::create(data, dataReference.size());
-        m_encodedDataLength = encodedDataLength;
-    } else {
-        m_buffer->append(data, dataReference.size());
+    callOnMainThread([this, protectedThis = makeRef(*this), encodedDataLength, buffer = SharedBuffer::create(data, dataReference.size())]() mutable {
+        if (!m_loader)
+            return;
+
         m_encodedDataLength += encodedDataLength;
-    }
 
-    if (m_isCheckingResponse)
-        return;
-
-    callOnMainThread([this, protectedThis = makeRef(*this)] {
-        if (!m_loader || !m_encodedDataLength)
-            return;
-
-        m_loader->didReceiveBuffer(m_buffer.releaseNonNull(), m_encodedDataLength, DataPayloadBytes);
-        m_encodedDataLength = 0;
+        m_loader->didReceiveBuffer(WTFMove(buffer), m_encodedDataLength, DataPayloadBytes);
     });
 }
 
@@ -193,29 +194,10 @@
 
 void ServiceWorkerClientFetch::didFinish()
 {
-    m_didFinish = true;
-
-    if (m_isCheckingResponse)
-        return;
-
     callOnMainThread([this, protectedThis = makeRef(*this)] {
         if (!m_loader)
             return;
 
-        switch (m_redirectionStatus) {
-        case RedirectionStatus::None:
-            break;
-        case RedirectionStatus::Receiving:
-            m_redirectionStatus = RedirectionStatus::Received;
-            return;
-        case RedirectionStatus::Following:
-            start();
-            return;
-        case RedirectionStatus::Received:
-            ASSERT_NOT_REACHED();
-            m_redirectionStatus = RedirectionStatus::None;
-        }
-
         ASSERT(!m_callback);
 
         m_loader->didFinishLoading(NetworkLoadMetrics { });
@@ -225,24 +207,18 @@
 
 void ServiceWorkerClientFetch::didFail(ResourceError&& error)
 {
-    m_didFail = true;
-    m_error = WTFMove(error);
-
-    if (m_isCheckingResponse)
-        return;
-
-    callOnMainThread([this, protectedThis = makeRef(*this)] {
+    callOnMainThread([this, protectedThis = makeRef(*this), error = WTFMove(error)] {
         if (!m_loader)
             return;
 
         auto* document = m_loader->frame() ? m_loader->frame()->document() : nullptr;
         if (document) {
-            document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, m_error.localizedDescription());
+            document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, error.localizedDescription());
             if (m_loader->options().destination != FetchOptions::Destination::EmptyString)
-                document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Cannot load ", m_error.failingURL().string(), "."));
+                document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Cannot load ", error.failingURL().string(), "."));
         }
 
-        m_loader->didFail(m_error);
+        m_loader->didFail(error);
 
         if (auto callback = WTFMove(m_callback))
             callback(Result::Succeeded);
@@ -253,8 +229,6 @@
 
 void ServiceWorkerClientFetch::didNotHandle()
 {
-    ASSERT(!m_isCheckingResponse);
-
     callOnMainThread([this, protectedThis = makeRef(*this)] {
         if (!m_loader)
             return;
@@ -271,38 +245,10 @@
     if (auto callback = WTFMove(m_callback))
         callback(Result::Cancelled);
 
-    if (!m_didFinish && !m_didFail) {
-        m_connection->cancelFetch(m_identifier, m_serviceWorkerRegistrationIdentifier);
-
-    }
+    m_connection->cancelFetch(m_identifier, m_serviceWorkerRegistrationIdentifier);
     m_loader = nullptr;
-    m_buffer = nullptr;
 }
 
-void ServiceWorkerClientFetch::continueLoadingAfterCheckingResponse()
-{
-    ASSERT(!m_isCheckingResponse);
-    if (!m_loader)
-        return;
-
-    if (m_encodedDataLength) {
-        callOnMainThread([this, protectedThis = makeRef(*this)] {
-            if (!m_loader || !m_encodedDataLength)
-                return;
-            m_loader->didReceiveBuffer(m_buffer.releaseNonNull(), m_encodedDataLength, DataPayloadBytes);
-            m_encodedDataLength = 0;
-        });
-    }
-
-    if (m_didFail) {
-        didFail(WTFMove(m_error));
-        return;
-    }
-
-    if (m_didFinish)
-        didFinish();
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -61,7 +61,8 @@
 
     Optional<WebCore::ResourceError> validateResponse(const WebCore::ResourceResponse&);
 
-    void didReceiveResponse(WebCore::ResourceResponse&&);
+    void didReceiveResponse(WebCore::ResourceResponse&&, bool needsContinueDidReceiveResponseMessage);
+    void didReceiveRedirectResponse(WebCore::ResourceResponse&&);
     void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength);
     void didReceiveFormData(const IPC::FormDataReference&);
     void didFinish();
@@ -68,23 +69,14 @@
     void didFail(WebCore::ResourceError&&);
     void didNotHandle();
 
-    void continueLoadingAfterCheckingResponse();
-
     WebServiceWorkerProvider& m_serviceWorkerProvider;
     RefPtr<WebCore::ResourceLoader> m_loader;
     WebCore::FetchIdentifier m_identifier;
     Ref<WebSWClientConnection> m_connection;
     Callback m_callback;
-    enum class RedirectionStatus { None, Receiving, Following, Received };
-    RedirectionStatus m_redirectionStatus { RedirectionStatus::None };
     bool m_shouldClearReferrerOnHTTPSToHTTPRedirect { true };
-    RefPtr<WebCore::SharedBuffer> m_buffer;
     int64_t m_encodedDataLength { 0 };
-    bool m_isCheckingResponse { false };
-    bool m_didFinish { false };
     bool m_didFail { false };
-    WebCore::ResourceError m_error;
-
     WebCore::ServiceWorkerRegistrationIdentifier m_serviceWorkerRegistrationIdentifier;
 };
 

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in	2019-02-18 16:15:22 UTC (rev 241695)
@@ -23,7 +23,8 @@
 #if ENABLE(SERVICE_WORKER)
 
 messages -> ServiceWorkerClientFetch {
-    DidReceiveResponse(WebCore::ResourceResponse response)
+    DidReceiveResponse(WebCore::ResourceResponse response, bool needsContinueDidReceiveResponseMessage)
+    DidReceiveRedirectResponse(WebCore::ResourceResponse response)
     DidReceiveData(IPC::DataReference data, int64_t encodedDataLength)
     DidReceiveFormData(IPC::FormDataReference data)
     DidFinish()

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -198,16 +198,21 @@
     });
 }
 
-void WebSWClientConnection::startFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const WebCore::ResourceRequest& request, const WebCore::FetchOptions& options, const String& referrer)
+void WebSWClientConnection::startFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const ResourceRequest& request, const FetchOptions& options, const String& referrer)
 {
     send(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer });
 }
 
-void WebSWClientConnection::cancelFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
+void WebSWClientConnection::cancelFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
 {
     send(Messages::WebSWServerConnection::CancelFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier });
 }
 
+void WebSWClientConnection::continueDidReceiveFetchResponse(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
+{
+    send(Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse { serviceWorkerRegistrationIdentifier, fetchIdentifier });
+}
+
 void WebSWClientConnection::postMessageToServiceWorkerClient(DocumentIdentifier destinationContextIdentifier, MessageWithMessagePorts&& message, ServiceWorkerData&& source, const String& sourceOrigin)
 {
     SWClientConnection::postMessageToServiceWorkerClient(destinationContextIdentifier, WTFMove(message), WTFMove(source), sourceOrigin);

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -63,6 +63,7 @@
     bool mayHaveServiceWorkerRegisteredForOrigin(const WebCore::SecurityOriginData&) const final;
     void startFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&, const String& referrer);
     void cancelFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier);
+    void continueDidReceiveFetchResponse(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier);
 
     void postMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerData&& source, const String& sourceOrigin);
 

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -215,6 +215,12 @@
         serviceWorkerThreadProxy->cancelFetch(serverConnectionIdentifier, fetchIdentifier);
 }
 
+void WebSWContextManagerConnection::continueDidReceiveFetchResponse(SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, FetchIdentifier fetchIdentifier)
+{
+    if (auto* serviceWorkerThreadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier))
+        serviceWorkerThreadProxy->continueDidReceiveFetchResponse(serverConnectionIdentifier, fetchIdentifier);
+}
+
 void WebSWContextManagerConnection::startFetch(SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer)
 {
     auto* serviceWorkerThreadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
@@ -228,7 +234,7 @@
         return;
     }
 
-    auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToNetworkProcess.copyRef(), serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier);
+    auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToNetworkProcess.copyRef(), serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier, request.requester() == ResourceRequest::Requester::Main);
     Optional<ServiceWorkerClientIdentifier> clientId;
     if (options.clientIdentifier)
         clientId = ServiceWorkerClientIdentifier { serverConnectionIdentifier, options.clientIdentifier.value() };

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -79,6 +79,7 @@
     void installServiceWorker(const WebCore::ServiceWorkerContextData&, PAL::SessionID, String&& userAgent);
     void startFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer);
     void cancelFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier);
+    void continueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier);
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerOrClientData&& sourceData);
     void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
     void fireActivateEvent(WebCore::ServiceWorkerIdentifier);

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in	2019-02-18 16:15:22 UTC (rev 241695)
@@ -26,6 +26,7 @@
     InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData, PAL::SessionID sessionID, String userAgent)
     StartFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer)
     CancelFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier)
+    ContinueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier)
     PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientData sourceData)
     FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
     FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp	2019-02-18 16:15:22 UTC (rev 241695)
@@ -42,25 +42,33 @@
 namespace WebKit {
 using namespace WebCore;
 
-WebServiceWorkerFetchTaskClient::~WebServiceWorkerFetchTaskClient()
-{
-    if (m_connection)
-        RunLoop::main().dispatch([connection = WTFMove(m_connection)] { });
-}
-
-WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier)
+WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, bool needsContinueDidReceiveResponseMessage)
     : m_connection(WTFMove(connection))
     , m_serverConnectionIdentifier(serverConnectionIdentifier)
     , m_serviceWorkerIdentifier(serviceWorkerIdentifier)
     , m_fetchIdentifier(fetchIdentifier)
+    , m_needsContinueDidReceiveResponseMessage(needsContinueDidReceiveResponseMessage)
 {
 }
 
+void WebServiceWorkerFetchTaskClient::didReceiveRedirection(const WebCore::ResourceResponse& response)
+{
+    if (!m_connection)
+        return;
+    m_connection->send(Messages::NetworkProcess::DidReceiveFetchRedirectResponse { m_serverConnectionIdentifier, m_fetchIdentifier, response }, 0);
+
+    cleanup();
+}
+
 void WebServiceWorkerFetchTaskClient::didReceiveResponse(const ResourceResponse& response)
 {
     if (!m_connection)
         return;
-    m_connection->send(Messages::NetworkProcess::DidReceiveFetchResponse { m_serverConnectionIdentifier, m_fetchIdentifier, response }, 0);
+
+    if (m_needsContinueDidReceiveResponseMessage)
+        m_waitingForContinueDidReceiveResponseMessage = true;
+
+    m_connection->send(Messages::NetworkProcess::DidReceiveFetchResponse { m_serverConnectionIdentifier, m_fetchIdentifier, response, m_needsContinueDidReceiveResponseMessage }, 0);
 }
 
 void WebServiceWorkerFetchTaskClient::didReceiveData(Ref<SharedBuffer>&& buffer)
@@ -67,6 +75,15 @@
 {
     if (!m_connection)
         return;
+
+    if (m_waitingForContinueDidReceiveResponseMessage) {
+        if (!WTF::holds_alternative<Ref<SharedBuffer>>(m_responseData))
+            m_responseData = buffer->copy();
+        else
+            WTF::get<Ref<SharedBuffer>>(m_responseData)->append(WTFMove(buffer));
+        return;
+    }
+
     m_connection->send(Messages::NetworkProcess::DidReceiveFetchData { m_serverConnectionIdentifier, m_fetchIdentifier, { buffer }, static_cast<int64_t>(buffer->size()) }, 0);
 }
 
@@ -75,6 +92,11 @@
     if (!m_connection)
         return;
 
+    if (m_waitingForContinueDidReceiveResponseMessage) {
+        m_responseData = formData->isolatedCopy();
+        return;
+    }
+
     // FIXME: We should send this form data to the other process and consume it there.
     // For now and for the case of blobs, we read it there and send the data through IPC.
     URL blobURL = formData->asBlobURL();
@@ -122,6 +144,11 @@
     if (!m_connection)
         return;
 
+    if (m_waitingForContinueDidReceiveResponseMessage) {
+        m_responseData = makeUniqueRef<ResourceError>(error.isolatedCopy());
+        return;
+    }
+
     m_connection->send(Messages::NetworkProcess::DidFailFetch { m_serverConnectionIdentifier, m_fetchIdentifier, error }, 0);
 
     cleanup();
@@ -132,6 +159,11 @@
     if (!m_connection)
         return;
 
+    if (m_waitingForContinueDidReceiveResponseMessage) {
+        m_didFinish = true;
+        return;
+    }
+
     m_connection->send(Messages::NetworkProcess::DidFinishFetch { m_serverConnectionIdentifier, m_fetchIdentifier }, 0);
 
     cleanup();
@@ -152,6 +184,28 @@
     m_connection = nullptr;
 }
 
+void WebServiceWorkerFetchTaskClient::continueDidReceiveResponse()
+{
+    if (!m_connection)
+        return;
+
+    m_waitingForContinueDidReceiveResponseMessage = false;
+
+    switchOn(m_responseData, [this](std::nullptr_t&) {
+        if (m_didFinish)
+            didFinish();
+    }, [this](Ref<SharedBuffer>& buffer) {
+        didReceiveData(WTFMove(buffer));
+        if (m_didFinish)
+            didFinish();
+    }, [this](Ref<FormData>& formData) {
+        didReceiveFormDataAndFinish(WTFMove(formData));
+    }, [this](UniqueRef<ResourceError>& error) {
+        didFail(error.get());
+    });
+    m_responseData = nullptr;
+}
+
 void WebServiceWorkerFetchTaskClient::cleanup()
 {
     m_connection = nullptr;

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h (241694 => 241695)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h	2019-02-18 16:15:09 UTC (rev 241694)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h	2019-02-18 16:15:22 UTC (rev 241695)
@@ -31,6 +31,7 @@
 #include <WebCore/FetchIdentifier.h>
 #include <WebCore/FetchLoader.h>
 #include <WebCore/FetchLoaderClient.h>
+#include <WebCore/ResourceError.h>
 #include <WebCore/ServiceWorkerFetch.h>
 #include <WebCore/ServiceWorkerTypes.h>
 
@@ -38,17 +39,16 @@
 
 class WebServiceWorkerFetchTaskClient final : public WebCore::ServiceWorkerFetch::Client {
 public:
-    static Ref<WebServiceWorkerFetchTaskClient> create(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier,  WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchTaskIdentifier)
+    static Ref<WebServiceWorkerFetchTaskClient> create(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier,  WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchTaskIdentifier, bool needsContinueDidReceiveResponseMessage)
     {
-        return adoptRef(*new WebServiceWorkerFetchTaskClient(WTFMove(connection), serviceWorkerIdentifier, serverConnectionIdentifier, fetchTaskIdentifier));
+        return adoptRef(*new WebServiceWorkerFetchTaskClient(WTFMove(connection), serviceWorkerIdentifier, serverConnectionIdentifier, fetchTaskIdentifier, needsContinueDidReceiveResponseMessage));
     }
 
-    ~WebServiceWorkerFetchTaskClient();
-
 private:
-    WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&&, WebCore::ServiceWorkerIdentifier, WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier);
+    WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&&, WebCore::ServiceWorkerIdentifier, WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, bool needsContinueDidReceiveResponseMessage);
 
     void didReceiveResponse(const WebCore::ResourceResponse&) final;
+    void didReceiveRedirection(const WebCore::ResourceResponse&) final;
     void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
     void didReceiveFormDataAndFinish(Ref<WebCore::FormData>&&) final;
     void didFail(const WebCore::ResourceError&) final;
@@ -55,6 +55,7 @@
     void didFinish() final;
     void didNotHandle() final;
     void cancel() final;
+    void continueDidReceiveResponse() final;
 
     void cleanup();
     
@@ -79,6 +80,10 @@
     WebCore::ServiceWorkerIdentifier m_serviceWorkerIdentifier;
     WebCore::FetchIdentifier m_fetchIdentifier;
     Optional<BlobLoader> m_blobLoader;
+    bool m_needsContinueDidReceiveResponseMessage { false };
+    bool m_waitingForContinueDidReceiveResponseMessage { false };
+    Variant<std::nullptr_t, Ref<WebCore::SharedBuffer>, Ref<FormData>, UniqueRef<ResourceError>> m_responseData;
+    bool m_didFinish { false };
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to