| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2020-2021, Andreas Kling <andreas@ladybird.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>
 | 
					
						
							| 
									
										
										
										
											2024-03-29 09:44:49 -04:00
										 |  |  | #include <AK/SourceLocation.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:27:37 +02:00
										 |  |  | #include <LibIPC/ConnectionToServer.h>
 | 
					
						
							| 
									
										
										
										
											2024-10-22 15:47:33 -06:00
										 |  |  | #include <LibIPC/Transport.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-23 11:18:35 +01:00
										 |  |  | #include <LibWeb/CSS/StyleSheetIdentifier.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-20 18:39:20 -04:00
										 |  |  | #include <LibWeb/HTML/ActivateTab.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-14 12:26:00 -04:00
										 |  |  | #include <LibWeb/HTML/FileFilter.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | #include <LibWeb/HTML/SelectItem.h>
 | 
					
						
							| 
									
										
										
										
											2024-01-30 20:05:00 -07:00
										 |  |  | #include <LibWeb/HTML/WebViewHints.h>
 | 
					
						
							| 
									
										
										
										
											2024-09-12 12:56:31 -04:00
										 |  |  | #include <LibWeb/Page/EventResult.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | #include <WebContent/WebContentClientEndpoint.h>
 | 
					
						
							|  |  |  | #include <WebContent/WebContentServerEndpoint.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-30 10:46:33 +02:00
										 |  |  | namespace WebView { | 
					
						
							| 
									
										
										
										
											2020-08-24 15:33:18 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-05 14:32:17 +02:00
										 |  |  | class ViewImplementation; | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-30 18:20:40 +01:00
										 |  |  | class WebContentClient final | 
					
						
							| 
									
										
										
										
											2022-02-25 12:27:37 +02:00
										 |  |  |     : public IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint> | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  |     , public WebContentClientEndpoint { | 
					
						
							| 
									
										
										
										
											2024-11-21 12:46:45 -07:00
										 |  |  |     C_OBJECT_ABSTRACT(WebContentClient); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2025-01-03 21:19:46 +05:00
										 |  |  |     using InitTransport = Messages::WebContentServer::InitTransport; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-20 21:34:51 +03:00
										 |  |  |     static Optional<ViewImplementation&> view_for_pid_and_page_id(pid_t pid, u64 page_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 13:43:45 -06:00
										 |  |  |     template<CallableAs<IterationDecision, WebContentClient&> Callback> | 
					
						
							|  |  |  |     static void for_each_client(Callback callback); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static size_t client_count() { return s_clients.size(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-22 15:47:33 -06:00
										 |  |  |     WebContentClient(IPC::Transport, ViewImplementation&); | 
					
						
							| 
									
										
										
										
											2024-06-20 21:34:51 +03:00
										 |  |  |     ~WebContentClient(); | 
					
						
							| 
									
										
										
										
											2022-10-05 14:32:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     void register_view(u64 page_id, ViewImplementation&); | 
					
						
							|  |  |  |     void unregister_view(u64 page_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-30 18:20:40 +01:00
										 |  |  |     Function<void()> on_web_content_process_crash; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 19:11:51 +03:00
										 |  |  |     void set_pid(pid_t pid) { m_process_handle.pid = pid; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-01-30 18:20:40 +01:00
										 |  |  |     virtual void die() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_paint(u64 page_id, Gfx::IntRect const&, i32) override; | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     virtual void did_finish_loading(u64 page_id, URL::URL const&) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_request_refresh(u64 page_id) override; | 
					
						
							|  |  |  |     virtual void did_request_cursor_change(u64 page_id, i32) override; | 
					
						
							|  |  |  |     virtual void did_change_title(u64 page_id, ByteString const&) override; | 
					
						
							| 
									
										
										
										
											2024-04-14 10:27:20 +02:00
										 |  |  |     virtual void did_change_url(u64 page_id, URL::URL const&) override; | 
					
						
							| 
									
										
										
										
											2024-07-02 16:48:57 +02:00
										 |  |  |     virtual void did_request_tooltip_override(u64 page_id, Gfx::IntPoint, ByteString const&) override; | 
					
						
							|  |  |  |     virtual void did_stop_tooltip_override(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-07-02 14:16:24 +02:00
										 |  |  |     virtual void did_enter_tooltip_area(u64 page_id, ByteString const&) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_leave_tooltip_area(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     virtual void did_hover_link(u64 page_id, URL::URL const&) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_unhover_link(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     virtual void did_click_link(u64 page_id, URL::URL const&, ByteString const&, unsigned) override; | 
					
						
							|  |  |  |     virtual void did_middle_click_link(u64 page_id, URL::URL const&, ByteString const&, unsigned) override; | 
					
						
							|  |  |  |     virtual void did_start_loading(u64 page_id, URL::URL const&, bool) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_request_context_menu(u64 page_id, Gfx::IntPoint) override; | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     virtual void did_request_link_context_menu(u64 page_id, Gfx::IntPoint, URL::URL const&, ByteString const&, unsigned) override; | 
					
						
							| 
									
										
										
										
											2025-01-10 20:33:27 +11:00
										 |  |  |     virtual void did_request_image_context_menu(u64 page_id, Gfx::IntPoint, URL::URL const&, ByteString const&, unsigned, Optional<Gfx::ShareableBitmap> const&) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_request_media_context_menu(u64 page_id, Gfx::IntPoint, ByteString const&, unsigned, Web::Page::MediaContextMenu const&) override; | 
					
						
							| 
									
										
										
										
											2024-10-18 17:20:15 -04:00
										 |  |  |     virtual void did_get_source(u64 page_id, URL::URL const&, URL::URL const&, String const&) override; | 
					
						
							| 
									
										
										
										
											2025-02-21 11:51:05 -05:00
										 |  |  |     virtual void did_inspect_dom_tree(u64 page_id, String const&) override; | 
					
						
							|  |  |  |     virtual void did_inspect_dom_node(u64 page_id, bool has_style, String const& computed_style, String const& resolved_style, String const& custom_properties, String const& node_box_sizing, String const& aria_properties_state, String const& fonts) override; | 
					
						
							|  |  |  |     virtual void did_inspect_accessibility_tree(u64 page_id, String const&) override; | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  |     virtual void did_get_hovered_node_id(u64 page_id, Web::UniqueNodeID const& node_id) override; | 
					
						
							|  |  |  |     virtual void did_finish_editing_dom_node(u64 page_id, Optional<Web::UniqueNodeID> const& node_id) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_get_dom_node_html(u64 page_id, String const& html) override; | 
					
						
							|  |  |  |     virtual void did_take_screenshot(u64 page_id, Gfx::ShareableBitmap const& screenshot) override; | 
					
						
							| 
									
										
										
										
											2024-09-19 10:40:00 -04:00
										 |  |  |     virtual void did_get_internal_page_info(u64 page_id, PageInfoType, String const&) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_output_js_console_message(u64 page_id, i32 message_index) override; | 
					
						
							| 
									
										
										
										
											2025-02-23 08:57:40 -05:00
										 |  |  |     virtual void did_get_js_console_messages(u64 page_id, i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_change_favicon(u64 page_id, Gfx::ShareableBitmap const&) override; | 
					
						
							|  |  |  |     virtual void did_request_alert(u64 page_id, String const&) override; | 
					
						
							|  |  |  |     virtual void did_request_confirm(u64 page_id, String const&) override; | 
					
						
							|  |  |  |     virtual void did_request_prompt(u64 page_id, String const&, String const&) override; | 
					
						
							|  |  |  |     virtual void did_request_set_prompt_text(u64 page_id, String const& message) override; | 
					
						
							|  |  |  |     virtual void did_request_accept_dialog(u64 page_id) override; | 
					
						
							|  |  |  |     virtual void did_request_dismiss_dialog(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-09-22 13:25:18 -04:00
										 |  |  |     virtual Messages::WebContentClient::DidRequestAllCookiesResponse did_request_all_cookies(URL::URL const&) override; | 
					
						
							|  |  |  |     virtual Messages::WebContentClient::DidRequestNamedCookieResponse did_request_named_cookie(URL::URL const&, String const&) override; | 
					
						
							|  |  |  |     virtual Messages::WebContentClient::DidRequestCookieResponse did_request_cookie(URL::URL const&, Web::Cookie::Source) override; | 
					
						
							|  |  |  |     virtual void did_set_cookie(URL::URL const&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override; | 
					
						
							|  |  |  |     virtual void did_update_cookie(Web::Cookie::Cookie const&) override; | 
					
						
							| 
									
										
										
										
											2024-10-13 08:56:46 -04:00
										 |  |  |     virtual void did_expire_cookies_with_time_offset(AK::Duration) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual Messages::WebContentClient::DidRequestNewWebViewResponse did_request_new_web_view(u64 page_id, Web::HTML::ActivateTab const&, Web::HTML::WebViewHints const&, Optional<u64> const& page_index) override; | 
					
						
							|  |  |  |     virtual void did_request_activate_tab(u64 page_id) override; | 
					
						
							|  |  |  |     virtual void did_close_browsing_context(u64 page_id) override; | 
					
						
							|  |  |  |     virtual void did_update_resource_count(u64 page_id, i32 count_waiting) override; | 
					
						
							|  |  |  |     virtual void did_request_restore_window(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-10-28 23:37:11 -04:00
										 |  |  |     virtual void did_request_reposition_window(u64 page_id, Gfx::IntPoint) override; | 
					
						
							|  |  |  |     virtual void did_request_resize_window(u64 page_id, Gfx::IntSize) override; | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  |     virtual void did_request_maximize_window(u64 page_id) override; | 
					
						
							|  |  |  |     virtual void did_request_minimize_window(u64 page_id) override; | 
					
						
							|  |  |  |     virtual void did_request_fullscreen_window(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_request_file(u64 page_id, ByteString const& path, i32) override; | 
					
						
							|  |  |  |     virtual void did_request_color_picker(u64 page_id, Color const& current_color) override; | 
					
						
							| 
									
										
										
										
											2024-03-14 12:26:00 -04:00
										 |  |  |     virtual void did_request_file_picker(u64 page_id, Web::HTML::FileFilter const& accepted_file_types, Web::HTML::AllowMultipleFiles) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_request_select_dropdown(u64 page_id, Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> const& items) override; | 
					
						
							| 
									
										
										
										
											2024-09-12 12:56:31 -04:00
										 |  |  |     virtual void did_finish_handling_input_event(u64 page_id, Web::EventResult event_result) override; | 
					
						
							| 
									
										
										
										
											2024-10-02 12:38:10 -04:00
										 |  |  |     virtual void did_finish_text_test(u64 page_id, String const& text) override; | 
					
						
							| 
									
										
										
										
											2024-12-19 14:16:05 +00:00
										 |  |  |     virtual void did_set_test_timeout(u64 page_id, double milliseconds) override; | 
					
						
							| 
									
										
										
										
											2024-12-23 22:15:06 +01:00
										 |  |  |     virtual void did_set_browser_zoom(u64 page_id, double factor) override; | 
					
						
							| 
									
										
										
										
											2024-06-09 18:35:32 +01:00
										 |  |  |     virtual void did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> const& total_match_count) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void did_change_theme_color(u64 page_id, Gfx::Color color) override; | 
					
						
							|  |  |  |     virtual void did_insert_clipboard_entry(u64 page_id, String const& data, String const& presentation_style, String const& mime_type) override; | 
					
						
							| 
									
										
										
										
											2024-03-26 19:27:06 -04:00
										 |  |  |     virtual void did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState) override; | 
					
						
							| 
									
										
										
										
											2024-04-13 23:12:55 +02:00
										 |  |  |     virtual void did_update_navigation_buttons_state(u64 page_id, bool back_enabled, bool forward_enabled) override; | 
					
						
							| 
									
										
										
										
											2024-06-17 18:50:57 +03:00
										 |  |  |     virtual void did_allocate_backing_stores(u64 page_id, i32 front_bitmap_id, Gfx::ShareableBitmap const&, i32 back_bitmap_id, Gfx::ShareableBitmap const&) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void inspector_did_load(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  |     virtual void inspector_did_select_dom_node(u64 page_id, Web::UniqueNodeID const& node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) override; | 
					
						
							|  |  |  |     virtual void inspector_did_set_dom_node_text(u64 page_id, Web::UniqueNodeID const& node_id, String const& text) override; | 
					
						
							|  |  |  |     virtual void inspector_did_set_dom_node_tag(u64 page_id, Web::UniqueNodeID const& node_id, String const& tag) override; | 
					
						
							|  |  |  |     virtual void inspector_did_add_dom_node_attributes(u64 page_id, Web::UniqueNodeID const& node_id, Vector<Attribute> const& attributes) override; | 
					
						
							|  |  |  |     virtual void inspector_did_replace_dom_node_attribute(u64 page_id, Web::UniqueNodeID const& node_id, size_t attribute_index, Vector<Attribute> const& replacement_attributes) override; | 
					
						
							|  |  |  |     virtual void inspector_did_request_dom_tree_context_menu(u64 page_id, Web::UniqueNodeID const& node_id, Gfx::IntPoint position, String const& type, Optional<String> const& tag, Optional<size_t> const& attribute_index) override; | 
					
						
							| 
									
										
										
										
											2024-09-06 13:22:16 -04:00
										 |  |  |     virtual void inspector_did_request_cookie_context_menu(u64 page_id, size_t cookie_index, Gfx::IntPoint position) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual void inspector_did_execute_console_script(u64 page_id, String const& script) override; | 
					
						
							| 
									
										
										
										
											2024-08-19 12:11:39 -04:00
										 |  |  |     virtual void inspector_did_export_inspector_html(u64 page_id, String const& html) override; | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     virtual Messages::WebContentClient::RequestWorkerAgentResponse request_worker_agent(u64 page_id) override; | 
					
						
							| 
									
										
										
										
											2024-08-23 11:18:35 +01:00
										 |  |  |     virtual void inspector_did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> const& stylesheets) override; | 
					
						
							|  |  |  |     virtual void inspector_did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier const& identifier) override; | 
					
						
							| 
									
										
										
										
											2024-10-18 17:20:15 -04:00
										 |  |  |     virtual void did_get_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier const& identifier, URL::URL const&, String const& source) override; | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-29 09:44:49 -04:00
										 |  |  |     Optional<ViewImplementation&> view_for_page_id(u64, SourceLocation = SourceLocation::current()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     // FIXME: Does a HashMap holding references make sense?
 | 
					
						
							|  |  |  |     HashMap<u64, ViewImplementation*> m_views; | 
					
						
							| 
									
										
										
										
											2024-04-22 14:11:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ProcessHandle m_process_handle; | 
					
						
							| 
									
										
										
										
											2024-06-26 13:43:45 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static HashTable<WebContentClient*> s_clients; | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-24 15:33:18 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 13:43:45 -06:00
										 |  |  | template<CallableAs<IterationDecision, WebContentClient&> Callback> | 
					
						
							|  |  |  | void WebContentClient::for_each_client(Callback callback) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     for (auto& it : s_clients) { | 
					
						
							|  |  |  |         if (callback(*it) == IterationDecision::Break) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-24 15:33:18 +04:30
										 |  |  | } |