Serenity Operating System
1/*
2 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
4 * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 */
8
9#pragma once
10
11#include <AK/HashMap.h>
12#include <LibIPC/ConnectionFromClient.h>
13#include <LibJS/Forward.h>
14#include <LibJS/Heap/Handle.h>
15#include <LibWeb/CSS/PreferredColorScheme.h>
16#include <LibWeb/Forward.h>
17#include <LibWeb/Loader/FileRequest.h>
18#include <LibWeb/Platform/Timer.h>
19#include <WebContent/Forward.h>
20#include <WebContent/WebContentClientEndpoint.h>
21#include <WebContent/WebContentConsoleClient.h>
22#include <WebContent/WebContentServerEndpoint.h>
23
24namespace WebContent {
25
26class ConnectionFromClient final
27 : public IPC::ConnectionFromClient<WebContentClientEndpoint, WebContentServerEndpoint> {
28 C_OBJECT(ConnectionFromClient);
29
30public:
31 ~ConnectionFromClient() override = default;
32
33 virtual void die() override;
34
35 void initialize_js_console(Badge<PageHost>);
36
37 void request_file(Web::FileRequest);
38
39 Optional<int> fd() { return socket().fd(); }
40
41 PageHost& page_host() { return *m_page_host; }
42 PageHost const& page_host() const { return *m_page_host; }
43
44private:
45 explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>);
46
47 Web::Page& page();
48 Web::Page const& page() const;
49
50 virtual void connect_to_webdriver(DeprecatedString const& webdriver_ipc_path) override;
51 virtual void update_system_theme(Core::AnonymousBuffer const&) override;
52 virtual void update_system_fonts(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;
53 virtual void update_screen_rects(Vector<Gfx::IntRect> const&, u32) override;
54 virtual void load_url(URL const&) override;
55 virtual void load_html(DeprecatedString const&, URL const&) override;
56 virtual void paint(Gfx::IntRect const&, i32) override;
57 virtual void set_viewport_rect(Gfx::IntRect const&) override;
58 virtual void mouse_down(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
59 virtual void mouse_move(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
60 virtual void mouse_up(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
61 virtual void mouse_wheel(Gfx::IntPoint, unsigned, unsigned, unsigned, i32, i32) override;
62 virtual void doubleclick(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
63 virtual void key_down(i32, unsigned, u32) override;
64 virtual void key_up(i32, unsigned, u32) override;
65 virtual void add_backing_store(i32, Gfx::ShareableBitmap const&) override;
66 virtual void remove_backing_store(i32) override;
67 virtual void debug_request(DeprecatedString const&, DeprecatedString const&) override;
68 virtual void get_source() override;
69 virtual void inspect_dom_tree() override;
70 virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) override;
71 virtual void inspect_accessibility_tree() override;
72 virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
73 virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override;
74 virtual void set_content_filters(Vector<DeprecatedString> const&) override;
75 virtual void set_proxy_mappings(Vector<DeprecatedString> const&, HashMap<DeprecatedString, size_t> const&) override;
76 virtual void set_preferred_color_scheme(Web::CSS::PreferredColorScheme const&) override;
77 virtual void set_has_focus(bool) override;
78 virtual void set_is_scripting_enabled(bool) override;
79 virtual void set_device_pixels_per_css_pixel(float) override;
80 virtual void set_window_position(Gfx::IntPoint) override;
81 virtual void set_window_size(Gfx::IntSize) override;
82 virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
83 virtual void set_system_visibility_state(bool visible) override;
84
85 virtual void js_console_input(DeprecatedString const&) override;
86 virtual void run_javascript(DeprecatedString const&) override;
87 virtual void js_console_request_messages(i32) override;
88
89 virtual void alert_closed() override;
90 virtual void confirm_closed(bool accepted) override;
91 virtual void prompt_closed(DeprecatedString const& response) override;
92
93 virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override;
94
95 virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;
96 virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;
97
98 virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text() override;
99 virtual void select_all() override;
100
101 void flush_pending_paint_requests();
102
103 void report_finished_handling_input_event(bool event_was_handled);
104
105 NonnullOwnPtr<PageHost> m_page_host;
106 struct PaintRequest {
107 Gfx::IntRect content_rect;
108 NonnullRefPtr<Gfx::Bitmap> bitmap;
109 i32 bitmap_id { -1 };
110 };
111 Vector<PaintRequest> m_pending_paint_requests;
112 RefPtr<Web::Platform::Timer> m_paint_flush_timer;
113
114 HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
115
116 WeakPtr<JS::Realm> m_realm;
117 OwnPtr<WebContentConsoleClient> m_console_client;
118 JS::Handle<JS::GlobalObject> m_console_global_object;
119
120 HashMap<int, Web::FileRequest> m_requested_files {};
121 int last_id { 0 };
122};
123
124}