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,
|
is_xhr: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, Clone)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct EventActor {
|
pub struct EventActor {
|
||||||
pub actor: String,
|
pub actor: String,
|
||||||
|
@ -55,6 +55,7 @@ pub struct EventActor {
|
||||||
#[serde(rename = "isXHR")]
|
#[serde(rename = "isXHR")]
|
||||||
pub is_xhr: bool,
|
pub is_xhr: bool,
|
||||||
pub private: bool,
|
pub private: bool,
|
||||||
|
pub cause: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -400,6 +401,7 @@ impl NetworkEventActor {
|
||||||
time_stamp: self.request.time_stamp,
|
time_stamp: self.request.time_stamp,
|
||||||
is_xhr: self.is_xhr,
|
is_xhr: self.is_xhr,
|
||||||
private: false,
|
private: false,
|
||||||
|
cause: "network".to_owned(), // TODO: Set the correct cause
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ impl RootActor {
|
||||||
sources: false,
|
sources: false,
|
||||||
highlightable: true,
|
highlightable: true,
|
||||||
custom_highlighters: 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);
|
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(
|
handle_network_event(
|
||||||
Arc::clone(&self.actors),
|
Arc::clone(&self.actors),
|
||||||
console_actor_name,
|
console_actor_name,
|
||||||
netevent_actor_name,
|
netevent_actor_name,
|
||||||
connections,
|
connections,
|
||||||
network_event,
|
network_event,
|
||||||
|
browsing_context_actor_name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,10 @@ use devtools_traits::NetworkEvent;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::actor::ActorRegistry;
|
use crate::actor::ActorRegistry;
|
||||||
|
use crate::actors::browsing_context::BrowsingContextActor;
|
||||||
use crate::actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg};
|
use crate::actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg};
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
|
use crate::resource::ResourceAvailable;
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct NetworkEventMsg {
|
struct NetworkEventMsg {
|
||||||
|
@ -57,27 +58,30 @@ pub(crate) fn handle_network_event(
|
||||||
netevent_actor_name: String,
|
netevent_actor_name: String,
|
||||||
mut connections: Vec<TcpStream>,
|
mut connections: Vec<TcpStream>,
|
||||||
network_event: NetworkEvent,
|
network_event: NetworkEvent,
|
||||||
|
browsing_context_actor_name: String,
|
||||||
) {
|
) {
|
||||||
let mut actors = actors.lock().unwrap();
|
let mut actors = actors.lock().unwrap();
|
||||||
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
|
||||||
|
|
||||||
match network_event {
|
match network_event {
|
||||||
NetworkEvent::HttpRequest(httprequest) => {
|
NetworkEvent::HttpRequest(httprequest) => {
|
||||||
// Store the request information in the actor
|
// Scope mutable borrow
|
||||||
actor.add_request(httprequest);
|
let event_actor = {
|
||||||
|
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||||
// Send a networkEvent message to the client
|
actor.add_request(httprequest);
|
||||||
let msg = NetworkEventMsg {
|
actor.event_actor()
|
||||||
from: console_actor_name,
|
|
||||||
type_: "networkEvent".to_owned(),
|
|
||||||
event_actor: actor.event_actor(),
|
|
||||||
};
|
};
|
||||||
|
// Mutable borrow released
|
||||||
|
let browsing_context_actor =
|
||||||
|
actors.find::<BrowsingContextActor>(&browsing_context_actor_name);
|
||||||
for stream in &mut connections {
|
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) => {
|
NetworkEvent::HttpResponse(httpresponse) => {
|
||||||
// Store the response information in the actor
|
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||||
actor.add_response(httpresponse);
|
actor.add_response(httpresponse);
|
||||||
|
|
||||||
let msg = NetworkEventUpdateMsg {
|
let msg = NetworkEventUpdateMsg {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue