mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +02:00
LibWebView: Add a settings section to manage browsing data caches
This adds a section to allow users to clear the HTTP disk cache and cookies / local storage / session storage. There are a few options to limit this action to a specific time range (e.g. "last hour"). The user is informed how much disk space is being used currently, and how much will be removed given the selected time range. The idea is that in the future, we can add more settings here to auto- delete data on exit, disable caching altogether, etc.
This commit is contained in:
Notes:
github-actions[bot]
2025-11-12 14:08:01 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/c34119cb29c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6675 Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/konradekk
@@ -63,6 +63,12 @@ void SettingsUI::register_interfaces()
|
||||
remove_all_site_setting_filters(data);
|
||||
});
|
||||
|
||||
register_interface("estimateBrowsingDataSizes"sv, [this](auto const& data) {
|
||||
estimate_browsing_data_sizes(data);
|
||||
});
|
||||
register_interface("clearBrowsingData"sv, [this](auto const& data) {
|
||||
clear_browsing_data(data);
|
||||
});
|
||||
register_interface("setGlobalPrivacyControl"sv, [this](auto const& data) {
|
||||
set_global_privacy_control(data);
|
||||
});
|
||||
@@ -275,6 +281,57 @@ void SettingsUI::remove_all_site_setting_filters(JsonValue const& site_setting)
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::estimate_browsing_data_sizes(JsonValue const& options)
|
||||
{
|
||||
if (!options.is_object())
|
||||
return;
|
||||
|
||||
auto& application = Application::the();
|
||||
|
||||
auto since = [&]() {
|
||||
if (auto since = options.as_object().get_integer<i64>("since"sv); since.has_value())
|
||||
return UnixDateTime::from_milliseconds_since_epoch(*since);
|
||||
return UnixDateTime::earliest();
|
||||
}();
|
||||
|
||||
application.estimate_browsing_data_size_accessed_since(since)
|
||||
->when_resolved([this](Application::BrowsingDataSizes sizes) {
|
||||
JsonObject result;
|
||||
|
||||
result.set("cacheSizeSinceRequestedTime"sv, sizes.cache_size_since_requested_time);
|
||||
result.set("totalCacheSize"sv, sizes.total_cache_size);
|
||||
|
||||
result.set("siteDataSizeSinceRequestedTime"sv, sizes.site_data_size_since_requested_time);
|
||||
result.set("totalSiteDataSize"sv, sizes.total_site_data_size);
|
||||
|
||||
async_send_message("estimatedBrowsingDataSizes"sv, move(result));
|
||||
})
|
||||
.when_rejected([](Error const& error) {
|
||||
dbgln("Failed to estimate browsing data sizes: {}", error);
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsUI::clear_browsing_data(JsonValue const& options)
|
||||
{
|
||||
if (!options.is_object())
|
||||
return;
|
||||
|
||||
Application::ClearBrowsingDataOptions clear_browsing_data_options;
|
||||
|
||||
if (auto since = options.as_object().get_integer<i64>("since"sv); since.has_value())
|
||||
clear_browsing_data_options.since = UnixDateTime::from_milliseconds_since_epoch(*since);
|
||||
|
||||
clear_browsing_data_options.delete_cached_files = options.as_object().get_bool("cachedFiles"sv).value_or(false)
|
||||
? Application::ClearBrowsingDataOptions::Delete::Yes
|
||||
: Application::ClearBrowsingDataOptions::Delete::No;
|
||||
|
||||
clear_browsing_data_options.delete_site_data = options.as_object().get_bool("siteData"sv).value_or(false)
|
||||
? Application::ClearBrowsingDataOptions::Delete::Yes
|
||||
: Application::ClearBrowsingDataOptions::Delete::No;
|
||||
|
||||
Application::the().clear_browsing_data(clear_browsing_data_options);
|
||||
}
|
||||
|
||||
void SettingsUI::set_global_privacy_control(JsonValue const& global_privacy_control)
|
||||
{
|
||||
if (!global_privacy_control.is_bool())
|
||||
|
||||
Reference in New Issue
Block a user