mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
DevTools: Add resource_available
as a common shared util (#36632)
These PR adds `resource_available` as a common shared util - [x] ./mach build -d does not report any errors - [x] ./mach test-tidy does not report any errors - [x] These changes partially implement https://github.com/servo/servo/issues/36027 --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
parent
e9e103b46c
commit
7c1e5918a8
6 changed files with 68 additions and 28 deletions
|
@ -31,6 +31,7 @@ use crate::actors::thread::ThreadActor;
|
||||||
use crate::actors::watcher::{SessionContext, SessionContextType, WatcherActor};
|
use crate::actors::watcher::{SessionContext, SessionContextType, WatcherActor};
|
||||||
use crate::id::{DevtoolsBrowserId, DevtoolsBrowsingContextId, DevtoolsOuterWindowId, IdMap};
|
use crate::id::{DevtoolsBrowserId, DevtoolsBrowsingContextId, DevtoolsOuterWindowId, IdMap};
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
|
use crate::resource::ResourceAvailable;
|
||||||
use crate::{EmptyReplyMsg, StreamId};
|
use crate::{EmptyReplyMsg, StreamId};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -56,14 +57,6 @@ struct FrameUpdateMsg {
|
||||||
title: String,
|
title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct ResourceAvailableReply<T: Serialize> {
|
|
||||||
from: String,
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
type_: String,
|
|
||||||
array: Vec<(String, Vec<T>)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct TabNavigated {
|
struct TabNavigated {
|
||||||
from: String,
|
from: String,
|
||||||
|
@ -152,6 +145,16 @@ pub(crate) struct BrowsingContextActor {
|
||||||
pub watcher: String,
|
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 {
|
impl Actor for BrowsingContextActor {
|
||||||
fn name(&self) -> String {
|
fn name(&self) -> String {
|
||||||
self.name.clone()
|
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<(), ()> {
|
pub fn simulate_color_scheme(&self, theme: Theme) -> Result<(), ()> {
|
||||||
self.script_chan
|
self.script_chan
|
||||||
.send(SimulateColorScheme(self.active_pipeline_id.get(), theme))
|
.send(SimulateColorScheme(self.active_pipeline_id.get(), theme))
|
||||||
|
|
|
@ -30,6 +30,7 @@ use crate::actors::browsing_context::BrowsingContextActor;
|
||||||
use crate::actors::object::ObjectActor;
|
use crate::actors::object::ObjectActor;
|
||||||
use crate::actors::worker::WorkerActor;
|
use crate::actors::worker::WorkerActor;
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
|
use crate::resource::ResourceAvailable;
|
||||||
use crate::{StreamId, UniqueId};
|
use crate::{StreamId, UniqueId};
|
||||||
|
|
||||||
trait EncodableConsoleMessage {
|
trait EncodableConsoleMessage {
|
||||||
|
|
|
@ -29,6 +29,7 @@ use crate::actors::watcher::thread_configuration::{
|
||||||
ThreadConfigurationActor, ThreadConfigurationActorMsg,
|
ThreadConfigurationActor, ThreadConfigurationActorMsg,
|
||||||
};
|
};
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
|
use crate::resource::ResourceAvailable;
|
||||||
use crate::{EmptyReplyMsg, StreamId};
|
use crate::{EmptyReplyMsg, StreamId};
|
||||||
|
|
||||||
pub mod network_parent;
|
pub mod network_parent;
|
||||||
|
|
|
@ -17,6 +17,7 @@ use servo_url::ServoUrl;
|
||||||
use crate::StreamId;
|
use crate::StreamId;
|
||||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
|
use crate::resource::ResourceAvailable;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[allow(dead_code)]
|
#[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 {
|
impl Actor for WorkerActor {
|
||||||
fn name(&self) -> String {
|
fn name(&self) -> String {
|
||||||
self.name.clone()
|
self.name.clone()
|
||||||
|
|
|
@ -30,6 +30,7 @@ use devtools_traits::{
|
||||||
use embedder_traits::{AllowOrDeny, EmbedderMsg, EmbedderProxy};
|
use embedder_traits::{AllowOrDeny, EmbedderMsg, EmbedderProxy};
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
use resource::ResourceAvailable;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use servo_rand::RngCore;
|
use servo_rand::RngCore;
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ mod actors {
|
||||||
mod id;
|
mod id;
|
||||||
mod network_handler;
|
mod network_handler;
|
||||||
mod protocol;
|
mod protocol;
|
||||||
|
mod resource;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
enum UniqueId {
|
enum UniqueId {
|
||||||
|
|
42
components/devtools/resource.rs
Normal file
42
components/devtools/resource.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* 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::RefCell;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::net::TcpStream;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::StreamId;
|
||||||
|
use crate::protocol::JsonPacketStream;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub(crate) struct ResourceAvailableReply<T: Serialize> {
|
||||||
|
pub from: String,
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub type_: String,
|
||||||
|
pub array: Vec<(String, Vec<T>)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) trait ResourceAvailable {
|
||||||
|
fn actor_name(&self) -> String;
|
||||||
|
|
||||||
|
fn get_streams(&self) -> &RefCell<HashMap<StreamId, TcpStream>>;
|
||||||
|
|
||||||
|
fn resource_available<T: Serialize>(&self, resource: T, resource_type: String) {
|
||||||
|
self.resources_available(vec![resource], resource_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resources_available<T: Serialize>(&self, resources: Vec<T>, resource_type: String) {
|
||||||
|
let msg = ResourceAvailableReply::<T> {
|
||||||
|
from: self.actor_name(),
|
||||||
|
type_: "resources-available-array".into(),
|
||||||
|
array: vec![(resource_type, resources)],
|
||||||
|
};
|
||||||
|
|
||||||
|
for stream in self.get_streams().borrow_mut().values_mut() {
|
||||||
|
let _ = stream.write_json_packet(&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue