mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
There is a lot needed all at once to actually inspect a tab's DOM tree. It begins with requesting a "watcher" from a TabActor. It seems there can be many types of watchers, but here we implement the "frame" watcher only. The watcher creates an "inspector", which in turn creates a "walker", which is the actor ultimately responsible for serializing and inspecting the DOM tree. In between all that, the DevTools client will send a handful of other informational requests. If we do not reply to these, the client will not move forward with the walker. For example, the CSSPropertiesActor will be asked for a list of all known CSS properties.
46 lines
1.3 KiB
C++
46 lines
1.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>
|
|
|
|
namespace DevTools {
|
|
|
|
class WalkerActor final : public Actor {
|
|
public:
|
|
static constexpr auto base_name = "walker"sv;
|
|
|
|
static NonnullRefPtr<WalkerActor> create(DevToolsServer&, ByteString name, WeakPtr<TabActor>, JsonObject dom_tree);
|
|
virtual ~WalkerActor() override;
|
|
|
|
virtual void handle_message(StringView type, JsonObject const&) override;
|
|
|
|
static bool is_suitable_for_dom_inspection(JsonValue const&);
|
|
JsonValue serialize_root() const;
|
|
|
|
private:
|
|
WalkerActor(DevToolsServer&, ByteString name, WeakPtr<TabActor>, JsonObject dom_tree);
|
|
|
|
JsonValue serialize_node(JsonObject const&) const;
|
|
Optional<JsonObject const&> find_node_by_selector(JsonObject const& node, StringView selector);
|
|
|
|
void populate_dom_tree_cache(JsonObject& node, JsonObject const* parent = nullptr);
|
|
|
|
WeakPtr<TabActor> m_tab;
|
|
JsonObject m_dom_tree;
|
|
|
|
HashMap<JsonObject const*, JsonObject const*> m_dom_node_to_parent_map;
|
|
HashMap<ByteString, JsonObject const*> m_actor_to_dom_node_map;
|
|
size_t m_dom_node_count { 0 };
|
|
};
|
|
|
|
}
|