aboutsummaryrefslogtreecommitdiffstats
path: root/components/devtools/actors
diff options
context:
space:
mode:
Diffstat (limited to 'components/devtools/actors')
-rw-r--r--components/devtools/actors/browsing_context.rs39
-rw-r--r--components/devtools/actors/console.rs1
-rw-r--r--components/devtools/actors/source.rs50
-rw-r--r--components/devtools/actors/thread.rs39
-rw-r--r--components/devtools/actors/watcher.rs3
-rw-r--r--components/devtools/actors/worker.rs11
6 files changed, 80 insertions, 63 deletions
diff --git a/components/devtools/actors/browsing_context.rs b/components/devtools/actors/browsing_context.rs
index c4ead7272bd..5de0855df4a 100644
--- a/components/devtools/actors/browsing_context.rs
+++ b/components/devtools/actors/browsing_context.rs
@@ -31,6 +31,7 @@ use crate::actors::thread::ThreadActor;
use crate::actors::watcher::{SessionContext, SessionContextType, WatcherActor};
use crate::id::{DevtoolsBrowserId, DevtoolsBrowsingContextId, DevtoolsOuterWindowId, IdMap};
use crate::protocol::JsonPacketStream;
+use crate::resource::ResourceAvailable;
use crate::{EmptyReplyMsg, StreamId};
#[derive(Serialize)]
@@ -57,14 +58,6 @@ struct FrameUpdateMsg {
}
#[derive(Serialize)]
-struct ResourceAvailableReply<T: Serialize> {
- from: String,
- #[serde(rename = "type")]
- type_: String,
- array: Vec<(String, Vec<T>)>,
-}
-
-#[derive(Serialize)]
struct TabNavigated {
from: String,
#[serde(rename = "type")]
@@ -152,6 +145,16 @@ pub(crate) struct BrowsingContextActor {
pub watcher: String,
}
+impl ResourceAvailable for BrowsingContextActor {
+ fn actor_name(&self) -> String {
+ self.name.clone()
+ }
+
+ fn get_streams(&self) -> &RefCell<HashMap<StreamId, TcpStream>> {
+ &self.streams
+ }
+}
+
impl Actor for BrowsingContextActor {
fn name(&self) -> String {
self.name.clone()
@@ -358,26 +361,6 @@ impl BrowsingContextActor {
});
}
- pub(crate) fn resource_available<T: Serialize>(&self, resource: T, resource_type: String) {
- self.resources_available(vec![resource], resource_type);
- }
-
- pub(crate) fn resources_available<T: Serialize>(
- &self,
- resources: Vec<T>,
- resource_type: String,
- ) {
- let msg = ResourceAvailableReply::<T> {
- from: self.name(),
- type_: "resources-available-array".into(),
- array: vec![(resource_type, resources)],
- };
-
- for stream in self.streams.borrow_mut().values_mut() {
- let _ = stream.write_json_packet(&msg);
- }
- }
-
pub fn simulate_color_scheme(&self, theme: Theme) -> Result<(), ()> {
self.script_chan
.send(SimulateColorScheme(self.active_pipeline_id.get(), theme))
diff --git a/components/devtools/actors/console.rs b/components/devtools/actors/console.rs
index ecd718e47d4..3897ffa0fce 100644
--- a/components/devtools/actors/console.rs
+++ b/components/devtools/actors/console.rs
@@ -30,6 +30,7 @@ use crate::actors::browsing_context::BrowsingContextActor;
use crate::actors::object::ObjectActor;
use crate::actors::worker::WorkerActor;
use crate::protocol::JsonPacketStream;
+use crate::resource::ResourceAvailable;
use crate::{StreamId, UniqueId};
trait EncodableConsoleMessage {
diff --git a/components/devtools/actors/source.rs b/components/devtools/actors/source.rs
new file mode 100644
index 00000000000..9d29bc1d3ef
--- /dev/null
+++ b/components/devtools/actors/source.rs
@@ -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()
+ }
+}
diff --git a/components/devtools/actors/thread.rs b/components/devtools/actors/thread.rs
index 85ff2b732eb..7ff11dff675 100644
--- a/components/devtools/actors/thread.rs
+++ b/components/devtools/actors/thread.rs
@@ -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 {
diff --git a/components/devtools/actors/watcher.rs b/components/devtools/actors/watcher.rs
index 77f82c1023a..6a84499b6dd 100644
--- a/components/devtools/actors/watcher.rs
+++ b/components/devtools/actors/watcher.rs
@@ -29,6 +29,7 @@ use crate::actors::watcher::thread_configuration::{
ThreadConfigurationActor, ThreadConfigurationActorMsg,
};
use crate::protocol::JsonPacketStream;
+use crate::resource::ResourceAvailable;
use crate::{EmptyReplyMsg, StreamId};
pub mod network_parent;
@@ -264,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" => {},
diff --git a/components/devtools/actors/worker.rs b/components/devtools/actors/worker.rs
index 046befe9dc9..42c9d9a9c28 100644
--- a/components/devtools/actors/worker.rs
+++ b/components/devtools/actors/worker.rs
@@ -17,6 +17,7 @@ use servo_url::ServoUrl;
use crate::StreamId;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream;
+use crate::resource::ResourceAvailable;
#[derive(Clone, Copy)]
#[allow(dead_code)]
@@ -53,6 +54,16 @@ impl WorkerActor {
}
}
+impl ResourceAvailable for WorkerActor {
+ fn actor_name(&self) -> String {
+ self.name.clone()
+ }
+
+ fn get_streams(&self) -> &RefCell<HashMap<StreamId, TcpStream>> {
+ &self.streams
+ }
+}
+
impl Actor for WorkerActor {
fn name(&self) -> String {
self.name.clone()