1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

WebDriver: Fix handling of disconnected WebContent process

If WebContent process got disconnected it is only necessary to remove
associated window instead of terminating the entire session.
This commit is contained in:
Aliaksandr Kalenik 2023-03-19 14:08:52 +03:00 committed by Jelle Raaijmakers
parent 7146c33522
commit 16a4949e33
3 changed files with 13 additions and 11 deletions

View file

@ -61,7 +61,7 @@ ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(NonnullRefPtr<S
server->listen(*m_web_content_socket_path); server->listen(*m_web_content_socket_path);
server->on_accept = [this, promise](auto client_socket) { server->on_accept = [this, promise](auto client_socket) {
auto maybe_connection = adopt_nonnull_ref_or_enomem(new (nothrow) WebContentConnection(move(client_socket), m_client, session_id())); auto maybe_connection = adopt_nonnull_ref_or_enomem(new (nothrow) WebContentConnection(move(client_socket)));
if (maybe_connection.is_error()) { if (maybe_connection.is_error()) {
// Use of MUST in this function is safe, as our promise callback can never error out. // Use of MUST in this function is safe, as our promise callback can never error out.
MUST(promise->resolve(maybe_connection.release_error())); MUST(promise->resolve(maybe_connection.release_error()));
@ -72,6 +72,12 @@ ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(NonnullRefPtr<S
auto web_content_connection = maybe_connection.release_value(); auto web_content_connection = maybe_connection.release_value();
auto window_handle = web_content_connection->get_window_handle(); auto window_handle = web_content_connection->get_window_handle();
web_content_connection->on_close = [this, window_handle]() {
dbgln_if(WEBDRIVER_DEBUG, "Window {} was closed remotely.", window_handle);
m_windows.remove(window_handle);
if (m_windows.is_empty())
m_client->close_session(session_id());
};
m_windows.set(window_handle, Session::Window { window_handle, move(web_content_connection) }); m_windows.set(window_handle, Session::Window { window_handle, move(web_content_connection) });
if (m_current_window_handle.is_empty()) if (m_current_window_handle.is_empty())

View file

@ -9,17 +9,15 @@
namespace WebDriver { namespace WebDriver {
WebContentConnection::WebContentConnection(NonnullOwnPtr<Core::LocalSocket> socket, NonnullRefPtr<Client> client, unsigned session_id) WebContentConnection::WebContentConnection(NonnullOwnPtr<Core::LocalSocket> socket)
: IPC::ConnectionFromClient<WebDriverClientEndpoint, WebDriverServerEndpoint>(*this, move(socket), 1) : IPC::ConnectionFromClient<WebDriverClientEndpoint, WebDriverServerEndpoint>(*this, move(socket), 1)
, m_client(move(client))
, m_session_id(session_id)
{ {
} }
void WebContentConnection::die() void WebContentConnection::die()
{ {
dbgln_if(WEBDRIVER_DEBUG, "Session {} was closed remotely. Shutting down...", m_session_id); if (on_close)
m_client->close_session(m_session_id); on_close();
} }
} }

View file

@ -18,13 +18,11 @@ class WebContentConnection
: public IPC::ConnectionFromClient<WebDriverClientEndpoint, WebDriverServerEndpoint> { : public IPC::ConnectionFromClient<WebDriverClientEndpoint, WebDriverServerEndpoint> {
C_OBJECT_ABSTRACT(WebContentConnection) C_OBJECT_ABSTRACT(WebContentConnection)
public: public:
WebContentConnection(NonnullOwnPtr<Core::LocalSocket> socket, NonnullRefPtr<Client> client, unsigned session_id); WebContentConnection(NonnullOwnPtr<Core::LocalSocket> socket);
Function<void()> on_close;
virtual void die() override; virtual void die() override;
private:
NonnullRefPtr<Client> m_client;
unsigned m_session_id { 0 };
}; };
} }