From ceccc2c1634d9cae7c601ac6f678520a18d41cc1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 5 Oct 2022 14:32:17 +0200 Subject: 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. --- Userland/Libraries/LibWebView/Forward.h | 2 + .../Libraries/LibWebView/OutOfProcessWebView.h | 74 ++++++++++++---------- Userland/Libraries/LibWebView/ViewImplementation.h | 56 ++++++++++++++++ Userland/Libraries/LibWebView/WebContentClient.cpp | 2 +- Userland/Libraries/LibWebView/WebContentClient.h | 8 +-- 5 files changed, 102 insertions(+), 40 deletions(-) create mode 100644 Userland/Libraries/LibWebView/ViewImplementation.h (limited to 'Userland') diff --git a/Userland/Libraries/LibWebView/Forward.h b/Userland/Libraries/LibWebView/Forward.h index a52b609cd5..a89e644404 100644 --- a/Userland/Libraries/LibWebView/Forward.h +++ b/Userland/Libraries/LibWebView/Forward.h @@ -9,5 +9,7 @@ namespace WebView { class OutOfProcessWebView; +class ViewImplementation; +class WebContentClient; } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index d5990d8ebb..6fc85212c9 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -11,12 +11,15 @@ #include #include #include +#include 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 on_set_cookie; Function on_resource_status_change; - void notify_server_did_layout(Badge, Gfx::IntSize const& content_size); - void notify_server_did_paint(Badge, i32 bitmap_id); - void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&); - void notify_server_did_change_selection(Badge); - void notify_server_did_request_cursor_change(Badge, Gfx::StandardCursor cursor); - void notify_server_did_change_title(Badge, String const&); - void notify_server_did_request_scroll(Badge, i32, i32); - void notify_server_did_request_scroll_to(Badge, Gfx::IntPoint const&); - void notify_server_did_request_scroll_into_view(Badge, Gfx::IntRect const&); - void notify_server_did_enter_tooltip_area(Badge, Gfx::IntPoint const&, String const&); - void notify_server_did_leave_tooltip_area(Badge); - void notify_server_did_hover_link(Badge, const AK::URL&); - void notify_server_did_unhover_link(Badge); - void notify_server_did_click_link(Badge, const AK::URL&, String const& target, unsigned modifiers); - void notify_server_did_middle_click_link(Badge, const AK::URL&, String const& target, unsigned modifiers); - void notify_server_did_start_loading(Badge, const AK::URL&); - void notify_server_did_finish_loading(Badge, const AK::URL&); - void notify_server_did_request_context_menu(Badge, Gfx::IntPoint const&); - void notify_server_did_request_link_context_menu(Badge, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers); - void notify_server_did_request_image_context_menu(Badge, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&); - void notify_server_did_request_alert(Badge, String const& message); - bool notify_server_did_request_confirm(Badge, String const& message); - String notify_server_did_request_prompt(Badge, 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 const& message_types, Vector const& messages); - void notify_server_did_change_favicon(Gfx::Bitmap const& favicon); - String notify_server_did_request_cookie(Badge, const AK::URL& url, Web::Cookie::Source source); - void notify_server_did_set_cookie(Badge, 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, 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, Gfx::IntSize const& content_size) override; + virtual void notify_server_did_paint(Badge, i32 bitmap_id) override; + virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) override; + virtual void notify_server_did_change_selection(Badge) override; + virtual void notify_server_did_request_cursor_change(Badge, Gfx::StandardCursor cursor) override; + virtual void notify_server_did_change_title(Badge, String const&) override; + virtual void notify_server_did_request_scroll(Badge, i32, i32) override; + virtual void notify_server_did_request_scroll_to(Badge, Gfx::IntPoint const&) override; + virtual void notify_server_did_request_scroll_into_view(Badge, Gfx::IntRect const&) override; + virtual void notify_server_did_enter_tooltip_area(Badge, Gfx::IntPoint const&, String const&) override; + virtual void notify_server_did_leave_tooltip_area(Badge) override; + virtual void notify_server_did_hover_link(Badge, const AK::URL&) override; + virtual void notify_server_did_unhover_link(Badge) override; + virtual void notify_server_did_click_link(Badge, const AK::URL&, String const& target, unsigned modifiers) override; + virtual void notify_server_did_middle_click_link(Badge, const AK::URL&, String const& target, unsigned modifiers) override; + virtual void notify_server_did_start_loading(Badge, const AK::URL&) override; + virtual void notify_server_did_finish_loading(Badge, const AK::URL&) override; + virtual void notify_server_did_request_context_menu(Badge, Gfx::IntPoint const&) override; + virtual void notify_server_did_request_link_context_menu(Badge, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers) override; + virtual void notify_server_did_request_image_context_menu(Badge, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&) override; + virtual void notify_server_did_request_alert(Badge, String const& message) override; + virtual bool notify_server_did_request_confirm(Badge, String const& message) override; + virtual String notify_server_did_request_prompt(Badge, 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 const& message_types, Vector const& messages) override; + virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) override; + virtual String notify_server_did_request_cookie(Badge, const AK::URL& url, Web::Cookie::Source source) override; + virtual void notify_server_did_set_cookie(Badge, 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, String const& path, i32) override; + void request_repaint(); void handle_resize(); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h new file mode 100644 index 0000000000..2421907b70 --- /dev/null +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace WebView { + +class ViewImplementation { +public: + virtual ~ViewImplementation() { } + + virtual void notify_server_did_layout(Badge, Gfx::IntSize const& content_size) = 0; + virtual void notify_server_did_paint(Badge, i32 bitmap_id) = 0; + virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) = 0; + virtual void notify_server_did_change_selection(Badge) = 0; + virtual void notify_server_did_request_cursor_change(Badge, Gfx::StandardCursor cursor) = 0; + virtual void notify_server_did_change_title(Badge, String const&) = 0; + virtual void notify_server_did_request_scroll(Badge, i32, i32) = 0; + virtual void notify_server_did_request_scroll_to(Badge, Gfx::IntPoint const&) = 0; + virtual void notify_server_did_request_scroll_into_view(Badge, Gfx::IntRect const&) = 0; + virtual void notify_server_did_enter_tooltip_area(Badge, Gfx::IntPoint const&, String const&) = 0; + virtual void notify_server_did_leave_tooltip_area(Badge) = 0; + virtual void notify_server_did_hover_link(Badge, const AK::URL&) = 0; + virtual void notify_server_did_unhover_link(Badge) = 0; + virtual void notify_server_did_click_link(Badge, const AK::URL&, String const& target, unsigned modifiers) = 0; + virtual void notify_server_did_middle_click_link(Badge, const AK::URL&, String const& target, unsigned modifiers) = 0; + virtual void notify_server_did_start_loading(Badge, const AK::URL&) = 0; + virtual void notify_server_did_finish_loading(Badge, const AK::URL&) = 0; + virtual void notify_server_did_request_context_menu(Badge, Gfx::IntPoint const&) = 0; + virtual void notify_server_did_request_link_context_menu(Badge, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers) = 0; + virtual void notify_server_did_request_image_context_menu(Badge, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&) = 0; + virtual void notify_server_did_request_alert(Badge, String const& message) = 0; + virtual bool notify_server_did_request_confirm(Badge, String const& message) = 0; + virtual String notify_server_did_request_prompt(Badge, 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 const& message_types, Vector const& messages) = 0; + virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) = 0; + virtual String notify_server_did_request_cookie(Badge, const AK::URL& url, Web::Cookie::Source source) = 0; + virtual void notify_server_did_set_cookie(Badge, 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, String const& path, i32) = 0; +}; + +} diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index b83307f115..2388e560e5 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -11,7 +11,7 @@ namespace WebView { -WebContentClient::WebContentClient(NonnullOwnPtr socket, OutOfProcessWebView& view) +WebContentClient::WebContentClient(NonnullOwnPtr socket, ViewImplementation& view) : IPC::ConnectionToServer(*this, move(socket)) , m_view(view) { diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 412584a68f..11c08f011a 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -14,7 +14,7 @@ namespace WebView { -class OutOfProcessWebView; +class ViewImplementation; class WebContentClient final : public IPC::ConnectionToServer @@ -22,11 +22,11 @@ class WebContentClient final IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/session/%sid/portal/webcontent"sv); public: + WebContentClient(NonnullOwnPtr, ViewImplementation&); + Function on_web_content_process_crash; private: - WebContentClient(NonnullOwnPtr, 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; }; } -- cgit v1.2.3