summaryrefslogtreecommitdiff
path: root/Userland/Services/WebDriver/Session.cpp
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2023-03-19 13:36:32 +0300
committerJelle Raaijmakers <jelle@gmta.nl>2023-03-19 14:51:40 +0100
commit63c16ff41ae53be5e101a757d3b2805edd1c8660 (patch)
tree9e336dc25b9003a9d83c0d9bb2f1226349da1eab /Userland/Services/WebDriver/Session.cpp
parentb79cd5cf6ea4addd9d7c47cea9d385883305b734 (diff)
downloadserenity-63c16ff41ae53be5e101a757d3b2805edd1c8660.zip
WebDriver: Inline `Sesssion::stop()` in session destructor
Previously it was possible to have following sequence of calls while destroying a session: 1. `WebContentConnection::die()` calls `Client::close_session()` 2. `Client::close_session()` removes a session from active sessions map which causes session destructor call. 3. Session destructor calls `Client::close_session()` to remove a session from active sessions. With `stop()` method inlined into destructor `close_session()` need to be called just once while destroying a session.
Diffstat (limited to 'Userland/Services/WebDriver/Session.cpp')
-rw-r--r--Userland/Services/WebDriver/Session.cpp54
1 files changed, 22 insertions, 32 deletions
diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp
index 674ef6f8e3..9a04bf9b4f 100644
--- a/Userland/Services/WebDriver/Session.cpp
+++ b/Userland/Services/WebDriver/Session.cpp
@@ -26,10 +26,29 @@ Session::Session(unsigned session_id, NonnullRefPtr<Client> client, Web::WebDriv
{
}
+// https://w3c.github.io/webdriver/#dfn-close-the-session
Session::~Session()
{
- if (auto error = stop(); error.is_error())
- warnln("Failed to stop session {}: {}", m_id, error.error());
+ if (!m_started)
+ return;
+
+ // 1. Perform the following substeps based on the remote end’s type:
+ // NOTE: We perform the "Remote end is an endpoint node" steps in the WebContent process.
+ web_content_connection().close_session();
+
+ // 2. Remove the current session from active sessions.
+ // NOTE: We are in a session destruction which means it is already removed
+ // from active sessions
+
+ // 3. Perform any implementation-specific cleanup steps.
+ if (m_browser_pid.has_value()) {
+ MUST(Core::System::kill(*m_browser_pid, SIGTERM));
+ m_browser_pid = {};
+ }
+ if (m_web_content_socket_path.has_value()) {
+ MUST(Core::System::unlink(*m_web_content_socket_path));
+ m_web_content_socket_path = {};
+ }
}
ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(NonnullRefPtr<ServerPromise> promise)
@@ -86,35 +105,6 @@ ErrorOr<void> Session::start(LaunchBrowserCallbacks const& callbacks)
return {};
}
-// https://w3c.github.io/webdriver/#dfn-close-the-session
-Web::WebDriver::Response Session::stop()
-{
- if (!m_started)
- return JsonValue {};
-
- // 1. Perform the following substeps based on the remote end’s type:
- // NOTE: We perform the "Remote end is an endpoint node" steps in the WebContent process.
- web_content_connection().close_session();
-
- // 2. Remove the current session from active sessions.
- m_client->close_session(session_id());
-
- // 3. Perform any implementation-specific cleanup steps.
- if (m_browser_pid.has_value()) {
- MUST(Core::System::kill(*m_browser_pid, SIGTERM));
- m_browser_pid = {};
- }
- if (m_web_content_socket_path.has_value()) {
- MUST(Core::System::unlink(*m_web_content_socket_path));
- m_web_content_socket_path = {};
- }
-
- m_started = false;
-
- // 4. If an error has occurred in any of the steps above, return the error, otherwise return success with data null.
- return JsonValue {};
-}
-
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
Web::WebDriver::Response Session::close_window()
{
@@ -127,7 +117,7 @@ Web::WebDriver::Response Session::close_window()
// 4. If there are no more open top-level browsing contexts, then close the session.
if (m_windows.size() == 1)
- TRY(stop());
+ m_client->close_session(session_id());
}
// 5. Return the result of running the remote end steps for the Get Window Handles command.