Parcourir la source

LibWeb+WebWorker: Add IPC messages to request and communicate shutdown

Andrew Kaster il y a 1 an
Parent
commit
27ef9ffa8f

+ 6 - 0
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<Core::LocalSocket> socket)
     : IPC::ConnectionToServer<WebWorkerClientEndpoint, WebWorkerServerEndpoint>(*this, move(socket))
 {

+ 4 - 0
Userland/Libraries/LibWeb/Worker/WebWorkerClient.h

@@ -21,6 +21,10 @@ class WebWorkerClient final
 public:
     explicit WebWorkerClient(NonnullOwnPtr<Core::LocalSocket>);
 
+    virtual void did_close_worker() override;
+
+    Function<void()> on_worker_close;
+
     IPC::File dup_socket();
 
 private:

+ 1 - 0
Userland/Libraries/LibWeb/Worker/WebWorkerClient.ipc

@@ -1,2 +1,3 @@
 endpoint WebWorkerClient {
+    did_close_worker() =|
 }

+ 2 - 0
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<IPC::File> file, i32 request_id) =|
 }

+ 10 - 0
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,

+ 2 - 0
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; }