mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWebView: Add autoplay settings to about:settings
The idea with the UI here is that it will serve as a generic component for all site settings, such as autoplay, notifications, etc. When the site settings dialog is opened, it is filled with the requested setting data, and messages sent to the browser process are based on the setting. This patch only implements the UI and persisted settings. It does not apply autoplay changes to the WebContent process.
This commit is contained in:
parent
c7979a8bd6
commit
223b04f087
Notes:
github-actions[bot]
2025-03-30 15:20:14 +00:00
Author: https://github.com/trflynn89
Commit: 223b04f087
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4146
Reviewed-by: https://github.com/tcl3 ✅
6 changed files with 614 additions and 10 deletions
|
@ -29,6 +29,21 @@ void SettingsUI::register_interfaces()
|
|||
register_interface("setSearchEngine"sv, [this](auto const& data) {
|
||||
set_search_engine(data);
|
||||
});
|
||||
register_interface("loadForciblyEnabledSiteSettings"sv, [this](auto const&) {
|
||||
load_forcibly_enabled_site_settings();
|
||||
});
|
||||
register_interface("setSiteSettingEnabledGlobally"sv, [this](auto const& data) {
|
||||
set_site_setting_enabled_globally(data);
|
||||
});
|
||||
register_interface("addSiteSettingFilter"sv, [this](auto const& data) {
|
||||
add_site_setting_filter(data);
|
||||
});
|
||||
register_interface("removeSiteSettingFilter"sv, [this](auto const& data) {
|
||||
remove_site_setting_filter(data);
|
||||
});
|
||||
register_interface("removeAllSiteSettingFilters"sv, [this](auto const& data) {
|
||||
remove_all_site_setting_filters(data);
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsUI::load_current_settings()
|
||||
|
@ -72,4 +87,113 @@ void SettingsUI::set_search_engine(JsonValue const& search_engine)
|
|||
WebView::Application::settings().set_search_engine(search_engine.as_string());
|
||||
}
|
||||
|
||||
enum class SiteSettingType {
|
||||
Autoplay,
|
||||
};
|
||||
|
||||
static constexpr StringView site_setting_type_to_string(SiteSettingType setting)
|
||||
{
|
||||
switch (setting) {
|
||||
case SiteSettingType::Autoplay:
|
||||
return "autoplay"sv;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
static Optional<SiteSettingType> site_setting_type(JsonValue const& settings)
|
||||
{
|
||||
if (!settings.is_object())
|
||||
return {};
|
||||
|
||||
auto setting_type = settings.as_object().get_string("setting"sv);
|
||||
if (!setting_type.has_value())
|
||||
return {};
|
||||
|
||||
if (*setting_type == "autoplay"sv)
|
||||
return SiteSettingType::Autoplay;
|
||||
return {};
|
||||
}
|
||||
|
||||
void SettingsUI::load_forcibly_enabled_site_settings()
|
||||
{
|
||||
JsonArray site_settings;
|
||||
|
||||
if (Application::web_content_options().enable_autoplay == EnableAutoplay::Yes)
|
||||
site_settings.must_append(site_setting_type_to_string(SiteSettingType::Autoplay));
|
||||
|
||||
async_send_message("forciblyEnableSiteSettings"sv, move(site_settings));
|
||||
}
|
||||
|
||||
void SettingsUI::set_site_setting_enabled_globally(JsonValue const& site_setting)
|
||||
{
|
||||
auto setting = site_setting_type(site_setting);
|
||||
if (!setting.has_value())
|
||||
return;
|
||||
|
||||
auto enabled = site_setting.as_object().get_bool("enabled"sv);
|
||||
if (!enabled.has_value())
|
||||
return;
|
||||
|
||||
switch (*setting) {
|
||||
case SiteSettingType::Autoplay:
|
||||
WebView::Application::settings().set_autoplay_enabled_globally(*enabled);
|
||||
break;
|
||||
}
|
||||
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::add_site_setting_filter(JsonValue const& site_setting)
|
||||
{
|
||||
auto setting = site_setting_type(site_setting);
|
||||
if (!setting.has_value())
|
||||
return;
|
||||
|
||||
auto filter = site_setting.as_object().get_string("filter"sv);
|
||||
if (!filter.has_value())
|
||||
return;
|
||||
|
||||
switch (*setting) {
|
||||
case SiteSettingType::Autoplay:
|
||||
WebView::Application::settings().add_autoplay_site_filter(*filter);
|
||||
break;
|
||||
}
|
||||
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::remove_site_setting_filter(JsonValue const& site_setting)
|
||||
{
|
||||
auto setting = site_setting_type(site_setting);
|
||||
if (!setting.has_value())
|
||||
return;
|
||||
|
||||
auto filter = site_setting.as_object().get_string("filter"sv);
|
||||
if (!filter.has_value())
|
||||
return;
|
||||
|
||||
switch (*setting) {
|
||||
case SiteSettingType::Autoplay:
|
||||
WebView::Application::settings().remove_autoplay_site_filter(*filter);
|
||||
break;
|
||||
}
|
||||
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::remove_all_site_setting_filters(JsonValue const& site_setting)
|
||||
{
|
||||
auto setting = site_setting_type(site_setting);
|
||||
if (!setting.has_value())
|
||||
return;
|
||||
|
||||
switch (*setting) {
|
||||
case SiteSettingType::Autoplay:
|
||||
WebView::Application::settings().remove_all_autoplay_site_filters();
|
||||
break;
|
||||
}
|
||||
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue