1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibWebView+WebContent: Make the DOM node HTML retrieval IPC async

This commit is contained in:
Timothy Flynn 2023-12-30 14:32:50 -05:00 committed by Andreas Kling
parent c190294a76
commit 93db790974
9 changed files with 24 additions and 13 deletions

View file

@ -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();
}

View file

@ -191,9 +191,9 @@ void ViewImplementation::remove_dom_node(i32 node_id)
client().async_remove_dom_node(node_id);
}
Optional<String> 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)

View file

@ -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<String> 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<void(ByteString const&)> on_received_accessibility_tree;
Function<void(i32 node_id)> on_received_hovered_node_id;
Function<void(Optional<i32> const& node_id)> on_finshed_editing_dom_node;
Function<void(String const&)> on_received_dom_node_html;
Function<void(i32 message_id)> on_received_console_message;
Function<void(i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages)> on_received_console_messages;
Function<Vector<Web::Cookie::Cookie>(AK::URL const& url)> on_get_all_cookies;

View file

@ -225,6 +225,12 @@ void WebContentClient::did_finish_editing_dom_node(Optional<i32> 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)

View file

@ -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<i32> 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<ByteString> const& message_types, Vector<ByteString> const& messages) override;
virtual void did_change_favicon(Gfx::ShareableBitmap const&) override;

View file

@ -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<PageClient>, Web::DOM::Document& document)

View file

@ -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;

View file

@ -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<i32> node_id) =|
did_get_dom_node_html(String html) =|
did_change_favicon(Gfx::ShareableBitmap favicon) =|
did_request_all_cookies(URL url) => (Vector<Web::Cookie::Cookie> cookies)

View file

@ -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<String> html)
get_dom_node_html(i32 node_id) =|
take_document_screenshot() => (Gfx::ShareableBitmap data)
take_dom_node_screenshot(i32 node_id) => (Gfx::ShareableBitmap data)