From c361ea8916400d79b296f9010fe29bdd23ba0650 Mon Sep 17 00:00:00 2001 From: rmg-x Date: Thu, 6 Mar 2025 17:54:40 -0600 Subject: [PATCH] WebContent+UI/Qt: Add debug option to toggle content filtering on/off This was needed by @piruzzolo on Discord for debugging purposes and seems pretty useful :^) --- Services/WebContent/ConnectionFromClient.cpp | 5 +++++ UI/Qt/BrowserWindow.cpp | 12 ++++++++++++ UI/Qt/BrowserWindow.h | 1 + UI/Qt/Tab.cpp | 5 +++++ UI/Qt/Tab.h | 1 + 5 files changed, 24 insertions(+) diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index dc1acf9d80d..d68f468c879 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -415,6 +415,11 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString request, ByteSt Web::ResourceLoader::the().set_navigator_compatibility_mode(compatibility_mode); return; } + + if (request == "content-filtering") { + Web::ContentFilter::the().set_filtering_enabled(argument == "on"); + return; + } } void ConnectionFromClient::get_source(u64 page_id) diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp index 140661be07c..45f9e4bc8cc 100644 --- a/UI/Qt/BrowserWindow.cpp +++ b/UI/Qt/BrowserWindow.cpp @@ -569,6 +569,17 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, IsPopupWindow }); }); + m_enable_content_filtering_action = new QAction("Enable Content Filtering", this); + m_enable_content_filtering_action->setCheckable(true); + m_enable_content_filtering_action->setChecked(true); + debug_menu->addAction(m_enable_content_filtering_action); + QObject::connect(m_enable_content_filtering_action, &QAction::triggered, this, [this] { + bool const state = m_enable_content_filtering_action->isChecked(); + for_each_tab([state](auto& tab) { + tab.set_content_filtering(state); + }); + }); + m_block_pop_ups_action = new QAction("Block Pop-ups", this); m_block_pop_ups_action->setCheckable(true); m_block_pop_ups_action->setChecked(WebView::Application::chrome_options().allow_popups == WebView::AllowPopups::No); @@ -828,6 +839,7 @@ void BrowserWindow::initialize_tab(Tab* tab) tab->set_line_box_borders(m_show_line_box_borders_action->isChecked()); tab->set_scripting(m_enable_scripting_action->isChecked()); + tab->set_content_filtering(m_enable_content_filtering_action->isChecked()); tab->set_block_popups(m_block_pop_ups_action->isChecked()); tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked()); tab->set_user_agent_string(user_agent_string()); diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.h index dcad36a4eb6..18602a76311 100644 --- a/UI/Qt/BrowserWindow.h +++ b/UI/Qt/BrowserWindow.h @@ -205,6 +205,7 @@ private: QAction* m_inspect_dom_node_action { nullptr }; QAction* m_show_line_box_borders_action { nullptr }; QAction* m_enable_scripting_action { nullptr }; + QAction* m_enable_content_filtering_action { nullptr }; QAction* m_block_pop_ups_action { nullptr }; QAction* m_enable_same_origin_policy_action { nullptr }; diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp index 876817dfe89..75d5ce7aeb5 100644 --- a/UI/Qt/Tab.cpp +++ b/UI/Qt/Tab.cpp @@ -982,6 +982,11 @@ void Tab::set_scripting(bool enabled) debug_request("scripting", enabled ? "on" : "off"); } +void Tab::set_content_filtering(bool const enabled) +{ + debug_request("content-filtering", enabled ? "on" : "off"); +} + void Tab::set_user_agent_string(ByteString const& user_agent) { debug_request("spoof-user-agent", user_agent); diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.h index f3bf9bfcc93..10154156bf6 100644 --- a/UI/Qt/Tab.h +++ b/UI/Qt/Tab.h @@ -91,6 +91,7 @@ public: void set_line_box_borders(bool); void set_same_origin_policy(bool); void set_scripting(bool); + void set_content_filtering(bool); void set_user_agent_string(ByteString const&); void set_navigator_compatibility_mode(ByteString const&);