diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-09-29 17:46:59 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-25 07:58:58 -0700 |
commit | e04ec39984e138c8aa0338631ab66487b0c37fc3 (patch) | |
tree | b9c050f04b4a0a53c35b474abd239d43b6c87bcd | |
parent | f1c7ee28103277828983060f907cd1dd1e8a08bd (diff) | |
download | serenity-e04ec39984e138c8aa0338631ab66487b0c37fc3.zip |
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.
-rw-r--r-- | Ladybird/SimpleWebView.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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 <LibWeb/HTML/Storage.h> #include <LibWeb/HTML/Window.h> #include <LibWeb/Layout/InitialContainingBlock.h> +#include <LibWeb/Loader/ContentFilter.h> #include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Page/Page.h> #include <LibWeb/Painting/PaintableBox.h> @@ -432,6 +433,19 @@ static void platform_init() #endif } +static ErrorOr<void> 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) |