mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 19:32:06 -05: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:
parent
7146c33522
commit
16a4949e33
3 changed files with 13 additions and 11 deletions
|
@ -61,7 +61,7 @@ ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(NonnullRefPtr<S
|
|||
server->listen(*m_web_content_socket_path);
|
||||
|
||||
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()) {
|
||||
// Use of MUST in this function is safe, as our promise callback can never error out.
|
||||
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 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) });
|
||||
|
||||
if (m_current_window_handle.is_empty())
|
||||
|
|
|
@ -9,17 +9,15 @@
|
|||
|
||||
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)
|
||||
, m_client(move(client))
|
||||
, m_session_id(session_id)
|
||||
{
|
||||
}
|
||||
|
||||
void WebContentConnection::die()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Session {} was closed remotely. Shutting down...", m_session_id);
|
||||
m_client->close_session(m_session_id);
|
||||
if (on_close)
|
||||
on_close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,11 @@ class WebContentConnection
|
|||
: public IPC::ConnectionFromClient<WebDriverClientEndpoint, WebDriverServerEndpoint> {
|
||||
C_OBJECT_ABSTRACT(WebContentConnection)
|
||||
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;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Client> m_client;
|
||||
unsigned m_session_id { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue