Devtools: refactor source actor state (#37528)

We currently store the source contents in both the SourceActor and the
ThreadActor’s SourceManager, which is redundant. We also currently send
the source contents in thread `sources` responses and watcher
`resources-available-array` messages, but in both cases this is
unnecessary (and ignored by the client).

This patch merges SourceData into SourceActor, making the latter the
single source of truth for source-related state. We also create a
SourceForm type, which represents the subset of source-related state
that gets sent in thread `sources` responses (and for now, watcher
`resources-available-array` messages).

Finally we rename `source_urls` → `source_actor_names` and `new_source`
→ `new_registered` for clarity.

Testing: no changes to client-facing behaviour, and this is covered by
tests

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
shuppy 2025-06-18 21:11:46 +10:00 committed by GitHub
parent 97011a53ac
commit 0896341285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 61 deletions

View file

@ -43,7 +43,7 @@ use crate::actors::performance::PerformanceActor;
use crate::actors::preference::PreferenceActor;
use crate::actors::process::ProcessActor;
use crate::actors::root::RootActor;
use crate::actors::source::{SourceActor, SourceData};
use crate::actors::source::SourceActor;
use crate::actors::thread::ThreadActor;
use crate::actors::worker::{WorkerActor, WorkerType};
use crate::id::IdMap;
@ -518,11 +518,14 @@ impl DevtoolsInstance {
fn handle_script_source_info(&mut self, pipeline_id: PipelineId, source_info: SourceInfo) {
let mut actors = self.actors.lock().unwrap();
let source_actor_name = SourceActor::new_source(
let source_actor = SourceActor::new_registered(
&mut actors,
source_info.url,
source_info.content.clone(),
source_info.content_type.unwrap(),
);
let source_actor_name = source_actor.name.clone();
let source_form = source_actor.source_form();
if let Some(worker_id) = source_info.worker_id {
let Some(worker_actor_name) = self.actor_workers.get(&worker_id) else {
@ -532,23 +535,12 @@ impl DevtoolsInstance {
let thread_actor_name = actors.find::<WorkerActor>(worker_actor_name).thread.clone();
let thread_actor = actors.find_mut::<ThreadActor>(&thread_actor_name);
thread_actor.source_manager.add_source(
source_info.url.clone(),
source_info.content.clone(),
source_actor_name.clone(),
);
let source = SourceData {
actor: source_actor_name,
url: source_info.url.to_string(),
is_black_boxed: false,
source_content: source_info.content,
};
thread_actor.source_manager.add_source(&source_actor_name);
let worker_actor = actors.find::<WorkerActor>(worker_actor_name);
for stream in self.connections.values_mut() {
worker_actor.resource_available(&source, "source".into(), stream);
worker_actor.resource_available(&source_form, "source".into(), stream);
}
} else {
let Some(browsing_context_id) = self.pipelines.get(&pipeline_id) else {
@ -565,24 +557,13 @@ impl DevtoolsInstance {
let thread_actor = actors.find_mut::<ThreadActor>(&thread_actor_name);
thread_actor.source_manager.add_source(
source_info.url.clone(),
source_info.content.clone(),
source_actor_name.clone(),
);
let source = SourceData {
actor: source_actor_name,
url: source_info.url.to_string(),
is_black_boxed: false,
source_content: source_info.content,
};
thread_actor.source_manager.add_source(&source_actor_name);
// Notify browsing context about the new source
let browsing_context = actors.find::<BrowsingContextActor>(actor_name);
for stream in self.connections.values_mut() {
browsing_context.resource_available(&source, "source".into(), stream);
browsing_context.resource_available(&source_form, "source".into(), stream);
}
}
}