ConnectionFromClient.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  5. * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
  6. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  7. *
  8. * SPDX-License-Identifier: BSD-2-Clause
  9. */
  10. #include <AK/Debug.h>
  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/Console.h>
  17. #include <LibJS/Heap/Heap.h>
  18. #include <LibJS/Runtime/ConsoleObject.h>
  19. #include <LibWeb/Bindings/MainThreadVM.h>
  20. #include <LibWeb/DOM/Document.h>
  21. #include <LibWeb/Dump.h>
  22. #include <LibWeb/HTML/BrowsingContext.h>
  23. #include <LibWeb/HTML/Scripting/ClassicScript.h>
  24. #include <LibWeb/HTML/Storage.h>
  25. #include <LibWeb/HTML/Window.h>
  26. #include <LibWeb/Layout/InitialContainingBlock.h>
  27. #include <LibWeb/Loader/ContentFilter.h>
  28. #include <LibWeb/Loader/ProxyMappings.h>
  29. #include <LibWeb/Loader/ResourceLoader.h>
  30. #include <LibWeb/Painting/PaintableBox.h>
  31. #include <LibWeb/Painting/StackingContext.h>
  32. #include <LibWeb/Platform/EventLoopPlugin.h>
  33. #include <WebContent/ConnectionFromClient.h>
  34. #include <WebContent/PageHost.h>
  35. #include <WebContent/WebContentClientEndpoint.h>
  36. #include <pthread.h>
  37. namespace WebContent {
  38. ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
  39. : IPC::ConnectionFromClient<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket), 1)
  40. , m_page_host(PageHost::create(*this))
  41. {
  42. m_paint_flush_timer = Web::Platform::Timer::create_single_shot(0, [this] { flush_pending_paint_requests(); });
  43. }
  44. void ConnectionFromClient::die()
  45. {
  46. Web::Platform::EventLoopPlugin::the().quit();
  47. }
  48. Web::Page& ConnectionFromClient::page()
  49. {
  50. return m_page_host->page();
  51. }
  52. Web::Page const& ConnectionFromClient::page() const
  53. {
  54. return m_page_host->page();
  55. }
  56. void ConnectionFromClient::connect_to_webdriver(DeprecatedString const& webdriver_ipc_path)
  57. {
  58. // FIXME: Propagate this error back to the browser.
  59. if (auto result = m_page_host->connect_to_webdriver(webdriver_ipc_path); result.is_error())
  60. dbgln("Unable to connect to the WebDriver process: {}", result.error());
  61. }
  62. void ConnectionFromClient::update_system_theme(Core::AnonymousBuffer const& theme_buffer)
  63. {
  64. Gfx::set_system_theme(theme_buffer);
  65. auto impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme_buffer);
  66. m_page_host->set_palette_impl(*impl);
  67. }
  68. void ConnectionFromClient::update_system_fonts(DeprecatedString const& default_font_query, DeprecatedString const& fixed_width_font_query, DeprecatedString const& window_title_font_query)
  69. {
  70. Gfx::FontDatabase::set_default_font_query(default_font_query);
  71. Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
  72. Gfx::FontDatabase::set_window_title_font_query(window_title_font_query);
  73. }
  74. void ConnectionFromClient::update_screen_rects(Vector<Gfx::IntRect> const& rects, u32 main_screen)
  75. {
  76. m_page_host->set_screen_rects(rects, main_screen);
  77. }
  78. void ConnectionFromClient::load_url(const URL& url)
  79. {
  80. dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadURL: url={}", url);
  81. #if defined(AK_OS_SERENITY)
  82. DeprecatedString process_name;
  83. if (url.host().is_empty())
  84. process_name = "WebContent";
  85. else
  86. process_name = DeprecatedString::formatted("WebContent: {}", url.host());
  87. pthread_setname_np(pthread_self(), process_name.characters());
  88. #endif
  89. page().load(url);
  90. }
  91. void ConnectionFromClient::load_html(DeprecatedString const& html, const URL& url)
  92. {
  93. dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadHTML: html={}, url={}", html, url);
  94. page().load_html(html, url);
  95. }
  96. void ConnectionFromClient::set_viewport_rect(Gfx::IntRect const& rect)
  97. {
  98. dbgln_if(SPAM_DEBUG, "handle: WebContentServer::SetViewportRect: rect={}", rect);
  99. m_page_host->set_viewport_rect(rect.to_type<Web::DevicePixels>());
  100. }
  101. void ConnectionFromClient::add_backing_store(i32 backing_store_id, Gfx::ShareableBitmap const& bitmap)
  102. {
  103. m_backing_stores.set(backing_store_id, *bitmap.bitmap());
  104. }
  105. void ConnectionFromClient::remove_backing_store(i32 backing_store_id)
  106. {
  107. m_backing_stores.remove(backing_store_id);
  108. m_pending_paint_requests.remove_all_matching([backing_store_id](auto& pending_repaint_request) { return pending_repaint_request.bitmap_id == backing_store_id; });
  109. }
  110. void ConnectionFromClient::paint(Gfx::IntRect const& content_rect, i32 backing_store_id)
  111. {
  112. for (auto& pending_paint : m_pending_paint_requests) {
  113. if (pending_paint.bitmap_id == backing_store_id) {
  114. pending_paint.content_rect = content_rect;
  115. return;
  116. }
  117. }
  118. auto it = m_backing_stores.find(backing_store_id);
  119. if (it == m_backing_stores.end()) {
  120. did_misbehave("Client requested paint with backing store ID");
  121. return;
  122. }
  123. auto& bitmap = *it->value;
  124. m_pending_paint_requests.append({ content_rect, bitmap, backing_store_id });
  125. m_paint_flush_timer->start();
  126. }
  127. void ConnectionFromClient::flush_pending_paint_requests()
  128. {
  129. for (auto& pending_paint : m_pending_paint_requests) {
  130. m_page_host->paint(pending_paint.content_rect.to_type<Web::DevicePixels>(), *pending_paint.bitmap);
  131. async_did_paint(pending_paint.content_rect, pending_paint.bitmap_id);
  132. }
  133. m_pending_paint_requests.clear();
  134. }
  135. void ConnectionFromClient::mouse_down(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers)
  136. {
  137. report_finished_handling_input_event(page().handle_mousedown(position.to_type<Web::DevicePixels>(), button, buttons, modifiers));
  138. }
  139. void ConnectionFromClient::mouse_move(Gfx::IntPoint position, [[maybe_unused]] unsigned int button, unsigned int buttons, unsigned int modifiers)
  140. {
  141. report_finished_handling_input_event(page().handle_mousemove(position.to_type<Web::DevicePixels>(), buttons, modifiers));
  142. }
  143. void ConnectionFromClient::mouse_up(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers)
  144. {
  145. report_finished_handling_input_event(page().handle_mouseup(position.to_type<Web::DevicePixels>(), button, buttons, modifiers));
  146. }
  147. void ConnectionFromClient::mouse_wheel(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers, i32 wheel_delta_x, i32 wheel_delta_y)
  148. {
  149. report_finished_handling_input_event(page().handle_mousewheel(position.to_type<Web::DevicePixels>(), button, buttons, modifiers, wheel_delta_x, wheel_delta_y));
  150. }
  151. void ConnectionFromClient::doubleclick(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers)
  152. {
  153. report_finished_handling_input_event(page().handle_doubleclick(position.to_type<Web::DevicePixels>(), button, buttons, modifiers));
  154. }
  155. void ConnectionFromClient::key_down(i32 key, unsigned int modifiers, u32 code_point)
  156. {
  157. report_finished_handling_input_event(page().handle_keydown((KeyCode)key, modifiers, code_point));
  158. }
  159. void ConnectionFromClient::key_up(i32 key, unsigned int modifiers, u32 code_point)
  160. {
  161. report_finished_handling_input_event(page().handle_keyup((KeyCode)key, modifiers, code_point));
  162. }
  163. void ConnectionFromClient::report_finished_handling_input_event(bool event_was_handled)
  164. {
  165. async_did_finish_handling_input_event(event_was_handled);
  166. }
  167. void ConnectionFromClient::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
  168. {
  169. if (request == "dump-dom-tree") {
  170. if (auto* doc = page().top_level_browsing_context().active_document())
  171. Web::dump_tree(*doc);
  172. }
  173. if (request == "dump-layout-tree") {
  174. if (auto* doc = page().top_level_browsing_context().active_document()) {
  175. if (auto* icb = doc->layout_node())
  176. Web::dump_tree(*icb);
  177. }
  178. }
  179. if (request == "dump-stacking-context-tree") {
  180. if (auto* doc = page().top_level_browsing_context().active_document()) {
  181. if (auto* icb = doc->layout_node()) {
  182. if (auto* stacking_context = icb->paint_box()->stacking_context())
  183. stacking_context->dump();
  184. }
  185. }
  186. }
  187. if (request == "dump-style-sheets") {
  188. if (auto* doc = page().top_level_browsing_context().active_document()) {
  189. for (auto& sheet : doc->style_sheets().sheets()) {
  190. Web::dump_sheet(sheet);
  191. }
  192. }
  193. }
  194. if (request == "collect-garbage") {
  195. Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
  196. }
  197. if (request == "set-line-box-borders") {
  198. bool state = argument == "on";
  199. m_page_host->set_should_show_line_box_borders(state);
  200. page().top_level_browsing_context().set_needs_display(page().top_level_browsing_context().viewport_rect());
  201. }
  202. if (request == "clear-cache") {
  203. Web::ResourceLoader::the().clear_cache();
  204. }
  205. if (request == "spoof-user-agent") {
  206. Web::ResourceLoader::the().set_user_agent(argument);
  207. }
  208. if (request == "same-origin-policy") {
  209. m_page_host->page().set_same_origin_policy_enabled(argument == "on");
  210. }
  211. if (request == "scripting") {
  212. m_page_host->page().set_is_scripting_enabled(argument == "on");
  213. }
  214. if (request == "block-pop-ups") {
  215. m_page_host->page().set_should_block_pop_ups(argument == "on");
  216. }
  217. if (request == "dump-local-storage") {
  218. if (auto* doc = page().top_level_browsing_context().active_document())
  219. doc->window().local_storage()->dump();
  220. }
  221. }
  222. void ConnectionFromClient::get_source()
  223. {
  224. if (auto* doc = page().top_level_browsing_context().active_document()) {
  225. async_did_get_source(doc->url(), doc->source());
  226. }
  227. }
  228. void ConnectionFromClient::inspect_dom_tree()
  229. {
  230. if (auto* doc = page().top_level_browsing_context().active_document()) {
  231. async_did_get_dom_tree(doc->dump_dom_tree_as_json());
  232. }
  233. }
  234. Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element)
  235. {
  236. auto& top_context = page().top_level_browsing_context();
  237. top_context.for_each_in_inclusive_subtree([&](auto& ctx) {
  238. if (ctx.active_document() != nullptr) {
  239. ctx.active_document()->set_inspected_node(nullptr);
  240. }
  241. return IterationDecision::Continue;
  242. });
  243. Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
  244. // Note: Nodes without layout (aka non-visible nodes, don't have style computed)
  245. if (!node || !node->layout_node()) {
  246. return { false, "", "", "", "" };
  247. }
  248. // FIXME: Pass the pseudo-element here.
  249. node->document().set_inspected_node(node);
  250. if (node->is_element()) {
  251. auto& element = verify_cast<Web::DOM::Element>(*node);
  252. if (!element.computed_css_values())
  253. return { false, "", "", "", "" };
  254. auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> DeprecatedString {
  255. StringBuilder builder;
  256. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  257. properties.for_each_property([&](auto property_id, auto& value) {
  258. MUST(serializer.add(Web::CSS::string_from_property_id(property_id), value.to_deprecated_string()));
  259. });
  260. MUST(serializer.finish());
  261. return builder.to_deprecated_string();
  262. };
  263. auto serialize_custom_properties_json = [](Web::DOM::Element const& element) -> DeprecatedString {
  264. StringBuilder builder;
  265. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  266. HashTable<DeprecatedString> seen_properties;
  267. auto const* element_to_check = &element;
  268. while (element_to_check) {
  269. for (auto const& property : element_to_check->custom_properties()) {
  270. if (!seen_properties.contains(property.key)) {
  271. seen_properties.set(property.key);
  272. MUST(serializer.add(property.key, property.value.value->to_deprecated_string()));
  273. }
  274. }
  275. element_to_check = element_to_check->parent_element();
  276. }
  277. MUST(serializer.finish());
  278. return builder.to_deprecated_string();
  279. };
  280. auto serialize_node_box_sizing_json = [](Web::Layout::Node const* layout_node) -> DeprecatedString {
  281. if (!layout_node || !layout_node->is_box()) {
  282. return "{}";
  283. }
  284. auto* box = static_cast<Web::Layout::Box const*>(layout_node);
  285. auto box_model = box->box_model();
  286. StringBuilder builder;
  287. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  288. MUST(serializer.add("padding_top"sv, box_model.padding.top.value()));
  289. MUST(serializer.add("padding_right"sv, box_model.padding.right.value()));
  290. MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom.value()));
  291. MUST(serializer.add("padding_left"sv, box_model.padding.left.value()));
  292. MUST(serializer.add("margin_top"sv, box_model.margin.top.value()));
  293. MUST(serializer.add("margin_right"sv, box_model.margin.right.value()));
  294. MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom.value()));
  295. MUST(serializer.add("margin_left"sv, box_model.margin.left.value()));
  296. MUST(serializer.add("border_top"sv, box_model.border.top.value()));
  297. MUST(serializer.add("border_right"sv, box_model.border.right.value()));
  298. MUST(serializer.add("border_bottom"sv, box_model.border.bottom.value()));
  299. MUST(serializer.add("border_left"sv, box_model.border.left.value()));
  300. if (auto* paint_box = box->paint_box()) {
  301. MUST(serializer.add("content_width"sv, paint_box->content_width().value()));
  302. MUST(serializer.add("content_height"sv, paint_box->content_height().value()));
  303. } else {
  304. MUST(serializer.add("content_width"sv, 0));
  305. MUST(serializer.add("content_height"sv, 0));
  306. }
  307. MUST(serializer.finish());
  308. return builder.to_deprecated_string();
  309. };
  310. if (pseudo_element.has_value()) {
  311. auto pseudo_element_node = element.get_pseudo_element_node(pseudo_element.value());
  312. if (!pseudo_element_node)
  313. return { false, "", "", "", "" };
  314. // FIXME: Pseudo-elements only exist as Layout::Nodes, which don't have style information
  315. // in a format we can use. So, we run the StyleComputer again to get the specified
  316. // values, and have to ignore the computed values and custom properties.
  317. auto pseudo_element_style = MUST(page().focused_context().active_document()->style_computer().compute_style(element, pseudo_element));
  318. DeprecatedString computed_values = serialize_json(pseudo_element_style);
  319. DeprecatedString resolved_values = "{}";
  320. DeprecatedString custom_properties_json = "{}";
  321. DeprecatedString node_box_sizing_json = serialize_node_box_sizing_json(pseudo_element_node.ptr());
  322. return { true, computed_values, resolved_values, custom_properties_json, node_box_sizing_json };
  323. }
  324. DeprecatedString computed_values = serialize_json(*element.computed_css_values());
  325. DeprecatedString resolved_values_json = serialize_json(element.resolved_css_values());
  326. DeprecatedString custom_properties_json = serialize_custom_properties_json(element);
  327. DeprecatedString node_box_sizing_json = serialize_node_box_sizing_json(element.layout_node());
  328. return { true, computed_values, resolved_values_json, custom_properties_json, node_box_sizing_json };
  329. }
  330. return { false, "", "", "", "" };
  331. }
  332. Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_hovered_node_id()
  333. {
  334. if (auto* document = page().top_level_browsing_context().active_document()) {
  335. auto hovered_node = document->hovered_node();
  336. if (hovered_node)
  337. return hovered_node->id();
  338. }
  339. return (i32)0;
  340. }
  341. void ConnectionFromClient::initialize_js_console(Badge<PageHost>)
  342. {
  343. auto* document = page().top_level_browsing_context().active_document();
  344. auto realm = document->realm().make_weak_ptr();
  345. if (m_realm.ptr() == realm.ptr())
  346. return;
  347. auto& console_object = *realm->intrinsics().console_object();
  348. m_realm = realm;
  349. m_console_client = make<WebContentConsoleClient>(console_object.console(), *m_realm, *this);
  350. console_object.console().set_client(*m_console_client.ptr());
  351. }
  352. void ConnectionFromClient::js_console_input(DeprecatedString const& js_source)
  353. {
  354. if (m_console_client)
  355. m_console_client->handle_input(js_source);
  356. }
  357. void ConnectionFromClient::run_javascript(DeprecatedString const& js_source)
  358. {
  359. auto* active_document = page().top_level_browsing_context().active_document();
  360. if (!active_document)
  361. return;
  362. // This is partially based on "execute a javascript: URL request" https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
  363. // Let settings be browsingContext's active document's relevant settings object.
  364. auto& settings = active_document->relevant_settings_object();
  365. // Let baseURL be settings's API base URL.
  366. auto base_url = settings.api_base_url();
  367. // Let script be the result of creating a classic script given scriptSource, settings, baseURL, and the default classic script fetch options.
  368. // FIXME: This doesn't pass in "default classic script fetch options"
  369. // FIXME: What should the filename be here?
  370. auto script = Web::HTML::ClassicScript::create("(client connection run_javascript)", js_source, settings, move(base_url));
  371. // Let evaluationStatus be the result of running the classic script script.
  372. auto evaluation_status = script->run();
  373. if (evaluation_status.is_error())
  374. dbgln("Exception :(");
  375. }
  376. void ConnectionFromClient::js_console_request_messages(i32 start_index)
  377. {
  378. if (m_console_client)
  379. m_console_client->send_messages(start_index);
  380. }
  381. Messages::WebContentServer::TakeDocumentScreenshotResponse ConnectionFromClient::take_document_screenshot()
  382. {
  383. auto* document = page().top_level_browsing_context().active_document();
  384. if (!document || !document->document_element())
  385. return { {} };
  386. auto const& content_size = m_page_host->content_size();
  387. Web::DevicePixelRect rect { { 0, 0 }, content_size };
  388. auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
  389. m_page_host->paint(rect, *bitmap);
  390. return { bitmap->to_shareable_bitmap() };
  391. }
  392. Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
  393. {
  394. return page().focused_context().selected_text();
  395. }
  396. void ConnectionFromClient::select_all()
  397. {
  398. page().focused_context().select_all();
  399. page().client().page_did_change_selection();
  400. }
  401. Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_layout_tree()
  402. {
  403. auto* document = page().top_level_browsing_context().active_document();
  404. if (!document)
  405. return DeprecatedString { "(no DOM tree)" };
  406. auto* layout_root = document->layout_node();
  407. if (!layout_root)
  408. return DeprecatedString { "(no layout tree)" };
  409. StringBuilder builder;
  410. Web::dump_tree(builder, *layout_root);
  411. return builder.to_deprecated_string();
  412. }
  413. void ConnectionFromClient::set_content_filters(Vector<DeprecatedString> const& filters)
  414. {
  415. for (auto& filter : filters)
  416. Web::ContentFilter::the().add_pattern(filter);
  417. }
  418. void ConnectionFromClient::set_proxy_mappings(Vector<DeprecatedString> const& proxies, HashMap<DeprecatedString, size_t> const& mappings)
  419. {
  420. auto keys = mappings.keys();
  421. quick_sort(keys, [&](auto& a, auto& b) { return a.length() < b.length(); });
  422. OrderedHashMap<DeprecatedString, size_t> sorted_mappings;
  423. for (auto& key : keys) {
  424. auto value = *mappings.get(key);
  425. if (value >= proxies.size())
  426. continue;
  427. sorted_mappings.set(key, value);
  428. }
  429. Web::ProxyMappings::the().set_mappings(proxies, move(sorted_mappings));
  430. }
  431. void ConnectionFromClient::set_preferred_color_scheme(Web::CSS::PreferredColorScheme const& color_scheme)
  432. {
  433. m_page_host->set_preferred_color_scheme(color_scheme);
  434. }
  435. void ConnectionFromClient::set_has_focus(bool has_focus)
  436. {
  437. m_page_host->set_has_focus(has_focus);
  438. }
  439. void ConnectionFromClient::set_is_scripting_enabled(bool is_scripting_enabled)
  440. {
  441. m_page_host->set_is_scripting_enabled(is_scripting_enabled);
  442. }
  443. void ConnectionFromClient::set_window_position(Gfx::IntPoint position)
  444. {
  445. m_page_host->set_window_position(position.to_type<Web::DevicePixels>());
  446. }
  447. void ConnectionFromClient::set_window_size(Gfx::IntSize size)
  448. {
  449. m_page_host->set_window_size(size.to_type<Web::DevicePixels>());
  450. }
  451. Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient::get_local_storage_entries()
  452. {
  453. auto* document = page().top_level_browsing_context().active_document();
  454. auto local_storage = document->window().local_storage();
  455. return local_storage->map();
  456. }
  457. Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClient::get_session_storage_entries()
  458. {
  459. auto* document = page().top_level_browsing_context().active_document();
  460. auto session_storage = document->window().session_storage();
  461. return session_storage->map();
  462. }
  463. void ConnectionFromClient::handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id)
  464. {
  465. auto result = m_requested_files.get(request_id);
  466. VERIFY(result.has_value());
  467. VERIFY(result.value()->on_file_request_finish);
  468. result.value()->on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() });
  469. m_requested_files.remove(request_id);
  470. }
  471. void ConnectionFromClient::request_file(NonnullRefPtr<Web::FileRequest>& file_request)
  472. {
  473. i32 const id = last_id++;
  474. m_requested_files.set(id, file_request);
  475. async_did_request_file(file_request->path(), id);
  476. }
  477. void ConnectionFromClient::set_system_visibility_state(bool visible)
  478. {
  479. m_page_host->page().top_level_browsing_context().set_system_visibility_state(
  480. visible
  481. ? Web::HTML::VisibilityState::Visible
  482. : Web::HTML::VisibilityState::Hidden);
  483. }
  484. void ConnectionFromClient::alert_closed()
  485. {
  486. m_page_host->alert_closed();
  487. }
  488. void ConnectionFromClient::confirm_closed(bool accepted)
  489. {
  490. m_page_host->confirm_closed(accepted);
  491. }
  492. void ConnectionFromClient::prompt_closed(DeprecatedString const& response)
  493. {
  494. m_page_host->prompt_closed(response);
  495. }
  496. void ConnectionFromClient::inspect_accessibility_tree()
  497. {
  498. if (auto* doc = page().top_level_browsing_context().active_document()) {
  499. async_did_get_accessibility_tree(doc->dump_accessibility_tree_as_json());
  500. }
  501. }
  502. }