diff options
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 43 | ||||
-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 | 24 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.h | 1 |
6 files changed, 46 insertions, 27 deletions
diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index b8f803f2f3..a7d70c8ff5 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -24,6 +24,7 @@ endpoint WebDriverClient { get_source() => (Web::WebDriver::Response response) execute_script(JsonValue payload) => (Web::WebDriver::Response response) execute_async_script(JsonValue payload) => (Web::WebDriver::Response response) + get_all_cookies() => (Web::WebDriver::Response response) take_screenshot() => (Web::WebDriver::Response response) take_element_screenshot(String element_id) => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 9b4e67098b..94b12c8a46 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -16,6 +16,7 @@ #include <LibWeb/CSS/PropertyID.h> #include <LibWeb/CSS/StyleProperties.h> #include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/Cookie/Cookie.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/Geometry/DOMRect.h> @@ -41,6 +42,22 @@ static JsonValue make_success_response(JsonValue value) return result; } +// https://w3c.github.io/webdriver/#dfn-serialized-cookie +static JsonValue serialize_cookie(Web::Cookie::Cookie const& cookie) +{ + JsonObject serialized_cookie; + serialized_cookie.set("name"sv, cookie.name); + serialized_cookie.set("value"sv, cookie.value); + serialized_cookie.set("path"sv, cookie.path); + serialized_cookie.set("domain"sv, cookie.domain); + serialized_cookie.set("secure"sv, cookie.secure); + serialized_cookie.set("httpOnly"sv, cookie.http_only); + serialized_cookie.set("expiry"sv, cookie.expiry_time.timestamp()); + serialized_cookie.set("sameSite"sv, Web::Cookie::same_site_to_string(cookie.same_site)); + + return serialized_cookie; +} + static JsonValue serialize_rect(Gfx::IntRect const& rect) { JsonObject serialized_rect = {}; @@ -829,6 +846,32 @@ Messages::WebDriverClient::ExecuteAsyncScriptResponse WebDriverConnection::execu VERIFY_NOT_REACHED(); } +// 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies +Messages::WebDriverClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies() +{ + // 1. If the current browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // FIXME: 2. Handle any user prompts, and return its value if it is an error. + + // 3. Let cookies be a new JSON List. + JsonArray cookies; + + // 4. For each cookie in all associated cookies of the current browsing context’s active document: + auto* document = m_page_host.page().top_level_browsing_context().active_document(); + + for (auto const& cookie : m_web_content_client.did_request_all_cookies(document->url())) { + // 1. Let serialized cookie be the result of serializing cookie. + auto serialized_cookie = serialize_cookie(cookie); + + // 2. Append serialized cookie to cookies + cookies.append(move(serialized_cookie)); + } + + // 5. Return success with data cookies. + return make_success_response(move(cookies)); +} + // 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 56e00a907e..91f6735056 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -56,6 +56,7 @@ private: virtual Messages::WebDriverClient::GetSourceResponse get_source() override; virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override; virtual Messages::WebDriverClient::ExecuteAsyncScriptResponse execute_async_script(JsonValue const& payload) override; + virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override; virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override; virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 0587209c91..c5f660eacc 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -753,8 +753,7 @@ Web::WebDriver::Response Client::handle_get_all_cookies(Vector<StringView> const { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/cookie"); auto* session = TRY(find_session_with_id(parameters[0])); - auto cookies = TRY(session->get_all_cookies()); - return make_json_value(cookies); + return session->web_content_connection().get_all_cookies(); } // 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 4732d4fef3..3c9c816c8c 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -313,30 +313,6 @@ static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie) return serialized_cookie; } -// 14.1 Get All Cookies, https://w3c.github.io/webdriver/#dfn-get-all-cookies -Web::WebDriver::Response Session::get_all_cookies() -{ - // 1. If the current 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 cookies be a new JSON List. - JsonArray cookies = {}; - - // 4. For each cookie in all associated cookies of the current browsing context’s active document: - for (auto const& cookie : m_browser_connection->get_all_cookies()) { - // 1. Let serialized cookie be the result of serializing cookie. - auto serialized_cookie = serialize_cookie(cookie); - - // 2. Append serialized cookie to cookies - cookies.append(serialized_cookie); - } - - // 5. Return success with data cookies. - return JsonValue(cookies); -} - // 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie Web::WebDriver::Response Session::get_named_cookie(String const& name) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index da590dc1ed..cb7fcdccc5 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -58,7 +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 get_all_cookies(); Web::WebDriver::Response get_named_cookie(String const& name); Web::WebDriver::Response add_cookie(JsonValue const& payload); Web::WebDriver::Response delete_cookie(StringView name); |