mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-31 15:32:51 +00:00
The NodeIdentifier struct essentially contains the DOM node ID within its WebContent process. These will repeat across multiple processes, thus we cannot use them to search for node actors in the global actor registry. Instead, we can store a map of all node actors created by the walker itself. The NodeIdentifier is then appropriate for actor lookups on that map. This has the added benefit of not needing to search the entire actor registry many times while forming the DOM node caches. This fix allows us to inspect multiple tabs at once.
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <AK/JsonObject.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/Optional.h>
|
|
#include <LibDevTools/Actor.h>
|
|
#include <LibDevTools/Actors/NodeActor.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWebView/Forward.h>
|
|
|
|
namespace DevTools {
|
|
|
|
class WalkerActor final : public Actor {
|
|
public:
|
|
static constexpr auto base_name = "walker"sv;
|
|
|
|
static NonnullRefPtr<WalkerActor> create(DevToolsServer&, String name, WeakPtr<TabActor>, JsonObject dom_tree);
|
|
virtual ~WalkerActor() override;
|
|
|
|
static bool is_suitable_for_dom_inspection(JsonValue const&);
|
|
JsonValue serialize_root() const;
|
|
|
|
struct DOMNode {
|
|
JsonObject const& node;
|
|
NodeIdentifier identifier;
|
|
NonnullRefPtr<TabActor> tab;
|
|
};
|
|
static Optional<DOMNode> dom_node_for(WeakPtr<WalkerActor> const&, StringView actor);
|
|
Optional<DOMNode> dom_node(StringView actor);
|
|
|
|
private:
|
|
WalkerActor(DevToolsServer&, String name, WeakPtr<TabActor>, JsonObject dom_tree);
|
|
|
|
virtual void handle_message(Message const&) override;
|
|
|
|
JsonValue serialize_node(JsonObject const&) const;
|
|
Optional<JsonObject const&> find_node_by_selector(JsonObject const& node, StringView selector);
|
|
|
|
Optional<JsonObject const&> previous_sibling_for_node(JsonObject const& node);
|
|
Optional<JsonObject const&> next_sibling_for_node(JsonObject const& node);
|
|
Optional<JsonObject const&> remove_node(JsonObject const& node);
|
|
|
|
void new_dom_node_mutation(WebView::Mutation);
|
|
JsonValue serialize_mutations();
|
|
|
|
bool replace_node_in_tree(JsonObject replacement);
|
|
|
|
void populate_dom_tree_cache();
|
|
void populate_dom_tree_cache(JsonObject& node, JsonObject const* parent);
|
|
|
|
NodeActor const& actor_for_node(JsonObject const& node);
|
|
|
|
WeakPtr<TabActor> m_tab;
|
|
WeakPtr<LayoutInspectorActor> m_layout_inspector;
|
|
|
|
JsonObject m_dom_tree;
|
|
|
|
Vector<WebView::Mutation> m_dom_node_mutations;
|
|
bool m_has_new_mutations_since_last_mutations_request { false };
|
|
|
|
HashMap<JsonObject const*, JsonObject const*> m_dom_node_to_parent_map;
|
|
HashMap<String, JsonObject const*> m_actor_to_dom_node_map;
|
|
HashMap<Web::UniqueNodeID, String> m_dom_node_id_to_actor_map;
|
|
|
|
HashMap<NodeIdentifier, WeakPtr<NodeActor>> m_node_actors;
|
|
};
|
|
|
|
}
|