diff options
author | Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 2023-03-14 14:09:50 +0300 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-03-16 13:17:37 -0400 |
commit | f28716582369cd7e79c3df7196278990d45492b7 (patch) | |
tree | 52a30bcf5a5aac721dca359f3a05153849b15126 /Userland/Services | |
parent | 7061322606321b856cbd95e7972c8c712d8fbce1 (diff) | |
download | serenity-f28716582369cd7e79c3df7196278990d45492b7.zip |
LibWeb+WebContent+WebDriver: Add WebDriver endpoint to open new window
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 39 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.h | 1 |
5 files changed, 51 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 035e37d714..3ae9553102 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -16,6 +16,7 @@ endpoint WebDriverClient { refresh() => (Web::WebDriver::Response response) get_title() => (Web::WebDriver::Response response) close_window() => (Web::WebDriver::Response response) + new_window(JsonValue payload) => (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) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index bd32b97ea1..bd157d4f70 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -536,6 +536,45 @@ Messages::WebDriverClient::CloseWindowResponse WebDriverConnection::close_window return JsonValue {}; } +// 11.5 New Window, https://w3c.github.io/webdriver/#dfn-new-window +Messages::WebDriverClient::NewWindowResponse WebDriverConnection::new_window(JsonValue const&) +{ + // 1. If the implementation does not support creating new top-level browsing contexts, 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()); + + // 3. Handle any user prompts and return its value if it is an error. + TRY(handle_any_user_prompts()); + + // FIXME: 4. Let type hint be the result of getting the property "type" from the parameters argument. + + // 5. Create a new top-level browsing context by running the window open steps with url set to "about:blank", + // target set to the empty string, and features set to "noopener" and the user agent configured to create a new + // browsing context. This must be done without invoking the focusing steps for the created browsing context. If + // type hint has the value "tab", and the implementation supports multiple browsing context in the same OS + // window, the new browsing context should share an OS window with the current browsing context. If type hint + // is "window", and the implementation supports multiple browsing contexts in separate OS windows, the + // created browsing context should be in a new OS window. In all other cases the details of how the browsing + // context is presented to the user are implementation defined. + // FIXME: Reuse code of window.open() instead of calling choose_a_browsing_context + auto [browsing_context, window_type] = m_page_client.page().top_level_browsing_context().choose_a_browsing_context("_blank"sv, true); + + // 6. Let handle be the associated window handle of the newly created window. + auto handle = browsing_context->window_handle(); + + // 7. Let type be "tab" if the newly created window shares an OS-level window with the current browsing context, or "window" otherwise. + auto type = "tab"sv; + + // 8. Let result be a new JSON Object initialized with: + JsonObject result; + result.set("handle"sv, JsonValue { handle }); + result.set("type"sv, JsonValue { type }); + + // 9. Return success with data result. + return result; +} + // 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect Messages::WebDriverClient::GetWindowRectResponse WebDriverConnection::get_window_rect() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 5e73b03be9..e1bfcf2aad 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -53,6 +53,7 @@ private: virtual Messages::WebDriverClient::RefreshResponse refresh() override; virtual Messages::WebDriverClient::GetTitleResponse get_title() override; virtual Messages::WebDriverClient::CloseWindowResponse close_window() override; + virtual Messages::WebDriverClient::NewWindowResponse new_window(JsonValue const& payload) 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; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 0af5239936..b97b732f67 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -335,6 +335,15 @@ Web::WebDriver::Response Client::get_window_handles(Web::WebDriver::Parameters p return session->get_window_handles(); } +// 11.5 New Window, https://w3c.github.io/webdriver/#dfn-new-window +// POST /session/{session id}/window/new +Web::WebDriver::Response Client::new_window(Web::WebDriver::Parameters parameters, JsonValue payload) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/new"); + auto session = TRY(find_session_with_id(parameters[0])); + return session->web_content_connection().new_window(payload); +} + // 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect // GET /session/{session id}/window/rect Web::WebDriver::Response Client::get_window_rect(Web::WebDriver::Parameters parameters, JsonValue) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index 10d4450a4e..27c204e692 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -52,6 +52,7 @@ private: virtual Web::WebDriver::Response close_window(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response switch_to_window(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response get_window_handles(Web::WebDriver::Parameters parameters, JsonValue payload) override; + virtual Web::WebDriver::Response new_window(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response get_window_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response set_window_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response maximize_window(Web::WebDriver::Parameters parameters, JsonValue payload) override; |