2020-06-17 17:31:42 +02:00
|
|
|
/*
|
2023-03-14 13:26:06 +01:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
2023-01-12 14:35:35 +00:00
|
|
|
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
2022-11-03 13:30:11 -04:00
|
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
2020-06-17 17:31:42 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-17 17:31:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
2023-03-14 13:26:06 +01:00
|
|
|
#include <AK/Queue.h>
|
2022-02-25 12:18:30 +02:00
|
|
|
#include <LibIPC/ConnectionFromClient.h>
|
2021-02-27 21:44:49 -06:00
|
|
|
#include <LibJS/Forward.h>
|
2021-09-03 10:16:36 +01:00
|
|
|
#include <LibJS/Heap/Handle.h>
|
2021-10-26 17:00:10 +01:00
|
|
|
#include <LibWeb/CSS/PreferredColorScheme.h>
|
2020-06-17 17:31:42 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
2022-02-26 17:50:31 +01:00
|
|
|
#include <LibWeb/Loader/FileRequest.h>
|
2022-10-05 19:33:30 +02:00
|
|
|
#include <LibWeb/Platform/Timer.h>
|
2023-11-19 10:42:11 -05:00
|
|
|
#include <LibWebView/Forward.h>
|
2020-06-17 17:31:42 +02:00
|
|
|
#include <WebContent/Forward.h>
|
2020-09-12 11:44:00 +02:00
|
|
|
#include <WebContent/WebContentClientEndpoint.h>
|
2021-02-27 21:44:49 -06:00
|
|
|
#include <WebContent/WebContentConsoleClient.h>
|
2020-06-17 17:31:42 +02:00
|
|
|
#include <WebContent/WebContentServerEndpoint.h>
|
|
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
|
2022-02-25 12:18:30 +02:00
|
|
|
class ConnectionFromClient final
|
|
|
|
|
: public IPC::ConnectionFromClient<WebContentClientEndpoint, WebContentServerEndpoint> {
|
|
|
|
|
C_OBJECT(ConnectionFromClient);
|
2020-06-17 17:31:42 +02:00
|
|
|
|
|
|
|
|
public:
|
2022-03-23 20:58:03 -06:00
|
|
|
~ConnectionFromClient() override = default;
|
2020-06-17 17:31:42 +02:00
|
|
|
|
|
|
|
|
virtual void die() override;
|
|
|
|
|
|
2023-11-29 09:34:38 -07:00
|
|
|
void initialize_js_console(Badge<PageClient>, Web::DOM::Document& document);
|
|
|
|
|
void destroy_js_console(Badge<PageClient>, Web::DOM::Document& document);
|
2021-09-04 11:14:25 +01:00
|
|
|
|
2023-01-30 16:35:47 -05:00
|
|
|
void request_file(Web::FileRequest);
|
2022-02-26 17:50:31 +01:00
|
|
|
|
2022-10-05 16:02:02 +02:00
|
|
|
Optional<int> fd() { return socket().fd(); }
|
|
|
|
|
|
2022-11-14 10:59:34 -05:00
|
|
|
PageHost& page_host() { return *m_page_host; }
|
|
|
|
|
PageHost const& page_host() const { return *m_page_host; }
|
|
|
|
|
|
2020-06-17 17:31:42 +02:00
|
|
|
private:
|
2023-02-08 23:05:44 +01:00
|
|
|
explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>);
|
2021-10-31 23:38:04 +01:00
|
|
|
|
2023-11-29 09:34:38 -07:00
|
|
|
PageClient& page(u64 index = 0);
|
|
|
|
|
PageClient const& page(u64 index = 0) const;
|
2020-06-17 17:31:42 +02:00
|
|
|
|
2023-03-14 07:05:57 +03:00
|
|
|
virtual Messages::WebContentServer::GetWindowHandleResponse get_window_handle() override;
|
2023-03-16 17:36:36 +03:00
|
|
|
virtual void set_window_handle(String const& handle) override;
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual void connect_to_webdriver(ByteString const& webdriver_ipc_path) override;
|
2021-05-02 19:54:34 +02:00
|
|
|
virtual void update_system_theme(Core::AnonymousBuffer const&) override;
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual void update_system_fonts(ByteString const&, ByteString const&, ByteString const&) override;
|
2023-12-14 07:17:00 +01:00
|
|
|
virtual void update_screen_rects(Vector<Web::DevicePixelRect> const&, u32) override;
|
2021-05-02 19:54:34 +02:00
|
|
|
virtual void load_url(URL const&) override;
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual void load_html(ByteString const&) override;
|
2023-12-14 07:17:00 +01:00
|
|
|
virtual void paint(Web::DevicePixelRect const&, i32) override;
|
|
|
|
|
virtual void set_viewport_rect(Web::DevicePixelRect const&) override;
|
2023-12-15 17:46:09 +01:00
|
|
|
virtual void mouse_down(Web::DevicePixelPoint, Web::DevicePixelPoint, unsigned, unsigned, unsigned) override;
|
|
|
|
|
virtual void mouse_move(Web::DevicePixelPoint, Web::DevicePixelPoint, unsigned, unsigned, unsigned) override;
|
|
|
|
|
virtual void mouse_up(Web::DevicePixelPoint, Web::DevicePixelPoint, unsigned, unsigned, unsigned) override;
|
|
|
|
|
virtual void mouse_wheel(Web::DevicePixelPoint, Web::DevicePixelPoint, unsigned, unsigned, unsigned, Web::DevicePixels, Web::DevicePixels) override;
|
|
|
|
|
virtual void doubleclick(Web::DevicePixelPoint, Web::DevicePixelPoint, unsigned, unsigned, unsigned) override;
|
2021-05-02 19:54:34 +02:00
|
|
|
virtual void key_down(i32, unsigned, u32) override;
|
2021-09-28 15:39:35 +02:00
|
|
|
virtual void key_up(i32, unsigned, u32) override;
|
2021-05-02 19:54:34 +02:00
|
|
|
virtual void add_backing_store(i32, Gfx::ShareableBitmap const&) override;
|
|
|
|
|
virtual void remove_backing_store(i32) override;
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual void debug_request(ByteString const&, ByteString const&) override;
|
2021-05-02 19:54:34 +02:00
|
|
|
virtual void get_source() override;
|
2021-06-07 16:35:10 +01:00
|
|
|
virtual void inspect_dom_tree() override;
|
2023-12-10 21:00:03 +13:00
|
|
|
virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) override;
|
2022-12-07 19:30:37 -06:00
|
|
|
virtual void inspect_accessibility_tree() override;
|
2021-08-27 17:33:10 +01:00
|
|
|
virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
|
2023-11-19 10:42:11 -05:00
|
|
|
|
|
|
|
|
virtual void set_dom_node_text(i32 node_id, String const& text) override;
|
|
|
|
|
virtual Messages::WebContentServer::SetDomNodeTagResponse set_dom_node_tag(i32 node_id, String const& name) override;
|
2023-12-05 16:49:47 -05:00
|
|
|
virtual void add_dom_node_attributes(i32 node_id, Vector<WebView::Attribute> const& attributes) override;
|
2023-11-19 10:42:11 -05:00
|
|
|
virtual void replace_dom_node_attribute(i32 node_id, String const& name, Vector<WebView::Attribute> const& replacement_attributes) override;
|
2023-12-07 11:00:57 -05:00
|
|
|
virtual Messages::WebContentServer::CreateChildElementResponse create_child_element(i32 node_id) override;
|
|
|
|
|
virtual Messages::WebContentServer::CreateChildTextNodeResponse create_child_text_node(i32 node_id) override;
|
2023-12-07 11:12:43 -05:00
|
|
|
virtual Messages::WebContentServer::CloneDomNodeResponse clone_dom_node(i32 node_id) override;
|
2023-12-05 14:59:54 -05:00
|
|
|
virtual void remove_dom_node(i32 node_id) override;
|
2023-12-06 10:36:27 -05:00
|
|
|
virtual Messages::WebContentServer::GetDomNodeHtmlResponse get_dom_node_html(i32 node_id) override;
|
2023-11-19 10:42:11 -05:00
|
|
|
|
2021-09-08 00:55:35 +02:00
|
|
|
virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override;
|
2023-08-03 09:59:12 +02:00
|
|
|
virtual Messages::WebContentServer::DumpPaintTreeResponse dump_paint_tree() override;
|
2023-05-28 20:54:33 +02:00
|
|
|
virtual Messages::WebContentServer::DumpTextResponse dump_text() override;
|
2023-04-21 07:54:56 -04:00
|
|
|
virtual void set_content_filters(Vector<String> const&) override;
|
2023-04-17 13:21:19 -04:00
|
|
|
virtual void set_autoplay_allowed_on_all_websites() override;
|
|
|
|
|
virtual void set_autoplay_allowlist(Vector<String> const& allowlist) override;
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual void set_proxy_mappings(Vector<ByteString> const&, HashMap<ByteString, size_t> const&) override;
|
2021-10-26 17:00:10 +01:00
|
|
|
virtual void set_preferred_color_scheme(Web::CSS::PreferredColorScheme const&) override;
|
2022-02-06 19:03:13 +01:00
|
|
|
virtual void set_has_focus(bool) override;
|
2022-03-30 23:23:14 +01:00
|
|
|
virtual void set_is_scripting_enabled(bool) override;
|
2023-01-12 14:35:35 +00:00
|
|
|
virtual void set_device_pixels_per_css_pixel(float) override;
|
2023-12-14 07:17:00 +01:00
|
|
|
virtual void set_window_position(Web::DevicePixelPoint) override;
|
|
|
|
|
virtual void set_window_size(Web::DevicePixelSize) override;
|
2022-02-26 17:50:31 +01:00
|
|
|
virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
|
2022-09-19 20:50:33 +02:00
|
|
|
virtual void set_system_visibility_state(bool visible) override;
|
2021-09-04 11:14:25 +01:00
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual void js_console_input(ByteString const&) override;
|
|
|
|
|
virtual void run_javascript(ByteString const&) override;
|
2021-09-04 11:14:25 +01:00
|
|
|
virtual void js_console_request_messages(i32) override;
|
|
|
|
|
|
2022-11-15 15:49:36 -05:00
|
|
|
virtual void alert_closed() override;
|
|
|
|
|
virtual void confirm_closed(bool accepted) override;
|
2023-03-13 17:30:51 -04:00
|
|
|
virtual void prompt_closed(Optional<String> const& response) override;
|
2023-09-04 11:32:40 +02:00
|
|
|
virtual void color_picker_closed(Optional<Color> const& picked_color) override;
|
2023-12-07 15:53:49 +01:00
|
|
|
virtual void select_dropdown_closed(Optional<String> const& value) override;
|
2022-11-15 15:49:36 -05:00
|
|
|
|
2023-06-16 10:51:38 -04:00
|
|
|
virtual void toggle_media_play_state() override;
|
2023-06-16 11:29:54 -04:00
|
|
|
virtual void toggle_media_mute_state() override;
|
2023-06-16 10:51:38 -04:00
|
|
|
virtual void toggle_media_loop_state() override;
|
|
|
|
|
virtual void toggle_media_controls_state() override;
|
2023-05-15 11:17:58 -04:00
|
|
|
|
2023-08-21 15:50:31 +01:00
|
|
|
virtual void set_user_style(String const&) override;
|
|
|
|
|
|
2023-11-23 12:22:23 -05:00
|
|
|
virtual void enable_inspector_prototype() override;
|
|
|
|
|
|
2022-11-05 00:09:41 -04:00
|
|
|
virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override;
|
2023-12-06 11:51:44 -05:00
|
|
|
virtual Messages::WebContentServer::TakeDomNodeScreenshotResponse take_dom_node_screenshot(i32 node_id) override;
|
2022-10-18 12:40:14 +02:00
|
|
|
|
2023-12-12 13:25:06 +01:00
|
|
|
virtual Messages::WebContentServer::DumpGcGraphResponse dump_gc_graph() override;
|
|
|
|
|
|
2022-04-02 00:14:04 +03:00
|
|
|
virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;
|
2022-05-07 22:45:43 +02:00
|
|
|
virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;
|
2022-04-02 00:14:04 +03:00
|
|
|
|
2021-07-14 08:32:55 -04:00
|
|
|
virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text() override;
|
2021-07-14 08:53:55 -04:00
|
|
|
virtual void select_all() override;
|
2020-06-17 17:31:42 +02:00
|
|
|
|
2020-07-05 16:26:15 +02:00
|
|
|
void flush_pending_paint_requests();
|
|
|
|
|
|
2022-11-21 16:07:47 +00:00
|
|
|
void report_finished_handling_input_event(bool event_was_handled);
|
|
|
|
|
|
2020-06-17 17:31:42 +02:00
|
|
|
NonnullOwnPtr<PageHost> m_page_host;
|
2020-07-05 16:26:15 +02:00
|
|
|
struct PaintRequest {
|
2023-12-14 07:17:00 +01:00
|
|
|
Web::DevicePixelRect content_rect;
|
2020-07-05 16:26:15 +02:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> bitmap;
|
2021-01-16 23:15:32 +01:00
|
|
|
i32 bitmap_id { -1 };
|
2020-07-05 16:26:15 +02:00
|
|
|
};
|
|
|
|
|
Vector<PaintRequest> m_pending_paint_requests;
|
2022-10-05 19:33:30 +02:00
|
|
|
RefPtr<Web::Platform::Timer> m_paint_flush_timer;
|
2021-01-16 23:15:32 +01:00
|
|
|
|
|
|
|
|
HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
|
2021-02-27 21:44:49 -06:00
|
|
|
|
2023-09-17 16:11:16 +02:00
|
|
|
HashMap<Web::DOM::Document*, NonnullOwnPtr<WebContentConsoleClient>> m_console_clients;
|
|
|
|
|
WeakPtr<WebContentConsoleClient> m_top_level_document_console_client;
|
|
|
|
|
|
2021-09-03 10:16:36 +01:00
|
|
|
JS::Handle<JS::GlobalObject> m_console_global_object;
|
2022-02-26 17:50:31 +01:00
|
|
|
|
2023-01-30 16:35:47 -05:00
|
|
|
HashMap<int, Web::FileRequest> m_requested_files {};
|
2022-02-26 17:50:31 +01:00
|
|
|
int last_id { 0 };
|
2023-03-14 13:26:06 +01:00
|
|
|
|
|
|
|
|
struct QueuedMouseEvent {
|
|
|
|
|
enum class Type {
|
|
|
|
|
MouseMove,
|
|
|
|
|
MouseDown,
|
|
|
|
|
MouseUp,
|
|
|
|
|
MouseWheel,
|
|
|
|
|
DoubleClick,
|
|
|
|
|
};
|
|
|
|
|
Type type {};
|
2023-12-15 17:46:09 +01:00
|
|
|
Web::DevicePixelPoint position {};
|
|
|
|
|
Web::DevicePixelPoint screen_position {};
|
2023-03-14 13:26:06 +01:00
|
|
|
unsigned button {};
|
|
|
|
|
unsigned buttons {};
|
|
|
|
|
unsigned modifiers {};
|
2023-12-15 17:46:09 +01:00
|
|
|
Web::DevicePixels wheel_delta_x {};
|
|
|
|
|
Web::DevicePixels wheel_delta_y {};
|
2023-03-14 13:47:40 +01:00
|
|
|
size_t coalesced_event_count { 0 };
|
2023-03-14 13:26:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct QueuedKeyboardEvent {
|
|
|
|
|
enum class Type {
|
|
|
|
|
KeyDown,
|
|
|
|
|
KeyUp,
|
|
|
|
|
};
|
|
|
|
|
Type type {};
|
|
|
|
|
i32 key {};
|
|
|
|
|
unsigned int modifiers {};
|
|
|
|
|
u32 code_point {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void enqueue_input_event(Variant<QueuedMouseEvent, QueuedKeyboardEvent>);
|
|
|
|
|
void process_next_input_event();
|
|
|
|
|
|
|
|
|
|
Queue<Variant<QueuedMouseEvent, QueuedKeyboardEvent>> m_input_event_queue;
|
|
|
|
|
|
|
|
|
|
RefPtr<Web::Platform::Timer> m_input_event_queue_timer;
|
2020-06-17 17:31:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|