From 27ef9ffa8f76b9bb38bc30ce05a1fdc19b849d91 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 9 Jul 2024 03:00:06 -0600 Subject: [PATCH] LibWeb+WebWorker: Add IPC messages to request and communicate shutdown --- Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp | 6 ++++++ Userland/Libraries/LibWeb/Worker/WebWorkerClient.h | 4 ++++ Userland/Libraries/LibWeb/Worker/WebWorkerClient.ipc | 1 + Userland/Libraries/LibWeb/Worker/WebWorkerServer.ipc | 2 ++ Userland/Services/WebWorker/ConnectionFromClient.cpp | 10 ++++++++++ Userland/Services/WebWorker/ConnectionFromClient.h | 2 ++ 6 files changed, 25 insertions(+) diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp index 9c71247becf..e4cf5c743ef 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp @@ -14,6 +14,12 @@ void WebWorkerClient::die() // FIXME: Notify WorkerAgent that the worker is ded } +void WebWorkerClient::did_close_worker() +{ + if (on_worker_close) + on_worker_close(); +} + WebWorkerClient::WebWorkerClient(NonnullOwnPtr socket) : IPC::ConnectionToServer(*this, move(socket)) { diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h index 1e7b675fa50..9600ce00965 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h @@ -21,6 +21,10 @@ class WebWorkerClient final public: explicit WebWorkerClient(NonnullOwnPtr); + virtual void did_close_worker() override; + + Function on_worker_close; + IPC::File dup_socket(); private: diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.ipc b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.ipc index 6af31841eff..4a6d849a14a 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.ipc +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.ipc @@ -1,2 +1,3 @@ endpoint WebWorkerClient { + did_close_worker() =| } diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerServer.ipc b/Userland/Libraries/LibWeb/Worker/WebWorkerServer.ipc index ecb5c036db5..0c218111547 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerServer.ipc +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerServer.ipc @@ -7,5 +7,7 @@ endpoint WebWorkerServer { start_dedicated_worker(URL::URL url, String type, String credentials, String name, Web::HTML::TransferDataHolder message_port, Web::HTML::SerializedEnvironmentSettingsObject outside_settings) =| + close_worker() =| + handle_file_return(i32 error, Optional file, i32 request_id) =| } diff --git a/Userland/Services/WebWorker/ConnectionFromClient.cpp b/Userland/Services/WebWorker/ConnectionFromClient.cpp index 8a644f3d255..dae20477dfb 100644 --- a/Userland/Services/WebWorker/ConnectionFromClient.cpp +++ b/Userland/Services/WebWorker/ConnectionFromClient.cpp @@ -11,6 +11,16 @@ namespace WebWorker { +void ConnectionFromClient::close_worker() +{ + async_did_close_worker(); + + // FIXME: Invoke a worker shutdown operation that implements the spec + m_worker_host = nullptr; + + die(); +} + void ConnectionFromClient::die() { // FIXME: When handling multiple workers in the same process, diff --git a/Userland/Services/WebWorker/ConnectionFromClient.h b/Userland/Services/WebWorker/ConnectionFromClient.h index f74b0e9b421..b6b7722196a 100644 --- a/Userland/Services/WebWorker/ConnectionFromClient.h +++ b/Userland/Services/WebWorker/ConnectionFromClient.h @@ -28,6 +28,8 @@ public: virtual void die() override; + virtual void close_worker() override; + void request_file(Web::FileRequest); PageHost& page_host() { return *m_page_host; }