Title: [292471] trunk/Source/WebKit
Revision
292471
Author
commit-qu...@webkit.org
Date
2022-04-06 09:00:13 -0700 (Wed, 06 Apr 2022)

Log Message

ServiceWorkerDownloadTask starts listening for IPC in constructor
https://bugs.webkit.org/show_bug.cgi?id=238860

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-04-06
Reviewed by Youenn Fablet.

IPC messages will start to be delivered after connection->addThreadMessageReceiver(..., this, ..) from
the message receive queue. This function cannot be called in the constructor, since the
virtual function table of the `this` object has not been constructed fully yet. This means
that if a message arrives during the constructor, it is dispatched via incorrect virtual function pointer.

Initiate the listening from a separate function that is called from ServiceWorkerDownloadTask::create().

No new tests, not testable.

* NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.cpp:
(WebKit::ServiceWorkerDownloadTask::startListeningForIPC):
(WebKit::ServiceWorkerDownloadTask::close):
* NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.h:
(WebKit::ServiceWorkerDownloadTask::create):
* NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::registerDownload):
(WebKit::WebSWServerToContextConnection::unregisterDownload):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292470 => 292471)


--- trunk/Source/WebKit/ChangeLog	2022-04-06 15:40:43 UTC (rev 292470)
+++ trunk/Source/WebKit/ChangeLog	2022-04-06 16:00:13 UTC (rev 292471)
@@ -1,3 +1,28 @@
+2022-04-06  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        ServiceWorkerDownloadTask starts listening for IPC in constructor
+        https://bugs.webkit.org/show_bug.cgi?id=238860
+
+        Reviewed by Youenn Fablet.
+
+        IPC messages will start to be delivered after connection->addThreadMessageReceiver(..., this, ..) from
+        the message receive queue. This function cannot be called in the constructor, since the
+        virtual function table of the `this` object has not been constructed fully yet. This means
+        that if a message arrives during the constructor, it is dispatched via incorrect virtual function pointer.
+
+        Initiate the listening from a separate function that is called from ServiceWorkerDownloadTask::create().
+
+        No new tests, not testable.
+
+        * NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.cpp:
+        (WebKit::ServiceWorkerDownloadTask::startListeningForIPC):
+        (WebKit::ServiceWorkerDownloadTask::close):
+        * NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.h:
+        (WebKit::ServiceWorkerDownloadTask::create):
+        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+        (WebKit::WebSWServerToContextConnection::registerDownload):
+        (WebKit::WebSWServerToContextConnection::unregisterDownload):
+
 2022-04-06  Youenn Fablet  <you...@apple.com>
 
         In case of COOP-based process swap, we need to make sure the document gets controlled by its matching service worker registration

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.cpp (292470 => 292471)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.cpp	2022-04-06 15:40:43 UTC (rev 292470)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.cpp	2022-04-06 16:00:13 UTC (rev 292471)
@@ -31,6 +31,7 @@
 #include "DownloadManager.h"
 #include "Logging.h"
 #include "NetworkProcess.h"
+#include "ServiceWorkerDownloadTaskMessages.h"
 #include "SharedBufferCopy.h"
 #include "WebErrors.h"
 #include "WebSWContextManagerConnectionMessages.h"
@@ -64,11 +65,17 @@
     ASSERT(!m_serviceWorkerConnection);
 }
 
+void ServiceWorkerDownloadTask::startListeningForIPC()
+{
+    m_serviceWorkerConnection->ipcConnection().addThreadMessageReceiver(Messages::ServiceWorkerDownloadTask::messageReceiverName(), this, fetchIdentifier().toUInt64());
+}
+
 void ServiceWorkerDownloadTask::close()
 {
     ASSERT(isMainRunLoop());
 
     if (m_serviceWorkerConnection) {
+        m_serviceWorkerConnection->ipcConnection().removeThreadMessageReceiver(Messages::ServiceWorkerDownloadTask::messageReceiverName(), fetchIdentifier().toUInt64());
         m_serviceWorkerConnection->unregisterDownload(*this);
         m_serviceWorkerConnection = nullptr;
     }

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.h (292470 => 292471)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.h	2022-04-06 15:40:43 UTC (rev 292470)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.h	2022-04-06 16:00:13 UTC (rev 292471)
@@ -50,7 +50,12 @@
 class ServiceWorkerDownloadTask : public NetworkDataTask, public IPC::Connection::ThreadMessageReceiver {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<ServiceWorkerDownloadTask> create(NetworkSession& session, NetworkDataTaskClient& client, WebSWServerToContextConnection& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, const WebCore::ResourceRequest& request, DownloadID downloadID) { return adoptRef(* new ServiceWorkerDownloadTask(session, client, connection, serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier, request, downloadID)); }
+    static Ref<ServiceWorkerDownloadTask> create(NetworkSession& session, NetworkDataTaskClient& client, WebSWServerToContextConnection& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, const WebCore::ResourceRequest& request, DownloadID downloadID)
+    {
+        auto task = adoptRef(*new ServiceWorkerDownloadTask(session, client, connection, serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier, request, downloadID));
+        task->startListeningForIPC();
+        return task;
+    }
     ~ServiceWorkerDownloadTask();
 
     WebCore::FetchIdentifier fetchIdentifier() const { return m_fetchIdentifier; }
@@ -65,6 +70,7 @@
 
 private:
     ServiceWorkerDownloadTask(NetworkSession&, NetworkDataTaskClient&, WebSWServerToContextConnection&, WebCore::ServiceWorkerIdentifier, WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceRequest&, DownloadID);
+    void startListeningForIPC();
 
     // IPC Message
     void didReceiveData(const IPC::SharedBufferCopy&, int64_t encodedDataLength);

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp (292470 => 292471)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp	2022-04-06 15:40:43 UTC (rev 292470)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp	2022-04-06 16:00:13 UTC (rev 292471)
@@ -33,7 +33,6 @@
 #include "NetworkConnectionToWebProcess.h"
 #include "NetworkProcess.h"
 #include "NetworkProcessProxyMessages.h"
-#include "ServiceWorkerDownloadTaskMessages.h"
 #include "ServiceWorkerFetchTask.h"
 #include "ServiceWorkerFetchTaskMessages.h"
 #include "WebCoreArgumentCoders.h"
@@ -248,13 +247,11 @@
 {
     ASSERT(!m_ongoingDownloads.contains(task.fetchIdentifier()));
     m_ongoingDownloads.add(task.fetchIdentifier(), task);
-    m_connection.connection().addThreadMessageReceiver(Messages::ServiceWorkerDownloadTask::messageReceiverName(), &task, task.fetchIdentifier().toUInt64());
 }
 
 void WebSWServerToContextConnection::unregisterDownload(ServiceWorkerDownloadTask& task)
 {
     m_ongoingDownloads.remove(task.fetchIdentifier());
-    m_connection.connection().removeThreadMessageReceiver(Messages::ServiceWorkerDownloadTask::messageReceiverName(), task.fetchIdentifier().toUInt64());
 }
 
 WebCore::ProcessIdentifier WebSWServerToContextConnection::webProcessIdentifier() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to