diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-08 13:06:22 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-11-08 19:58:34 -0500 |
commit | 3ba6b5a7cbf9d8efba5599c9c8d9b09945167157 (patch) | |
tree | 9f4625eaabbb5bf7fa536928fb4e77d563e72af1 /Userland | |
parent | 31bb79295d64ff16835603f9423464c55c5bde22 (diff) | |
download | serenity-3ba6b5a7cbf9d8efba5599c9c8d9b09945167157.zip |
WebContent+WebDriver: Move the Get Current URL command to WebContent
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 18 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 3 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.cpp | 15 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.h | 1 |
6 files changed, 21 insertions, 18 deletions
diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index e91a73ef6d..e05233f3bb 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -3,4 +3,5 @@ endpoint WebDriverClient { set_is_webdriver_active(bool active) =| navigate_to(JsonValue payload) => (Web::WebDriver::Response response) + get_current_url() => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 898297d957..7b21161888 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -11,6 +11,7 @@ #include <AK/JsonObject.h> #include <AK/JsonValue.h> #include <AK/Vector.h> +#include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/BrowsingContext.h> #include <LibWeb/Page/Page.h> #include <LibWeb/Platform/Timer.h> @@ -86,6 +87,23 @@ Messages::WebDriverClient::NavigateToResponse WebDriverConnection::navigate_to(J return { make_success_response({}) }; } +// 10.2 Get Current URL, https://w3c.github.io/webdriver/#get-current-url +Messages::WebDriverClient::GetCurrentUrlResponse WebDriverConnection::get_current_url() +{ + dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection::get_current_url"); + + // 1. If the current top-level browsing context is no longer open, return error with error code no such window. + DRIVER_TRY(ensure_open_top_level_browsing_context()); + + // FIXME: 2. Handle any user prompts and return its value if it is an error. + + // 3. Let url be the serialization of the current top-level browsing context’s active document’s document URL. + auto url = m_page_host.page().top_level_browsing_context().active_document()->url().to_string(); + + // 4. Return success with data url. + return { make_success_response(url) }; +} + // https://w3c.github.io/webdriver/#dfn-no-longer-open ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index ac756e2496..a2b8d76b17 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -30,6 +30,7 @@ private: virtual void die() override { } virtual void set_is_webdriver_active(bool) override; virtual Messages::WebDriverClient::NavigateToResponse navigate_to(JsonValue const& payload) override; + virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override; ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context(); diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index d62008b108..0f826b0e74 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -491,8 +491,7 @@ Web::WebDriver::Response Client::handle_get_current_url(Vector<StringView> const { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->get_current_url()); - return make_json_value(result); + return session->web_content_connection().get_current_url(); } // 10.3 Back, https://w3c.github.io/webdriver/#dfn-back diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 10e644e58b..65c1363138 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -165,21 +165,6 @@ Web::WebDriver::Response Session::set_timeouts(JsonValue const& payload) return JsonValue {}; } -// 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url -Web::WebDriver::Response Session::get_current_url() -{ - // 1. 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: 2. Handle any user prompts and return its value if it is an error. - - // 3. Let url be the serialization of the current top-level browsing context’s active document’s document URL. - auto url = m_browser_connection->get_url().to_string(); - - // 4. Return success with data url. - return JsonValue(url); -} - // 10.3 Back, https://w3c.github.io/webdriver/#dfn-back Web::WebDriver::Response Session::back() { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index baa97fd1a9..329249ab16 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -51,7 +51,6 @@ public: ErrorOr<void> stop(); JsonObject get_timeouts(); Web::WebDriver::Response set_timeouts(JsonValue const& payload); - Web::WebDriver::Response get_current_url(); Web::WebDriver::Response back(); Web::WebDriver::Response forward(); Web::WebDriver::Response refresh(); |