| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2020-2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |  * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> | 
					
						
							|  |  |  |  * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org> | 
					
						
							| 
									
										
										
										
											2024-08-23 11:18:35 +01:00
										 |  |  |  * Copyright (c) 2024, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-24 11:57:33 -05:00
										 |  |  | #include <AK/JsonValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | #include <LibGfx/ShareableBitmap.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | #include <LibJS/Console.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/ConsoleObject.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-04 21:57:13 +13:00
										 |  |  | #include <LibWeb/Bindings/MainThreadVM.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-23 10:42:35 +01:00
										 |  |  | #include <LibWeb/CSS/CSSImportRule.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | #include <LibWeb/Cookie/ParsedCookie.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | #include <LibWeb/DOM/Attr.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/NamedNodeMap.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-23 10:42:35 +01:00
										 |  |  | #include <LibWeb/HTML/HTMLLinkElement.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/HTMLStyleElement.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | #include <LibWeb/HTML/Scripting/ClassicScript.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | #include <LibWeb/HTML/TraversableNavigable.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Layout/Viewport.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Painting/PaintableBox.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Painting/ViewportPaintable.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | #include <LibWebView/Attribute.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | #include <WebContent/ConnectionFromClient.h>
 | 
					
						
							| 
									
										
										
										
											2025-02-24 09:48:13 -05:00
										 |  |  | #include <WebContent/DevToolsConsoleClient.h>
 | 
					
						
							|  |  |  | #include <WebContent/InspectorConsoleClient.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | #include <WebContent/PageClient.h>
 | 
					
						
							|  |  |  | #include <WebContent/PageHost.h>
 | 
					
						
							|  |  |  | #include <WebContent/WebContentClientEndpoint.h>
 | 
					
						
							|  |  |  | #include <WebContent/WebDriverConnection.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace WebContent { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 16:42:14 +02:00
										 |  |  | static PageClient::UseSkiaPainter s_use_skia_painter = PageClient::UseSkiaPainter::GPUBackendIfAvailable; | 
					
						
							| 
									
										
										
										
											2024-12-09 21:51:19 +00:00
										 |  |  | static bool s_is_headless { false }; | 
					
						
							| 
									
										
										
										
											2025-02-24 09:48:13 -05:00
										 |  |  | static bool s_devtools_enabled { false }; | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC_DEFINE_ALLOCATOR(PageClient); | 
					
						
							| 
									
										
										
										
											2024-04-06 10:16:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-17 14:13:32 +03:00
										 |  |  | void PageClient::set_use_skia_painter(UseSkiaPainter use_skia_painter) | 
					
						
							| 
									
										
										
										
											2024-06-15 00:18:04 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-07-17 14:13:32 +03:00
										 |  |  |     s_use_skia_painter = use_skia_painter; | 
					
						
							| 
									
										
										
										
											2024-06-15 00:18:04 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-09 21:51:19 +00:00
										 |  |  | bool PageClient::is_headless() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return s_is_headless; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_is_headless(bool is_headless) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     s_is_headless = is_headless; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-24 09:48:13 -05:00
										 |  |  | void PageClient::set_devtools_enabled(bool devtools_enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     s_devtools_enabled = devtools_enabled; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC::Ref<PageClient> PageClient::create(JS::VM& vm, PageHost& page_host, u64 id) | 
					
						
							| 
									
										
										
										
											2023-12-04 21:40:33 +13:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-11-14 06:13:46 +13:00
										 |  |  |     return vm.heap().allocate<PageClient>(page_host, id); | 
					
						
							| 
									
										
										
										
											2023-12-04 21:40:33 +13:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | PageClient::PageClient(PageHost& owner, u64 id) | 
					
						
							|  |  |  |     : m_owner(owner) | 
					
						
							| 
									
										
										
										
											2023-12-04 21:57:13 +13:00
										 |  |  |     , m_page(Web::Page::create(Web::Bindings::main_thread_vm(), *this)) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |     , m_id(id) | 
					
						
							| 
									
										
										
										
											2024-06-17 18:50:57 +03:00
										 |  |  |     , m_backing_store_manager(*this) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							|  |  |  |     setup_palette(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 17:44:57 +02:00
										 |  |  |     int refresh_interval = 1000 / 60; // FIXME: Account for the actual refresh rate of the display
 | 
					
						
							|  |  |  |     m_paint_refresh_timer = Core::Timer::create_repeating(refresh_interval, [] { | 
					
						
							|  |  |  |         Web::HTML::main_thread_event_loop().queue_task_to_update_the_rendering(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2024-06-16 10:38:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 17:44:57 +02:00
										 |  |  |     m_paint_refresh_timer->start(); | 
					
						
							| 
									
										
										
										
											2023-12-21 22:58:54 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 17:44:57 +02:00
										 |  |  | PageClient::~PageClient() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 20:11:06 +01:00
										 |  |  | bool PageClient::is_ready_to_paint() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_paint_state == PaintState::Ready; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 10:35:45 -05:00
										 |  |  | void PageClient::ready_to_paint() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-03 17:44:57 +02:00
										 |  |  |     m_paint_state = PaintState::Ready; | 
					
						
							| 
									
										
										
										
											2024-01-07 10:35:45 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 21:57:13 +13:00
										 |  |  | void PageClient::visit_edges(JS::Cell::Visitor& visitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::visit_edges(visitor); | 
					
						
							|  |  |  |     visitor.visit(m_page); | 
					
						
							| 
									
										
										
										
											2024-10-17 18:50:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_webdriver) | 
					
						
							|  |  |  |         m_webdriver->visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2023-12-04 21:57:13 +13:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | ConnectionFromClient& PageClient::client() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_owner.client(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_has_focus(bool has_focus) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_has_focus = has_focus; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::setup_palette() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // FIXME: Get the proper palette from our peer somehow
 | 
					
						
							|  |  |  |     auto buffer_or_error = Core::AnonymousBuffer::create_with_size(sizeof(Gfx::SystemTheme)); | 
					
						
							|  |  |  |     VERIFY(!buffer_or_error.is_error()); | 
					
						
							|  |  |  |     auto buffer = buffer_or_error.release_value(); | 
					
						
							|  |  |  |     auto* theme = buffer.data<Gfx::SystemTheme>(); | 
					
						
							| 
									
										
										
										
											2024-05-23 23:07:39 -04:00
										 |  |  |     theme->color[to_underlying(Gfx::ColorRole::Window)] = Color(Color::Magenta).value(); | 
					
						
							|  |  |  |     theme->color[to_underlying(Gfx::ColorRole::WindowText)] = Color(Color::Cyan).value(); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |     m_palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool PageClient::is_connection_open() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return client().is_open(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Gfx::Palette PageClient::palette() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return Gfx::Palette(*m_palette_impl); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_palette_impl(Gfx::PaletteImpl& impl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_palette_impl = impl; | 
					
						
							|  |  |  |     if (auto* document = page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2024-09-04 10:01:08 +02:00
										 |  |  |         document->invalidate_style(Web::DOM::StyleInvalidationReason::SettingsChange); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_preferred_color_scheme = color_scheme; | 
					
						
							|  |  |  |     if (auto* document = page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2024-09-04 10:01:08 +02:00
										 |  |  |         document->invalidate_style(Web::DOM::StyleInvalidationReason::SettingsChange); | 
					
						
							| 
									
										
										
										
											2024-06-13 01:03:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_preferred_contrast(Web::CSS::PreferredContrast contrast) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_preferred_contrast = contrast; | 
					
						
							|  |  |  |     if (auto* document = page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2024-09-04 10:01:08 +02:00
										 |  |  |         document->invalidate_style(Web::DOM::StyleInvalidationReason::SettingsChange); | 
					
						
							| 
									
										
										
										
											2024-06-13 16:15:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_preferred_motion(Web::CSS::PreferredMotion motion) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_preferred_motion = motion; | 
					
						
							|  |  |  |     if (auto* document = page().top_level_browsing_context().active_document()) | 
					
						
							| 
									
										
										
										
											2024-09-04 10:01:08 +02:00
										 |  |  |         document->invalidate_style(Web::DOM::StyleInvalidationReason::SettingsChange); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_is_scripting_enabled(bool is_scripting_enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().set_is_scripting_enabled(is_scripting_enabled); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_window_position(Web::DevicePixelPoint position) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().set_window_position(position); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_window_size(Web::DevicePixelSize size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().set_window_size(size); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Web::Layout::Viewport* PageClient::layout_root() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto* document = page().top_level_browsing_context().active_document(); | 
					
						
							|  |  |  |     if (!document) | 
					
						
							|  |  |  |         return nullptr; | 
					
						
							|  |  |  |     return document->layout_node(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-03 22:12:28 +10:00
										 |  |  | void PageClient::process_screenshot_requests() | 
					
						
							| 
									
										
										
										
											2024-05-28 15:51:53 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-06-21 19:15:32 +03:00
										 |  |  |     while (!m_screenshot_tasks.is_empty()) { | 
					
						
							|  |  |  |         auto task = m_screenshot_tasks.dequeue(); | 
					
						
							|  |  |  |         if (task.node_id.has_value()) { | 
					
						
							|  |  |  |             auto* dom_node = Web::DOM::Node::from_unique_id(*task.node_id); | 
					
						
							|  |  |  |             if (!dom_node || !dom_node->paintable_box()) { | 
					
						
							|  |  |  |                 client().async_did_take_screenshot(m_id, {}); | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             auto rect = page().enclosing_device_rect(dom_node->paintable_box()->absolute_border_box_rect()); | 
					
						
							|  |  |  |             auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  |             auto backing_store = Web::Painting::BitmapBackingStore(*bitmap); | 
					
						
							|  |  |  |             paint(rect, backing_store, { .paint_overlay = Web::PaintOptions::PaintOverlay::No }); | 
					
						
							| 
									
										
										
										
											2024-06-21 19:15:32 +03:00
										 |  |  |             client().async_did_take_screenshot(m_id, bitmap->to_shareable_bitmap()); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             Web::DevicePixelRect rect { { 0, 0 }, content_size() }; | 
					
						
							|  |  |  |             auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors(); | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  |             auto backing_store = Web::Painting::BitmapBackingStore(*bitmap); | 
					
						
							|  |  |  |             paint(rect, backing_store); | 
					
						
							| 
									
										
										
										
											2024-06-21 19:15:32 +03:00
										 |  |  |             client().async_did_take_screenshot(m_id, bitmap->to_shareable_bitmap()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-07-03 22:12:28 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::paint_next_frame() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  |     auto back_store = m_backing_store_manager.back_store(); | 
					
						
							|  |  |  |     if (!back_store) | 
					
						
							| 
									
										
										
										
											2024-05-28 15:51:53 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto viewport_rect = page().css_to_device_rect(page().top_level_traversable()->viewport_rect()); | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  |     paint(viewport_rect, *back_store); | 
					
						
							| 
									
										
										
										
											2024-05-28 15:51:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 18:50:57 +03:00
										 |  |  |     m_backing_store_manager.swap_back_and_front(); | 
					
						
							| 
									
										
										
										
											2024-05-28 15:51:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_paint_state = PaintState::WaitingForClient; | 
					
						
							| 
									
										
										
										
											2024-06-17 18:50:57 +03:00
										 |  |  |     client().async_did_paint(m_id, viewport_rect.to_type<int>(), m_backing_store_manager.front_id()); | 
					
						
							| 
									
										
										
										
											2024-05-28 15:51:53 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  | void PageClient::paint(Web::DevicePixelRect const& content_rect, Web::Painting::BackingStore& target, Web::PaintOptions paint_options) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-06-10 02:58:32 +03:00
										 |  |  |     paint_options.should_show_line_box_borders = m_should_show_line_box_borders; | 
					
						
							|  |  |  |     paint_options.has_focus = m_has_focus; | 
					
						
							|  |  |  |     page().top_level_traversable()->paint(content_rect, target, paint_options); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-14 23:25:12 +01:00
										 |  |  | Queue<Web::QueuedInputEvent>& PageClient::input_event_queue() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return client().input_event_queue(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::report_finished_handling_input_event(u64 page_id, Web::EventResult event_was_handled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_finish_handling_input_event(page_id, event_was_handled); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-03 17:53:55 +03:00
										 |  |  | void PageClient::set_viewport_size(Web::DevicePixelSize const& size) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-06-03 17:53:55 +03:00
										 |  |  |     page().top_level_traversable()->set_viewport_size(page().device_to_css_size(size)); | 
					
						
							| 
									
										
										
										
											2024-06-17 18:50:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_backing_store_manager.restart_resize_timer(); | 
					
						
							|  |  |  |     m_backing_store_manager.resize_backing_stores_if_needed(BackingStoreManager::WindowResizingInProgress::Yes); | 
					
						
							| 
									
										
										
										
											2024-12-23 22:15:06 +01:00
										 |  |  |     m_pending_set_browser_zoom_request = false; | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-20 12:17:29 +00:00
										 |  |  | void PageClient::page_did_request_cursor_change(Gfx::Cursor const& cursor) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-02-20 12:17:29 +00:00
										 |  |  |     client().async_did_request_cursor_change(m_id, cursor); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_layout() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto* layout_root = this->layout_root(); | 
					
						
							|  |  |  |     VERIFY(layout_root); | 
					
						
							| 
									
										
										
										
											2024-11-07 14:09:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |     if (layout_root->paintable_box()->has_scrollable_overflow()) | 
					
						
							|  |  |  |         m_content_size = page().enclosing_device_rect(layout_root->paintable_box()->scrollable_overflow_rect().value()).size(); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         m_content_size = page().enclosing_device_rect(layout_root->paintable_box()->absolute_rect()).size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | void PageClient::page_did_change_title(ByteString const& title) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_change_title(m_id, title); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 10:27:20 +02:00
										 |  |  | void PageClient::page_did_change_url(URL::URL const& url) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_change_url(m_id, url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | void PageClient::page_did_request_refresh() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_refresh(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 23:37:11 -04:00
										 |  |  | void PageClient::page_did_request_resize_window(Gfx::IntSize size) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-28 23:37:11 -04:00
										 |  |  |     client().async_did_request_resize_window(m_id, size); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 23:37:11 -04:00
										 |  |  | void PageClient::page_did_request_reposition_window(Gfx::IntPoint position) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-28 23:37:11 -04:00
										 |  |  |     client().async_did_request_reposition_window(m_id, position); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_restore_window() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_restore_window(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  | void PageClient::page_did_request_maximize_window() | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  |     client().async_did_request_maximize_window(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  | void PageClient::page_did_request_minimize_window() | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  |     client().async_did_request_minimize_window(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  | void PageClient::page_did_request_fullscreen_window() | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-28 23:45:18 -04:00
										 |  |  |     client().async_did_request_fullscreen_window(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-02 16:48:57 +02:00
										 |  |  | void PageClient::page_did_request_tooltip_override(Web::CSSPixelPoint position, ByteString const& title) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto device_position = page().css_to_device_point(position); | 
					
						
							|  |  |  |     client().async_did_request_tooltip_override(m_id, { device_position.x(), device_position.y() }, title); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_stop_tooltip_override() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_leave_tooltip_area(m_id); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-02 14:16:24 +02:00
										 |  |  | void PageClient::page_did_enter_tooltip_area(ByteString const& title) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-07-02 14:16:24 +02:00
										 |  |  |     client().async_did_enter_tooltip_area(m_id, title); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_leave_tooltip_area() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_leave_tooltip_area(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 22:02:55 -04:00
										 |  |  | void PageClient::page_did_hover_link(URL::URL const& url) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_hover_link(m_id, url); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_unhover_link() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_unhover_link(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-01 13:38:21 -04:00
										 |  |  | void PageClient::page_did_click_link(URL::URL const& url, ByteString const& target, unsigned modifiers) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_click_link(m_id, url, target, modifiers); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-01 13:39:57 -04:00
										 |  |  | void PageClient::page_did_middle_click_link(URL::URL const& url, ByteString const& target, unsigned modifiers) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_middle_click_link(m_id, url, target, modifiers); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 22:02:55 -04:00
										 |  |  | void PageClient::page_did_start_loading(URL::URL const& url, bool is_redirect) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_start_loading(m_id, url, is_redirect); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_create_new_document(Web::DOM::Document& document) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     initialize_js_console(document); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 17:21:09 +02:00
										 |  |  | void PageClient::page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document& document) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:14:53 -04:00
										 |  |  |     auto& realm = document.realm(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 13:18:44 -04:00
										 |  |  |     if (auto console_client = document.console_client()) { | 
					
						
							| 
									
										
										
										
											2025-01-21 09:12:05 -05:00
										 |  |  |         auto& web_content_console_client = as<WebContentConsoleClient>(*console_client); | 
					
						
							| 
									
										
										
										
											2024-07-31 13:18:44 -04:00
										 |  |  |         m_top_level_document_console_client = web_content_console_client; | 
					
						
							| 
									
										
										
										
											2024-07-31 12:14:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         auto console_object = realm.intrinsics().console_object(); | 
					
						
							|  |  |  |         console_object->console().set_client(*console_client); | 
					
						
							| 
									
										
										
										
											2024-07-31 13:18:44 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 22:02:55 -04:00
										 |  |  | void PageClient::page_did_finish_loading(URL::URL const& url) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_finish_loading(m_id, url); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-02 12:38:10 -04:00
										 |  |  | void PageClient::page_did_finish_text_test(String const& text) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-02 12:38:10 -04:00
										 |  |  |     client().async_did_finish_text_test(m_id, text); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-19 14:16:05 +00:00
										 |  |  | void PageClient::page_did_set_test_timeout(double milliseconds) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_set_test_timeout(m_id, milliseconds); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 22:15:06 +01:00
										 |  |  | void PageClient::page_did_set_browser_zoom(double factor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_pending_set_browser_zoom_request = true; | 
					
						
							|  |  |  |     client().async_did_set_browser_zoom(m_id, factor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto& event_loop = Web::HTML::main_thread_event_loop(); | 
					
						
							|  |  |  |     event_loop.spin_until(GC::create_function(event_loop.heap(), [&]() { | 
					
						
							|  |  |  |         return !m_pending_set_browser_zoom_request || !is_connection_open(); | 
					
						
							|  |  |  |     })); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | void PageClient::page_did_request_context_menu(Web::CSSPixelPoint content_position) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_context_menu(m_id, page().css_to_device_point(content_position).to_type<int>()); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | void PageClient::page_did_request_link_context_menu(Web::CSSPixelPoint content_position, URL::URL const& url, ByteString const& target, unsigned modifiers) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_link_context_menu(m_id, page().css_to_device_point(content_position).to_type<int>(), url, target, modifiers); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-10 20:33:27 +11:00
										 |  |  | void PageClient::page_did_request_image_context_menu(Web::CSSPixelPoint content_position, URL::URL const& url, ByteString const& target, unsigned modifiers, Optional<Gfx::Bitmap const*> bitmap_pointer) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-01-10 20:33:27 +11:00
										 |  |  |     Optional<Gfx::ShareableBitmap> bitmap; | 
					
						
							|  |  |  |     if (bitmap_pointer.has_value() && bitmap_pointer.value()) | 
					
						
							|  |  |  |         bitmap = bitmap_pointer.value()->to_shareable_bitmap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_image_context_menu(m_id, page().css_to_device_point(content_position).to_type<int>(), url, target, modifiers, bitmap); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | void PageClient::page_did_request_media_context_menu(Web::CSSPixelPoint content_position, ByteString const& target, unsigned modifiers, Web::Page::MediaContextMenu menu) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_media_context_menu(m_id, page().css_to_device_point(content_position).to_type<int>(), target, modifiers, move(menu)); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_alert(String const& message) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_alert(m_id, message); | 
					
						
							| 
									
										
										
										
											2024-10-25 10:28:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_webdriver) | 
					
						
							|  |  |  |         m_webdriver->page_did_open_dialog({}); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::alert_closed() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().alert_closed(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_confirm(String const& message) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_confirm(m_id, message); | 
					
						
							| 
									
										
										
										
											2024-10-25 10:28:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_webdriver) | 
					
						
							|  |  |  |         m_webdriver->page_did_open_dialog({}); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::confirm_closed(bool accepted) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().confirm_closed(accepted); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_prompt(String const& message, String const& default_) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_prompt(m_id, message, default_); | 
					
						
							| 
									
										
										
										
											2024-10-25 10:28:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_webdriver) | 
					
						
							|  |  |  |         m_webdriver->page_did_open_dialog({}); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_set_prompt_text(String const& text) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_set_prompt_text(m_id, text); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::prompt_closed(Optional<String> response) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().prompt_closed(move(response)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-11 06:53:10 +01:00
										 |  |  | void PageClient::color_picker_update(Optional<Color> picked_color, Web::HTML::ColorPickerUpdateState state) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-12-11 06:53:10 +01:00
										 |  |  |     page().color_picker_update(picked_color, state); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 19:19:08 +02:00
										 |  |  | void PageClient::select_dropdown_closed(Optional<u32> const& selected_item_id) | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:19:08 +02:00
										 |  |  |     page().select_dropdown_closed(selected_item_id); | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | Web::WebIDL::ExceptionOr<void> PageClient::toggle_media_play_state() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return page().toggle_media_play_state(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::toggle_media_mute_state() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().toggle_media_mute_state(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Web::WebIDL::ExceptionOr<void> PageClient::toggle_media_loop_state() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return page().toggle_media_loop_state(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Web::WebIDL::ExceptionOr<void> PageClient::toggle_media_controls_state() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return page().toggle_media_controls_state(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::set_user_style(String source) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     page().set_user_style(source); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_accept_dialog() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_accept_dialog(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_dismiss_dialog() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_dismiss_dialog(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_change_favicon(Gfx::Bitmap const& favicon) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_change_favicon(m_id, favicon.to_shareable_bitmap()); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | Vector<Web::Cookie::Cookie> PageClient::page_did_request_all_cookies(URL::URL const& url) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-22 13:25:18 -04:00
										 |  |  |     return client().did_request_all_cookies(url); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | Optional<Web::Cookie::Cookie> PageClient::page_did_request_named_cookie(URL::URL const& url, String const& name) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-22 13:25:18 -04:00
										 |  |  |     return client().did_request_named_cookie(url, name); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 22:02:55 -04:00
										 |  |  | String PageClient::page_did_request_cookie(URL::URL const& url, Web::Cookie::Source source) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-22 13:25:18 -04:00
										 |  |  |     auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidRequestCookie>(url, source); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  |     if (!response) { | 
					
						
							|  |  |  |         dbgln("WebContent client disconnected during DidRequestCookie. Exiting peacefully."); | 
					
						
							|  |  |  |         exit(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return response->take_cookie(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-28 22:02:55 -04:00
										 |  |  | void PageClient::page_did_set_cookie(URL::URL const& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-22 13:25:18 -04:00
										 |  |  |     auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidSetCookie>(url, cookie, source); | 
					
						
							| 
									
										
										
										
											2024-01-10 12:23:00 -05:00
										 |  |  |     if (!response) { | 
					
						
							|  |  |  |         dbgln("WebContent client disconnected during DidSetCookie. Exiting peacefully."); | 
					
						
							|  |  |  |         exit(0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_update_cookie(Web::Cookie::Cookie cookie) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-22 13:25:18 -04:00
										 |  |  |     client().async_did_update_cookie(move(cookie)); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-13 08:56:46 -04:00
										 |  |  | void PageClient::page_did_expire_cookies_with_time_offset(AK::Duration offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_expire_cookies_with_time_offset(offset); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | void PageClient::page_did_update_resource_count(i32 count_waiting) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_update_resource_count(m_id, count_waiting); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-30 20:55:24 -07:00
										 |  |  | PageClient::NewWebViewResult PageClient::page_did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Web::HTML::TokenizedFeature::NoOpener no_opener) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-01-30 20:55:24 -07:00
										 |  |  |     auto& new_client = m_owner.create_page(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Optional<u64> page_id; | 
					
						
							|  |  |  |     if (no_opener == Web::HTML::TokenizedFeature::NoOpener::Yes) { | 
					
						
							|  |  |  |         // FIXME: Create an abstraction to let this WebContent process know about a new process we create?
 | 
					
						
							|  |  |  |         // FIXME: For now, just create a new page in the same process anyway
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     page_id = new_client.m_id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidRequestNewWebView>(m_id, activate_tab, hints, page_id); | 
					
						
							| 
									
										
										
										
											2024-01-30 20:05:00 -07:00
										 |  |  |     if (!response) { | 
					
						
							|  |  |  |         dbgln("WebContent client disconnected during DidRequestNewWebView. Exiting peacefully."); | 
					
						
							|  |  |  |         exit(0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-01-30 20:55:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return { &new_client.page(), response->take_handle() }; | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_activate_tab() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_activate_tab(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void PageClient::page_did_close_top_level_traversable() | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     // FIXME: Rename this IPC call
 | 
					
						
							|  |  |  |     client().async_did_close_browsing_context(m_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // NOTE: This only removes the strong reference the PageHost has for this PageClient.
 | 
					
						
							|  |  |  |     //       It will be GC'd 'later'.
 | 
					
						
							|  |  |  |     m_owner.remove_page({}, m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-13 23:12:55 +02:00
										 |  |  | void PageClient::page_did_update_navigation_buttons_state(bool back_enabled, bool forward_enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_update_navigation_buttons_state(m_id, back_enabled, forward_enabled); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | void PageClient::request_file(Web::FileRequest file_request) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().request_file(m_id, move(file_request)); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_request_color_picker(Color current_color) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_color_picker(m_id, current_color); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-14 12:26:00 -04:00
										 |  |  | void PageClient::page_did_request_file_picker(Web::HTML::FileFilter accepted_file_types, Web::HTML::AllowMultipleFiles allow_multiple_files) | 
					
						
							| 
									
										
										
										
											2024-02-25 13:02:47 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-14 12:26:00 -04:00
										 |  |  |     client().async_did_request_file_picker(m_id, move(accepted_file_types), allow_multiple_files); | 
					
						
							| 
									
										
										
										
											2024-02-25 13:02:47 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 22:35:37 +01:00
										 |  |  | void PageClient::page_did_request_select_dropdown(Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items) | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_request_select_dropdown(m_id, page().css_to_device_point(content_position).to_type<int>(), minimum_width * device_pixels_per_css_pixel(), items); | 
					
						
							| 
									
										
										
										
											2023-12-07 15:53:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | void PageClient::page_did_change_theme_color(Gfx::Color color) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_change_theme_color(m_id, color); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::page_did_insert_clipboard_entry(String data, String presentation_style, String mime_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_did_insert_clipboard_entry(m_id, move(data), move(presentation_style), move(mime_type)); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-26 19:27:06 -04:00
										 |  |  | void PageClient::page_did_change_audio_play_state(Web::HTML::AudioPlayState play_state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_change_audio_play_state(m_id, play_state); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 18:50:57 +03:00
										 |  |  | void PageClient::page_did_allocate_backing_stores(i32 front_bitmap_id, Gfx::ShareableBitmap front_bitmap, i32 back_bitmap_id, Gfx::ShareableBitmap back_bitmap) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_allocate_backing_stores(m_id, front_bitmap_id, front_bitmap, back_bitmap_id, back_bitmap); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-17 18:44:39 -06:00
										 |  |  | IPC::File PageClient::request_worker_agent() | 
					
						
							| 
									
										
										
										
											2024-01-06 13:13:59 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::RequestWorkerAgent>(m_id); | 
					
						
							| 
									
										
										
										
											2024-01-06 13:13:59 -07:00
										 |  |  |     if (!response) { | 
					
						
							|  |  |  |         dbgln("WebContent client disconnected during RequestWorkerAgent. Exiting peacefully."); | 
					
						
							|  |  |  |         exit(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-17 18:44:39 -06:00
										 |  |  |     return response->take_socket(); | 
					
						
							| 
									
										
										
										
											2024-01-06 13:13:59 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | void PageClient::inspector_did_load() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_inspector_did_load(m_id); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  | void PageClient::inspector_did_select_dom_node(Web::UniqueNodeID node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_inspector_did_select_dom_node(m_id, node_id, pseudo_element); | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  | void PageClient::inspector_did_set_dom_node_text(Web::UniqueNodeID node_id, String const& text) | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_inspector_did_set_dom_node_text(m_id, node_id, text); | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  | void PageClient::inspector_did_set_dom_node_tag(Web::UniqueNodeID node_id, String const& tag) | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_inspector_did_set_dom_node_tag(m_id, node_id, tag); | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | static Vector<WebView::Attribute> named_node_map_to_vector(GC::Ref<Web::DOM::NamedNodeMap> map) | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     Vector<WebView::Attribute> attributes; | 
					
						
							| 
									
										
										
										
											2023-12-05 16:43:14 -05:00
										 |  |  |     attributes.ensure_capacity(map->length()); | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-05 16:43:14 -05:00
										 |  |  |     for (size_t i = 0; i < map->length(); ++i) { | 
					
						
							|  |  |  |         auto const* attribute = map->item(i); | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  |         VERIFY(attribute); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         attributes.empend(attribute->name().to_string(), attribute->value()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-05 16:43:14 -05:00
										 |  |  |     return attributes; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | void PageClient::inspector_did_add_dom_node_attributes(Web::UniqueNodeID node_id, GC::Ref<Web::DOM::NamedNodeMap> attributes) | 
					
						
							| 
									
										
										
										
											2023-12-05 16:43:14 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_inspector_did_add_dom_node_attributes(m_id, node_id, named_node_map_to_vector(attributes)); | 
					
						
							| 
									
										
										
										
											2023-12-05 16:43:14 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | void PageClient::inspector_did_replace_dom_node_attribute(Web::UniqueNodeID node_id, size_t attribute_index, GC::Ref<Web::DOM::NamedNodeMap> replacement_attributes) | 
					
						
							| 
									
										
										
										
											2023-12-05 16:43:14 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-18 13:59:28 -05:00
										 |  |  |     client().async_inspector_did_replace_dom_node_attribute(m_id, node_id, attribute_index, named_node_map_to_vector(replacement_attributes)); | 
					
						
							| 
									
										
										
										
											2023-12-03 11:49:08 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  | void PageClient::inspector_did_request_dom_tree_context_menu(Web::UniqueNodeID node_id, Web::CSSPixelPoint position, String const& type, Optional<String> const& tag, Optional<size_t> const& attribute_index) | 
					
						
							| 
									
										
										
										
											2023-12-05 14:47:56 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-18 13:59:28 -05:00
										 |  |  |     client().async_inspector_did_request_dom_tree_context_menu(m_id, node_id, page().css_to_device_point(position).to_type<int>(), type, tag, attribute_index); | 
					
						
							| 
									
										
										
										
											2023-12-05 14:47:56 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-06 13:22:16 -04:00
										 |  |  | void PageClient::inspector_did_request_cookie_context_menu(size_t cookie_index, Web::CSSPixelPoint position) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_inspector_did_request_cookie_context_menu(m_id, cookie_index, page().css_to_device_point(position).to_type<int>()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 11:18:35 +01:00
										 |  |  | void PageClient::inspector_did_request_style_sheet_source(Web::CSS::StyleSheetIdentifier const& identifier) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_inspector_did_request_style_sheet_source(m_id, identifier); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-30 19:27:32 -05:00
										 |  |  | void PageClient::inspector_did_execute_console_script(String const& script) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     client().async_inspector_did_execute_console_script(m_id, script); | 
					
						
							| 
									
										
										
										
											2023-11-30 19:27:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 12:11:39 -04:00
										 |  |  | void PageClient::inspector_did_export_inspector_html(String const& html) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_inspector_did_export_inspector_html(m_id, html); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | ErrorOr<void> PageClient::connect_to_webdriver(ByteString const& webdriver_ipc_path) | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | { | 
					
						
							|  |  |  |     VERIFY(!m_webdriver); | 
					
						
							|  |  |  |     m_webdriver = TRY(WebDriverConnection::connect(*this, webdriver_ipc_path)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | void PageClient::initialize_js_console(Web::DOM::Document& document) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:03:40 -04:00
										 |  |  |     if (document.is_temporary_document_for_fragment_parsing()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     auto& realm = document.realm(); | 
					
						
							|  |  |  |     auto console_object = realm.intrinsics().console_object(); | 
					
						
							| 
									
										
										
										
											2025-02-24 09:48:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     GC::Ptr<JS::ConsoleClient> console_client; | 
					
						
							|  |  |  |     if (s_devtools_enabled) | 
					
						
							|  |  |  |         console_client = DevToolsConsoleClient::create(document.realm(), console_object->console(), *this); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         console_client = InspectorConsoleClient::create(document.realm(), console_object->console(), *this); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 13:18:44 -04:00
										 |  |  |     document.set_console_client(console_client); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-24 11:57:33 -05:00
										 |  |  | void PageClient::did_execute_js_console_input(JsonValue result) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_execute_js_console_input(m_id, move(result)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 08:57:40 -05:00
										 |  |  | void PageClient::js_console_input(StringView js_source) | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_top_level_document_console_client) | 
					
						
							|  |  |  |         m_top_level_document_console_client->handle_input(js_source); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 08:57:40 -05:00
										 |  |  | void PageClient::run_javascript(StringView js_source) | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | { | 
					
						
							|  |  |  |     auto* active_document = page().top_level_browsing_context().active_document(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!active_document) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // This is partially based on "execute a javascript: URL request" https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 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(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-25 16:27:26 +13:00
										 |  |  |     // Let script be the result of creating a classic script given scriptSource, setting's realm, baseURL, and the default classic script fetch options.
 | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  |     // FIXME: This doesn't pass in "default classic script fetch options"
 | 
					
						
							|  |  |  |     // FIXME: What should the filename be here?
 | 
					
						
							| 
									
										
										
										
											2024-10-25 16:27:26 +13:00
										 |  |  |     auto script = Web::HTML::ClassicScript::create("(client connection run_javascript)", js_source, settings.realm(), move(base_url)); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Let evaluationStatus be the result of running the classic script script.
 | 
					
						
							|  |  |  |     auto evaluation_status = script->run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (evaluation_status.is_error()) | 
					
						
							|  |  |  |         dbgln("Exception :("); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::js_console_request_messages(i32 start_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_top_level_document_console_client) | 
					
						
							|  |  |  |         m_top_level_document_console_client->send_messages(start_index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::did_output_js_console_message(i32 message_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().async_did_output_js_console_message(m_id, message_index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PageClient::console_peer_did_misbehave(char const* reason) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     client().did_misbehave(reason); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-04 07:56:42 -05:00
										 |  |  | void PageClient::did_get_styled_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages) | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-03-04 07:56:42 -05:00
										 |  |  |     client().async_did_get_styled_js_console_messages(m_id, start_index, move(message_types), move(messages)); | 
					
						
							| 
									
										
										
										
											2024-02-02 18:00:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 10:42:35 +01:00
										 |  |  | static void gather_style_sheets(Vector<Web::CSS::StyleSheetIdentifier>& results, Web::CSS::CSSStyleSheet& sheet) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Web::CSS::StyleSheetIdentifier identifier {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool valid = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (sheet.owner_rule()) { | 
					
						
							|  |  |  |         identifier.type = Web::CSS::StyleSheetIdentifier::Type::ImportRule; | 
					
						
							|  |  |  |     } else if (auto* node = sheet.owner_node()) { | 
					
						
							|  |  |  |         if (node->is_html_style_element() || node->is_svg_style_element()) { | 
					
						
							|  |  |  |             identifier.type = Web::CSS::StyleSheetIdentifier::Type::StyleElement; | 
					
						
							|  |  |  |         } else if (is<Web::HTML::HTMLLinkElement>(node)) { | 
					
						
							|  |  |  |             identifier.type = Web::CSS::StyleSheetIdentifier::Type::LinkElement; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             dbgln("Can't identify where style sheet came from; owner node is {}", node->debug_description()); | 
					
						
							|  |  |  |             identifier.type = Web::CSS::StyleSheetIdentifier::Type::StyleElement; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         identifier.dom_element_unique_id = node->unique_id(); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         dbgln("Style sheet has no owner rule or owner node; skipping"); | 
					
						
							|  |  |  |         valid = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (valid) { | 
					
						
							|  |  |  |         if (auto location = sheet.location(); location.has_value()) | 
					
						
							|  |  |  |             identifier.url = location.release_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         results.append(move(identifier)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto& import_rule : sheet.import_rules()) { | 
					
						
							|  |  |  |         if (import_rule->loaded_style_sheet()) { | 
					
						
							|  |  |  |             gather_style_sheets(results, *import_rule->loaded_style_sheet()); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             // We can gather this anyway, and hope it loads later
 | 
					
						
							|  |  |  |             results.append({ .type = Web::CSS::StyleSheetIdentifier::Type::ImportRule, | 
					
						
							| 
									
										
										
										
											2024-12-03 22:31:33 +13:00
										 |  |  |                 .url = import_rule->url().to_string() }); | 
					
						
							| 
									
										
										
										
											2024-08-23 10:42:35 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Vector<Web::CSS::StyleSheetIdentifier> PageClient::list_style_sheets() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Vector<Web::CSS::StyleSheetIdentifier> results; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto const* document = page().top_level_browsing_context().active_document(); | 
					
						
							|  |  |  |     if (document) { | 
					
						
							|  |  |  |         for (auto& sheet : document->style_sheets().sheets()) { | 
					
						
							|  |  |  |             gather_style_sheets(results, sheet); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // User style
 | 
					
						
							|  |  |  |     if (page().user_style().has_value()) { | 
					
						
							|  |  |  |         results.append({ | 
					
						
							|  |  |  |             .type = Web::CSS::StyleSheetIdentifier::Type::UserStyle, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // User-agent
 | 
					
						
							|  |  |  |     results.append({ | 
					
						
							|  |  |  |         .type = Web::CSS::StyleSheetIdentifier::Type::UserAgent, | 
					
						
							|  |  |  |         .url = "CSS/Default.css"_string, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     if (document && document->in_quirks_mode()) { | 
					
						
							|  |  |  |         results.append({ | 
					
						
							|  |  |  |             .type = Web::CSS::StyleSheetIdentifier::Type::UserAgent, | 
					
						
							|  |  |  |             .url = "CSS/QuirksMode.css"_string, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     results.append({ | 
					
						
							|  |  |  |         .type = Web::CSS::StyleSheetIdentifier::Type::UserAgent, | 
					
						
							|  |  |  |         .url = "MathML/Default.css"_string, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     results.append({ | 
					
						
							|  |  |  |         .type = Web::CSS::StyleSheetIdentifier::Type::UserAgent, | 
					
						
							|  |  |  |         .url = "SVG/Default.css"_string, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return results; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-23 18:42:39 +02:00
										 |  |  | Web::DisplayListPlayerType PageClient::display_list_player_type() const | 
					
						
							| 
									
										
										
										
											2024-06-19 14:46:27 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-07-17 14:13:32 +03:00
										 |  |  |     switch (s_use_skia_painter) { | 
					
						
							|  |  |  |     case UseSkiaPainter::GPUBackendIfAvailable: | 
					
						
							|  |  |  |         return Web::DisplayListPlayerType::SkiaGPUIfAvailable; | 
					
						
							|  |  |  |     case UseSkiaPainter::CPUBackend: | 
					
						
							|  |  |  |         return Web::DisplayListPlayerType::SkiaCPU; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-06-19 14:46:27 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 10:37:44 +02:00
										 |  |  | void PageClient::queue_screenshot_task(Optional<Web::UniqueNodeID> node_id) | 
					
						
							| 
									
										
										
										
											2024-06-21 19:15:32 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     m_screenshot_tasks.enqueue({ node_id }); | 
					
						
							| 
									
										
										
										
											2025-02-01 19:33:18 +01:00
										 |  |  |     page().top_level_traversable()->set_needs_repaint(); | 
					
						
							| 
									
										
										
										
											2024-06-21 19:15:32 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-29 09:34:38 -07:00
										 |  |  | } |