mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
DevTools: Move Source
related code to dedicated source.rs
file (#36667)
Currently Source related code exists in watcher.rs and thread.rs. This change moves source-related code to a dedicated source.rs file. This is in preparation for adding support for showing source code in the Debugger > Source panel. - [x] Testing: These changes should not affect current functionality as it only moves the existing code - [x] Fixes: part of https://github.com/servo/servo/issues/36027 --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
parent
d661d4a620
commit
c16d86f7a4
4 changed files with 62 additions and 38 deletions
50
components/devtools/actors/source.rs
Normal file
50
components/devtools/actors/source.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use serde::Serialize;
|
||||
use servo_url::ServoUrl;
|
||||
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct SourceData {
|
||||
pub actor: String,
|
||||
/// URL of the script, or URL of the page for inline scripts.
|
||||
pub url: String,
|
||||
pub is_black_boxed: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub(crate) struct SourcesReply {
|
||||
pub from: String,
|
||||
pub sources: Vec<SourceData>,
|
||||
}
|
||||
|
||||
pub(crate) struct Source {
|
||||
actor_name: String,
|
||||
source_urls: RefCell<BTreeSet<SourceData>>,
|
||||
}
|
||||
|
||||
impl Source {
|
||||
pub fn new(actor_name: String) -> Self {
|
||||
Self {
|
||||
actor_name,
|
||||
source_urls: RefCell::new(BTreeSet::default()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_source(&self, url: ServoUrl) {
|
||||
self.source_urls.borrow_mut().insert(SourceData {
|
||||
actor: self.actor_name.clone(),
|
||||
url: url.to_string(),
|
||||
is_black_boxed: false,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn sources(&self) -> Ref<BTreeSet<SourceData>> {
|
||||
self.source_urls.borrow()
|
||||
}
|
||||
}
|
|
@ -2,14 +2,12 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
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 super::source::{Source, SourcesReply};
|
||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||
use crate::protocol::JsonPacketStream;
|
||||
use crate::{EmptyReplyMsg, StreamId};
|
||||
|
@ -52,45 +50,18 @@ struct ThreadInterruptedReply {
|
|||
type_: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct SourcesReply {
|
||||
from: String,
|
||||
sources: Vec<Source>,
|
||||
}
|
||||
|
||||
#[derive(Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Source {
|
||||
pub actor: String,
|
||||
/// URL of the script, or URL of the page for inline scripts.
|
||||
pub url: String,
|
||||
pub is_black_boxed: bool,
|
||||
}
|
||||
|
||||
pub struct ThreadActor {
|
||||
name: String,
|
||||
source_urls: RefCell<BTreeSet<Source>>,
|
||||
pub name: String,
|
||||
pub source_manager: Source,
|
||||
}
|
||||
|
||||
impl ThreadActor {
|
||||
pub fn new(name: String) -> ThreadActor {
|
||||
ThreadActor {
|
||||
name,
|
||||
source_urls: RefCell::new(BTreeSet::default()),
|
||||
name: name.clone(),
|
||||
source_manager: Source::new(name),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_source(&self, url: ServoUrl) {
|
||||
self.source_urls.borrow_mut().insert(Source {
|
||||
actor: self.name.clone(),
|
||||
url: url.to_string(),
|
||||
is_black_boxed: false,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn sources(&self) -> Ref<BTreeSet<Source>> {
|
||||
self.source_urls.borrow()
|
||||
}
|
||||
}
|
||||
|
||||
impl Actor for ThreadActor {
|
||||
|
|
|
@ -265,7 +265,7 @@ impl Actor for WatcherActor {
|
|||
},
|
||||
"source" => {
|
||||
let thread_actor = registry.find::<ThreadActor>(&target.thread);
|
||||
let sources = thread_actor.sources();
|
||||
let sources = thread_actor.source_manager.sources();
|
||||
target.resources_available(sources.iter().collect(), "source".into());
|
||||
},
|
||||
"console-message" | "error-message" => {},
|
||||
|
|
|
@ -19,7 +19,7 @@ use std::net::{Shutdown, TcpListener, TcpStream};
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
|
||||
use actors::thread::Source;
|
||||
use actors::source::SourceData;
|
||||
use base::id::{BrowsingContextId, PipelineId, WebViewId};
|
||||
use crossbeam_channel::{Receiver, Sender, unbounded};
|
||||
use devtools_traits::{
|
||||
|
@ -66,6 +66,7 @@ mod actors {
|
|||
pub mod process;
|
||||
pub mod reflow;
|
||||
pub mod root;
|
||||
pub mod source;
|
||||
pub mod stylesheets;
|
||||
pub mod tab;
|
||||
pub mod thread;
|
||||
|
@ -525,9 +526,11 @@ impl DevtoolsInstance {
|
|||
.clone();
|
||||
|
||||
let thread_actor = actors.find_mut::<ThreadActor>(&thread_actor_name);
|
||||
thread_actor.add_source(source_info.url.clone());
|
||||
thread_actor
|
||||
.source_manager
|
||||
.add_source(source_info.url.clone());
|
||||
|
||||
let source = Source {
|
||||
let source = SourceData {
|
||||
actor: thread_actor_name.clone(),
|
||||
url: source_info.url.to_string(),
|
||||
is_black_boxed: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue