mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Update handle_network_event to use BrowsingContextActor for HttpRequest (#37263)
- Add browsing_context_actor_name parameter to handle_network_event - Replace NetworkEventMsg in HttpRequest case with BrowsingContextActor::resource_available - Update DevTools caller in lib.rs to pass browsing_context_actor_name Testing: Fixes: https://github.com/servo/servo/issues/33556#issuecomment-2756544430 --------- Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
parent
5c597f98e0
commit
e1ec650cfe
4 changed files with 49 additions and 29 deletions
|
@ -18,6 +18,7 @@ use serde_json::{Map, Value};
|
|||
|
||||
use crate::StreamId;
|
||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||
use crate::network_handler::Cause;
|
||||
use crate::protocol::JsonPacketStream;
|
||||
|
||||
struct HttpRequest {
|
||||
|
@ -44,7 +45,7 @@ pub struct NetworkEventActor {
|
|||
is_xhr: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EventActor {
|
||||
pub actor: String,
|
||||
|
@ -55,6 +56,7 @@ pub struct EventActor {
|
|||
#[serde(rename = "isXHR")]
|
||||
pub is_xhr: bool,
|
||||
pub private: bool,
|
||||
pub cause: Cause,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -392,6 +394,14 @@ impl NetworkEventActor {
|
|||
LocalResult::Ambiguous(date_time, _) => date_time.to_rfc3339().to_string(),
|
||||
};
|
||||
|
||||
let cause_type = match self.request.url.as_str() {
|
||||
// Adjust based on request data
|
||||
url if url.ends_with(".css") => "stylesheet",
|
||||
url if url.ends_with(".js") => "script",
|
||||
url if url.ends_with(".png") || url.ends_with(".jpg") => "img",
|
||||
_ => "document",
|
||||
};
|
||||
|
||||
EventActor {
|
||||
actor: self.name(),
|
||||
url: self.request.url.clone(),
|
||||
|
@ -400,6 +410,10 @@ impl NetworkEventActor {
|
|||
time_stamp: self.request.time_stamp,
|
||||
is_xhr: self.is_xhr,
|
||||
private: false,
|
||||
cause: Cause {
|
||||
type_: cause_type.to_string(),
|
||||
loading_document_uri: None, // Set if available
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ impl RootActor {
|
|||
sources: false,
|
||||
highlightable: true,
|
||||
custom_highlighters: true,
|
||||
network_monitor: false,
|
||||
network_monitor: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -478,18 +478,21 @@ impl DevtoolsInstance {
|
|||
request_id: String,
|
||||
network_event: NetworkEvent,
|
||||
) {
|
||||
let console_actor_name = match self.find_console_actor(pipeline_id, None) {
|
||||
Some(name) => name,
|
||||
None => return,
|
||||
};
|
||||
let netevent_actor_name = self.find_network_event_actor(request_id);
|
||||
|
||||
let Some(id) = self.pipelines.get(&pipeline_id) else {
|
||||
return;
|
||||
};
|
||||
let Some(browsing_context_actor_name) = self.browsing_contexts.get(id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
handle_network_event(
|
||||
Arc::clone(&self.actors),
|
||||
console_actor_name,
|
||||
netevent_actor_name,
|
||||
connections,
|
||||
network_event,
|
||||
browsing_context_actor_name.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,17 +9,10 @@ use devtools_traits::NetworkEvent;
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::actor::ActorRegistry;
|
||||
use crate::actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg};
|
||||
use crate::actors::browsing_context::BrowsingContextActor;
|
||||
use crate::actors::network_event::{NetworkEventActor, ResponseStartMsg};
|
||||
use crate::protocol::JsonPacketStream;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct NetworkEventMsg {
|
||||
from: String,
|
||||
#[serde(rename = "type")]
|
||||
type_: String,
|
||||
event_actor: EventActor,
|
||||
}
|
||||
use crate::resource::ResourceAvailable;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -50,34 +43,44 @@ struct EventTimingsUpdateMsg {
|
|||
struct SecurityInfoUpdateMsg {
|
||||
state: String,
|
||||
}
|
||||
#[derive(Clone, Serialize)]
|
||||
pub struct Cause {
|
||||
#[serde(rename = "type")]
|
||||
pub type_: String,
|
||||
#[serde(rename = "loadingDocumentUri")]
|
||||
pub loading_document_uri: Option<String>,
|
||||
}
|
||||
|
||||
pub(crate) fn handle_network_event(
|
||||
actors: Arc<Mutex<ActorRegistry>>,
|
||||
console_actor_name: String,
|
||||
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
|
||||
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(),
|
||||
// Scope mutable borrow
|
||||
let event_actor = {
|
||||
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
|
||||
actor.add_request(httprequest);
|
||||
actor.event_actor()
|
||||
};
|
||||
|
||||
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