DevTools: Implement support for showing source_content in Debugger > Source panel (#36774)

This patch adds support for showing source_content in `Debugger >
Source` panel. This works by handling the clients `source` messages in
the source actor. These source actors are already advertised as resource
via the watcher, populating the source list. We also update the
`sources` handler in thread actor for future work in thread debugging.

Note: while this PR also adds support for showing worker script
source_content, worker has been broken (See
https://github.com/servo/servo/issues/37012). I was able to confirm the
`content_type` and `source_content` for worker script in logs.


![image](https://github.com/user-attachments/assets/bd53ea29-003a-4b5e-a3e8-6e280afa4671)

Fixes: part of https://github.com/servo/servo/issues/36027

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
atbrakhi 2025-06-13 11:31:33 +02:00 committed by GitHub
parent 5159529888
commit 7a801f0ef5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 204 additions and 42 deletions

View file

@ -4,10 +4,16 @@
use std::cell::{Ref, RefCell};
use std::collections::BTreeSet;
use std::net::TcpStream;
use serde::Serialize;
use serde_json::{Map, Value};
use servo_url::ServoUrl;
use crate::StreamId;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream;
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct SourceData {
@ -15,6 +21,7 @@ pub(crate) struct SourceData {
/// URL of the script, or URL of the page for inline scripts.
pub url: String,
pub is_black_boxed: bool,
pub source_content: String,
}
#[derive(Serialize)]
@ -23,24 +30,38 @@ pub(crate) struct SourcesReply {
pub sources: Vec<SourceData>,
}
pub(crate) struct Source {
actor_name: String,
source_urls: RefCell<BTreeSet<SourceData>>,
pub(crate) struct SourceManager {
pub source_urls: RefCell<BTreeSet<SourceData>>,
}
impl Source {
pub fn new(actor_name: String) -> Self {
#[derive(Clone, Debug)]
pub struct SourceActor {
pub name: String,
pub content: String,
pub content_type: String,
}
#[derive(Serialize)]
struct SourceContentReply {
from: String,
#[serde(rename = "contentType")]
content_type: String,
source: String,
}
impl SourceManager {
pub fn new() -> Self {
Self {
actor_name,
source_urls: RefCell::new(BTreeSet::default()),
}
}
pub fn add_source(&self, url: ServoUrl) {
pub fn add_source(&self, url: ServoUrl, source_content: String, actor_name: String) {
self.source_urls.borrow_mut().insert(SourceData {
actor: self.actor_name.clone(),
actor: actor_name,
url: url.to_string(),
is_black_boxed: false,
source_content,
});
}
@ -48,3 +69,51 @@ impl Source {
self.source_urls.borrow()
}
}
impl SourceActor {
pub fn new(name: String, content: String, content_type: String) -> SourceActor {
SourceActor {
name,
content,
content_type,
}
}
pub fn new_source(actors: &mut ActorRegistry, content: String, content_type: String) -> String {
let source_actor_name = actors.new_name("source");
let source_actor = SourceActor::new(source_actor_name.clone(), content, content_type);
actors.register(Box::new(source_actor));
source_actor_name
}
}
impl Actor for SourceActor {
fn name(&self) -> String {
self.name.clone()
}
fn handle_message(
&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
_id: StreamId,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
// Client has requested contents of the source.
"source" => {
let reply = SourceContentReply {
from: self.name(),
content_type: self.content_type.clone(),
source: self.content.clone(),
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
_ => ActorMessageStatus::Ignored,
})
}
}