From dc2233ef7aaf194ae171058432afe133cd36a0ef Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Tue, 16 Jan 2024 18:55:40 +0100 Subject: [PATCH] Ladybird+WebContent: Add chrome command line and exe path passing --- Base/res/ladybird/templates/version.html | 9 ++++----- Ladybird/AppKit/main.mm | 4 ++++ Ladybird/HelperProcess.cpp | 4 ++++ Ladybird/Qt/main.cpp | 4 ++++ Ladybird/Types.h | 4 ++++ Ladybird/WebContent/main.cpp | 6 ++++++ .../LibWeb/Loader/GeneratedPagesLoader.cpp | 12 ++++++++++++ .../Libraries/LibWeb/Loader/GeneratedPagesLoader.h | 6 ++++++ Userland/Utilities/headless-browser.cpp | 13 ++++++++++--- 9 files changed, 54 insertions(+), 8 deletions(-) diff --git a/Base/res/ladybird/templates/version.html b/Base/res/ladybird/templates/version.html index 219f102471..b33677fc77 100644 --- a/Base/res/ladybird/templates/version.html +++ b/Base/res/ladybird/templates/version.html @@ -25,7 +25,7 @@ - + @@ -39,15 +39,14 @@ - + +
Version:@browser_version@ @browser_version@
Arch:User Agent: @user_agent@
@executable_path@
diff --git a/Ladybird/AppKit/main.mm b/Ladybird/AppKit/main.mm index 984e17bbff..3d8bc8d44f 100644 --- a/Ladybird/AppKit/main.mm +++ b/Ladybird/AppKit/main.mm @@ -68,7 +68,11 @@ ErrorOr serenity_main(Main::Arguments arguments) if (initial_urls.is_empty()) initial_urls.append(new_tab_page_url); + StringBuilder command_line_builder; + command_line_builder.join(' ', arguments.strings); 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()))), .enable_gpu_painting = use_gpu_painting ? Ladybird::EnableGPUPainting::Yes : Ladybird::EnableGPUPainting::No, .use_lagom_networking = Ladybird::UseLagomNetworking::Yes, .wait_for_debugger = debug_web_content ? Ladybird::WaitForDebugger::Yes : Ladybird::WaitForDebugger::No, diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index 2c055b0d91..e4fa22dc18 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -44,6 +44,10 @@ ErrorOr> launch_web_content_process( "--tool=callgrind"sv, "--instr-atstart=no"sv, path.bytes_as_string_view(), + "--command-line"sv, + web_content_options.command_line, + "--executable-path"sv, + web_content_options.executable_path, "--webcontent-fd-passing-socket"sv, webcontent_fd_passing_socket_string }; diff --git a/Ladybird/Qt/main.cpp b/Ladybird/Qt/main.cpp index 80b5654be4..18134f877c 100644 --- a/Ladybird/Qt/main.cpp +++ b/Ladybird/Qt/main.cpp @@ -143,7 +143,11 @@ ErrorOr serenity_main(Main::Arguments arguments) initial_urls.append(ak_string_from_qstring(new_tab_page)); } + StringBuilder command_line_builder; + command_line_builder.join(' ', arguments.strings); 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()))), .enable_callgrind_profiling = enable_callgrind_profiling ? Ladybird::EnableCallgrindProfiling::Yes : Ladybird::EnableCallgrindProfiling::No, .enable_gpu_painting = use_gpu_painting ? Ladybird::EnableGPUPainting::Yes : Ladybird::EnableGPUPainting::No, .use_lagom_networking = enable_qt_networking ? Ladybird::UseLagomNetworking::No : Ladybird::UseLagomNetworking::Yes, diff --git a/Ladybird/Types.h b/Ladybird/Types.h index 530b3a69fa..03373c245b 100644 --- a/Ladybird/Types.h +++ b/Ladybird/Types.h @@ -6,6 +6,8 @@ #pragma once +#include + namespace Ladybird { enum class EnableCallgrindProfiling { @@ -34,6 +36,8 @@ enum class WaitForDebugger { }; struct WebContentOptions { + String command_line; + String executable_path; EnableCallgrindProfiling enable_callgrind_profiling { EnableCallgrindProfiling::No }; EnableGPUPainting enable_gpu_painting { EnableGPUPainting::No }; IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No }; diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index 76060d6b7b..1eed83da86 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -76,6 +76,8 @@ ErrorOr serenity_main(Main::Arguments arguments) #endif }); + StringView command_line {}; + StringView executable_path {}; int webcontent_fd_passing_socket { -1 }; bool is_layout_test_mode = false; bool use_lagom_networking = false; @@ -83,6 +85,8 @@ ErrorOr serenity_main(Main::Arguments arguments) bool wait_for_debugger = false; 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(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket"); args_parser.add_option(is_layout_test_mode, "Is layout test mode", "layout-test-mode", 0); args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking", 0); @@ -95,6 +99,8 @@ ErrorOr serenity_main(Main::Arguments arguments) Core::Process::wait_for_debugger_and_break(); } + Web::set_chrome_process_command_line(command_line); + Web::set_chrome_process_executable_path(executable_path); if (use_gpu_painting) { WebContent::PageClient::set_use_gpu_painter(); } diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp index 46da0a8f3b..20975b9ea5 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp @@ -16,6 +16,16 @@ namespace Web { +void set_chrome_process_command_line(StringView command_line) +{ + s_chrome_process_command_line = MUST(String::from_utf8(command_line)); +} + +void set_chrome_process_executable_path(StringView executable_path) +{ + s_chrome_process_executable_path = MUST(String::from_utf8(executable_path)); +} + ErrorOr load_error_page(AK::URL const& url) { // Generate HTML error page from error template file @@ -81,6 +91,8 @@ ErrorOr load_about_version_page() generator.set("arch_name", CPU_STRING); generator.set("os_name", OS_STRING); generator.set("user_agent", default_user_agent); + generator.set("command_line", s_chrome_process_command_line); + generator.set("executable_path", s_chrome_process_executable_path); generator.append(template_file->data()); return TRY(String::from_utf8(generator.as_string_view())); } diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h index 0e7153f319..b9235c6126 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h @@ -11,6 +11,12 @@ namespace Web { +static String s_chrome_process_command_line {}; +static String s_chrome_process_executable_path {}; + +void set_chrome_process_command_line(StringView command_line); +void set_chrome_process_executable_path(StringView executable_path); + ErrorOr load_error_page(AK::URL const&); ErrorOr load_file_directory_page(AK::URL const&); diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 2e4783dc08..696eabe5bf 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -62,7 +62,7 @@ static StringView s_current_test_path; class HeadlessWebContentView final : public WebView::ViewImplementation { public: - static ErrorOr> create(Core::AnonymousBuffer theme, Gfx::IntSize const& window_size, StringView web_driver_ipc_path, Ladybird::IsLayoutTestMode is_layout_test_mode = Ladybird::IsLayoutTestMode::No) + static ErrorOr> create(Core::AnonymousBuffer theme, Gfx::IntSize const& window_size, String const& command_line, StringView web_driver_ipc_path, Ladybird::IsLayoutTestMode is_layout_test_mode = Ladybird::IsLayoutTestMode::No) { #if defined(AK_OS_SERENITY) auto database = TRY(WebView::Database::create()); @@ -77,9 +77,14 @@ public: #if defined(AK_OS_SERENITY) view->m_client_state.client = TRY(WebView::WebContentClient::try_create(*view)); + (void)command_line; (void)is_layout_test_mode; #else - Ladybird::WebContentOptions web_content_options { .is_layout_test_mode = is_layout_test_mode }; + Ladybird::WebContentOptions web_content_options { + .command_line = command_line, + .executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))), + .is_layout_test_mode = is_layout_test_mode, + }; auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, web_content_options)); @@ -616,7 +621,9 @@ ErrorOr serenity_main(Main::Arguments arguments) is_layout_test_mode = true; } - auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path, is_layout_test_mode ? Ladybird::IsLayoutTestMode::Yes : Ladybird::IsLayoutTestMode::No)); + StringBuilder command_line_builder; + command_line_builder.join(' ', arguments.strings); + auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, MUST(command_line_builder.to_string()), web_driver_ipc_path, is_layout_test_mode ? Ladybird::IsLayoutTestMode::Yes : Ladybird::IsLayoutTestMode::No)); if (!test_root_path.is_empty()) { return run_tests(*view, test_root_path, dump_failed_ref_tests);