ConnectionFromClient.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, 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. *
  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. if (auto result = Web::dump_sheet(sheet); result.is_error())
  191. dbgln("Failed to dump style sheets: {}", result.error());
  192. }
  193. }
  194. }
  195. if (request == "collect-garbage") {
  196. Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
  197. }
  198. if (request == "set-line-box-borders") {
  199. bool state = argument == "on";
  200. m_page_host->set_should_show_line_box_borders(state);
  201. page().top_level_browsing_context().set_needs_display(page().top_level_browsing_context().viewport_rect());
  202. }
  203. if (request == "clear-cache") {
  204. Web::ResourceLoader::the().clear_cache();
  205. }
  206. if (request == "spoof-user-agent") {
  207. Web::ResourceLoader::the().set_user_agent(argument);
  208. }
  209. if (request == "same-origin-policy") {
  210. m_page_host->page().set_same_origin_policy_enabled(argument == "on");
  211. }
  212. if (request == "scripting") {
  213. m_page_host->page().set_is_scripting_enabled(argument == "on");
  214. }
  215. if (request == "block-pop-ups") {
  216. m_page_host->page().set_should_block_pop_ups(argument == "on");
  217. }
  218. if (request == "dump-local-storage") {
  219. if (auto* doc = page().top_level_browsing_context().active_document())
  220. doc->window().local_storage()->dump();
  221. }
  222. }
  223. void ConnectionFromClient::get_source()
  224. {
  225. if (auto* doc = page().top_level_browsing_context().active_document()) {
  226. async_did_get_source(doc->url(), doc->source());
  227. }
  228. }
  229. void ConnectionFromClient::inspect_dom_tree()
  230. {
  231. if (auto* doc = page().top_level_browsing_context().active_document()) {
  232. async_did_get_dom_tree(doc->dump_dom_tree_as_json());
  233. }
  234. }
  235. Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element)
  236. {
  237. auto& top_context = page().top_level_browsing_context();
  238. top_context.for_each_in_inclusive_subtree([&](auto& ctx) {
  239. if (ctx.active_document() != nullptr) {
  240. ctx.active_document()->set_inspected_node(nullptr);
  241. }
  242. return IterationDecision::Continue;
  243. });
  244. Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
  245. // Note: Nodes without layout (aka non-visible nodes, don't have style computed)
  246. if (!node || !node->layout_node()) {
  247. return { false, "", "", "", "" };
  248. }
  249. // FIXME: Pass the pseudo-element here.
  250. node->document().set_inspected_node(node);
  251. if (node->is_element()) {
  252. auto& element = verify_cast<Web::DOM::Element>(*node);
  253. if (!element.computed_css_values())
  254. return { false, "", "", "", "" };
  255. auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> DeprecatedString {
  256. StringBuilder builder;
  257. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  258. properties.for_each_property([&](auto property_id, auto& value) {
  259. MUST(serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string()));
  260. });
  261. MUST(serializer.finish());
  262. return builder.to_deprecated_string();
  263. };
  264. auto serialize_custom_properties_json = [](Web::DOM::Element const& element) -> DeprecatedString {
  265. StringBuilder builder;
  266. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  267. HashTable<DeprecatedString> seen_properties;
  268. auto const* element_to_check = &element;
  269. while (element_to_check) {
  270. for (auto const& property : element_to_check->custom_properties()) {
  271. if (!seen_properties.contains(property.key)) {
  272. seen_properties.set(property.key);
  273. MUST(serializer.add(property.key, property.value.value->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string()));
  274. }
  275. }
  276. element_to_check = element_to_check->parent_element();
  277. }
  278. MUST(serializer.finish());
  279. return builder.to_deprecated_string();
  280. };
  281. auto serialize_node_box_sizing_json = [](Web::Layout::Node const* layout_node) -> DeprecatedString {
  282. if (!layout_node || !layout_node->is_box()) {
  283. return "{}";
  284. }
  285. auto* box = static_cast<Web::Layout::Box const*>(layout_node);
  286. auto box_model = box->box_model();
  287. StringBuilder builder;
  288. auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
  289. MUST(serializer.add("padding_top"sv, box_model.padding.top.value()));
  290. MUST(serializer.add("padding_right"sv, box_model.padding.right.value()));
  291. MUST(serializer.add("padding_bottom"sv, box_model.padding.bottom.value()));
  292. MUST(serializer.add("padding_left"sv, box_model.padding.left.value()));
  293. MUST(serializer.add("margin_top"sv, box_model.margin.top.value()));
  294. MUST(serializer.add("margin_right"sv, box_model.margin.right.value()));
  295. MUST(serializer.add("margin_bottom"sv, box_model.margin.bottom.value()));
  296. MUST(serializer.add("margin_left"sv, box_model.margin.left.value()));
  297. MUST(serializer.add("border_top"sv, box_model.border.top.value()));
  298. MUST(serializer.add("border_right"sv, box_model.border.right.value()));
  299. MUST(serializer.add("border_bottom"sv, box_model.border.bottom.value()));
  300. MUST(serializer.add("border_left"sv, box_model.border.left.value()));
  301. if (auto* paint_box = box->paint_box()) {
  302. MUST(serializer.add("content_width"sv, paint_box->content_width().value()));
  303. MUST(serializer.add("content_height"sv, paint_box->content_height().value()));
  304. } else {
  305. MUST(serializer.add("content_width"sv, 0));
  306. MUST(serializer.add("content_height"sv, 0));
  307. }
  308. MUST(serializer.finish());
  309. return builder.to_deprecated_string();
  310. };
  311. if (pseudo_element.has_value()) {
  312. auto pseudo_element_node = element.get_pseudo_element_node(pseudo_element.value());
  313. if (!pseudo_element_node)
  314. return { false, "", "", "", "" };
  315. // FIXME: Pseudo-elements only exist as Layout::Nodes, which don't have style information
  316. // in a format we can use. So, we run the StyleComputer again to get the specified
  317. // values, and have to ignore the computed values and custom properties.
  318. auto pseudo_element_style = MUST(page().focused_context().active_document()->style_computer().compute_style(element, pseudo_element));
  319. DeprecatedString computed_values = serialize_json(pseudo_element_style);
  320. DeprecatedString resolved_values = "{}";
  321. DeprecatedString custom_properties_json = "{}";
  322. DeprecatedString node_box_sizing_json = serialize_node_box_sizing_json(pseudo_element_node.ptr());
  323. return { true, computed_values, resolved_values, custom_properties_json, node_box_sizing_json };
  324. }
  325. DeprecatedString computed_values = serialize_json(*element.computed_css_values());
  326. DeprecatedString resolved_values_json = serialize_json(element.resolved_css_values());
  327. DeprecatedString custom_properties_json = serialize_custom_properties_json(element);
  328. DeprecatedString node_box_sizing_json = serialize_node_box_sizing_json(element.layout_node());
  329. return { true, computed_values, resolved_values_json, custom_properties_json, node_box_sizing_json };
  330. }
  331. return { false, "", "", "", "" };
  332. }
  333. Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_hovered_node_id()
  334. {
  335. if (auto* document = page().top_level_browsing_context().active_document()) {
  336. auto hovered_node = document->hovered_node();
  337. if (hovered_node)
  338. return hovered_node->id();
  339. }
  340. return (i32)0;
  341. }
  342. void ConnectionFromClient::initialize_js_console(Badge<PageHost>)
  343. {
  344. auto* document = page().top_level_browsing_context().active_document();
  345. auto realm = document->realm().make_weak_ptr();
  346. if (m_realm.ptr() == realm.ptr())
  347. return;
  348. auto& console_object = *realm->intrinsics().console_object();
  349. m_realm = realm;
  350. m_console_client = make<WebContentConsoleClient>(console_object.console(), *m_realm, *this);
  351. console_object.console().set_client(*m_console_client.ptr());
  352. }
  353. void ConnectionFromClient::js_console_input(DeprecatedString const& js_source)
  354. {
  355. if (m_console_client)
  356. m_console_client->handle_input(js_source);
  357. }
  358. void ConnectionFromClient::run_javascript(DeprecatedString const& js_source)
  359. {
  360. auto* active_document = page().top_level_browsing_context().active_document();
  361. if (!active_document)
  362. return;
  363. // This is partially based on "execute a javascript: URL request" https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
  364. // Let settings be browsingContext's active document's relevant settings object.
  365. auto& settings = active_document->relevant_settings_object();
  366. // Let baseURL be settings's API base URL.
  367. auto base_url = settings.api_base_url();
  368. // Let script be the result of creating a classic script given scriptSource, settings, baseURL, and the default classic script fetch options.
  369. // FIXME: This doesn't pass in "default classic script fetch options"
  370. // FIXME: What should the filename be here?
  371. auto script = Web::HTML::ClassicScript::create("(client connection run_javascript)", js_source, settings, move(base_url));
  372. // Let evaluationStatus be the result of running the classic script script.
  373. auto evaluation_status = script->run();
  374. if (evaluation_status.is_error())
  375. dbgln("Exception :(");
  376. }
  377. void ConnectionFromClient::js_console_request_messages(i32 start_index)
  378. {
  379. if (m_console_client)
  380. m_console_client->send_messages(start_index);
  381. }
  382. Messages::WebContentServer::TakeDocumentScreenshotResponse ConnectionFromClient::take_document_screenshot()
  383. {
  384. auto* document = page().top_level_browsing_context().active_document();
  385. if (!document || !document->document_element())
  386. return { {} };
  387. auto const& content_size = m_page_host->content_size();
  388. Web::DevicePixelRect rect { { 0, 0 }, content_size };
  389. auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, rect.size().to_type<int>()).release_value_but_fixme_should_propagate_errors();
  390. m_page_host->paint(rect, *bitmap);
  391. return { bitmap->to_shareable_bitmap() };
  392. }
  393. Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
  394. {
  395. return page().focused_context().selected_text();
  396. }
  397. void ConnectionFromClient::select_all()
  398. {
  399. page().focused_context().select_all();
  400. page().client().page_did_change_selection();
  401. }
  402. Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_layout_tree()
  403. {
  404. auto* document = page().top_level_browsing_context().active_document();
  405. if (!document)
  406. return DeprecatedString { "(no DOM tree)" };
  407. auto* layout_root = document->layout_node();
  408. if (!layout_root)
  409. return DeprecatedString { "(no layout tree)" };
  410. StringBuilder builder;
  411. Web::dump_tree(builder, *layout_root);
  412. return builder.to_deprecated_string();
  413. }
  414. void ConnectionFromClient::set_content_filters(Vector<DeprecatedString> const& filters)
  415. {
  416. for (auto& filter : filters)
  417. Web::ContentFilter::the().add_pattern(filter);
  418. }
  419. void ConnectionFromClient::set_proxy_mappings(Vector<DeprecatedString> const& proxies, HashMap<DeprecatedString, size_t> const& mappings)
  420. {
  421. auto keys = mappings.keys();
  422. quick_sort(keys, [&](auto& a, auto& b) { return a.length() < b.length(); });
  423. OrderedHashMap<DeprecatedString, size_t> sorted_mappings;
  424. for (auto& key : keys) {
  425. auto value = *mappings.get(key);
  426. if (value >= proxies.size())
  427. continue;
  428. sorted_mappings.set(key, value);
  429. }
  430. Web::ProxyMappings::the().set_mappings(proxies, move(sorted_mappings));
  431. }
  432. void ConnectionFromClient::set_preferred_color_scheme(Web::CSS::PreferredColorScheme const& color_scheme)
  433. {
  434. m_page_host->set_preferred_color_scheme(color_scheme);
  435. }
  436. void ConnectionFromClient::set_has_focus(bool has_focus)
  437. {
  438. m_page_host->set_has_focus(has_focus);
  439. }
  440. void ConnectionFromClient::set_is_scripting_enabled(bool is_scripting_enabled)
  441. {
  442. m_page_host->set_is_scripting_enabled(is_scripting_enabled);
  443. }
  444. void ConnectionFromClient::set_device_pixels_per_css_pixel(float device_pixels_per_css_pixel)
  445. {
  446. m_page_host->set_device_pixels_per_css_pixel(device_pixels_per_css_pixel);
  447. }
  448. void ConnectionFromClient::set_window_position(Gfx::IntPoint position)
  449. {
  450. m_page_host->set_window_position(position.to_type<Web::DevicePixels>());
  451. }
  452. void ConnectionFromClient::set_window_size(Gfx::IntSize size)
  453. {
  454. m_page_host->set_window_size(size.to_type<Web::DevicePixels>());
  455. }
  456. Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient::get_local_storage_entries()
  457. {
  458. auto* document = page().top_level_browsing_context().active_document();
  459. auto local_storage = document->window().local_storage();
  460. return local_storage->map();
  461. }
  462. Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClient::get_session_storage_entries()
  463. {
  464. auto* document = page().top_level_browsing_context().active_document();
  465. auto session_storage = document->window().session_storage();
  466. return session_storage->map();
  467. }
  468. void ConnectionFromClient::handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id)
  469. {
  470. auto file_request = m_requested_files.get(request_id);
  471. VERIFY(file_request.has_value());
  472. VERIFY(file_request.value().on_file_request_finish);
  473. file_request.value().on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() });
  474. m_requested_files.remove(request_id);
  475. }
  476. void ConnectionFromClient::request_file(Web::FileRequest file_request)
  477. {
  478. i32 const id = last_id++;
  479. auto path = file_request.path();
  480. m_requested_files.set(id, move(file_request));
  481. async_did_request_file(path, id);
  482. }
  483. void ConnectionFromClient::set_system_visibility_state(bool visible)
  484. {
  485. m_page_host->page().top_level_browsing_context().set_system_visibility_state(
  486. visible
  487. ? Web::HTML::VisibilityState::Visible
  488. : Web::HTML::VisibilityState::Hidden);
  489. }
  490. void ConnectionFromClient::alert_closed()
  491. {
  492. m_page_host->alert_closed();
  493. }
  494. void ConnectionFromClient::confirm_closed(bool accepted)
  495. {
  496. m_page_host->confirm_closed(accepted);
  497. }
  498. void ConnectionFromClient::prompt_closed(DeprecatedString const& response)
  499. {
  500. m_page_host->prompt_closed(response);
  501. }
  502. void ConnectionFromClient::inspect_accessibility_tree()
  503. {
  504. if (auto* doc = page().top_level_browsing_context().active_document()) {
  505. async_did_get_accessibility_tree(doc->dump_accessibility_tree_as_json());
  506. }
  507. }
  508. }