WebContentClient.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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(OutOfProcessWebView& view)
  12. : IPC::ServerConnection<WebContentClientEndpoint, WebContentServerEndpoint>(*this, "/tmp/portal/webcontent")
  13. , m_view(view)
  14. {
  15. handshake();
  16. }
  17. void WebContentClient::die()
  18. {
  19. VERIFY(on_web_content_process_crash);
  20. on_web_content_process_crash();
  21. }
  22. void WebContentClient::handshake()
  23. {
  24. greet();
  25. }
  26. void WebContentClient::did_paint(const Gfx::IntRect&, i32 bitmap_id)
  27. {
  28. m_view.notify_server_did_paint({}, bitmap_id);
  29. }
  30. void WebContentClient::did_finish_loading(URL const& url)
  31. {
  32. m_view.notify_server_did_finish_loading({}, url);
  33. }
  34. void WebContentClient::did_invalidate_content_rect(Gfx::IntRect const& content_rect)
  35. {
  36. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidInvalidateContentRect! content_rect={}", content_rect);
  37. // FIXME: Figure out a way to coalesce these messages to reduce unnecessary painting
  38. m_view.notify_server_did_invalidate_content_rect({}, content_rect);
  39. }
  40. void WebContentClient::did_change_selection()
  41. {
  42. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeSelection!");
  43. m_view.notify_server_did_change_selection({});
  44. }
  45. void WebContentClient::did_request_cursor_change(i32 cursor_type)
  46. {
  47. if (cursor_type < 0 || cursor_type >= (i32)Gfx::StandardCursor::__Count) {
  48. dbgln("DidRequestCursorChange: Bad cursor type");
  49. return;
  50. }
  51. m_view.notify_server_did_request_cursor_change({}, (Gfx::StandardCursor)cursor_type);
  52. }
  53. void WebContentClient::did_layout(Gfx::IntSize const& content_size)
  54. {
  55. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidLayout! content_size={}", content_size);
  56. m_view.notify_server_did_layout({}, content_size);
  57. }
  58. void WebContentClient::did_change_title(String const& title)
  59. {
  60. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeTitle! title={}", title);
  61. m_view.notify_server_did_change_title({}, title);
  62. }
  63. void WebContentClient::did_request_scroll(int wheel_delta)
  64. {
  65. m_view.notify_server_did_request_scroll({}, wheel_delta);
  66. }
  67. void WebContentClient::did_request_scroll_into_view(Gfx::IntRect const& rect)
  68. {
  69. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidRequestScrollIntoView! rect={}", rect);
  70. m_view.notify_server_did_request_scroll_into_view({}, rect);
  71. }
  72. void WebContentClient::did_enter_tooltip_area(Gfx::IntPoint const& content_position, String const& title)
  73. {
  74. m_view.notify_server_did_enter_tooltip_area({}, content_position, title);
  75. }
  76. void WebContentClient::did_leave_tooltip_area()
  77. {
  78. m_view.notify_server_did_leave_tooltip_area({});
  79. }
  80. void WebContentClient::did_hover_link(URL const& url)
  81. {
  82. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidHoverLink! url={}", url);
  83. m_view.notify_server_did_hover_link({}, url);
  84. }
  85. void WebContentClient::did_unhover_link()
  86. {
  87. dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidUnhoverLink!");
  88. m_view.notify_server_did_unhover_link({});
  89. }
  90. void WebContentClient::did_click_link(URL const& url, String const& target, unsigned modifiers)
  91. {
  92. m_view.notify_server_did_click_link({}, url, target, modifiers);
  93. }
  94. void WebContentClient::did_middle_click_link(URL const& url, String const& target, unsigned modifiers)
  95. {
  96. m_view.notify_server_did_middle_click_link({}, url, target, modifiers);
  97. }
  98. void WebContentClient::did_start_loading(URL const& url)
  99. {
  100. m_view.notify_server_did_start_loading({}, url);
  101. }
  102. void WebContentClient::did_request_context_menu(Gfx::IntPoint const& content_position)
  103. {
  104. m_view.notify_server_did_request_context_menu({}, content_position);
  105. }
  106. void WebContentClient::did_request_link_context_menu(Gfx::IntPoint const& content_position, URL const& url, String const& target, unsigned modifiers)
  107. {
  108. m_view.notify_server_did_request_link_context_menu({}, content_position, url, target, modifiers);
  109. }
  110. void WebContentClient::did_request_image_context_menu(Gfx::IntPoint const& content_position, URL const& url, String const& target, unsigned modifiers, Gfx::ShareableBitmap const& bitmap)
  111. {
  112. m_view.notify_server_did_request_image_context_menu({}, content_position, url, target, modifiers, bitmap);
  113. }
  114. void WebContentClient::did_get_source(URL const& url, String const& source)
  115. {
  116. m_view.notify_server_did_get_source(url, source);
  117. }
  118. void WebContentClient::did_js_console_output(String const& method, String const& line)
  119. {
  120. m_view.notify_server_did_js_console_output(method, line);
  121. }
  122. void WebContentClient::did_request_alert(String const& message)
  123. {
  124. m_view.notify_server_did_request_alert({}, message);
  125. }
  126. Messages::WebContentClient::DidRequestConfirmResponse WebContentClient::did_request_confirm(String const& message)
  127. {
  128. return m_view.notify_server_did_request_confirm({}, message);
  129. }
  130. Messages::WebContentClient::DidRequestPromptResponse WebContentClient::did_request_prompt(String const& message, String const& default_)
  131. {
  132. return m_view.notify_server_did_request_prompt({}, message, default_);
  133. }
  134. void WebContentClient::did_change_favicon(Gfx::ShareableBitmap const& favicon)
  135. {
  136. if (!favicon.is_valid()) {
  137. dbgln("DidChangeFavicon: Received invalid favicon");
  138. return;
  139. }
  140. m_view.notify_server_did_change_favicon(*favicon.bitmap());
  141. }
  142. Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(URL const& url, u8 source)
  143. {
  144. return m_view.notify_server_did_request_cookie({}, url, static_cast<Cookie::Source>(source));
  145. }
  146. void WebContentClient::did_set_cookie(URL const& url, Web::Cookie::ParsedCookie const& cookie, u8 source)
  147. {
  148. m_view.notify_server_did_set_cookie({}, url, cookie, static_cast<Cookie::Source>(source));
  149. }
  150. }