Truly independent web browser
Meta: Find PDF.js in non-vcpkg installations
sideshowbarker8aa5fa172208
diff --git a/Documentation/BuildInstructionsLadybird.md b/Documentation/BuildInstructionsLadybird.mdindex 0f3bd03399a..10c0acab8f6 100644--- a/Documentation/BuildInstructionsLadybird.md+++ b/Documentation/BuildInstructionsLadybird.md@@ -284,6 +284,14 @@ special CMake rules. The expected location of resource files can be tweaked by pthe standard CMAKE_INSTALL_DATADIR variable. CMAKE_INSTALL_DATADIR is expected to be a path relativeto CMAKE_INSTALL_PREFIX. If it is not, things will break.+PDF viewing also requires the PDF.js distribution. The vcpkg port and Flatpak module provide it.+For other builds, use the version pinned in `vcpkg.json` and apply+[`0001-ladybird-embed.patch`](../Meta/CMake/vcpkg/overlay-ports/pdfjs/0001-ladybird-embed.patch).+Install the patched distribution under `<prefix>/share/pdfjs` and add that prefix to `CMAKE_PREFIX_PATH`,+or set `PDFJS_DIR` directly to the directory containing `build/pdf.mjs` and `web/`.+If PDF.js is unavailable, PDF-dependent tests are skipped. Missing decoder files in a build configured+with PDF.js still cause the rendering test to fail.+### Custom CMake build directoryThe script Meta/ladybird.py and the Release preset in CMakePresets.json both define a build directory ofdiff --git a/Meta/CMake/FindPDFJS.cmake b/Meta/CMake/FindPDFJS.cmakenew file mode 100644index 00000000000..35afa199c39--- /dev/null+++ b/Meta/CMake/FindPDFJS.cmake@@ -0,0 +1,14 @@+if (NOT "${VCPKG_INSTALLED_DIR}" STREQUAL "" AND NOT "${VCPKG_TARGET_TRIPLET}" STREQUAL "")+ set(_PDFJS_HINTS "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}")+endif()++find_path(PDFJS_DIR+ NAMES build/pdf.mjs+ HINTS ${_PDFJS_HINTS}+ PATH_SUFFIXES share/pdfjs+ DOC "Path to the Ladybird-patched PDF.js distribution"+)++include(FindPackageHandleStandardArgs)+find_package_handle_standard_args(PDFJS REQUIRED_VARS PDFJS_DIR)+mark_as_advanced(PDFJS_DIR)diff --git a/Meta/CMake/check_for_dependencies.cmake b/Meta/CMake/check_for_dependencies.cmakeindex 636bcf18f4c..c6d079c3f54 100644--- a/Meta/CMake/check_for_dependencies.cmake+++ b/Meta/CMake/check_for_dependencies.cmake@@ -21,6 +21,7 @@ find_package(harfbuzz REQUIRED)find_package(JPEG REQUIRED)find_package(LIBAVIF REQUIRED)find_package(PNG REQUIRED)+find_package(PDFJS QUIET)find_package(WebP REQUIRED)find_path(WUFFS_INCLUDE_DIR NAMES wuffs/wuffs-v0.3.c REQUIRED)diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 2a07e38d127..61bb1a2a942 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -1,3 +1,7 @@+[RequiresPDFJS]+Layout/input/pdf-viewer.pdf+Text/input/PDF/jbig2-image.html+[LoadFromHttpServer]Text/input/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.htmlText/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/diff --git a/Tests/LibWeb/test-web/CMakeLists.txt b/Tests/LibWeb/test-web/CMakeLists.txtindex 0775fe6a021..49e7561859c 100644--- a/Tests/LibWeb/test-web/CMakeLists.txt+++ b/Tests/LibWeb/test-web/CMakeLists.txt@@ -13,6 +13,7 @@ set(SOURCES)add_executable(test-web ${SOURCES})+target_compile_definitions(test-web PRIVATE HAS_PDFJS=$<BOOL:${PDFJS_FOUND}>)add_dependencies(test-web ladybird_build_resource_files ${ladybird_helper_processes})target_link_libraries(test-web PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)diff --git a/Tests/LibWeb/test-web/main.cpp b/Tests/LibWeb/test-web/main.cppindex 7c8d68e9da7..f01ba7ec265 100644--- a/Tests/LibWeb/test-web/main.cpp+++ b/Tests/LibWeb/test-web/main.cpp@@ -141,6 +141,9 @@ static ErrorOr<void> load_test_config(StringView test_root_path)for (auto const& group : config->groups()) {if (group == "Skipped"sv) {TRY(add_config_paths(test_root_path, config->keys(group), s_skipped_tests));+ } else if (group == "RequiresPDFJS"sv) {+ if (!HAS_PDFJS)+ TRY(add_config_paths(test_root_path, config->keys(group), s_skipped_tests));} else if (group == "LoadFromHttpServer"sv) {TRY(add_config_paths(test_root_path, config->keys(group), s_loaded_from_http_server));} else if (group == "CapFrameRate"sv) {diff --git a/UI/cmake/ResourceFiles.cmake b/UI/cmake/ResourceFiles.cmakeindex f4d19cf263e..ee9cf9fe8a3 100644--- a/UI/cmake/ResourceFiles.cmake+++ b/UI/cmake/ResourceFiles.cmake@@ -85,8 +85,7 @@ set(THEMES)list(TRANSFORM THEMES PREPEND "${LADYBIRD_SOURCE_DIR}/Base/res/themes/")-# pdf.js viewer assets installed by the pdfjs vcpkg port.-# Only populated when building with vcpkg and pdfjs is installed.+# PDF.js viewer assets are optional for builds without the PDF.js distribution.set(PDFJS_BUILD_FILES "")set(PDFJS_WEB_BASE_FILES "")set(PDFJS_WEB_IMAGE_FILES "")@@ -94,22 +93,19 @@ set(PDFJS_WEB_WASM_FILES "")set(PDFJS_WEB_LOCALE_JSON "")set(PDFJS_WEB_LOCALE_EN_US "")set(PDFJS_VIEWER_HTML "")-if (NOT "${VCPKG_INSTALLED_DIR}" STREQUAL "" AND NOT "${VCPKG_TARGET_TRIPLET}" STREQUAL "")- set(_pdfjs_vcpkg_dir "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/pdfjs")- if (EXISTS "${_pdfjs_vcpkg_dir}/build/pdf.mjs")- file(GLOB PDFJS_BUILD_FILES "${_pdfjs_vcpkg_dir}/build/*.mjs")- set(_pdfjs_ladybird_dir "${LADYBIRD_SOURCE_DIR}/Base/res/ladybird/pdfjs")- set(PDFJS_WEB_BASE_FILES- "${_pdfjs_ladybird_dir}/pdfjs-ladybird-transport.mjs"- "${_pdfjs_vcpkg_dir}/web/viewer.mjs"- "${_pdfjs_vcpkg_dir}/web/viewer.css"- )- file(GLOB PDFJS_WEB_IMAGE_FILES "${_pdfjs_vcpkg_dir}/web/images/*")- file(GLOB PDFJS_WEB_WASM_FILES "${_pdfjs_vcpkg_dir}/web/wasm/*")- set(PDFJS_WEB_LOCALE_JSON "${_pdfjs_vcpkg_dir}/web/locale/locale.json")- set(PDFJS_WEB_LOCALE_EN_US "${_pdfjs_vcpkg_dir}/web/locale/en-US/viewer.ftl")- set(PDFJS_VIEWER_HTML "${_pdfjs_vcpkg_dir}/web/viewer.html")- endif()+if (PDFJS_FOUND)+ file(GLOB PDFJS_BUILD_FILES "${PDFJS_DIR}/build/*.mjs")+ set(_pdfjs_ladybird_dir "${LADYBIRD_SOURCE_DIR}/Base/res/ladybird/pdfjs")+ set(PDFJS_WEB_BASE_FILES+ "${_pdfjs_ladybird_dir}/pdfjs-ladybird-transport.mjs"+ "${PDFJS_DIR}/web/viewer.mjs"+ "${PDFJS_DIR}/web/viewer.css"+ )+ file(GLOB PDFJS_WEB_IMAGE_FILES "${PDFJS_DIR}/web/images/*")+ file(GLOB PDFJS_WEB_WASM_FILES "${PDFJS_DIR}/web/wasm/*")+ set(PDFJS_WEB_LOCALE_JSON "${PDFJS_DIR}/web/locale/locale.json")+ set(PDFJS_WEB_LOCALE_EN_US "${PDFJS_DIR}/web/locale/en-US/viewer.ftl")+ set(PDFJS_VIEWER_HTML "${PDFJS_DIR}/web/viewer.html")endif()function(copy_resource_set subdir)