WebContentClient.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "WebContentClient.h"
  7. #include "Application.h"
  8. #include "ViewImplementation.h"
  9. #include <LibWeb/Cookie/ParsedCookie.h>
  10. namespace WebView {
  11. HashTable<WebContentClient*> WebContentClient::s_clients;
  12. Optional<ViewImplementation&> WebContentClient::view_for_pid_and_page_id(pid_t pid, u64 page_id)
  13. {
  14. for (auto* client : s_clients) {
  15. if (client->m_process_handle.pid == pid)
  16. return client->view_for_page_id(page_id);
  17. }
  18. return {};
  19. }
  20. WebContentClient::WebContentClient(NonnullOwnPtr<Core::LocalSocket> socket, ViewImplementation& view)
  21. : IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket))
  22. {
  23. s_clients.set(this);
  24. m_views.set(0, &view);
  25. }
  26. WebContentClient::~WebContentClient()
  27. {
  28. s_clients.remove(this);
  29. }
  30. void WebContentClient::die()
  31. {
  32. // Intentionally empty. Restart is handled at another level.
  33. }
  34. void WebContentClient::register_view(u64 page_id, ViewImplementation& view)
  35. {
  36. VERIFY(page_id > 0);
  37. m_views.set(page_id, &view);
  38. }
  39. void WebContentClient::unregister_view(u64 page_id)
  40. {
  41. m_views.remove(page_id);
  42. if (m_views.is_empty()) {
  43. on_web_content_process_crash = nullptr;
  44. async_close_server();
  45. }
  46. }
  47. void WebContentClient::did_paint(u64 page_id, Gfx::IntRect const& rect, i32 bitmap_id)
  48. {
  49. if (auto view = view_for_page_id(page_id); view.has_value())
  50. view->server_did_paint({}, bitmap_id, rect.size());
  51. }
  52. void WebContentClient::did_start_loading(u64 page_id, URL::URL const& url, bool is_redirect)
  53. {
  54. if (auto process = WebView::Application::the().find_process(m_process_handle.pid); process.has_value())
  55. process->set_title(OptionalNone {});
  56. if (auto view = view_for_page_id(page_id); view.has_value()) {
  57. view->set_url({}, url);
  58. if (view->on_load_start)
  59. view->on_load_start(url, is_redirect);
  60. }
  61. }
  62. void WebContentClient::did_finish_loading(u64 page_id, URL::URL const& url)
  63. {
  64. if (auto view = view_for_page_id(page_id); view.has_value()) {
  65. view->set_url({}, url);
  66. if (view->on_load_finish)
  67. view->on_load_finish(url);
  68. }
  69. }
  70. void WebContentClient::did_finish_text_test(u64 page_id)
  71. {
  72. if (auto view = view_for_page_id(page_id); view.has_value()) {
  73. if (view->on_text_test_finish)
  74. view->on_text_test_finish();
  75. }
  76. }
  77. void WebContentClient::did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> const& total_match_count)
  78. {
  79. if (auto view = view_for_page_id(page_id); view.has_value()) {
  80. if (view->on_find_in_page)
  81. view->on_find_in_page(current_match_index, total_match_count);
  82. }
  83. }
  84. void WebContentClient::did_request_navigate_back(u64 page_id)
  85. {
  86. if (auto view = view_for_page_id(page_id); view.has_value()) {
  87. if (view->on_navigate_back)
  88. view->on_navigate_back();
  89. }
  90. }
  91. void WebContentClient::did_request_navigate_forward(u64 page_id)
  92. {
  93. if (auto view = view_for_page_id(page_id); view.has_value()) {
  94. if (view->on_navigate_forward)
  95. view->on_navigate_forward();
  96. }
  97. }
  98. void WebContentClient::did_request_refresh(u64 page_id)
  99. {
  100. if (auto view = view_for_page_id(page_id); view.has_value()) {
  101. if (view->on_refresh)
  102. view->on_refresh();
  103. }
  104. }
  105. void WebContentClient::did_request_cursor_change(u64 page_id, i32 cursor_type)
  106. {
  107. if (cursor_type < 0 || cursor_type >= (i32)Gfx::StandardCursor::__Count) {
  108. dbgln("DidRequestCursorChange: Bad cursor type");
  109. return;
  110. }
  111. if (auto view = view_for_page_id(page_id); view.has_value()) {
  112. if (view->on_cursor_change)
  113. view->on_cursor_change(static_cast<Gfx::StandardCursor>(cursor_type));
  114. }
  115. }
  116. void WebContentClient::did_layout(u64 page_id, Gfx::IntSize content_size)
  117. {
  118. if (auto view = view_for_page_id(page_id); view.has_value()) {
  119. if (view->on_did_layout)
  120. view->on_did_layout(content_size);
  121. }
  122. }
  123. void WebContentClient::did_change_title(u64 page_id, ByteString const& title)
  124. {
  125. if (auto process = WebView::Application::the().find_process(m_process_handle.pid); process.has_value())
  126. process->set_title(MUST(String::from_byte_string(title)));
  127. if (auto view = view_for_page_id(page_id); view.has_value()) {
  128. if (!view->on_title_change)
  129. return;
  130. if (title.is_empty())
  131. view->on_title_change(view->url().to_byte_string());
  132. else
  133. view->on_title_change(title);
  134. }
  135. }
  136. void WebContentClient::did_change_url(u64 page_id, URL::URL const& url)
  137. {
  138. if (auto view = view_for_page_id(page_id); view.has_value()) {
  139. view->set_url({}, url);
  140. if (view->on_url_change)
  141. view->on_url_change(url);
  142. }
  143. }
  144. void WebContentClient::did_request_tooltip_override(u64 page_id, Gfx::IntPoint position, ByteString const& title)
  145. {
  146. if (auto view = view_for_page_id(page_id); view.has_value()) {
  147. if (view->on_request_tooltip_override)
  148. view->on_request_tooltip_override(view->to_widget_position(position), title);
  149. }
  150. }
  151. void WebContentClient::did_stop_tooltip_override(u64 page_id)
  152. {
  153. if (auto view = view_for_page_id(page_id); view.has_value()) {
  154. if (view->on_stop_tooltip_override)
  155. view->on_stop_tooltip_override();
  156. }
  157. }
  158. void WebContentClient::did_enter_tooltip_area(u64 page_id, ByteString const& title)
  159. {
  160. if (auto view = view_for_page_id(page_id); view.has_value()) {
  161. if (view->on_enter_tooltip_area)
  162. view->on_enter_tooltip_area(title);
  163. }
  164. }
  165. void WebContentClient::did_leave_tooltip_area(u64 page_id)
  166. {
  167. if (auto view = view_for_page_id(page_id); view.has_value()) {
  168. if (view->on_leave_tooltip_area)
  169. view->on_leave_tooltip_area();
  170. }
  171. }
  172. void WebContentClient::did_hover_link(u64 page_id, URL::URL const& url)
  173. {
  174. if (auto view = view_for_page_id(page_id); view.has_value()) {
  175. if (view->on_link_hover)
  176. view->on_link_hover(url);
  177. }
  178. }
  179. void WebContentClient::did_unhover_link(u64 page_id)
  180. {
  181. if (auto view = view_for_page_id(page_id); view.has_value()) {
  182. if (view->on_link_unhover)
  183. view->on_link_unhover();
  184. }
  185. }
  186. void WebContentClient::did_click_link(u64 page_id, URL::URL const& url, ByteString const& target, unsigned modifiers)
  187. {
  188. if (auto view = view_for_page_id(page_id); view.has_value()) {
  189. if (view->on_link_click)
  190. view->on_link_click(url, target, modifiers);
  191. }
  192. }
  193. void WebContentClient::did_middle_click_link(u64 page_id, URL::URL const& url, ByteString const& target, unsigned modifiers)
  194. {
  195. if (auto view = view_for_page_id(page_id); view.has_value()) {
  196. if (view->on_link_middle_click)
  197. view->on_link_middle_click(url, target, modifiers);
  198. }
  199. }
  200. void WebContentClient::did_request_context_menu(u64 page_id, Gfx::IntPoint content_position)
  201. {
  202. if (auto view = view_for_page_id(page_id); view.has_value()) {
  203. if (view->on_context_menu_request)
  204. view->on_context_menu_request(view->to_widget_position(content_position));
  205. }
  206. }
  207. void WebContentClient::did_request_link_context_menu(u64 page_id, Gfx::IntPoint content_position, URL::URL const& url, ByteString const&, unsigned)
  208. {
  209. if (auto view = view_for_page_id(page_id); view.has_value()) {
  210. if (view->on_link_context_menu_request)
  211. view->on_link_context_menu_request(url, view->to_widget_position(content_position));
  212. }
  213. }
  214. void WebContentClient::did_request_image_context_menu(u64 page_id, Gfx::IntPoint content_position, URL::URL const& url, ByteString const&, unsigned, Gfx::ShareableBitmap const& bitmap)
  215. {
  216. if (auto view = view_for_page_id(page_id); view.has_value()) {
  217. if (view->on_image_context_menu_request)
  218. view->on_image_context_menu_request(url, view->to_widget_position(content_position), bitmap);
  219. }
  220. }
  221. void WebContentClient::did_request_media_context_menu(u64 page_id, Gfx::IntPoint content_position, ByteString const&, unsigned, Web::Page::MediaContextMenu const& menu)
  222. {
  223. if (auto view = view_for_page_id(page_id); view.has_value()) {
  224. if (view->on_media_context_menu_request)
  225. view->on_media_context_menu_request(view->to_widget_position(content_position), menu);
  226. }
  227. }
  228. void WebContentClient::did_get_source(u64 page_id, URL::URL const& url, ByteString const& source)
  229. {
  230. if (auto view = view_for_page_id(page_id); view.has_value()) {
  231. if (view->on_received_source)
  232. view->on_received_source(url, source);
  233. }
  234. }
  235. void WebContentClient::did_inspect_dom_tree(u64 page_id, ByteString const& dom_tree)
  236. {
  237. if (auto view = view_for_page_id(page_id); view.has_value()) {
  238. if (view->on_received_dom_tree)
  239. view->on_received_dom_tree(dom_tree);
  240. }
  241. }
  242. void WebContentClient::did_inspect_dom_node(u64 page_id, bool has_style, ByteString const& computed_style, ByteString const& resolved_style, ByteString const& custom_properties, ByteString const& node_box_sizing, ByteString const& aria_properties_state, ByteString const& fonts)
  243. {
  244. auto view = view_for_page_id(page_id);
  245. if (!view.has_value() || !view->on_received_dom_node_properties)
  246. return;
  247. Optional<ViewImplementation::DOMNodeProperties> properties;
  248. if (has_style) {
  249. properties = ViewImplementation::DOMNodeProperties {
  250. .computed_style_json = MUST(String::from_byte_string(computed_style)),
  251. .resolved_style_json = MUST(String::from_byte_string(resolved_style)),
  252. .custom_properties_json = MUST(String::from_byte_string(custom_properties)),
  253. .node_box_sizing_json = MUST(String::from_byte_string(node_box_sizing)),
  254. .aria_properties_state_json = MUST(String::from_byte_string(aria_properties_state)),
  255. .fonts_json = MUST(String::from_byte_string(fonts))
  256. };
  257. }
  258. view->on_received_dom_node_properties(move(properties));
  259. }
  260. void WebContentClient::did_inspect_accessibility_tree(u64 page_id, ByteString const& accessibility_tree)
  261. {
  262. if (auto view = view_for_page_id(page_id); view.has_value()) {
  263. if (view->on_received_accessibility_tree)
  264. view->on_received_accessibility_tree(accessibility_tree);
  265. }
  266. }
  267. void WebContentClient::did_get_hovered_node_id(u64 page_id, i32 node_id)
  268. {
  269. if (auto view = view_for_page_id(page_id); view.has_value()) {
  270. if (view->on_received_hovered_node_id)
  271. view->on_received_hovered_node_id(node_id);
  272. }
  273. }
  274. void WebContentClient::did_finish_editing_dom_node(u64 page_id, Optional<i32> const& node_id)
  275. {
  276. if (auto view = view_for_page_id(page_id); view.has_value()) {
  277. if (view->on_finshed_editing_dom_node)
  278. view->on_finshed_editing_dom_node(node_id);
  279. }
  280. }
  281. void WebContentClient::did_get_dom_node_html(u64 page_id, String const& html)
  282. {
  283. if (auto view = view_for_page_id(page_id); view.has_value()) {
  284. if (view->on_received_dom_node_html)
  285. view->on_received_dom_node_html(html);
  286. }
  287. }
  288. void WebContentClient::did_take_screenshot(u64 page_id, Gfx::ShareableBitmap const& screenshot)
  289. {
  290. if (auto view = view_for_page_id(page_id); view.has_value())
  291. view->did_receive_screenshot({}, screenshot);
  292. }
  293. void WebContentClient::did_output_js_console_message(u64 page_id, i32 message_index)
  294. {
  295. if (auto view = view_for_page_id(page_id); view.has_value()) {
  296. if (view->on_received_console_message)
  297. view->on_received_console_message(message_index);
  298. }
  299. }
  300. void WebContentClient::did_get_js_console_messages(u64 page_id, i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages)
  301. {
  302. if (auto view = view_for_page_id(page_id); view.has_value()) {
  303. if (view->on_received_console_messages)
  304. view->on_received_console_messages(start_index, message_types, messages);
  305. }
  306. }
  307. void WebContentClient::did_request_alert(u64 page_id, String const& message)
  308. {
  309. if (auto view = view_for_page_id(page_id); view.has_value()) {
  310. if (view->on_request_alert)
  311. view->on_request_alert(message);
  312. }
  313. }
  314. void WebContentClient::did_request_confirm(u64 page_id, String const& message)
  315. {
  316. if (auto view = view_for_page_id(page_id); view.has_value()) {
  317. if (view->on_request_confirm)
  318. view->on_request_confirm(message);
  319. }
  320. }
  321. void WebContentClient::did_request_prompt(u64 page_id, String const& message, String const& default_)
  322. {
  323. if (auto view = view_for_page_id(page_id); view.has_value()) {
  324. if (view->on_request_prompt)
  325. view->on_request_prompt(message, default_);
  326. }
  327. }
  328. void WebContentClient::did_request_set_prompt_text(u64 page_id, String const& message)
  329. {
  330. if (auto view = view_for_page_id(page_id); view.has_value()) {
  331. if (view->on_request_set_prompt_text)
  332. view->on_request_set_prompt_text(message);
  333. }
  334. }
  335. void WebContentClient::did_request_accept_dialog(u64 page_id)
  336. {
  337. if (auto view = view_for_page_id(page_id); view.has_value()) {
  338. if (view->on_request_accept_dialog)
  339. view->on_request_accept_dialog();
  340. }
  341. }
  342. void WebContentClient::did_request_dismiss_dialog(u64 page_id)
  343. {
  344. if (auto view = view_for_page_id(page_id); view.has_value()) {
  345. if (view->on_request_dismiss_dialog)
  346. view->on_request_dismiss_dialog();
  347. }
  348. }
  349. void WebContentClient::did_change_favicon(u64 page_id, Gfx::ShareableBitmap const& favicon)
  350. {
  351. if (!favicon.is_valid()) {
  352. dbgln("DidChangeFavicon: Received invalid favicon");
  353. return;
  354. }
  355. if (auto view = view_for_page_id(page_id); view.has_value()) {
  356. if (view->on_favicon_change)
  357. view->on_favicon_change(*favicon.bitmap());
  358. }
  359. }
  360. Messages::WebContentClient::DidRequestAllCookiesResponse WebContentClient::did_request_all_cookies(u64 page_id, URL::URL const& url)
  361. {
  362. if (auto view = view_for_page_id(page_id); view.has_value()) {
  363. if (view->on_get_all_cookies)
  364. return view->on_get_all_cookies(url);
  365. }
  366. return Vector<Web::Cookie::Cookie> {};
  367. }
  368. Messages::WebContentClient::DidRequestNamedCookieResponse WebContentClient::did_request_named_cookie(u64 page_id, URL::URL const& url, String const& name)
  369. {
  370. if (auto view = view_for_page_id(page_id); view.has_value()) {
  371. if (view->on_get_named_cookie)
  372. return view->on_get_named_cookie(url, name);
  373. }
  374. return OptionalNone {};
  375. }
  376. Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(u64 page_id, URL::URL const& url, Web::Cookie::Source source)
  377. {
  378. if (auto view = view_for_page_id(page_id); view.has_value()) {
  379. if (view->on_get_cookie)
  380. return view->on_get_cookie(url, source);
  381. }
  382. return String {};
  383. }
  384. void WebContentClient::did_set_cookie(u64 page_id, URL::URL const& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)
  385. {
  386. if (auto view = view_for_page_id(page_id); view.has_value()) {
  387. if (view->on_set_cookie)
  388. view->on_set_cookie(url, cookie, source);
  389. }
  390. }
  391. void WebContentClient::did_update_cookie(u64 page_id, Web::Cookie::Cookie const& cookie)
  392. {
  393. if (auto view = view_for_page_id(page_id); view.has_value()) {
  394. if (view->on_update_cookie)
  395. view->on_update_cookie(cookie);
  396. }
  397. }
  398. Messages::WebContentClient::DidRequestNewWebViewResponse WebContentClient::did_request_new_web_view(u64 page_id, Web::HTML::ActivateTab const& activate_tab, Web::HTML::WebViewHints const& hints, Optional<u64> const& page_index)
  399. {
  400. if (auto view = view_for_page_id(page_id); view.has_value()) {
  401. if (view->on_new_web_view)
  402. return view->on_new_web_view(activate_tab, hints, page_index);
  403. }
  404. return String {};
  405. }
  406. void WebContentClient::did_request_activate_tab(u64 page_id)
  407. {
  408. if (auto view = view_for_page_id(page_id); view.has_value()) {
  409. if (view->on_activate_tab)
  410. view->on_activate_tab();
  411. }
  412. }
  413. void WebContentClient::did_close_browsing_context(u64 page_id)
  414. {
  415. if (auto view = view_for_page_id(page_id); view.has_value()) {
  416. if (view->on_close)
  417. view->on_close();
  418. }
  419. }
  420. void WebContentClient::did_update_resource_count(u64 page_id, i32 count_waiting)
  421. {
  422. if (auto view = view_for_page_id(page_id); view.has_value()) {
  423. if (view->on_resource_status_change)
  424. view->on_resource_status_change(count_waiting);
  425. }
  426. }
  427. void WebContentClient::did_request_restore_window(u64 page_id)
  428. {
  429. if (auto view = view_for_page_id(page_id); view.has_value()) {
  430. if (view->on_restore_window)
  431. view->on_restore_window();
  432. }
  433. }
  434. Messages::WebContentClient::DidRequestRepositionWindowResponse WebContentClient::did_request_reposition_window(u64 page_id, Gfx::IntPoint position)
  435. {
  436. if (auto view = view_for_page_id(page_id); view.has_value()) {
  437. if (view->on_reposition_window)
  438. return view->on_reposition_window(position);
  439. }
  440. return Gfx::IntPoint {};
  441. }
  442. Messages::WebContentClient::DidRequestResizeWindowResponse WebContentClient::did_request_resize_window(u64 page_id, Gfx::IntSize size)
  443. {
  444. if (auto view = view_for_page_id(page_id); view.has_value()) {
  445. if (view->on_resize_window)
  446. return view->on_resize_window(size);
  447. }
  448. return Gfx::IntSize {};
  449. }
  450. Messages::WebContentClient::DidRequestMaximizeWindowResponse WebContentClient::did_request_maximize_window(u64 page_id)
  451. {
  452. if (auto view = view_for_page_id(page_id); view.has_value()) {
  453. if (view->on_maximize_window)
  454. return view->on_maximize_window();
  455. }
  456. return Gfx::IntRect {};
  457. }
  458. Messages::WebContentClient::DidRequestMinimizeWindowResponse WebContentClient::did_request_minimize_window(u64 page_id)
  459. {
  460. if (auto view = view_for_page_id(page_id); view.has_value()) {
  461. if (view->on_minimize_window)
  462. return view->on_minimize_window();
  463. }
  464. return Gfx::IntRect {};
  465. }
  466. Messages::WebContentClient::DidRequestFullscreenWindowResponse WebContentClient::did_request_fullscreen_window(u64 page_id)
  467. {
  468. if (auto view = view_for_page_id(page_id); view.has_value()) {
  469. if (view->on_fullscreen_window)
  470. return view->on_fullscreen_window();
  471. }
  472. return Gfx::IntRect {};
  473. }
  474. void WebContentClient::did_request_file(u64 page_id, ByteString const& path, i32 request_id)
  475. {
  476. if (auto view = view_for_page_id(page_id); view.has_value()) {
  477. if (view->on_request_file)
  478. view->on_request_file(path, request_id);
  479. }
  480. }
  481. void WebContentClient::did_request_color_picker(u64 page_id, Color const& current_color)
  482. {
  483. if (auto view = view_for_page_id(page_id); view.has_value()) {
  484. if (view->on_request_color_picker)
  485. view->on_request_color_picker(current_color);
  486. }
  487. }
  488. void WebContentClient::did_request_file_picker(u64 page_id, Web::HTML::FileFilter const& accepted_file_types, Web::HTML::AllowMultipleFiles allow_multiple_files)
  489. {
  490. if (auto view = view_for_page_id(page_id); view.has_value()) {
  491. if (view->on_request_file_picker)
  492. view->on_request_file_picker(accepted_file_types, allow_multiple_files);
  493. }
  494. }
  495. void WebContentClient::did_request_select_dropdown(u64 page_id, Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> const& items)
  496. {
  497. if (auto view = view_for_page_id(page_id); view.has_value()) {
  498. if (view->on_request_select_dropdown)
  499. view->on_request_select_dropdown(content_position, minimum_width, items);
  500. }
  501. }
  502. void WebContentClient::did_finish_handling_input_event(u64 page_id, Web::EventResult event_result)
  503. {
  504. if (auto view = view_for_page_id(page_id); view.has_value())
  505. view->did_finish_handling_input_event({}, event_result);
  506. }
  507. void WebContentClient::did_change_theme_color(u64 page_id, Gfx::Color color)
  508. {
  509. if (auto view = view_for_page_id(page_id); view.has_value()) {
  510. if (view->on_theme_color_change)
  511. view->on_theme_color_change(color);
  512. }
  513. }
  514. void WebContentClient::did_insert_clipboard_entry(u64 page_id, String const& data, String const& presentation_style, String const& mime_type)
  515. {
  516. if (auto view = view_for_page_id(page_id); view.has_value()) {
  517. if (view->on_insert_clipboard_entry)
  518. view->on_insert_clipboard_entry(data, presentation_style, mime_type);
  519. }
  520. }
  521. void WebContentClient::did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState play_state)
  522. {
  523. if (auto view = view_for_page_id(page_id); view.has_value())
  524. view->did_change_audio_play_state({}, play_state);
  525. }
  526. void WebContentClient::did_update_navigation_buttons_state(u64 page_id, bool back_enabled, bool forward_enabled)
  527. {
  528. if (auto view = view_for_page_id(page_id); view.has_value())
  529. view->did_update_navigation_buttons_state({}, back_enabled, forward_enabled);
  530. }
  531. void WebContentClient::did_allocate_backing_stores(u64 page_id, i32 front_bitmap_id, Gfx::ShareableBitmap const& front_bitmap, i32 back_bitmap_id, Gfx::ShareableBitmap const& back_bitmap)
  532. {
  533. if (auto view = view_for_page_id(page_id); view.has_value())
  534. view->did_allocate_backing_stores({}, front_bitmap_id, front_bitmap, back_bitmap_id, back_bitmap);
  535. }
  536. void WebContentClient::inspector_did_load(u64 page_id)
  537. {
  538. if (auto view = view_for_page_id(page_id); view.has_value()) {
  539. if (view->on_inspector_loaded)
  540. view->on_inspector_loaded();
  541. }
  542. }
  543. void WebContentClient::inspector_did_select_dom_node(u64 page_id, i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element)
  544. {
  545. if (auto view = view_for_page_id(page_id); view.has_value()) {
  546. if (view->on_inspector_selected_dom_node)
  547. view->on_inspector_selected_dom_node(node_id, pseudo_element);
  548. }
  549. }
  550. void WebContentClient::inspector_did_set_dom_node_text(u64 page_id, i32 node_id, String const& text)
  551. {
  552. if (auto view = view_for_page_id(page_id); view.has_value()) {
  553. if (view->on_inspector_set_dom_node_text)
  554. view->on_inspector_set_dom_node_text(node_id, text);
  555. }
  556. }
  557. void WebContentClient::inspector_did_set_dom_node_tag(u64 page_id, i32 node_id, String const& tag)
  558. {
  559. if (auto view = view_for_page_id(page_id); view.has_value()) {
  560. if (view->on_inspector_set_dom_node_tag)
  561. view->on_inspector_set_dom_node_tag(node_id, tag);
  562. }
  563. }
  564. void WebContentClient::inspector_did_add_dom_node_attributes(u64 page_id, i32 node_id, Vector<Attribute> const& attributes)
  565. {
  566. if (auto view = view_for_page_id(page_id); view.has_value()) {
  567. if (view->on_inspector_added_dom_node_attributes)
  568. view->on_inspector_added_dom_node_attributes(node_id, attributes);
  569. }
  570. }
  571. void WebContentClient::inspector_did_replace_dom_node_attribute(u64 page_id, i32 node_id, size_t attribute_index, Vector<Attribute> const& replacement_attributes)
  572. {
  573. if (auto view = view_for_page_id(page_id); view.has_value()) {
  574. if (view->on_inspector_replaced_dom_node_attribute)
  575. view->on_inspector_replaced_dom_node_attribute(node_id, attribute_index, replacement_attributes);
  576. }
  577. }
  578. void WebContentClient::inspector_did_request_dom_tree_context_menu(u64 page_id, i32 node_id, Gfx::IntPoint position, String const& type, Optional<String> const& tag, Optional<size_t> const& attribute_index)
  579. {
  580. if (auto view = view_for_page_id(page_id); view.has_value()) {
  581. if (view->on_inspector_requested_dom_tree_context_menu)
  582. view->on_inspector_requested_dom_tree_context_menu(node_id, view->to_widget_position(position), type, tag, attribute_index);
  583. }
  584. }
  585. void WebContentClient::inspector_did_request_cookie_context_menu(u64 page_id, size_t cookie_index, Gfx::IntPoint position)
  586. {
  587. if (auto view = view_for_page_id(page_id); view.has_value()) {
  588. if (view->on_inspector_requested_cookie_context_menu)
  589. view->on_inspector_requested_cookie_context_menu(cookie_index, view->to_widget_position(position));
  590. }
  591. }
  592. void WebContentClient::inspector_did_execute_console_script(u64 page_id, String const& script)
  593. {
  594. if (auto view = view_for_page_id(page_id); view.has_value()) {
  595. if (view->on_inspector_executed_console_script)
  596. view->on_inspector_executed_console_script(script);
  597. }
  598. }
  599. void WebContentClient::inspector_did_export_inspector_html(u64 page_id, String const& html)
  600. {
  601. if (auto view = view_for_page_id(page_id); view.has_value()) {
  602. if (view->on_inspector_exported_inspector_html)
  603. view->on_inspector_exported_inspector_html(html);
  604. }
  605. }
  606. Messages::WebContentClient::RequestWorkerAgentResponse WebContentClient::request_worker_agent(u64 page_id)
  607. {
  608. if (auto view = view_for_page_id(page_id); view.has_value()) {
  609. if (view->on_request_worker_agent)
  610. return view->on_request_worker_agent();
  611. }
  612. return IPC::File {};
  613. }
  614. void WebContentClient::inspector_did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> const& stylesheets)
  615. {
  616. if (auto view = view_for_page_id(page_id); view.has_value()) {
  617. if (view->on_received_style_sheet_list)
  618. view->on_received_style_sheet_list(stylesheets);
  619. }
  620. }
  621. void WebContentClient::inspector_did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier const& identifier)
  622. {
  623. if (auto view = view_for_page_id(page_id); view.has_value()) {
  624. if (view->on_inspector_requested_style_sheet_source)
  625. view->on_inspector_requested_style_sheet_source(identifier);
  626. }
  627. }
  628. void WebContentClient::did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier const& identifier, String const& source)
  629. {
  630. if (auto view = view_for_page_id(page_id); view.has_value()) {
  631. if (view->on_received_style_sheet_source)
  632. view->on_received_style_sheet_source(identifier, source);
  633. }
  634. }
  635. Optional<ViewImplementation&> WebContentClient::view_for_page_id(u64 page_id, SourceLocation location)
  636. {
  637. if (auto view = m_views.get(page_id); view.has_value())
  638. return *view.value();
  639. dbgln("WebContentClient::{}: Did not find a page with ID {}", location.function_name(), page_id);
  640. return {};
  641. }
  642. }