mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:57:45 +00:00
Browser: Add support for disabling content filtering
Just for completeness.
This commit is contained in:
parent
43e463748d
commit
4d1c28a23f
5 changed files with 26 additions and 6 deletions
|
@ -14,6 +14,7 @@ namespace Browser {
|
||||||
extern String g_home_url;
|
extern String g_home_url;
|
||||||
extern String g_search_engine;
|
extern String g_search_engine;
|
||||||
extern Vector<String> g_content_filters;
|
extern Vector<String> g_content_filters;
|
||||||
|
extern bool g_content_filters_enabled;
|
||||||
extern IconBag g_icon_bag;
|
extern IconBag g_icon_bag;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -526,6 +526,14 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
m_tab_widget->set_active_widget(&new_tab);
|
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)
|
void BrowserWindow::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
|
||||||
{
|
{
|
||||||
if (domain != "Browser" || group != "Preferences")
|
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)
|
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")
|
if (domain != "Browser" || group != "Preferences")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (key == "ShowBookmarksBar") {
|
if (key == "ShowBookmarksBar") {
|
||||||
m_window_actions.show_bookmarks_bar_action().set_checked(value);
|
m_window_actions.show_bookmarks_bar_action().set_checked(value);
|
||||||
Browser::BookmarksBarWidget::the().set_visible(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
|
// NOTE: CloseDownloadWidgetOnFinish is read each time in DownloadWindow
|
||||||
|
|
|
@ -40,6 +40,8 @@ public:
|
||||||
GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; }
|
GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; }
|
||||||
GUI::Action& inspect_dom_node_action() { return *m_inspect_dom_node_action; }
|
GUI::Action& inspect_dom_node_action() { return *m_inspect_dom_node_action; }
|
||||||
|
|
||||||
|
void content_filters_changed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit BrowserWindow(CookieJar&, URL);
|
explicit BrowserWindow(CookieJar&, URL);
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,10 @@ Tab::Tab(BrowserWindow& window)
|
||||||
auto& webview_container = *find_descendant_of_type_named<GUI::Widget>("webview_container");
|
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 = 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());
|
auto& go_back_button = toolbar.add_action(window.go_back_action());
|
||||||
go_back_button.on_context_menu_request = [this](auto& context_menu_event) {
|
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()
|
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()
|
GUI::AbstractScrollableWidget& Tab::view()
|
||||||
|
|
|
@ -30,6 +30,7 @@ namespace Browser {
|
||||||
String g_search_engine;
|
String g_search_engine;
|
||||||
String g_home_url;
|
String g_home_url;
|
||||||
Vector<String> g_content_filters;
|
Vector<String> g_content_filters;
|
||||||
|
bool g_content_filters_enabled { true };
|
||||||
IconBag g_icon_bag;
|
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_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_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());
|
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());
|
dbgln("Reloading content filters failed: {}", error.release_error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window->tab_widget().for_each_child_of_type<Browser::Tab>([](auto& tab) {
|
window->content_filters_changed();
|
||||||
tab.content_filters_changed();
|
|
||||||
return IterationDecision::Continue;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
TRY(content_filters_watcher->add_watch(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::FileWatcherEvent::Type::ContentModified));
|
TRY(content_filters_watcher->add_watch(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::FileWatcherEvent::Type::ContentModified));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue