diff options
author | Vyacheslav Pukhanov <vyacheslav@pukhanov.ru> | 2021-11-24 19:15:04 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-24 19:07:48 +0100 |
commit | 3f006d81feacbdf088f554087ad4705712f8e871 (patch) | |
tree | 9f4257340057b8f8fee99553332d2ab66b185ba3 /Userland/Libraries/LibWeb/DOM/Node.cpp | |
parent | 58397f356f6a4359d5aefe6a5dcd618abd23cd77 (diff) | |
download | serenity-3f006d81feacbdf088f554087ad4705712f8e871.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Node.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 52c2213303..2b8b2b88eb 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -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"); |