diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-09 11:00:53 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-09 19:59:26 +0000 |
commit | 03d0c7a5b66683be81778d6d9abe0e0255463206 (patch) | |
tree | 119a322fdf045d98b81e96b09f3e2eb42da9e9d6 | |
parent | 1c398b32ce022161dc96da7c036e28bb3691d5c7 (diff) | |
download | serenity-03d0c7a5b66683be81778d6d9abe0e0255463206.zip |
Browser+WebContent+WebDriver: Move [Max,Min]imize Window to WebContent
This also lets us more fully implement the "iconify the window" method,
which requires we block until the document reaches the "hidden" state.
-rw-r--r-- | Userland/Applications/Browser/WebDriverConnection.cpp | 31 | ||||
-rw-r--r-- | Userland/Applications/Browser/WebDriverConnection.h | 4 | ||||
-rw-r--r-- | Userland/Applications/Browser/WebDriverSessionClient.ipc | 4 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 2 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 69 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 4 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 6 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.cpp | 39 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.h | 2 |
9 files changed, 75 insertions, 86 deletions
diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 4f24227c6f..c4e41a261a 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -58,37 +58,6 @@ void WebDriverConnection::forward() browser_window->active_tab().go_forward(); } -Messages::WebDriverSessionClient::GetWindowRectResponse WebDriverConnection::get_window_rect() -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_window_rect"); - if (auto browser_window = m_browser_window.strong_ref()) - return { browser_window->rect() }; - return { {} }; -} - -void WebDriverConnection::restore_window() -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: restore_window"); - if (auto browser_window = m_browser_window.strong_ref()) { - browser_window->show(); - browser_window->move_to_front(); - } -} - -void WebDriverConnection::maximize_window() -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: maximize_window"); - if (auto browser_window = m_browser_window.strong_ref()) - browser_window->set_maximized(true); -} - -void WebDriverConnection::minimize_window() -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: minimize_window"); - if (auto browser_window = m_browser_window.strong_ref()) - browser_window->set_minimized(true); -} - Messages::WebDriverSessionClient::SerializeSourceResponse WebDriverConnection::serialize_source() { dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: serialize_source"); diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 1649eeb037..b48d32df1e 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -42,10 +42,6 @@ public: virtual void refresh() override; virtual void back() override; virtual void forward() override; - virtual Messages::WebDriverSessionClient::GetWindowRectResponse get_window_rect() override; - virtual void restore_window() override; - virtual void maximize_window() override; - virtual void minimize_window() override; virtual Messages::WebDriverSessionClient::SerializeSourceResponse serialize_source() override; virtual Messages::WebDriverSessionClient::ExecuteScriptResponse execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async) override; virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override; diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index acf401ec43..c267d1d3b7 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -18,10 +18,6 @@ endpoint WebDriverSessionClient { refresh() =| back() =| forward() =| - get_window_rect() => (Gfx::IntRect rect) - restore_window() =| - maximize_window() =| - minimize_window() =| serialize_source() => (String source) execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result) get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies) diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 2ef7c66f7e..9ca42eddc7 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -7,4 +7,6 @@ endpoint WebDriverClient { get_current_url() => (Web::WebDriver::Response response) get_window_rect() => (Web::WebDriver::Response response) set_window_rect(JsonValue payload) => (Web::WebDriver::Response response) + maximize_window() => (Web::WebDriver::Response response) + minimize_window() => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 11c4621fe1..5f52ed7b6f 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -222,6 +222,45 @@ Messages::WebDriverClient::SetWindowRectResponse WebDriverConnection::set_window return serialize_rect(window_rect); } +// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window +Messages::WebDriverClient::MaximizeWindowResponse WebDriverConnection::maximize_window() +{ + // 1. If the remote end does not support the Maximize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation. + + // 2. If the current top-level browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // FIXME: 3. Handle any user prompts and return its value if it is an error. + // FIXME: 4. Fully exit fullscreen. + + // 5. Restore the window. + restore_the_window(); + + // 6. Maximize the window of the current top-level browsing context. + auto window_rect = maximize_the_window(); + + // 7. Return success with data set to the WindowRect object for the current top-level browsing context. + return serialize_rect(window_rect); +} + +// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window +Messages::WebDriverClient::MinimizeWindowResponse WebDriverConnection::minimize_window() +{ + // 1. If the remote end does not support the Minimize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation. + + // 2. If the current top-level browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // FIXME: 3. Handle any user prompts and return its value if it is an error. + // FIXME: 4. Fully exit fullscreen. + + // 5. Iconify the window. + auto window_rect = iconify_the_window(); + + // 6. Return success with data set to the WindowRect object for the current top-level browsing context. + return serialize_rect(window_rect); +} + // https://w3c.github.io/webdriver/#dfn-no-longer-open ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context() { @@ -240,9 +279,35 @@ void WebDriverConnection::restore_the_window() // Do not return from this operation until the visibility state of the top-level browsing context’s active document has reached the visible state, or until the operation times out. // FIXME: Implement timeouts. Web::Platform::EventLoopPlugin::the().spin_until([this]() { - auto state = m_page_host.page().top_level_browsing_context().active_document()->visibility_state(); - return state == "visible"sv; + auto state = m_page_host.page().top_level_browsing_context().system_visibility_state(); + return state == Web::HTML::VisibilityState::Visible; + }); +} + +// https://w3c.github.io/webdriver/#dfn-maximize-the-window +Gfx::IntRect WebDriverConnection::maximize_the_window() +{ + // To maximize the window, given an operating system level window with an associated top-level browsing context, run the implementation-specific steps to transition the operating system level window into the maximized window state. + auto rect = m_web_content_client.did_request_maximize_window(); + + // Return when the window has completed the transition, or within an implementation-defined timeout. + return rect; +} + +// https://w3c.github.io/webdriver/#dfn-iconify-the-window +Gfx::IntRect WebDriverConnection::iconify_the_window() +{ + // To iconify the window, given an operating system level window with an associated top-level browsing context, run implementation-specific steps to iconify, minimize, or hide the window from the visible screen. + auto rect = m_web_content_client.did_request_minimize_window(); + + // Do not return from this operation until the visibility state of the top-level browsing context’s active document has reached the hidden state, or until the operation times out. + // FIXME: Implement timeouts. + Web::Platform::EventLoopPlugin::the().spin_until([this]() { + auto state = m_page_host.page().top_level_browsing_context().system_visibility_state(); + return state == Web::HTML::VisibilityState::Hidden; }); + + return rect; } } diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 2d84e37be1..369ef20363 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -35,9 +35,13 @@ private: virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override; virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override; virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override; + virtual Messages::WebDriverClient::MaximizeWindowResponse maximize_window() override; + virtual Messages::WebDriverClient::MinimizeWindowResponse minimize_window() override; ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context(); void restore_the_window(); + Gfx::IntRect maximize_the_window(); + Gfx::IntRect iconify_the_window(); ConnectionFromClient& m_web_content_client; PageHost& m_page_host; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 2b92dd77bc..ba782e8510 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -600,8 +600,7 @@ Web::WebDriver::Response Client::handle_maximize_window(Vector<StringView> const { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/maximize"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->maximize_window()); - return make_json_value(result); + return session->web_content_connection().maximize_window(); } // 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window @@ -610,8 +609,7 @@ Web::WebDriver::Response Client::handle_minimize_window(Vector<StringView> const { dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/minimize"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->minimize_window()); - return make_json_value(result); + return session->web_content_connection().minimize_window(); } // 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 2028e9cf0c..ef70dcf297 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -311,45 +311,6 @@ static JsonValue serialize_rect(Gfx::IntRect const& rect) return serialized_rect; } -// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window -Web::WebDriver::Response Session::maximize_window() -{ - // 1. If the remote end does not support the Maximize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation. - - // 2. If the current top-level browsing context is no longer open, return error with error code no such window. - TRY(check_for_open_top_level_browsing_context_or_return_error()); - - // FIXME: 3. Handle any user prompts and return its value if it is an error. - // FIXME: 4. Fully exit fullscreen. - - // 5. Restore the window. - m_browser_connection->async_restore_window(); - - // 6. Maximize the window of the current top-level browsing context. - m_browser_connection->async_maximize_window(); - - // 7. Return success with data set to the WindowRect object for the current top-level browsing context. - return serialize_rect(m_browser_connection->get_window_rect()); -} - -// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window -Web::WebDriver::Response Session::minimize_window() -{ - // 1. If the remote end does not support the Minimize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation. - - // 2. If the current top-level browsing context is no longer open, return error with error code no such window. - TRY(check_for_open_top_level_browsing_context_or_return_error()); - - // FIXME: 3. Handle any user prompts and return its value if it is an error. - // FIXME: 4. Fully exit fullscreen. - - // 5. Iconify the window. - m_browser_connection->async_minimize_window(); - - // 6. Return success with data set to the WindowRect object for the current top-level browsing context. - return serialize_rect(m_browser_connection->get_window_rect()); -} - // https://w3c.github.io/webdriver/#dfn-get-or-create-a-web-element-reference static String get_or_create_a_web_element_reference(Session::LocalElement const& element) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 9094d07718..5acf1b6892 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -58,8 +58,6 @@ public: Web::WebDriver::Response get_window_handle(); ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window(); Web::WebDriver::Response get_window_handles() const; - Web::WebDriver::Response maximize_window(); - Web::WebDriver::Response minimize_window(); Web::WebDriver::Response find_element(JsonValue const& payload); Web::WebDriver::Response find_elements(JsonValue const& payload); Web::WebDriver::Response find_element_from_element(JsonValue const& payload, StringView parameter_element_id); |