ConnectionFromClient.cpp 22 KB

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