2024-06-29 22:24:01 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-08-28 15:29:51 -04:00
|
|
|
#include <AK/ByteString.h>
|
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
#include <AK/Optional.h>
|
2024-08-17 20:13:54 -06:00
|
|
|
#include <AK/Swift.h>
|
2024-06-29 22:24:01 -06:00
|
|
|
#include <LibCore/EventLoop.h>
|
2024-08-24 12:15:20 -04:00
|
|
|
#include <LibCore/Forward.h>
|
2025-02-15 08:09:47 -05:00
|
|
|
#include <LibDevTools/DevToolsDelegate.h>
|
|
|
|
#include <LibDevTools/Forward.h>
|
2024-11-13 15:33:02 -05:00
|
|
|
#include <LibImageDecoderClient/Client.h>
|
2024-07-30 14:01:05 -04:00
|
|
|
#include <LibMain/Main.h>
|
2024-11-13 15:33:02 -05:00
|
|
|
#include <LibRequests/RequestClient.h>
|
2024-07-30 14:01:05 -04:00
|
|
|
#include <LibURL/URL.h>
|
2025-09-03 11:23:09 -04:00
|
|
|
#include <LibWeb/CSS/PreferredColorScheme.h>
|
|
|
|
#include <LibWeb/CSS/PreferredContrast.h>
|
|
|
|
#include <LibWeb/CSS/PreferredMotion.h>
|
2025-09-18 08:16:36 -04:00
|
|
|
#include <LibWeb/Clipboard/SystemClipboard.h>
|
2025-09-13 09:08:24 -04:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2025-07-01 20:55:11 -07:00
|
|
|
#include <LibWebView/Forward.h>
|
2024-07-30 14:01:05 -04:00
|
|
|
#include <LibWebView/Options.h>
|
2024-06-29 22:24:01 -06:00
|
|
|
#include <LibWebView/Process.h>
|
|
|
|
#include <LibWebView/ProcessManager.h>
|
2025-03-20 12:59:44 -04:00
|
|
|
#include <LibWebView/Settings.h>
|
2025-06-08 23:35:46 +02:00
|
|
|
#include <LibWebView/StorageJar.h>
|
2024-06-29 22:24:01 -06:00
|
|
|
|
|
|
|
namespace WebView {
|
|
|
|
|
2025-04-23 12:37:05 -04:00
|
|
|
struct ApplicationSettingsObserver;
|
|
|
|
|
2025-07-01 20:55:11 -07:00
|
|
|
class WEBVIEW_API Application : public DevTools::DevToolsDelegate {
|
2024-06-29 22:24:01 -06:00
|
|
|
AK_MAKE_NONCOPYABLE(Application);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Application();
|
|
|
|
|
2025-06-06 15:42:12 -04:00
|
|
|
ErrorOr<int> execute();
|
2024-06-29 22:24:01 -06:00
|
|
|
|
|
|
|
static Application& the() { return *s_the; }
|
|
|
|
|
2025-03-20 12:59:44 -04:00
|
|
|
static Settings& settings() { return the().m_settings; }
|
|
|
|
|
2025-03-15 16:56:52 -04:00
|
|
|
static BrowserOptions const& browser_options() { return the().m_browser_options; }
|
2024-12-02 19:33:26 -06:00
|
|
|
static WebContentOptions& web_content_options() { return the().m_web_content_options; }
|
2024-07-30 14:01:05 -04:00
|
|
|
|
2024-11-13 15:33:02 -05:00
|
|
|
static Requests::RequestClient& request_server_client() { return *the().m_request_server_client; }
|
|
|
|
static ImageDecoderClient::Client& image_decoder_client() { return *the().m_image_decoder_client; }
|
|
|
|
|
2024-09-05 18:19:51 -04:00
|
|
|
static CookieJar& cookie_jar() { return *the().m_cookie_jar; }
|
2025-06-08 23:35:46 +02:00
|
|
|
static StorageJar& storage_jar() { return *the().m_storage_jar; }
|
2024-09-05 18:19:51 -04:00
|
|
|
|
2025-06-11 07:32:37 -04:00
|
|
|
static ProcessManager& process_manager() { return *the().m_process_manager; }
|
2025-03-24 09:50:12 -04:00
|
|
|
|
2025-03-09 18:01:25 -04:00
|
|
|
ErrorOr<NonnullRefPtr<WebContentClient>> launch_web_content_process(ViewImplementation&);
|
2025-09-13 09:08:24 -04:00
|
|
|
|
2025-09-04 08:53:57 -04:00
|
|
|
virtual Optional<ViewImplementation&> active_web_view() const { return {}; }
|
2025-09-13 09:08:24 -04:00
|
|
|
virtual Optional<ViewImplementation&> open_blank_new_tab(Web::HTML::ActivateTab) const { return {}; }
|
|
|
|
void open_url_in_new_tab(URL::URL const&, Web::HTML::ActivateTab) const;
|
2024-11-13 15:33:02 -05:00
|
|
|
|
2024-06-29 22:24:01 -06:00
|
|
|
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);
|
|
|
|
|
2024-08-28 15:29:51 -04:00
|
|
|
ErrorOr<LexicalPath> path_for_downloaded_file(StringView file) const;
|
|
|
|
|
2025-09-04 08:53:57 -04:00
|
|
|
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const;
|
|
|
|
virtual void display_error_dialog(StringView error_message) const;
|
|
|
|
|
2025-09-18 09:18:54 -04:00
|
|
|
virtual Utf16String clipboard_text() const { return {}; }
|
2025-09-18 08:16:36 -04:00
|
|
|
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const { return {}; }
|
|
|
|
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) { }
|
|
|
|
|
2025-09-01 08:20:14 -04:00
|
|
|
Action& reload_action() { return *m_reload_action; }
|
|
|
|
Action& copy_selection_action() { return *m_copy_selection_action; }
|
|
|
|
Action& paste_action() { return *m_paste_action; }
|
|
|
|
Action& select_all_action() { return *m_select_all_action; }
|
2025-09-17 09:18:08 -04:00
|
|
|
|
|
|
|
Action& open_about_page_action() { return *m_open_about_page_action; }
|
|
|
|
Action& open_settings_page_action() { return *m_open_settings_page_action; }
|
2025-09-01 08:20:14 -04:00
|
|
|
|
2025-09-10 07:23:15 -04:00
|
|
|
Menu& zoom_menu() { return *m_zoom_menu; }
|
|
|
|
Action& reset_zoom_action() { return *m_reset_zoom_action; }
|
|
|
|
|
2025-09-03 11:23:09 -04:00
|
|
|
Menu& color_scheme_menu() { return *m_color_scheme_menu; }
|
|
|
|
Menu& contrast_menu() { return *m_contrast_menu; }
|
|
|
|
Menu& motion_menu() { return *m_motion_menu; }
|
2025-09-17 10:22:23 -04:00
|
|
|
|
|
|
|
Menu& inspect_menu() { return *m_inspect_menu; }
|
|
|
|
Action& view_source_action() { return *m_view_source_action; }
|
|
|
|
|
2025-09-03 09:00:52 -04:00
|
|
|
Menu& debug_menu() { return *m_debug_menu; }
|
|
|
|
|
|
|
|
void apply_view_options(Badge<ViewImplementation>, ViewImplementation&);
|
|
|
|
|
2025-09-17 10:03:01 -04:00
|
|
|
ErrorOr<void> toggle_devtools_enabled();
|
2025-02-15 08:09:47 -05:00
|
|
|
void refresh_tab_list();
|
|
|
|
|
2025-09-16 18:06:00 -07:00
|
|
|
Optional<Core::TimeZoneWatcher&> time_zone_watcher();
|
|
|
|
|
2024-06-29 22:24:01 -06:00
|
|
|
protected:
|
2025-06-10 19:20:46 -04:00
|
|
|
explicit Application(Optional<ByteString> ladybird_binary_path = {});
|
2024-07-30 14:01:05 -04:00
|
|
|
|
2025-06-10 19:20:46 -04:00
|
|
|
ErrorOr<void> initialize(Main::Arguments const&);
|
2025-06-10 19:13:03 -04:00
|
|
|
|
2024-06-29 22:24:01 -06:00
|
|
|
virtual void process_did_exit(Process&&);
|
|
|
|
|
2024-07-30 14:01:05 -04:00
|
|
|
virtual void create_platform_arguments(Core::ArgsParser&) { }
|
2025-03-15 16:56:52 -04:00
|
|
|
virtual void create_platform_options(BrowserOptions&, WebContentOptions&) { }
|
2025-06-06 15:42:12 -04:00
|
|
|
virtual NonnullOwnPtr<Core::EventLoop> create_platform_event_loop();
|
2024-07-30 14:01:05 -04:00
|
|
|
|
2024-08-28 15:29:51 -04:00
|
|
|
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
|
|
|
|
|
2025-09-17 10:03:01 -04:00
|
|
|
virtual void on_devtools_enabled() const;
|
|
|
|
virtual void on_devtools_disabled() const;
|
|
|
|
|
2025-06-10 14:56:24 -04:00
|
|
|
Main::Arguments& arguments() { return m_arguments; }
|
|
|
|
|
2024-06-29 22:24:01 -06:00
|
|
|
private:
|
2025-06-10 19:20:46 -04:00
|
|
|
ErrorOr<void> launch_services();
|
2025-03-09 18:01:25 -04:00
|
|
|
void launch_spare_web_content_process();
|
2024-11-13 15:33:02 -05:00
|
|
|
ErrorOr<void> launch_request_server();
|
|
|
|
ErrorOr<void> launch_image_decoder_server();
|
2025-02-15 08:09:47 -05:00
|
|
|
ErrorOr<void> launch_devtools_server();
|
|
|
|
|
2025-09-01 08:20:14 -04:00
|
|
|
void initialize_actions();
|
|
|
|
|
2025-02-15 08:09:47 -05:00
|
|
|
virtual Vector<DevTools::TabDescription> tab_list() const override;
|
|
|
|
virtual Vector<DevTools::CSSProperty> css_property_list() const override;
|
2025-02-21 16:22:12 -05:00
|
|
|
virtual void inspect_tab(DevTools::TabDescription const&, OnTabInspectionComplete) const override;
|
2025-03-19 15:50:56 -04:00
|
|
|
virtual void listen_for_dom_properties(DevTools::TabDescription const&, OnDOMNodePropertiesReceived) const override;
|
|
|
|
virtual void stop_listening_for_dom_properties(DevTools::TabDescription const&) const override;
|
2025-03-20 16:56:46 +00:00
|
|
|
virtual void inspect_dom_node(DevTools::TabDescription const&, DOMNodeProperties::Type, Web::UniqueNodeID, Optional<Web::CSS::PseudoElement>) const override;
|
2025-02-21 16:22:12 -05:00
|
|
|
virtual void clear_inspected_dom_node(DevTools::TabDescription const&) const override;
|
2025-03-20 16:56:46 +00:00
|
|
|
virtual void highlight_dom_node(DevTools::TabDescription const&, Web::UniqueNodeID, Optional<Web::CSS::PseudoElement>) const override;
|
2025-02-21 16:22:12 -05:00
|
|
|
virtual void clear_highlighted_dom_node(DevTools::TabDescription const&) const override;
|
2025-03-06 19:56:03 -05:00
|
|
|
virtual void listen_for_dom_mutations(DevTools::TabDescription const&, OnDOMMutationReceived) const override;
|
|
|
|
virtual void stop_listening_for_dom_mutations(DevTools::TabDescription const&) const override;
|
2025-03-10 18:15:31 -04:00
|
|
|
virtual void get_dom_node_inner_html(DevTools::TabDescription const&, Web::UniqueNodeID, OnDOMNodeHTMLReceived) const override;
|
2025-03-10 17:36:41 -04:00
|
|
|
virtual void get_dom_node_outer_html(DevTools::TabDescription const&, Web::UniqueNodeID, OnDOMNodeHTMLReceived) const override;
|
|
|
|
virtual void set_dom_node_outer_html(DevTools::TabDescription const&, Web::UniqueNodeID, String const&, OnDOMNodeEditComplete) const override;
|
2025-03-08 11:00:03 -05:00
|
|
|
virtual void set_dom_node_text(DevTools::TabDescription const&, Web::UniqueNodeID, String const&, OnDOMNodeEditComplete) const override;
|
|
|
|
virtual void set_dom_node_tag(DevTools::TabDescription const&, Web::UniqueNodeID, String const&, OnDOMNodeEditComplete) const override;
|
|
|
|
virtual void add_dom_node_attributes(DevTools::TabDescription const&, Web::UniqueNodeID, ReadonlySpan<Attribute>, OnDOMNodeEditComplete) const override;
|
|
|
|
virtual void replace_dom_node_attribute(DevTools::TabDescription const&, Web::UniqueNodeID, String const&, ReadonlySpan<Attribute>, OnDOMNodeEditComplete) const override;
|
2025-03-07 09:19:28 -05:00
|
|
|
virtual void create_child_element(DevTools::TabDescription const&, Web::UniqueNodeID, OnDOMNodeEditComplete) const override;
|
2025-03-10 18:01:29 -04:00
|
|
|
virtual void insert_dom_node_before(DevTools::TabDescription const&, Web::UniqueNodeID, Web::UniqueNodeID, Optional<Web::UniqueNodeID>, OnDOMNodeEditComplete) const override;
|
2025-03-07 09:44:24 -05:00
|
|
|
virtual void clone_dom_node(DevTools::TabDescription const&, Web::UniqueNodeID, OnDOMNodeEditComplete) const override;
|
2025-03-06 20:08:27 -05:00
|
|
|
virtual void remove_dom_node(DevTools::TabDescription const&, Web::UniqueNodeID, OnDOMNodeEditComplete) const override;
|
2025-03-11 17:14:54 -04:00
|
|
|
virtual void retrieve_style_sheets(DevTools::TabDescription const&, OnStyleSheetsReceived) const override;
|
|
|
|
virtual void retrieve_style_sheet_source(DevTools::TabDescription const&, Web::CSS::StyleSheetIdentifier const&) const override;
|
|
|
|
virtual void listen_for_style_sheet_sources(DevTools::TabDescription const&, OnStyleSheetSourceReceived) const override;
|
|
|
|
virtual void stop_listening_for_style_sheet_sources(DevTools::TabDescription const&) const override;
|
2025-03-08 11:00:03 -05:00
|
|
|
virtual void evaluate_javascript(DevTools::TabDescription const&, String const&, OnScriptEvaluationComplete) const override;
|
2025-03-04 08:48:20 -05:00
|
|
|
virtual void listen_for_console_messages(DevTools::TabDescription const&, OnConsoleMessageAvailable, OnReceivedConsoleMessages) const override;
|
|
|
|
virtual void stop_listening_for_console_messages(DevTools::TabDescription const&) const override;
|
|
|
|
virtual void request_console_messages(DevTools::TabDescription const&, i32) const override;
|
2024-11-13 15:33:02 -05:00
|
|
|
|
2024-06-29 22:24:01 -06:00
|
|
|
static Application* s_the;
|
|
|
|
|
2025-03-20 12:59:44 -04:00
|
|
|
Settings m_settings;
|
2025-04-23 12:37:05 -04:00
|
|
|
OwnPtr<ApplicationSettingsObserver> m_settings_observer;
|
2025-03-20 12:59:44 -04:00
|
|
|
|
2025-06-10 14:56:24 -04:00
|
|
|
Main::Arguments m_arguments;
|
2025-03-15 16:56:52 -04:00
|
|
|
BrowserOptions m_browser_options;
|
2024-07-30 14:01:05 -04:00
|
|
|
WebContentOptions m_web_content_options;
|
|
|
|
|
2024-11-13 15:33:02 -05:00
|
|
|
RefPtr<Requests::RequestClient> m_request_server_client;
|
|
|
|
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
|
|
|
|
|
2025-03-09 18:01:25 -04:00
|
|
|
RefPtr<WebContentClient> m_spare_web_content_process;
|
|
|
|
bool m_has_queued_task_to_launch_spare_web_content_process { false };
|
|
|
|
|
2024-09-05 18:19:51 -04:00
|
|
|
RefPtr<Database> m_database;
|
|
|
|
OwnPtr<CookieJar> m_cookie_jar;
|
2025-06-08 23:35:46 +02:00
|
|
|
OwnPtr<StorageJar> m_storage_jar;
|
2024-09-05 18:19:51 -04:00
|
|
|
|
2024-08-24 12:15:20 -04:00
|
|
|
OwnPtr<Core::TimeZoneWatcher> m_time_zone_watcher;
|
|
|
|
|
2025-06-06 15:42:12 -04:00
|
|
|
OwnPtr<Core::EventLoop> m_event_loop;
|
2025-06-11 07:32:37 -04:00
|
|
|
OwnPtr<ProcessManager> m_process_manager;
|
2025-02-15 08:09:47 -05:00
|
|
|
|
2025-09-01 08:20:14 -04:00
|
|
|
RefPtr<Action> m_reload_action;
|
|
|
|
RefPtr<Action> m_copy_selection_action;
|
|
|
|
RefPtr<Action> m_paste_action;
|
|
|
|
RefPtr<Action> m_select_all_action;
|
2025-09-17 09:18:08 -04:00
|
|
|
|
|
|
|
RefPtr<Action> m_open_about_page_action;
|
|
|
|
RefPtr<Action> m_open_settings_page_action;
|
2025-09-01 08:20:14 -04:00
|
|
|
|
2025-09-10 07:23:15 -04:00
|
|
|
RefPtr<Menu> m_zoom_menu;
|
|
|
|
RefPtr<Action> m_reset_zoom_action;
|
|
|
|
|
2025-09-03 11:23:09 -04:00
|
|
|
RefPtr<Menu> m_color_scheme_menu;
|
|
|
|
Web::CSS::PreferredColorScheme m_color_scheme { Web::CSS::PreferredColorScheme::Auto };
|
|
|
|
|
|
|
|
RefPtr<Menu> m_contrast_menu;
|
|
|
|
Web::CSS::PreferredContrast m_contrast { Web::CSS::PreferredContrast::Auto };
|
|
|
|
|
|
|
|
RefPtr<Menu> m_motion_menu;
|
|
|
|
Web::CSS::PreferredMotion m_motion { Web::CSS::PreferredMotion::Auto };
|
|
|
|
|
2025-09-17 10:22:23 -04:00
|
|
|
RefPtr<Menu> m_inspect_menu;
|
|
|
|
RefPtr<Action> m_view_source_action;
|
|
|
|
RefPtr<Action> m_toggle_devtools_action;
|
|
|
|
|
2025-09-03 09:00:52 -04:00
|
|
|
RefPtr<Menu> m_debug_menu;
|
|
|
|
RefPtr<Action> m_show_line_box_borders_action;
|
|
|
|
RefPtr<Action> m_enable_scripting_action;
|
|
|
|
RefPtr<Action> m_enable_content_filtering_action;
|
|
|
|
RefPtr<Action> m_block_pop_ups_action;
|
|
|
|
StringView m_user_agent_string;
|
|
|
|
StringView m_navigator_compatibility_mode;
|
|
|
|
|
2025-06-10 19:20:46 -04:00
|
|
|
#if defined(AK_OS_MACOS)
|
|
|
|
OwnPtr<MachPortServer> m_mach_port_server;
|
|
|
|
#endif
|
|
|
|
|
2025-02-15 08:09:47 -05:00
|
|
|
OwnPtr<DevTools::DevToolsServer> m_devtools;
|
2024-07-16 05:33:39 -06:00
|
|
|
} SWIFT_IMMORTAL_REFERENCE;
|
2025-04-23 12:37:05 -04:00
|
|
|
|
2024-06-29 22:24:01 -06:00
|
|
|
}
|
2024-07-30 14:01:05 -04:00
|
|
|
|
2025-06-10 19:20:46 -04:00
|
|
|
#define WEB_VIEW_APPLICATION(ApplicationType) \
|
|
|
|
public: \
|
|
|
|
template<typename... ApplicationArguments> \
|
|
|
|
static ErrorOr<NonnullOwnPtr<ApplicationType>> create(Main::Arguments const& arguments, ApplicationArguments&&... application_arguments) \
|
|
|
|
{ \
|
|
|
|
auto app = adopt_own(*new ApplicationType { forward<ApplicationArguments>(application_arguments)... }); \
|
|
|
|
TRY(app->initialize(arguments)); \
|
|
|
|
return app; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static ApplicationType& the() \
|
|
|
|
{ \
|
|
|
|
return static_cast<ApplicationType&>(WebView::Application::the()); \
|
|
|
|
} \
|
|
|
|
\
|
2025-06-10 19:15:40 -04:00
|
|
|
private:
|