| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-02-20 19:03:06 +01:00
										 |  |  |  * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-08-21 15:50:31 +01:00
										 |  |  |  * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-01-12 14:35:35 +00:00
										 |  |  |  * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-10-18 12:40:14 +02:00
										 |  |  |  * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-11-03 13:30:11 -04:00
										 |  |  |  * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |  * Copyright (c) 2023-2024, Andrew Kaster <akaster@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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 18:39:00 +01:00
										 |  |  | #include <AK/Debug.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-07 16:35:10 +01:00
										 |  |  | #include <AK/JsonObject.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-08 01:46:47 +04:30
										 |  |  | #include <AK/QuickSort.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | #include <LibGfx/Bitmap.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-09 09:28:38 +02:00
										 |  |  | #include <LibGfx/Font/FontDatabase.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | #include <LibGfx/SystemTheme.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | #include <LibJS/Heap/Heap.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-28 14:20:06 +01:00
										 |  |  | #include <LibJS/Runtime/ConsoleObject.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-21 08:52:03 -05:00
										 |  |  | #include <LibWeb/ARIA/RoleType.h>
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:41:07 +01:00
										 |  |  | #include <LibWeb/Bindings/MainThreadVM.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-08 06:37:18 +02:00
										 |  |  | #include <LibWeb/CSS/StyleComputer.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | #include <LibWeb/DOM/Attr.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/CharacterData.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | #include <LibWeb/DOM/Element.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/ElementFactory.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | #include <LibWeb/DOM/Text.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | #include <LibWeb/Dump.h>
 | 
					
						
							| 
									
										
										
										
											2021-11-18 15:01:28 +01:00
										 |  |  | #include <LibWeb/HTML/BrowsingContext.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-25 13:02:47 -05:00
										 |  |  | #include <LibWeb/HTML/HTMLInputElement.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/SelectedFile.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  | #include <LibWeb/HTML/Storage.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-14 20:19:41 +02:00
										 |  |  | #include <LibWeb/HTML/TraversableNavigable.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  | #include <LibWeb/HTML/Window.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-05 16:54:53 -05:00
										 |  |  | #include <LibWeb/Infra/Strings.h>
 | 
					
						
							| 
									
										
										
										
											2023-02-25 11:04:29 +01:00
										 |  |  | #include <LibWeb/Layout/Viewport.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-27 11:39:17 +02:00
										 |  |  | #include <LibWeb/Loader/ContentFilter.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-08 01:46:47 +04:30
										 |  |  | #include <LibWeb/Loader/ProxyMappings.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-29 15:31:09 -04:00
										 |  |  | #include <LibWeb/Loader/ResourceLoader.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-06 10:36:27 -05:00
										 |  |  | #include <LibWeb/Namespace.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-11 00:03:28 +01:00
										 |  |  | #include <LibWeb/Painting/StackingContext.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-19 09:29:04 +02:00
										 |  |  | #include <LibWeb/Painting/ViewportPaintable.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-17 13:21:19 -04:00
										 |  |  | #include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-08 10:54:52 +02:00
										 |  |  | #include <LibWeb/Platform/EventLoopPlugin.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | #include <LibWebView/Attribute.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | #include <WebContent/ConnectionFromClient.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | #include <WebContent/PageClient.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | #include <WebContent/PageHost.h>
 | 
					
						
							|  |  |  | #include <WebContent/WebContentClientEndpoint.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef AK_OS_SERENITY
 | 
					
						
							|  |  |  | #    include <pthread.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace WebContent { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-08 23:05:44 +01:00
										 |  |  | ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket> socket) | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  |     : IPC::ConnectionFromClient<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket), 1) | 
					
						
							| 
									
										
										
										
											2020-06-17 18:00:18 +02:00
										 |  |  |     , m_page_host(PageHost::create(*this)) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |     m_input_event_queue_timer = Web::Platform::Timer::create_single_shot(0, [this] { process_next_input_event(); }); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::die() | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-08 10:54:52 +02:00
										 |  |  |     Web::Platform::EventLoopPlugin::the().quit(); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  | Optional<PageClient&> ConnectionFromClient::page(u64 index) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |     return m_page_host->page(index); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  | Optional<PageClient const&> ConnectionFromClient::page(u64 index) const | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |     return m_page_host->page(index); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::GetWindowHandleResponse ConnectionFromClient::get_window_handle(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-03-14 07:05:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::get_window_handle: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return String {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return page.page().top_level_traversable()->window_handle(); | 
					
						
							| 
									
										
										
										
											2023-03-14 07:05:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_window_handle(u64 page_id, String const& handle) | 
					
						
							| 
									
										
										
										
											2023-03-16 17:36:36 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_window_handle: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().top_level_traversable()->set_window_handle(handle); | 
					
						
							| 
									
										
										
										
											2023-03-16 17:36:36 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::connect_to_webdriver(u64 page_id, ByteString const& webdriver_ipc_path) | 
					
						
							| 
									
										
										
										
											2022-11-08 10:03:07 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::connect_to_webdriver: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 10:56:12 -05:00
										 |  |  |     // FIXME: Propagate this error back to the browser.
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     if (auto result = page.connect_to_webdriver(webdriver_ipc_path); result.is_error()) | 
					
						
							| 
									
										
										
										
											2022-11-08 10:03:07 -05:00
										 |  |  |         dbgln("Unable to connect to the WebDriver process: {}", result.error()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::update_system_theme(u64 page_id, Core::AnonymousBuffer const& theme_buffer) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::update_system_theme: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     Gfx::set_system_theme(theme_buffer); | 
					
						
							|  |  |  |     auto impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme_buffer); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     page.set_palette_impl(*impl); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::update_system_fonts(u64, ByteString const& default_font_query, ByteString const& fixed_width_font_query, ByteString const& window_title_font_query) | 
					
						
							| 
									
										
										
										
											2021-05-21 18:10:23 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     Gfx::FontDatabase::set_default_font_query(default_font_query); | 
					
						
							|  |  |  |     Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query); | 
					
						
							| 
									
										
										
										
											2022-07-31 18:41:07 +02:00
										 |  |  |     Gfx::FontDatabase::set_window_title_font_query(window_title_font_query); | 
					
						
							| 
									
										
										
										
											2021-05-21 18:10:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::update_screen_rects(u64 page_id, Vector<Web::DevicePixelRect> const& rects, u32 main_screen) | 
					
						
							| 
									
										
										
										
											2021-04-04 00:12:37 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::update_screen_rects: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_screen_rects(rects, main_screen); | 
					
						
							| 
									
										
										
										
											2021-04-04 00:12:37 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::load_url(u64 page_id, const URL& url) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadURL: url={}", url); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::load_url: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:14:12 +02:00
										 |  |  | #if defined(AK_OS_SERENITY)
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     ByteString process_name; | 
					
						
							| 
									
										
										
										
											2023-07-27 21:40:41 +12:00
										 |  |  |     if (url.host().has<Empty>() || url.host() == String {}) | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  |         process_name = "WebContent"; | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         process_name = ByteString::formatted("WebContent: {}", url.serialized_host().release_value_but_fixme_should_propagate_errors()); | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pthread_setname_np(pthread_self(), process_name.characters()); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:14:12 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     page.page().load(url); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::load_html(u64 page_id, ByteString const& html) | 
					
						
							| 
									
										
										
										
											2020-10-08 21:11:01 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-17 17:12:17 +02:00
										 |  |  |     dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadHTML: html={}", html); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::load_html: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().load_html(html); | 
					
						
							| 
									
										
										
										
											2020-10-08 21:11:01 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_viewport_rect(u64 page_id, Web::DevicePixelRect const& rect) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     dbgln_if(SPAM_DEBUG, "handle: WebContentServer::SetViewportRect: rect={}", rect); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_viewport_rect: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_viewport_rect(rect); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::add_backing_store(u64 page_id, i32 front_bitmap_id, Gfx::ShareableBitmap const& front_bitmap, i32 back_bitmap_id, Gfx::ShareableBitmap const& back_bitmap) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::add_backing_store: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.add_backing_store(front_bitmap_id, front_bitmap, back_bitmap_id, back_bitmap); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::ready_to_paint(u64 page_id) | 
					
						
							| 
									
										
										
										
											2024-01-07 10:35:45 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::ready_to_paint: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.ready_to_paint(); | 
					
						
							| 
									
										
										
										
											2024-01-07 10:35:45 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  | void ConnectionFromClient::process_next_input_event() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_input_event_queue.is_empty()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto event = m_input_event_queue.dequeue(); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |     auto maybe_page = page(event.page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::process_next_input_event: No page with ID {}", event.page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page->page(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto handled = event.event.visit( | 
					
						
							|  |  |  |         [&](Web::KeyEvent const& event) { | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |             switch (event.type) { | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |             case Web::KeyEvent::Type::KeyDown: | 
					
						
							|  |  |  |                 return page.handle_keydown(event.key, event.modifiers, event.code_point); | 
					
						
							|  |  |  |             case Web::KeyEvent::Type::KeyUp: | 
					
						
							|  |  |  |                 return page.handle_keyup(event.key, event.modifiers, event.code_point); | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |             VERIFY_NOT_REACHED(); | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |         [&](Web::MouseEvent const& event) { | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |             switch (event.type) { | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |             case Web::MouseEvent::Type::MouseDown: | 
					
						
							|  |  |  |                 return page.handle_mousedown(event.position, event.screen_position, event.button, event.buttons, event.modifiers); | 
					
						
							|  |  |  |             case Web::MouseEvent::Type::MouseUp: | 
					
						
							|  |  |  |                 return page.handle_mouseup(event.position, event.screen_position, event.button, event.buttons, event.modifiers); | 
					
						
							|  |  |  |             case Web::MouseEvent::Type::MouseMove: | 
					
						
							|  |  |  |                 return page.handle_mousemove(event.position, event.screen_position, event.buttons, event.modifiers); | 
					
						
							|  |  |  |             case Web::MouseEvent::Type::MouseWheel: | 
					
						
							|  |  |  |                 return page.handle_mousewheel(event.position, event.screen_position, event.button, event.buttons, event.modifiers, event.wheel_delta_x, event.wheel_delta_y); | 
					
						
							|  |  |  |             case Web::MouseEvent::Type::DoubleClick: | 
					
						
							|  |  |  |                 return page.handle_doubleclick(event.position, event.screen_position, event.button, event.buttons, event.modifiers); | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |             VERIFY_NOT_REACHED(); | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |     // We have to notify the client about coalesced events, so we do that by saying none of them were handled by the web page.
 | 
					
						
							|  |  |  |     for (size_t i = 0; i < event.coalesced_event_count; ++i) | 
					
						
							|  |  |  |         report_finished_handling_input_event(event.page_id, false); | 
					
						
							|  |  |  |     report_finished_handling_input_event(event.page_id, handled); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  |     if (!m_input_event_queue.is_empty()) | 
					
						
							|  |  |  |         m_input_event_queue_timer->start(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  | void ConnectionFromClient::key_event(u64 page_id, Web::KeyEvent const& event) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |     enqueue_input_event({ page_id, move(const_cast<Web::KeyEvent&>(event)), 0 }); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  | void ConnectionFromClient::mouse_event(u64 page_id, Web::MouseEvent const& event) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |     // OPTIMIZATION: Coalesce consecutive unprocessed mouse move and wheel events.
 | 
					
						
							| 
									
										
										
										
											2024-03-06 10:36:28 -05:00
										 |  |  |     auto event_to_coalesce = [&]() -> Web::MouseEvent const* { | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |         if (m_input_event_queue.is_empty()) | 
					
						
							| 
									
										
										
										
											2024-03-06 10:36:28 -05:00
										 |  |  |             return nullptr; | 
					
						
							|  |  |  |         if (m_input_event_queue.tail().page_id != page_id) | 
					
						
							|  |  |  |             return nullptr; | 
					
						
							| 
									
										
										
										
											2023-03-14 13:47:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |         if (event.type != Web::MouseEvent::Type::MouseMove && event.type != Web::MouseEvent::Type::MouseWheel) | 
					
						
							| 
									
										
										
										
											2024-03-06 10:36:28 -05:00
										 |  |  |             return nullptr; | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-06 10:36:28 -05:00
										 |  |  |         if (auto const* mouse_event = m_input_event_queue.tail().event.get_pointer<Web::MouseEvent>()) { | 
					
						
							|  |  |  |             if (mouse_event->type == event.type) | 
					
						
							|  |  |  |                 return mouse_event; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-06 10:36:28 -05:00
										 |  |  |         return nullptr; | 
					
						
							| 
									
										
										
										
											2023-08-04 20:52:43 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-06 10:36:28 -05:00
										 |  |  |     if (auto const* last_mouse_event = event_to_coalesce()) { | 
					
						
							|  |  |  |         auto& mutable_event = const_cast<Web::MouseEvent&>(event); | 
					
						
							|  |  |  |         mutable_event.wheel_delta_x += last_mouse_event->wheel_delta_x; | 
					
						
							|  |  |  |         mutable_event.wheel_delta_y += last_mouse_event->wheel_delta_y; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_input_event_queue.tail().event = move(mutable_event); | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |         ++m_input_event_queue.tail().coalesced_event_count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-04 20:52:43 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  |     enqueue_input_event({ page_id, move(const_cast<Web::MouseEvent&>(event)), 0 }); | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:06:32 -05:00
										 |  |  | void ConnectionFromClient::enqueue_input_event(QueuedInputEvent event) | 
					
						
							| 
									
										
										
										
											2023-03-14 13:26:06 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_input_event_queue.enqueue(move(event)); | 
					
						
							|  |  |  |     m_input_event_queue_timer->start(); | 
					
						
							| 
									
										
										
										
											2022-11-21 16:07:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::report_finished_handling_input_event(u64 page_id, bool event_was_handled) | 
					
						
							| 
									
										
										
										
											2022-11-21 16:07:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_handling_input_event(page_id, event_was_handled); | 
					
						
							| 
									
										
										
										
											2021-09-28 15:39:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::debug_request(u64 page_id, ByteString const& request, ByteString const& argument) | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::debug_request: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-14 20:19:41 +02:00
										 |  |  |     if (request == "dump-session-history") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         auto const& traversable = page.page().top_level_traversable(); | 
					
						
							| 
									
										
										
										
											2023-08-14 20:19:41 +02:00
										 |  |  |         Web::dump_tree(*traversable); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "dump-dom-tree") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* doc = page.page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |             Web::dump_tree(*doc); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "dump-layout-tree") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2023-02-25 11:04:29 +01:00
										 |  |  |             if (auto* viewport = doc->layout_node()) | 
					
						
							|  |  |  |                 Web::dump_tree(*viewport); | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-18 20:22:58 +01:00
										 |  |  |     if (request == "dump-paint-tree") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2023-03-18 20:22:58 +01:00
										 |  |  |             if (auto* paintable = doc->paintable()) | 
					
						
							|  |  |  |                 Web::dump_tree(*paintable); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-03-18 20:22:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-05 19:01:12 +01:00
										 |  |  |     if (request == "dump-stacking-context-tree") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2023-02-25 11:04:29 +01:00
										 |  |  |             if (auto* viewport = doc->layout_node()) { | 
					
						
							| 
									
										
										
										
											2023-04-20 16:01:38 +01:00
										 |  |  |                 if (auto* stacking_context = viewport->paintable_box()->stacking_context()) | 
					
						
							| 
									
										
										
										
											2022-02-05 19:01:12 +01:00
										 |  |  |                     stacking_context->dump(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2022-02-05 19:01:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "dump-style-sheets") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |             for (auto& sheet : doc->style_sheets().sheets()) { | 
					
						
							| 
									
										
										
										
											2023-01-13 20:10:00 +01:00
										 |  |  |                 if (auto result = Web::dump_sheet(sheet); result.is_error()) | 
					
						
							|  |  |  |                     dbgln("Failed to dump style sheets: {}", result.error()); | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-27 15:33:08 +03:30
										 |  |  |     if (request == "dump-all-resolved-styles") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2023-05-27 15:33:08 +03:30
										 |  |  |             Queue<Web::DOM::Node*> elements_to_visit; | 
					
						
							|  |  |  |             elements_to_visit.enqueue(doc->document_element()); | 
					
						
							|  |  |  |             while (!elements_to_visit.is_empty()) { | 
					
						
							|  |  |  |                 auto element = elements_to_visit.dequeue(); | 
					
						
							|  |  |  |                 for (auto& child : element->children_as_vector()) | 
					
						
							|  |  |  |                     elements_to_visit.enqueue(child.ptr()); | 
					
						
							|  |  |  |                 if (element->is_element()) { | 
					
						
							| 
									
										
										
										
											2024-03-05 18:10:02 -07:00
										 |  |  |                     auto styles = doc->style_computer().compute_style(*static_cast<Web::DOM::Element*>(element)); | 
					
						
							| 
									
										
										
										
											2023-05-27 15:33:08 +03:30
										 |  |  |                     dbgln("+ Element {}", element->debug_description()); | 
					
						
							|  |  |  |                     auto& properties = styles->properties(); | 
					
						
							|  |  |  |                     for (size_t i = 0; i < properties.size(); ++i) | 
					
						
							| 
									
										
										
										
											2023-08-07 22:26:17 -04:00
										 |  |  |                         dbgln("|  {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), properties[i].has_value() ? properties[i]->style->to_string() : ""_string); | 
					
						
							| 
									
										
										
										
											2023-05-27 15:33:08 +03:30
										 |  |  |                     dbgln("---"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-05-27 15:33:08 +03:30
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "collect-garbage") { | 
					
						
							| 
									
										
										
										
											2021-02-03 10:41:07 +01:00
										 |  |  |         Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "set-line-box-borders") { | 
					
						
							|  |  |  |         bool state = argument == "on"; | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         page.set_should_show_line_box_borders(state); | 
					
						
							|  |  |  |         page.page().top_level_traversable()->set_needs_display(page.page().top_level_traversable()->viewport_rect()); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-29 15:31:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "clear-cache") { | 
					
						
							| 
									
										
										
										
											2021-03-29 15:31:09 -04:00
										 |  |  |         Web::ResourceLoader::the().clear_cache(); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-03-29 15:31:09 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-14 15:13:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "spoof-user-agent") { | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         Web::ResourceLoader::the().set_user_agent(MUST(String::from_byte_string(argument))); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-04-14 15:13:51 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-12 02:10:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (request == "same-origin-policy") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         page.page().set_same_origin_policy_enabled(argument == "on"); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-09-12 02:10:43 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-30 23:29:15 +01:00
										 |  |  |     if (request == "scripting") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         page.page().set_is_scripting_enabled(argument == "on"); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2022-03-30 23:29:15 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-15 02:01:13 +02:00
										 |  |  |     if (request == "block-pop-ups") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         page.page().set_should_block_pop_ups(argument == "on"); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2022-11-15 02:01:13 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  |     if (request == "dump-local-storage") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* document = page.page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2024-03-10 08:41:18 +01:00
										 |  |  |             document->window()->local_storage().release_value_but_fixme_should_propagate_errors()->dump(); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:12:17 +01:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-09-12 16:36:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (request == "load-reference-page") { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |         if (auto* document = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2023-09-12 16:36:10 +01:00
										 |  |  |             auto maybe_link = document->query_selector("link[rel=match]"sv); | 
					
						
							|  |  |  |             if (maybe_link.is_error() || !maybe_link.value()) { | 
					
						
							|  |  |  |                 // To make sure that we fail the ref-test if the link is missing, load the error page.
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |                 load_html(page_id, "<h1>Failed to find <link rel="match" /> in ref test page!</h1> Make sure you added it."); | 
					
						
							| 
									
										
										
										
											2023-09-12 16:36:10 +01:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 auto link = maybe_link.release_value(); | 
					
						
							| 
									
										
										
										
											2024-01-16 19:04:45 +01:00
										 |  |  |                 auto url = document->parse_url(link->get_attribute_value(Web::HTML::AttributeNames::href)); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |                 load_url(page_id, url); | 
					
						
							| 
									
										
										
										
											2023-09-12 16:36:10 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::get_source(u64 page_id) | 
					
						
							| 
									
										
										
										
											2021-02-23 06:14:12 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::get_source: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_get_source(page_id, doc->url(), doc->source().to_byte_string()); | 
					
						
							| 
									
										
										
										
											2021-02-23 06:14:12 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::inspect_dom_tree(u64 page_id) | 
					
						
							| 
									
										
										
										
											2021-06-07 16:35:10 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::inspect_dom_tree: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_inspect_dom_tree(page_id, doc->dump_dom_tree_as_json().to_byte_string()); | 
					
						
							| 
									
										
										
										
											2021-06-07 16:35:10 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::inspect_dom_node(u64 page_id, i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::inspect_dom_node: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto& top_context = page.page().top_level_browsing_context(); | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     top_context.for_each_in_inclusive_subtree([&](auto& ctx) { | 
					
						
							|  |  |  |         if (ctx.active_document() != nullptr) { | 
					
						
							| 
									
										
										
										
											2023-06-02 22:50:11 +02:00
										 |  |  |             ctx.active_document()->set_inspected_node(nullptr, {}); | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |         return IterationDecision::Continue; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-02 14:30:00 +01:00
										 |  |  |     Web::DOM::Node* node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2022-07-05 11:56:41 +01:00
										 |  |  |     // Note: Nodes without layout (aka non-visible nodes, don't have style computed)
 | 
					
						
							|  |  |  |     if (!node || !node->layout_node()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 22:50:11 +02:00
										 |  |  |     node->document().set_inspected_node(node, pseudo_element); | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |     if (node->is_element()) { | 
					
						
							|  |  |  |         auto& element = verify_cast<Web::DOM::Element>(*node); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |         if (!element.computed_css_values()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |             async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> ByteString { | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |             StringBuilder builder; | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02:00
										 |  |  |             auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |             properties.for_each_property([&](auto property_id, auto& value) { | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |                 MUST(serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string().to_byte_string())); | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |             }); | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02:00
										 |  |  |             MUST(serializer.finish()); | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |             return builder.to_byte_string(); | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         auto serialize_custom_properties_json = [](Web::DOM::Element const& element, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) -> ByteString { | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |             StringBuilder builder; | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02:00
										 |  |  |             auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |             HashTable<FlyString> seen_properties; | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             auto const* element_to_check = &element; | 
					
						
							|  |  |  |             while (element_to_check) { | 
					
						
							| 
									
										
										
										
											2023-05-17 17:05:36 +02:00
										 |  |  |                 for (auto const& property : element_to_check->custom_properties(pseudo_element)) { | 
					
						
							| 
									
										
										
										
											2022-02-10 17:04:31 +01:00
										 |  |  |                     if (!seen_properties.contains(property.key)) { | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |                         seen_properties.set(property.key); | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |                         MUST(serializer.add(property.key, property.value.value->to_string())); | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 element_to_check = element_to_check->parent_element(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02:00
										 |  |  |             MUST(serializer.finish()); | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |             return builder.to_byte_string(); | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         auto serialize_node_box_sizing_json = [](Web::Layout::Node const* layout_node) -> ByteString { | 
					
						
							| 
									
										
										
										
											2022-03-10 11:24:55 +00:00
										 |  |  |             if (!layout_node || !layout_node->is_box()) { | 
					
						
							| 
									
										
										
										
											2022-03-10 11:29:09 +00:00
										 |  |  |                 return "{}"; | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-03-10 11:24:55 +00:00
										 |  |  |             auto* box = static_cast<Web::Layout::Box const*>(layout_node); | 
					
						
							|  |  |  |             auto box_model = box->box_model(); | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |             StringBuilder builder; | 
					
						
							|  |  |  |             auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); | 
					
						
							| 
									
										
										
										
											2023-06-12 21:37:35 +03:00
										 |  |  |             MUST(serializer.add("padding_top"sv, box_model.padding.top.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("padding_right"sv, box_model.padding.right.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("padding_left"sv, box_model.padding.left.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_top"sv, box_model.margin.top.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_right"sv, box_model.margin.right.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_left"sv, box_model.margin.left.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("border_top"sv, box_model.border.top.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("border_right"sv, box_model.border.right.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("border_bottom"sv, box_model.border.bottom.to_double())); | 
					
						
							|  |  |  |             MUST(serializer.add("border_left"sv, box_model.border.left.to_double())); | 
					
						
							| 
									
										
										
										
											2023-04-20 16:00:42 +01:00
										 |  |  |             if (auto* paintable_box = box->paintable_box()) { | 
					
						
							| 
									
										
										
										
											2023-06-12 21:37:35 +03:00
										 |  |  |                 MUST(serializer.add("content_width"sv, paintable_box->content_width().to_double())); | 
					
						
							|  |  |  |                 MUST(serializer.add("content_height"sv, paintable_box->content_height().to_double())); | 
					
						
							| 
									
										
										
										
											2022-03-09 23:53:41 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |                 MUST(serializer.add("content_width"sv, 0)); | 
					
						
							|  |  |  |                 MUST(serializer.add("content_height"sv, 0)); | 
					
						
							| 
									
										
										
										
											2022-03-09 23:53:41 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |             MUST(serializer.finish()); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |             return builder.to_byte_string(); | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         auto serialize_aria_properties_state_json = [](Web::DOM::Element const& element) -> ByteString { | 
					
						
							| 
									
										
										
										
											2023-05-21 08:52:03 -05:00
										 |  |  |             auto role_name = element.role_or_default(); | 
					
						
							|  |  |  |             if (!role_name.has_value()) { | 
					
						
							|  |  |  |                 return ""; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             auto aria_data = MUST(Web::ARIA::AriaData::build_data(element)); | 
					
						
							|  |  |  |             auto role = MUST(Web::ARIA::RoleType::build_role_object(role_name.value(), element.is_focusable(), *aria_data)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             StringBuilder builder; | 
					
						
							|  |  |  |             auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); | 
					
						
							|  |  |  |             MUST(role->serialize_as_json(serializer)); | 
					
						
							|  |  |  |             MUST(serializer.finish()); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |             return builder.to_byte_string(); | 
					
						
							| 
									
										
										
										
											2023-05-21 08:52:03 -05:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  |         if (pseudo_element.has_value()) { | 
					
						
							|  |  |  |             auto pseudo_element_node = element.get_pseudo_element_node(pseudo_element.value()); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |             if (!pseudo_element_node) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |                 async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // FIXME: Pseudo-elements only exist as Layout::Nodes, which don't have style information
 | 
					
						
							|  |  |  |             //        in a format we can use. So, we run the StyleComputer again to get the specified
 | 
					
						
							|  |  |  |             //        values, and have to ignore the computed values and custom properties.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 18:10:02 -07:00
										 |  |  |             auto pseudo_element_style = page.page().focused_context().active_document()->style_computer().compute_style(element, pseudo_element); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |             ByteString computed_values = serialize_json(pseudo_element_style); | 
					
						
							|  |  |  |             ByteString resolved_values = "{}"; | 
					
						
							|  |  |  |             ByteString custom_properties_json = serialize_custom_properties_json(element, pseudo_element); | 
					
						
							|  |  |  |             ByteString node_box_sizing_json = serialize_node_box_sizing_json(pseudo_element_node.ptr()); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |             async_did_inspect_dom_node(page_id, true, move(computed_values), move(resolved_values), move(custom_properties_json), move(node_box_sizing_json), {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         ByteString computed_values = serialize_json(*element.computed_css_values()); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |         ByteString resolved_values = serialize_json(element.resolved_css_values()); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         ByteString custom_properties_json = serialize_custom_properties_json(element, {}); | 
					
						
							|  |  |  |         ByteString node_box_sizing_json = serialize_node_box_sizing_json(element.layout_node()); | 
					
						
							|  |  |  |         ByteString aria_properties_state_json = serialize_aria_properties_state_json(element); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_inspect_dom_node(page_id, true, move(computed_values), move(resolved_values), move(custom_properties_json), move(node_box_sizing_json), move(aria_properties_state_json)); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:30:27 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {}); | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::inspect_accessibility_tree(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-12-30 09:06:22 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::inspect_accessibility_tree: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (auto* doc = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_inspect_accessibility_tree(page_id, doc->dump_accessibility_tree_as_json().to_byte_string()); | 
					
						
							| 
									
										
										
										
											2023-12-30 09:06:22 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::get_hovered_node_id(u64 page_id) | 
					
						
							| 
									
										
										
										
											2021-08-27 17:33:10 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::get_hovered_node_id: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-30 09:42:24 -05:00
										 |  |  |     i32 node_id = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     if (auto* document = page.page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2023-12-30 09:42:24 -05:00
										 |  |  |         if (auto* hovered_node = document->hovered_node()) | 
					
						
							|  |  |  |             node_id = hovered_node->unique_id(); | 
					
						
							| 
									
										
										
										
											2021-08-27 17:33:10 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-30 09:42:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_get_hovered_node_id(page_id, node_id); | 
					
						
							| 
									
										
										
										
											2021-08-27 17:33:10 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_dom_node_text(u64 page_id, i32 node_id, String const& text) | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node || (!dom_node->is_text() && !dom_node->is_comment())) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto& character_data = static_cast<Web::DOM::CharacterData&>(*dom_node); | 
					
						
							|  |  |  |     character_data.set_data(text); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, character_data.unique_id()); | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_dom_node_tag(u64 page_id, i32 node_id, String const& name) | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node || !dom_node->is_element() || !dom_node->parent()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto& element = static_cast<Web::DOM::Element&>(*dom_node); | 
					
						
							|  |  |  |     auto new_element = Web::DOM::create_element(element.document(), name, element.namespace_uri(), element.prefix(), element.is_value()).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     element.for_each_attribute([&](auto const& attribute) { | 
					
						
							| 
									
										
										
										
											2024-01-03 12:47:38 +13:00
										 |  |  |         new_element->set_attribute_value(attribute.local_name(), attribute.value(), attribute.prefix(), attribute.namespace_uri()); | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (auto* child_node = element.first_child()) { | 
					
						
							|  |  |  |         MUST(element.remove_child(*child_node)); | 
					
						
							|  |  |  |         MUST(new_element->append_child(*child_node)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     element.parent()->replace_child(*new_element, element).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, new_element->unique_id()); | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::add_dom_node_attributes(u64 page_id, i32 node_id, Vector<WebView::Attribute> const& attributes) | 
					
						
							| 
									
										
										
										
											2023-12-05 16:49:47 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node || !dom_node->is_element()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-05 16:49:47 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-05 16:49:47 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto& element = static_cast<Web::DOM::Element&>(*dom_node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto const& attribute : attributes) | 
					
						
							|  |  |  |         element.set_attribute(attribute.name, attribute.value).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, element.unique_id()); | 
					
						
							| 
									
										
										
										
											2023-12-05 16:49:47 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::replace_dom_node_attribute(u64 page_id, i32 node_id, String const& name, Vector<WebView::Attribute> const& replacement_attributes) | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node || !dom_node->is_element()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto& element = static_cast<Web::DOM::Element&>(*dom_node); | 
					
						
							| 
									
										
										
										
											2023-12-05 16:54:53 -05:00
										 |  |  |     bool should_remove_attribute = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto const& attribute : replacement_attributes) { | 
					
						
							|  |  |  |         if (should_remove_attribute && Web::Infra::is_ascii_case_insensitive_match(name, attribute.name)) | 
					
						
							|  |  |  |             should_remove_attribute = false; | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         element.set_attribute(attribute.name, attribute.value).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2023-12-05 16:54:53 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (should_remove_attribute) | 
					
						
							|  |  |  |         element.remove_attribute(name); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, element.unique_id()); | 
					
						
							| 
									
										
										
										
											2023-11-19 10:42:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::create_child_element(u64 page_id, i32 node_id) | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto element = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  |     dom_node->append_child(element).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, element->unique_id()); | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::create_child_text_node(u64 page_id, i32 node_id) | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto text_node = dom_node->heap().allocate<Web::DOM::Text>(dom_node->realm(), dom_node->document(), "text"_string); | 
					
						
							|  |  |  |     dom_node->append_child(text_node).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, text_node->unique_id()); | 
					
						
							| 
									
										
										
										
											2023-12-07 11:00:57 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::clone_dom_node(u64 page_id, i32 node_id) | 
					
						
							| 
									
										
										
										
											2023-12-07 11:12:43 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node || !dom_node->parent_node()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-07 11:12:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto dom_node_clone = dom_node->clone_node(nullptr, true); | 
					
						
							|  |  |  |     dom_node->parent_node()->insert_before(dom_node_clone, dom_node->next_sibling()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, dom_node_clone->unique_id()); | 
					
						
							| 
									
										
										
										
											2023-12-07 11:12:43 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::remove_dom_node(u64 page_id, i32 node_id) | 
					
						
							| 
									
										
										
										
											2023-12-05 14:59:54 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::remove_dom_node: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* active_document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!active_document) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-05 14:59:54 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-05 14:59:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     if (!dom_node) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_finish_editing_dom_node(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-05 14:59:54 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* previous_dom_node = dom_node->previous_sibling(); | 
					
						
							|  |  |  |     if (!previous_dom_node) | 
					
						
							|  |  |  |         previous_dom_node = dom_node->parent(); | 
					
						
							| 
									
										
										
										
											2023-12-05 14:59:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dom_node->remove(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still
 | 
					
						
							|  |  |  |     //        remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
 | 
					
						
							|  |  |  |     //        which really hurts performance.
 | 
					
						
							|  |  |  |     active_document->force_layout(); | 
					
						
							| 
									
										
										
										
											2023-12-30 10:08:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_finish_editing_dom_node(page_id, previous_dom_node->unique_id()); | 
					
						
							| 
									
										
										
										
											2023-12-05 14:59:54 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::get_dom_node_html(u64 page_id, i32 node_id) | 
					
						
							| 
									
										
										
										
											2023-12-06 10:36:27 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							|  |  |  |     if (!dom_node) | 
					
						
							| 
									
										
										
										
											2023-12-30 14:32:50 -05:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2023-12-06 10:36:27 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: Implement Element's outerHTML attribute.
 | 
					
						
							|  |  |  |     auto container = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  |     container->append_child(dom_node->clone_node(nullptr, true)).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-30 14:32:50 -05:00
										 |  |  |     auto html = container->inner_html().release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_get_dom_node_html(page_id, move(html)); | 
					
						
							| 
									
										
										
										
											2023-09-17 16:11:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::take_document_screenshot(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-09-17 16:11:16 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::take_document_screenshot: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2023-12-31 09:51:02 -05:00
										 |  |  |     if (!document || !document->document_element()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_take_screenshot(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-31 09:51:02 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-11-05 00:09:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto const& content_size = page.content_size(); | 
					
						
							| 
									
										
										
										
											2022-11-25 17:07:19 +00:00
										 |  |  |     Web::DevicePixelRect rect { { 0, 0 }, content_size }; | 
					
						
							| 
									
										
										
										
											2022-11-05 00:09:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-20 20:06:05 +01:00
										 |  |  |     auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     page.paint(rect, *bitmap); | 
					
						
							| 
									
										
										
										
											2022-11-05 00:09:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_take_screenshot(page_id, bitmap->to_shareable_bitmap()); | 
					
						
							| 
									
										
										
										
											2022-11-05 00:09:41 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::take_dom_node_screenshot(u64 page_id, i32 node_id) | 
					
						
							| 
									
										
										
										
											2023-12-06 11:51:44 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::take_dom_node_screenshot: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 11:51:44 -05:00
										 |  |  |     auto* dom_node = Web::DOM::Node::from_unique_id(node_id); | 
					
						
							| 
									
										
										
										
											2023-12-31 09:51:02 -05:00
										 |  |  |     if (!dom_node || !dom_node->paintable_box()) { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |         async_did_take_screenshot(page_id, {}); | 
					
						
							| 
									
										
										
										
											2023-12-31 09:51:02 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-06 11:51:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto rect = page.page().enclosing_device_rect(dom_node->paintable_box()->absolute_border_box_rect()); | 
					
						
							| 
									
										
										
										
											2023-12-06 11:51:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     page.paint(rect, *bitmap, { .paint_overlay = Web::PaintOptions::PaintOverlay::No }); | 
					
						
							| 
									
										
										
										
											2023-12-06 11:51:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_take_screenshot(page_id, bitmap->to_shareable_bitmap()); | 
					
						
							| 
									
										
										
										
											2023-12-06 11:51:44 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::DumpGcGraphResponse ConnectionFromClient::dump_gc_graph(u64) | 
					
						
							| 
									
										
										
										
											2023-12-12 13:25:06 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     auto gc_graph_json = Web::Bindings::main_thread_vm().heap().dump_graph(); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     return MUST(String::from_byte_string(gc_graph_json.to_byte_string())); | 
					
						
							| 
									
										
										
										
											2023-12-12 13:25:06 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text(u64 page_id) | 
					
						
							| 
									
										
										
										
											2021-07-14 08:32:55 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::get_selected_text: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return ByteString {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return page.page().focused_context().selected_text().to_byte_string(); | 
					
						
							| 
									
										
										
										
											2021-07-14 08:32:55 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::select_all(u64 page_id) | 
					
						
							| 
									
										
										
										
											2021-07-14 08:53:55 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::select_all: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().focused_context().select_all(); | 
					
						
							| 
									
										
										
										
											2021-07-14 08:53:55 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_layout_tree(u64 page_id) | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::dump_layout_tree: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return ByteString { "(no page)" }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  |     if (!document) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no DOM tree)" }; | 
					
						
							| 
									
										
										
										
											2023-04-25 17:58:26 +02:00
										 |  |  |     document->update_layout(); | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  |     auto* layout_root = document->layout_node(); | 
					
						
							|  |  |  |     if (!layout_root) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no layout tree)" }; | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     Web::dump_tree(builder, *layout_root); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     return builder.to_byte_string(); | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::DumpPaintTreeResponse ConnectionFromClient::dump_paint_tree(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-08-03 09:59:12 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::dump_paint_tree: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return ByteString { "(no page)" }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2023-08-03 09:59:12 +02:00
										 |  |  |     if (!document) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no DOM tree)" }; | 
					
						
							| 
									
										
										
										
											2023-08-03 09:59:12 +02:00
										 |  |  |     document->update_layout(); | 
					
						
							|  |  |  |     auto* layout_root = document->layout_node(); | 
					
						
							|  |  |  |     if (!layout_root) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no layout tree)" }; | 
					
						
							| 
									
										
										
										
											2023-08-03 09:59:12 +02:00
										 |  |  |     if (!layout_root->paintable()) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no paint tree)" }; | 
					
						
							| 
									
										
										
										
											2023-08-03 09:59:12 +02:00
										 |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     Web::dump_tree(builder, *layout_root->paintable()); | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     return builder.to_byte_string(); | 
					
						
							| 
									
										
										
										
											2023-08-03 09:59:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::DumpTextResponse ConnectionFromClient::dump_text(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-05-28 20:54:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::dump_text: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return ByteString { "(no page)" }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2023-05-28 20:54:33 +02:00
										 |  |  |     if (!document) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no DOM tree)" }; | 
					
						
							| 
									
										
										
										
											2023-05-28 20:54:33 +02:00
										 |  |  |     if (!document->body()) | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |         return ByteString { "(no body)" }; | 
					
						
							| 
									
										
										
										
											2023-05-28 20:54:33 +02:00
										 |  |  |     return document->body()->inner_text(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_content_filters(u64, Vector<String> const& filters) | 
					
						
							| 
									
										
										
										
											2021-09-27 11:39:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-21 07:36:40 -04:00
										 |  |  |     Web::ContentFilter::the().set_patterns(filters).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:39:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_autoplay_allowed_on_all_websites(u64) | 
					
						
							| 
									
										
										
										
											2023-04-17 13:21:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     auto& autoplay_allowlist = Web::PermissionsPolicy::AutoplayAllowlist::the(); | 
					
						
							|  |  |  |     autoplay_allowlist.enable_globally(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_autoplay_allowlist(u64, Vector<String> const& allowlist) | 
					
						
							| 
									
										
										
										
											2023-04-17 13:21:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     auto& autoplay_allowlist = Web::PermissionsPolicy::AutoplayAllowlist::the(); | 
					
						
							|  |  |  |     autoplay_allowlist.enable_for_origins(allowlist).release_value_but_fixme_should_propagate_errors(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_proxy_mappings(u64, Vector<ByteString> const& proxies, HashMap<ByteString, size_t> const& mappings) | 
					
						
							| 
									
										
										
										
											2022-04-08 01:46:47 +04:30
										 |  |  | { | 
					
						
							|  |  |  |     auto keys = mappings.keys(); | 
					
						
							|  |  |  |     quick_sort(keys, [&](auto& a, auto& b) { return a.length() < b.length(); }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     OrderedHashMap<ByteString, size_t> sorted_mappings; | 
					
						
							| 
									
										
										
										
											2022-04-08 01:46:47 +04:30
										 |  |  |     for (auto& key : keys) { | 
					
						
							|  |  |  |         auto value = *mappings.get(key); | 
					
						
							|  |  |  |         if (value >= proxies.size()) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         sorted_mappings.set(key, value); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Web::ProxyMappings::the().set_mappings(proxies, move(sorted_mappings)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_preferred_color_scheme(u64 page_id, Web::CSS::PreferredColorScheme const& color_scheme) | 
					
						
							| 
									
										
										
										
											2021-10-26 17:00:10 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_preferred_color_scheme: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_preferred_color_scheme(color_scheme); | 
					
						
							| 
									
										
										
										
											2021-10-26 17:00:10 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_has_focus(u64 page_id, bool has_focus) | 
					
						
							| 
									
										
										
										
											2022-02-06 19:03:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_has_focus: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_has_focus(has_focus); | 
					
						
							| 
									
										
										
										
											2022-02-06 19:03:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_is_scripting_enabled(u64 page_id, bool is_scripting_enabled) | 
					
						
							| 
									
										
										
										
											2022-03-30 23:23:14 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_is_scripting_enabled: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_is_scripting_enabled(is_scripting_enabled); | 
					
						
							| 
									
										
										
										
											2022-03-30 23:23:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_device_pixels_per_css_pixel(u64 page_id, float device_pixels_per_css_pixel) | 
					
						
							| 
									
										
										
										
											2023-01-12 14:35:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_device_pixels_per_css_pixel: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_device_pixels_per_css_pixel(device_pixels_per_css_pixel); | 
					
						
							| 
									
										
										
										
											2023-01-12 14:35:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_window_position(u64 page_id, Web::DevicePixelPoint position) | 
					
						
							| 
									
										
										
										
											2022-11-01 14:55:53 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_window_position: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_window_position(position); | 
					
						
							| 
									
										
										
										
											2022-11-01 14:55:53 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_window_size(u64 page_id, Web::DevicePixelSize size) | 
					
						
							| 
									
										
										
										
											2022-11-01 14:55:53 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_window_size: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.set_window_size(size); | 
					
						
							| 
									
										
										
										
											2022-11-01 14:55:53 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient::get_local_storage_entries(u64 page_id) | 
					
						
							| 
									
										
										
										
											2022-04-02 00:14:04 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::get_local_storage_entries: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return OrderedHashMap<String, String> {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2024-03-10 08:41:18 +01:00
										 |  |  |     auto local_storage = document->window()->local_storage().release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2022-04-02 00:14:04 +03:00
										 |  |  |     return local_storage->map(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-05-07 22:45:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClient::get_session_storage_entries(u64 page_id) | 
					
						
							| 
									
										
										
										
											2022-05-07 22:45:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::get_session_storage_entries: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return OrderedHashMap<String, String> {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto* document = page.page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2024-03-10 08:41:18 +01:00
										 |  |  |     auto session_storage = document->window()->session_storage().release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2022-05-07 22:45:43 +02:00
										 |  |  |     return session_storage->map(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::handle_file_return(u64, i32 error, Optional<IPC::File> const& file, i32 request_id) | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-02-02 07:29:19 -05:00
										 |  |  |     auto file_request = m_requested_files.take(request_id); | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-30 16:35:47 -05:00
										 |  |  |     VERIFY(file_request.has_value()); | 
					
						
							|  |  |  |     VERIFY(file_request.value().on_file_request_finish); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     file_request.value().on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() }); | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::request_file(u64 page_id, Web::FileRequest file_request) | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     i32 const id = last_id++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-30 16:35:47 -05:00
										 |  |  |     auto path = file_request.path(); | 
					
						
							|  |  |  |     m_requested_files.set(id, move(file_request)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     async_did_request_file(page_id, path, id); | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-09-19 20:50:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_system_visibility_state(u64 page_id, bool visible) | 
					
						
							| 
									
										
										
										
											2022-09-19 20:50:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_system_visibility_state: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().top_level_traversable()->set_system_visibility_state( | 
					
						
							| 
									
										
										
										
											2022-09-19 20:50:33 +02:00
										 |  |  |         visible | 
					
						
							|  |  |  |             ? Web::HTML::VisibilityState::Visible | 
					
						
							|  |  |  |             : Web::HTML::VisibilityState::Hidden); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::js_console_input(u64 page_id, ByteString const& js_source) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::js_console_input: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.js_console_input(js_source); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConnectionFromClient::run_javascript(u64 page_id, ByteString const& js_source) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::run_javascript: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.run_javascript(js_source); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConnectionFromClient::js_console_request_messages(u64 page_id, i32 start_index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::js_console_request_messages: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.js_console_request_messages(start_index); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConnectionFromClient::alert_closed(u64 page_id) | 
					
						
							| 
									
										
										
										
											2022-11-15 15:49:36 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::alert_closed: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().alert_closed(); | 
					
						
							| 
									
										
										
										
											2022-11-15 15:49:36 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::confirm_closed(u64 page_id, bool accepted) | 
					
						
							| 
									
										
										
										
											2022-11-15 15:49:36 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::confirm_closed: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().confirm_closed(accepted); | 
					
						
							| 
									
										
										
										
											2022-11-15 15:49:36 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::prompt_closed(u64 page_id, Optional<String> const& response) | 
					
						
							| 
									
										
										
										
											2022-11-15 15:49:36 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::prompt_closed: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().prompt_closed(response); | 
					
						
							| 
									
										
										
										
											2022-11-15 15:49:36 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::color_picker_update(u64 page_id, Optional<Color> const& picked_color, Web::HTML::ColorPickerUpdateState const& state) | 
					
						
							| 
									
										
										
										
											2023-09-04 11:32:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::color_picker_update: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().color_picker_update(picked_color, state); | 
					
						
							| 
									
										
										
										
											2023-09-04 11:32:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-25 13:02:47 -05:00
										 |  |  | void ConnectionFromClient::file_picker_closed(u64 page_id, Vector<Web::HTML::SelectedFile> const& selected_files) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::color_picker_update: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  |     page.page().file_picker_closed(const_cast<Vector<Web::HTML::SelectedFile>&>(selected_files)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::select_dropdown_closed(u64 page_id, Optional<String> const& value) | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::select_dropdown_closed: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().select_dropdown_closed(value); | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::toggle_media_play_state(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-05-15 11:17:58 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::toggle_media_play_state: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().toggle_media_play_state().release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2023-05-15 11:17:58 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::toggle_media_mute_state(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-06-16 11:29:54 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::toggle_media_mute_state: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().toggle_media_mute_state(); | 
					
						
							| 
									
										
										
										
											2023-06-16 11:29:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::toggle_media_loop_state(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-05-15 11:17:58 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::toggle_media_loop_state: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().toggle_media_loop_state().release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2023-05-15 11:17:58 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::toggle_media_controls_state(u64 page_id) | 
					
						
							| 
									
										
										
										
											2023-05-15 11:17:58 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::toggle_media_controls_state: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().toggle_media_controls_state().release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2023-05-15 11:17:58 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::set_user_style(u64 page_id, String const& source) | 
					
						
							| 
									
										
										
										
											2023-08-21 15:50:31 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-12 17:39:20 -07:00
										 |  |  |     auto maybe_page = page(page_id); | 
					
						
							|  |  |  |     if (!maybe_page.has_value()) { | 
					
						
							|  |  |  |         dbgln("ConnectionFromClient::set_user_style: No page with ID {}", page_id); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& page = maybe_page.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page.page().set_user_style(source); | 
					
						
							| 
									
										
										
										
											2023-08-21 15:50:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void ConnectionFromClient::enable_inspector_prototype(u64) | 
					
						
							| 
									
										
										
										
											2023-11-23 12:22:23 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     Web::HTML::Window::set_inspector_object_exposed(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } |