mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 08:10:02 +00:00
LibDevTools: Implement a real actor for DOM nodes
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.
This commit is contained in:
parent
6e8d77ff7f
commit
c56bf8ac93
Notes:
github-actions[bot]
2025-02-24 17:06:54 +00:00
Author: https://github.com/trflynn89
Commit: c56bf8ac93
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3666
Reviewed-by: https://github.com/AtkinsSJ
7 changed files with 83 additions and 6 deletions
44
Libraries/LibDevTools/Actors/NodeActor.cpp
Normal file
44
Libraries/LibDevTools/Actors/NodeActor.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue