mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-13 12:31:51 +00:00
The DevTools client will now send requests to the node actor, rather than just sending messages to other actors on the node's behalf. This exposed a slight issue in the way we assign actor IDs. Node actors are created in the walker actor constructor, which executes before the actor ID is incremented. So we must be sure to increment the actor ID before invoking any actor constructors. Otherwise, the walker actor and the first node actor have the same numeric ID.
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/JsonObject.h>
|
|
#include <LibDevTools/Actors/NodeActor.h>
|
|
#include <LibDevTools/Actors/WalkerActor.h>
|
|
|
|
namespace DevTools {
|
|
|
|
NonnullRefPtr<NodeActor> NodeActor::create(DevToolsServer& devtools, String name, WeakPtr<WalkerActor> walker)
|
|
{
|
|
return adopt_ref(*new NodeActor(devtools, move(name), move(walker)));
|
|
}
|
|
|
|
NodeActor::NodeActor(DevToolsServer& devtools, String name, WeakPtr<WalkerActor> walker)
|
|
: Actor(devtools, move(name))
|
|
, m_walker(move(walker))
|
|
{
|
|
}
|
|
|
|
NodeActor::~NodeActor() = default;
|
|
|
|
void NodeActor::handle_message(StringView type, JsonObject const&)
|
|
{
|
|
JsonObject response;
|
|
response.set("from"sv, name());
|
|
|
|
if (type == "getUniqueSelector"sv) {
|
|
if (auto walker = m_walker.strong_ref()) {
|
|
if (auto const& dom_node = walker->dom_node(name()); dom_node.has_value())
|
|
response.set("value"sv, dom_node->node.get_string("name"sv)->to_ascii_lowercase());
|
|
}
|
|
|
|
send_message(move(response));
|
|
return;
|
|
}
|
|
|
|
send_unrecognized_packet_type_error(type);
|
|
}
|
|
|
|
}
|