diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp index 18c744b8f99..10559d20cb3 100644 --- a/Libraries/LibWebView/Application.cpp +++ b/Libraries/LibWebView/Application.cpp @@ -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, diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h index 06645073557..503aa9780cd 100644 --- a/Libraries/LibWebView/Application.h +++ b/Libraries/LibWebView/Application.h @@ -72,9 +72,9 @@ public: protected: template ApplicationType> - static NonnullOwnPtr create(Main::Arguments& arguments) + static NonnullOwnPtr 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 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 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 create(Main::Arguments& arguments) \ - { \ - return WebView::Application::create(arguments); \ - } \ - \ - static ApplicationType& the() \ - { \ - return static_cast(WebView::Application::the()); \ - } \ - \ - ApplicationType(Badge, Main::Arguments&); +#define WEB_VIEW_APPLICATION(ApplicationType) \ +public: \ + static NonnullOwnPtr create(Main::Arguments const& arguments) \ + { \ + return WebView::Application::create(arguments); \ + } \ + \ + static ApplicationType& the() \ + { \ + return static_cast(WebView::Application::the()); \ + } \ + \ + ApplicationType(Badge); diff --git a/Tests/LibWeb/test-web/Application.cpp b/Tests/LibWeb/test-web/Application.cpp index 4b818bc4dde..405fb740971 100644 --- a/Tests/LibWeb/test-web/Application.cpp +++ b/Tests/LibWeb/test-web/Application.cpp @@ -14,7 +14,7 @@ namespace TestWeb { -Application::Application(Badge, Main::Arguments&) +Application::Application(Badge) : test_concurrency(Core::System::hardware_concurrency()) , python_executable_path("python3") { diff --git a/UI/AppKit/Application/Application.mm b/UI/AppKit/Application/Application.mm index 7b6f75c13a1..1a90e5a6e5b 100644 --- a/UI/AppKit/Application/Application.mm +++ b/UI/AppKit/Application/Application.mm @@ -17,7 +17,7 @@ namespace Ladybird { -Application::Application(Badge, Main::Arguments&) +Application::Application(Badge) { } diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp index 7d33858df62..02043589638 100644 --- a/UI/Qt/Application.cpp +++ b/UI/Qt/Application.cpp @@ -16,8 +16,39 @@ namespace Ladybird { -Application::Application(Badge, Main::Arguments& arguments) - : QApplication(arguments.argc, arguments.argv) +class LadybirdQApplication : public QApplication { +public: + explicit LadybirdQApplication(Main::Arguments& arguments) + : QApplication(arguments.argc, arguments.argv) + { + } + + virtual bool event(QEvent* event) override + { + auto& application = static_cast(WebView::Application::the()); + + switch (event->type()) { + case QEvent::FileOpen: { + if (!application.on_open_file) + break; + + auto const& open_event = *static_cast(event); + auto file = ak_string_from_qstring(open_event.file()); + + if (auto file_url = WebView::sanitize_url(file); file_url.has_value()) + application.on_open_file(file_url.release_value()); + break; + } + + default: + break; + } + + return QApplication::event(event); + } +}; + +Application::Application(Badge) { } @@ -30,7 +61,11 @@ void Application::create_platform_options(WebView::BrowserOptions&, WebView::Web NonnullOwnPtr Application::create_platform_event_loop() { - Core::EventLoopManager::install(*new WebView::EventLoopManagerQt); + if (!browser_options().headless_mode.has_value()) { + m_application = make(arguments()); + Core::EventLoopManager::install(*new WebView::EventLoopManagerQt); + } + auto event_loop = WebView::Application::create_platform_event_loop(); if (!browser_options().headless_mode.has_value()) @@ -39,27 +74,6 @@ NonnullOwnPtr Application::create_platform_event_loop() return event_loop; } -bool Application::event(QEvent* event) -{ - switch (event->type()) { - case QEvent::FileOpen: { - if (!on_open_file) - break; - - auto const& open_event = *static_cast(event); - auto file = ak_string_from_qstring(open_event.file()); - - if (auto file_url = WebView::sanitize_url(file); file_url.has_value()) - on_open_file(file_url.release_value()); - break; - } - default: - break; - } - - return QApplication::event(event); -} - BrowserWindow& Application::new_window(Vector const& initial_urls, BrowserWindow::IsPopupWindow is_popup_window, Tab* parent_tab, Optional page_index) { auto* window = new BrowserWindow(initial_urls, is_popup_window, parent_tab, move(page_index)); diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h index 60c306f932b..5fbe4e9b5e4 100644 --- a/UI/Qt/Application.h +++ b/UI/Qt/Application.h @@ -15,17 +15,12 @@ namespace Ladybird { -class Application - : public QApplication - , public WebView::Application { - Q_OBJECT +class Application : public WebView::Application { WEB_VIEW_APPLICATION(Application) public: virtual ~Application() override; - virtual bool event(QEvent* event) override; - Function on_open_file; BrowserWindow& new_window(Vector const& initial_urls, BrowserWindow::IsPopupWindow is_popup_window = BrowserWindow::IsPopupWindow::No, Tab* parent_tab = nullptr, Optional page_index = {}); @@ -39,6 +34,7 @@ private: virtual Optional ask_user_for_download_folder() const override; + OwnPtr m_application; BrowserWindow* m_active_window { nullptr }; };