WebContentClient.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. #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(NonnullOwnPtr<Core::LocalSocket> socket, ViewImplementation& view)
  22. : IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket))
  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)
  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();
  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, ByteString 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, 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, i32 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<i32> 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. 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)
  381. {
  382. if (auto view = view_for_page_id(page_id); view.has_value()) {
  383. if (view->on_new_web_view)
  384. return view->on_new_web_view(activate_tab, hints, page_index);
  385. }
  386. return String {};
  387. }
  388. void WebContentClient::did_request_activate_tab(u64 page_id)
  389. {
  390. if (auto view = view_for_page_id(page_id); view.has_value()) {
  391. if (view->on_activate_tab)
  392. view->on_activate_tab();
  393. }
  394. }
  395. void WebContentClient::did_close_browsing_context(u64 page_id)
  396. {
  397. if (auto view = view_for_page_id(page_id); view.has_value()) {
  398. if (view->on_close)
  399. view->on_close();
  400. }
  401. }
  402. void WebContentClient::did_update_resource_count(u64 page_id, i32 count_waiting)
  403. {
  404. if (auto view = view_for_page_id(page_id); view.has_value()) {
  405. if (view->on_resource_status_change)
  406. view->on_resource_status_change(count_waiting);
  407. }
  408. }
  409. void WebContentClient::did_request_restore_window(u64 page_id)
  410. {
  411. if (auto view = view_for_page_id(page_id); view.has_value()) {
  412. if (view->on_restore_window)
  413. view->on_restore_window();
  414. }
  415. }
  416. Messages::WebContentClient::DidRequestRepositionWindowResponse WebContentClient::did_request_reposition_window(u64 page_id, Gfx::IntPoint position)
  417. {
  418. if (auto view = view_for_page_id(page_id); view.has_value()) {
  419. if (view->on_reposition_window)
  420. return view->on_reposition_window(position);
  421. }
  422. return Gfx::IntPoint {};
  423. }
  424. Messages::WebContentClient::DidRequestResizeWindowResponse WebContentClient::did_request_resize_window(u64 page_id, Gfx::IntSize size)
  425. {
  426. if (auto view = view_for_page_id(page_id); view.has_value()) {
  427. if (view->on_resize_window)
  428. return view->on_resize_window(size);
  429. }
  430. return Gfx::IntSize {};
  431. }
  432. Messages::WebContentClient::DidRequestMaximizeWindowResponse WebContentClient::did_request_maximize_window(u64 page_id)
  433. {
  434. if (auto view = view_for_page_id(page_id); view.has_value()) {
  435. if (view->on_maximize_window)
  436. return view->on_maximize_window();
  437. }
  438. return Gfx::IntRect {};
  439. }
  440. Messages::WebContentClient::DidRequestMinimizeWindowResponse WebContentClient::did_request_minimize_window(u64 page_id)
  441. {
  442. if (auto view = view_for_page_id(page_id); view.has_value()) {
  443. if (view->on_minimize_window)
  444. return view->on_minimize_window();
  445. }
  446. return Gfx::IntRect {};
  447. }
  448. Messages::WebContentClient::DidRequestFullscreenWindowResponse 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. return view->on_fullscreen_window();
  453. }
  454. return Gfx::IntRect {};
  455. }
  456. void WebContentClient::did_request_file(u64 page_id, ByteString const& path, i32 request_id)
  457. {
  458. if (auto view = view_for_page_id(page_id); view.has_value()) {
  459. if (view->on_request_file)
  460. view->on_request_file(path, request_id);
  461. }
  462. }
  463. void WebContentClient::did_request_color_picker(u64 page_id, Color const& current_color)
  464. {
  465. if (auto view = view_for_page_id(page_id); view.has_value()) {
  466. if (view->on_request_color_picker)
  467. view->on_request_color_picker(current_color);
  468. }
  469. }
  470. void WebContentClient::did_request_file_picker(u64 page_id, Web::HTML::FileFilter const& accepted_file_types, Web::HTML::AllowMultipleFiles allow_multiple_files)
  471. {
  472. if (auto view = view_for_page_id(page_id); view.has_value()) {
  473. if (view->on_request_file_picker)
  474. view->on_request_file_picker(accepted_file_types, allow_multiple_files);
  475. }
  476. }
  477. void WebContentClient::did_request_select_dropdown(u64 page_id, Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> const& items)
  478. {
  479. if (auto view = view_for_page_id(page_id); view.has_value()) {
  480. if (view->on_request_select_dropdown)
  481. view->on_request_select_dropdown(content_position, minimum_width, items);
  482. }
  483. }
  484. void WebContentClient::did_finish_handling_input_event(u64 page_id, Web::EventResult event_result)
  485. {
  486. if (auto view = view_for_page_id(page_id); view.has_value())
  487. view->did_finish_handling_input_event({}, event_result);
  488. }
  489. void WebContentClient::did_change_theme_color(u64 page_id, Gfx::Color color)
  490. {
  491. if (auto view = view_for_page_id(page_id); view.has_value()) {
  492. if (view->on_theme_color_change)
  493. view->on_theme_color_change(color);
  494. }
  495. }
  496. void WebContentClient::did_insert_clipboard_entry(u64 page_id, String const& data, String const& presentation_style, String const& mime_type)
  497. {
  498. if (auto view = view_for_page_id(page_id); view.has_value()) {
  499. if (view->on_insert_clipboard_entry)
  500. view->on_insert_clipboard_entry(data, presentation_style, mime_type);
  501. }
  502. }
  503. void WebContentClient::did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState play_state)
  504. {
  505. if (auto view = view_for_page_id(page_id); view.has_value())
  506. view->did_change_audio_play_state({}, play_state);
  507. }
  508. void WebContentClient::did_update_navigation_buttons_state(u64 page_id, bool back_enabled, bool forward_enabled)
  509. {
  510. if (auto view = view_for_page_id(page_id); view.has_value())
  511. view->did_update_navigation_buttons_state({}, back_enabled, forward_enabled);
  512. }
  513. 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)
  514. {
  515. if (auto view = view_for_page_id(page_id); view.has_value())
  516. view->did_allocate_backing_stores({}, front_bitmap_id, front_bitmap, back_bitmap_id, back_bitmap);
  517. }
  518. void WebContentClient::inspector_did_load(u64 page_id)
  519. {
  520. if (auto view = view_for_page_id(page_id); view.has_value()) {
  521. if (view->on_inspector_loaded)
  522. view->on_inspector_loaded();
  523. }
  524. }
  525. void WebContentClient::inspector_did_select_dom_node(u64 page_id, i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element)
  526. {
  527. if (auto view = view_for_page_id(page_id); view.has_value()) {
  528. if (view->on_inspector_selected_dom_node)
  529. view->on_inspector_selected_dom_node(node_id, pseudo_element);
  530. }
  531. }
  532. void WebContentClient::inspector_did_set_dom_node_text(u64 page_id, i32 node_id, String const& text)
  533. {
  534. if (auto view = view_for_page_id(page_id); view.has_value()) {
  535. if (view->on_inspector_set_dom_node_text)
  536. view->on_inspector_set_dom_node_text(node_id, text);
  537. }
  538. }
  539. void WebContentClient::inspector_did_set_dom_node_tag(u64 page_id, i32 node_id, String const& tag)
  540. {
  541. if (auto view = view_for_page_id(page_id); view.has_value()) {
  542. if (view->on_inspector_set_dom_node_tag)
  543. view->on_inspector_set_dom_node_tag(node_id, tag);
  544. }
  545. }
  546. void WebContentClient::inspector_did_add_dom_node_attributes(u64 page_id, i32 node_id, Vector<Attribute> const& attributes)
  547. {
  548. if (auto view = view_for_page_id(page_id); view.has_value()) {
  549. if (view->on_inspector_added_dom_node_attributes)
  550. view->on_inspector_added_dom_node_attributes(node_id, attributes);
  551. }
  552. }
  553. void WebContentClient::inspector_did_replace_dom_node_attribute(u64 page_id, i32 node_id, size_t attribute_index, Vector<Attribute> const& replacement_attributes)
  554. {
  555. if (auto view = view_for_page_id(page_id); view.has_value()) {
  556. if (view->on_inspector_replaced_dom_node_attribute)
  557. view->on_inspector_replaced_dom_node_attribute(node_id, attribute_index, replacement_attributes);
  558. }
  559. }
  560. 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)
  561. {
  562. if (auto view = view_for_page_id(page_id); view.has_value()) {
  563. if (view->on_inspector_requested_dom_tree_context_menu)
  564. view->on_inspector_requested_dom_tree_context_menu(node_id, view->to_widget_position(position), type, tag, attribute_index);
  565. }
  566. }
  567. void WebContentClient::inspector_did_request_cookie_context_menu(u64 page_id, size_t cookie_index, Gfx::IntPoint position)
  568. {
  569. if (auto view = view_for_page_id(page_id); view.has_value()) {
  570. if (view->on_inspector_requested_cookie_context_menu)
  571. view->on_inspector_requested_cookie_context_menu(cookie_index, view->to_widget_position(position));
  572. }
  573. }
  574. void WebContentClient::inspector_did_execute_console_script(u64 page_id, String const& script)
  575. {
  576. if (auto view = view_for_page_id(page_id); view.has_value()) {
  577. if (view->on_inspector_executed_console_script)
  578. view->on_inspector_executed_console_script(script);
  579. }
  580. }
  581. void WebContentClient::inspector_did_export_inspector_html(u64 page_id, String const& html)
  582. {
  583. if (auto view = view_for_page_id(page_id); view.has_value()) {
  584. if (view->on_inspector_exported_inspector_html)
  585. view->on_inspector_exported_inspector_html(html);
  586. }
  587. }
  588. Messages::WebContentClient::RequestWorkerAgentResponse WebContentClient::request_worker_agent(u64 page_id)
  589. {
  590. if (auto view = view_for_page_id(page_id); view.has_value()) {
  591. if (view->on_request_worker_agent)
  592. return view->on_request_worker_agent();
  593. }
  594. return IPC::File {};
  595. }
  596. void WebContentClient::inspector_did_list_style_sheets(u64 page_id, Vector<Web::CSS::StyleSheetIdentifier> const& stylesheets)
  597. {
  598. if (auto view = view_for_page_id(page_id); view.has_value()) {
  599. if (view->on_received_style_sheet_list)
  600. view->on_received_style_sheet_list(stylesheets);
  601. }
  602. }
  603. void WebContentClient::inspector_did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier const& identifier)
  604. {
  605. if (auto view = view_for_page_id(page_id); view.has_value()) {
  606. if (view->on_inspector_requested_style_sheet_source)
  607. view->on_inspector_requested_style_sheet_source(identifier);
  608. }
  609. }
  610. void WebContentClient::did_request_style_sheet_source(u64 page_id, Web::CSS::StyleSheetIdentifier const& identifier, String const& source)
  611. {
  612. if (auto view = view_for_page_id(page_id); view.has_value()) {
  613. if (view->on_received_style_sheet_source)
  614. view->on_received_style_sheet_source(identifier, source);
  615. }
  616. }
  617. Optional<ViewImplementation&> WebContentClient::view_for_page_id(u64 page_id, SourceLocation location)
  618. {
  619. if (auto view = m_views.get(page_id); view.has_value())
  620. return *view.value();
  621. dbgln("WebContentClient::{}: Did not find a page with ID {}", location.function_name(), page_id);
  622. return {};
  623. }
  624. }