diff --git a/Ladybird/Android/src/main/cpp/RequestServerService.cpp b/Ladybird/Android/src/main/cpp/RequestServerService.cpp index d815b4b1086..b3e11f8ed41 100644 --- a/Ladybird/Android/src/main/cpp/RequestServerService.cpp +++ b/Ladybird/Android/src/main/cpp/RequestServerService.cpp @@ -23,14 +23,9 @@ // FIXME: Share b/w RequestServer and WebSocket ErrorOr find_certificates(StringView serenity_resource_root) { - auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root); - if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); - - cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()); - if (!FileSystem::exists(cert_path)) - return Error::from_string_view("Don't know how to load certs!"sv); - } + auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root); + if (!FileSystem::exists(cert_path)) + return Error::from_string_view("Don't know how to load certs!"sv); return cert_path; } diff --git a/Ladybird/Android/src/main/cpp/WebSocketService.cpp b/Ladybird/Android/src/main/cpp/WebSocketService.cpp index 561dd768dd9..aab7df7dd31 100644 --- a/Ladybird/Android/src/main/cpp/WebSocketService.cpp +++ b/Ladybird/Android/src/main/cpp/WebSocketService.cpp @@ -19,14 +19,9 @@ // FIXME: Share b/w RequestServer and WebSocket ErrorOr find_certificates(StringView serenity_resource_root) { - auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root); - if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); - - cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()); - if (!FileSystem::exists(cert_path)) - return Error::from_string_view("Don't know how to load certs!"sv); - } + auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root); + if (!FileSystem::exists(cert_path)) + return Error::from_string_view("Don't know how to load certs!"sv); return cert_path; } diff --git a/Ladybird/RequestServer/main.cpp b/Ladybird/RequestServer/main.cpp index ab71fac878b..6f1a834dc23 100644 --- a/Ladybird/RequestServer/main.cpp +++ b/Ladybird/RequestServer/main.cpp @@ -23,14 +23,9 @@ // FIXME: Share b/w RequestServer and WebSocket ErrorOr find_certificates(StringView serenity_resource_root) { - auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root); - if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); - - cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()); - if (!FileSystem::exists(cert_path)) - return Error::from_string_view("Don't know how to load certs!"sv); - } + auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root); + if (!FileSystem::exists(cert_path)) + return Error::from_string_view("Don't know how to load certs!"sv); return cert_path; } diff --git a/Ladybird/Utilities.cpp b/Ladybird/Utilities.cpp index dc0423c7981..eb78a414dd6 100644 --- a/Ladybird/Utilities.cpp +++ b/Ladybird/Utilities.cpp @@ -23,10 +23,6 @@ ErrorOr application_directory() void platform_init() { s_serenity_resource_root = [] { - auto const* source_dir = getenv("SERENITY_SOURCE_DIR"); - if (source_dir) { - return ByteString::formatted("{}/Base", source_dir); - } auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME"); VERIFY(home); auto home_lagom = ByteString::formatted("{}/.lagom", home); @@ -36,11 +32,11 @@ void platform_init() #ifdef AK_OS_MACOS return LexicalPath(app_dir).parent().append("Resources"sv).string(); #else - return LexicalPath(app_dir).parent().append("share"sv).string(); + return LexicalPath(app_dir).parent().append("share/Lagom"sv).string(); #endif }(); - Core::ResourceImplementation::install(make(MUST(String::formatted("{}/res", s_serenity_resource_root)))); + Core::ResourceImplementation::install(make(MUST(String::from_byte_string(s_serenity_resource_root)))); } ErrorOr> get_paths_for_helper_process(StringView process_name) diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index ec881fcdb43..b4b3fad8840 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -142,16 +143,11 @@ ErrorOr serenity_main(Main::Arguments arguments) static ErrorOr load_content_filters() { - auto file_or_error = Core::File::open(ByteString::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read); - if (file_or_error.is_error()) - file_or_error = Core::File::open(ByteString::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::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::InputBufferedFile::create(move(file))); auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); + auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/BrowserContentFilters.txt"sv)); + auto ad_filter_list = TRY(InputBufferedSeekable::create(make(resource->data()))); + Vector patterns; while (TRY(ad_filter_list->can_read_line())) { @@ -171,16 +167,11 @@ static ErrorOr load_content_filters() static ErrorOr load_autoplay_allowlist() { - auto file_or_error = Core::File::open(TRY(String::formatted("{}/home/anon/.config/BrowserAutoplayAllowlist.txt", s_serenity_resource_root)), Core::File::OpenMode::Read); - if (file_or_error.is_error()) - file_or_error = Core::File::open(TRY(String::formatted("{}/res/ladybird/BrowserAutoplayAllowlist.txt", s_serenity_resource_root)), Core::File::OpenMode::Read); - if (file_or_error.is_error()) - return file_or_error.release_error(); - - auto file = file_or_error.release_value(); - auto allowlist = TRY(Core::InputBufferedFile::create(move(file))); auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); + auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/BrowserAutoplayAllowlist.txt"sv)); + auto allowlist = TRY(InputBufferedSeekable::create(make(resource->data()))); + Vector origins; while (TRY(allowlist->can_read_line())) { diff --git a/Ladybird/WebSocket/main.cpp b/Ladybird/WebSocket/main.cpp index bb7046ebd60..632865b55b8 100644 --- a/Ladybird/WebSocket/main.cpp +++ b/Ladybird/WebSocket/main.cpp @@ -19,14 +19,9 @@ // FIXME: Share b/w RequestServer and WebSocket ErrorOr find_certificates(StringView serenity_resource_root) { - auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root); - if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); - - cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()); - if (!FileSystem::exists(cert_path)) - return Error::from_string_view("Don't know how to load certs!"sv); - } + auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root); + if (!FileSystem::exists(cert_path)) + return Error::from_string_view("Don't know how to load certs!"sv); return cert_path; } diff --git a/Ladybird/cmake/InstallRules.cmake b/Ladybird/cmake/InstallRules.cmake index 1903adbd757..35017f7071c 100644 --- a/Ladybird/cmake/InstallRules.cmake +++ b/Ladybird/cmake/InstallRules.cmake @@ -2,7 +2,7 @@ include(CMakePackageConfigHelpers) include(GNUInstallDirs) -set(package ladybird) +set(package Ladybird) set(ladybird_applications ladybird ${ladybird_helper_processes}) @@ -94,42 +94,21 @@ install( COMPONENT ladybird_Development ) -install(DIRECTORY - "${SERENITY_SOURCE_DIR}/Base/res/fonts" - "${SERENITY_SOURCE_DIR}/Base/res/icons" - "${SERENITY_SOURCE_DIR}/Base/res/ladybird" - "${SERENITY_SOURCE_DIR}/Base/res/themes" - "${SERENITY_SOURCE_DIR}/Base/res/color-palettes" - "${SERENITY_SOURCE_DIR}/Base/res/cursor-themes" - DESTINATION "${CMAKE_INSTALL_DATADIR}/res" - USE_SOURCE_PERMISSIONS MESSAGE_NEVER - COMPONENT ladybird_Runtime -) - -install(FILES - "${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserAutoplayAllowlist.txt" - "${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt" - "${Lagom_BINARY_DIR}/cacert.pem" - DESTINATION "${CMAKE_INSTALL_DATADIR}/res/ladybird" - COMPONENT ladybird_Runtime -) +if (NOT APPLE) + # On macOS the resources are handled via the MACOSX_PACKAGE_LOCATION property on each resource file + install_ladybird_resources("${CMAKE_INSTALL_DATADIR}/Lagom" ladybird_Runtime) +endif() if (APPLE) # Fixup the app bundle and copy: # - Libraries from lib/ to Ladybird.app/Contents/lib - # - Resources from share/res/ to Ladybird.app/Contents/Resources/res install(CODE " - set(res_dir \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/res) - if (IS_ABSOLUTE ${CMAKE_INSTALL_DATADIR}) - set(res_dir ${CMAKE_INSTALL_DATADIR}/res) - endif() set(lib_dir \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) if (IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) set(lib_dir ${CMAKE_INSTALL_LIBDIR}) endif() set(contents_dir \${CMAKE_INSTALL_PREFIX}/bundle/Ladybird.app/Contents) - file(COPY \${res_dir} DESTINATION \${contents_dir}/Resources) file(COPY \${lib_dir} DESTINATION \${contents_dir}) " COMPONENT ladybird_Runtime) diff --git a/Ladybird/cmake/ResourceFiles.cmake b/Ladybird/cmake/ResourceFiles.cmake index a13fff7eddb..d627818d4fb 100644 --- a/Ladybird/cmake/ResourceFiles.cmake +++ b/Ladybird/cmake/ResourceFiles.cmake @@ -163,3 +163,15 @@ function(copy_resources_to_build base_directory bundle_target) add_dependencies(${bundle_target} "${bundle_target}_build_resource_files") endfunction() + +function(install_ladybird_resources destination component) + install(FILES ${FONTS} DESTINATION "${destination}/fonts" COMPONENT ${component}) + install(FILES ${16x16_ICONS} DESTINATION "${destination}/icons/16x16" COMPONENT ${component}) + install(FILES ${32x32_ICONS} DESTINATION "${destination}/icons/32x32" COMPONENT ${component}) + install(FILES ${BROWSER_ICONS} DESTINATION "${destination}/icons/browser" COMPONENT ${component}) + install(FILES ${THEMES} DESTINATION "${destination}/themes" COMPONENT ${component}) + install(FILES ${WEB_RESOURCES} DESTINATION "${destination}/ladybird" COMPONENT ${component}) + install(FILES ${WEB_TEMPLATES} DESTINATION "${destination}/ladybird/templates" COMPONENT ${component}) + install(FILES ${CONFIG_RESOURCES} DESTINATION "${destination}/ladybird" COMPONENT ${component}) + install(FILES ${DOWNLOADED_RESOURCES} DESTINATION "${destination}/ladybird" COMPONENT ${component}) +endfunction()