mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibDevTools: Automatically set the "from" field for server responses
The "from" field is required in every response. It is the name of the actor sending the message. This patch fills in the "from" field in the Actor base class so that subclasses don't have to.
This commit is contained in:
parent
a7b577126a
commit
4ce10f3bf4
Notes:
github-actions[bot]
2025-03-12 16:49:10 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/4ce10f3bf40 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3904
19 changed files with 19 additions and 76 deletions
|
@ -19,22 +19,23 @@ Actor::Actor(DevToolsServer& devtools, String name)
|
|||
|
||||
Actor::~Actor() = default;
|
||||
|
||||
void Actor::send_message(JsonValue message, Optional<BlockToken> block_token)
|
||||
void Actor::send_message(JsonObject message, Optional<BlockToken> block_token)
|
||||
{
|
||||
if (m_block_responses && !block_token.has_value()) {
|
||||
m_blocked_responses.append(move(message));
|
||||
return;
|
||||
}
|
||||
|
||||
message.set("from"sv, name());
|
||||
|
||||
if (auto& connection = devtools().connection())
|
||||
connection->send_message(message);
|
||||
connection->send_message(move(message));
|
||||
}
|
||||
|
||||
// https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#error-packets
|
||||
void Actor::send_missing_parameter_error(StringView parameter)
|
||||
{
|
||||
JsonObject error;
|
||||
error.set("from"sv, name());
|
||||
error.set("error"sv, "missingParameter"sv);
|
||||
error.set("message"sv, MUST(String::formatted("Missing parameter: '{}'", parameter)));
|
||||
send_message(move(error));
|
||||
|
@ -44,7 +45,6 @@ void Actor::send_missing_parameter_error(StringView parameter)
|
|||
void Actor::send_unrecognized_packet_type_error(StringView type)
|
||||
{
|
||||
JsonObject error;
|
||||
error.set("from"sv, name());
|
||||
error.set("error"sv, "unrecognizedPacketType"sv);
|
||||
error.set("message"sv, MUST(String::formatted("Unrecognized packet type: '{}'", type)));
|
||||
send_message(move(error));
|
||||
|
@ -55,7 +55,6 @@ void Actor::send_unrecognized_packet_type_error(StringView type)
|
|||
void Actor::send_unknown_actor_error(StringView actor)
|
||||
{
|
||||
JsonObject error;
|
||||
error.set("from"sv, name());
|
||||
error.set("error"sv, "unknownActor"sv);
|
||||
error.set("message"sv, MUST(String::formatted("Unknown actor: '{}'", actor)));
|
||||
send_message(move(error));
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
WeakPtr<Actor> m_actor;
|
||||
};
|
||||
|
||||
void send_message(JsonValue, Optional<BlockToken> block_token = {});
|
||||
void send_message(JsonObject, Optional<BlockToken> block_token = {});
|
||||
void send_missing_parameter_error(StringView parameter);
|
||||
void send_unrecognized_packet_type_error(StringView type);
|
||||
void send_unknown_actor_error(StringView actor);
|
||||
|
@ -59,7 +59,7 @@ private:
|
|||
DevToolsServer& m_devtools;
|
||||
String m_name;
|
||||
|
||||
Vector<JsonValue> m_blocked_responses;
|
||||
Vector<JsonObject> m_blocked_responses;
|
||||
bool m_block_responses { false };
|
||||
};
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ CSSPropertiesActor::~CSSPropertiesActor() = default;
|
|||
void CSSPropertiesActor::handle_message(StringView type, JsonObject const&)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getCSSDatabase"sv) {
|
||||
auto css_property_list = devtools().delegate().css_property_list();
|
||||
|
|
|
@ -31,7 +31,6 @@ ConsoleActor::~ConsoleActor() = default;
|
|||
void ConsoleActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "autocomplete"sv) {
|
||||
response.set("matches"sv, JsonArray {});
|
||||
|
@ -81,7 +80,6 @@ void ConsoleActor::handle_message(StringView type, JsonObject const& message)
|
|||
void ConsoleActor::received_console_result(String result_id, String input, JsonValue result, BlockToken block_token)
|
||||
{
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("type"sv, "evaluationResult"_string);
|
||||
message.set("timestamp"sv, AK::UnixDateTime::now().milliseconds_since_epoch());
|
||||
message.set("resultID"sv, move(result_id));
|
||||
|
|
|
@ -48,10 +48,9 @@ void DeviceActor::handle_message(StringView type, JsonObject const&)
|
|||
value.set("arch"sv, arch);
|
||||
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
response.set("value"sv, move(value));
|
||||
|
||||
send_message(move(response));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ FrameActor::~FrameActor()
|
|||
void FrameActor::handle_message(StringView type, JsonObject const&)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "detach"sv) {
|
||||
if (auto tab = m_tab.strong_ref()) {
|
||||
|
@ -88,7 +87,6 @@ void FrameActor::send_frame_update_message()
|
|||
}
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("type"sv, "frameUpdate"sv);
|
||||
message.set("frames"sv, move(frames));
|
||||
send_message(move(message));
|
||||
|
@ -198,7 +196,6 @@ void FrameActor::console_messages_received(i32 start_index, Vector<WebView::Cons
|
|||
array.must_append(move(console_message));
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("type"sv, "resources-available-array"sv);
|
||||
message.set("array"sv, move(array));
|
||||
send_message(move(message));
|
||||
|
|
|
@ -30,7 +30,6 @@ HighlighterActor::~HighlighterActor() = default;
|
|||
void HighlighterActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "show"sv) {
|
||||
auto node = message.get_string("node"sv);
|
||||
|
|
|
@ -32,7 +32,6 @@ InspectorActor::~InspectorActor() = default;
|
|||
void InspectorActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getPageStyle"sv) {
|
||||
if (!m_page_style)
|
||||
|
@ -101,7 +100,6 @@ void InspectorActor::received_dom_tree(JsonObject dom_tree, BlockToken block_tok
|
|||
walker.set("root"sv, walker_actor.serialize_root());
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("walker"sv, move(walker));
|
||||
send_message(move(message), move(block_token));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ LayoutInspectorActor::~LayoutInspectorActor() = default;
|
|||
void LayoutInspectorActor::handle_message(StringView type, JsonObject const&)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getCurrentFlexbox"sv) {
|
||||
response.set("flexbox"sv, JsonValue {});
|
||||
|
|
|
@ -96,7 +96,6 @@ NodeActor::~NodeActor() = default;
|
|||
void NodeActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getUniqueSelector"sv) {
|
||||
auto dom_node = WalkerActor::dom_node_for(m_walker, name());
|
||||
|
@ -136,7 +135,7 @@ void NodeActor::handle_message(StringView type, JsonObject const& message)
|
|||
}
|
||||
|
||||
if (auto self = weak_self.strong_ref())
|
||||
self->finished_editing_dom_node(move(block_token));
|
||||
self->send_message({}, move(block_token));
|
||||
};
|
||||
|
||||
if (attribute_to_replace.has_value()) {
|
||||
|
@ -172,7 +171,7 @@ void NodeActor::handle_message(StringView type, JsonObject const& message)
|
|||
}
|
||||
|
||||
if (auto self = weak_self.strong_ref())
|
||||
self->finished_editing_dom_node(move(block_token));
|
||||
self->send_message({}, move(block_token));
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -181,11 +180,4 @@ void NodeActor::handle_message(StringView type, JsonObject const& message)
|
|||
send_unrecognized_packet_type_error(type);
|
||||
}
|
||||
|
||||
void NodeActor::finished_editing_dom_node(BlockToken block_token)
|
||||
{
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
send_message(move(message), move(block_token));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ public:
|
|||
private:
|
||||
NodeActor(DevToolsServer&, String name, NodeIdentifier, WeakPtr<WalkerActor>);
|
||||
|
||||
void finished_editing_dom_node(BlockToken);
|
||||
|
||||
NodeIdentifier m_node_identifier;
|
||||
|
||||
WeakPtr<WalkerActor> m_walker;
|
||||
|
|
|
@ -31,7 +31,6 @@ PageStyleActor::~PageStyleActor() = default;
|
|||
void PageStyleActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getApplied"sv) {
|
||||
// FIXME: This provides information to the "styles" pane in the inspector tab, which allows toggling and editing
|
||||
|
@ -119,7 +118,6 @@ void PageStyleActor::inspect_dom_node(StringView node_actor, Callback&& callback
|
|||
void PageStyleActor::received_layout(JsonObject const& computed_style, JsonObject const& node_box_sizing, BlockToken block_token)
|
||||
{
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("autoMargins"sv, JsonObject {});
|
||||
|
||||
auto pixel_value = [&](auto const& object, auto key) {
|
||||
|
@ -175,7 +173,6 @@ void PageStyleActor::received_computed_style(JsonObject const& computed_style, B
|
|||
});
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("computed"sv, move(computed));
|
||||
send_message(move(message), move(block_token));
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ void PreferenceActor::handle_message(StringView type, JsonObject const&)
|
|||
// We just blindly return `false` for these, but we will eventually want a real configuration manager.
|
||||
if (type == "getBoolPref"sv) {
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
response.set("value"sv, false);
|
||||
send_message(move(response));
|
||||
return;
|
||||
|
|
|
@ -27,7 +27,6 @@ NonnullRefPtr<RootActor> RootActor::create(DevToolsServer& devtools, String name
|
|||
traits.set("networkMonitor"sv, false);
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, actor->name());
|
||||
message.set("applicationType"sv, "browser"sv);
|
||||
message.set("traits"sv, move(traits));
|
||||
actor->send_message(move(message));
|
||||
|
@ -45,7 +44,6 @@ RootActor::~RootActor() = default;
|
|||
void RootActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "connect") {
|
||||
send_message(move(response));
|
||||
|
@ -165,7 +163,6 @@ void RootActor::send_tab_list_changed_message()
|
|||
return;
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("type"sv, "tabListChanged"sv);
|
||||
send_message(move(message));
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ TabActor::~TabActor()
|
|||
void TabActor::handle_message(StringView type, JsonObject const&)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getFavicon"sv) {
|
||||
// FIXME: Firefox DevTools wants a favicon URL here, but supplying a URL seems to prevent this tab from being
|
||||
|
|
|
@ -25,7 +25,6 @@ TargetConfigurationActor::~TargetConfigurationActor() = default;
|
|||
void TargetConfigurationActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "updateConfiguration"sv) {
|
||||
auto configuration = message.get_object("configuration"sv);
|
||||
|
|
|
@ -25,7 +25,6 @@ ThreadConfigurationActor::~ThreadConfigurationActor() = default;
|
|||
void ThreadConfigurationActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "updateConfiguration"sv) {
|
||||
auto configuration = message.get_object("configuration"sv);
|
||||
|
|
|
@ -46,7 +46,6 @@ WalkerActor::~WalkerActor()
|
|||
void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "children"sv) {
|
||||
auto node = message.get_string("node"sv);
|
||||
|
@ -99,11 +98,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
return;
|
||||
}
|
||||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
if (auto self = weak_self.strong_ref())
|
||||
self->send_message({}, move(block_token));
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -138,11 +134,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
return;
|
||||
}
|
||||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
if (auto self = weak_self.strong_ref())
|
||||
self->send_message({}, move(block_token));
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -199,7 +192,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
message.set("value"sv, html.release_value());
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
|
@ -243,7 +235,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
}
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
message.set("newParents"sv, JsonArray {});
|
||||
message.set("nodes"sv, move(nodes));
|
||||
self->send_message(move(message), move(block_token));
|
||||
|
@ -299,11 +290,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
return;
|
||||
}
|
||||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
if (auto self = weak_self.strong_ref())
|
||||
self->send_message({}, move(block_token));
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -346,7 +334,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
message.set("value"sv, html.release_value());
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
|
@ -445,7 +432,6 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
message.set("nextSibling"sv, move(next_sibling));
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
|
@ -488,11 +474,8 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
return;
|
||||
}
|
||||
|
||||
if (auto self = weak_self.strong_ref()) {
|
||||
JsonObject message;
|
||||
message.set("from"sv, self->name());
|
||||
self->send_message(move(message), move(block_token));
|
||||
}
|
||||
if (auto self = weak_self.strong_ref())
|
||||
self->send_message({}, move(block_token));
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -503,10 +486,7 @@ void WalkerActor::handle_message(StringView type, JsonObject const& message)
|
|||
response.set("node"sv, serialize_root());
|
||||
send_message(move(response));
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
send_message(move(message));
|
||||
|
||||
send_message({});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -772,7 +752,6 @@ void WalkerActor::new_dom_node_mutation(WebView::Mutation mutation)
|
|||
return;
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
message.set("type"sv, "newMutations"sv);
|
||||
send_message(move(message));
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ WatcherActor::~WatcherActor() = default;
|
|||
void WatcherActor::handle_message(StringView type, JsonObject const& message)
|
||||
{
|
||||
JsonObject response;
|
||||
response.set("from"sv, name());
|
||||
|
||||
if (type == "getParentBrowsingContextID"sv) {
|
||||
auto browsing_context_id = message.get_integer<u64>("browsingContextID"sv);
|
||||
|
@ -110,10 +109,7 @@ void WatcherActor::handle_message(StringView type, JsonObject const& message)
|
|||
|
||||
target.send_frame_update_message();
|
||||
|
||||
JsonObject message;
|
||||
message.set("from"sv, name());
|
||||
send_message(move(message));
|
||||
|
||||
send_message({});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue