Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Libraries/LibDevTools/Actors/DeviceActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DeviceActor::handle_message(Message const& message)
value.set("version"sv, browser_version);
value.set("appbuildid"sv, build_id);
value.set("platformbuildid"sv, build_id);
value.set("platformversion"sv, "139.0"sv);
value.set("platformversion"sv, "152.0"sv);
value.set("useragent"sv, Web::default_user_agent);
value.set("os"sv, platform_name);
value.set("arch"sv, arch);
Expand Down
28 changes: 21 additions & 7 deletions Libraries/LibDevTools/Actors/RootActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,31 @@ void RootActor::handle_message(Message const& message)
if (!browser_id.has_value())
return;

TabActor const* tab_actor = nullptr;

for (auto const& actor : devtools().actor_registry()) {
auto const* tab_actor = as_if<TabActor>(*actor.value);
if (!tab_actor)
continue;
if (tab_actor->description().id != *browser_id)
continue;
auto const* candidate = as_if<TabActor>(*actor.value);

response.set("tab"sv, tab_actor->serialize_description());
break;
if (candidate && candidate->description().id == *browser_id) {
tab_actor = candidate;
break;
}
}

// The tab might not have been registered yet if the client did not request the tab list on this connection,
// e.g. when a toolbox connects directly to a tab known from a previous connection.
if (!tab_actor) {
for (auto& tab_description : devtools().delegate().tab_list()) {
if (tab_description.id == *browser_id) {
tab_actor = &devtools().register_actor<TabActor>(move(tab_description));
break;
}
}
}

if (tab_actor)
response.set("tab"sv, tab_actor->serialize_description());

send_response(message, move(response));
return;
}
Expand Down
3 changes: 2 additions & 1 deletion Libraries/LibDevTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ set(SOURCES
Actors/WatcherActor.cpp
Connection.cpp
DevToolsServer.cpp
FirefoxClient.cpp
IndexedDBSerialization.cpp
StorageHelpers.cpp
)

ladybird_lib(LibDevTools devtools EXPLICIT_SYMBOL_EXPORT)
target_link_libraries(LibDevTools PRIVATE LibCore LibHTTP LibWeb LibURL)
target_link_libraries(LibDevTools PRIVATE LibCore LibFileSystem LibHTTP LibWeb LibURL)
1 change: 1 addition & 0 deletions Libraries/LibDevTools/DevToolsDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class DEVTOOLS_API DevToolsDelegate {

virtual void did_connect_devtools_client(TabDescription const&) const { }
virtual void did_disconnect_devtools_client(TabDescription const&) const { }
virtual void did_close_devtools_connection() { }
};

}
8 changes: 7 additions & 1 deletion Libraries/LibDevTools/DevToolsServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <LibDevTools/Actors/ProcessActor.h>
#include <LibDevTools/Actors/TabActor.h>
#include <LibDevTools/Connection.h>
#include <LibDevTools/DevToolsDelegate.h>
#include <LibDevTools/DevToolsServer.h>

namespace DevTools {
Expand Down Expand Up @@ -87,10 +88,13 @@ void DevToolsServer::unregister_actor(String const& name)

ErrorOr<void> DevToolsServer::on_new_client()
{
// The client must be accepted even when one is already active; a pending connection left in the listen backlog
// would cause the accept notifier to fire in a busy loop.
auto client = TRY(m_server->accept());

if (m_connection)
return Error::from_string_literal("Only one active DevTools connection is currently allowed");

auto client = TRY(m_server->accept());
auto buffered_socket = TRY(Core::BufferedTCPSocket::create(move(client)));

m_connection = Connection::create(move(buffered_socket));
Expand Down Expand Up @@ -152,6 +156,8 @@ void DevToolsServer::close_connection()
weak_self->m_connection = nullptr;
weak_self->m_actor_registry.clear();
weak_self->m_root_actor = nullptr;

weak_self->m_delegate.did_close_devtools_connection();
});
}

Expand Down
1 change: 1 addition & 0 deletions Libraries/LibDevTools/DevToolsServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DEVTOOLS_API DevToolsServer : public Weakable<DevToolsServer> {
~DevToolsServer();

RefPtr<Connection>& connection() { return m_connection; }
bool has_active_connection() const { return m_connection; }
DevToolsDelegate const& delegate() const { return m_delegate; }
ActorRegistry const& actor_registry() const { return m_actor_registry; }
Optional<u16> local_port() const;
Expand Down
Loading