From dc34aeb764b23db3234c3b7c3c6c98b354f70863 Mon Sep 17 00:00:00 2001 From: rmg-x Date: Sat, 4 Jan 2025 11:29:05 -0600 Subject: [PATCH] LibWebView: Add method to remove all cookies globally The inspector widget has this functionality, but it's limited to the site you're currently viewing. This commit adds an option for removing all cookies globally. Previously, the workaround was to open a sqlite shell and run: `DELETE FROM Cookies;` on the database yourself. --- Libraries/LibWebView/CookieJar.cpp | 15 +++++++++++++++ Libraries/LibWebView/CookieJar.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Libraries/LibWebView/CookieJar.cpp b/Libraries/LibWebView/CookieJar.cpp index 5ce475d0cbc..eb469f7f6f2 100644 --- a/Libraries/LibWebView/CookieJar.cpp +++ b/Libraries/LibWebView/CookieJar.cpp @@ -174,6 +174,11 @@ void CookieJar::dump_cookies() dbgln("{} cookies stored\n{}", m_transient_storage.size(), builder.string_view()); } +void CookieJar::clear_all_cookies() +{ + m_transient_storage.expire_and_purge_all_cookies(); +} + Vector CookieJar::get_all_cookies() { Vector cookies; @@ -639,6 +644,16 @@ UnixDateTime CookieJar::TransientStorage::purge_expired_cookies(Optional offset = {}); + void expire_and_purge_all_cookies(); auto take_dirty_cookies() { return move(m_dirty_cookies); } @@ -91,6 +92,7 @@ public: void set_cookie(const URL::URL& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source); void update_cookie(Web::Cookie::Cookie); void dump_cookies(); + void clear_all_cookies(); Vector get_all_cookies(); Vector get_all_cookies(URL::URL const& url); Optional get_named_cookie(URL::URL const& url, StringView name);