WebContentClient.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 "OutOfProcessWebView.h"
  8. #include <AK/Debug.h>
  9. #include <LibWeb/Cookie/ParsedCookie.h>
  10. namespace WebView {
  11. WebContentClient::WebContentClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, ViewImplementation& view)
  12. : IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket))
  13. , m_view(view)
  14. {
  15. }
  16. void WebContentClient::die()
  17. {
  18. VERIFY(on_web_content_process_crash);
  19. on_web_content_process_crash();
  20. }
  21. void WebContentClient::did_paint(Gfx::IntRect const&, i32 bitmap_id)
  22. {
  23. m_view.notify_server_did_paint({}, bitmap_id);
  24. }
  25. void WebContentClient::did_finish_loading(AK::URL const& url)
  26. {
  27. m_view.notify_server_did_finish_loading({}, url);
  28. }
  29. void WebContentClient::did_request_navigate_back()
  30. {
  31. m_view.notify_server_did_request_navigate_back({});
  32. }
  33. void WebContentClient::did_request_navigate_forward()
  34. {
  35. m_view.notify_server_did_request_navigate_forward({});
  36. }
  37. void WebContentClient::did_request_refresh()
  38. {
  39. m_view.notify_server_did_request_refresh({});
  40. }
  41. void WebContentClient::did_invalidate_content_rect(Gfx::IntRect const& content_rect)
  42. {
  43. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidInvalidateContentRect! content_rect={}", content_rect);
  44. // FIXME: Figure out a way to coalesce these messages to reduce unnecessary painting
  45. m_view.notify_server_did_invalidate_content_rect({}, content_rect);
  46. }
  47. void WebContentClient::did_change_selection()
  48. {
  49. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeSelection!");
  50. m_view.notify_server_did_change_selection({});
  51. }
  52. void WebContentClient::did_request_cursor_change(i32 cursor_type)
  53. {
  54. if (cursor_type < 0 || cursor_type >= (i32)Gfx::StandardCursor::__Count) {
  55. dbgln("DidRequestCursorChange: Bad cursor type");
  56. return;
  57. }
  58. m_view.notify_server_did_request_cursor_change({}, (Gfx::StandardCursor)cursor_type);
  59. }
  60. void WebContentClient::did_layout(Gfx::IntSize content_size)
  61. {
  62. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidLayout! content_size={}", content_size);
  63. m_view.notify_server_did_layout({}, content_size);
  64. }
  65. void WebContentClient::did_change_title(DeprecatedString const& title)
  66. {
  67. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeTitle! title={}", title);
  68. m_view.notify_server_did_change_title({}, title);
  69. }
  70. void WebContentClient::did_request_scroll(i32 x_delta, i32 y_delta)
  71. {
  72. m_view.notify_server_did_request_scroll({}, x_delta, y_delta);
  73. }
  74. void WebContentClient::did_request_scroll_to(Gfx::IntPoint scroll_position)
  75. {
  76. m_view.notify_server_did_request_scroll_to({}, scroll_position);
  77. }
  78. void WebContentClient::did_request_scroll_into_view(Gfx::IntRect const& rect)
  79. {
  80. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidRequestScrollIntoView! rect={}", rect);
  81. m_view.notify_server_did_request_scroll_into_view({}, rect);
  82. }
  83. void WebContentClient::did_enter_tooltip_area(Gfx::IntPoint content_position, DeprecatedString const& title)
  84. {
  85. m_view.notify_server_did_enter_tooltip_area({}, content_position, title);
  86. }
  87. void WebContentClient::did_leave_tooltip_area()
  88. {
  89. m_view.notify_server_did_leave_tooltip_area({});
  90. }
  91. void WebContentClient::did_hover_link(AK::URL const& url)
  92. {
  93. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidHoverLink! url={}", url);
  94. m_view.notify_server_did_hover_link({}, url);
  95. }
  96. void WebContentClient::did_unhover_link()
  97. {
  98. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidUnhoverLink!");
  99. m_view.notify_server_did_unhover_link({});
  100. }
  101. void WebContentClient::did_click_link(AK::URL const& url, DeprecatedString const& target, unsigned modifiers)
  102. {
  103. m_view.notify_server_did_click_link({}, url, target, modifiers);
  104. }
  105. void WebContentClient::did_middle_click_link(AK::URL const& url, DeprecatedString const& target, unsigned modifiers)
  106. {
  107. m_view.notify_server_did_middle_click_link({}, url, target, modifiers);
  108. }
  109. void WebContentClient::did_start_loading(AK::URL const& url, bool is_redirect)
  110. {
  111. m_view.notify_server_did_start_loading({}, url, is_redirect);
  112. }
  113. void WebContentClient::did_request_context_menu(Gfx::IntPoint content_position)
  114. {
  115. m_view.notify_server_did_request_context_menu({}, content_position);
  116. }
  117. void WebContentClient::did_request_link_context_menu(Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const& target, unsigned modifiers)
  118. {
  119. m_view.notify_server_did_request_link_context_menu({}, content_position, url, target, modifiers);
  120. }
  121. void WebContentClient::did_request_image_context_menu(Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const& target, unsigned modifiers, Gfx::ShareableBitmap const& bitmap)
  122. {
  123. m_view.notify_server_did_request_image_context_menu({}, content_position, url, target, modifiers, bitmap);
  124. }
  125. void WebContentClient::did_get_source(AK::URL const& url, DeprecatedString const& source)
  126. {
  127. m_view.notify_server_did_get_source(url, source);
  128. }
  129. void WebContentClient::did_get_dom_tree(DeprecatedString const& dom_tree)
  130. {
  131. m_view.notify_server_did_get_dom_tree(dom_tree);
  132. }
  133. void WebContentClient::did_get_dom_node_properties(i32 node_id, DeprecatedString const& specified_style, DeprecatedString const& computed_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing)
  134. {
  135. m_view.notify_server_did_get_dom_node_properties(node_id, specified_style, computed_style, custom_properties, node_box_sizing);
  136. }
  137. void WebContentClient::did_output_js_console_message(i32 message_index)
  138. {
  139. m_view.notify_server_did_output_js_console_message(message_index);
  140. }
  141. void WebContentClient::did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages)
  142. {
  143. m_view.notify_server_did_get_js_console_messages(start_index, message_types, messages);
  144. }
  145. void WebContentClient::did_request_alert(DeprecatedString const& message)
  146. {
  147. m_view.notify_server_did_request_alert({}, message);
  148. }
  149. void WebContentClient::did_request_confirm(DeprecatedString const& message)
  150. {
  151. m_view.notify_server_did_request_confirm({}, message);
  152. }
  153. void WebContentClient::did_request_prompt(DeprecatedString const& message, DeprecatedString const& default_)
  154. {
  155. m_view.notify_server_did_request_prompt({}, message, default_);
  156. }
  157. void WebContentClient::did_request_set_prompt_text(DeprecatedString const& message)
  158. {
  159. m_view.notify_server_did_request_set_prompt_text({}, message);
  160. }
  161. void WebContentClient::did_request_accept_dialog()
  162. {
  163. m_view.notify_server_did_request_accept_dialog({});
  164. }
  165. void WebContentClient::did_request_dismiss_dialog()
  166. {
  167. m_view.notify_server_did_request_dismiss_dialog({});
  168. }
  169. void WebContentClient::did_change_favicon(Gfx::ShareableBitmap const& favicon)
  170. {
  171. if (!favicon.is_valid()) {
  172. dbgln("DidChangeFavicon: Received invalid favicon");
  173. return;
  174. }
  175. m_view.notify_server_did_change_favicon(*favicon.bitmap());
  176. }
  177. Messages::WebContentClient::DidRequestAllCookiesResponse WebContentClient::did_request_all_cookies(AK::URL const& url)
  178. {
  179. return m_view.notify_server_did_request_all_cookies({}, url);
  180. }
  181. Messages::WebContentClient::DidRequestNamedCookieResponse WebContentClient::did_request_named_cookie(AK::URL const& url, DeprecatedString const& name)
  182. {
  183. return m_view.notify_server_did_request_named_cookie({}, url, name);
  184. }
  185. Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(AK::URL const& url, u8 source)
  186. {
  187. return m_view.notify_server_did_request_cookie({}, url, static_cast<Web::Cookie::Source>(source));
  188. }
  189. void WebContentClient::did_set_cookie(AK::URL const& url, Web::Cookie::ParsedCookie const& cookie, u8 source)
  190. {
  191. m_view.notify_server_did_set_cookie({}, url, cookie, static_cast<Web::Cookie::Source>(source));
  192. }
  193. void WebContentClient::did_update_cookie(AK::URL const& url, Web::Cookie::Cookie const& cookie)
  194. {
  195. m_view.notify_server_did_update_cookie({}, url, cookie);
  196. }
  197. void WebContentClient::did_update_resource_count(i32 count_waiting)
  198. {
  199. m_view.notify_server_did_update_resource_count(count_waiting);
  200. }
  201. void WebContentClient::did_request_restore_window()
  202. {
  203. m_view.notify_server_did_request_restore_window();
  204. }
  205. Messages::WebContentClient::DidRequestRepositionWindowResponse WebContentClient::did_request_reposition_window(Gfx::IntPoint position)
  206. {
  207. return m_view.notify_server_did_request_reposition_window(position);
  208. }
  209. Messages::WebContentClient::DidRequestResizeWindowResponse WebContentClient::did_request_resize_window(Gfx::IntSize size)
  210. {
  211. return m_view.notify_server_did_request_resize_window(size);
  212. }
  213. Messages::WebContentClient::DidRequestMaximizeWindowResponse WebContentClient::did_request_maximize_window()
  214. {
  215. return m_view.notify_server_did_request_maximize_window();
  216. }
  217. Messages::WebContentClient::DidRequestMinimizeWindowResponse WebContentClient::did_request_minimize_window()
  218. {
  219. return m_view.notify_server_did_request_minimize_window();
  220. }
  221. Messages::WebContentClient::DidRequestFullscreenWindowResponse WebContentClient::did_request_fullscreen_window()
  222. {
  223. return m_view.notify_server_did_request_fullscreen_window();
  224. }
  225. void WebContentClient::did_request_file(DeprecatedString const& path, i32 request_id)
  226. {
  227. m_view.notify_server_did_request_file({}, path, request_id);
  228. }
  229. void WebContentClient::did_finish_handling_input_event(bool event_was_accepted)
  230. {
  231. m_view.notify_server_did_finish_handling_input_event(event_was_accepted);
  232. }
  233. }