2020-06-17 18:31:42 +03:00
|
|
|
/*
|
2021-02-10 10:48:28 +03:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-06-17 18:31:42 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-17 18:31:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "WebContentClient.h"
|
2020-08-17 17:20:47 +03:00
|
|
|
#include "OutOfProcessWebView.h"
|
2021-01-17 18:57:17 +03:00
|
|
|
#include <AK/Debug.h>
|
2021-04-15 17:36:20 +03:00
|
|
|
#include <LibWeb/Cookie/ParsedCookie.h>
|
2020-06-17 18:31:42 +03:00
|
|
|
|
2020-08-24 14:03:18 +03:00
|
|
|
namespace Web {
|
|
|
|
|
2020-08-17 17:20:47 +03:00
|
|
|
WebContentClient::WebContentClient(OutOfProcessWebView& view)
|
2020-06-17 18:31:42 +03:00
|
|
|
: IPC::ServerConnection<WebContentClientEndpoint, WebContentServerEndpoint>(*this, "/tmp/portal/webcontent")
|
|
|
|
, m_view(view)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-30 20:20:40 +03:00
|
|
|
void WebContentClient::die()
|
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(on_web_content_process_crash);
|
2021-01-30 20:20:40 +03:00
|
|
|
on_web_content_process_crash();
|
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_paint(const Gfx::IntRect&, i32 bitmap_id)
|
2020-06-17 18:31:42 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_paint({}, bitmap_id);
|
2020-06-17 18:31:42 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_finish_loading(URL const& url)
|
2020-06-17 18:31:42 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_finish_loading({}, url);
|
2020-06-17 18:31:42 +03:00
|
|
|
}
|
2020-06-17 19:00:18 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_invalidate_content_rect(Gfx::IntRect const& content_rect)
|
2020-06-17 19:00:18 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidInvalidateContentRect! content_rect={}", content_rect);
|
2020-06-17 19:00:18 +03:00
|
|
|
|
|
|
|
// FIXME: Figure out a way to coalesce these messages to reduce unnecessary painting
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_invalidate_content_rect({}, content_rect);
|
2020-06-17 19:00:18 +03:00
|
|
|
}
|
2020-07-04 21:57:57 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_change_selection()
|
2020-07-04 21:57:57 +03:00
|
|
|
{
|
2021-05-01 22:10:08 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeSelection!");
|
2020-07-04 21:57:57 +03:00
|
|
|
m_view.notify_server_did_change_selection({});
|
|
|
|
}
|
2020-07-05 00:19:32 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_cursor_change(i32 cursor_type)
|
2021-02-28 00:12:12 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
if (cursor_type < 0 || cursor_type >= (i32)Gfx::StandardCursor::__Count) {
|
2021-02-28 00:12:12 +03:00
|
|
|
dbgln("DidRequestCursorChange: Bad cursor type");
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_request_cursor_change({}, (Gfx::StandardCursor)cursor_type);
|
2021-02-28 00:12:12 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_layout(Gfx::IntSize const& content_size)
|
2020-07-05 00:19:32 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidLayout! content_size={}", content_size);
|
|
|
|
m_view.notify_server_did_layout({}, content_size);
|
2020-07-05 00:19:32 +03:00
|
|
|
}
|
2020-07-05 00:40:17 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_change_title(String const& title)
|
2020-07-05 00:40:17 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeTitle! title={}", title);
|
|
|
|
m_view.notify_server_did_change_title({}, title);
|
2020-07-05 00:40:17 +03:00
|
|
|
}
|
2020-07-05 16:43:43 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_scroll(int wheel_delta)
|
2021-03-02 00:39:07 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_request_scroll({}, wheel_delta);
|
2021-03-02 00:39:07 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_scroll_into_view(Gfx::IntRect const& rect)
|
2020-07-05 16:43:43 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidRequestScrollIntoView! rect={}", rect);
|
|
|
|
m_view.notify_server_did_request_scroll_into_view({}, rect);
|
2020-07-05 16:43:43 +03:00
|
|
|
}
|
2020-07-05 17:59:20 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_enter_tooltip_area(Gfx::IntPoint const& content_position, String const& title)
|
2021-03-30 19:10:06 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_enter_tooltip_area({}, content_position, title);
|
2021-03-30 19:10:06 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_leave_tooltip_area()
|
2021-03-30 19:10:06 +03:00
|
|
|
{
|
|
|
|
m_view.notify_server_did_leave_tooltip_area({});
|
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_hover_link(URL const& url)
|
2020-07-05 17:59:20 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidHoverLink! url={}", url);
|
|
|
|
m_view.notify_server_did_hover_link({}, url);
|
2020-07-05 17:59:20 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_unhover_link()
|
2020-07-05 17:59:20 +03:00
|
|
|
{
|
2021-05-01 22:10:08 +03:00
|
|
|
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidUnhoverLink!");
|
2020-07-05 17:59:20 +03:00
|
|
|
m_view.notify_server_did_unhover_link({});
|
|
|
|
}
|
2020-07-06 21:01:46 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_click_link(URL const& url, String const& target, unsigned modifiers)
|
2020-07-06 21:01:46 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_click_link({}, url, target, modifiers);
|
2020-07-06 21:01:46 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_middle_click_link(URL const& url, String const& target, unsigned modifiers)
|
2020-07-06 21:01:46 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_middle_click_link({}, url, target, modifiers);
|
2020-07-06 21:01:46 +03:00
|
|
|
}
|
2020-07-06 22:58:16 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_start_loading(URL const& url)
|
2020-07-06 22:58:16 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_start_loading({}, url);
|
2020-07-06 22:58:16 +03:00
|
|
|
}
|
2020-07-07 13:24:29 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_context_menu(Gfx::IntPoint const& content_position)
|
2020-07-07 13:24:29 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_request_context_menu({}, content_position);
|
2020-07-07 13:24:29 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_link_context_menu(Gfx::IntPoint const& content_position, URL const& url, String const& target, unsigned modifiers)
|
2020-07-07 13:24:29 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_request_link_context_menu({}, content_position, url, target, modifiers);
|
2020-07-07 13:24:29 +03:00
|
|
|
}
|
2020-08-24 14:03:18 +03:00
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_image_context_menu(Gfx::IntPoint const& content_position, URL const& url, String const& target, unsigned modifiers, Gfx::ShareableBitmap const& bitmap)
|
2021-04-11 17:49:25 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_request_image_context_menu({}, content_position, url, target, modifiers, bitmap);
|
2021-04-11 17:49:25 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_get_source(URL const& url, String const& source)
|
2021-02-23 15:17:23 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_get_source(url, source);
|
2021-02-23 15:17:23 +03:00
|
|
|
}
|
|
|
|
|
2021-05-03 16:52:56 +03:00
|
|
|
void WebContentClient::did_js_console_output(String const& method, String const& line)
|
2021-02-28 06:47:14 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_js_console_output(method, line);
|
2021-02-28 06:47:14 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_request_alert(String const& message)
|
2020-09-12 12:56:13 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_request_alert({}, message);
|
2020-09-12 12:56:13 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
Messages::WebContentClient::DidRequestConfirmResponse WebContentClient::did_request_confirm(String const& message)
|
2021-02-10 10:48:28 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
return m_view.notify_server_did_request_confirm({}, message);
|
2021-02-10 10:48:28 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
Messages::WebContentClient::DidRequestPromptResponse WebContentClient::did_request_prompt(String const& message, String const& default_)
|
2021-02-20 14:05:18 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
return m_view.notify_server_did_request_prompt({}, message, default_);
|
2021-02-20 14:05:18 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_change_favicon(Gfx::ShareableBitmap const& favicon)
|
2021-03-26 17:41:25 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
if (!favicon.is_valid()) {
|
2021-03-26 17:41:25 +03:00
|
|
|
dbgln("DidChangeFavicon: Received invalid favicon");
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_change_favicon(*favicon.bitmap());
|
2021-03-26 17:41:25 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
Messages::WebContentClient::DidRequestCookieResponse WebContentClient::did_request_cookie(URL const& url, u8 source)
|
2021-04-11 17:54:11 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
return m_view.notify_server_did_request_cookie({}, url, static_cast<Cookie::Source>(source));
|
2021-04-11 17:54:11 +03:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:54:34 +03:00
|
|
|
void WebContentClient::did_set_cookie(URL const& url, Web::Cookie::ParsedCookie const& cookie, u8 source)
|
2021-04-11 17:54:11 +03:00
|
|
|
{
|
2021-05-02 20:54:34 +03:00
|
|
|
m_view.notify_server_did_set_cookie({}, url, cookie, static_cast<Cookie::Source>(source));
|
2021-04-11 17:54:11 +03:00
|
|
|
}
|
|
|
|
|
2020-08-24 14:03:18 +03:00
|
|
|
}
|