LibDevTools: Introduce a Firefox DevTools server library

To aid with debugging web page issues in Ladybird without needing to
implement a fully fledged inspector, we can implement the Firefox
DevTools protocol and use their DevTools. The protocol is described
here:

https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html

This commit contains just enough to connect to Ladybird from a DevTools
client.
This commit is contained in:
Timothy Flynn 2025-02-15 07:35:58 -05:00 committed by Tim Flynn
commit 58bc44ba2a
Notes: github-actions[bot] 2025-02-19 13:47:24 +00:00
20 changed files with 947 additions and 0 deletions

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Badge.h>
#include <AK/ByteString.h>
#include <AK/Optional.h>
#include <AK/RefCounted.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <AK/WeakPtr.h>
#include <AK/Weakable.h>
#include <LibDevTools/Forward.h>
namespace DevTools {
class Actor
: public RefCounted<Actor>
, public Weakable<Actor> {
public:
virtual ~Actor();
ByteString const& name() const { return m_name; }
virtual void handle_message(StringView type, JsonObject const&) = 0;
class [[nodiscard]] BlockToken {
public:
BlockToken(Badge<Actor>, Actor&);
~BlockToken();
BlockToken(BlockToken const&) = delete;
BlockToken& operator=(BlockToken const&) = delete;
BlockToken(BlockToken&&);
BlockToken& operator=(BlockToken&&);
private:
WeakPtr<Actor> m_actor;
};
void send_message(JsonValue, 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);
protected:
explicit Actor(DevToolsServer&, ByteString name);
DevToolsServer& devtools() { return m_devtools; }
DevToolsServer const& devtools() const { return m_devtools; }
BlockToken block_responses();
private:
DevToolsServer& m_devtools;
ByteString m_name;
Vector<JsonValue> m_blocked_responses;
bool m_block_responses { false };
};
}