1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:07:35 +00:00

Browser: Propagate autoplay settings to the WebContent process

This commit is contained in:
Timothy Flynn 2023-04-17 13:37:36 -04:00 committed by Andreas Kling
parent 65283d6879
commit fed2606591
6 changed files with 62 additions and 1 deletions

View file

@ -36,6 +36,8 @@ DeprecatedString g_home_url;
DeprecatedString g_new_tab_url;
Vector<DeprecatedString> g_content_filters;
bool g_content_filters_enabled { true };
Vector<String> g_autoplay_allowlist;
bool g_autoplay_allowed_on_all_websites { false };
Vector<DeprecatedString> g_proxies;
HashMap<DeprecatedString, size_t> g_proxy_mappings;
IconBag g_icon_bag;
@ -57,6 +59,26 @@ static ErrorOr<void> load_content_filters()
return {};
}
static ErrorOr<void> load_autoplay_allowlist()
{
auto file = TRY(Core::File::open(TRY(String::formatted("{}/BrowserAutoplayAllowlist.txt", Core::StandardPaths::config_directory())), Core::File::OpenMode::Read));
auto allowlist = TRY(Core::BufferedFile::create(move(file)));
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
Browser::g_autoplay_allowlist.clear_with_capacity();
while (TRY(allowlist->can_read_line())) {
auto line = TRY(allowlist->read_line(buffer));
if (line.is_empty())
continue;
auto domain = TRY(String::from_utf8(line));
TRY(Browser::g_autoplay_allowlist.try_append(move(domain)));
}
return {};
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (getuid() == 0) {
@ -110,11 +132,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Browser::g_new_tab_url = Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, "file:///res/html/misc/new-tab.html"sv);
Browser::g_search_engine = Config::read_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, {});
Browser::g_content_filters_enabled = Config::read_bool("Browser"sv, "Preferences"sv, "EnableContentFilters"sv, true);
Browser::g_autoplay_allowed_on_all_websites = Config::read_bool("Browser"sv, "Preferences"sv, "AllowAutoplayOnAllWebsites"sv, false);
Browser::g_icon_bag = TRY(Browser::IconBag::try_create());
auto database = TRY(Browser::Database::create());
TRY(load_content_filters());
TRY(load_autoplay_allowlist());
for (auto& group : Config::list_groups("Browser"sv)) {
if (!group.starts_with("Proxy:"sv))
@ -156,6 +180,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
};
TRY(content_filters_watcher->add_watch(DeprecatedString::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::FileWatcherEvent::Type::ContentModified));
auto autoplay_allowlist_watcher = TRY(Core::FileWatcher::create());
autoplay_allowlist_watcher->on_change = [&](Core::FileWatcherEvent const&) {
dbgln("Reloading autoplay allowlist because config file changed");
if (auto error = load_autoplay_allowlist(); error.is_error()) {
dbgln("Reloading autoplay allowlist failed: {}", error.release_error());
return;
}
window->autoplay_allowlist_changed();
};
TRY(autoplay_allowlist_watcher->add_watch(DeprecatedString::formatted("{}/BrowserAutoplayAllowlist.txt", Core::StandardPaths::config_directory()), Core::FileWatcherEvent::Type::ContentModified));
app->on_action_enter = [&](GUI::Action& action) {
if (auto* browser_window = dynamic_cast<Browser::BrowserWindow*>(app->active_window())) {
auto* tab = static_cast<Browser::Tab*>(browser_window->tab_widget().active_widget());