1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:37:35 +00:00

LibWeb: Add JSON serialization for nested browsing contexts

This changes allows for nested browser contexts to be embedded in the
serialized JSON of their container element (like `iframe`) and enables
their inspection in the DOM Inspector.
This commit is contained in:
Vyacheslav Pukhanov 2021-11-24 19:15:04 +03:00 committed by Andreas Kling
parent 58397f356f
commit 3f006d81fe
4 changed files with 21 additions and 1 deletions

View file

@ -24,6 +24,7 @@
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ProcessingInstruction.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/BrowsingContextContainer.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
@ -702,13 +703,22 @@ void Node::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) c
} else if (is_element()) {
object.add("type", "element");
auto element = static_cast<DOM::Element const*>(this);
auto const* element = static_cast<DOM::Element const*>(this);
if (element->has_attributes()) {
auto attributes = object.add_object("attributes");
element->for_each_attribute([&attributes](auto& name, auto& value) {
attributes.add(name, value);
});
}
if (element->is_browsing_context_container()) {
auto const* container = static_cast<HTML::BrowsingContextContainer const*>(element);
if (auto const* content_document = container->content_document()) {
auto children = object.add_array("children");
JsonObjectSerializer<StringBuilder> content_document_object = children.add_object();
content_document->serialize_tree_as_json(content_document_object);
}
}
} else if (is_text()) {
object.add("type", "text");