diff options
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 5 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 34 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 2 | ||||
-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 |
7 files changed, 43 insertions, 18 deletions
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 81e0bb388f..9ee6866b29 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -374,6 +374,11 @@ Tab::Tab(BrowserWindow& window) on_set_cookie(url, cookie, source); }; + view().on_update_cookie = [this](auto& url, auto& cookie) { + if (on_update_cookie) + on_update_cookie(url, cookie); + }; + view().on_get_source = [this](auto& url, auto& source) { view_source(url, source); }; diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 9ff40b94d8..9adf708f45 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -27,6 +27,7 @@ endpoint WebDriverClient { get_all_cookies() => (Web::WebDriver::Response response) 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) 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 bc850fd910..321653c0a0 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -975,6 +975,21 @@ Messages::WebDriverClient::AddCookieResponse WebDriverConnection::add_cookie(Jso return make_success_response({}); } +// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie +Messages::WebDriverClient::DeleteCookieResponse WebDriverConnection::delete_cookie(String const& name) +{ + // 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 using the url variable name parameter as the filter argument. + delete_cookies(name); + + // 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() { @@ -1138,4 +1153,23 @@ ErrorOr<WebDriverConnection::ScriptArguments, Web::WebDriver::Error> WebDriverCo return ScriptArguments { move(script), move(arguments) }; } +// https://w3c.github.io/webdriver/#dfn-delete-cookies +void WebDriverConnection::delete_cookies(Optional<StringView> const& name) +{ + // For each cookie among all associated cookies of the current browsing context’s active document, un the substeps of the first matching condition: + auto* document = m_page_host.page().top_level_browsing_context().active_document(); + + for (auto& cookie : m_web_content_client.did_request_all_cookies(document->url())) { + // -> 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_web_content_client.async_did_update_cookie(document->url(), cookie); + } + // -> Otherwise + // Do nothing. + } +} + } diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 2e48343a3e..2cf2139273 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -59,6 +59,7 @@ private: virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override; 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::TakeScreenshotResponse take_screenshot() override; virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override; @@ -73,6 +74,7 @@ private: JS::MarkedVector<JS::Value> arguments; }; ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JsonValue const& payload); + void delete_cookies(Optional<StringView> const& name = {}); ConnectionFromClient& m_web_content_client; PageHost& m_page_host; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index c3daca6e0d..41802b21ec 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -780,8 +780,7 @@ Web::WebDriver::Response Client::handle_delete_cookie(Vector<StringView> const& { dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie/<name>"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->delete_cookie(parameters[1])); - return make_json_value(result); + return session->web_content_connection().delete_cookie(parameters[1]); } // 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index efd9b43afc..ef706409fa 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -315,21 +315,6 @@ void Session::delete_cookies(Optional<StringView> const& name) } } -// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie -Web::WebDriver::Response Session::delete_cookie(StringView name) -{ - // 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 using the url variable name parameter as the filter argument. - delete_cookies(name); - - // 4. Return success with data null. - return JsonValue(); -} - // 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies Web::WebDriver::Response Session::delete_all_cookies() { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 0f3ee28f07..1e801ded03 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 delete_cookie(StringView name); Web::WebDriver::Response delete_all_cookies(); Web::WebDriver::Response take_element_screenshot(StringView element_id); |