mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibWebView+WebContent: Inform WebContent process if browser is headless
This commit is contained in:
parent
520bf6c9be
commit
e764df15eb
Notes:
github-actions[bot]
2024-12-10 18:32:56 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/e764df15eb5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2858 Reviewed-by: https://github.com/trflynn89
9 changed files with 31 additions and 0 deletions
|
@ -407,6 +407,8 @@ public:
|
|||
|
||||
virtual DisplayListPlayerType display_list_player_type() const = 0;
|
||||
|
||||
virtual bool is_headless() const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~PageClient() = default;
|
||||
};
|
||||
|
|
|
@ -82,6 +82,7 @@ public:
|
|||
virtual bool is_ready_to_paint() const override { return true; }
|
||||
|
||||
virtual DisplayListPlayerType display_list_player_type() const override { return m_host_page->client().display_list_player_type(); }
|
||||
virtual bool is_headless() const override { return m_host_page->client().is_headless(); }
|
||||
|
||||
private:
|
||||
explicit SVGPageClient(Page& host_page)
|
||||
|
|
|
@ -108,6 +108,8 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
|||
arguments.append("--force-fontconfig"sv);
|
||||
if (web_content_options.collect_garbage_on_every_allocation == WebView::CollectGarbageOnEveryAllocation::Yes)
|
||||
arguments.append("--collect-garbage-on-every-allocation"sv);
|
||||
if (web_content_options.is_headless == WebView::IsHeadless::Yes)
|
||||
arguments.append("--headless"sv);
|
||||
|
||||
if (auto const maybe_echo_server_port = web_content_options.echo_server_port; maybe_echo_server_port.has_value()) {
|
||||
arguments.append("--echo-server-port"sv);
|
||||
|
|
|
@ -113,6 +113,11 @@ enum class CollectGarbageOnEveryAllocation {
|
|||
Yes,
|
||||
};
|
||||
|
||||
enum class IsHeadless {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
struct WebContentOptions {
|
||||
String command_line;
|
||||
String executable_path;
|
||||
|
@ -128,6 +133,7 @@ struct WebContentOptions {
|
|||
EnableAutoplay enable_autoplay { EnableAutoplay::No };
|
||||
CollectGarbageOnEveryAllocation collect_garbage_on_every_allocation { CollectGarbageOnEveryAllocation::No };
|
||||
Optional<u16> echo_server_port {};
|
||||
IsHeadless is_headless { IsHeadless::No };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
namespace WebContent {
|
||||
|
||||
static PageClient::UseSkiaPainter s_use_skia_painter = PageClient::UseSkiaPainter::GPUBackendIfAvailable;
|
||||
static bool s_is_headless { false };
|
||||
|
||||
GC_DEFINE_ALLOCATOR(PageClient);
|
||||
|
||||
|
@ -40,6 +41,16 @@ void PageClient::set_use_skia_painter(UseSkiaPainter use_skia_painter)
|
|||
s_use_skia_painter = use_skia_painter;
|
||||
}
|
||||
|
||||
bool PageClient::is_headless() const
|
||||
{
|
||||
return s_is_headless;
|
||||
}
|
||||
|
||||
void PageClient::set_is_headless(bool is_headless)
|
||||
{
|
||||
s_is_headless = is_headless;
|
||||
}
|
||||
|
||||
GC::Ref<PageClient> PageClient::create(JS::VM& vm, PageHost& page_host, u64 id)
|
||||
{
|
||||
return vm.heap().allocate<PageClient>(page_host, id);
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
};
|
||||
static void set_use_skia_painter(UseSkiaPainter);
|
||||
|
||||
virtual bool is_headless() const override;
|
||||
static void set_is_headless(bool);
|
||||
|
||||
virtual bool is_ready_to_paint() const override;
|
||||
|
||||
virtual Web::Page& page() override { return *m_page; }
|
||||
|
|
|
@ -107,6 +107,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
bool force_cpu_painting = false;
|
||||
bool force_fontconfig = false;
|
||||
bool collect_garbage_on_every_allocation = false;
|
||||
bool is_headless = false;
|
||||
StringView echo_server_port_string_view {};
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
|
@ -127,6 +128,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
|
||||
args_parser.add_option(collect_garbage_on_every_allocation, "Collect garbage after every JS heap allocation", "collect-garbage-on-every-allocation");
|
||||
args_parser.add_option(echo_server_port_string_view, "Echo server port used in test internals", "echo-server-port", 0, "echo_server_port");
|
||||
args_parser.add_option(is_headless, "Report that the browser is running in headless mode", "headless");
|
||||
|
||||
args_parser.parse(arguments);
|
||||
|
||||
|
@ -152,6 +154,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
// Always use the CPU backend for layout tests, as the GPU backend is not deterministic
|
||||
WebContent::PageClient::set_use_skia_painter(force_cpu_painting ? WebContent::PageClient::UseSkiaPainter::CPUBackend : WebContent::PageClient::UseSkiaPainter::GPUBackendIfAvailable);
|
||||
|
||||
WebContent::PageClient::set_is_headless(is_headless);
|
||||
|
||||
if (enable_http_cache) {
|
||||
Web::Fetch::Fetching::g_http_cache_enabled = true;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
virtual void request_file(Web::FileRequest) override;
|
||||
virtual bool is_ready_to_paint() const override { return true; }
|
||||
virtual Web::DisplayListPlayerType display_list_player_type() const override { VERIFY_NOT_REACHED(); }
|
||||
virtual bool is_headless() const override { VERIFY_NOT_REACHED(); }
|
||||
|
||||
private:
|
||||
explicit PageHost(ConnectionFromClient&);
|
||||
|
|
|
@ -85,6 +85,7 @@ void Application::create_platform_options(WebView::ChromeOptions& chrome_options
|
|||
}
|
||||
|
||||
web_content_options.is_layout_test_mode = is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No;
|
||||
web_content_options.is_headless = WebView::IsHeadless::Yes;
|
||||
}
|
||||
|
||||
ErrorOr<void> Application::launch_test_fixtures()
|
||||
|
|
Loading…
Reference in a new issue