ConnectionFromClient.cpp 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. /*
  2. * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  5. * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
  6. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  7. * Copyright (c) 2023-2024, Andrew Kaster <akaster@serenityos.org>
  8. *
  9. * SPDX-License-Identifier: BSD-2-Clause
  10. */
  11. #include <AK/JsonObject.h>
  12. #include <AK/QuickSort.h>
  13. #include <LibGfx/Bitmap.h>
  14. #include <LibGfx/Font/FontDatabase.h>
  15. #include <LibGfx/SystemTheme.h>
  16. #include <LibJS/Heap/Heap.h>
  17. #include <LibJS/Runtime/ConsoleObject.h>
  18. #include <LibWeb/ARIA/RoleType.h>
  19. #include <LibWeb/Bindings/MainThreadVM.h>
  20. #include <LibWeb/CSS/StyleComputer.h>
  21. #include <LibWeb/DOM/Attr.h>
  22. #include <LibWeb/DOM/CharacterData.h>
  23. #include <LibWeb/DOM/Document.h>
  24. #include <LibWeb/DOM/Element.h>
  25. #include <LibWeb/DOM/ElementFactory.h>
  26. #include <LibWeb/DOM/Text.h>
  27. #include <LibWeb/Dump.h>
  28. #include <LibWeb/HTML/BrowsingContext.h>
  29. #include <LibWeb/HTML/HTMLInputElement.h>
  30. #include <LibWeb/HTML/SelectedFile.h>
  31. #include <LibWeb/HTML/Storage.h>
  32. #include <LibWeb/HTML/TraversableNavigable.h>
  33. #include <LibWeb/HTML/Window.h>
  34. #include <LibWeb/Infra/Strings.h>
  35. #include <LibWeb/Layout/Viewport.h>
  36. #include <LibWeb/Loader/ContentFilter.h>
  37. #include <LibWeb/Loader/ProxyMappings.h>
  38. #include <LibWeb/Loader/ResourceLoader.h>
  39. #include <LibWeb/Loader/UserAgent.h>
  40. #include <LibWeb/Namespace.h>
  41. #include <LibWeb/Painting/StackingContext.h>
  42. #include <LibWeb/Painting/ViewportPaintable.h>
  43. #include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
  44. #include <LibWeb/Platform/EventLoopPlugin.h>
  45. #include <LibWebView/Attribute.h>
  46. #include <WebContent/ConnectionFromClient.h>
  47. #include <WebContent/PageClient.h>
  48. #include <WebContent/PageHost.h>
  49. #include <WebContent/WebContentClientEndpoint.h>
  50. namespace WebContent {
  51. ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket> socket)
  52. : IPC::ConnectionFromClient<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket), 1)
  53. , m_page_host(PageHost::create(*this))
  54. {
  55. m_input_event_queue_timer = Web::Platform::Timer::create_single_shot(0, [this] { process_next_input_event(); });
  56. }
  57. ConnectionFromClient::~ConnectionFromClient() = default;
  58. void ConnectionFromClient::die()
  59. {
  60. Web::Platform::EventLoopPlugin::the().quit();
  61. }
  62. Optional<PageClient&> ConnectionFromClient::page(u64 index, SourceLocation location)
  63. {
  64. if (auto page = m_page_host->page(index); page.has_value())
  65. return *page;
  66. dbgln("ConnectionFromClient::{}: Did not find a page with ID {}", location.function_name(), index);
  67. return {};
  68. }
  69. Optional<PageClient const&> ConnectionFromClient::page(u64 index, SourceLocation location) const
  70. {
  71. if (auto page = m_page_host->page(index); page.has_value())
  72. return *page;
  73. dbgln("ConnectionFromClient::{}: Did not find a page with ID {}", location.function_name(), index);
  74. return {};
  75. }
  76. void ConnectionFromClient::close_server()
  77. {
  78. shutdown();
  79. }
  80. Messages::WebContentServer::GetWindowHandleResponse ConnectionFromClient::get_window_handle(u64 page_id)
  81. {
  82. if (auto page = this->page(page_id); page.has_value())
  83. return page->page().top_level_traversable()->window_handle();
  84. return String {};
  85. }
  86. void ConnectionFromClient::set_window_handle(u64 page_id, String const& handle)
  87. {
  88. if (auto page = this->page(page_id); page.has_value())
  89. page->page().top_level_traversable()->set_window_handle(handle);
  90. }
  91. void ConnectionFromClient::connect_to_webdriver(u64 page_id, ByteString const& webdriver_ipc_path)
  92. {
  93. if (auto page = this->page(page_id); page.has_value()) {
  94. // FIXME: Propagate this error back to the browser.
  95. if (auto result = page->connect_to_webdriver(webdriver_ipc_path); result.is_error())
  96. dbgln("Unable to connect to the WebDriver process: {}", result.error());
  97. }
  98. }
  99. void ConnectionFromClient::connect_to_image_decoder(IPC::File const& image_decoder_socket)
  100. {
  101. if (on_image_decoder_connection)
  102. on_image_decoder_connection(image_decoder_socket);
  103. }
  104. void ConnectionFromClient::update_system_theme(u64 page_id, Core::AnonymousBuffer const& theme_buffer)
  105. {
  106. auto page = this->page(page_id);
  107. if (!page.has_value())
  108. return;
  109. Gfx::set_system_theme(theme_buffer);
  110. auto impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme_buffer);
  111. page->set_palette_impl(*impl);
  112. }
  113. void ConnectionFromClient::update_screen_rects(u64 page_id, Vector<Web::DevicePixelRect> const& rects, u32 main_screen)
  114. {
  115. if (auto page = this->page(page_id); page.has_value())
  116. page->set_screen_rects(rects, main_screen);
  117. }
  118. void ConnectionFromClient::load_url(u64 page_id, const URL::URL& url)
  119. {
  120. auto page = this->page(page_id);
  121. if (!page.has_value())
  122. return;
  123. page->page().load(url);
  124. }
  125. void ConnectionFromClient::load_html(u64 page_id, ByteString const& html)
  126. {
  127. if (auto page = this->page(page_id); page.has_value())
  128. page->page().load_html(html);
  129. }
  130. void ConnectionFromClient::reload(u64 page_id)
  131. {
  132. if (auto page = this->page(page_id); page.has_value())
  133. page->page().reload();
  134. }
  135. void ConnectionFromClient::traverse_the_history_by_delta(u64 page_id, i32 delta)
  136. {
  137. if (auto page = this->page(page_id); page.has_value())
  138. page->page().traverse_the_history_by_delta(delta);
  139. }
  140. void ConnectionFromClient::set_viewport_size(u64 page_id, Web::DevicePixelSize const size)
  141. {
  142. if (auto page = this->page(page_id); page.has_value())
  143. page->set_viewport_size(size);
  144. }
  145. void ConnectionFromClient::ready_to_paint(u64 page_id)
  146. {
  147. if (auto page = this->page(page_id); page.has_value())
  148. page->ready_to_paint();
  149. }
  150. void ConnectionFromClient::process_next_input_event()
  151. {
  152. if (m_input_event_queue.is_empty())
  153. return;
  154. auto event = m_input_event_queue.dequeue();
  155. auto page = this->page(event.page_id);
  156. if (!page.has_value())
  157. return;
  158. auto handled = event.event.visit(
  159. [&](Web::KeyEvent const& event) {
  160. switch (event.type) {
  161. case Web::KeyEvent::Type::KeyDown:
  162. return page->page().handle_keydown(event.key, event.modifiers, event.code_point);
  163. case Web::KeyEvent::Type::KeyUp:
  164. return page->page().handle_keyup(event.key, event.modifiers, event.code_point);
  165. }
  166. VERIFY_NOT_REACHED();
  167. },
  168. [&](Web::MouseEvent const& event) {
  169. switch (event.type) {
  170. case Web::MouseEvent::Type::MouseDown:
  171. return page->page().handle_mousedown(event.position, event.screen_position, event.button, event.buttons, event.modifiers);
  172. case Web::MouseEvent::Type::MouseUp:
  173. return page->page().handle_mouseup(event.position, event.screen_position, event.button, event.buttons, event.modifiers);
  174. case Web::MouseEvent::Type::MouseMove:
  175. return page->page().handle_mousemove(event.position, event.screen_position, event.buttons, event.modifiers);
  176. case Web::MouseEvent::Type::MouseWheel:
  177. return page->page().handle_mousewheel(event.position, event.screen_position, event.button, event.buttons, event.modifiers, event.wheel_delta_x, event.wheel_delta_y);
  178. case Web::MouseEvent::Type::DoubleClick:
  179. return page->page().handle_doubleclick(event.position, event.screen_position, event.button, event.buttons, event.modifiers);
  180. }
  181. VERIFY_NOT_REACHED();
  182. });
  183. // We have to notify the client about coalesced events, so we do that by saying none of them were handled by the web page->
  184. for (size_t i = 0; i < event.coalesced_event_count; ++i)
  185. report_finished_handling_input_event(event.page_id, false);
  186. report_finished_handling_input_event(event.page_id, handled);
  187. if (!m_input_event_queue.is_empty())
  188. m_input_event_queue_timer->start();
  189. }
  190. void ConnectionFromClient::key_event(u64 page_id, Web::KeyEvent const& event)
  191. {
  192. enqueue_input_event({ page_id, move(const_cast<Web::KeyEvent&>(event)), 0 });
  193. }
  194. void ConnectionFromClient::mouse_event(u64 page_id, Web::MouseEvent const& event)
  195. {
  196. // OPTIMIZATION: Coalesce consecutive unprocessed mouse move and wheel events.
  197. auto event_to_coalesce = [&]() -> Web::MouseEvent const* {
  198. if (m_input_event_queue.is_empty())
  199. return nullptr;
  200. if (m_input_event_queue.tail().page_id != page_id)
  201. return nullptr;
  202. if (event.type != Web::MouseEvent::Type::MouseMove && event.type != Web::MouseEvent::Type::MouseWheel)
  203. return nullptr;
  204. if (auto const* mouse_event = m_input_event_queue.tail().event.get_pointer<Web::MouseEvent>()) {
  205. if (mouse_event->type == event.type)
  206. return mouse_event;
  207. }
  208. return nullptr;
  209. };
  210. if (auto const* last_mouse_event = event_to_coalesce()) {
  211. auto& mutable_event = const_cast<Web::MouseEvent&>(event);
  212. mutable_event.wheel_delta_x += last_mouse_event->wheel_delta_x;
  213. mutable_event.wheel_delta_y += last_mouse_event->wheel_delta_y;
  214. m_input_event_queue.tail().event = move(mutable_event);
  215. ++m_input_event_queue.tail().coalesced_event_count;
  216. return;
  217. }
  218. enqueue_input_event({ page_id, move(const_cast<Web::MouseEvent&>(event)), 0 });
  219. }
  220. void ConnectionFromClient::enqueue_input_event(QueuedInputEvent event)
  221. {
  222. m_input_event_queue.enqueue(move(event));
  223. m_input_event_queue_timer->start();
  224. }
  225. void ConnectionFromClient::report_finished_handling_input_event(u64 page_id, bool event_was_handled)
  226. {
  227. async_did_finish_handling_input_event(page_id, event_was_handled);
  228. }
  229. void ConnectionFromClient::debug_request(u64 page_id, ByteString const& request, ByteString const& argument)
  230. {
  231. auto page = this->page(page_id);
  232. if (!page.has_value())
  233. return;
  234. if (request == "dump-session-history") {
  235. auto const& traversable = page->page().top_level_traversable();
  236. Web::dump_tree(*traversable);
  237. }
  238. if (request == "dump-dom-tree") {
  239. if (auto* doc = page->page().top_level_browsing_context().active_document())
  240. Web::dump_tree(*doc);
  241. return;
  242. }
  243. if (request == "dump-layout-tree") {
  244. if (auto* doc = page->page().top_level_browsing_context().active_document()) {
  245. if (auto* viewport = doc->layout_node())
  246. Web::dump_tree(*viewport);
  247. }
  248. return;
  249. }
  250. if (request == "dump-paint-tree") {
  251. if (auto* doc = page->page().top_level_browsing_context().active_document()) {
  252. if (auto* paintable = doc->paintable())
  253. Web::dump_tree(*paintable);
  254. }
  255. return;
  256. }
  257. if (request == "dump-stacking-context-tree") {
  258. if (auto* doc = page->page().top_level_browsing_context().active_document()) {
  259. if (auto* viewport = doc->layout_node()) {
  260. if (auto* stacking_context = viewport->paintable_box()->stacking_context())
  261. stacking_context->dump();
  262. }
  263. }
  264. return;
  265. }
  266. if (request == "dump-style-sheets") {
  267. if (auto* doc = page->page().top_level_browsing_context().active_document()) {
  268. for (auto& sheet : doc->style_sheets().sheets()) {
  269. if (auto result = Web::dump_sheet(sheet); result.is_error())
  270. dbgln("Failed to dump style sheets: {}", result.error());
  271. }
  272. }
  273. return;
  274. }
  275. if (request == "dump-all-resolved-styles") {
  276. if (auto* doc = page->page().top_level_browsing_context().active_document()) {
  277. Queue<Web::DOM::Node*> elements_to_visit;
  278. elements_to_visit.enqueue(doc->document_element());
  279. while (!elements_to_visit.is_empty()) {
  280. auto element = elements_to_visit.dequeue();
  281. for (auto& child : element->children_as_vector())
  282. elements_to_visit.enqueue(child.ptr());
  283. if (element->is_element()) {
  284. auto styles = doc->style_computer().compute_style(*static_cast<Web::DOM::Element*>(element));
  285. dbgln("+ Element {}", element->debug_description());
  286. for (size_t i = 0; i < Web::CSS::StyleProperties::number_of_properties; ++i) {
  287. auto property = styles->maybe_null_property(static_cast<Web::CSS::PropertyID>(i));
  288. dbgln("| {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), property ? property->to_string() : ""_string);
  289. }
  290. dbgln("---");
  291. }
  292. }
  293. }
  294. return;
  295. }
  296. if (request == "collect-garbage") {
  297. Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
  298. return;
  299. }
  300. if (request == "set-line-box-borders") {
  301. bool state = argument == "on";
  302. page->set_should_show_line_box_borders(state);
  303. page->page().top_level_traversable()->set_needs_display(page->page().top_level_traversable()->viewport_rect());
  304. return;
  305. }
  306. if (request == "clear-cache") {
  307. Web::ResourceLoader::the().clear_cache();
  308. return;
  309. }
  310. if (request == "spoof-user-agent") {
  311. Web::ResourceLoader::the().set_user_agent(MUST(String::from_byte_string(argument)));
  312. return;
  313. }
  314. if (request == "same-origin-policy") {
  315. page->page().set_same_origin_policy_enabled(argument == "on");
  316. return;
  317. }
  318. if (request == "scripting") {
  319. page->page().set_is_scripting_enabled(argument == "on");
  320. return;
  321. }
  322. if (request == "block-pop-ups") {
  323. page->page().set_should_block_pop_ups(argument == "on");
  324. return;
  325. }
  326. if (request == "dump-local-storage") {
  327. if (auto* document = page->page().top_level_browsing_context().active_document())
  328. document->window()->local_storage().release_value_but_fixme_should_propagate_errors()->dump();
  329. return;
  330. }
  331. if (request == "load-reference-page") {
  332. if (auto* document = page->page().top_level_browsing_context().active_document()) {
  333. auto maybe_link = document->query_selector("link[rel=match]"sv);
  334. if (maybe_link.is_error() || !maybe_link.value()) {
  335. // To make sure that we fail the ref-test if the link is missing, load the error page->
  336. load_html(page_id, "<h1>Failed to find &lt;link rel=&quot;match&quot; /&gt; in ref test page!</h1> Make sure you added it.");
  337. } else {
  338. auto link = maybe_link.release_value();
  339. auto url = document->parse_url(link->get_attribute_value(Web::HTML::AttributeNames::href));
  340. load_url(page_id, url);
  341. }
  342. }
  343. return;
  344. }
  345. if (request == "navigator-compatibility-mode") {
  346. Web::NavigatorCompatibilityMode compatibility_mode;
  347. if (argument == "chrome") {
  348. compatibility_mode = Web::NavigatorCompatibilityMode::Chrome;
  349. } else if (argument == "gecko") {
  350. compatibility_mode = Web::NavigatorCompatibilityMode::Gecko;
  351. } else if (argument == "webkit") {
  352. compatibility_mode = Web::NavigatorCompatibilityMode::WebKit;
  353. } else {
  354. dbgln("Unknown navigator compatibility mode '{}', defaulting to Chrome", argument);
  355. compatibility_mode = Web::NavigatorCompatibilityMode::Chrome;
  356. }
  357. Web::ResourceLoader::the().set_navigator_compatibility_mode(compatibility_mode);
  358. return;
  359. }
  360. }
  361. void ConnectionFromClient::get_source(u64 page_id)
  362. {
  363. if (auto page = this->page(page_id); page.has_value()) {
  364. if (auto* doc = page->page().top_level_browsing_context().active_document())
  365. async_did_get_source(page_id, doc->url(), doc->source().to_byte_string());
  366. }
  367. }
  368. void ConnectionFromClient::inspect_dom_tree(u64 page_id)
  369. {
  370. if (auto page = this->page(page_id); page.has_value()) {
  371. if (auto* doc = page->page().top_level_browsing_context().active_document())
  372. async_did_inspect_dom_tree(page_id, doc->dump_dom_tree_as_json().to_byte_string());
  373. }
  374. }
  375. void ConnectionFromClient::inspect_dom_node(u64 page_id, i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element)
  376. {
  377. auto page = this->page(page_id);
  378. if (!page.has_value())
  379. return;
  380. auto& top_context = page->page().top_level_browsing_context();
  381. top_context.for_each_in_inclusive_subtree([&](auto& ctx) {
  382. if (ctx.active_document() != nullptr) {
  383. ctx.active_document()->set_inspected_node(nullptr, {});
  384. }
  385. return Web::TraversalDecision::Continue;
  386. });
  387. Web::DOM::Node* node = Web::DOM::Node::from_unique_id(node_id);
  388. // Note: Nodes without layout (aka non-visible nodes, don't have style computed)
  389. if (!node || !node->layout_node()) {
  390. async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {});
  391. return;
  392. }
  393. node->document().set_inspected_node(node, pseudo_element);
  394. if (node->is_element()) {
  395. auto& element = verify_cast<Web::DOM::Element>(*node);
  396. if (!element.computed_css_values()) {
  397. async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {});
  398. return;
  399. }
  400. auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> ByteString {
  401. StringBuilder builder;
  402. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  403. properties.for_each_property([&](auto property_id, auto& value) {
  404. MUST(serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string().to_byte_string()));
  405. });
  406. MUST(serializer.finish());
  407. return builder.to_byte_string();
  408. };
  409. auto serialize_custom_properties_json = [](Web::DOM::Element const& element, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) -> ByteString {
  410. StringBuilder builder;
  411. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  412. HashTable<FlyString> seen_properties;
  413. auto const* element_to_check = &element;
  414. while (element_to_check) {
  415. for (auto const& property : element_to_check->custom_properties(pseudo_element)) {
  416. if (!seen_properties.contains(property.key)) {
  417. seen_properties.set(property.key);
  418. MUST(serializer.add(property.key, property.value.value->to_string()));
  419. }
  420. }
  421. element_to_check = element_to_check->parent_element();
  422. }
  423. MUST(serializer.finish());
  424. return builder.to_byte_string();
  425. };
  426. auto serialize_node_box_sizing_json = [](Web::Layout::Node const* layout_node) -> ByteString {
  427. if (!layout_node || !layout_node->is_box()) {
  428. return "{}";
  429. }
  430. auto* box = static_cast<Web::Layout::Box const*>(layout_node);
  431. auto box_model = box->box_model();
  432. StringBuilder builder;
  433. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  434. MUST(serializer.add("padding_top"sv, box_model.padding.top.to_double()));
  435. MUST(serializer.add("padding_right"sv, box_model.padding.right.to_double()));
  436. MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom.to_double()));
  437. MUST(serializer.add("padding_left"sv, box_model.padding.left.to_double()));
  438. MUST(serializer.add("margin_top"sv, box_model.margin.top.to_double()));
  439. MUST(serializer.add("margin_right"sv, box_model.margin.right.to_double()));
  440. MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom.to_double()));
  441. MUST(serializer.add("margin_left"sv, box_model.margin.left.to_double()));
  442. MUST(serializer.add("border_top"sv, box_model.border.top.to_double()));
  443. MUST(serializer.add("border_right"sv, box_model.border.right.to_double()));
  444. MUST(serializer.add("border_bottom"sv, box_model.border.bottom.to_double()));
  445. MUST(serializer.add("border_left"sv, box_model.border.left.to_double()));
  446. if (auto* paintable_box = box->paintable_box()) {
  447. MUST(serializer.add("content_width"sv, paintable_box->content_width().to_double()));
  448. MUST(serializer.add("content_height"sv, paintable_box->content_height().to_double()));
  449. } else {
  450. MUST(serializer.add("content_width"sv, 0));
  451. MUST(serializer.add("content_height"sv, 0));
  452. }
  453. MUST(serializer.finish());
  454. return builder.to_byte_string();
  455. };
  456. auto serialize_aria_properties_state_json = [](Web::DOM::Element const& element) -> ByteString {
  457. auto role_name = element.role_or_default();
  458. if (!role_name.has_value()) {
  459. return "";
  460. }
  461. auto aria_data = MUST(Web::ARIA::AriaData::build_data(element));
  462. auto role = MUST(Web::ARIA::RoleType::build_role_object(role_name.value(), element.is_focusable(), *aria_data));
  463. StringBuilder builder;
  464. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  465. MUST(role->serialize_as_json(serializer));
  466. MUST(serializer.finish());
  467. return builder.to_byte_string();
  468. };
  469. if (pseudo_element.has_value()) {
  470. auto pseudo_element_node = element.get_pseudo_element_node(pseudo_element.value());
  471. if (!pseudo_element_node) {
  472. async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {});
  473. return;
  474. }
  475. // FIXME: Pseudo-elements only exist as Layout::Nodes, which don't have style information
  476. // in a format we can use. So, we run the StyleComputer again to get the specified
  477. // values, and have to ignore the computed values and custom properties.
  478. auto pseudo_element_style = page->page().focused_navigable().active_document()->style_computer().compute_style(element, pseudo_element);
  479. ByteString computed_values = serialize_json(pseudo_element_style);
  480. ByteString resolved_values = "{}";
  481. ByteString custom_properties_json = serialize_custom_properties_json(element, pseudo_element);
  482. ByteString node_box_sizing_json = serialize_node_box_sizing_json(pseudo_element_node.ptr());
  483. async_did_inspect_dom_node(page_id, true, move(computed_values), move(resolved_values), move(custom_properties_json), move(node_box_sizing_json), {});
  484. return;
  485. }
  486. ByteString computed_values = serialize_json(*element.computed_css_values());
  487. ByteString resolved_values = serialize_json(element.resolved_css_values());
  488. ByteString custom_properties_json = serialize_custom_properties_json(element, {});
  489. ByteString node_box_sizing_json = serialize_node_box_sizing_json(element.layout_node());
  490. ByteString aria_properties_state_json = serialize_aria_properties_state_json(element);
  491. async_did_inspect_dom_node(page_id, true, move(computed_values), move(resolved_values), move(custom_properties_json), move(node_box_sizing_json), move(aria_properties_state_json));
  492. return;
  493. }
  494. async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {});
  495. }
  496. void ConnectionFromClient::inspect_accessibility_tree(u64 page_id)
  497. {
  498. if (auto page = this->page(page_id); page.has_value()) {
  499. if (auto* doc = page->page().top_level_browsing_context().active_document())
  500. async_did_inspect_accessibility_tree(page_id, doc->dump_accessibility_tree_as_json().to_byte_string());
  501. }
  502. }
  503. void ConnectionFromClient::get_hovered_node_id(u64 page_id)
  504. {
  505. auto page = this->page(page_id);
  506. if (!page.has_value())
  507. return;
  508. i32 node_id = 0;
  509. if (auto* document = page->page().top_level_browsing_context().active_document()) {
  510. if (auto* hovered_node = document->hovered_node())
  511. node_id = hovered_node->unique_id();
  512. }
  513. async_did_get_hovered_node_id(page_id, node_id);
  514. }
  515. void ConnectionFromClient::set_dom_node_text(u64 page_id, i32 node_id, String const& text)
  516. {
  517. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  518. if (!dom_node || (!dom_node->is_text() && !dom_node->is_comment())) {
  519. async_did_finish_editing_dom_node(page_id, {});
  520. return;
  521. }
  522. auto& character_data = static_cast<Web::DOM::CharacterData&>(*dom_node);
  523. character_data.set_data(text);
  524. async_did_finish_editing_dom_node(page_id, character_data.unique_id());
  525. }
  526. void ConnectionFromClient::set_dom_node_tag(u64 page_id, i32 node_id, String const& name)
  527. {
  528. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  529. if (!dom_node || !dom_node->is_element() || !dom_node->parent()) {
  530. async_did_finish_editing_dom_node(page_id, {});
  531. return;
  532. }
  533. auto& element = static_cast<Web::DOM::Element&>(*dom_node);
  534. auto new_element = Web::DOM::create_element(element.document(), name, element.namespace_uri(), element.prefix(), element.is_value()).release_value_but_fixme_should_propagate_errors();
  535. element.for_each_attribute([&](auto const& attribute) {
  536. new_element->set_attribute_value(attribute.local_name(), attribute.value(), attribute.prefix(), attribute.namespace_uri());
  537. });
  538. while (auto* child_node = element.first_child()) {
  539. MUST(element.remove_child(*child_node));
  540. MUST(new_element->append_child(*child_node));
  541. }
  542. element.parent()->replace_child(*new_element, element).release_value_but_fixme_should_propagate_errors();
  543. async_did_finish_editing_dom_node(page_id, new_element->unique_id());
  544. }
  545. void ConnectionFromClient::add_dom_node_attributes(u64 page_id, i32 node_id, Vector<WebView::Attribute> const& attributes)
  546. {
  547. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  548. if (!dom_node || !dom_node->is_element()) {
  549. async_did_finish_editing_dom_node(page_id, {});
  550. return;
  551. }
  552. auto& element = static_cast<Web::DOM::Element&>(*dom_node);
  553. for (auto const& attribute : attributes) {
  554. // NOTE: We ignore invalid attributes for now, but we may want to send feedback to the user that this failed.
  555. (void)element.set_attribute(attribute.name, attribute.value);
  556. }
  557. async_did_finish_editing_dom_node(page_id, element.unique_id());
  558. }
  559. void ConnectionFromClient::replace_dom_node_attribute(u64 page_id, i32 node_id, String const& name, Vector<WebView::Attribute> const& replacement_attributes)
  560. {
  561. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  562. if (!dom_node || !dom_node->is_element()) {
  563. async_did_finish_editing_dom_node(page_id, {});
  564. return;
  565. }
  566. auto& element = static_cast<Web::DOM::Element&>(*dom_node);
  567. bool should_remove_attribute = true;
  568. for (auto const& attribute : replacement_attributes) {
  569. if (should_remove_attribute && Web::Infra::is_ascii_case_insensitive_match(name, attribute.name))
  570. should_remove_attribute = false;
  571. // NOTE: We ignore invalid attributes for now, but we may want to send feedback to the user that this failed.
  572. (void)element.set_attribute(attribute.name, attribute.value);
  573. }
  574. if (should_remove_attribute)
  575. element.remove_attribute(name);
  576. async_did_finish_editing_dom_node(page_id, element.unique_id());
  577. }
  578. void ConnectionFromClient::create_child_element(u64 page_id, i32 node_id)
  579. {
  580. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  581. if (!dom_node) {
  582. async_did_finish_editing_dom_node(page_id, {});
  583. return;
  584. }
  585. auto element = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors();
  586. dom_node->append_child(element).release_value_but_fixme_should_propagate_errors();
  587. async_did_finish_editing_dom_node(page_id, element->unique_id());
  588. }
  589. void ConnectionFromClient::create_child_text_node(u64 page_id, i32 node_id)
  590. {
  591. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  592. if (!dom_node) {
  593. async_did_finish_editing_dom_node(page_id, {});
  594. return;
  595. }
  596. auto text_node = dom_node->heap().allocate<Web::DOM::Text>(dom_node->realm(), dom_node->document(), "text"_string);
  597. dom_node->append_child(text_node).release_value_but_fixme_should_propagate_errors();
  598. async_did_finish_editing_dom_node(page_id, text_node->unique_id());
  599. }
  600. void ConnectionFromClient::clone_dom_node(u64 page_id, i32 node_id)
  601. {
  602. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  603. if (!dom_node || !dom_node->parent_node()) {
  604. async_did_finish_editing_dom_node(page_id, {});
  605. return;
  606. }
  607. auto dom_node_clone = MUST(dom_node->clone_node(nullptr, true));
  608. dom_node->parent_node()->insert_before(dom_node_clone, dom_node->next_sibling());
  609. async_did_finish_editing_dom_node(page_id, dom_node_clone->unique_id());
  610. }
  611. void ConnectionFromClient::remove_dom_node(u64 page_id, i32 node_id)
  612. {
  613. auto page = this->page(page_id);
  614. if (!page.has_value())
  615. return;
  616. auto* active_document = page->page().top_level_browsing_context().active_document();
  617. if (!active_document) {
  618. async_did_finish_editing_dom_node(page_id, {});
  619. return;
  620. }
  621. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  622. if (!dom_node) {
  623. async_did_finish_editing_dom_node(page_id, {});
  624. return;
  625. }
  626. auto* previous_dom_node = dom_node->previous_sibling();
  627. if (!previous_dom_node)
  628. previous_dom_node = dom_node->parent();
  629. dom_node->remove();
  630. async_did_finish_editing_dom_node(page_id, previous_dom_node->unique_id());
  631. }
  632. void ConnectionFromClient::get_dom_node_html(u64 page_id, i32 node_id)
  633. {
  634. auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
  635. if (!dom_node)
  636. return;
  637. String html;
  638. if (dom_node->is_element()) {
  639. auto const& element = static_cast<Web::DOM::Element const&>(*dom_node);
  640. html = element.outer_html().release_value_but_fixme_should_propagate_errors();
  641. } else if (dom_node->is_text() || dom_node->is_comment()) {
  642. auto const& character_data = static_cast<Web::DOM::CharacterData const&>(*dom_node);
  643. html = character_data.data();
  644. } else {
  645. return;
  646. }
  647. async_did_get_dom_node_html(page_id, move(html));
  648. }
  649. void ConnectionFromClient::take_document_screenshot(u64 page_id)
  650. {
  651. auto page = this->page(page_id);
  652. if (!page.has_value())
  653. return;
  654. page->queue_screenshot_task({});
  655. }
  656. void ConnectionFromClient::take_dom_node_screenshot(u64 page_id, i32 node_id)
  657. {
  658. auto page = this->page(page_id);
  659. if (!page.has_value())
  660. return;
  661. page->queue_screenshot_task(node_id);
  662. }
  663. Messages::WebContentServer::DumpGcGraphResponse ConnectionFromClient::dump_gc_graph(u64)
  664. {
  665. auto gc_graph_json = Web::Bindings::main_thread_vm().heap().dump_graph();
  666. return MUST(String::from_byte_string(gc_graph_json.to_byte_string()));
  667. }
  668. Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text(u64 page_id)
  669. {
  670. if (auto page = this->page(page_id); page.has_value())
  671. return page->page().focused_navigable().selected_text().to_byte_string();
  672. return ByteString {};
  673. }
  674. void ConnectionFromClient::select_all(u64 page_id)
  675. {
  676. if (auto page = this->page(page_id); page.has_value())
  677. page->page().focused_navigable().select_all();
  678. }
  679. void ConnectionFromClient::find_in_page(u64 page_id, String const& query, CaseSensitivity case_sensitivity)
  680. {
  681. auto page = this->page(page_id);
  682. if (!page.has_value())
  683. return;
  684. auto result = page->page().find_in_page({ .string = query, .case_sensitivity = case_sensitivity });
  685. async_did_find_in_page(page_id, result.current_match_index, result.total_match_count);
  686. }
  687. void ConnectionFromClient::find_in_page_next_match(u64 page_id)
  688. {
  689. auto page = this->page(page_id);
  690. if (!page.has_value())
  691. return;
  692. auto result = page->page().find_in_page_next_match();
  693. async_did_find_in_page(page_id, result.current_match_index, result.total_match_count);
  694. }
  695. void ConnectionFromClient::find_in_page_previous_match(u64 page_id)
  696. {
  697. auto page = this->page(page_id);
  698. if (!page.has_value())
  699. return;
  700. auto result = page->page().find_in_page_previous_match();
  701. async_did_find_in_page(page_id, result.current_match_index, result.total_match_count);
  702. }
  703. void ConnectionFromClient::paste(u64 page_id, String const& text)
  704. {
  705. if (auto page = this->page(page_id); page.has_value())
  706. page->page().focused_navigable().paste(text);
  707. }
  708. Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_layout_tree(u64 page_id)
  709. {
  710. auto page = this->page(page_id);
  711. if (!page.has_value())
  712. return ByteString { "(no page)" };
  713. auto* document = page->page().top_level_browsing_context().active_document();
  714. if (!document)
  715. return ByteString { "(no DOM tree)" };
  716. document->update_layout();
  717. auto* layout_root = document->layout_node();
  718. if (!layout_root)
  719. return ByteString { "(no layout tree)" };
  720. StringBuilder builder;
  721. Web::dump_tree(builder, *layout_root);
  722. return builder.to_byte_string();
  723. }
  724. Messages::WebContentServer::DumpPaintTreeResponse ConnectionFromClient::dump_paint_tree(u64 page_id)
  725. {
  726. auto page = this->page(page_id);
  727. if (!page.has_value())
  728. return ByteString { "(no page)" };
  729. auto* document = page->page().top_level_browsing_context().active_document();
  730. if (!document)
  731. return ByteString { "(no DOM tree)" };
  732. document->update_layout();
  733. auto* layout_root = document->layout_node();
  734. if (!layout_root)
  735. return ByteString { "(no layout tree)" };
  736. if (!layout_root->paintable())
  737. return ByteString { "(no paint tree)" };
  738. StringBuilder builder;
  739. Web::dump_tree(builder, *layout_root->paintable());
  740. return builder.to_byte_string();
  741. }
  742. Messages::WebContentServer::DumpTextResponse ConnectionFromClient::dump_text(u64 page_id)
  743. {
  744. auto page = this->page(page_id);
  745. if (!page.has_value())
  746. return ByteString { "(no page)" };
  747. auto* document = page->page().top_level_browsing_context().active_document();
  748. if (!document)
  749. return ByteString { "(no DOM tree)" };
  750. if (!document->body())
  751. return ByteString { "(no body)" };
  752. return document->body()->inner_text();
  753. }
  754. void ConnectionFromClient::set_content_filters(u64, Vector<String> const& filters)
  755. {
  756. Web::ContentFilter::the().set_patterns(filters).release_value_but_fixme_should_propagate_errors();
  757. }
  758. void ConnectionFromClient::set_autoplay_allowed_on_all_websites(u64)
  759. {
  760. auto& autoplay_allowlist = Web::PermissionsPolicy::AutoplayAllowlist::the();
  761. autoplay_allowlist.enable_globally();
  762. }
  763. void ConnectionFromClient::set_autoplay_allowlist(u64, Vector<String> const& allowlist)
  764. {
  765. auto& autoplay_allowlist = Web::PermissionsPolicy::AutoplayAllowlist::the();
  766. autoplay_allowlist.enable_for_origins(allowlist).release_value_but_fixme_should_propagate_errors();
  767. }
  768. void ConnectionFromClient::set_proxy_mappings(u64, Vector<ByteString> const& proxies, HashMap<ByteString, size_t> const& mappings)
  769. {
  770. auto keys = mappings.keys();
  771. quick_sort(keys, [&](auto& a, auto& b) { return a.length() < b.length(); });
  772. OrderedHashMap<ByteString, size_t> sorted_mappings;
  773. for (auto& key : keys) {
  774. auto value = *mappings.get(key);
  775. if (value >= proxies.size())
  776. continue;
  777. sorted_mappings.set(key, value);
  778. }
  779. Web::ProxyMappings::the().set_mappings(proxies, move(sorted_mappings));
  780. }
  781. void ConnectionFromClient::set_preferred_color_scheme(u64 page_id, Web::CSS::PreferredColorScheme const& color_scheme)
  782. {
  783. if (auto page = this->page(page_id); page.has_value())
  784. page->set_preferred_color_scheme(color_scheme);
  785. }
  786. void ConnectionFromClient::set_preferred_contrast(u64 page_id, Web::CSS::PreferredContrast const& contrast)
  787. {
  788. if (auto page = this->page(page_id); page.has_value())
  789. page->set_preferred_contrast(contrast);
  790. }
  791. void ConnectionFromClient::set_preferred_motion(u64 page_id, Web::CSS::PreferredMotion const& motion)
  792. {
  793. if (auto page = this->page(page_id); page.has_value())
  794. page->set_preferred_motion(motion);
  795. }
  796. void ConnectionFromClient::set_preferred_languages(u64, Vector<String> const& preferred_languages)
  797. {
  798. // FIXME: Whenever the user agent needs to make the navigator.languages attribute of a Window or WorkerGlobalScope
  799. // object global return a new set of language tags, the user agent must queue a global task on the DOM manipulation
  800. // task source given global to fire an event named languagechange at global, and wait until that task begins to be
  801. // executed before actually returning a new value.
  802. Web::ResourceLoader::the().set_preferred_languages(preferred_languages);
  803. }
  804. void ConnectionFromClient::set_enable_do_not_track(u64, bool enable)
  805. {
  806. Web::ResourceLoader::the().set_enable_do_not_track(enable);
  807. }
  808. void ConnectionFromClient::set_has_focus(u64 page_id, bool has_focus)
  809. {
  810. if (auto page = this->page(page_id); page.has_value())
  811. page->set_has_focus(has_focus);
  812. }
  813. void ConnectionFromClient::set_is_scripting_enabled(u64 page_id, bool is_scripting_enabled)
  814. {
  815. if (auto page = this->page(page_id); page.has_value())
  816. page->set_is_scripting_enabled(is_scripting_enabled);
  817. }
  818. void ConnectionFromClient::set_device_pixels_per_css_pixel(u64 page_id, float device_pixels_per_css_pixel)
  819. {
  820. if (auto page = this->page(page_id); page.has_value())
  821. page->set_device_pixels_per_css_pixel(device_pixels_per_css_pixel);
  822. }
  823. void ConnectionFromClient::set_window_position(u64 page_id, Web::DevicePixelPoint position)
  824. {
  825. if (auto page = this->page(page_id); page.has_value())
  826. page->set_window_position(position);
  827. }
  828. void ConnectionFromClient::set_window_size(u64 page_id, Web::DevicePixelSize size)
  829. {
  830. if (auto page = this->page(page_id); page.has_value())
  831. page->set_window_size(size);
  832. }
  833. Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient::get_local_storage_entries(u64 page_id)
  834. {
  835. auto page = this->page(page_id);
  836. if (!page.has_value())
  837. return OrderedHashMap<String, String> {};
  838. auto* document = page->page().top_level_browsing_context().active_document();
  839. auto local_storage = document->window()->local_storage().release_value_but_fixme_should_propagate_errors();
  840. return local_storage->map();
  841. }
  842. Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClient::get_session_storage_entries(u64 page_id)
  843. {
  844. auto page = this->page(page_id);
  845. if (!page.has_value())
  846. return OrderedHashMap<String, String> {};
  847. auto* document = page->page().top_level_browsing_context().active_document();
  848. auto session_storage = document->window()->session_storage().release_value_but_fixme_should_propagate_errors();
  849. return session_storage->map();
  850. }
  851. void ConnectionFromClient::handle_file_return(u64, i32 error, Optional<IPC::File> const& file, i32 request_id)
  852. {
  853. auto file_request = m_requested_files.take(request_id);
  854. VERIFY(file_request.has_value());
  855. VERIFY(file_request.value().on_file_request_finish);
  856. file_request.value().on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() });
  857. }
  858. void ConnectionFromClient::request_file(u64 page_id, Web::FileRequest file_request)
  859. {
  860. i32 const id = last_id++;
  861. auto path = file_request.path();
  862. m_requested_files.set(id, move(file_request));
  863. async_did_request_file(page_id, path, id);
  864. }
  865. void ConnectionFromClient::set_system_visibility_state(u64 page_id, bool visible)
  866. {
  867. if (auto page = this->page(page_id); page.has_value()) {
  868. page->page().top_level_traversable()->set_system_visibility_state(
  869. visible
  870. ? Web::HTML::VisibilityState::Visible
  871. : Web::HTML::VisibilityState::Hidden);
  872. }
  873. }
  874. void ConnectionFromClient::js_console_input(u64 page_id, ByteString const& js_source)
  875. {
  876. auto page = this->page(page_id);
  877. if (!page.has_value())
  878. return;
  879. page->js_console_input(js_source);
  880. }
  881. void ConnectionFromClient::run_javascript(u64 page_id, ByteString const& js_source)
  882. {
  883. if (auto page = this->page(page_id); page.has_value())
  884. page->run_javascript(js_source);
  885. }
  886. void ConnectionFromClient::js_console_request_messages(u64 page_id, i32 start_index)
  887. {
  888. if (auto page = this->page(page_id); page.has_value())
  889. page->js_console_request_messages(start_index);
  890. }
  891. void ConnectionFromClient::alert_closed(u64 page_id)
  892. {
  893. if (auto page = this->page(page_id); page.has_value())
  894. page->page().alert_closed();
  895. }
  896. void ConnectionFromClient::confirm_closed(u64 page_id, bool accepted)
  897. {
  898. if (auto page = this->page(page_id); page.has_value())
  899. page->page().confirm_closed(accepted);
  900. }
  901. void ConnectionFromClient::prompt_closed(u64 page_id, Optional<String> const& response)
  902. {
  903. if (auto page = this->page(page_id); page.has_value())
  904. page->page().prompt_closed(response);
  905. }
  906. void ConnectionFromClient::color_picker_update(u64 page_id, Optional<Color> const& picked_color, Web::HTML::ColorPickerUpdateState const& state)
  907. {
  908. if (auto page = this->page(page_id); page.has_value())
  909. page->page().color_picker_update(picked_color, state);
  910. }
  911. void ConnectionFromClient::file_picker_closed(u64 page_id, Vector<Web::HTML::SelectedFile> const& selected_files)
  912. {
  913. if (auto page = this->page(page_id); page.has_value())
  914. page->page().file_picker_closed(const_cast<Vector<Web::HTML::SelectedFile>&>(selected_files));
  915. }
  916. void ConnectionFromClient::select_dropdown_closed(u64 page_id, Optional<u32> const& selected_item_id)
  917. {
  918. if (auto page = this->page(page_id); page.has_value())
  919. page->page().select_dropdown_closed(selected_item_id);
  920. }
  921. void ConnectionFromClient::toggle_media_play_state(u64 page_id)
  922. {
  923. if (auto page = this->page(page_id); page.has_value())
  924. page->page().toggle_media_play_state().release_value_but_fixme_should_propagate_errors();
  925. }
  926. void ConnectionFromClient::toggle_media_mute_state(u64 page_id)
  927. {
  928. if (auto page = this->page(page_id); page.has_value())
  929. page->page().toggle_media_mute_state();
  930. }
  931. void ConnectionFromClient::toggle_media_loop_state(u64 page_id)
  932. {
  933. if (auto page = this->page(page_id); page.has_value())
  934. page->page().toggle_media_loop_state().release_value_but_fixme_should_propagate_errors();
  935. }
  936. void ConnectionFromClient::toggle_media_controls_state(u64 page_id)
  937. {
  938. if (auto page = this->page(page_id); page.has_value())
  939. page->page().toggle_media_controls_state().release_value_but_fixme_should_propagate_errors();
  940. }
  941. void ConnectionFromClient::toggle_page_mute_state(u64 page_id)
  942. {
  943. if (auto page = this->page(page_id); page.has_value())
  944. page->page().toggle_page_mute_state();
  945. }
  946. void ConnectionFromClient::set_user_style(u64 page_id, String const& source)
  947. {
  948. if (auto page = this->page(page_id); page.has_value())
  949. page->page().set_user_style(source);
  950. }
  951. void ConnectionFromClient::enable_inspector_prototype(u64)
  952. {
  953. Web::HTML::Window::set_inspector_object_exposed(true);
  954. }
  955. }