2024-06-30 04:24:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
#include <AK/Badge.h>
|
2024-08-28 19:29:51 +00:00
|
|
|
#include <AK/ByteString.h>
|
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
#include <AK/Optional.h>
|
2024-08-18 02:13:54 +00:00
|
|
|
#include <AK/Swift.h>
|
2024-06-30 04:24:01 +00:00
|
|
|
#include <LibCore/EventLoop.h>
|
2024-08-24 16:15:20 +00:00
|
|
|
#include <LibCore/Forward.h>
|
2024-07-30 18:01:05 +00:00
|
|
|
#include <LibMain/Main.h>
|
|
|
|
#include <LibURL/URL.h>
|
|
|
|
#include <LibWebView/Options.h>
|
2024-06-30 04:24:01 +00:00
|
|
|
#include <LibWebView/Process.h>
|
|
|
|
#include <LibWebView/ProcessManager.h>
|
|
|
|
|
|
|
|
namespace WebView {
|
|
|
|
|
|
|
|
class Application {
|
|
|
|
AK_MAKE_NONCOPYABLE(Application);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Application();
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
int execute();
|
2024-06-30 04:24:01 +00:00
|
|
|
|
|
|
|
static Application& the() { return *s_the; }
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
static ChromeOptions const& chrome_options() { return the().m_chrome_options; }
|
|
|
|
static WebContentOptions const& web_content_options() { return the().m_web_content_options; }
|
|
|
|
|
2024-09-05 22:19:51 +00:00
|
|
|
static CookieJar& cookie_jar() { return *the().m_cookie_jar; }
|
|
|
|
|
2024-06-30 04:24:01 +00:00
|
|
|
Core::EventLoop& event_loop() { return m_event_loop; }
|
|
|
|
|
|
|
|
void add_child_process(Process&&);
|
|
|
|
|
|
|
|
// FIXME: Should these methods be part of Application, instead of deferring to ProcessManager?
|
|
|
|
#if defined(AK_OS_MACH)
|
|
|
|
void set_process_mach_port(pid_t, Core::MachPort&&);
|
|
|
|
#endif
|
|
|
|
Optional<Process&> find_process(pid_t);
|
|
|
|
|
|
|
|
// FIXME: Should we just expose the ProcessManager via a getter?
|
|
|
|
void update_process_statistics();
|
|
|
|
String generate_process_statistics_html();
|
|
|
|
|
2024-08-28 19:29:51 +00:00
|
|
|
ErrorOr<LexicalPath> path_for_downloaded_file(StringView file) const;
|
|
|
|
|
2024-06-30 04:24:01 +00:00
|
|
|
protected:
|
2024-07-30 18:01:05 +00:00
|
|
|
template<DerivedFrom<Application> ApplicationType>
|
|
|
|
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments, URL::URL new_tab_page_url)
|
|
|
|
{
|
|
|
|
auto app = adopt_own(*new ApplicationType { {}, arguments });
|
|
|
|
app->initialize(arguments, move(new_tab_page_url));
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
Application();
|
|
|
|
|
2024-06-30 04:24:01 +00:00
|
|
|
virtual void process_did_exit(Process&&);
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
virtual void create_platform_arguments(Core::ArgsParser&) { }
|
|
|
|
virtual void create_platform_options(ChromeOptions&, WebContentOptions&) { }
|
|
|
|
|
2024-08-28 19:29:51 +00:00
|
|
|
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
|
|
|
|
|
2024-06-30 04:24:01 +00:00
|
|
|
private:
|
2024-07-30 18:01:05 +00:00
|
|
|
void initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url);
|
|
|
|
|
2024-06-30 04:24:01 +00:00
|
|
|
static Application* s_the;
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
ChromeOptions m_chrome_options;
|
|
|
|
WebContentOptions m_web_content_options;
|
|
|
|
|
2024-09-05 22:19:51 +00:00
|
|
|
RefPtr<Database> m_database;
|
|
|
|
OwnPtr<CookieJar> m_cookie_jar;
|
|
|
|
|
2024-08-24 16:15:20 +00:00
|
|
|
OwnPtr<Core::TimeZoneWatcher> m_time_zone_watcher;
|
|
|
|
|
2024-06-30 04:24:01 +00:00
|
|
|
Core::EventLoop m_event_loop;
|
|
|
|
ProcessManager m_process_manager;
|
|
|
|
bool m_in_shutdown { false };
|
2024-07-16 11:33:39 +00:00
|
|
|
} SWIFT_IMMORTAL_REFERENCE;
|
2024-06-30 04:24:01 +00:00
|
|
|
|
|
|
|
}
|
2024-07-30 18:01:05 +00:00
|
|
|
|
|
|
|
#define WEB_VIEW_APPLICATION(ApplicationType) \
|
|
|
|
public: \
|
|
|
|
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments, URL::URL new_tab_page_url) \
|
|
|
|
{ \
|
|
|
|
return WebView::Application::create<ApplicationType>(arguments, move(new_tab_page_url)); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
ApplicationType(Badge<WebView::Application>, Main::Arguments&);
|