WebDriver: Implement POST /session/{id}/window/fullscreen endpoint

This commit is contained in:
Tobias Christiansen 2022-11-09 19:09:17 +01:00 committed by Linus Groh
parent 6805cf00ad
commit 1aa16b4dd4
12 changed files with 57 additions and 0 deletions

View file

@ -287,6 +287,11 @@ Tab::Tab(BrowserWindow& window)
return this->window().rect();
};
view().on_fullscreen_window = [this]() {
this->window().set_fullscreen(true);
return this->window().rect();
};
m_link_context_menu = GUI::Menu::construct();
auto link_default_action = GUI::Action::create("&Open", g_icon_bag.go_to, [this](auto&) {
view().on_link_click(m_link_context_menu_url, "", 0);

View file

@ -473,6 +473,13 @@ Gfx::IntRect OutOfProcessWebView::notify_server_did_request_minimize_window()
return {};
}
Gfx::IntRect OutOfProcessWebView::notify_server_did_request_fullscreen_window()
{
if (on_fullscreen_window)
return on_fullscreen_window();
return {};
}
void OutOfProcessWebView::notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32 request_id)
{
auto file = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window(), path);

View file

@ -106,6 +106,7 @@ public:
Function<Gfx::IntSize(Gfx::IntSize const&)> on_resize_window;
Function<Gfx::IntRect()> on_maximize_window;
Function<Gfx::IntRect()> on_minimize_window;
Function<Gfx::IntRect()> on_fullscreen_window;
private:
OutOfProcessWebView();
@ -174,6 +175,7 @@ private:
virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize const&) override;
virtual Gfx::IntRect notify_server_did_request_maximize_window() override;
virtual Gfx::IntRect notify_server_did_request_minimize_window() override;
virtual Gfx::IntRect notify_server_did_request_fullscreen_window() override;
virtual void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32) override;
void request_repaint();

View file

@ -61,6 +61,7 @@ public:
virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize const&) = 0;
virtual Gfx::IntRect notify_server_did_request_maximize_window() = 0;
virtual Gfx::IntRect notify_server_did_request_minimize_window() = 0;
virtual Gfx::IntRect notify_server_did_request_fullscreen_window() = 0;
virtual void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32) = 0;
};

View file

@ -255,6 +255,11 @@ Messages::WebContentClient::DidRequestMinimizeWindowResponse WebContentClient::d
return m_view.notify_server_did_request_minimize_window();
}
Messages::WebContentClient::DidRequestFullscreenWindowResponse WebContentClient::did_request_fullscreen_window()
{
return m_view.notify_server_did_request_fullscreen_window();
}
void WebContentClient::did_request_file(String const& path, i32 request_id)
{
m_view.notify_server_did_request_file({}, path, request_id);

View file

@ -72,6 +72,7 @@ private:
virtual Messages::WebContentClient::DidRequestResizeWindowResponse did_request_resize_window(Gfx::IntSize const&) override;
virtual Messages::WebContentClient::DidRequestMaximizeWindowResponse did_request_maximize_window() override;
virtual Messages::WebContentClient::DidRequestMinimizeWindowResponse did_request_minimize_window() override;
virtual Messages::WebContentClient::DidRequestFullscreenWindowResponse did_request_fullscreen_window() override;
virtual void did_request_file(String const& path, i32) override;
ViewImplementation& m_view;

View file

@ -50,6 +50,7 @@ endpoint WebContentClient
did_request_resize_window(Gfx::IntSize size) => (Gfx::IntSize window_size)
did_request_maximize_window() => (Gfx::IntRect window_rect)
did_request_minimize_window() => (Gfx::IntRect window_rect)
did_request_fullscreen_window() => (Gfx::IntRect window_rect)
did_request_file(String path, i32 request_id) =|
did_output_js_console_message(i32 message_index) =|

View file

@ -15,6 +15,7 @@ endpoint WebDriverClient {
set_window_rect(JsonValue payload) => (Web::WebDriver::Response response)
maximize_window() => (Web::WebDriver::Response response)
minimize_window() => (Web::WebDriver::Response response)
fullscreen_window() => (Web::WebDriver::Response response)
find_element(JsonValue payload) => (Web::WebDriver::Response response)
find_elements(JsonValue payload) => (Web::WebDriver::Response response)
find_element_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response)

View file

@ -515,6 +515,28 @@ Messages::WebDriverClient::MinimizeWindowResponse WebDriverConnection::minimize_
return serialize_rect(window_rect);
}
// 11.8.5 Fullscreen Window, https://w3c.github.io/webdriver/#dfn-fullscreen-window
Messages::WebDriverClient::FullscreenWindowResponse WebDriverConnection::fullscreen_window()
{
// 1. If the remote end does not support fullscreen 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.
// 4. Restore the window.
restore_the_window();
// 5. FIXME: Call fullscreen an element with the current top-level browsing contexts active documents document element.
// As described in https://fullscreen.spec.whatwg.org/#fullscreen-an-element
// NOTE: What we do here is basically `requestFullscreen(options)` with options["navigationUI"]="show"
auto rect = m_web_content_client.did_request_fullscreen_window();
// 6. Return success with data set to the WindowRect object for the current top-level browsing context.
return serialize_rect(rect);
}
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
Messages::WebDriverClient::FindElementResponse WebDriverConnection::find_element(JsonValue const& payload)
{

View file

@ -48,6 +48,7 @@ private:
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;
virtual Messages::WebDriverClient::FullscreenWindowResponse fullscreen_window() override;
virtual Messages::WebDriverClient::FindElementResponse find_element(JsonValue const& payload) override;
virtual Messages::WebDriverClient::FindElementsResponse find_elements(JsonValue const& payload) override;
virtual Messages::WebDriverClient::FindElementFromElementResponse find_element_from_element(JsonValue const& payload, String const& element_id) override;

View file

@ -43,6 +43,7 @@ Vector<Client::Route> Client::s_routes = {
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "rect" }, &Client::handle_set_window_rect },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "maximize" }, &Client::handle_maximize_window },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "minimize" }, &Client::handle_minimize_window },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "window", "fullscreen" }, &Client::handle_fullscreen_window },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element" }, &Client::handle_find_element },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "elements" }, &Client::handle_find_elements },
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element", ":element_id", "element" }, &Client::handle_find_element_from_element },
@ -608,6 +609,15 @@ Web::WebDriver::Response Client::handle_minimize_window(Vector<StringView> const
return session->web_content_connection().minimize_window();
}
// 11.8.5 Fullscreen Window, https://w3c.github.io/webdriver/#dfn-fullscreen-window
// POST /session/{session id}/window/fullscreen
Web::WebDriver::Response Client::handle_fullscreen_window(Vector<StringView> const& parameters, JsonValue const&)
{
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/fullscreen");
auto* session = TRY(find_session_with_id(parameters[0]));
return session->web_content_connection().fullscreen_window();
}
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
// POST /session/{session id}/element
Web::WebDriver::Response Client::handle_find_element(Vector<StringView> const& parameters, JsonValue const& payload)

View file

@ -67,6 +67,7 @@ private:
Web::WebDriver::Response handle_set_window_rect(Vector<StringView> const&, JsonValue const& payload);
Web::WebDriver::Response handle_maximize_window(Vector<StringView> const&, JsonValue const& payload);
Web::WebDriver::Response handle_minimize_window(Vector<StringView> const&, JsonValue const& payload);
Web::WebDriver::Response handle_fullscreen_window(Vector<StringView> const&, JsonValue const& payload);
Web::WebDriver::Response handle_find_element(Vector<StringView> const&, JsonValue const& payload);
Web::WebDriver::Response handle_find_elements(Vector<StringView> const&, JsonValue const& payload);
Web::WebDriver::Response handle_find_element_from_element(Vector<StringView> const&, JsonValue const& payload);