Files
servo/components/script/dom/fetchlaterresult.rs
Tim van der Lippe 680a780552 Implement fetchLater (#39547)
Allows fetches to be deferred, only in a secure context. It does not yet
implement quota computation, since we don't have a concept of document
quota yet.

Also update the `fetch/api/idlharness` test to run in a secure context,
since this API is only available there.

Positive Mozilla position:
https://github.com/mozilla/standards-positions/issues/703
Positive WebKit position:
https://github.com/WebKit/standards-positions/issues/85

Closes whatwg/fetch#1858

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-10-02 07:51:19 +00:00

60 lines
2.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::sync::{Arc, Mutex};
use dom_struct::dom_struct;
use crate::dom::bindings::codegen::Bindings::FetchLaterResultBinding::FetchLaterResultMethods;
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window;
use crate::fetch::DeferredFetchRecord;
use crate::script_runtime::CanGc;
/// <https://fetch.spec.whatwg.org/#fetchlaterresult>
#[dom_struct]
pub(crate) struct FetchLaterResult {
reflector_: Reflector,
/// <https://fetch.spec.whatwg.org/#fetchlaterresult-activated-getter-steps>
#[conditional_malloc_size_of]
#[no_trace]
activated_getter_steps: Arc<Mutex<DeferredFetchRecord>>,
}
impl FetchLaterResult {
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
fn new_inherited(activated_getter_steps: Arc<Mutex<DeferredFetchRecord>>) -> FetchLaterResult {
FetchLaterResult {
reflector_: Reflector::new(),
activated_getter_steps,
}
}
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub(crate) fn new(
window: &Window,
activated_getter_steps: Arc<Mutex<DeferredFetchRecord>>,
can_gc: CanGc,
) -> DomRoot<FetchLaterResult> {
reflect_dom_object(
Box::new(FetchLaterResult::new_inherited(activated_getter_steps)),
window,
can_gc,
)
}
}
impl FetchLaterResultMethods<crate::DomTypeHolder> for FetchLaterResult {
/// <https://fetch.spec.whatwg.org/#dom-fetchlaterresult-activated>
fn Activated(&self) -> bool {
// The activated getter steps are to return the result of running thiss activated getter steps.
self.activated_getter_steps
.lock()
.expect("Activated getter not accessible")
.activated_getter_steps()
}
}