LibWebView+UI: Do not create a QApplication in headless mode

This is causing errors on the WPT runner, which does not have a display
output. To do this requires shuffling around the Main::Arguments struct,
as we now need access to it from overridden WebView::Application methods
after construction.
This commit is contained in:
Timothy Flynn 2025-06-10 14:56:24 -04:00 committed by Tim Ledbetter
commit fa164083fd
Notes: github-actions[bot] 2025-06-10 22:11:59 +00:00
6 changed files with 64 additions and 49 deletions

View file

@ -85,6 +85,8 @@ Application::~Application()
void Application::initialize(Main::Arguments const& arguments)
{
m_arguments = arguments;
#ifndef AK_OS_WINDOWS
// Increase the open file limit, as the default limits on Linux cause us to run out of file descriptors with around 15 tabs open.
if (auto result = Core::System::set_resource_limits(RLIMIT_NOFILE, 8192); result.is_error())
@ -184,7 +186,7 @@ void Application::initialize(Main::Arguments const& arguments)
});
create_platform_arguments(args_parser);
args_parser.parse(arguments);
args_parser.parse(m_arguments);
// Our persisted SQL storage assumes it runs in a singleton process. If we have multiple UI processes accessing
// the same underlying database, one of them is likely to fail.
@ -235,7 +237,7 @@ void Application::initialize(Main::Arguments const& arguments)
m_browser_options.webdriver_content_ipc_path = *webdriver_content_ipc_path;
m_web_content_options = {
.command_line = MUST(String::join(' ', arguments.strings)),
.command_line = MUST(String::join(' ', m_arguments.strings)),
.executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))),
.user_agent_preset = move(user_agent_preset),
.is_layout_test_mode = layout_test_mode ? IsLayoutTestMode::Yes : IsLayoutTestMode::No,

View file

@ -72,9 +72,9 @@ public:
protected:
template<DerivedFrom<Application> ApplicationType>
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments)
static NonnullOwnPtr<ApplicationType> create(Main::Arguments const& arguments)
{
auto app = adopt_own(*new ApplicationType { {}, arguments });
auto app = adopt_own(*new ApplicationType { {} });
app->initialize(arguments);
return app;
@ -90,6 +90,8 @@ protected:
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
Main::Arguments& arguments() { return m_arguments; }
private:
void initialize(Main::Arguments const& arguments);
@ -134,6 +136,7 @@ private:
Settings m_settings;
OwnPtr<ApplicationSettingsObserver> m_settings_observer;
Main::Arguments m_arguments;
BrowserOptions m_browser_options;
WebContentOptions m_web_content_options;
@ -157,16 +160,16 @@ private:
}
#define WEB_VIEW_APPLICATION(ApplicationType) \
public: \
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments) \
{ \
return WebView::Application::create<ApplicationType>(arguments); \
} \
\
static ApplicationType& the() \
{ \
return static_cast<ApplicationType&>(WebView::Application::the()); \
} \
\
ApplicationType(Badge<WebView::Application>, Main::Arguments&);
#define WEB_VIEW_APPLICATION(ApplicationType) \
public: \
static NonnullOwnPtr<ApplicationType> create(Main::Arguments const& arguments) \
{ \
return WebView::Application::create<ApplicationType>(arguments); \
} \
\
static ApplicationType& the() \
{ \
return static_cast<ApplicationType&>(WebView::Application::the()); \
} \
\
ApplicationType(Badge<WebView::Application>);