| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-03-09 23:53:41 +01:00
										 |  |  |  * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-09-03 11:14:37 +01:00
										 |  |  |  * Copyright (c) 2021, Sam Atkins <atkinssj@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-02-27 21:44:49 -06:00
										 |  |  | #include <LibJS/Console.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | #include <LibJS/Heap/Heap.h>
 | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | #include <LibJS/Interpreter.h>
 | 
					
						
							|  |  |  | #include <LibJS/Parser.h>
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:41:07 +01:00
										 |  |  | #include <LibWeb/Bindings/MainThreadVM.h>
 | 
					
						
							| 
									
										
										
										
											2021-04-15 10:36:20 -04:00
										 |  |  | #include <LibWeb/Cookie/ParsedCookie.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Dump.h>
 | 
					
						
							| 
									
										
										
										
											2021-11-18 15:01:28 +01:00
										 |  |  | #include <LibWeb/HTML/BrowsingContext.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  | #include <LibWeb/HTML/Scripting/ClassicScript.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  | #include <LibWeb/HTML/Storage.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  | #include <LibWeb/HTML/Window.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-08 11:27:46 +02:00
										 |  |  | #include <LibWeb/Layout/InitialContainingBlock.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>
 | 
					
						
							| 
									
										
										
										
											2022-03-10 23:13:37 +01:00
										 |  |  | #include <LibWeb/Painting/PaintableBox.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-11 00:03:28 +01:00
										 |  |  | #include <LibWeb/Painting/StackingContext.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | #include <WebContent/ConnectionFromClient.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | #include <WebContent/PageHost.h>
 | 
					
						
							|  |  |  | #include <WebContent/WebContentClientEndpoint.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  | #include <pthread.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace WebContent { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket) | 
					
						
							|  |  |  |     : 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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  |     m_paint_flush_timer = Core::Timer::create_single_shot(0, [this] { flush_pending_paint_requests(); }); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-11-29 17:29:23 +01:00
										 |  |  |     Core::EventLoop::current().quit(0); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | Web::Page& ConnectionFromClient::page() | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_page_host->page(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | Web::Page const& ConnectionFromClient::page() const | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_page_host->page(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::update_system_theme(Core::AnonymousBuffer const& theme_buffer) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     Gfx::set_system_theme(theme_buffer); | 
					
						
							|  |  |  |     auto impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme_buffer); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  |     m_page_host->set_palette_impl(*impl); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-31 18:41:07 +02:00
										 |  |  | void ConnectionFromClient::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query, String 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::update_screen_rects(Vector<Gfx::IntRect> const& rects, u32 main_screen) | 
					
						
							| 
									
										
										
										
											2021-04-04 00:12:37 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-13 06:16:06 -06:00
										 |  |  |     m_page_host->set_screen_rects(rects, main_screen); | 
					
						
							| 
									
										
										
										
											2021-04-04 00:12:37 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::load_url(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); | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     String process_name; | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (url.host().is_empty()) | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  |         process_name = "WebContent"; | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |         process_name = String::formatted("WebContent: {}", url.host()); | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pthread_setname_np(pthread_self(), process_name.characters()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     page().load(url); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::load_html(String const& html, const URL& url) | 
					
						
							| 
									
										
										
										
											2020-10-08 21:11:01 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadHTML: html={}, url={}", html, url); | 
					
						
							|  |  |  |     page().load_html(html, url); | 
					
						
							| 
									
										
										
										
											2020-10-08 21:11:01 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::set_viewport_rect(Gfx::IntRect 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); | 
					
						
							|  |  |  |     m_page_host->set_viewport_rect(rect); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::add_backing_store(i32 backing_store_id, Gfx::ShareableBitmap const& bitmap) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     m_backing_stores.set(backing_store_id, *bitmap.bitmap()); | 
					
						
							| 
									
										
										
										
											2021-01-16 23:15:32 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::remove_backing_store(i32 backing_store_id) | 
					
						
							| 
									
										
										
										
											2021-01-16 23:15:32 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     m_backing_stores.remove(backing_store_id); | 
					
						
							| 
									
										
										
										
											2022-04-05 17:22:54 +02:00
										 |  |  |     m_pending_paint_requests.remove_all_matching([backing_store_id](auto& pending_repaint_request) { return pending_repaint_request.bitmap_id == backing_store_id; }); | 
					
						
							| 
									
										
										
										
											2021-01-16 23:15:32 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::paint(Gfx::IntRect const& content_rect, i32 backing_store_id) | 
					
						
							| 
									
										
										
										
											2021-01-16 23:15:32 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  |     for (auto& pending_paint : m_pending_paint_requests) { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |         if (pending_paint.bitmap_id == backing_store_id) { | 
					
						
							|  |  |  |             pending_paint.content_rect = content_rect; | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     auto it = m_backing_stores.find(backing_store_id); | 
					
						
							| 
									
										
										
										
											2021-01-16 23:15:32 +01:00
										 |  |  |     if (it == m_backing_stores.end()) { | 
					
						
							|  |  |  |         did_misbehave("Client requested paint with backing store ID"); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-16 23:15:32 +01:00
										 |  |  |     auto& bitmap = *it->value; | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     m_pending_paint_requests.append({ content_rect, bitmap, backing_store_id }); | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  |     m_paint_flush_timer->start(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::flush_pending_paint_requests() | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     for (auto& pending_paint : m_pending_paint_requests) { | 
					
						
							|  |  |  |         m_page_host->paint(pending_paint.content_rect, *pending_paint.bitmap); | 
					
						
							| 
									
										
										
										
											2021-05-03 13:33:59 +02:00
										 |  |  |         async_did_paint(pending_paint.content_rect, pending_paint.bitmap_id); | 
					
						
							| 
									
										
										
										
											2020-07-05 16:26:15 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     m_pending_paint_requests.clear(); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::mouse_down(Gfx::IntPoint const& position, unsigned int button, [[maybe_unused]] unsigned int buttons, unsigned int modifiers) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     page().handle_mousedown(position, button, modifiers); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::mouse_move(Gfx::IntPoint const& position, [[maybe_unused]] unsigned int button, unsigned int buttons, unsigned int modifiers) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     page().handle_mousemove(position, buttons, modifiers); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::mouse_up(Gfx::IntPoint const& position, unsigned int button, [[maybe_unused]] unsigned int buttons, unsigned int modifiers) | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     page().handle_mouseup(position, button, modifiers); | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::mouse_wheel(Gfx::IntPoint const& position, unsigned int button, [[maybe_unused]] unsigned int buttons, unsigned int modifiers, i32 wheel_delta_x, i32 wheel_delta_y) | 
					
						
							| 
									
										
										
										
											2021-02-22 19:45:41 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-12-13 23:22:28 +01:00
										 |  |  |     page().handle_mousewheel(position, button, modifiers, wheel_delta_x, wheel_delta_y); | 
					
						
							| 
									
										
										
										
											2021-02-22 19:45:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 19:38:32 +02:00
										 |  |  | void ConnectionFromClient::doubleclick(Gfx::IntPoint const& position, unsigned int button, [[maybe_unused]] unsigned int buttons, unsigned int modifiers) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().handle_doubleclick(position, button, modifiers); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::key_down(i32 key, unsigned int modifiers, u32 code_point) | 
					
						
							| 
									
										
										
										
											2020-08-03 19:58:59 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     page().handle_keydown((KeyCode)key, modifiers, code_point); | 
					
						
							| 
									
										
										
										
											2020-08-03 19:58:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::key_up(i32 key, unsigned int modifiers, u32 code_point) | 
					
						
							| 
									
										
										
										
											2021-09-28 15:39:35 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     page().handle_keyup((KeyCode)key, modifiers, code_point); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::debug_request(String const& request, String const& argument) | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "dump-dom-tree") { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |         if (auto* doc = page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |             Web::dump_tree(*doc); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "dump-layout-tree") { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |         if (auto* doc = page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |             if (auto* icb = doc->layout_node()) | 
					
						
							|  |  |  |                 Web::dump_tree(*icb); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-05 19:01:12 +01:00
										 |  |  |     if (request == "dump-stacking-context-tree") { | 
					
						
							|  |  |  |         if (auto* doc = page().top_level_browsing_context().active_document()) { | 
					
						
							|  |  |  |             if (auto* icb = doc->layout_node()) { | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:16 +01:00
										 |  |  |                 if (auto* stacking_context = icb->paint_box()->stacking_context()) | 
					
						
							| 
									
										
										
										
											2022-02-05 19:01:12 +01:00
										 |  |  |                     stacking_context->dump(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "dump-style-sheets") { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |         if (auto* doc = page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |             for (auto& sheet : doc->style_sheets().sheets()) { | 
					
						
							|  |  |  |                 Web::dump_sheet(sheet); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											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"; | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  |         m_page_host->set_should_show_line_box_borders(state); | 
					
						
							| 
									
										
										
										
											2021-05-30 12:36:53 +02:00
										 |  |  |         page().top_level_browsing_context().set_needs_display(page().top_level_browsing_context().viewport_rect()); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-14 15:13:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |     if (request == "spoof-user-agent") { | 
					
						
							|  |  |  |         Web::ResourceLoader::the().set_user_agent(argument); | 
					
						
							| 
									
										
										
										
											2021-04-14 15:13:51 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-12 02:10:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (request == "same-origin-policy") { | 
					
						
							|  |  |  |         m_page_host->page().set_same_origin_policy_enabled(argument == "on"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-30 23:29:15 +01:00
										 |  |  |     if (request == "scripting") { | 
					
						
							|  |  |  |         m_page_host->page().set_is_scripting_enabled(argument == "on"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 19:50:14 +01:00
										 |  |  |     if (request == "dump-local-storage") { | 
					
						
							|  |  |  |         if (auto* doc = page().top_level_browsing_context().active_document()) | 
					
						
							|  |  |  |             doc->window().local_storage()->dump(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-31 09:06:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::get_source() | 
					
						
							| 
									
										
										
										
											2021-02-23 06:14:12 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |     if (auto* doc = page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2021-05-03 13:33:59 +02:00
										 |  |  |         async_did_get_source(doc->url(), doc->source()); | 
					
						
							| 
									
										
										
										
											2021-02-23 06:14:12 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::inspect_dom_tree() | 
					
						
							| 
									
										
										
										
											2021-06-07 16:35:10 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |     if (auto* doc = page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2021-06-07 16:35:10 +01:00
										 |  |  |         async_did_get_dom_tree(doc->dump_dom_tree_as_json()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  | Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |     auto& top_context = page().top_level_browsing_context(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     top_context.for_each_in_inclusive_subtree([&](auto& ctx) { | 
					
						
							|  |  |  |         if (ctx.active_document() != nullptr) { | 
					
						
							|  |  |  |             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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |     Web::DOM::Node* node = Web::DOM::Node::from_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()) { | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |         return { false, "", "", "", "" }; | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  |     // FIXME: Pass the pseudo-element here.
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |     node->document().set_inspected_node(node); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2022-03-15 19:41:35 +01:00
										 |  |  |         if (!element.computed_css_values()) | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |             return { false, "", "", "", "" }; | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |         auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> String { | 
					
						
							|  |  |  |             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) { | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02:00
										 |  |  |                 MUST(serializer.add(Web::CSS::string_from_property_id(property_id), value.to_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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:05:39 +03:00
										 |  |  |             return builder.to_string(); | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |         auto serialize_custom_properties_json = [](Web::DOM::Element const& element) -> String { | 
					
						
							|  |  |  |             StringBuilder builder; | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02:00
										 |  |  |             auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |             HashTable<String> seen_properties; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             auto const* element_to_check = &element; | 
					
						
							|  |  |  |             while (element_to_check) { | 
					
						
							|  |  |  |                 for (auto const& property : element_to_check->custom_properties()) { | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2022-02-24 20:08:48 +02: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
										 |  |  | 
 | 
					
						
							|  |  |  |             return builder.to_string(); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2022-03-10 11:24:55 +00:00
										 |  |  |         auto serialize_node_box_sizing_json = [](Web::Layout::Node const* layout_node) -> String { | 
					
						
							|  |  |  |             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)); | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |             MUST(serializer.add("padding_top"sv, box_model.padding.top)); | 
					
						
							|  |  |  |             MUST(serializer.add("padding_right"sv, box_model.padding.right)); | 
					
						
							|  |  |  |             MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom)); | 
					
						
							|  |  |  |             MUST(serializer.add("padding_left"sv, box_model.padding.left)); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_top"sv, box_model.margin.top)); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_right"sv, box_model.margin.right)); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom)); | 
					
						
							|  |  |  |             MUST(serializer.add("margin_left"sv, box_model.margin.left)); | 
					
						
							|  |  |  |             MUST(serializer.add("border_top"sv, box_model.border.top)); | 
					
						
							|  |  |  |             MUST(serializer.add("border_right"sv, box_model.border.right)); | 
					
						
							|  |  |  |             MUST(serializer.add("border_bottom"sv, box_model.border.bottom)); | 
					
						
							|  |  |  |             MUST(serializer.add("border_left"sv, box_model.border.left)); | 
					
						
							| 
									
										
										
										
											2022-03-09 23:53:41 +01:00
										 |  |  |             if (auto* paint_box = box->paint_box()) { | 
					
						
							| 
									
										
										
										
											2022-07-11 17:32:29 +00:00
										 |  |  |                 MUST(serializer.add("content_width"sv, paint_box->content_width())); | 
					
						
							|  |  |  |                 MUST(serializer.add("content_height"sv, paint_box->content_height())); | 
					
						
							| 
									
										
										
										
											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()); | 
					
						
							|  |  |  |             return builder.to_string(); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											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()); | 
					
						
							|  |  |  |             if (pseudo_element_node.is_null()) | 
					
						
							|  |  |  |                 return { false, "", "", "", "" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // 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.
 | 
					
						
							|  |  |  |             auto pseudo_element_style = page().focused_context().active_document()->style_computer().compute_style(element, pseudo_element); | 
					
						
							| 
									
										
										
										
											2022-03-15 19:41:35 +01:00
										 |  |  |             String computed_values = serialize_json(pseudo_element_style); | 
					
						
							|  |  |  |             String resolved_values = "{}"; | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  |             String custom_properties_json = "{}"; | 
					
						
							| 
									
										
										
										
											2022-03-10 11:24:55 +00:00
										 |  |  |             String node_box_sizing_json = serialize_node_box_sizing_json(pseudo_element_node.ptr()); | 
					
						
							| 
									
										
										
										
											2022-03-15 19:41:35 +01:00
										 |  |  |             return { true, computed_values, resolved_values, custom_properties_json, node_box_sizing_json }; | 
					
						
							| 
									
										
										
										
											2022-03-04 16:29:05 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-15 19:41:35 +01:00
										 |  |  |         String computed_values = serialize_json(*element.computed_css_values()); | 
					
						
							| 
									
										
										
										
											2022-03-15 19:32:17 +01:00
										 |  |  |         String resolved_values_json = serialize_json(element.resolved_css_values()); | 
					
						
							| 
									
										
										
										
											2021-12-08 11:51:26 +00:00
										 |  |  |         String custom_properties_json = serialize_custom_properties_json(element); | 
					
						
							| 
									
										
										
										
											2022-03-10 11:24:55 +00:00
										 |  |  |         String node_box_sizing_json = serialize_node_box_sizing_json(element.layout_node()); | 
					
						
							| 
									
										
										
										
											2022-03-15 19:41:35 +01:00
										 |  |  |         return { true, computed_values, resolved_values_json, custom_properties_json, node_box_sizing_json }; | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-27 01:38:12 +01:00
										 |  |  |     return { false, "", "", "", "" }; | 
					
						
							| 
									
										
										
										
											2021-08-27 12:31:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_hovered_node_id() | 
					
						
							| 
									
										
										
										
											2021-08-27 17:33:10 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |     if (auto* document = page().top_level_browsing_context().active_document()) { | 
					
						
							| 
									
										
										
										
											2021-08-27 17:33:10 +01:00
										 |  |  |         auto hovered_node = document->hovered_node(); | 
					
						
							|  |  |  |         if (hovered_node) | 
					
						
							|  |  |  |             return hovered_node->id(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return (i32)0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::initialize_js_console(Badge<PageHost>) | 
					
						
							| 
									
										
										
										
											2021-09-04 11:14:25 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |     auto* document = page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:14:25 +01:00
										 |  |  |     auto interpreter = document->interpreter().make_weak_ptr(); | 
					
						
							|  |  |  |     if (m_interpreter.ptr() == interpreter.ptr()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_interpreter = interpreter; | 
					
						
							|  |  |  |     m_console_client = make<WebContentConsoleClient>(interpreter->global_object().console(), interpreter, *this); | 
					
						
							|  |  |  |     interpreter->global_object().console().set_client(*m_console_client.ptr()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | void ConnectionFromClient::js_console_input(String const& js_source) | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_console_client) | 
					
						
							| 
									
										
										
										
											2021-05-02 19:54:34 +02:00
										 |  |  |         m_console_client->handle_input(js_source); | 
					
						
							| 
									
										
										
										
											2021-02-27 21:44:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::run_javascript(String const& js_source) | 
					
						
							| 
									
										
										
										
											2021-08-24 16:56:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  |     auto* active_document = page().top_level_browsing_context().active_document(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!active_document) | 
					
						
							| 
									
										
										
										
											2021-08-24 16:56:42 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  |     // This is partially based on "execute a javascript: URL request" https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
 | 
					
						
							| 
									
										
										
										
											2021-08-24 16:56:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  |     // Let settings be browsingContext's active document's relevant settings object.
 | 
					
						
							|  |  |  |     auto& settings = active_document->relevant_settings_object(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Let baseURL be settings's API base URL.
 | 
					
						
							|  |  |  |     auto base_url = settings.api_base_url(); | 
					
						
							| 
									
										
										
										
											2022-01-16 13:16:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  |     // Let script be the result of creating a classic script given scriptSource, settings, baseURL, and the default classic script fetch options.
 | 
					
						
							|  |  |  |     // FIXME: This doesn't pass in "default classic script fetch options"
 | 
					
						
							|  |  |  |     // FIXME: What should the filename be here?
 | 
					
						
							|  |  |  |     auto script = Web::HTML::ClassicScript::create("(client connection run_javascript)", js_source, settings, move(base_url)); | 
					
						
							| 
									
										
										
										
											2021-08-24 16:56:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 16:12:53 +01:00
										 |  |  |     // Let evaluationStatus be the result of running the classic script script.
 | 
					
						
							|  |  |  |     auto evaluation_status = script->run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (evaluation_status.is_error()) | 
					
						
							| 
									
										
										
										
											2021-08-24 16:56:42 +02:00
										 |  |  |         dbgln("Exception :("); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::js_console_request_messages(i32 start_index) | 
					
						
							| 
									
										
										
										
											2021-09-04 11:14:25 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-30 22:28:37 +03:00
										 |  |  |     if (m_console_client) | 
					
						
							|  |  |  |         m_console_client->send_messages(start_index); | 
					
						
							| 
									
										
										
										
											2021-09-04 11:14:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text() | 
					
						
							| 
									
										
										
										
											2021-07-14 08:32:55 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     return page().focused_context().selected_text(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::select_all() | 
					
						
							| 
									
										
										
										
											2021-07-14 08:53:55 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     page().focused_context().select_all(); | 
					
						
							|  |  |  |     page().client().page_did_change_selection(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_layout_tree() | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-09-09 13:14:32 +02:00
										 |  |  |     auto* document = page().top_level_browsing_context().active_document(); | 
					
						
							| 
									
										
										
										
											2021-09-08 00:55:35 +02:00
										 |  |  |     if (!document) | 
					
						
							|  |  |  |         return String { "(no DOM tree)" }; | 
					
						
							|  |  |  |     auto* layout_root = document->layout_node(); | 
					
						
							|  |  |  |     if (!layout_root) | 
					
						
							|  |  |  |         return String { "(no layout tree)" }; | 
					
						
							|  |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     Web::dump_tree(builder, *layout_root); | 
					
						
							|  |  |  |     return builder.to_string(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::set_content_filters(Vector<String> const& filters) | 
					
						
							| 
									
										
										
										
											2021-09-27 11:39:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     for (auto& filter : filters) | 
					
						
							|  |  |  |         Web::ContentFilter::the().add_pattern(filter); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-08 01:46:47 +04:30
										 |  |  | void ConnectionFromClient::set_proxy_mappings(Vector<String> const& proxies, HashMap<String, size_t> const& mappings) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto keys = mappings.keys(); | 
					
						
							|  |  |  |     quick_sort(keys, [&](auto& a, auto& b) { return a.length() < b.length(); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     OrderedHashMap<String, size_t> sorted_mappings; | 
					
						
							|  |  |  |     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)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::set_preferred_color_scheme(Web::CSS::PreferredColorScheme const& color_scheme) | 
					
						
							| 
									
										
										
										
											2021-10-26 17:00:10 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_page_host->set_preferred_color_scheme(color_scheme); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 12:18:30 +02:00
										 |  |  | void ConnectionFromClient::set_has_focus(bool has_focus) | 
					
						
							| 
									
										
										
										
											2022-02-06 19:03:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_page_host->set_has_focus(has_focus); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-30 23:23:14 +01:00
										 |  |  | void ConnectionFromClient::set_is_scripting_enabled(bool is_scripting_enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_page_host->set_is_scripting_enabled(is_scripting_enabled); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-02 00:14:04 +03:00
										 |  |  | Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient::get_local_storage_entries() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto* document = page().top_level_browsing_context().active_document(); | 
					
						
							|  |  |  |     auto local_storage = document->window().local_storage(); | 
					
						
							|  |  |  |     return local_storage->map(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-05-07 22:45:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClient::get_session_storage_entries() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto* document = page().top_level_browsing_context().active_document(); | 
					
						
							|  |  |  |     auto session_storage = document->window().session_storage(); | 
					
						
							|  |  |  |     return session_storage->map(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-02-26 17:50:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ConnectionFromClient::handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto result = m_requested_files.get(request_id); | 
					
						
							|  |  |  |     VERIFY(result.has_value()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(result.value()->on_file_request_finish); | 
					
						
							|  |  |  |     result.value()->on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() }); | 
					
						
							|  |  |  |     m_requested_files.remove(request_id); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConnectionFromClient::request_file(NonnullRefPtr<Web::FileRequest>& file_request) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     i32 const id = last_id++; | 
					
						
							|  |  |  |     m_requested_files.set(id, file_request); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async_did_request_file(file_request->path(), id); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-17 17:31:42 +02:00
										 |  |  | } |