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