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

Ladybird/SimpleWebView: Install and check for content filters in res/

This allows installed ladybird and Andriod ladybird to find the content
filters without copying all of Base/home/anon into the install tree.
This commit is contained in:
Andrew Kaster 2022-10-03 18:28:31 -06:00
parent 02b3a89d96
commit fb1ca02a74
3 changed files with 23 additions and 2 deletions

View file

@ -435,14 +435,23 @@ static void platform_init()
static ErrorOr<void> load_content_filters() 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 file_or_error = Core::Stream::File::open(String::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::Stream::OpenMode::Read);
if (file_or_error.is_error())
file_or_error = Core::Stream::File::open(String::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::Stream::OpenMode::Read);
if (file_or_error.is_error())
return file_or_error.release_error();
auto file = file_or_error.release_value();
auto ad_filter_list = TRY(Core::Stream::BufferedFile::create(move(file))); auto ad_filter_list = TRY(Core::Stream::BufferedFile::create(move(file)));
auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
size_t num_filters = 0;
while (TRY(ad_filter_list->can_read_line())) { while (TRY(ad_filter_list->can_read_line())) {
auto line = TRY(ad_filter_list->read_line(buffer)); auto line = TRY(ad_filter_list->read_line(buffer));
if (!line.is_empty()) if (!line.is_empty()) {
Web::ContentFilter::the().add_pattern(line); Web::ContentFilter::the().add_pattern(line);
++num_filters;
} }
}
dbgln("Added {} content filters", num_filters);
return {}; return {};
} }

View file

@ -49,6 +49,12 @@ copy_res_folder(emoji)
copy_res_folder(themes) copy_res_folder(themes)
copy_res_folder(color-palettes) copy_res_folder(color-palettes)
copy_res_folder(cursor-themes) copy_res_folder(cursor-themes)
add_custom_target(copy-content-filters
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt"
"asset-bundle/res/ladybird/BrowserContentFilters.txt"
)
add_dependencies(archive-assets copy-content-filters)
add_custom_target(copy-assets COMMAND ${CMAKE_COMMAND} -E copy_if_different ladybird-assets.tar.gz "${CMAKE_SOURCE_DIR}/android/assets") add_custom_target(copy-assets COMMAND ${CMAKE_COMMAND} -E copy_if_different ladybird-assets.tar.gz "${CMAKE_SOURCE_DIR}/android/assets")
add_dependencies(copy-assets archive-assets) add_dependencies(copy-assets archive-assets)
add_dependencies(ladybird copy-assets) add_dependencies(ladybird copy-assets)

View file

@ -73,3 +73,9 @@ install(DIRECTORY
USE_SOURCE_PERMISSIONS MESSAGE_NEVER USE_SOURCE_PERMISSIONS MESSAGE_NEVER
COMPONENT ladybird_Runtime COMPONENT ladybird_Runtime
) )
install(FILES
"${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt"
DESTINATION "${CMAKE_INSTALL_DATADIR}/res/ladybird"
COMPONENT ladybird_Runtime
)