diff --git a/Userland/Libraries/LibWebView/InspectorClient.cpp b/Userland/Libraries/LibWebView/InspectorClient.cpp index 1c77856666..30cfa1d3d3 100644 --- a/Userland/Libraries/LibWebView/InspectorClient.cpp +++ b/Userland/Libraries/LibWebView/InspectorClient.cpp @@ -100,6 +100,11 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple inspect(); }; + m_content_web_view.on_received_dom_node_html = [this](auto const& html) { + if (m_content_web_view.on_insert_clipboard_entry) + m_content_web_view.on_insert_clipboard_entry(html, "unspecified"_string, "text/plain"_string); + }; + m_content_web_view.on_received_console_message = [this](auto message_index) { handle_console_message(message_index); }; @@ -241,11 +246,7 @@ void InspectorClient::context_menu_copy_dom_node() { VERIFY(m_context_menu_data.has_value()); - if (auto html = m_content_web_view.get_dom_node_html(m_context_menu_data->dom_node_id); html.has_value()) { - if (m_content_web_view.on_insert_clipboard_entry) - m_content_web_view.on_insert_clipboard_entry(*html, "unspecified"_string, "text/plain"_string); - } - + m_content_web_view.get_dom_node_html(m_context_menu_data->dom_node_id); m_context_menu_data.clear(); } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 6cff070d57..f0cbbf12e2 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -191,9 +191,9 @@ void ViewImplementation::remove_dom_node(i32 node_id) client().async_remove_dom_node(node_id); } -Optional ViewImplementation::get_dom_node_html(i32 node_id) +void ViewImplementation::get_dom_node_html(i32 node_id) { - return client().get_dom_node_html(node_id); + client().async_get_dom_node_html(node_id); } void ViewImplementation::debug_request(ByteString const& request, ByteString const& argument) diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 1925575e57..1e33c1c4da 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -72,7 +72,7 @@ public: void create_child_text_node(i32 node_id); void clone_dom_node(i32 node_id); void remove_dom_node(i32 node_id); - Optional get_dom_node_html(i32 node_id); + void get_dom_node_html(i32 node_id); void debug_request(ByteString const& request, ByteString const& argument = {}); @@ -145,6 +145,7 @@ public: Function on_received_accessibility_tree; Function on_received_hovered_node_id; Function const& node_id)> on_finshed_editing_dom_node; + Function on_received_dom_node_html; Function on_received_console_message; Function const& message_types, Vector const& messages)> on_received_console_messages; Function(AK::URL const& url)> on_get_all_cookies; diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index b590dc40a1..f939b2da8f 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -225,6 +225,12 @@ void WebContentClient::did_finish_editing_dom_node(Optional const& node_id) m_view.on_finshed_editing_dom_node(node_id); } +void WebContentClient::did_get_dom_node_html(String const& html) +{ + if (m_view.on_received_dom_node_html) + m_view.on_received_dom_node_html(html); +} + void WebContentClient::did_output_js_console_message(i32 message_index) { if (m_view.on_received_console_message) diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 60bf0f1be8..44bba319b8 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -57,6 +57,7 @@ private: virtual void did_inspect_accessibility_tree(ByteString const&) override; virtual void did_get_hovered_node_id(i32 node_id) override; virtual void did_finish_editing_dom_node(Optional const& node_id) override; + virtual void did_get_dom_node_html(String const& html) override; virtual void did_output_js_console_message(i32 message_index) override; virtual void did_get_js_console_messages(i32 start_index, Vector const& message_types, Vector const& messages) override; virtual void did_change_favicon(Gfx::ShareableBitmap const&) override; diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 3e00c4aff2..a197224fbc 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -781,17 +781,18 @@ void ConnectionFromClient::remove_dom_node(i32 node_id) async_did_finish_editing_dom_node(previous_dom_node->unique_id()); } -Messages::WebContentServer::GetDomNodeHtmlResponse ConnectionFromClient::get_dom_node_html(i32 node_id) +void ConnectionFromClient::get_dom_node_html(i32 node_id) { auto* dom_node = Web::DOM::Node::from_unique_id(node_id); if (!dom_node) - return OptionalNone {}; + return; // FIXME: Implement Element's outerHTML attribute. auto container = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors(); container->append_child(dom_node->clone_node(nullptr, true)).release_value_but_fixme_should_propagate_errors(); - return container->inner_html().release_value_but_fixme_should_propagate_errors(); + auto html = container->inner_html().release_value_but_fixme_should_propagate_errors(); + async_did_get_dom_node_html(move(html)); } void ConnectionFromClient::initialize_js_console(Badge, Web::DOM::Document& document) diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index a16d375cd0..2df6d520ef 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -84,7 +84,7 @@ private: virtual void create_child_text_node(i32 node_id) override; virtual void clone_dom_node(i32 node_id) override; virtual void remove_dom_node(i32 node_id) override; - virtual Messages::WebContentServer::GetDomNodeHtmlResponse get_dom_node_html(i32 node_id) override; + virtual void get_dom_node_html(i32 node_id) override; virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; virtual Messages::WebContentServer::DumpPaintTreeResponse dump_paint_tree() override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index a78c8bf338..bec98f90b0 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -46,6 +46,7 @@ endpoint WebContentClient did_inspect_accessibility_tree(ByteString accessibility_tree) =| did_get_hovered_node_id(i32 node_id) =| did_finish_editing_dom_node(Optional node_id) =| + did_get_dom_node_html(String html) =| did_change_favicon(Gfx::ShareableBitmap favicon) =| did_request_all_cookies(URL url) => (Vector cookies) diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 045f4448de..1290a9dc96 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -52,7 +52,7 @@ endpoint WebContentServer create_child_text_node(i32 node_id) =| clone_dom_node(i32 node_id) =| remove_dom_node(i32 node_id) =| - get_dom_node_html(i32 node_id) => (Optional html) + get_dom_node_html(i32 node_id) =| take_document_screenshot() => (Gfx::ShareableBitmap data) take_dom_node_screenshot(i32 node_id) => (Gfx::ShareableBitmap data)