diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2022-10-03 18:28:31 -0600 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-25 07:58:58 -0700 |
commit | fb1ca02a748dda126d0ed9909411576211cf20df (patch) | |
tree | cf37ef12e46993ce381dbc202dba51482302aff9 /Ladybird | |
parent | 02b3a89d966e8a7ed3ae1616a3c31353b7096d9d (diff) | |
download | serenity-fb1ca02a748dda126d0ed9909411576211cf20df.zip |
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.
Diffstat (limited to 'Ladybird')
-rw-r--r-- | Ladybird/SimpleWebView.cpp | 13 | ||||
-rw-r--r-- | Ladybird/cmake/AndroidExtras.cmake | 6 | ||||
-rw-r--r-- | Ladybird/cmake/InstallRules.cmake | 6 |
3 files changed, 23 insertions, 2 deletions
diff --git a/Ladybird/SimpleWebView.cpp b/Ladybird/SimpleWebView.cpp index 48734faebd..9a41a26683 100644 --- a/Ladybird/SimpleWebView.cpp +++ b/Ladybird/SimpleWebView.cpp @@ -435,14 +435,23 @@ static void platform_init() 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 buffer = TRY(ByteBuffer::create_uninitialized(4096)); + size_t num_filters = 0; while (TRY(ad_filter_list->can_read_line())) { auto line = TRY(ad_filter_list->read_line(buffer)); - if (!line.is_empty()) + if (!line.is_empty()) { Web::ContentFilter::the().add_pattern(line); + ++num_filters; + } } + dbgln("Added {} content filters", num_filters); return {}; } diff --git a/Ladybird/cmake/AndroidExtras.cmake b/Ladybird/cmake/AndroidExtras.cmake index b668d0e18e..923098f424 100644 --- a/Ladybird/cmake/AndroidExtras.cmake +++ b/Ladybird/cmake/AndroidExtras.cmake @@ -49,6 +49,12 @@ copy_res_folder(emoji) copy_res_folder(themes) copy_res_folder(color-palettes) 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_dependencies(copy-assets archive-assets) add_dependencies(ladybird copy-assets) diff --git a/Ladybird/cmake/InstallRules.cmake b/Ladybird/cmake/InstallRules.cmake index 04a222f5be..d2a5932c29 100644 --- a/Ladybird/cmake/InstallRules.cmake +++ b/Ladybird/cmake/InstallRules.cmake @@ -73,3 +73,9 @@ install(DIRECTORY USE_SOURCE_PERMISSIONS MESSAGE_NEVER COMPONENT ladybird_Runtime ) + +install(FILES + "${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt" + DESTINATION "${CMAKE_INSTALL_DATADIR}/res/ladybird" + COMPONENT ladybird_Runtime +) |