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

View file

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

View file

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

View file

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

View file

@ -17,9 +17,7 @@
namespace Ladybird {
Application::Application(Badge<WebView::Application>)
{
}
Application::Application() = default;
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;
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; }
private:
explicit Application();
virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override;
virtual NonnullOwnPtr<Core::EventLoop> create_platform_event_loop() override;