mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:47:35 +00:00
Browser: Propagate autoplay settings to the WebContent process
This commit is contained in:
parent
65283d6879
commit
fed2606591
6 changed files with 62 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/String.h>
|
||||
#include <Applications/Browser/IconBag.h>
|
||||
|
||||
namespace Browser {
|
||||
|
@ -15,9 +16,11 @@ extern DeprecatedString g_home_url;
|
|||
extern DeprecatedString g_new_tab_url;
|
||||
extern DeprecatedString g_search_engine;
|
||||
extern Vector<DeprecatedString> g_content_filters;
|
||||
extern bool g_content_filters_enabled;
|
||||
extern Vector<String> g_autoplay_allowlist;
|
||||
extern bool g_autoplay_allowed_on_all_websites;
|
||||
extern Vector<DeprecatedString> g_proxies;
|
||||
extern HashMap<DeprecatedString, size_t> g_proxy_mappings;
|
||||
extern bool g_content_filters_enabled;
|
||||
extern IconBag g_icon_bag;
|
||||
extern DeprecatedString g_webdriver_content_ipc_path;
|
||||
|
||||
|
|
|
@ -683,6 +683,14 @@ void BrowserWindow::content_filters_changed()
|
|||
});
|
||||
}
|
||||
|
||||
void BrowserWindow::autoplay_allowlist_changed()
|
||||
{
|
||||
tab_widget().for_each_child_of_type<Browser::Tab>([](auto& tab) {
|
||||
tab.autoplay_allowlist_changed();
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
void BrowserWindow::proxy_mappings_changed()
|
||||
{
|
||||
tab_widget().for_each_child_of_type<Browser::Tab>([](auto& tab) {
|
||||
|
@ -729,6 +737,9 @@ void BrowserWindow::config_bool_did_change(DeprecatedString const& domain, Depre
|
|||
} else if (key == "EnableContentFilters") {
|
||||
Browser::g_content_filters_enabled = value;
|
||||
content_filters_changed();
|
||||
} else if (key == "AllowAutoplayOnAllWebsites") {
|
||||
Browser::g_autoplay_allowed_on_all_websites = value;
|
||||
autoplay_allowlist_changed();
|
||||
}
|
||||
|
||||
// NOTE: CloseDownloadWidgetOnFinish is read each time in DownloadWindow
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
GUI::Action& take_full_screenshot_action() { return *m_take_full_screenshot_action; }
|
||||
|
||||
void content_filters_changed();
|
||||
void autoplay_allowlist_changed();
|
||||
void proxy_mappings_changed();
|
||||
|
||||
void broadcast_window_position(Gfx::IntPoint);
|
||||
|
|
|
@ -131,6 +131,8 @@ Tab::Tab(BrowserWindow& window)
|
|||
else
|
||||
m_web_content_view->set_content_filters({});
|
||||
|
||||
autoplay_allowlist_changed();
|
||||
|
||||
m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings);
|
||||
if (!g_webdriver_content_ipc_path.is_empty())
|
||||
enable_webdriver_mode();
|
||||
|
@ -661,6 +663,14 @@ void Tab::content_filters_changed()
|
|||
m_web_content_view->set_content_filters({});
|
||||
}
|
||||
|
||||
void Tab::autoplay_allowlist_changed()
|
||||
{
|
||||
if (g_autoplay_allowed_on_all_websites)
|
||||
m_web_content_view->set_autoplay_allowed_on_all_websites();
|
||||
else
|
||||
m_web_content_view->set_autoplay_allowlist(g_autoplay_allowlist);
|
||||
}
|
||||
|
||||
void Tab::proxy_mappings_changed()
|
||||
{
|
||||
m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings);
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
void did_become_active();
|
||||
void context_menu_requested(Gfx::IntPoint screen_position);
|
||||
void content_filters_changed();
|
||||
void autoplay_allowlist_changed();
|
||||
void proxy_mappings_changed();
|
||||
|
||||
void action_entered(GUI::Action&);
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue