From 28fb30b22f649213f1a7d1fad3512630e19487bd Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 3 Feb 2025 09:22:44 -0500 Subject: [PATCH] LibWeb: Move AO to check if a browsing context is open to a helper file This will be needed outside of WebDriverConnection.cpp. --- Libraries/LibWeb/WebDriver/Contexts.cpp | 9 +++++++++ Libraries/LibWeb/WebDriver/Contexts.h | 2 ++ Services/WebContent/WebDriverConnection.cpp | 18 +++++------------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/WebDriver/Contexts.cpp b/Libraries/LibWeb/WebDriver/Contexts.cpp index cb7fbd459c9..dcb72c3e2a2 100644 --- a/Libraries/LibWeb/WebDriver/Contexts.cpp +++ b/Libraries/LibWeb/WebDriver/Contexts.cpp @@ -127,4 +127,13 @@ ErrorOr, WebDriver::Error> deserialize_web_window(JS: return *navigable->active_window_proxy(); } +// https://w3c.github.io/webdriver/#dfn-no-longer-open +ErrorOr ensure_browsing_context_is_open(GC::Ptr browsing_context) +{ + // A browsing context is said to be no longer open if its navigable has been destroyed. + if (!browsing_context || browsing_context->has_navigable_been_destroyed()) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found"sv); + return {}; +} + } diff --git a/Libraries/LibWeb/WebDriver/Contexts.h b/Libraries/LibWeb/WebDriver/Contexts.h index 0a35f966256..e18416659f6 100644 --- a/Libraries/LibWeb/WebDriver/Contexts.h +++ b/Libraries/LibWeb/WebDriver/Contexts.h @@ -22,4 +22,6 @@ ErrorOr, WebDriver::Error> deserialize_web_frame(JS:: bool represents_a_web_window(JS::Value); ErrorOr, WebDriver::Error> deserialize_web_window(JS::Object const&); +ErrorOr ensure_browsing_context_is_open(GC::Ptr); + } diff --git a/Services/WebContent/WebDriverConnection.cpp b/Services/WebContent/WebDriverConnection.cpp index 1ee29a7c3a9..01cc8856b47 100644 --- a/Services/WebContent/WebDriverConnection.cpp +++ b/Services/WebContent/WebDriverConnection.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -113,15 +114,6 @@ static Gfx::IntRect compute_window_rect(Web::Page const& page) }; } -// https://w3c.github.io/webdriver/#dfn-no-longer-open -static ErrorOr ensure_browsing_context_is_open(GC::Ptr browsing_context) -{ - // A browsing context is said to be no longer open if its navigable has been destroyed. - if (!browsing_context || browsing_context->has_navigable_been_destroyed()) - return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found"sv); - return {}; -} - // https://w3c.github.io/webdriver/#dfn-scrolls-into-view static void scroll_element_into_view(Web::DOM::Element& element) { @@ -769,7 +761,7 @@ Messages::WebDriverClient::SwitchToParentFrameResponse WebDriverConnection::swit } // 2. If session's current parent browsing context is no longer open, return error with error code no such window. - TRY(ensure_browsing_context_is_open(current_parent_browsing_context())); + TRY(Web::WebDriver::ensure_browsing_context_is_open(current_parent_browsing_context())); // 3. Try to handle any user prompts with session. handle_any_user_prompts([this]() { @@ -2623,12 +2615,12 @@ Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse WebDriver ErrorOr WebDriverConnection::ensure_current_browsing_context_is_open() { - return ensure_browsing_context_is_open(current_browsing_context()); + return Web::WebDriver::ensure_browsing_context_is_open(current_browsing_context()); } ErrorOr WebDriverConnection::ensure_current_top_level_browsing_context_is_open() { - return ensure_browsing_context_is_open(current_top_level_browsing_context()); + return Web::WebDriver::ensure_browsing_context_is_open(current_top_level_browsing_context()); } // https://w3c.github.io/webdriver/#dfn-handle-any-user-prompts @@ -2696,7 +2688,7 @@ void WebDriverConnection::wait_for_navigation_to_complete(OnNavigationComplete o } // 2. If the current browsing context is no longer open, return success with data null. - if (ensure_browsing_context_is_open(current_browsing_context()).is_error()) { + if (Web::WebDriver::ensure_browsing_context_is_open(current_browsing_context()).is_error()) { on_complete->function()(JsonValue {}); return; }