mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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.  Fixes: part of https://github.com/servo/servo/issues/36027 --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
parent
5159529888
commit
7a801f0ef5
8 changed files with 204 additions and 42 deletions
|
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue