ladybird/Libraries/LibDevTools/Actors/NodeActor.h
Timothy Flynn 80d7350ee5 LibDevTools: Ensure the walker actor only displays nodes it created
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.
2025-03-14 09:04:03 +01:00

61 lines
1.7 KiB
C++

/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashFunctions.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Traits.h>
#include <LibDevTools/Actor.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/Forward.h>
namespace DevTools {
struct NodeIdentifier {
static NodeIdentifier for_node(JsonObject const& node);
bool operator==(NodeIdentifier const&) const = default;
Web::UniqueNodeID id { 0 };
Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element;
};
class NodeActor final : public Actor {
public:
static constexpr auto base_name = "node"sv;
static NonnullRefPtr<NodeActor> create(DevToolsServer&, String name, NodeIdentifier, WeakPtr<WalkerActor>);
virtual ~NodeActor() override;
NodeIdentifier const& node_identifier() const { return m_node_identifier; }
WeakPtr<WalkerActor> const& walker() const { return m_walker; }
private:
NodeActor(DevToolsServer&, String name, NodeIdentifier, WeakPtr<WalkerActor>);
virtual void handle_message(Message const&) override;
NodeIdentifier m_node_identifier;
WeakPtr<WalkerActor> m_walker;
};
}
template<>
struct AK::Traits<DevTools::NodeIdentifier> : public AK::DefaultTraits<DevTools::NodeIdentifier> {
static bool equals(DevTools::NodeIdentifier const& lhs, DevTools::NodeIdentifier const& rhs)
{
return lhs == rhs;
}
static unsigned hash(DevTools::NodeIdentifier const& node_identifier)
{
auto pseudo_element = node_identifier.pseudo_element.value_or(Web::CSS::Selector::PseudoElement::Type::KnownPseudoElementCount);
return pair_int_hash(node_identifier.id.value(), to_underlying(pseudo_element));
}
};