Skip to content

Commit

Permalink
LibWebView: Add method to remove all cookies globally
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmg-x committed Jan 4, 2025
1 parent c60ad5b commit e45929e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Libraries/LibWebView/CookieJar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Web::Cookie::Cookie> CookieJar::get_all_cookies()
{
Vector<Web::Cookie::Cookie> cookies;
Expand Down Expand Up @@ -639,6 +644,16 @@ UnixDateTime CookieJar::TransientStorage::purge_expired_cookies(Optional<AK::Dur
return now;
}

void CookieJar::TransientStorage::expire_and_purge_all_cookies()
{
for (auto& [key, value] : m_cookies) {
value.expiry_time = UnixDateTime::earliest();
set_cookie(key, value);
}

purge_expired_cookies();
}

void CookieJar::PersistedStorage::insert_cookie(Web::Cookie::Cookie const& cookie)
{
database.execute_statement(
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibWebView/CookieJar.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CookieJar {
size_t size() const { return m_cookies.size(); }

UnixDateTime purge_expired_cookies(Optional<AK::Duration> offset = {});
void expire_and_purge_all_cookies();

auto take_dirty_cookies() { return move(m_dirty_cookies); }

Expand Down Expand Up @@ -91,6 +92,7 @@ class CookieJar {
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<Web::Cookie::Cookie> get_all_cookies();
Vector<Web::Cookie::Cookie> get_all_cookies(URL::URL const& url);
Optional<Web::Cookie::Cookie> get_named_cookie(URL::URL const& url, StringView name);
Expand Down

0 comments on commit e45929e

Please sign in to comment.