summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej <sppmacd@pm.me>2022-02-01 11:17:37 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-18 19:00:42 +0100
commit4d1c28a23f71f92690a99455e213389519eb143a (patch)
tree88467711e2a49d49c870e2c55ede9f1d68497787
parent43e463748d0a6503db3966c1daa385b14884f527 (diff)
downloadserenity-4d1c28a23f71f92690a99455e213389519eb143a.zip
Browser: Add support for disabling content filtering
Just for completeness.
-rw-r--r--Userland/Applications/Browser/Browser.h1
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp12
-rw-r--r--Userland/Applications/Browser/BrowserWindow.h2
-rw-r--r--Userland/Applications/Browser/Tab.cpp10
-rw-r--r--Userland/Applications/Browser/main.cpp7
5 files changed, 26 insertions, 6 deletions
diff --git a/Userland/Applications/Browser/Browser.h b/Userland/Applications/Browser/Browser.h
index db773c58f2..fccb78d47b 100644
--- a/Userland/Applications/Browser/Browser.h
+++ b/Userland/Applications/Browser/Browser.h
@@ -14,6 +14,7 @@ namespace Browser {
extern String g_home_url;
extern String g_search_engine;
extern Vector<String> g_content_filters;
+extern bool g_content_filters_enabled;
extern IconBag g_icon_bag;
}
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index 943703ac3a..9589ca6658 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -526,6 +526,14 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
m_tab_widget->set_active_widget(&new_tab);
}
+void BrowserWindow::content_filters_changed()
+{
+ tab_widget().for_each_child_of_type<Browser::Tab>([](auto& tab) {
+ tab.content_filters_changed();
+ return IterationDecision::Continue;
+ });
+}
+
void BrowserWindow::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
{
if (domain != "Browser" || group != "Preferences")
@@ -541,12 +549,16 @@ void BrowserWindow::config_string_did_change(String const& domain, String const&
void BrowserWindow::config_bool_did_change(String const& domain, String const& group, String const& key, bool value)
{
+ dbgln("{} {} {} {}", domain, group, key, value);
if (domain != "Browser" || group != "Preferences")
return;
if (key == "ShowBookmarksBar") {
m_window_actions.show_bookmarks_bar_action().set_checked(value);
Browser::BookmarksBarWidget::the().set_visible(value);
+ } else if (key == "EnableContentFilters") {
+ Browser::g_content_filters_enabled = value;
+ content_filters_changed();
}
// NOTE: CloseDownloadWidgetOnFinish is read each time in DownloadWindow
diff --git a/Userland/Applications/Browser/BrowserWindow.h b/Userland/Applications/Browser/BrowserWindow.h
index a4c68d5e3b..88e4496349 100644
--- a/Userland/Applications/Browser/BrowserWindow.h
+++ b/Userland/Applications/Browser/BrowserWindow.h
@@ -40,6 +40,8 @@ public:
GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; }
GUI::Action& inspect_dom_node_action() { return *m_inspect_dom_node_action; }
+ void content_filters_changed();
+
private:
explicit BrowserWindow(CookieJar&, URL);
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp
index b31120fec6..97ba5b10df 100644
--- a/Userland/Applications/Browser/Tab.cpp
+++ b/Userland/Applications/Browser/Tab.cpp
@@ -89,7 +89,10 @@ Tab::Tab(BrowserWindow& window)
auto& webview_container = *find_descendant_of_type_named<GUI::Widget>("webview_container");
m_web_content_view = webview_container.add<Web::OutOfProcessWebView>();
- m_web_content_view->set_content_filters(g_content_filters);
+ if (g_content_filters_enabled)
+ m_web_content_view->set_content_filters(g_content_filters);
+ else
+ m_web_content_view->set_content_filters({});
auto& go_back_button = toolbar.add_action(window.go_back_action());
go_back_button.on_context_menu_request = [this](auto& context_menu_event) {
@@ -444,7 +447,10 @@ void Tab::context_menu_requested(const Gfx::IntPoint& screen_position)
void Tab::content_filters_changed()
{
- m_web_content_view->set_content_filters(g_content_filters);
+ if (g_content_filters_enabled)
+ m_web_content_view->set_content_filters(g_content_filters);
+ else
+ m_web_content_view->set_content_filters({});
}
GUI::AbstractScrollableWidget& Tab::view()
diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp
index 016bb0c584..4048580bab 100644
--- a/Userland/Applications/Browser/main.cpp
+++ b/Userland/Applications/Browser/main.cpp
@@ -30,6 +30,7 @@ namespace Browser {
String g_search_engine;
String g_home_url;
Vector<String> g_content_filters;
+bool g_content_filters_enabled { true };
IconBag g_icon_bag;
}
@@ -88,6 +89,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Browser::g_home_url = Config::read_string("Browser", "Preferences", "Home", "file:///res/html/misc/welcome.html");
Browser::g_search_engine = Config::read_string("Browser", "Preferences", "SearchEngine", {});
+ Browser::g_content_filters_enabled = Config::read_bool("Browser", "Preferences", "EnableContentFilters");
Browser::g_icon_bag = TRY(Browser::IconBag::try_create());
@@ -113,10 +115,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
dbgln("Reloading content filters failed: {}", error.release_error());
return;
}
- window->tab_widget().for_each_child_of_type<Browser::Tab>([](auto& tab) {
- tab.content_filters_changed();
- return IterationDecision::Continue;
- });
+ window->content_filters_changed();
};
TRY(content_filters_watcher->add_watch(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::FileWatcherEvent::Type::ContentModified));