summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-17 13:37:36 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-18 16:30:02 +0200
commitfed2606591c457587a4b5d80ce94ee8f70fc8787 (patch)
tree2c4cb210ec1962d2a2955b937f4a1eb68522177d /Userland
parent65283d6879d7c5b4ed063c36d532d70cc3472f80 (diff)
downloadserenity-fed2606591c457587a4b5d80ce94ee8f70fc8787.zip
Browser: Propagate autoplay settings to the WebContent process
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Browser/Browser.h5
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp11
-rw-r--r--Userland/Applications/Browser/BrowserWindow.h1
-rw-r--r--Userland/Applications/Browser/Tab.cpp10
-rw-r--r--Userland/Applications/Browser/Tab.h1
-rw-r--r--Userland/Applications/Browser/main.cpp35
6 files changed, 62 insertions, 1 deletions
diff --git a/Userland/Applications/Browser/Browser.h b/Userland/Applications/Browser/Browser.h
index 417dcbfeaa..b95273a1a7 100644
--- a/Userland/Applications/Browser/Browser.h
+++ b/Userland/Applications/Browser/Browser.h
@@ -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;
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index 5495256728..119814c75f 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -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
diff --git a/Userland/Applications/Browser/BrowserWindow.h b/Userland/Applications/Browser/BrowserWindow.h
index df7c9026dd..0d19d196a6 100644
--- a/Userland/Applications/Browser/BrowserWindow.h
+++ b/Userland/Applications/Browser/BrowserWindow.h
@@ -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);
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp
index 02951e512d..1469ea2500 100644
--- a/Userland/Applications/Browser/Tab.cpp
+++ b/Userland/Applications/Browser/Tab.cpp
@@ -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);
diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h
index ac5db49646..2d99798caa 100644
--- a/Userland/Applications/Browser/Tab.h
+++ b/Userland/Applications/Browser/Tab.h
@@ -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&);
diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp
index 7b92e10d34..0fefc3a807 100644
--- a/Userland/Applications/Browser/main.cpp
+++ b/Userland/Applications/Browser/main.cpp
@@ -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());