aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-01-11 12:49:22 +0100
committerGitHub <noreply@github.com>2025-01-11 11:49:22 +0000
commit748954d610e5357b19506d0f9390bc769dd32213 (patch)
tree2e035c4dceefe825353cf6b4545d7d3387c98672 /components/script/script_thread.rs
parente2be55b873e7bd28c7bd8f92688e7f2035611326 (diff)
downloadservo-748954d610e5357b19506d0f9390bc769dd32213.tar.gz
servo-748954d610e5357b19506d0f9390bc769dd32213.zip
net: Use `RequestId` to cancel fetches instead of creating an IPC channel (#34883)
Instead of creating an IPC channel for every fetch, allow cancelling fetches based on the `RequestId` of the original request. This requires that `RequestId`s be UUIDs so that they are unique between processes that might communicating with the resource process. In addition, the resource process loop now keeps a `HashMap` or `Weak` handles to cancellers and cleans them up. This allows for creating mutiple `FetchCanceller`s in `script` for a single fetch request, allowing integration of the media and video elements to integrate with the `Document` canceller list -- meaning these fetches also get cancelled when the `Document` unloads. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs30
1 files changed, 11 insertions, 19 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index f7ff5c14dad..a4704cb2b42 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -139,6 +139,7 @@ use crate::dom::window::Window;
use crate::dom::windowproxy::{CreatorBrowsingContextInfo, WindowProxy};
use crate::dom::worklet::WorkletThreadPool;
use crate::dom::workletglobalscope::WorkletGlobalScopeInit;
+use crate::fetch::FetchCanceller;
use crate::messaging::{
CommonScriptMsg, MainThreadScriptMsg, MixedMessage, ScriptEventLoopSender,
ScriptThreadReceivers, ScriptThreadSenders,
@@ -3426,17 +3427,10 @@ impl ScriptThread {
.borrow_mut()
.push((incomplete.pipeline_id, context));
- let cancellation_receiver = incomplete.canceller.initialize();
- NavigationListener::new(
- incomplete.request_builder(),
- self.senders.self_sender.clone(),
- )
- .initiate_fetch(
- &self.resource_threads.core_thread,
- None,
- Some(cancellation_receiver),
- );
-
+ let request_builder = incomplete.request_builder();
+ incomplete.canceller = FetchCanceller::new(request_builder.id);
+ NavigationListener::new(request_builder, self.senders.self_sender.clone())
+ .initiate_fetch(&self.resource_threads.core_thread, None);
self.incomplete_loads.borrow_mut().push(incomplete);
}
@@ -3557,12 +3551,9 @@ impl ScriptThread {
.unwrap_or(200),
});
- let cancellation_receiver = incomplete_load.canceller.initialize();
- NavigationListener::new(request_builder, self.senders.self_sender.clone()).initiate_fetch(
- &self.resource_threads.core_thread,
- response_init,
- Some(cancellation_receiver),
- );
+ incomplete_load.canceller = FetchCanceller::new(request_builder.id);
+ NavigationListener::new(request_builder, self.senders.self_sender.clone())
+ .initiate_fetch(&self.resource_threads.core_thread, response_init);
}
/// Synchronously fetch `about:blank`. Stores the `InProgressLoad`
@@ -3590,7 +3581,7 @@ impl ScriptThread {
self.incomplete_loads.borrow_mut().push(incomplete);
- let dummy_request_id = RequestId::next();
+ let dummy_request_id = RequestId::default();
context.process_response(dummy_request_id, Ok(FetchMetadata::Unfiltered(meta)));
context.process_response_chunk(dummy_request_id, chunk);
context.process_response_eof(
@@ -3614,7 +3605,8 @@ impl ScriptThread {
self.incomplete_loads.borrow_mut().push(incomplete);
let mut context = ParserContext::new(id, url);
- let dummy_request_id = RequestId::next();
+ let dummy_request_id = RequestId::default();
+
context.process_response(dummy_request_id, Ok(FetchMetadata::Unfiltered(meta)));
context.process_response_chunk(dummy_request_id, chunk);
context.process_response_eof(