LibWebView+UI: Don't declare a magic ctor for Application subclasses

You would have to just know that you need to define the constructor with
this declaration. Let's allow subclasses to define constructors as they
see fit.
This commit is contained in:
Timothy Flynn 2025-06-10 19:13:03 -04:00 committed by Tim Flynn
commit b425ce93b1
Notes: github-actions[bot] 2025-06-11 11:27:40 +00:00
7 changed files with 24 additions and 33 deletions

View file

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <AK/Badge.h>
#include <AK/ByteString.h> #include <AK/ByteString.h>
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/Optional.h> #include <AK/Optional.h>
@ -71,17 +70,10 @@ public:
void refresh_tab_list(); void refresh_tab_list();
protected: protected:
template<DerivedFrom<Application> ApplicationType>
static NonnullOwnPtr<ApplicationType> create(Main::Arguments const& arguments)
{
auto app = adopt_own(*new ApplicationType { {} });
app->initialize(arguments);
return app;
}
Application(); Application();
void initialize(Main::Arguments const&);
virtual void process_did_exit(Process&&); virtual void process_did_exit(Process&&);
virtual void create_platform_arguments(Core::ArgsParser&) { } virtual void create_platform_arguments(Core::ArgsParser&) { }
@ -93,8 +85,6 @@ protected:
Main::Arguments& arguments() { return m_arguments; } Main::Arguments& arguments() { return m_arguments; }
private: private:
void initialize(Main::Arguments const& arguments);
void launch_spare_web_content_process(); void launch_spare_web_content_process();
ErrorOr<void> launch_request_server(); ErrorOr<void> launch_request_server();
ErrorOr<void> launch_image_decoder_server(); ErrorOr<void> launch_image_decoder_server();
@ -162,14 +152,15 @@ private:
#define WEB_VIEW_APPLICATION(ApplicationType) \ #define WEB_VIEW_APPLICATION(ApplicationType) \
public: \ public: \
static NonnullOwnPtr<ApplicationType> create(Main::Arguments const& arguments) \ template<typename... ApplicationArguments> \
static NonnullOwnPtr<ApplicationType> create(Main::Arguments const& arguments, ApplicationArguments&&... application_arguments) \
{ \ { \
return WebView::Application::create<ApplicationType>(arguments); \ auto app = adopt_own(*new ApplicationType { forward<ApplicationArguments>(application_arguments)... }); \
app->initialize(arguments); \
return app; \
} \ } \
\ \
static ApplicationType& the() \ static ApplicationType& the() \
{ \ { \
return static_cast<ApplicationType&>(WebView::Application::the()); \ return static_cast<ApplicationType&>(WebView::Application::the()); \
} \ }
\
ApplicationType(Badge<WebView::Application>);

View file

@ -14,7 +14,7 @@
namespace TestWeb { namespace TestWeb {
Application::Application(Badge<WebView::Application>) Application::Application()
: test_concurrency(Core::System::hardware_concurrency()) : test_concurrency(Core::System::hardware_concurrency())
, python_executable_path("python3") , python_executable_path("python3")
{ {

View file

@ -17,6 +17,7 @@ class Application : public WebView::Application {
WEB_VIEW_APPLICATION(Application) WEB_VIEW_APPLICATION(Application)
public: public:
explicit Application();
~Application(); ~Application();
virtual void create_platform_arguments(Core::ArgsParser&) override; virtual void create_platform_arguments(Core::ArgsParser&) override;

View file

@ -16,6 +16,8 @@ class Application final : public WebView::Application {
WEB_VIEW_APPLICATION(Application) WEB_VIEW_APPLICATION(Application)
private: private:
explicit Application();
virtual Optional<ByteString> ask_user_for_download_folder() const override; virtual Optional<ByteString> ask_user_for_download_folder() const override;
virtual NonnullOwnPtr<Core::EventLoop> create_platform_event_loop() override; virtual NonnullOwnPtr<Core::EventLoop> create_platform_event_loop() override;
}; };

View file

@ -17,9 +17,7 @@
namespace Ladybird { namespace Ladybird {
Application::Application(Badge<WebView::Application>) Application::Application() = default;
{
}
Optional<ByteString> Application::ask_user_for_download_folder() const Optional<ByteString> Application::ask_user_for_download_folder() const
{ {

View file

@ -48,10 +48,7 @@ public:
} }
}; };
Application::Application(Badge<WebView::Application>) Application::Application() = default;
{
}
Application::~Application() = default; Application::~Application() = default;
void Application::create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions& web_content_options) void Application::create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions& web_content_options)

View file

@ -29,6 +29,8 @@ public:
void set_active_window(BrowserWindow& w) { m_active_window = &w; } void set_active_window(BrowserWindow& w) { m_active_window = &w; }
private: private:
explicit Application();
virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override; virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override;
virtual NonnullOwnPtr<Core::EventLoop> create_platform_event_loop() override; virtual NonnullOwnPtr<Core::EventLoop> create_platform_event_loop() override;