ConnectionFromClient.cpp 45 KB

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