LibWebView: Add abstract virtual base for WebView implementations

This patch adds WebView::ViewImplementation with all the
`notify_server_did_this_or_that()` functions from OOPWV.

This will allow us to share code between different web views, paving the
way for a Qt widget in Ladybird that can talk to a WebContent process.
This commit is contained in:
Andreas Kling 2022-10-05 14:32:17 +02:00
parent d652794862
commit ceccc2c163
5 changed files with 102 additions and 40 deletions

View file

@ -9,5 +9,7 @@
namespace WebView {
class OutOfProcessWebView;
class ViewImplementation;
class WebContentClient;
}

View file

@ -11,12 +11,15 @@
#include <LibGUI/Widget.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/Page/Page.h>
#include <LibWebView/ViewImplementation.h>
namespace WebView {
class WebContentClient;
class OutOfProcessWebView final : public GUI::AbstractScrollableWidget {
class OutOfProcessWebView final
: public GUI::AbstractScrollableWidget
, public ViewImplementation {
C_OBJECT(OutOfProcessWebView);
public:
@ -80,40 +83,6 @@ public:
Function<void(const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)> on_set_cookie;
Function<void(i32 count_waiting)> on_resource_status_change;
void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize const& content_size);
void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&);
void notify_server_did_change_selection(Badge<WebContentClient>);
void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor);
void notify_server_did_change_title(Badge<WebContentClient>, String const&);
void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32);
void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint const&);
void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&);
void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint const&, String const&);
void notify_server_did_leave_tooltip_area(Badge<WebContentClient>);
void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&);
void notify_server_did_unhover_link(Badge<WebContentClient>);
void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers);
void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers);
void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&);
void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&);
void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&);
void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers);
void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&);
void notify_server_did_request_alert(Badge<WebContentClient>, String const& message);
bool notify_server_did_request_confirm(Badge<WebContentClient>, String const& message);
String notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_);
void notify_server_did_get_source(const AK::URL& url, String const& source);
void notify_server_did_get_dom_tree(String const& dom_tree);
void notify_server_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);
void notify_server_did_output_js_console_message(i32 message_index);
void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages);
void notify_server_did_change_favicon(Gfx::Bitmap const& favicon);
String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source);
void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source);
void notify_server_did_update_resource_count(i32 count_waiting);
void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32);
private:
OutOfProcessWebView();
@ -137,6 +106,41 @@ private:
// ^AbstractScrollableWidget
virtual void did_scroll() override;
// ^WebView::ViewImplementation
virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize const& content_size) override;
virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override;
virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override;
virtual void notify_server_did_change_selection(Badge<WebContentClient>) override;
virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override;
virtual void notify_server_did_change_title(Badge<WebContentClient>, String const&) override;
virtual void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32) override;
virtual void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint const&) override;
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override;
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint const&, String const&) override;
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
virtual void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&) override;
virtual void notify_server_did_unhover_link(Badge<WebContentClient>) override;
virtual void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers) override;
virtual void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers) override;
virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&) override;
virtual void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&) override;
virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&) override;
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers) override;
virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&) override;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) override;
virtual bool notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
virtual String notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) override;
virtual void notify_server_did_get_source(const AK::URL& url, String const& source) override;
virtual void notify_server_did_get_dom_tree(String const& dom_tree) override;
virtual void notify_server_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) override;
virtual void notify_server_did_output_js_console_message(i32 message_index) override;
virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) override;
virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) override;
virtual String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) override;
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override;
virtual void notify_server_did_update_resource_count(i32 count_waiting) override;
virtual void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32) override;
void request_repaint();
void handle_resize();

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <LibGfx/Forward.h>
#include <LibGfx/StandardCursor.h>
#include <LibWeb/Forward.h>
#include <LibWebView/Forward.h>
namespace WebView {
class ViewImplementation {
public:
virtual ~ViewImplementation() { }
virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize const& content_size) = 0;
virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) = 0;
virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) = 0;
virtual void notify_server_did_change_selection(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) = 0;
virtual void notify_server_did_change_title(Badge<WebContentClient>, String const&) = 0;
virtual void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32) = 0;
virtual void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint const&) = 0;
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) = 0;
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint const&, String const&) = 0;
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) = 0;
virtual void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&) = 0;
virtual void notify_server_did_unhover_link(Badge<WebContentClient>) = 0;
virtual void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers) = 0;
virtual void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers) = 0;
virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&) = 0;
virtual void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&) = 0;
virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&) = 0;
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers) = 0;
virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&) = 0;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) = 0;
virtual bool notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) = 0;
virtual String notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) = 0;
virtual void notify_server_did_get_source(const AK::URL& url, String const& source) = 0;
virtual void notify_server_did_get_dom_tree(String const& dom_tree) = 0;
virtual void notify_server_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) = 0;
virtual void notify_server_did_output_js_console_message(i32 message_index) = 0;
virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) = 0;
virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) = 0;
virtual String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) = 0;
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) = 0;
virtual void notify_server_did_update_resource_count(i32 count_waiting) = 0;
virtual void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32) = 0;
};
}

View file

@ -11,7 +11,7 @@
namespace WebView {
WebContentClient::WebContentClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, OutOfProcessWebView& view)
WebContentClient::WebContentClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, ViewImplementation& view)
: IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>(*this, move(socket))
, m_view(view)
{

View file

@ -14,7 +14,7 @@
namespace WebView {
class OutOfProcessWebView;
class ViewImplementation;
class WebContentClient final
: public IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>
@ -22,11 +22,11 @@ class WebContentClient final
IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/session/%sid/portal/webcontent"sv);
public:
WebContentClient(NonnullOwnPtr<Core::Stream::LocalSocket>, ViewImplementation&);
Function<void()> on_web_content_process_crash;
private:
WebContentClient(NonnullOwnPtr<Core::Stream::LocalSocket>, OutOfProcessWebView&);
virtual void die() override;
virtual void did_paint(Gfx::IntRect const&, i32) override;
@ -63,7 +63,7 @@ private:
virtual void did_update_resource_count(i32 count_waiting) override;
virtual void did_request_file(String const& path, i32) override;
OutOfProcessWebView& m_view;
ViewImplementation& m_view;
};
}