WebContentClient.cpp 25 KB

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