diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 5fc59ad373..ea285b4e28 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -10,8 +10,6 @@ #include "WebDriverConnection.h" #include "BrowserWindow.h" #include -#include -#include #include namespace Browser { @@ -58,26 +56,4 @@ void WebDriverConnection::forward() browser_window->active_tab().go_forward(); } -Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies() -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies"); - if (auto browser_window = m_browser_window.strong_ref()) { - if (browser_window->active_tab().on_get_cookies_entries) { - return { browser_window->active_tab().on_get_cookies_entries() }; - } - } - return { {} }; -} - -void WebDriverConnection::update_cookie(Web::Cookie::Cookie const& cookie) -{ - dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: update_cookie {}", cookie.name); - if (auto browser_window = m_browser_window.strong_ref()) { - auto& tab = browser_window->active_tab(); - if (tab.on_update_cookie) { - tab.on_update_cookie(tab.url(), cookie); - } - } -} - } diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index d6a92e8e83..55151da325 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -42,8 +42,6 @@ public: virtual void refresh() override; virtual void back() override; virtual void forward() override; - virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override; - virtual void update_cookie(Web::Cookie::Cookie const&) override; private: WebDriverConnection(NonnullOwnPtr socket, NonnullRefPtr browser_window); diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index e7ac4b9a36..62705a1fc5 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -18,6 +18,4 @@ endpoint WebDriverSessionClient { refresh() =| back() =| forward() =| - get_all_cookies() => (Vector cookies) - update_cookie(Web::Cookie::Cookie cookie) =| } diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 9adf708f45..4c60c996ed 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -28,6 +28,7 @@ endpoint WebDriverClient { get_named_cookie(String name) => (Web::WebDriver::Response response) add_cookie(JsonValue payload) => (Web::WebDriver::Response response) delete_cookie(String name) => (Web::WebDriver::Response response) + delete_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 321653c0a0..a88a6761e6 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -990,6 +990,21 @@ Messages::WebDriverClient::DeleteCookieResponse WebDriverConnection::delete_cook return make_success_response({}); } +// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies +Messages::WebDriverClient::DeleteAllCookiesResponse WebDriverConnection::delete_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. Delete cookies, giving no filtering argument. + delete_cookies(); + + // 4. Return success with data null. + return make_success_response({}); +} + // 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 2cf2139273..aa67512462 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -60,6 +60,7 @@ private: virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override; virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override; virtual Messages::WebDriverClient::DeleteCookieResponse delete_cookie(String const& name) override; + virtual Messages::WebDriverClient::DeleteAllCookiesResponse delete_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 41802b21ec..b3087b86c9 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -789,8 +789,7 @@ Web::WebDriver::Response Client::handle_delete_all_cookies(Vector co { dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session//cookie"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->delete_all_cookies()); - return make_json_value(result); + return session->web_content_connection().delete_all_cookies(); } // 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index ef706409fa..1213e7276a 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -19,9 +19,6 @@ #include #include #include -#include -#include -#include #include namespace WebDriver { @@ -297,37 +294,4 @@ Web::WebDriver::Response Session::get_window_handles() const return JsonValue { handles }; } -// https://w3c.github.io/webdriver/#dfn-delete-cookies -void Session::delete_cookies(Optional const& name) -{ - // For each cookie among all associated cookies of the current browsing context’s active document, - // run the substeps of the first matching condition: - for (auto& cookie : m_browser_connection->get_all_cookies()) { - // -> name is undefined - // -> name is equal to cookie name - if (!name.has_value() || name.value() == cookie.name) { - // Set the cookie expiry time to a Unix timestamp in the past. - cookie.expiry_time = Core::DateTime::from_timestamp(0); - m_browser_connection->async_update_cookie(cookie); - } - // -> Otherwise - // Do nothing. - } -} - -// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies -Web::WebDriver::Response Session::delete_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. Delete cookies, giving no filtering argument. - delete_cookies(); - - // 4. Return success with data null. - return JsonValue(); -} - } diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 1e801ded03..52d88f1ff6 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -58,12 +58,9 @@ public: Web::WebDriver::Response get_window_handle(); ErrorOr> close_window(); Web::WebDriver::Response get_window_handles() const; - Web::WebDriver::Response delete_all_cookies(); Web::WebDriver::Response take_element_screenshot(StringView element_id); private: - void delete_cookies(Optional const& name = {}); - enum class ServerType { Browser, WebContent,