diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index 754fb20b8d2..5656b210aa5 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -80,6 +80,10 @@ ErrorOr> launch_web_content_process( web_content_options.executable_path.to_byte_string(), }; + if (web_content_options.config_path.has_value()) { + arguments.append("--config-path"sv); + arguments.append(web_content_options.config_path.value()); + } if (web_content_options.is_layout_test_mode == Ladybird::IsLayoutTestMode::Yes) arguments.append("--layout-test-mode"sv); if (web_content_options.use_lagom_networking == Ladybird::UseLagomNetworking::Yes) diff --git a/Ladybird/Qt/main.cpp b/Ladybird/Qt/main.cpp index a9c4d9648cd..a85969185ea 100644 --- a/Ladybird/Qt/main.cpp +++ b/Ladybird/Qt/main.cpp @@ -175,6 +175,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Ladybird::WebContentOptions web_content_options { .command_line = MUST(command_line_builder.to_string()), .executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))), + .config_path = Ladybird::Settings::the()->directory(), .enable_callgrind_profiling = enable_callgrind_profiling ? Ladybird::EnableCallgrindProfiling::Yes : Ladybird::EnableCallgrindProfiling::No, .enable_skia_painting = use_skia_painting ? Ladybird::EnableSkiaPainting::Yes : Ladybird::EnableSkiaPainting::No, .use_lagom_networking = enable_qt_networking ? Ladybird::UseLagomNetworking::No : Ladybird::UseLagomNetworking::Yes, diff --git a/Ladybird/Types.h b/Ladybird/Types.h index a99fc63bdcc..8aff64c9ff2 100644 --- a/Ladybird/Types.h +++ b/Ladybird/Types.h @@ -58,6 +58,7 @@ enum class ExposeInternalsObject { struct WebContentOptions { String command_line; String executable_path; + Optional config_path {}; EnableCallgrindProfiling enable_callgrind_profiling { EnableCallgrindProfiling::No }; EnableSkiaPainting enable_skia_painting { EnableSkiaPainting::No }; IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No }; diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index cd25d3a582a..ef9bff248da 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -46,8 +46,8 @@ # include #endif -static ErrorOr load_content_filters(); -static ErrorOr load_autoplay_allowlist(); +static ErrorOr load_content_filters(StringView config_path); +static ErrorOr load_autoplay_allowlist(StringView config_path); static ErrorOr initialize_lagom_networking(int request_server_socket); static ErrorOr initialize_image_decoder(int image_decoder_socket); static ErrorOr reinitialize_image_decoder(IPC::File const& image_decoder_socket); @@ -92,6 +92,7 @@ ErrorOr serenity_main(Main::Arguments arguments) StringView command_line {}; StringView executable_path {}; + auto config_path = ByteString::formatted("{}/ladybird/default-config", s_serenity_resource_root); StringView mach_server_name {}; Vector certificates; int request_server_socket { -1 }; @@ -108,6 +109,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Core::ArgsParser args_parser; args_parser.add_option(command_line, "Chrome process command line", "command-line", 0, "command_line"); args_parser.add_option(executable_path, "Chrome process executable path", "executable-path", 0, "executable_path"); + args_parser.add_option(config_path, "Ladybird configuration path", "config-path", 0, "config_path"); args_parser.add_option(request_server_socket, "File descriptor of the socket for the RequestServer connection", "request-server-socket", 'r', "request_server_socket"); args_parser.add_option(image_decoder_socket, "File descriptor of the socket for the ImageDecoder connection", "image-decoder-socket", 'i', "image_decoder_socket"); args_parser.add_option(is_layout_test_mode, "Is layout test mode", "layout-test-mode"); @@ -173,11 +175,11 @@ ErrorOr serenity_main(Main::Arguments arguments) Web::WebIDL::g_enable_idl_tracing = true; } - auto maybe_content_filter_error = load_content_filters(); + auto maybe_content_filter_error = load_content_filters(config_path); if (maybe_content_filter_error.is_error()) dbgln("Failed to load content filters: {}", maybe_content_filter_error.error()); - auto maybe_autoplay_allowlist_error = load_autoplay_allowlist(); + auto maybe_autoplay_allowlist_error = load_autoplay_allowlist(config_path); if (maybe_autoplay_allowlist_error.is_error()) dbgln("Failed to load autoplay allowlist: {}", maybe_autoplay_allowlist_error.error()); @@ -193,12 +195,12 @@ ErrorOr serenity_main(Main::Arguments arguments) return event_loop.exec(); } -static ErrorOr load_content_filters() +static ErrorOr load_content_filters(StringView config_path) { auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); - auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/default-config/BrowserContentFilters.txt"sv)); - auto ad_filter_list = TRY(InputBufferedSeekable::create(make(resource->data()))); + auto file = TRY(Core::File::open(ByteString::formatted("{}/BrowserContentFilters.txt", config_path), Core::File::OpenMode::Read)); + auto ad_filter_list = TRY(Core::InputBufferedFile::create(move(file))); Vector patterns; @@ -217,12 +219,12 @@ static ErrorOr load_content_filters() return {}; } -static ErrorOr load_autoplay_allowlist() +static ErrorOr load_autoplay_allowlist(StringView config_path) { auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); - auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/default-config/BrowserAutoplayAllowlist.txt"sv)); - auto allowlist = TRY(InputBufferedSeekable::create(make(resource->data()))); + auto file = TRY(Core::File::open(ByteString::formatted("{}/BrowserAutoplayAllowlist.txt", config_path), Core::File::OpenMode::Read)); + auto allowlist = TRY(Core::InputBufferedFile::create(move(file))); Vector origins;