Browser: Add support for disabling content filtering

Just for completeness.
This commit is contained in:
Maciej 2022-02-01 11:17:37 +01:00 committed by Andreas Kling
parent 43e463748d
commit 4d1c28a23f
Notes: sideshowbarker 2024-07-17 18:35:03 +09:00
5 changed files with 26 additions and 6 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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);

View file

@ -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()

View file

@ -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));