From f7c212a19dd9a3e33521f92ccb63ded27e72ab7c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 8 Nov 2022 10:42:12 -0500 Subject: [PATCH] WebContent+WebDriver: Set the navigator.webdriver flag from WebDriver This moves setting the navigator.webdriver flag from after WebContent creates the WebDriver connection, to its own IPC to be triggered from WebDriver. This is closer to the spec, but mostly serves as an easy test to validate the connection. --- Userland/Services/WebContent/ConnectionFromClient.cpp | 7 ------- Userland/Services/WebContent/ConnectionFromClient.h | 1 - Userland/Services/WebContent/WebContentServer.ipc | 1 - Userland/Services/WebContent/WebDriverClient.ipc | 1 + Userland/Services/WebContent/WebDriverConnection.cpp | 5 +++++ Userland/Services/WebContent/WebDriverConnection.h | 1 + Userland/Services/WebDriver/Client.cpp | 5 ++++- Userland/Services/WebDriver/Session.h | 6 ++++++ 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index f4ab796d12..6b0abf4cf1 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -74,8 +74,6 @@ void ConnectionFromClient::connect_to_webdriver(String const& webdriver_ipc_path // FIXME: Propogate this error back to the browser. if (auto result = m_page_host->connect_to_webdriver(webdriver_ipc_path); result.is_error()) dbgln("Unable to connect to the WebDriver process: {}", result.error()); - else - set_is_webdriver_active(true); } void ConnectionFromClient::update_system_theme(Core::AnonymousBuffer const& theme_buffer) @@ -801,11 +799,6 @@ void ConnectionFromClient::set_is_scripting_enabled(bool is_scripting_enabled) m_page_host->set_is_scripting_enabled(is_scripting_enabled); } -void ConnectionFromClient::set_is_webdriver_active(bool is_webdriver_active) -{ - m_page_host->set_is_webdriver_active(is_webdriver_active); -} - void ConnectionFromClient::set_window_position(Gfx::IntPoint const& position) { m_page_host->set_window_position(position); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index d71afb0095..073f2f717f 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -74,7 +74,6 @@ private: virtual void set_preferred_color_scheme(Web::CSS::PreferredColorScheme const&) override; virtual void set_has_focus(bool) override; virtual void set_is_scripting_enabled(bool) override; - virtual void set_is_webdriver_active(bool) override; virtual void set_window_position(Gfx::IntPoint const&) override; virtual void set_window_size(Gfx::IntSize const&) override; virtual void handle_file_return(i32 error, Optional const& file, i32 request_id) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 3e065edf69..0381142151 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -71,7 +71,6 @@ endpoint WebContentServer set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme) =| set_has_focus(bool has_focus) =| set_is_scripting_enabled(bool is_scripting_enabled) =| - set_is_webdriver_active(bool is_webdriver_active) =| set_window_position(Gfx::IntPoint position) =| set_window_size(Gfx::IntSize size) =| diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 6c11180cf7..02292f5cf4 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -1,2 +1,3 @@ endpoint WebDriverClient { + set_is_webdriver_active(bool active) =| } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index dbc42c471c..4119ca716e 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -34,4 +34,9 @@ WebDriverConnection::WebDriverConnection(NonnullOwnPtr socket, PageHost& page_host); virtual void die() override { } + virtual void set_is_webdriver_active(bool) override; PageHost& m_page_host; }; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 1a614f4919..ad11fcb3bc 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -385,6 +385,8 @@ Web::WebDriver::Response Client::handle_new_session(Vector const&, J return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::SessionNotCreated, String::formatted("Failed to start session: {}", start_result.error().string_literal())); } + auto& web_content_connection = session->web_content_connection(); + // FIXME: 8. Set the current session to session. // FIXME: 9. Run any WebDriver new session algorithm defined in external specifications, @@ -405,7 +407,8 @@ Web::WebDriver::Response Client::handle_new_session(Vector const&, J // FIXME: 12. Initialize the following from capabilities: // NOTE: See spec for steps - // FIXME: 13. Set the webdriver-active flag to true. + // 13. Set the webdriver-active flag to true. + web_content_connection.async_set_is_webdriver_active(true); // FIXME: 14. Set the current top-level browsing context for session with the top-level browsing context // of the UA’s current browsing context. diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 8e7885fdfd..e7d711d7f5 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -41,6 +41,12 @@ public: ErrorOr check_for_open_top_level_browsing_context_or_return_error(); String const& current_window_handle() { return m_current_window_handle; } + WebContentConnection& web_content_connection() + { + VERIFY(m_web_content_connection); + return *m_web_content_connection; + } + ErrorOr start(); ErrorOr stop(); JsonObject get_timeouts();