diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-05 14:32:17 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-06 09:51:04 +0200 |
commit | ceccc2c1634d9cae7c601ac6f678520a18d41cc1 (patch) | |
tree | c7a30f4ba295bbc31ffc541354785ccd52591539 /Userland | |
parent | d65279486277b1c1fe09249d01b22faa05c7ab59 (diff) | |
download | serenity-ceccc2c1634d9cae7c601ac6f678520a18d41cc1.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWebView/Forward.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/OutOfProcessWebView.h | 74 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/ViewImplementation.h | 56 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/WebContentClient.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/WebContentClient.h | 8 |
5 files changed, 102 insertions, 40 deletions
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 <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(); 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 <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; +}; + +} 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<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) { 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<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; }; } |