From e04ec39984e138c8aa0338631ab66487b0c37fc3 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Thu, 29 Sep 2022 17:46:59 +0100 Subject: [PATCH] Ladybird: Start applying the default content filter For the first cut, the file path is not configurable and the content filter cannot be toggled on or off. If we fail to apply the content filters for any reason (e.g. the filter file doesn't exist), we simply just stop loading the content filters to allow using Ladybird without content filters. --- Ladybird/SimpleWebView.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Ladybird/SimpleWebView.cpp b/Ladybird/SimpleWebView.cpp index 78d87b217b..f1f0a1df5d 100644 --- a/Ladybird/SimpleWebView.cpp +++ b/Ladybird/SimpleWebView.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -432,6 +433,19 @@ static void platform_init() #endif } +static ErrorOr load_content_filters() +{ + auto file = TRY(Core::Stream::File::open(String::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::Stream::OpenMode::Read)); + auto ad_filter_list = TRY(Core::Stream::BufferedFile::create(move(file))); + auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); + while (TRY(ad_filter_list->can_read_line())) { + auto line = TRY(ad_filter_list->read_line(buffer)); + if (!line.is_empty()) + Web::ContentFilter::the().add_pattern(line); + } + return {}; +} + void initialize_web_engine() { platform_init(); @@ -447,6 +461,10 @@ void initialize_web_engine() Web::Platform::FontPlugin::install(*new Ladybird::FontPluginQt); Web::FrameLoader::set_error_page_url(String::formatted("file://{}/res/html/error.html", s_serenity_resource_root)); + + auto maybe_content_filter_error = load_content_filters(); + if (maybe_content_filter_error.is_error()) + dbgln("Failed to load content filters: {}", maybe_content_filter_error.error()); } void SimpleWebView::debug_request(String const& request, String const& argument)