WebContentClient.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 Web {
  11. WebContentClient::WebContentClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, OutOfProcessWebView& 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(const Gfx::IntRect&, 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_invalidate_content_rect(Gfx::IntRect const& content_rect)
  30. {
  31. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidInvalidateContentRect! content_rect={}", content_rect);
  32. // FIXME: Figure out a way to coalesce these messages to reduce unnecessary painting
  33. m_view.notify_server_did_invalidate_content_rect({}, content_rect);
  34. }
  35. void WebContentClient::did_change_selection()
  36. {
  37. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeSelection!");
  38. m_view.notify_server_did_change_selection({});
  39. }
  40. void WebContentClient::did_request_cursor_change(i32 cursor_type)
  41. {
  42. if (cursor_type < 0 || cursor_type >= (i32)Gfx::StandardCursor::__Count) {
  43. dbgln("DidRequestCursorChange: Bad cursor type");
  44. return;
  45. }
  46. m_view.notify_server_did_request_cursor_change({}, (Gfx::StandardCursor)cursor_type);
  47. }
  48. void WebContentClient::did_layout(Gfx::IntSize const& content_size)
  49. {
  50. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidLayout! content_size={}", content_size);
  51. m_view.notify_server_did_layout({}, content_size);
  52. }
  53. void WebContentClient::did_change_title(String const& title)
  54. {
  55. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeTitle! title={}", title);
  56. m_view.notify_server_did_change_title({}, title);
  57. }
  58. void WebContentClient::did_request_scroll(i32 x_delta, i32 y_delta)
  59. {
  60. m_view.notify_server_did_request_scroll({}, x_delta, y_delta);
  61. }
  62. void WebContentClient::did_request_scroll_to(Gfx::IntPoint const& scroll_position)
  63. {
  64. m_view.notify_server_did_request_scroll_to({}, scroll_position);
  65. }
  66. void WebContentClient::did_request_scroll_into_view(Gfx::IntRect const& rect)
  67. {
  68. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidRequestScrollIntoView! rect={}", rect);
  69. m_view.notify_server_did_request_scroll_into_view({}, rect);
  70. }
  71. void WebContentClient::did_enter_tooltip_area(Gfx::IntPoint const& content_position, String const& title)
  72. {
  73. m_view.notify_server_did_enter_tooltip_area({}, content_position, title);
  74. }
  75. void WebContentClient::did_leave_tooltip_area()
  76. {
  77. m_view.notify_server_did_leave_tooltip_area({});
  78. }
  79. void WebContentClient::did_hover_link(AK::URL const& url)
  80. {
  81. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidHoverLink! url={}", url);
  82. m_view.notify_server_did_hover_link({}, url);
  83. }
  84. void WebContentClient::did_unhover_link()
  85. {
  86. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidUnhoverLink!");
  87. m_view.notify_server_did_unhover_link({});
  88. }
  89. void WebContentClient::did_click_link(AK::URL const& url, String const& target, unsigned modifiers)
  90. {
  91. m_view.notify_server_did_click_link({}, url, target, modifiers);
  92. }
  93. void WebContentClient::did_middle_click_link(AK::URL const& url, String const& target, unsigned modifiers)
  94. {
  95. m_view.notify_server_did_middle_click_link({}, url, target, modifiers);
  96. }
  97. void WebContentClient::did_start_loading(AK::URL const& url)
  98. {
  99. m_view.notify_server_did_start_loading({}, url);
  100. }
  101. void WebContentClient::did_request_context_menu(Gfx::IntPoint const& content_position)
  102. {
  103. m_view.notify_server_did_request_context_menu({}, content_position);
  104. }
  105. void WebContentClient::did_request_link_context_menu(Gfx::IntPoint const& content_position, AK::URL const& url, String const& target, unsigned modifiers)
  106. {
  107. m_view.notify_server_did_request_link_context_menu({}, content_position, url, target, modifiers);
  108. }
  109. void WebContentClient::did_request_image_context_menu(Gfx::IntPoint const& content_position, AK::URL const& url, String const& target, unsigned modifiers, Gfx::ShareableBitmap const& bitmap)
  110. {
  111. m_view.notify_server_did_request_image_context_menu({}, content_position, url, target, modifiers, bitmap);
  112. }
  113. void WebContentClient::did_get_source(AK::URL const& url, String const& source)
  114. {
  115. m_view.notify_server_did_get_source(url, source);
  116. }
  117. void WebContentClient::did_get_dom_tree(String const& dom_tree)
  118. {
  119. m_view.notify_server_did_get_dom_tree(dom_tree);
  120. }
  121. void WebContentClient::did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties, String const& node_box_sizing)
  122. {
  123. m_view.notify_server_did_get_dom_node_properties(node_id, specified_style, computed_style, custom_properties, node_box_sizing);
  124. }
  125. void WebContentClient::did_output_js_console_message(i32 message_index)
  126. {
  127. m_view.notify_server_did_output_js_console_message(message_index);
  128. }
  129. void WebContentClient::did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)
  130. {
  131. m_view.notify_server_did_get_js_console_messages(start_index, message_types, messages);
  132. }
  133. void WebContentClient::did_request_alert(String const& message)
  134. {
  135. m_view.notify_server_did_request_alert({}, message);
  136. }
  137. Messages::WebContentClient::DidRequestConfirmResponse WebContentClient::did_request_confirm(String const& message)
  138. {
  139. return m_view.notify_server_did_request_confirm({}, message);
  140. }
  141. Messages::WebContentClient::DidRequestPromptResponse WebContentClient::did_request_prompt(String const& message, String const& default_)
  142. {
  143. return m_view.notify_server_did_request_prompt({}, message, default_);
  144. }
  145. void WebContentClient::did_change_favicon(Gfx::ShareableBitmap const& favicon)
  146. {
  147. if (!favicon.is_valid()) {
  148. dbgln("DidChangeFavicon: Received invalid favicon");
  149. return;
  150. }
  151. m_view.notify_server_did_change_favicon(*favicon.bitmap());
  152. }
  153. Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(AK::URL const& url, u8 source)
  154. {
  155. return m_view.notify_server_did_request_cookie({}, url, static_cast<Cookie::Source>(source));
  156. }
  157. void WebContentClient::did_set_cookie(AK::URL const& url, Web::Cookie::ParsedCookie const& cookie, u8 source)
  158. {
  159. m_view.notify_server_did_set_cookie({}, url, cookie, static_cast<Cookie::Source>(source));
  160. }
  161. void WebContentClient::did_update_resource_count(i32 count_waiting)
  162. {
  163. m_view.notify_server_did_update_resource_count(count_waiting);
  164. }
  165. }