diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 8beef56bbe5..8e8a71ba499 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -201,6 +201,11 @@ void ViewImplementation::replace_dom_node_attribute(i32 node_id, String name, Ve client().async_replace_dom_node_attribute(node_id, move(name), move(replacement_attributes)); } +void ViewImplementation::remove_dom_node(i32 node_id) +{ + client().async_remove_dom_node(node_id); +} + void ViewImplementation::debug_request(DeprecatedString const& request, DeprecatedString const& argument) { client().async_debug_request(request, argument); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 90ddfbb09c4..aa3cd19082d 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -67,6 +67,7 @@ public: Optional set_dom_node_tag(i32 node_id, String name); void add_dom_node_attributes(i32 node_id, Vector attributes); void replace_dom_node_attribute(i32 node_id, String name, Vector replacement_attributes); + void remove_dom_node(i32 node_id); void debug_request(DeprecatedString const& request, DeprecatedString const& argument = {}); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index d0f205c7f5a..0e142e8bf1b 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -711,6 +711,24 @@ void ConnectionFromClient::replace_dom_node_attribute(i32 node_id, String const& element.set_attribute(attribute.name, attribute.value).release_value_but_fixme_should_propagate_errors(); } +void ConnectionFromClient::remove_dom_node(i32 node_id) +{ + auto* active_document = page().page().top_level_browsing_context().active_document(); + if (!active_document) + return; + + auto* dom_node = Web::DOM::Node::from_unique_id(node_id); + if (!dom_node) + return; + + dom_node->remove(); + + // FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still + // remain in the layout tree. This has to be fixed, this just causes everything to be recomputed + // which really hurts performance. + active_document->force_layout(); +} + void ConnectionFromClient::initialize_js_console(Badge, Web::DOM::Document& document) { auto& realm = document.realm(); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index 906bb9c89c4..e74fdaeae04 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -80,6 +80,7 @@ private: virtual Messages::WebContentServer::SetDomNodeTagResponse set_dom_node_tag(i32 node_id, String const& name) override; virtual void add_dom_node_attributes(i32 node_id, Vector const& attributes) override; virtual void replace_dom_node_attribute(i32 node_id, String const& name, Vector const& replacement_attributes) override; + virtual void remove_dom_node(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/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 28faeae0b00..3ef342dc482 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -50,6 +50,7 @@ endpoint WebContentServer set_dom_node_tag(i32 node_id, String name) => (Optional node_id) add_dom_node_attributes(i32 node_id, Vector attributes) =| replace_dom_node_attribute(i32 node_id, String name, Vector replacement_attributes) =| + remove_dom_node(i32 node_id) =| take_document_screenshot() => (Gfx::ShareableBitmap data)