diff options
Diffstat (limited to 'Userland/Applications/Browser/main.cpp')
-rw-r--r-- | Userland/Applications/Browser/main.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 4de1e7faef..64d118264d 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -21,7 +21,6 @@ #include <LibGUI/Icon.h> #include <LibGUI/TabWidget.h> #include <LibMain/Main.h> -#include <stdio.h> #include <unistd.h> namespace Browser { @@ -33,6 +32,26 @@ IconBag g_icon_bag; } +static ErrorOr<void> load_content_filters() +{ + auto file = TRY(Core::Stream::File::open(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::Stream::OpenMode::Read)); + auto ad_filter_list = TRY(Core::Stream::BufferedFile::create(move(file))); + auto maybe_buffer = ByteBuffer::create_uninitialized(4096); + if (maybe_buffer.has_value()) { + auto buffer = maybe_buffer.release_value(); + + while (TRY(ad_filter_list->can_read_line())) { + auto length = TRY(ad_filter_list->read_line(buffer)); + StringView line { buffer.data(), length }; + dbgln("Content filter for {}", line); + if (!line.is_empty()) + Browser::g_content_filters.append(line); + } + } + + return {}; +} + ErrorOr<int> serenity_main(Main::Arguments arguments) { if (getuid() == 0) { @@ -74,16 +93,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) Browser::g_icon_bag = TRY(Browser::IconBag::try_create()); - auto ad_filter_list_or_error = Core::File::open(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::OpenMode::ReadOnly); - if (!ad_filter_list_or_error.is_error()) { - auto& ad_filter_list = *ad_filter_list_or_error.value(); - while (!ad_filter_list.eof()) { - auto line = ad_filter_list.read_line(); - if (line.is_empty()) - continue; - Browser::g_content_filters.append(move(line)); - } - } + TRY(load_content_filters()); URL first_url = Browser::g_home_url; if (specified_url) { |