mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Update handle_network_event to use BrowsingContextActor for HttpRequest
Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
parent
fcc391d852
commit
ff98f673c2
4 changed files with 31 additions and 15 deletions
|
@ -44,7 +44,7 @@ pub struct NetworkEventActor {
|
|||
is_xhr: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EventActor {
|
||||
pub actor: String,
|
||||
|
@ -55,6 +55,7 @@ pub struct EventActor {
|
|||
#[serde(rename = "isXHR")]
|
||||
pub is_xhr: bool,
|
||||
pub private: bool,
|
||||
pub cause: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -400,6 +401,7 @@ impl NetworkEventActor {
|
|||
time_stamp: self.request.time_stamp,
|
||||
is_xhr: self.is_xhr,
|
||||
private: false,
|
||||
cause: "network".to_owned(), // TODO: Set the correct cause
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ impl RootActor {
|
|||
sources: false,
|
||||
highlightable: true,
|
||||
custom_highlighters: true,
|
||||
network_monitor: false,
|
||||
network_monitor: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -483,12 +483,22 @@ impl DevtoolsInstance {
|
|||
};
|
||||
let netevent_actor_name = self.find_network_event_actor(request_id);
|
||||
|
||||
// Get browsing_context_actor_name
|
||||
let browsing_context_actor_name = match self.pipelines.get(&pipeline_id) {
|
||||
Some(id) => match self.browsing_contexts.get(id) {
|
||||
Some(name) => name.clone(),
|
||||
None => return,
|
||||
},
|
||||
None => return,
|
||||
};
|
||||
|
||||
handle_network_event(
|
||||
Arc::clone(&self.actors),
|
||||
console_actor_name,
|
||||
netevent_actor_name,
|
||||
connections,
|
||||
network_event,
|
||||
browsing_context_actor_name,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,10 @@ use devtools_traits::NetworkEvent;
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::actor::ActorRegistry;
|
||||
use crate::actors::browsing_context::BrowsingContextActor;
|
||||
use crate::actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg};
|
||||
use crate::protocol::JsonPacketStream;
|
||||
|
||||
use crate::resource::ResourceAvailable;
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct NetworkEventMsg {
|
||||
|
@ -57,27 +58,30 @@ pub(crate) fn handle_network_event(
|
|||
netevent_actor_name: String,
|
||||
mut connections: Vec<TcpStream>,
|
||||
network_event: NetworkEvent,
|
||||
browsing_context_actor_name: String,
|
||||
) {
|
||||
let mut actors = actors.lock().unwrap();
|
||||
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||
|
||||
match network_event {
|
||||
NetworkEvent::HttpRequest(httprequest) => {
|
||||
// Store the request information in the actor
|
||||
// Scope mutable borrow
|
||||
let event_actor = {
|
||||
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||
actor.add_request(httprequest);
|
||||
|
||||
// Send a networkEvent message to the client
|
||||
let msg = NetworkEventMsg {
|
||||
from: console_actor_name,
|
||||
type_: "networkEvent".to_owned(),
|
||||
event_actor: actor.event_actor(),
|
||||
actor.event_actor()
|
||||
};
|
||||
// Mutable borrow released
|
||||
let browsing_context_actor =
|
||||
actors.find::<BrowsingContextActor>(&browsing_context_actor_name);
|
||||
for stream in &mut connections {
|
||||
let _ = stream.write_json_packet(&msg);
|
||||
browsing_context_actor.resource_available(
|
||||
event_actor.clone(),
|
||||
"network-event".to_string(),
|
||||
stream,
|
||||
);
|
||||
}
|
||||
},
|
||||
NetworkEvent::HttpResponse(httpresponse) => {
|
||||
// Store the response information in the actor
|
||||
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||
actor.add_response(httpresponse);
|
||||
|
||||
let msg = NetworkEventUpdateMsg {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue