Title: [245873] trunk
Revision
245873
Author
[email protected]
Date
2019-05-29 15:21:08 -0700 (Wed, 29 May 2019)

Log Message

Reestablish WebSWClientConnection in case of network process crash
https://bugs.webkit.org/show_bug.cgi?id=198333

Reviewed by Alex Christensen.

Source/WebCore:

Refactor DocumentLoader to no longer take a ref to the SWClientConnection.
Instead, store the sessionID and get the SWClientConnection from it.
Remove unused code from ServiceWorkerContainer.

Test: http/wpt/service-workers/service-worker-networkprocess-crash.html

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::registerTemporaryServiceWorkerClient):
(WebCore::DocumentLoader::unregisterTemporaryServiceWorkerClient):
* loader/DocumentLoader.h:
* workers/service/ServiceWorkerContainer.cpp:
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerJobClient.h:

Source/WebKit:

WebSWClientConnection now takes a RefPtr<IPC::Connection> so that on network process crash, it will set it back to null.
On the next call that needs the connection, WebSWClientConnection will reinitialize its underlying IPC connection and its own identifier.
Make sure that all code paths requiring this initialization are covered.

* WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::didClose):
(WebKit::NetworkProcessConnection::serviceWorkerConnectionForSession):
(WebKit::NetworkProcessConnection::isRegisteredActiveSWClientConnection):
(WebKit::NetworkProcessConnection::initializeSWClientConnection):
* WebProcess/Network/NetworkProcessConnection.h:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::WebSWClientConnection):
(WebKit::WebSWClientConnection::~WebSWClientConnection):
(WebKit::WebSWClientConnection::initializeConnectionIfNeeded):
(WebKit::WebSWClientConnection::ensureConnectionAndSend):
(WebKit::WebSWClientConnection::scheduleJobInServer):
(WebKit::WebSWClientConnection::finishFetchingScriptInServer):
(WebKit::WebSWClientConnection::addServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::removeServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::registerServiceWorkerClient):
(WebKit::WebSWClientConnection::unregisterServiceWorkerClient):
(WebKit::WebSWClientConnection::didResolveRegistrationPromise):
(WebKit::WebSWClientConnection::matchRegistration):
(WebKit::WebSWClientConnection::runOrDelayTaskForImport):
(WebKit::WebSWClientConnection::whenRegistrationReady):
(WebKit::WebSWClientConnection::getRegistrations):
(WebKit::WebSWClientConnection::startFetch):
(WebKit::WebSWClientConnection::cancelFetch):
(WebKit::WebSWClientConnection::continueDidReceiveFetchResponse):
(WebKit::WebSWClientConnection::connectionToServerLost):
(WebKit::WebSWClientConnection::syncTerminateWorker):
(WebKit::WebSWClientConnection::serverConnectionIdentifier const):
(WebKit::WebSWClientConnection::updateThrottleState):
* WebProcess/Storage/WebSWClientConnection.h:

LayoutTests:

* http/wpt/service-workers/service-worker-networkprocess-crash-expected.txt: Added.
* http/wpt/service-workers/service-worker-networkprocess-crash.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (245872 => 245873)


--- trunk/LayoutTests/ChangeLog	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/LayoutTests/ChangeLog	2019-05-29 22:21:08 UTC (rev 245873)
@@ -1,3 +1,13 @@
+2019-05-29  Youenn Fablet  <[email protected]>
+
+        Reestablish WebSWClientConnection in case of network process crash
+        https://bugs.webkit.org/show_bug.cgi?id=198333
+
+        Reviewed by Alex Christensen.
+
+        * http/wpt/service-workers/service-worker-networkprocess-crash-expected.txt: Added.
+        * http/wpt/service-workers/service-worker-networkprocess-crash.html: Added.
+
 2019-05-29  Antti Koivisto  <[email protected]>
 
         Scrolling node ordering wrong when a layer has both positioning and fixed/sticky node

Added: trunk/LayoutTests/http/wpt/service-workers/service-worker-networkprocess-crash-expected.txt (0 => 245873)


--- trunk/LayoutTests/http/wpt/service-workers/service-worker-networkprocess-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/service-worker-networkprocess-crash-expected.txt	2019-05-29 22:21:08 UTC (rev 245873)
@@ -0,0 +1,5 @@
+
+PASS Setup worker 
+PASS Frame being controlled 
+PASS Frame being controlled after network process crash 
+

Added: trunk/LayoutTests/http/wpt/service-workers/service-worker-networkprocess-crash.html (0 => 245873)


--- trunk/LayoutTests/http/wpt/service-workers/service-worker-networkprocess-crash.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/service-worker-networkprocess-crash.html	2019-05-29 22:21:08 UTC (rev 245873)
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Cache Storage: network process crash</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var scope = "/WebKit/service-workers/resources";
+
+function withFrame(url)
+{
+    return new Promise((resolve) => {
+        let frame = document.createElement('iframe');
+        frame.src = ""
+        frame._onload_ = function() { resolve(frame); };
+        document.body.appendChild(frame);
+    });
+}
+
+async function registerServiceWorker()
+{
+    var registration = await navigator.serviceWorker.register("fetchEvent-worker.js", { scope : scope });
+    var activeWorker = registration.active;
+    if (activeWorker)
+        return;
+    activeWorker = registration.installing;
+    return new Promise(resolve => {
+        activeWorker.addEventListener('statechange', () => {
+            if (activeWorker.state === "activated")
+                resolve(registration);
+        });
+    });
+}
+
+promise_test(async (test) => {
+    await registerServiceWorker();
+}, "Setup worker");
+
+promise_test(async (test) => {
+    const frame = await withFrame(scope + "/empty.html");
+    assert_not_equals(frame.contentWindow.navigator.serviceWorker.controller, null);
+    frame.remove();
+}, "Frame being controlled");
+
+promise_test(async (test) => {
+    if (window.testRunner && window.testRunner.terminateNetworkProcess)
+        testRunner.terminateNetworkProcess();
+
+    const frame = await withFrame(scope + "/empty.html");
+    assert_not_equals(frame.contentWindow.navigator.serviceWorker.controller, null);
+    frame.remove();
+}, "Frame being controlled after network process crash");
+</script>
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (245872 => 245873)


--- trunk/Source/WebCore/ChangeLog	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebCore/ChangeLog	2019-05-29 22:21:08 UTC (rev 245873)
@@ -1,3 +1,24 @@
+2019-05-29  Youenn Fablet  <[email protected]>
+
+        Reestablish WebSWClientConnection in case of network process crash
+        https://bugs.webkit.org/show_bug.cgi?id=198333
+
+        Reviewed by Alex Christensen.
+
+        Refactor DocumentLoader to no longer take a ref to the SWClientConnection.
+        Instead, store the sessionID and get the SWClientConnection from it.
+        Remove unused code from ServiceWorkerContainer.
+
+        Test: http/wpt/service-workers/service-worker-networkprocess-crash.html
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::registerTemporaryServiceWorkerClient):
+        (WebCore::DocumentLoader::unregisterTemporaryServiceWorkerClient):
+        * loader/DocumentLoader.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+        * workers/service/ServiceWorkerContainer.h:
+        * workers/service/ServiceWorkerJobClient.h:
+
 2019-05-29  David Kilzer  <[email protected]>
 
         IndexedDatabase Server thread in com.apple.WebKit.Networking process leaks objects into an autoreleasePool that's never cleared

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (245872 => 245873)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2019-05-29 22:21:08 UTC (rev 245873)
@@ -1815,11 +1815,13 @@
 
     m_temporaryServiceWorkerClient = TemporaryServiceWorkerClient {
         DocumentIdentifier::generate(),
-        *ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(m_frame->page()->sessionID())
+        m_frame->page()->sessionID()
     };
 
+    auto& serviceWorkerConnection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(m_temporaryServiceWorkerClient->sessionID);
+
     // FIXME: Compute ServiceWorkerClientFrameType appropriately.
-    ServiceWorkerClientData data { { m_temporaryServiceWorkerClient->serviceWorkerConnection->serverConnectionIdentifier(), m_temporaryServiceWorkerClient->documentIdentifier }, ServiceWorkerClientType::Window, ServiceWorkerClientFrameType::None, url };
+    ServiceWorkerClientData data { { serviceWorkerConnection.serverConnectionIdentifier(), m_temporaryServiceWorkerClient->documentIdentifier }, ServiceWorkerClientType::Window, ServiceWorkerClientFrameType::None, url };
 
     RefPtr<SecurityOrigin> topOrigin;
     if (m_frame->isMainFrame())
@@ -1826,7 +1828,7 @@
         topOrigin = SecurityOrigin::create(url);
     else
         topOrigin = &m_frame->mainFrame().document()->topOrigin();
-    m_temporaryServiceWorkerClient->serviceWorkerConnection->registerServiceWorkerClient(*topOrigin, WTFMove(data), m_serviceWorkerRegistrationData->identifier, m_frame->loader().userAgent(url));
+    serviceWorkerConnection.registerServiceWorkerClient(*topOrigin, WTFMove(data), m_serviceWorkerRegistrationData->identifier, m_frame->loader().userAgent(url));
 #else
     UNUSED_PARAM(url);
 #endif
@@ -1838,7 +1840,8 @@
     if (!m_temporaryServiceWorkerClient)
         return;
 
-    m_temporaryServiceWorkerClient->serviceWorkerConnection->unregisterServiceWorkerClient(m_temporaryServiceWorkerClient->documentIdentifier);
+    auto& serviceWorkerConnection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(m_temporaryServiceWorkerClient->sessionID);
+    serviceWorkerConnection.unregisterServiceWorkerClient(m_temporaryServiceWorkerClient->documentIdentifier);
     m_temporaryServiceWorkerClient = WTF::nullopt;
 #endif
 }

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (245872 => 245873)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2019-05-29 22:21:08 UTC (rev 245873)
@@ -611,7 +611,7 @@
     Optional<ServiceWorkerRegistrationData> m_serviceWorkerRegistrationData;
     struct TemporaryServiceWorkerClient {
         DocumentIdentifier documentIdentifier;
-        Ref<SWClientConnection> serviceWorkerConnection;
+        PAL::SessionID sessionID;
     };
     Optional<TemporaryServiceWorkerClient> m_temporaryServiceWorkerClient;
 #endif

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (245872 => 245873)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2019-05-29 22:21:08 UTC (rev 245873)
@@ -575,12 +575,6 @@
     m_jobMap.remove(job.identifier());
 }
 
-SWServerConnectionIdentifier ServiceWorkerContainer::connectionIdentifier()
-{
-    ASSERT(m_swConnection);
-    return m_swConnection->serverConnectionIdentifier();
-}
-
 const char* ServiceWorkerContainer::activeDOMObjectName() const
 {
     return "ServiceWorkerContainer";

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (245872 => 245873)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2019-05-29 22:21:08 UTC (rev 245873)
@@ -103,7 +103,6 @@
     void didFinishGetRegistrationRequest(uint64_t requestIdentifier, Optional<ServiceWorkerRegistrationData>&&);
     void didFinishGetRegistrationsRequest(uint64_t requestIdentifier, Vector<ServiceWorkerRegistrationData>&&);
 
-    SWServerConnectionIdentifier connectionIdentifier() final;
     DocumentOrWorkerIdentifier contextIdentifier() final;
 
     SWClientConnection& ensureSWClientConnection();

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h (245872 => 245873)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h	2019-05-29 22:21:08 UTC (rev 245873)
@@ -51,8 +51,6 @@
     virtual void startScriptFetchForJob(ServiceWorkerJob&, FetchOptions::Cache) = 0;
     virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const String& script, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy) = 0;
     virtual void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&, Exception&&) = 0;
-
-    virtual SWServerConnectionIdentifier connectionIdentifier() = 0;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/ChangeLog (245872 => 245873)


--- trunk/Source/WebKit/ChangeLog	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebKit/ChangeLog	2019-05-29 22:21:08 UTC (rev 245873)
@@ -1,3 +1,45 @@
+2019-05-29  Youenn Fablet  <[email protected]>
+
+        Reestablish WebSWClientConnection in case of network process crash
+        https://bugs.webkit.org/show_bug.cgi?id=198333
+
+        Reviewed by Alex Christensen.
+
+        WebSWClientConnection now takes a RefPtr<IPC::Connection> so that on network process crash, it will set it back to null.
+        On the next call that needs the connection, WebSWClientConnection will reinitialize its underlying IPC connection and its own identifier.
+        Make sure that all code paths requiring this initialization are covered.
+
+        * WebProcess/Network/NetworkProcessConnection.cpp:
+        (WebKit::NetworkProcessConnection::didClose):
+        (WebKit::NetworkProcessConnection::serviceWorkerConnectionForSession):
+        (WebKit::NetworkProcessConnection::isRegisteredActiveSWClientConnection):
+        (WebKit::NetworkProcessConnection::initializeSWClientConnection):
+        * WebProcess/Network/NetworkProcessConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::WebSWClientConnection):
+        (WebKit::WebSWClientConnection::~WebSWClientConnection):
+        (WebKit::WebSWClientConnection::initializeConnectionIfNeeded):
+        (WebKit::WebSWClientConnection::ensureConnectionAndSend):
+        (WebKit::WebSWClientConnection::scheduleJobInServer):
+        (WebKit::WebSWClientConnection::finishFetchingScriptInServer):
+        (WebKit::WebSWClientConnection::addServiceWorkerRegistrationInServer):
+        (WebKit::WebSWClientConnection::removeServiceWorkerRegistrationInServer):
+        (WebKit::WebSWClientConnection::registerServiceWorkerClient):
+        (WebKit::WebSWClientConnection::unregisterServiceWorkerClient):
+        (WebKit::WebSWClientConnection::didResolveRegistrationPromise):
+        (WebKit::WebSWClientConnection::matchRegistration):
+        (WebKit::WebSWClientConnection::runOrDelayTaskForImport):
+        (WebKit::WebSWClientConnection::whenRegistrationReady):
+        (WebKit::WebSWClientConnection::getRegistrations):
+        (WebKit::WebSWClientConnection::startFetch):
+        (WebKit::WebSWClientConnection::cancelFetch):
+        (WebKit::WebSWClientConnection::continueDidReceiveFetchResponse):
+        (WebKit::WebSWClientConnection::connectionToServerLost):
+        (WebKit::WebSWClientConnection::syncTerminateWorker):
+        (WebKit::WebSWClientConnection::serverConnectionIdentifier const):
+        (WebKit::WebSWClientConnection::updateThrottleState):
+        * WebProcess/Storage/WebSWClientConnection.h:
+
 2019-05-29  Said Abou-Hallawa  <[email protected]>
 
         [iOS] WebPage::positionInformation() may set InteractionInformationAtPosition.isImage to true but leave image unset

Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp (245872 => 245873)


--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp	2019-05-29 22:21:08 UTC (rev 245873)
@@ -195,11 +195,9 @@
 #endif
 
 #if ENABLE(SERVICE_WORKER)
+    m_swConnectionsByIdentifier.clear();
     for (auto& connection : m_swConnectionsBySession.values())
         connection->connectionToServerLost();
-    
-    m_swConnectionsByIdentifier.clear();
-    m_swConnectionsBySession.clear();
 #endif
 }
 
@@ -262,14 +260,22 @@
 WebSWClientConnection& NetworkProcessConnection::serviceWorkerConnectionForSession(PAL::SessionID sessionID)
 {
     ASSERT(sessionID.isValid());
-    return *m_swConnectionsBySession.ensure(sessionID, [&] {
-        auto connection = WebSWClientConnection::create(m_connection, sessionID);
-        
-        auto result = m_swConnectionsByIdentifier.add(connection->serverConnectionIdentifier(), connection.ptr());
-        ASSERT_UNUSED(result, result.isNewEntry);
-        
-        return connection;
+    return *m_swConnectionsBySession.ensure(sessionID, [sessionID] {
+        return WebSWClientConnection::create(sessionID);
     }).iterator->value;
 }
+
+SWServerConnectionIdentifier NetworkProcessConnection::initializeSWClientConnection(WebSWClientConnection& connection)
+{
+    SWServerConnectionIdentifier identifier;
+    bool result = m_connection->sendSync(Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection(connection.sessionID()), Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection::Reply(identifier), 0);
+    ASSERT_UNUSED(result, result);
+
+    ASSERT(!m_swConnectionsByIdentifier.contains(identifier));
+    m_swConnectionsByIdentifier.add(identifier, &connection);
+
+    return identifier;
+}
+
 #endif
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h (245872 => 245873)


--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h	2019-05-29 22:21:08 UTC (rev 245873)
@@ -29,6 +29,7 @@
 #include "Connection.h"
 #include "ShareableResource.h"
 #include "WebIDBConnectionToServer.h"
+#include <WebCore/ServiceWorkerTypes.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
 
@@ -74,6 +75,8 @@
 #if ENABLE(SERVICE_WORKER)
     WebSWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID sessionID) { return m_swConnectionsBySession.get(sessionID); }
     WebSWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID);
+
+    WebCore::SWServerConnectionIdentifier initializeSWClientConnection(WebSWClientConnection&);
 #endif
 
 private:

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (245872 => 245873)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2019-05-29 22:21:08 UTC (rev 245873)
@@ -31,7 +31,7 @@
 #include "DataReference.h"
 #include "FormDataReference.h"
 #include "Logging.h"
-#include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkProcessConnection.h"
 #include "ServiceWorkerClientFetch.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
@@ -51,40 +51,57 @@
 using namespace PAL;
 using namespace WebCore;
 
-WebSWClientConnection::WebSWClientConnection(IPC::Connection& connection, SessionID sessionID)
+
+WebSWClientConnection::WebSWClientConnection(SessionID sessionID)
     : m_sessionID(sessionID)
-    , m_connection(connection)
     , m_swOriginTable(makeUniqueRef<WebSWOriginTable>())
 {
     ASSERT(sessionID.isValid());
-    bool result = sendSync(Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection(sessionID), Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection::Reply(m_identifier));
+    initializeConnectionIfNeeded();
+}
 
-    ASSERT_UNUSED(result, result);
+WebSWClientConnection::~WebSWClientConnection()
+{
+}
+
+void WebSWClientConnection::initializeConnectionIfNeeded()
+{
+    if (m_connection)
+        return;
+
+    auto& networkProcessConnection = WebProcess::singleton().ensureNetworkProcessConnection();
+
+    m_connection = &networkProcessConnection.connection();
+    m_identifier = networkProcessConnection.initializeSWClientConnection(*this);
+
     updateThrottleState();
 }
 
-WebSWClientConnection::~WebSWClientConnection()
+template<typename U>
+void WebSWClientConnection::ensureConnectionAndSend(const U& message)
 {
+    initializeConnectionIfNeeded();
+    send(message);
 }
 
 void WebSWClientConnection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
-    send(Messages::WebSWServerConnection::ScheduleJobInServer(jobData));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::ScheduleJobInServer(jobData));
 }
 
 void WebSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerFetchResult& result)
 {
-    send(Messages::WebSWServerConnection::FinishFetchingScriptInServer(result));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::FinishFetchingScriptInServer(result));
 }
 
 void WebSWClientConnection::addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    send(Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer(identifier));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer(identifier));
 }
 
 void WebSWClientConnection::removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(identifier));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(identifier));
 }
 
 void WebSWClientConnection::postMessageToServiceWorker(ServiceWorkerIdentifier destinationIdentifier, MessageWithMessagePorts&& message, const ServiceWorkerOrClientIdentifier& sourceIdentifier)
@@ -96,17 +113,17 @@
 
 void WebSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData& data, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, const String& userAgent)
 {
-    send(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent });
 }
 
 void WebSWClientConnection::unregisterServiceWorkerClient(DocumentIdentifier contextIdentifier)
 {
-    send(Messages::WebSWServerConnection::UnregisterServiceWorkerClient { ServiceWorkerClientIdentifier { serverConnectionIdentifier(), contextIdentifier } });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::UnregisterServiceWorkerClient { ServiceWorkerClientIdentifier { serverConnectionIdentifier(), contextIdentifier } });
 }
 
 void WebSWClientConnection::didResolveRegistrationPromise(const ServiceWorkerRegistrationKey& key)
 {
-    send(Messages::WebSWServerConnection::DidResolveRegistrationPromise(key));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::DidResolveRegistrationPromise(key));
 }
 
 bool WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData& origin) const
@@ -157,16 +174,18 @@
     runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = WTFMove(topOrigin), clientURL]() mutable {
         uint64_t callbackID = ++m_previousCallbackIdentifier;
         m_ongoingMatchRegistrationTasks.add(callbackID, WTFMove(callback));
-        send(Messages::WebSWServerConnection::MatchRegistration(callbackID, topOrigin, clientURL));
+        ensureConnectionAndSend(Messages::WebSWServerConnection::MatchRegistration(callbackID, topOrigin, clientURL));
     });
 }
 
 void WebSWClientConnection::runOrDelayTaskForImport(WTF::Function<void()>&& task)
 {
-    if (m_swOriginTable->isImported())
+    if (m_swOriginTable->isImported()) {
         task();
-    else
-        m_tasksPendingOriginImport.append(WTFMove(task));
+        return;
+    }
+    m_tasksPendingOriginImport.append(WTFMove(task));
+    initializeConnectionIfNeeded();
 }
 
 void WebSWClientConnection::whenRegistrationReady(const SecurityOrigin& topOrigin, const URL& clientURL, WhenRegistrationReadyCallback&& callback)
@@ -173,7 +192,7 @@
 {
     uint64_t callbackID = ++m_previousCallbackIdentifier;
     m_ongoingRegistrationReadyTasks.add(callbackID, WTFMove(callback));
-    send(Messages::WebSWServerConnection::WhenRegistrationReady(callbackID, topOrigin.data(), clientURL));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::WhenRegistrationReady(callbackID, topOrigin.data(), clientURL));
 }
 
 void WebSWClientConnection::registrationReady(uint64_t callbackID, WebCore::ServiceWorkerRegistrationData&& registrationData)
@@ -195,27 +214,29 @@
     runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = WTFMove(topOrigin), clientURL]() mutable {
         uint64_t callbackID = ++m_previousCallbackIdentifier;
         m_ongoingGetRegistrationsTasks.add(callbackID, WTFMove(callback));
-        send(Messages::WebSWServerConnection::GetRegistrations(callbackID, topOrigin, clientURL));
+        ensureConnectionAndSend(Messages::WebSWServerConnection::GetRegistrations(callbackID, topOrigin, clientURL));
     });
 }
 
 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 });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer });
 }
 
 void WebSWClientConnection::cancelFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
 {
-    send(Messages::WebSWServerConnection::CancelFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::CancelFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier });
 }
 
 void WebSWClientConnection::continueDidReceiveFetchResponse(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
 {
-    send(Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse { serviceWorkerRegistrationIdentifier, fetchIdentifier });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse { serviceWorkerRegistrationIdentifier, fetchIdentifier });
 }
 
 void WebSWClientConnection::connectionToServerLost()
 {
+    m_connection = nullptr;
+
     auto registrationTasks = WTFMove(m_ongoingMatchRegistrationTasks);
     for (auto& callback : registrationTasks.values())
         callback(WTF::nullopt);
@@ -229,13 +250,21 @@
 
 void WebSWClientConnection::syncTerminateWorker(ServiceWorkerIdentifier identifier)
 {
+    initializeConnectionIfNeeded();
+
     sendSync(Messages::WebSWServerConnection::SyncTerminateWorkerFromClient(identifier), Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::Reply());
 }
 
+WebCore::SWServerConnectionIdentifier WebSWClientConnection::serverConnectionIdentifier() const
+{
+    const_cast<WebSWClientConnection*>(this)->initializeConnectionIfNeeded();
+    return m_identifier;
+}
+
 void WebSWClientConnection::updateThrottleState()
 {
     m_isThrottleable = WebProcess::singleton().areAllPagesThrottleable();
-    send(Messages::WebSWServerConnection::SetThrottleState { m_isThrottleable });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::SetThrottleState { m_isThrottleable });
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (245872 => 245873)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2019-05-29 22:07:29 UTC (rev 245872)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2019-05-29 22:21:08 UTC (rev 245873)
@@ -47,12 +47,12 @@
 class WebSWOriginTable;
 class WebServiceWorkerProvider;
 
-class WebSWClientConnection final : public WebCore::SWClientConnection, public IPC::MessageSender, public IPC::MessageReceiver {
+class WebSWClientConnection final : public WebCore::SWClientConnection, private IPC::MessageSender, public IPC::MessageReceiver {
 public:
-    static Ref<WebSWClientConnection> create(IPC::Connection& connection, PAL::SessionID sessionID) { return adoptRef(*new WebSWClientConnection { connection, sessionID }); }
+    static Ref<WebSWClientConnection> create(PAL::SessionID sessionID) { return adoptRef(*new WebSWClientConnection { sessionID }); }
     ~WebSWClientConnection();
 
-    WebCore::SWServerConnectionIdentifier serverConnectionIdentifier() const final { return m_identifier; }
+    WebCore::SWServerConnectionIdentifier serverConnectionIdentifier() const final;
 
     void addServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier) final;
     void removeServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier) final;
@@ -69,9 +69,13 @@
 
     void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final;
 
+    PAL::SessionID sessionID() const { return m_sessionID; }
+
 private:
-    WebSWClientConnection(IPC::Connection&, PAL::SessionID);
+    explicit WebSWClientConnection(PAL::SessionID);
 
+    void initializeConnectionIfNeeded();
+
     void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
     void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source) final;
@@ -94,16 +98,18 @@
 
     void runOrDelayTaskForImport(WTF::Function<void()>&& task);
 
-    IPC::Connection* messageSenderConnection() const final { return m_connection.ptr(); }
+    IPC::Connection* messageSenderConnection() const final { return m_connection.get(); }
     uint64_t messageSenderDestinationID() const final { return m_identifier.toUInt64(); }
 
     void setSWOriginTableSharedMemory(const SharedMemory::Handle&);
     void setSWOriginTableIsImported();
 
+    template<typename U> void ensureConnectionAndSend(const U& message);
+
     PAL::SessionID m_sessionID;
     WebCore::SWServerConnectionIdentifier m_identifier;
 
-    Ref<IPC::Connection> m_connection;
+    RefPtr<IPC::Connection> m_connection;
     UniqueRef<WebSWOriginTable> m_swOriginTable;
 
     uint64_t m_previousCallbackIdentifier { 0 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to