1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

Browser+Ladybird+LibWeb: Port content filters to String

This commit is contained in:
Timothy Flynn 2023-04-21 07:54:56 -04:00 committed by Andreas Kling
parent 76ae60da15
commit 5089766af6
11 changed files with 23 additions and 22 deletions

View file

@ -15,7 +15,7 @@ namespace Browser {
extern DeprecatedString g_home_url;
extern DeprecatedString g_new_tab_url;
extern DeprecatedString g_search_engine;
extern Vector<DeprecatedString> g_content_filters;
extern Vector<String> g_content_filters;
extern bool g_content_filters_enabled;
extern Vector<String> g_autoplay_allowlist;
extern bool g_autoplay_allowed_on_all_websites;

View file

@ -126,11 +126,7 @@ Tab::Tab(BrowserWindow& window)
auto preferred_color_scheme = Web::CSS::preferred_color_scheme_from_string(Config::read_string("Browser"sv, "Preferences"sv, "ColorScheme"sv, "auto"sv));
m_web_content_view->set_preferred_color_scheme(preferred_color_scheme);
if (g_content_filters_enabled)
m_web_content_view->set_content_filters(g_content_filters);
else
m_web_content_view->set_content_filters({});
content_filters_changed();
autoplay_allowlist_changed();
m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings);

View file

@ -34,7 +34,7 @@ namespace Browser {
DeprecatedString g_search_engine;
DeprecatedString g_home_url;
DeprecatedString g_new_tab_url;
Vector<DeprecatedString> g_content_filters;
Vector<String> g_content_filters;
bool g_content_filters_enabled { true };
Vector<String> g_autoplay_allowlist;
bool g_autoplay_allowed_on_all_websites { false };
@ -47,7 +47,7 @@ DeprecatedString g_webdriver_content_ipc_path;
static ErrorOr<void> load_content_filters()
{
auto file = TRY(Core::File::open(DeprecatedString::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::File::OpenMode::Read));
auto file = TRY(Core::File::open(TRY(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory())), Core::File::OpenMode::Read));
auto ad_filter_list = TRY(Core::BufferedFile::create(move(file)));
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
@ -55,8 +55,11 @@ static ErrorOr<void> load_content_filters()
while (TRY(ad_filter_list->can_read_line())) {
auto line = TRY(ad_filter_list->read_line(buffer));
if (!line.is_empty())
Browser::g_content_filters.append(line);
if (line.is_empty())
continue;
auto pattern = TRY(String::from_utf8(line));
TRY(Browser::g_content_filters.try_append(move(pattern)));
}
return {};