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:
Usman Yahaya Baba 2025-06-10 15:11:39 +01:00 committed by GitHub
parent 5c597f98e0
commit e1ec650cfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 29 deletions

View file

@ -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 {