Skip to content

Commit dc34aeb

Browse files
rmg-xAtkinsSJ
authored andcommitted
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.
1 parent 49a7a0f commit dc34aeb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Libraries/LibWebView/CookieJar.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ void CookieJar::dump_cookies()
174174
dbgln("{} cookies stored\n{}", m_transient_storage.size(), builder.string_view());
175175
}
176176

177+
void CookieJar::clear_all_cookies()
178+
{
179+
m_transient_storage.expire_and_purge_all_cookies();
180+
}
181+
177182
Vector<Web::Cookie::Cookie> CookieJar::get_all_cookies()
178183
{
179184
Vector<Web::Cookie::Cookie> cookies;
@@ -639,6 +644,16 @@ UnixDateTime CookieJar::TransientStorage::purge_expired_cookies(Optional<AK::Dur
639644
return now;
640645
}
641646

647+
void CookieJar::TransientStorage::expire_and_purge_all_cookies()
648+
{
649+
for (auto& [key, value] : m_cookies) {
650+
value.expiry_time = UnixDateTime::earliest();
651+
set_cookie(key, value);
652+
}
653+
654+
purge_expired_cookies();
655+
}
656+
642657
void CookieJar::PersistedStorage::insert_cookie(Web::Cookie::Cookie const& cookie)
643658
{
644659
database.execute_statement(

Libraries/LibWebView/CookieJar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CookieJar {
4848
size_t size() const { return m_cookies.size(); }
4949

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

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

@@ -91,6 +92,7 @@ class CookieJar {
9192
void set_cookie(const URL::URL& url, Web::Cookie::ParsedCookie const& parsed_cookie, Web::Cookie::Source source);
9293
void update_cookie(Web::Cookie::Cookie);
9394
void dump_cookies();
95+
void clear_all_cookies();
9496
Vector<Web::Cookie::Cookie> get_all_cookies();
9597
Vector<Web::Cookie::Cookie> get_all_cookies(URL::URL const& url);
9698
Optional<Web::Cookie::Cookie> get_named_cookie(URL::URL const& url, StringView name);

0 commit comments

Comments
 (0)