Skip to content

Truly independent web browser

LibWeb: Implement the performance entries in Rust

Shannon Booth6e48cd1903f4
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/cpp_cell.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/cpp_cell.rs
index a32c253d0e1..fa9cf97b145 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/cpp_cell.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/cpp_cell.rs
@@ -7,7 +7,7 @@
use core::ffi::c_void;
use core::ptr::NonNull;
-use libjs_rust::api::{ForeignCellSlot, Trace};
+use libjs_rust::api::{ForeignCellSlot, Gc, GcWeak, Trace, Vm};
/// A cell of LibWeb's C++ code, which this keeps alive.
#[derive(Trace)]
@@ -36,3 +36,21 @@ impl CppCell {
self.0.as_ptr()
}
}
+
+/// A cell of LibWeb's C++ code, which this does not keep alive.
+#[derive(Clone, Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct WeakCppCell(GcWeak<c_void>);
+
+impl WeakCppCell {
+ pub(crate) fn new(vm: &Vm, cell: &CppCell) -> Self {
+ let cell = NonNull::new(cell.as_ptr()).expect("a CppCell holds a cell");
+ // SAFETY: The CppCell keeps the cell alive.
+ Self(GcWeak::new(vm.heap(), unsafe { Gc::from_non_null(cell) }))
+ }
+
+ pub(crate) fn get(&self) -> Option<CppCell> {
+ // SAFETY: A cell that the weak reference still has is live.
+ self.0.get().map(|cell| unsafe { CppCell::from_raw(cell.as_ptr()) })
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/environment_settings_object.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/environment_settings_object.rs
index 92ad10b59c9..b9b1244aaa6 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/environment_settings_object.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/environment_settings_object.rs
@@ -20,6 +20,7 @@ unsafe extern "C" {
fn web_bindings_relevant_settings_object(global_object: *mut c_void) -> *mut c_void;
fn web_bindings_environment_settings_object_global_object(settings_object: *mut c_void) -> *mut c_void;
fn web_bindings_environment_settings_object_realm(settings_object: *mut c_void) -> *mut c_void;
+ fn web_bindings_environment_settings_object_time_origin(settings_object: *mut c_void) -> f64;
fn web_bindings_environment_settings_object_id(
settings_object: *mut c_void,
id: *mut c_void,
@@ -85,6 +86,12 @@ impl CppEnvironmentSettingsObject {
unsafe { Gc::from_non_null(NonNull::new(realm.cast()).expect("a settings object has a realm")) }
}
+ /// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-time-origin
+ pub(crate) fn time_origin(&self) -> f64 {
+ // SAFETY: The settings object is live.
+ unsafe { web_bindings_environment_settings_object_time_origin(self.as_ptr()) }
+ }
+
/// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-a-url
pub(crate) fn encoding_parse_url(&self, url: &Utf16String) -> Option<Url> {
let mut parsed_url = None;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs
index 0782d060b32..fe5d69fd25d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs
@@ -10,11 +10,11 @@ use core::ffi::c_void;
use core::ptr::NonNull;
use libjs_rust::api::{Gc, MarkedVec, Object, Realm, Trace, Vm};
-use liburl_rust::Url;
use crate::bindings::cpp_cell::CppCell;
use crate::bindings::event_target::CppEventTarget;
use crate::bindings::interface::Wrappable;
+use crate::dom::document::CppDocument;
unsafe extern "C" {
fn web_bindings_window_from_global_object(global_object: *mut c_void) -> *mut c_void;
@@ -24,11 +24,6 @@ unsafe extern "C" {
fn web_bindings_window_page_id(window: *mut c_void) -> u64;
fn web_bindings_window_has_transient_activation(window: *mut c_void) -> bool;
fn web_bindings_window_as_event_target(window: *mut c_void) -> *mut c_void;
- fn web_bindings_document_has_navigable(document: *mut c_void) -> bool;
- fn web_bindings_document_is_fully_active(document: *mut c_void) -> bool;
- fn web_bindings_document_has_focus(document: *mut c_void) -> bool;
- fn web_bindings_document_has_been_destroyed(document: *mut c_void) -> bool;
- fn web_bindings_document_url(document: *mut c_void) -> liburl_rust::RustUrl;
fn web_bindings_worker_global_scope_from_global_object(global_object: *mut c_void) -> *mut c_void;
fn web_bindings_worker_global_scope_is_closing(worker_global_scope: *mut c_void) -> bool;
}
@@ -43,11 +38,6 @@ pub(crate) struct CppWindow(CppCell);
#[gc(crate = libjs_rust)]
pub(crate) struct CppWorkerGlobalScope(CppCell);
-/// https://dom.spec.whatwg.org/#document
-#[derive(Clone, Trace)]
-#[gc(crate = libjs_rust)]
-pub(crate) struct CppDocument(CppCell);
-
/// The cell of a C++ object that LibWeb returns, or None for a null pointer.
///
/// # Safety
@@ -138,39 +128,7 @@ impl CppWindow {
/// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-document-window
pub(crate) fn associated_document(&self) -> CppDocument {
// SAFETY: The Window is live, and LibWeb returns its live associated Document.
- CppDocument(unsafe { CppCell::from_raw(web_bindings_window_associated_document(self.0.as_ptr())) })
- }
-}
-
-impl CppDocument {
- /// https://html.spec.whatwg.org/multipage/document-sequences.html#fully-active
- pub(crate) fn is_fully_active(&self) -> bool {
- // SAFETY: The Document is live.
- unsafe { web_bindings_document_is_fully_active(self.0.as_ptr()) }
- }
-
- /// https://html.spec.whatwg.org/multipage/interaction.html#has-focus-steps
- pub(crate) fn has_focus(&self) -> bool {
- // SAFETY: The Document is live.
- unsafe { web_bindings_document_has_focus(self.0.as_ptr()) }
- }
-
- /// https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document
- pub(crate) fn has_been_destroyed(&self) -> bool {
- // SAFETY: The Document is live.
- unsafe { web_bindings_document_has_been_destroyed(self.0.as_ptr()) }
- }
-
- /// Whether the Document's node navigable is not null, https://html.spec.whatwg.org/multipage/document-sequences.html#node-navigable
- pub(crate) fn has_navigable(&self) -> bool {
- // SAFETY: The Document is live.
- unsafe { web_bindings_document_has_navigable(self.0.as_ptr()) }
- }
-
- /// https://dom.spec.whatwg.org/#concept-document-url
- pub(crate) fn url(&self) -> Url {
- // SAFETY: The Document is live, and LibWeb lends its URL, which this copies before the Document can change it.
- unsafe { web_bindings_document_url(self.0.as_ptr()).to_url() }
+ unsafe { CppDocument::from_raw(web_bindings_window_associated_document(self.0.as_ptr())) }
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/dom/document.rs b/Libraries/LibWeb/Bindings/Rust/src/dom/document.rs
new file mode 100644
index 00000000000..9dd7cc99d56
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/dom/document.rs
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+use core::ffi::c_void;
+
+use libjs_rust::api::Trace;
+use liburl_rust::Url;
+
+use crate::bindings::cpp_cell::CppCell;
+use crate::bindings::interface::{Ref, cell_from_abi, cell_into_abi};
+use crate::navigation_timing::performance_navigation_timing::PerformanceNavigationTiming;
+
+unsafe extern "C" {
+ fn web_bindings_document_has_navigable(document: *mut c_void) -> bool;
+ fn web_bindings_document_is_fully_active(document: *mut c_void) -> bool;
+ fn web_bindings_document_has_focus(document: *mut c_void) -> bool;
+ fn web_bindings_document_has_been_destroyed(document: *mut c_void) -> bool;
+ fn web_bindings_document_url(document: *mut c_void) -> liburl_rust::RustUrl;
+ fn web_bindings_document_load_timing_info(document: *mut c_void, load_timing_info: *mut DocumentLoadTimingInfo);
+ fn web_bindings_document_previous_document_unload_timing(
+ document: *mut c_void,
+ unload_timing: *mut DocumentUnloadTimingInfo,
+ );
+ fn web_bindings_document_navigation_timing_entry(document: *mut c_void) -> *mut c_void;
+ fn web_bindings_document_set_navigation_timing_entry(document: *mut c_void, entry: *mut c_void);
+}
+
+/// https://dom.spec.whatwg.org/#document
+#[derive(Clone, Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct CppDocument(CppCell);
+
+/// https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info
+#[derive(Clone, Copy, Default)]
+#[repr(C)]
+pub(crate) struct DocumentLoadTimingInfo {
+ pub(crate) navigation_start_time: f64,
+ pub(crate) dom_interactive_time: f64,
+ pub(crate) dom_content_loaded_event_start_time: f64,
+ pub(crate) dom_content_loaded_event_end_time: f64,
+ pub(crate) dom_complete_time: f64,
+ pub(crate) load_event_start_time: f64,
+ pub(crate) load_event_end_time: f64,
+ pub(crate) dom_loading_time: f64,
+}
+
+/// https://html.spec.whatwg.org/multipage/dom.html#document-unload-timing-info
+#[derive(Clone, Copy, Default)]
+#[repr(C)]
+pub(crate) struct DocumentUnloadTimingInfo {
+ pub(crate) unload_event_start_time: f64,
+ pub(crate) unload_event_end_time: f64,
+}
+
+impl CppDocument {
+ /// # Safety
+ ///
+ /// `document` must be a live Document.
+ pub(crate) unsafe fn from_raw(document: *mut c_void) -> Self {
+ // SAFETY: The caller passes a live Document.
+ Self(unsafe { CppCell::from_raw(document) })
+ }
+
+ /// https://html.spec.whatwg.org/multipage/document-sequences.html#fully-active
+ pub(crate) fn is_fully_active(&self) -> bool {
+ // SAFETY: The Document is live.
+ unsafe { web_bindings_document_is_fully_active(self.0.as_ptr()) }
+ }
+
+ /// https://html.spec.whatwg.org/multipage/interaction.html#has-focus-steps
+ pub(crate) fn has_focus(&self) -> bool {
+ // SAFETY: The Document is live.
+ unsafe { web_bindings_document_has_focus(self.0.as_ptr()) }
+ }
+
+ /// https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document
+ pub(crate) fn has_been_destroyed(&self) -> bool {
+ // SAFETY: The Document is live.
+ unsafe { web_bindings_document_has_been_destroyed(self.0.as_ptr()) }
+ }
+
+ /// Whether the Document's node navigable is not null, https://html.spec.whatwg.org/multipage/document-sequences.html#node-navigable
+ pub(crate) fn has_navigable(&self) -> bool {
+ // SAFETY: The Document is live.
+ unsafe { web_bindings_document_has_navigable(self.0.as_ptr()) }
+ }
+
+ /// https://dom.spec.whatwg.org/#concept-document-url
+ pub(crate) fn url(&self) -> Url {
+ // SAFETY: The Document is live, and LibWeb lends its URL, which this copies before the Document can change it.
+ unsafe { web_bindings_document_url(self.0.as_ptr()).to_url() }
+ }
+
+ /// https://html.spec.whatwg.org/multipage/dom.html#load-timing-info
+ pub(crate) fn load_timing_info(&self) -> DocumentLoadTimingInfo {
+ let mut load_timing_info = DocumentLoadTimingInfo::default();
+ // SAFETY: The Document is live, and LibWeb writes its load timing info.
+ unsafe { web_bindings_document_load_timing_info(self.0.as_ptr(), &raw mut load_timing_info) };
+ load_timing_info
+ }
+
+ /// https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing
+ pub(crate) fn previous_document_unload_timing(&self) -> DocumentUnloadTimingInfo {
+ let mut unload_timing = DocumentUnloadTimingInfo::default();
+ // SAFETY: The Document is live, and LibWeb writes its previous document unload timing.
+ unsafe { web_bindings_document_previous_document_unload_timing(self.0.as_ptr(), &raw mut unload_timing) };
+ unload_timing
+ }
+
+ /// https://w3c.github.io/navigation-timing/#dfn-document-navigation-timing-entry
+ pub(crate) fn navigation_timing_entry(&self) -> Option<Ref<PerformanceNavigationTiming>> {
+ // SAFETY: The Document is live.
+ let entry = unsafe { web_bindings_document_navigation_timing_entry(self.0.as_ptr()) };
+ // SAFETY: LibWeb returns null or the cell of the Document's PerformanceNavigationTiming.
+ (!entry.is_null()).then(|| unsafe { cell_from_abi(entry) })
+ }
+
+ pub(crate) fn set_navigation_timing_entry(&self, entry: Ref<PerformanceNavigationTiming>) {
+ // SAFETY: The Document and the entry are live.
+ unsafe { web_bindings_document_set_navigation_timing_entry(self.0.as_ptr(), cell_into_abi(entry)) };
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs
index da7f37015e5..7d46beaf6de 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs
@@ -8,4 +8,6 @@
#[cfg(not(test))]
pub(crate) mod abort_signal;
+#[cfg(not(test))]
+pub(crate) mod document;
pub(crate) mod event;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs
index 06b3cf34fc7..9bce3ad2f22 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs
@@ -7,3 +7,4 @@
//! Event Timing, https://w3c.github.io/event-timing/
pub(crate) mod event_counts;
+pub(crate) mod performance_event_timing;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rs
new file mode 100644
index 00000000000..2b63a8e0fdf
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rs
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2024, Noah Bright <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PerformanceEventTiming, https://w3c.github.io/event-timing/#sec-performance-event-timing
+
+use core::cell::{Cell, RefCell};
+use core::ffi::c_void;
+
+use ak::{Utf16FlyString, Utf16String};
+use libjs_rust::api::{GcRefCell, Trace, Vm};
+
+use crate::bindings::conversions::CppInterface;
+use crate::bindings::cpp_cell::CppCell;
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate, cell_from_abi, cell_into_abi};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::css::css_rule::wrap_cpp_cell;
+use crate::paint_timing::paint_timing::is_exposed_for_paint_timing;
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
+use crate::performance_timeline::performance_observer::PerformanceObserverInit;
+
+/// https://w3c.github.io/event-timing/#sec-performance-event-timing
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceEventTiming {
+ // NB: An entry is "event", unless it is the copy of an entry that is queued as the first input.
+ entry: PerformanceEntry,
+ has_duration: Cell<bool>,
+ processing_start: f64,
+ processing_end: Cell<f64>,
+ cancelable: bool,
+ /// https://w3c.github.io/event-timing/#eventtarget
+ event_target: GcRefCell<Option<CppCell>>,
+ #[gc(untraced)]
+ target_selector: RefCell<Utf16String>,
+ interaction_id: Cell<u64>,
+}
+
+impl Wrappable for PerformanceEventTiming {}
+
+impl Inherits<PerformanceEntry> for PerformanceEventTiming {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+impl PerformanceEventTiming {
+ // https://w3c.github.io/event-timing/#initialize-event-timing
+ pub(crate) fn create(
+ vm: &Vm,
+ name: Utf16String,
+ start_time: f64,
+ processing_start: f64,
+ cancelable: bool,
+ interaction_id: u64,
+ ) -> Ref<Self> {
+ // 2. Let timingEntry be a new PerformanceEventTiming object with event's relevant realm.
+ // 3. Set timingEntry's name to event's type attribute value.
+ // 4. Set timingEntry's entryType to "event".
+ // 5. Set timingEntry's startTime to event's timeStamp attribute value.
+ // 6. Set timingEntry's processingStart to processingStart.
+ // 7. Set timingEntry's cancelable to event's cancelable attribute value.
+ // 8. Set timingEntry's interactionId to interactionId.
+ let timing_entry = allocate(vm, |_| Self {
+ entry: PerformanceEntry::new(name, Utf16String::from_utf8("event"), start_time, 0.0),
+ has_duration: Cell::new(false),
+ processing_start,
+ processing_end: Cell::new(0.0),
+ cancelable,
+ event_target: GcRefCell::new(None),
+ target_selector: RefCell::new(Utf16String::default()),
+ interaction_id: Cell::new(interaction_id),
+ });
+ let any_entry = AnyPerformanceEntry::PerformanceEventTiming(timing_entry);
+ any_entry.entry().set_object(any_entry);
+ timing_entry
+ }
+
+ pub(crate) fn copy_with_entry_type(&self, vm: &Vm, entry_type: Utf16String) -> Ref<Self> {
+ let entry = self.entry.object();
+ let copy = allocate(vm, |_| Self {
+ entry: PerformanceEntry::new(entry.name(), entry_type, entry.start_time(), entry.duration()),
+ has_duration: Cell::new(self.has_duration.get()),
+ processing_start: self.processing_start,
+ processing_end: Cell::new(self.processing_end.get()),
+ cancelable: self.cancelable,
+ event_target: GcRefCell::new(self.event_target.borrow().clone()),
+ target_selector: RefCell::new(self.target_selector.borrow().clone()),
+ interaction_id: Cell::new(self.interaction_id.get()),
+ });
+ let any_entry = AnyPerformanceEntry::PerformanceEventTiming(copy);
+ any_entry.entry().set_object(any_entry);
+ copy
+ }
+
+ pub(crate) fn processing_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ Ok(self.processing_start)
+ }
+
+ pub(crate) fn processing_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ Ok(self.processing_end.get())
+ }
+
+ pub(crate) fn cancelable(&self, _: &mut CallContext) -> WebIdlResult<bool> {
+ Ok(self.cancelable)
+ }
+
+ // https://w3c.github.io/event-timing/#dom-performanceeventtiming-target
+ pub(crate) fn target(&self, cx: &mut CallContext) -> WebIdlResult<Option<CppInterface>> {
+ let event_target = self.event_target.borrow();
+
+ // 1. If this's eventTarget is not exposed for paint timing given null, return null.
+ let Some(event_target) = event_target
+ .as_ref()
+ .filter(|target| is_exposed_for_paint_timing(target))
+ else {
+ return Ok(None);
+ };
+
+ // 2. Return this's eventTarget.
+ Ok(Some(wrap_cpp_cell(cx, event_target)))
+ }
+
+ pub(crate) fn target_selector(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ Ok(self.target_selector.borrow().clone())
+ }
+
+ pub(crate) fn interaction_id(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ Ok(self.interaction_id.get())
+ }
+
+ // https://w3c.github.io/event-timing/#should-add-performanceeventtiming
+ pub(crate) fn should_add_entry(&self, options: Option<&PerformanceObserverInit>) -> bool {
+ // 1. If entry's entryType attribute value equals to "first-input", return true.
+ let entry = self.entry.object();
+ if entry.entry_type() == Utf16String::from_utf8("first-input") {
+ return true;
+ }
+
+ // 2. Assert that entry's entryType attribute value equals "event".
+ assert!(entry.entry_type() == Utf16String::from_utf8("event"));
+
+ // 3. Let minDuration be computed as follows:
+ let min_duration = match options.and_then(|options| options.duration_threshold) {
+ // 1. If options is not present or if options's durationThreshold is not present, let minDuration be 104.
+ None => 104.0,
+ // 2. Otherwise, let minDuration be the maximum between 16 and options's durationThreshold value.
+ Some(duration_threshold) => f64::max(16.0, duration_threshold),
+ };
+
+ // 4. If entry's duration attribute value is greater than or equal to minDuration, return true.
+ // 5. Otherwise, return false.
+ entry.duration() >= min_duration
+ }
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming.
+unsafe fn entry_from_abi(entry: *mut c_void) -> Ref<PerformanceEventTiming> {
+ // SAFETY: The caller passes the live cell of a PerformanceEventTiming.
+ unsafe { cell_from_abi(entry) }
+}
+
+/// https://w3c.github.io/event-timing/#initialize-event-timing
+///
+/// # Safety
+///
+/// `vm` must be the live VM, and `name` a raw AK::Utf16String that C++ hands over.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_create_performance_event_timing(
+ vm: *mut c_void,
+ name: usize,
+ start_time: f64,
+ processing_start: f64,
+ cancelable: bool,
+ interaction_id: u64,
+) -> *mut c_void {
+ // SAFETY: The caller passes the live VM and hands over the string.
+ let (vm, name) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(name)) };
+ let entry = PerformanceEventTiming::create(vm, name, start_time, processing_start, cancelable, interaction_id);
+ cell_into_abi(entry)
+}
+
+/// # Safety
+///
+/// `vm` must be the live VM, `entry` the live cell of a PerformanceEventTiming, and `entry_type` a raw
+/// AK::Utf16FlyString that C++ lends for the call.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_copy_with_entry_type(
+ vm: *mut c_void,
+ entry: *mut c_void,
+ entry_type: usize,
+) -> *mut c_void {
+ // SAFETY: The caller passes the live VM and a live entry, and lends the fly string.
+ let (vm, entry, entry_type) = unsafe {
+ (
+ &*vm.cast::<Vm>(),
+ entry_from_abi(entry),
+ Utf16String::from(Utf16FlyString::from_raw_borrowed(entry_type)),
+ )
+ };
+ let copy = entry.copy_with_entry_type(vm, entry_type);
+ cell_into_abi(copy)
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_has_duration(entry: *mut c_void) -> bool {
+ // SAFETY: The caller passes a live entry.
+ unsafe { entry_from_abi(entry) }.has_duration.get()
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_set_duration(entry: *mut c_void, duration: f64) {
+ // SAFETY: The caller passes a live entry.
+ let entry = unsafe { entry_from_abi(entry) };
+ entry.entry.set_duration(duration);
+ entry.has_duration.set(true);
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_set_processing_end(entry: *mut c_void, processing_end: f64) {
+ // SAFETY: The caller passes a live entry.
+ unsafe { entry_from_abi(entry) }.processing_end.set(processing_end);
+}
+
+/// # Safety
+///
+/// `vm` must be the live VM, `entry` the live cell of a PerformanceEventTiming, and `event_target` null or a live Node.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_set_event_target(
+ vm: *mut c_void,
+ entry: *mut c_void,
+ event_target: *mut c_void,
+) {
+ // SAFETY: The caller passes the live VM, a live entry, and null or a live Node.
+ let (vm, entry, event_target) = unsafe {
+ (
+ &*vm.cast::<Vm>(),
+ entry_from_abi(entry),
+ (!event_target.is_null()).then(|| CppCell::from_raw(event_target)),
+ )
+ };
+ *entry.event_target.borrow_mut(vm) = event_target;
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming, and `target_selector` a raw AK::Utf16String that C++
+/// hands over.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_set_target_selector(entry: *mut c_void, target_selector: usize) {
+ // SAFETY: The caller passes a live entry and hands over the string.
+ let (entry, target_selector) = unsafe { (entry_from_abi(entry), Utf16String::from_raw_owned(target_selector)) };
+ *entry.target_selector.borrow_mut() = target_selector;
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_interaction_id(entry: *mut c_void) -> u64 {
+ // SAFETY: The caller passes a live entry.
+ unsafe { entry_from_abi(entry) }.interaction_id.get()
+}
+
+/// # Safety
+///
+/// `entry` must be the live cell of a PerformanceEventTiming.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_event_timing_set_interaction_id(entry: *mut c_void, interaction_id: u64) {
+ // SAFETY: The caller passes a live entry.
+ unsafe { entry_from_abi(entry) }.interaction_id.set(interaction_id);
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/fetch_timing_info.rs b/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/fetch_timing_info.rs
new file mode 100644
index 00000000000..dedb3fd08ce
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/fetch_timing_info.rs
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+use core::ffi::c_void;
+use core::ptr::NonNull;
+
+use ak::Span;
+
+unsafe extern "C" {
+ fn web_fetch_timing_info_read(timing_info: *mut c_void, values: *mut FetchTimingInfo);
+ fn web_fetch_timing_info_alpn_negotiated_protocol(
+ timing_info: *mut c_void,
+ context: *mut c_void,
+ callback: unsafe extern "C" fn(*mut c_void, Span<'_, u8>),
+ );
+ fn web_fetch_timing_info_for_each_server_timing_header(
+ timing_info: *mut c_void,
+ context: *mut c_void,
+ callback: unsafe extern "C" fn(*mut c_void, Span<'_, u8>),
+ );
+ fn web_fetch_timing_info_unref(timing_info: *mut c_void);
+}
+
+/// https://fetch.spec.whatwg.org/#connection-timing-info
+#[derive(Clone, Copy, Default)]
+#[repr(C)]
+pub(crate) struct ConnectionTimingInfo {
+ pub(crate) domain_lookup_start_time: f64,
+ pub(crate) domain_lookup_end_time: f64,
+ pub(crate) connection_start_time: f64,
+ pub(crate) connection_end_time: f64,
+ pub(crate) secure_connection_start_time: f64,
+}
+
+/// https://fetch.spec.whatwg.org/#fetch-timing-info
+#[derive(Clone, Copy, Default)]
+#[repr(C)]
+pub(crate) struct FetchTimingInfo {
+ pub(crate) start_time: f64,
+ pub(crate) redirect_start_time: f64,
+ pub(crate) redirect_end_time: f64,
+ pub(crate) post_redirect_start_time: f64,
+ pub(crate) final_service_worker_start_time: f64,
+ pub(crate) final_network_request_start_time: f64,
+ pub(crate) first_interim_network_response_start_time: f64,
+ pub(crate) final_network_response_start_time: f64,
+ pub(crate) end_time: f64,
+ final_connection_timing_info: ConnectionTimingInfo,
+ has_final_connection_timing_info: bool,
+ pub(crate) render_blocking: bool,
+}
+
+impl FetchTimingInfo {
+ pub(crate) fn final_connection_timing_info(&self) -> Option<ConnectionTimingInfo> {
+ self.has_final_connection_timing_info
+ .then_some(self.final_connection_timing_info)
+ }
+}
+
+/// https://fetch.spec.whatwg.org/#fetch-timing-info
+pub(crate) struct CppFetchTimingInfo(NonNull<c_void>);
+
+impl CppFetchTimingInfo {
+ /// # Safety
+ ///
+ /// `timing_info` must be a fetch timing info that LibWeb hands over a reference to.
+ pub(crate) unsafe fn adopt(timing_info: *mut c_void) -> Self {
+ Self(NonNull::new(timing_info).expect("LibWeb hands over a fetch timing info"))
+ }
+
+ pub(crate) fn read(&self) -> FetchTimingInfo {
+ let mut values = FetchTimingInfo::default();
+ // SAFETY: This holds a reference to the timing info, and LibWeb writes its values.
+ unsafe { web_fetch_timing_info_read(self.0.as_ptr(), &raw mut values) };
+ values
+ }
+
+ /// https://fetch.spec.whatwg.org/#connection-timing-info-alpn-negotiated-protocol
+ pub(crate) fn alpn_negotiated_protocol(&self) -> Vec<u8> {
+ unsafe extern "C" fn copy(context: *mut c_void, protocol: Span<'_, u8>) {
+ // SAFETY: The context is the protocol below, and LibWeb lends the bytes for the call.
+ *unsafe { &mut *context.cast::<Vec<u8>>() } = protocol.as_slice().to_vec();
+ }
+ let mut protocol = Vec::new();
+ // SAFETY: This holds a reference to the timing info, and the protocol outlives the call.
+ unsafe { web_fetch_timing_info_alpn_negotiated_protocol(self.0.as_ptr(), (&raw mut protocol).cast(), copy) };
+ protocol
+ }
+
+ /// https://fetch.spec.whatwg.org/#fetch-timing-info-server-timing-headers
+ pub(crate) fn server_timing_headers(&self) -> Vec<Vec<u8>> {
+ unsafe extern "C" fn append(context: *mut c_void, header: Span<'_, u8>) {
+ // SAFETY: The context is the list below, and LibWeb lends the header for the call.
+ unsafe { &mut *context.cast::<Vec<Vec<u8>>>() }.push(header.as_slice().to_vec());
+ }
+ let mut headers = Vec::new();
+ // SAFETY: This holds a reference to the timing info, and the list outlives the call.
+ unsafe {
+ web_fetch_timing_info_for_each_server_timing_header(self.0.as_ptr(), (&raw mut headers).cast(), append);
+ };
+ headers
+ }
+}
+
+impl Drop for CppFetchTimingInfo {
+ fn drop(&mut self) {
+ // SAFETY: This holds a reference to the timing info, which it lets go of.
+ unsafe { web_fetch_timing_info_unref(self.0.as_ptr()) };
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/mod.rs
index acb9980c41b..ac95facc772 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/fetch/infrastructure/mod.rs
@@ -7,4 +7,5 @@
//! Infrastructure, https://fetch.spec.whatwg.org/#infrastructure
pub(crate) mod fetch_controller;
+pub(crate) mod fetch_timing_info;
pub(crate) mod http;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs b/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs
index e8728f55429..8cbd6616278 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs
@@ -8,35 +8,31 @@
//! Performance, https://w3c.github.io/hr-time/#sec-performance
+use core::cell::Cell;
use core::ffi::c_void;
use core::ptr::NonNull;
use ak::Utf16String;
-use libjs_rust::api::{Gc, GcRefCell, MarkedVec, Realm, Trace, Value, Vm, utf16_formatted};
+use libjs_rust::api::{Gc, MarkedVec, Realm, Trace, Value, Vm, utf16_formatted};
-use crate::bindings::conversions::CppInterface;
-use crate::bindings::cpp_cell::CppCell;
use crate::bindings::event_target::{CppEventTarget, GetTheParent};
use crate::bindings::global_object::{CppWindow, window_from_global_object};
use crate::bindings::interface::{Ref, Wrappable, allocate};
use crate::bindings::{CallContext, Exception, WebIdlResult};
-use crate::css::css_rule::wrap_cpp_cell;
use crate::event_timing::event_counts::EventCounts;
use crate::html::window_or_worker_global_scope::structured_clone;
-use crate::performance_timeline::performance_entry::wrap_entries;
+use crate::navigation_timing::performance_navigation::PerformanceNavigation;
+use crate::navigation_timing::performance_timing::{PerformanceTiming, is_performance_timing_attribute};
+use crate::performance_timeline::performance_entry::AnyPerformanceEntry;
use crate::performance_timeline::performance_timeline::{PerformanceTimeline, PerformanceTimelineRef};
-use crate::user_timing::performance_mark::{PerformanceMarkOptions, run_the_performance_mark_constructor};
-use crate::user_timing::performance_measure::{
- DOMStringOrDouble, PerformanceMeasureOptions, create_performance_measure,
+use crate::user_timing::performance_mark::{
+ PerformanceMark, PerformanceMarkOptions, run_the_performance_mark_constructor,
};
+use crate::user_timing::performance_measure::{DOMStringOrDouble, PerformanceMeasure, PerformanceMeasureOptions};
unsafe extern "C" {
fn web_high_resolution_time_current_high_resolution_time(global_object: *mut c_void) -> f64;
fn web_high_resolution_time_get_time_origin_timestamp(global_object: *mut c_void) -> f64;
- fn web_navigation_timing_performance_timing_create(window: *mut c_void) -> *mut c_void;
- fn web_navigation_timing_performance_navigation_create(window: *mut c_void) -> *mut c_void;
- fn web_navigation_timing_is_performance_timing_attribute(name: usize) -> bool;
- fn web_navigation_timing_performance_timing_attribute(timing: *mut c_void, name: usize) -> u64;
fn web_event_timing_interaction_count(window: *mut c_void) -> u64;
}
@@ -51,8 +47,8 @@ pub(crate) enum DOMStringOrPerformanceMeasureOptions {
pub(crate) struct Performance {
event_target: CppEventTarget,
realm: Gc<Realm>,
- timing: GcRefCell<Option<CppCell>>,
- navigation: GcRefCell<Option<CppCell>>,
+ timing: Cell<Option<Ref<PerformanceTiming>>>,
+ navigation: Cell<Option<Ref<PerformanceNavigation>>>,
}
impl Wrappable for Performance {
@@ -71,18 +67,13 @@ impl GetTheParent for Performance {
}
}
-fn is_performance_timing_attribute(name: &Utf16String) -> bool {
- // SAFETY: The name is lent for the call.
- unsafe { web_navigation_timing_is_performance_timing_attribute(name.raw_identity()) }
-}
-
impl Performance {
pub(crate) fn create(vm: &Vm, realm: Gc<Realm>) -> Ref<Self> {
let performance = allocate(vm, |_| Self {
event_target: CppEventTarget::new(),
realm,
- timing: GcRefCell::default(),
- navigation: GcRefCell::default(),
+ timing: Cell::new(None),
+ navigation: Cell::new(None),
});
performance.event_target.set_owner(performance);
performance
@@ -100,33 +91,30 @@ impl Performance {
window_from_global_object(self.realm.global_object())
}
- fn timing_cell(&self, vm: &Vm) -> CppCell {
- if let Some(timing) = self.timing.borrow().as_ref() {
- return timing.clone();
+ fn timing_object(&self, vm: &Vm) -> Ref<PerformanceTiming> {
+ if let Some(timing) = self.timing.get() {
+ return timing;
}
let window = self.window().expect("only a Window has a PerformanceTiming");
- // SAFETY: The Window is live, and LibWeb returns a new, live PerformanceTiming.
- let timing = unsafe { CppCell::from_raw(web_navigation_timing_performance_timing_create(window.as_ptr())) };
- *self.timing.borrow_mut(vm) = Some(timing.clone());
+ let timing = allocate(vm, |_| PerformanceTiming::new(window));
+ self.timing.set(Some(timing));
timing
}
// https://w3c.github.io/navigation-timing/#dom-performance-timing
- pub(crate) fn timing(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
- Ok(wrap_cpp_cell(cx, &self.timing_cell(cx.vm())))
+ pub(crate) fn timing(&self, cx: &mut CallContext) -> WebIdlResult<Ref<PerformanceTiming>> {
+ Ok(self.timing_object(cx.vm()))
}
// https://w3c.github.io/navigation-timing/#dom-performance-navigation
- pub(crate) fn navigation(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
- if let Some(navigation) = self.navigation.borrow().as_ref() {
- return Ok(wrap_cpp_cell(cx, navigation));
+ pub(crate) fn navigation(&self, cx: &mut CallContext) -> WebIdlResult<Ref<PerformanceNavigation>> {
+ if let Some(navigation) = self.navigation.get() {
+ return Ok(navigation);
}
let window = self.window().expect("only a Window has a PerformanceNavigation");
- // SAFETY: The Window is live, and LibWeb returns a new, live PerformanceNavigation.
- let navigation =
- unsafe { CppCell::from_raw(web_navigation_timing_performance_navigation_create(window.as_ptr())) };
- *self.navigation.borrow_mut(cx.vm()) = Some(navigation.clone());
- Ok(wrap_cpp_cell(cx, &navigation))
+ let navigation = allocate(cx.vm(), |_| PerformanceNavigation::new(window));
+ self.navigation.set(Some(navigation));
+ Ok(navigation)
}
// https://w3c.github.io/event-timing/#dom-performance-eventcounts
@@ -168,21 +156,21 @@ impl Performance {
cx: &mut CallContext,
mark_name: Utf16String,
mark_options: PerformanceMarkOptions,
- ) -> WebIdlResult<CppInterface> {
+ ) -> WebIdlResult<Ref<PerformanceMark>> {
let vm = cx.vm();
// 1. Run the PerformanceMark constructor and let entry be the newly created object.
- let entry = run_the_performance_mark_constructor(self.realm, &mark_name, &mark_options)?;
+ let entry = run_the_performance_mark_constructor(cx, self.realm, mark_name, &mark_options)?;
// 2. Queue entry.
let timeline = self.performance_timeline(vm);
- timeline.queue_performance_entry(vm, &entry);
+ timeline.queue_performance_entry(vm, &AnyPerformanceEntry::PerformanceMark(entry));
// 3. Add entry to the performance entry buffer.
- timeline.add_performance_entry(vm, &entry, false);
+ timeline.add_performance_entry(vm, &AnyPerformanceEntry::PerformanceMark(entry), false);
// 4. Return entry.
- Ok(entry.wrap(cx))
+ Ok(entry)
}
pub(crate) fn clear_marks(&self, cx: &mut CallContext, mark_name: Option<Utf16String>) -> WebIdlResult<()> {
@@ -217,21 +205,14 @@ impl Performance {
return Ok(0.0);
}
- let timing = self.timing_cell(vm);
+ let timing = self.timing_object(vm);
+ let mut cx = CallContext::new(vm, self.realm);
// 3. Let startTime be the value of navigationStart in the PerformanceTiming interface.
- // SAFETY: The PerformanceTiming is live, and the name is lent for the call.
- let start_time = unsafe {
- web_navigation_timing_performance_timing_attribute(
- timing.as_ptr(),
- Utf16String::from_utf8("navigationStart").raw_identity(),
- )
- };
+ let start_time = timing.navigation_start(&mut cx)?;
// 4. Let endTime be the value of name in the PerformanceTiming interface.
- // SAFETY: The PerformanceTiming is live, and the name is lent for the call.
- let end_time =
- unsafe { web_navigation_timing_performance_timing_attribute(timing.as_ptr(), name.raw_identity()) };
+ let end_time = timing.attribute(&mut cx, name)?;
// 5. If endTime is 0, throw an InvalidAccessError.
if end_time == 0 {
@@ -301,7 +282,7 @@ impl Performance {
measure_name: Utf16String,
start_or_measure_options: DOMStringOrPerformanceMeasureOptions,
end_mark: Option<Utf16String>,
- ) -> WebIdlResult<CppInterface> {
+ ) -> WebIdlResult<Ref<PerformanceMeasure>> {
let vm = cx.vm();
// 1. If startOrMeasureOptions is a PerformanceMeasureOptions object and at least one of start, end, duration, and detail
@@ -420,17 +401,17 @@ impl Performance {
{
detail = structured_clone(&CallContext::new(vm, self.realm), options_detail, &[])?;
}
- let entry = create_performance_measure(&measure_name, start_time, duration, detail);
+ let entry = PerformanceMeasure::create(vm, measure_name, start_time, duration, detail);
// 10. Queue entry.
let timeline = self.performance_timeline(vm);
- timeline.queue_performance_entry(vm, &entry);
+ timeline.queue_performance_entry(vm, &AnyPerformanceEntry::PerformanceMeasure(entry));
// 11. Add entry to the performance entry buffer.
- timeline.add_performance_entry(vm, &entry, false);
+ timeline.add_performance_entry(vm, &AnyPerformanceEntry::PerformanceMeasure(entry), false);
// 12. Return entry.
- Ok(entry.wrap(cx))
+ Ok(entry)
}
// https://w3c.github.io/user-timing/#dom-performance-clearmeasures
@@ -472,13 +453,16 @@ impl Performance {
}
// https://w3c.github.io/performance-timeline/#getentries-method
- pub(crate) fn get_entries<'vm>(&self, cx: &mut CallContext<'vm>) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ pub(crate) fn get_entries<'vm>(
+ &self,
+ cx: &mut CallContext<'vm>,
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// Returns a PerformanceEntryList object returned by the filter buffer map by name and type algorithm with name and
// type set to null.
let entries = self
.performance_timeline(cx.vm())
.filter_buffer_map_by_name_and_type(cx, None, None);
- Ok(wrap_entries(cx, &entries))
+ Ok(entries)
}
// https://w3c.github.io/performance-timeline/#dom-performance-getentriesbytype
@@ -486,13 +470,13 @@ impl Performance {
&self,
cx: &mut CallContext<'vm>,
r#type: Utf16String,
- ) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// Returns a PerformanceEntryList object returned by filter buffer map by name and type algorithm with name set to null,
// and type set to the method's input type parameter.
let entries = self
.performance_timeline(cx.vm())
.filter_buffer_map_by_name_and_type(cx, None, Some(&r#type));
- Ok(wrap_entries(cx, &entries))
+ Ok(entries)
}
// https://w3c.github.io/performance-timeline/#dom-performance-getentriesbyname
@@ -501,13 +485,13 @@ impl Performance {
cx: &mut CallContext<'vm>,
name: Utf16String,
r#type: Option<Utf16String>,
- ) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// Returns a PerformanceEntryList object returned by filter buffer map by name and type algorithm with name set to the
// method input name parameter, and type set to null if optional entryType is omitted, or set to the method's input type
// parameter otherwise.
let entries =
self.performance_timeline(cx.vm())
.filter_buffer_map_by_name_and_type(cx, Some(&name), r#type.as_ref());
- Ok(wrap_entries(cx, &entries))
+ Ok(entries)
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs
index c90d775bc1c..1ae14a87159 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs
@@ -85,6 +85,8 @@ pub(crate) mod structured_serialize;
#[cfg(not(test))]
pub(crate) mod text_metrics;
#[cfg(not(test))]
+pub(crate) mod visibility_state_entry;
+#[cfg(not(test))]
pub(crate) mod window;
#[cfg(not(test))]
pub(crate) mod window_or_worker_global_scope;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/visibility_state_entry.rs b/Libraries/LibWeb/Bindings/Rust/src/html/visibility_state_entry.rs
new file mode 100644
index 00000000000..8175ae4420c
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/visibility_state_entry.rs
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! VisibilityStateEntry, https://html.spec.whatwg.org/multipage/interaction.html#visibilitystateentry
+
+use core::ffi::c_void;
+
+use ak::Utf16String;
+use libjs_rust::api::{Trace, Vm};
+
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate, cell_into_abi};
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
+
+/// https://html.spec.whatwg.org/multipage/interaction.html#visibilitystateentry
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct VisibilityStateEntry {
+ entry: PerformanceEntry,
+}
+
+impl Wrappable for VisibilityStateEntry {}
+
+impl Inherits<PerformanceEntry> for VisibilityStateEntry {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+impl VisibilityStateEntry {
+ pub(crate) fn create(vm: &Vm, visibility_state: Utf16String, timestamp: f64) -> Ref<Self> {
+ let entry = allocate(vm, |_| Self {
+ // The name getter steps are to return this's visibility state.
+ // The entryType getter steps are to return "visibility-state".
+ // The startTime getter steps are to return this's timestamp.
+ // The duration getter steps are to return zero.
+ entry: PerformanceEntry::new(
+ visibility_state,
+ Utf16String::from_utf8("visibility-state"),
+ timestamp,
+ 0.0,
+ ),
+ });
+ let any_entry = AnyPerformanceEntry::VisibilityStateEntry(entry);
+ any_entry.entry().set_object(any_entry);
+ entry
+ }
+}
+
+/// https://html.spec.whatwg.org/multipage/interaction.html#visibilitystateentry
+///
+/// # Safety
+///
+/// `vm` must be the live VM, and `visibility_state` a raw AK::Utf16String that C++ hands over.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_html_create_visibility_state_entry(
+ vm: *mut c_void,
+ visibility_state: usize,
+ timestamp: f64,
+) -> *mut c_void {
+ // SAFETY: The caller passes the live VM and hands over the string.
+ let (vm, visibility_state) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(visibility_state)) };
+ cell_into_abi(VisibilityStateEntry::create(vm, visibility_state, timestamp))
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/largest_contentful_paint/largest_contentful_paint.rs b/Libraries/LibWeb/Bindings/Rust/src/largest_contentful_paint/largest_contentful_paint.rs
new file mode 100644
index 00000000000..e7d309ba27a
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/largest_contentful_paint/largest_contentful_paint.rs
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! LargestContentfulPaint, https://w3c.github.io/largest-contentful-paint/#sec-largest-contentful-paint-interface
+
+use core::ffi::c_void;
+
+use ak::Utf16String;
+use libjs_rust::api::{Trace, Vm};
+
+use crate::bindings::conversions::CppInterface;
+use crate::bindings::cpp_cell::{CppCell, WeakCppCell};
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate, cell_into_abi};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::css::css_rule::wrap_cpp_cell;
+use crate::paint_timing::paint_timing::is_exposed_for_paint_timing;
+use crate::paint_timing::paint_timing_mixin::{PaintTimingInfo, PaintTimingMixin, default_paint_timestamp};
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
+
+/// https://w3c.github.io/largest-contentful-paint/#sec-largest-contentful-paint-interface
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct LargestContentfulPaint {
+ entry: PerformanceEntry,
+ #[gc(untraced)]
+ paint_timing_mixin: PaintTimingMixin,
+ /// https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-size
+ size: u32,
+ /// https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-loadtime
+ load_time: f64,
+ /// https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-id
+ id: Utf16String,
+ /// https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-url
+ url: Utf16String,
+ /// https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-element
+ // NB: Held weakly, as the element getter returns null for an element that is not connected.
+ element: WeakCppCell,
+}
+
+impl Wrappable for LargestContentfulPaint {}
+
+impl Inherits<PerformanceEntry> for LargestContentfulPaint {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+impl LargestContentfulPaint {
+ // https://w3c.github.io/largest-contentful-paint/#create-a-largestcontentfulpaint-entry
+ pub(crate) fn create(
+ vm: &Vm,
+ paint_timing_info: PaintTimingInfo,
+ size: u32,
+ url: Utf16String,
+ id: Utf16String,
+ load_time: f64,
+ element: &CppCell,
+ ) -> Ref<Self> {
+ let entry = allocate(vm, |_| Self {
+ // The name attribute's getter must return the empty string.
+ // The startTime attribute's getter must return the value of this's renderTime.
+ // The duration attribute's getter must return 0.
+ entry: PerformanceEntry::new(
+ Utf16String::default(),
+ Utf16String::from_utf8("largest-contentful-paint"),
+ default_paint_timestamp(&paint_timing_info),
+ 0.0,
+ ),
+ paint_timing_mixin: PaintTimingMixin::new(paint_timing_info),
+ size,
+ load_time,
+ id,
+ url,
+ element: WeakCppCell::new(vm, element),
+ });
+ let any_entry = AnyPerformanceEntry::LargestContentfulPaint(entry);
+ any_entry.entry().set_object(any_entry);
+ entry
+ }
+
+ // https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-loadtime
+ pub(crate) fn load_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The loadTime attribute must return the value of this's loadTime.
+ Ok(self.load_time)
+ }
+
+ // https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-rendertime
+ pub(crate) fn render_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The renderTime attribute must return the default paint timestamp given this's paint timing info.
+ Ok(default_paint_timestamp(self.paint_timing_mixin.paint_timing_info()))
+ }
+
+ // https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-size
+ pub(crate) fn size(&self, _: &mut CallContext) -> WebIdlResult<u32> {
+ // The size attribute must return the value of this's size.
+ Ok(self.size)
+ }
+
+ // https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-id
+ pub(crate) fn id(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The id attribute must return the value of this's id.
+ Ok(self.id.clone())
+ }
+
+ // https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-url
+ pub(crate) fn url(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The url attribute must return the value of this's url.
+ Ok(self.url.clone())
+ }
+
+ // https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-element
+ pub(crate) fn element(&self, cx: &mut CallContext) -> WebIdlResult<Option<CppInterface>> {
+ // 1. If this's element is not exposed for paint timing given null, return null.
+ let Some(element) = self.element.get().filter(is_exposed_for_paint_timing) else {
+ return Ok(None);
+ };
+
+ // 2. Return this's element.
+ Ok(Some(wrap_cpp_cell(cx, &element)))
+ }
+
+ pub(crate) fn paint_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ Ok(self.paint_timing_mixin.paint_time())
+ }
+
+ pub(crate) fn presentation_time(&self, _: &mut CallContext) -> WebIdlResult<Option<f64>> {
+ Ok(self.paint_timing_mixin.presentation_time())
+ }
+}
+
+/// https://w3c.github.io/largest-contentful-paint/#create-a-largestcontentfulpaint-entry
+///
+/// # Safety
+///
+/// `vm` must be the live VM, `url` and `id` raw AK::Utf16Strings that C++ hands over, and `element` a live Element.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_largest_contentful_paint_create(
+ vm: *mut c_void,
+ rendering_update_end_time: f64,
+ has_presentation_time: bool,
+ presentation_time: f64,
+ size: u32,
+ url: usize,
+ id: usize,
+ load_time: f64,
+ element: *mut c_void,
+) -> *mut c_void {
+ // SAFETY: The caller passes the live VM and a live Element, and hands over the strings.
+ let (vm, url, id, element) = unsafe {
+ (
+ &*vm.cast::<Vm>(),
+ Utf16String::from_raw_owned(url),
+ Utf16String::from_raw_owned(id),
+ CppCell::from_raw(element),
+ )
+ };
+ let paint_timing_info =
+ PaintTimingInfo::from_abi(rendering_update_end_time, has_presentation_time, presentation_time);
+ cell_into_abi(LargestContentfulPaint::create(
+ vm,
+ paint_timing_info,
+ size,
+ url,
+ id,
+ load_time,
+ &element,
+ ))
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/largest_contentful_paint/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/largest_contentful_paint/mod.rs
new file mode 100644
index 00000000000..de3f9fc5999
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/largest_contentful_paint/mod.rs
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! Largest Contentful Paint, https://w3c.github.io/largest-contentful-paint/
+
+#[allow(
+ clippy::module_inception,
+ reason = "the module mirrors the specification's LargestContentfulPaint interface, which the crate module is named after"
+)]
+pub(crate) mod largest_contentful_paint;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/lib.rs b/Libraries/LibWeb/Bindings/Rust/src/lib.rs
index 751c6490681..d95779f70c5 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/lib.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/lib.rs
@@ -101,6 +101,10 @@ pub(crate) mod encoding;
not(web_idl_bindings),
allow(dead_code, reason = "only the generated bindings use the interfaces")
)]
+#[allow(
+ clippy::unnecessary_wraps,
+ reason = "the bindings call every attribute and operation as one that can throw"
+)]
pub(crate) mod event_timing;
#[cfg(not(test))]
pub(crate) mod fetch;
@@ -151,6 +155,26 @@ pub(crate) mod html;
reason = "the bindings call every attribute and operation as one that can throw"
)]
pub(crate) mod indexed_db;
+#[cfg(not(test))]
+#[cfg_attr(
+ not(web_idl_bindings),
+ allow(dead_code, reason = "only the generated bindings use the interfaces")
+)]
+#[allow(
+ clippy::unnecessary_wraps,
+ reason = "the bindings call every attribute and operation as one that can throw"
+)]
+pub(crate) mod largest_contentful_paint;
+#[cfg(not(test))]
+#[cfg_attr(
+ not(web_idl_bindings),
+ allow(dead_code, reason = "only the generated bindings use the interfaces")
+)]
+#[allow(
+ clippy::unnecessary_wraps,
+ reason = "the bindings call every attribute and operation as one that can throw"
+)]
+pub(crate) mod navigation_timing;
#[cfg_attr(
not(web_idl_bindings),
allow(dead_code, reason = "only the generated bindings use the interfaces")
@@ -165,9 +189,29 @@ pub(crate) mod notifications_api;
clippy::unnecessary_wraps,
reason = "the bindings call every attribute and operation as one that can throw"
)]
+pub(crate) mod paint_timing;
+#[cfg(not(test))]
+#[cfg_attr(
+ not(web_idl_bindings),
+ allow(dead_code, reason = "only the generated bindings use the interfaces")
+)]
+#[allow(
+ clippy::unnecessary_wraps,
+ reason = "the bindings call every attribute and operation as one that can throw"
+)]
pub(crate) mod performance_timeline;
#[cfg(not(test))]
pub(crate) mod platform;
+#[cfg(not(test))]
+#[cfg_attr(
+ not(web_idl_bindings),
+ allow(dead_code, reason = "only the generated bindings use the interfaces")
+)]
+#[allow(
+ clippy::unnecessary_wraps,
+ reason = "the bindings call every attribute and operation as one that can throw"
+)]
+pub(crate) mod resource_timing;
#[cfg_attr(
not(web_idl_bindings),
allow(dead_code, reason = "only the generated bindings use the interfaces")
diff --git a/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/mod.rs
new file mode 100644
index 00000000000..d830faa585e
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/mod.rs
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! Navigation Timing, https://w3c.github.io/navigation-timing/
+
+pub(crate) mod performance_navigation;
+pub(crate) mod performance_navigation_timing;
+pub(crate) mod performance_timing;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation.rs b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation.rs
new file mode 100644
index 00000000000..981e8c21f61
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation.rs
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2024, Colin Reeder <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PerformanceNavigation, https://w3c.github.io/navigation-timing/#the-performancenavigation-interface
+
+use libjs_rust::api::Trace;
+
+use crate::bindings::global_object::CppWindow;
+use crate::bindings::interface::{Ref, Wrappable};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::navigation_timing::performance_navigation_timing::{NavigationTimingType, PerformanceNavigationTiming};
+
+const TYPE_NAVIGATE: u16 = 0;
+const TYPE_RELOAD: u16 = 1;
+const TYPE_BACK_FORWARD: u16 = 2;
+
+/// https://w3c.github.io/navigation-timing/#the-performancenavigation-interface
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceNavigation {
+ window: CppWindow,
+}
+
+impl Wrappable for PerformanceNavigation {}
+
+impl PerformanceNavigation {
+ pub(crate) fn new(window: CppWindow) -> Self {
+ Self { window }
+ }
+
+ fn navigation_timing_entry(&self) -> Option<Ref<PerformanceNavigationTiming>> {
+ self.window.associated_document().navigation_timing_entry()
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigation-type
+ pub(crate) fn r#type(&self, cx: &mut CallContext) -> WebIdlResult<u16> {
+ // This attribute must return the type of the last non-redirect navigation. It must have one of the following
+ // navigation type values.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(TYPE_NAVIGATE);
+ };
+
+ Ok(match entry.r#type(cx)? {
+ NavigationTimingType::Navigate => TYPE_NAVIGATE,
+ NavigationTimingType::Reload => TYPE_RELOAD,
+ NavigationTimingType::BackForward => TYPE_BACK_FORWARD,
+ })
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigation-redirectcount
+ pub(crate) fn redirect_count(&self, cx: &mut CallContext) -> WebIdlResult<u16> {
+ // This attribute must return the number of redirects since the last non-redirect navigation. If there is no
+ // redirect or there is any redirect that is not from the same origin as the destination document, this attribute
+ // must return zero.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+
+ entry.redirect_count(cx)
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation_timing.rs
new file mode 100644
index 00000000000..4184c37669e
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation_timing.rs
@@ -0,0 +1,264 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PerformanceNavigationTiming, https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming
+
+use core::ffi::c_void;
+
+use ak::Utf16String;
+use libjs_rust::api::{Gc, Realm, Trace, Vm};
+
+use crate::bindings::environment_settings_object::relevant_settings_object;
+use crate::bindings::interface::{Inherits, Wrappable, allocate, realm_arguments};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::dom::document::CppDocument;
+use crate::fetch::infrastructure::fetch_timing_info::CppFetchTimingInfo;
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
+use crate::performance_timeline::performance_timeline::PerformanceTimeline;
+use crate::resource_timing::performance_resource_timing::{
+ CacheState, PerformanceResourceTiming, ResponseBodyInfo, ResponseBodyInfoAbi,
+};
+
+/// https://w3c.github.io/navigation-timing/#dom-navigationtimingtype
+#[derive(Clone, Copy)]
+pub(crate) enum NavigationTimingType {
+ Navigate,
+ Reload,
+ BackForward,
+}
+
+impl NavigationTimingType {
+ fn from_abi(navigation_type: u8) -> Self {
+ match navigation_type {
+ 0 => Self::Navigate,
+ 1 => Self::Reload,
+ 2 => Self::BackForward,
+ _ => unreachable!("C++ passes a navigation timing type"),
+ }
+ }
+}
+
+/// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceNavigationTiming {
+ resource_timing: PerformanceResourceTiming,
+ document: CppDocument,
+ redirect_count: u16,
+ #[gc(untraced)]
+ navigation_type: NavigationTimingType,
+}
+
+impl Wrappable for PerformanceNavigationTiming {}
+
+impl Inherits<PerformanceResourceTiming> for PerformanceNavigationTiming {
+ fn parent(&self) -> &PerformanceResourceTiming {
+ &self.resource_timing
+ }
+}
+
+impl PerformanceNavigationTiming {
+ // https://w3c.github.io/navigation-timing/#performanceentry
+ pub(crate) fn duration(&self) -> f64 {
+ // The duration getter step is to return a DOMHighResTimeStamp equal to the difference between loadEventEnd and
+ // this's startTime.
+ self.document.load_timing_info().load_event_end_time
+ }
+
+ // https://w3c.github.io/navigation-timing/#PerformanceResourceTiming
+ pub(crate) fn redirect_start(&self) -> f64 {
+ // 1. If this's redirect count is 0, return 0.
+ if self.redirect_count == 0 {
+ return 0.0;
+ }
+
+ // 2. Otherwise return this's redirectStart.
+ self.resource_timing.resource_timing_redirect_start()
+ }
+
+ // https://w3c.github.io/navigation-timing/#PerformanceResourceTiming
+ pub(crate) fn redirect_end(&self) -> f64 {
+ // 1. If this's redirect count is 0, return 0.
+ if self.redirect_count == 0 {
+ return 0.0;
+ }
+
+ // 2. Otherwise return this's redirectEnd.
+ self.resource_timing.resource_timing_redirect_end()
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-unloadeventstart
+ pub(crate) fn unload_event_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The unloadEventStart getter steps are to return this's previous document unload timing's unload event start
+ // time.
+ Ok(self.document.previous_document_unload_timing().unload_event_start_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-unloadeventend
+ pub(crate) fn unload_event_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The unloadEventEnd getter steps are to return this's previous document unload timing's unload event end time.
+ Ok(self.document.previous_document_unload_timing().unload_event_end_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-dominteractive
+ pub(crate) fn dom_interactive(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The domInteractive getter steps are to return this's document load timing's DOM interactive time.
+ Ok(self.document.load_timing_info().dom_interactive_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-domcontentloadedeventstart
+ pub(crate) fn dom_content_loaded_event_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The domContentLoadedEventStart getter steps are to return this's document load timing's DOM content loaded
+ // event start time.
+ Ok(self.document.load_timing_info().dom_content_loaded_event_start_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-domcontentloadedeventend
+ pub(crate) fn dom_content_loaded_event_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The domContentLoadedEventEnd getter steps are to return this's document load timing's DOM content loaded event
+ // end time.
+ Ok(self.document.load_timing_info().dom_content_loaded_event_end_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-domcomplete
+ pub(crate) fn dom_complete(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The domComplete getter steps are to return this's document load timing's DOM complete time.
+ Ok(self.document.load_timing_info().dom_complete_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-loadeventstart
+ pub(crate) fn load_event_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The loadEventStart getter steps are to return this's document load timing's load event start time.
+ Ok(self.document.load_timing_info().load_event_start_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-loadeventend
+ pub(crate) fn load_event_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The loadEventEnd getter steps are to return this's document load timing's load event end time.
+ Ok(self.document.load_timing_info().load_event_end_time)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-type
+ pub(crate) fn r#type(&self, _: &mut CallContext) -> WebIdlResult<NavigationTimingType> {
+ // The type getter steps are to run the this's navigation type.
+ Ok(self.navigation_type)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-redirectcount
+ pub(crate) fn redirect_count(&self, _: &mut CallContext) -> WebIdlResult<u16> {
+ // The redirectCount getter steps are to return this's redirect count.
+ Ok(self.redirect_count)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-criticalchrestart
+ pub(crate) fn critical_ch_restart(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The criticalCHRestart getter steps are to return this's `Critical-CH` restart time.
+ // FIXME: Implement the `Critical-CH` restart time.
+ Ok(0.0)
+ }
+}
+
+// https://w3c.github.io/navigation-timing/#dfn-create-the-navigation-timing-entry
+#[expect(clippy::too_many_arguments, reason = "these are the inputs of the algorithm")]
+fn create_the_navigation_timing_entry(
+ vm: &Vm,
+ realm: Gc<Realm>,
+ document: CppDocument,
+ document_url: Utf16String,
+ timing_info: CppFetchTimingInfo,
+ redirect_count: u16,
+ navigation_type: NavigationTimingType,
+ cache_mode: Option<CacheState>,
+ body_info: ResponseBodyInfo,
+ response_status: u16,
+) {
+ // 1. Let global be document's relevant global object.
+ // NB: The realm is that of global.
+
+ // 2. Let navigationTimingEntry be a new PerformanceNavigationTiming object in global's realm.
+ let time_origin = relevant_settings_object(realm.global_object()).time_origin();
+ let entry = PerformanceEntry::new(document_url, Utf16String::from_utf8("navigation"), 0.0, 0.0);
+
+ // 3. Setup the resource timing entry for navigationTimingEntry given "navigation", document's URL, fetchTiming,
+ // cacheMode, and bodyInfo.
+ let resource_timing = PerformanceResourceTiming::setup_the_resource_timing_entry(
+ entry,
+ time_origin,
+ Utf16String::from_utf8("navigation"),
+ timing_info,
+ cache_mode,
+ body_info,
+ response_status,
+ Utf16String::default(),
+ );
+
+ // 4. Set navigationTimingEntry's document load timing to document's load timing info
+ // 5. Set navigationTimingEntry's previous document unload timing to document's previous document unload timing.
+ // NB: The entry reads both from the document, which it keeps.
+ // 6. Set navigationTimingEntry's redirect count to redirectCount.
+ // 7. Set navigationTimingEntry's navigation type to navigationType.
+ // 8. Set navigationTimingEntry's service worker timing to serviceWorkerTiming.
+ // FIXME: Implement service worker timing.
+ let navigation_timing_entry = allocate(vm, |_| PerformanceNavigationTiming {
+ resource_timing,
+ document: document.clone(),
+ redirect_count,
+ navigation_type,
+ });
+ let entry = AnyPerformanceEntry::PerformanceNavigationTiming(navigation_timing_entry);
+ entry.entry().set_object(entry);
+
+ // 9. Set document's navigation timing entry to navigationTimingEntry.
+ document.set_navigation_timing_entry(navigation_timing_entry);
+
+ // 10. Set navigationTimingEntry's `Critical-CH` restart time to criticalCHRestart.
+ // FIXME: Implement the `Critical-CH` restart time.
+ // 11. Set navigationTimingEntry's not restored reasons to the result of creating a NotRestoredReasons object given
+ // document's not restored reasons.
+ // FIXME: Implement not restored reasons.
+
+ // 12. Add navigationTimingEntry to global's performance entry buffer.
+ PerformanceTimeline::of(vm, realm).add_performance_entry(vm, &entry, false);
+}
+
+/// https://w3c.github.io/navigation-timing/#dfn-create-the-navigation-timing-entry
+///
+/// # Safety
+///
+/// `vm` must be the live VM, `realm` the live realm of the document's relevant global object, `document` a live
+/// Document, `timing_info` a fetch timing info that LibWeb hands over a reference to, and `document_url` and the content
+/// type of `body_info` raw AK::Utf16Strings that LibWeb hands over.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_navigation_timing_create_the_navigation_timing_entry(
+ vm: *mut c_void,
+ realm: *mut c_void,
+ document: *mut c_void,
+ document_url: usize,
+ timing_info: *mut c_void,
+ redirect_count: u16,
+ navigation_type: u8,
+ cache_mode: u8,
+ body_info: ResponseBodyInfoAbi,
+ response_status: u16,
+) {
+ // SAFETY: The caller passes the live VM and a live realm.
+ let (vm, realm) = unsafe { realm_arguments(vm, realm) };
+ // SAFETY: The caller passes a live Document, hands over the timing info and the strings.
+ unsafe {
+ create_the_navigation_timing_entry(
+ vm,
+ realm,
+ CppDocument::from_raw(document),
+ Utf16String::from_raw_owned(document_url),
+ CppFetchTimingInfo::adopt(timing_info),
+ redirect_count,
+ NavigationTimingType::from_abi(navigation_type),
+ CacheState::from_abi(cache_mode),
+ body_info.into_body_info(),
+ response_status,
+ );
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_timing.rs
new file mode 100644
index 00000000000..cc4aac45132
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_timing.rs
@@ -0,0 +1,335 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <[email protected]>
+ * Copyright (c) 2025, Tim Ledbetter <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PerformanceTiming, https://w3c.github.io/navigation-timing/#the-performancetiming-interface
+
+use ak::Utf16String;
+use libjs_rust::api::Trace;
+
+use crate::bindings::global_object::CppWindow;
+use crate::bindings::interface::{Inherits, Ref, Wrappable};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::dom::document::CppDocument;
+use crate::navigation_timing::performance_navigation_timing::PerformanceNavigationTiming;
+
+unsafe extern "C" {
+ fn web_high_resolution_time_estimated_monotonic_time_of_the_unix_epoch() -> f64;
+ fn web_high_resolution_time_coarsen_time(timestamp: f64) -> f64;
+}
+
+type Attribute = fn(&PerformanceTiming, &mut CallContext<'_>) -> WebIdlResult<u64>;
+
+const ATTRIBUTES: [(&str, Attribute); 21] = [
+ ("connectEnd", PerformanceTiming::connect_end),
+ ("connectStart", PerformanceTiming::connect_start),
+ ("domainLookupEnd", PerformanceTiming::domain_lookup_end),
+ ("domainLookupStart", PerformanceTiming::domain_lookup_start),
+ ("domComplete", PerformanceTiming::dom_complete),
+ (
+ "domContentLoadedEventEnd",
+ PerformanceTiming::dom_content_loaded_event_end,
+ ),
+ (
+ "domContentLoadedEventStart",
+ PerformanceTiming::dom_content_loaded_event_start,
+ ),
+ ("domInteractive", PerformanceTiming::dom_interactive),
+ ("domLoading", PerformanceTiming::dom_loading),
+ ("fetchStart", PerformanceTiming::fetch_start),
+ ("loadEventEnd", PerformanceTiming::load_event_end),
+ ("loadEventStart", PerformanceTiming::load_event_start),
+ ("navigationStart", PerformanceTiming::navigation_start),
+ ("redirectEnd", PerformanceTiming::redirect_end),
+ ("redirectStart", PerformanceTiming::redirect_start),
+ ("requestStart", PerformanceTiming::request_start),
+ ("responseEnd", PerformanceTiming::response_end),
+ ("responseStart", PerformanceTiming::response_start),
+ ("secureConnectionStart", PerformanceTiming::secure_connection_start),
+ ("unloadEventEnd", PerformanceTiming::unload_event_end),
+ ("unloadEventStart", PerformanceTiming::unload_event_start),
+];
+
+fn attribute_named(name: &Utf16String) -> Option<Attribute> {
+ ATTRIBUTES
+ .iter()
+ .find(|(attribute_name, _)| *name == Utf16String::from_utf8(attribute_name))
+ .map(|(_, attribute)| *attribute)
+}
+
+pub(crate) fn is_performance_timing_attribute(name: &Utf16String) -> bool {
+ attribute_named(name).is_some()
+}
+
+/// https://w3c.github.io/navigation-timing/#the-performancetiming-interface
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceTiming {
+ window: CppWindow,
+}
+
+impl Wrappable for PerformanceTiming {}
+
+// All time values are measured in milliseconds since midnight of January 1, 1970 (UTC).
+fn monotonic_timestamp_to_wall_time_milliseconds(timestamp: f64) -> u64 {
+ if timestamp == 0.0 {
+ return 0;
+ }
+
+ // SAFETY: These read the clock.
+ let wall_time = timestamp - unsafe { web_high_resolution_time_estimated_monotonic_time_of_the_unix_epoch() };
+ let coarsened_time = unsafe { web_high_resolution_time_coarsen_time(wall_time) };
+ #[expect(
+ clippy::cast_possible_truncation,
+ clippy::cast_sign_loss,
+ reason = "C++ casts it to u64"
+ )]
+ let milliseconds = coarsened_time as u64;
+ milliseconds
+}
+
+impl PerformanceTiming {
+ pub(crate) fn new(window: CppWindow) -> Self {
+ Self { window }
+ }
+
+ pub(crate) fn attribute(&self, cx: &mut CallContext, name: &Utf16String) -> WebIdlResult<u64> {
+ attribute_named(name).expect("the name is that of a PerformanceTiming attribute")(self, cx)
+ }
+
+ fn document(&self) -> CppDocument {
+ self.window.associated_document()
+ }
+
+ fn navigation_timing_entry(&self) -> Option<Ref<PerformanceNavigationTiming>> {
+ self.document().navigation_timing_entry()
+ }
+
+ // The document's time origin is its navigation start time, so a timestamp relative to it becomes monotonic by adding
+ // that back. A fetch phase coinciding with navigation start is 0 relative to the time origin without being unset.
+ fn fetch_phase_to_wall_time_milliseconds(&self, relative_timestamp: f64) -> u64 {
+ monotonic_timestamp_to_wall_time_milliseconds(
+ relative_timestamp + self.document().load_timing_info().navigation_start_time,
+ )
+ }
+
+ fn relative_timestamp_to_wall_time_milliseconds(&self, relative_timestamp: f64) -> u64 {
+ if relative_timestamp == 0.0 {
+ return 0;
+ }
+
+ self.fetch_phase_to_wall_time_milliseconds(relative_timestamp)
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-navigationstart
+ pub(crate) fn navigation_start(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately after the user agent finishes prompting to unload the previous
+ // document. If there is no previous document, this attribute must return the time the current document is created.
+ Ok(monotonic_timestamp_to_wall_time_milliseconds(
+ self.document().load_timing_info().navigation_start_time,
+ ))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-unloadeventstart
+ pub(crate) fn unload_event_start(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // If the previous document and the current document have the same origin, this attribute must return the time
+ // immediately before the user agent starts the unload event of the previous document. If there is no previous
+ // document or the previous document has a different origin than the current document, this attribute must return
+ // zero.
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(
+ self.document()
+ .previous_document_unload_timing()
+ .unload_event_start_time,
+ ))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-unloadeventend
+ pub(crate) fn unload_event_end(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // If the previous document and the current document have the same origin, this attribute must return the time
+ // immediately after the user agent finishes the unload event of the previous document. If there is no previous
+ // document or the previous document has a different origin than the current document or the unload is not yet
+ // completed, this attribute must return zero.
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(
+ self.document().previous_document_unload_timing().unload_event_end_time,
+ ))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-redirectstart
+ pub(crate) fn redirect_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // If there are HTTP redirects when navigating and if all the redirects are from the same origin, this attribute
+ // must return the starting time of the fetch that initiates the redirect. Otherwise, this attribute must return
+ // zero.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+
+ if entry.redirect_count(cx)? == 0 {
+ return Ok(0);
+ }
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.redirect_start()))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-redirectend
+ pub(crate) fn redirect_end(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // If there are HTTP redirects when navigating and all redirects are from the same origin, this attribute must
+ // return the time immediately after receiving the last byte of the response of the last redirect. Otherwise, this
+ // attribute must return zero.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+
+ if entry.redirect_count(cx)? == 0 {
+ return Ok(0);
+ }
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.redirect_end()))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-fetchstart
+ pub(crate) fn fetch_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // If the new resource is to be fetched using a "GET" request method, fetchStart must return the time immediately
+ // before the user agent starts checking the HTTP cache. Otherwise, it must return the time when the user agent
+ // starts fetching the resource.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().fetch_start(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-domainlookupstart
+ pub(crate) fn domain_lookup_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent starts the domain name lookup for the
+ // current document.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().domain_lookup_start(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-domainlookupend
+ pub(crate) fn domain_lookup_end(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately after the user agent finishes the domain name lookup for the
+ // current document.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().domain_lookup_end(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-connectstart
+ pub(crate) fn connect_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent start establishing the connection to the
+ // server to retrieve the document.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().connect_start(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-connectend
+ pub(crate) fn connect_end(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately after the user agent finishes establishing the connection to
+ // the server to retrieve the current document.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().connect_end(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-secureconnectionstart
+ pub(crate) fn secure_connection_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // When this attribute is available, if the scheme of the current page is "https", this attribute must return the
+ // time immediately before the user agent starts the handshake process to secure the current connection. If this
+ // attribute is available but HTTPS is not used, this attribute must return zero.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(entry.parent().secure_connection_start(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-requeststart
+ pub(crate) fn request_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent starts requesting the current document
+ // from the server, or HTTP cache or from local resources.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().request_start(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-responsestart
+ pub(crate) fn response_start(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately after the user agent receives the first byte of the response
+ // from the server, or HTTP cache or from local resources.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.fetch_phase_to_wall_time_milliseconds(entry.parent().response_start(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-responseend
+ pub(crate) fn response_end(&self, cx: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately after the user agent receives the last byte of the current
+ // document or immediately before the transport connection is closed, whichever comes first.
+ let Some(entry) = self.navigation_timing_entry() else {
+ return Ok(0);
+ };
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(entry.parent().response_end(cx)?))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-domloading
+ pub(crate) fn dom_loading(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent sets the current document readiness to
+ // "loading".
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(self.document().load_timing_info().dom_loading_time))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-dominteractive
+ pub(crate) fn dom_interactive(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent sets the current document readiness to
+ // "interactive".
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(self.document().load_timing_info().dom_interactive_time))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-domcontentloadedeventstart
+ pub(crate) fn dom_content_loaded_event_start(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent fires the DOMContentLoaded event at the
+ // Document.
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(
+ self.document().load_timing_info().dom_content_loaded_event_start_time,
+ ))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-domcontentloadedeventend
+ pub(crate) fn dom_content_loaded_event_end(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately after the document's DOMContentLoaded event completes.
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(
+ self.document().load_timing_info().dom_content_loaded_event_end_time,
+ ))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-domcomplete
+ pub(crate) fn dom_complete(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the user agent sets the current document readiness to
+ // "complete".
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(self.document().load_timing_info().dom_complete_time))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-loadeventstart
+ pub(crate) fn load_event_start(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time immediately before the load event of the current document is fired. It must
+ // return zero when the load event is not fired yet.
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(self.document().load_timing_info().load_event_start_time))
+ }
+
+ // https://w3c.github.io/navigation-timing/#dom-performancetiming-loadeventend
+ pub(crate) fn load_event_end(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // This attribute must return the time when the load event of the current document is completed. It must return
+ // zero when the load event is not fired or is not completed.
+ Ok(self.relative_timestamp_to_wall_time_milliseconds(self.document().load_timing_info().load_event_end_time))
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/paint_timing/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/mod.rs
new file mode 100644
index 00000000000..bfbec6967d5
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/mod.rs
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! Paint Timing, https://w3c.github.io/paint-timing/
+
+#[allow(
+ clippy::module_inception,
+ reason = "the module mirrors PaintTiming/PaintTiming.cpp, which the crate module is named after"
+)]
+pub(crate) mod paint_timing;
+pub(crate) mod paint_timing_mixin;
+pub(crate) mod performance_paint_timing;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/paint_timing/paint_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/paint_timing.rs
new file mode 100644
index 00000000000..4d79ded6750
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/paint_timing.rs
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+use core::ffi::c_void;
+
+use crate::bindings::cpp_cell::CppCell;
+
+unsafe extern "C" {
+ fn web_paint_timing_is_exposed_for_paint_timing(node: *mut c_void) -> bool;
+}
+
+/// https://w3c.github.io/paint-timing/#exposed-for-paint-timing
+pub(crate) fn is_exposed_for_paint_timing(node: &CppCell) -> bool {
+ // NB: Given a null document. Only elements can be exposed for paint timing.
+ // SAFETY: The node is live.
+ unsafe { web_paint_timing_is_exposed_for_paint_timing(node.as_ptr()) }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/paint_timing/paint_timing_mixin.rs b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/paint_timing_mixin.rs
new file mode 100644
index 00000000000..25f68d0f335
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/paint_timing_mixin.rs
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PaintTimingMixin, https://w3c.github.io/paint-timing/#sec-PaintTimingMixin
+
+/// https://w3c.github.io/paint-timing/#paint-timing-info
+#[derive(Clone, Copy)]
+pub(crate) struct PaintTimingInfo {
+ /// https://w3c.github.io/paint-timing/#paint-timing-info-rendering-update-end-time
+ pub(crate) rendering_update_end_time: f64,
+ /// https://w3c.github.io/paint-timing/#paint-timing-info-implementation-defined-presentation-time
+ pub(crate) implementation_defined_presentation_time: Option<f64>,
+}
+
+impl PaintTimingInfo {
+ pub(crate) fn from_abi(
+ rendering_update_end_time: f64,
+ has_presentation_time: bool,
+ implementation_defined_presentation_time: f64,
+ ) -> Self {
+ Self {
+ rendering_update_end_time,
+ implementation_defined_presentation_time: has_presentation_time
+ .then_some(implementation_defined_presentation_time),
+ }
+ }
+}
+
+// https://w3c.github.io/paint-timing/#default-paint-timestamp
+pub(crate) fn default_paint_timestamp(paint_timing_info: &PaintTimingInfo) -> f64 {
+ // To get the default paint timestamp for a paint timing info paintTimingInfo, return paintTimingInfo's
+ // implementation-defined presentation time if it is non-null, otherwise paintTimingInfo's rendering update end time.
+ paint_timing_info
+ .implementation_defined_presentation_time
+ .unwrap_or(paint_timing_info.rendering_update_end_time)
+}
+
+/// https://w3c.github.io/paint-timing/#sec-PaintTimingMixin
+pub(crate) struct PaintTimingMixin {
+ // https://w3c.github.io/paint-timing/#painttimingmixin-paint-timing-info
+ // NB: Every object that includes this mixin is created with a paint timing info, so it is never null here.
+ paint_timing_info: PaintTimingInfo,
+}
+
+impl PaintTimingMixin {
+ pub(crate) fn new(paint_timing_info: PaintTimingInfo) -> Self {
+ Self { paint_timing_info }
+ }
+
+ // https://w3c.github.io/paint-timing/#dom-painttimingmixin-painttime
+ pub(crate) fn paint_time(&self) -> f64 {
+ // The paintTime attribute's getter step is to return this's paint timing info's rendering update end time.
+ self.paint_timing_info.rendering_update_end_time
+ }
+
+ // https://w3c.github.io/paint-timing/#dom-painttimingmixin-presentationtime
+ pub(crate) fn presentation_time(&self) -> Option<f64> {
+ // The presentationTime attribute's getter step, if exists, is to return this's paint timing info's
+ // implementation-defined presentation time.
+ self.paint_timing_info.implementation_defined_presentation_time
+ }
+
+ pub(crate) fn paint_timing_info(&self) -> &PaintTimingInfo {
+ &self.paint_timing_info
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/paint_timing/performance_paint_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/performance_paint_timing.rs
new file mode 100644
index 00000000000..ec696a545f1
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/paint_timing/performance_paint_timing.rs
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PerformancePaintTiming, https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming
+
+use core::ffi::c_void;
+
+use ak::Utf16String;
+use libjs_rust::api::{Trace, Vm};
+
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate, cell_into_abi};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::paint_timing::paint_timing_mixin::{PaintTimingInfo, PaintTimingMixin, default_paint_timestamp};
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
+
+/// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformancePaintTiming {
+ entry: PerformanceEntry,
+ #[gc(untraced)]
+ paint_timing_mixin: PaintTimingMixin,
+}
+
+impl Wrappable for PerformancePaintTiming {}
+
+impl Inherits<PerformanceEntry> for PerformancePaintTiming {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+impl PerformancePaintTiming {
+ // https://w3c.github.io/paint-timing/#report-paint-timing
+ pub(crate) fn create(vm: &Vm, paint_type: Utf16String, paint_timing_info: PaintTimingInfo) -> Ref<Self> {
+ let new_entry = allocate(vm, |_| Self {
+ // 1. Set newEntry's name attribute to paintType.
+ // 3. Set newEntry's startTime attribute to the default paint timestamp given paintTimingInfo.
+ // 4. Set newEntry's duration attribute to 0.
+ entry: PerformanceEntry::new(
+ paint_type,
+ Utf16String::from_utf8("paint"),
+ default_paint_timestamp(&paint_timing_info),
+ 0.0,
+ ),
+ // 2. Set newEntry's paint timing info to paintTimingInfo.
+ paint_timing_mixin: PaintTimingMixin::new(paint_timing_info),
+ });
+ let any_entry = AnyPerformanceEntry::PerformancePaintTiming(new_entry);
+ any_entry.entry().set_object(any_entry);
+ new_entry
+ }
+
+ pub(crate) fn paint_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ Ok(self.paint_timing_mixin.paint_time())
+ }
+
+ pub(crate) fn presentation_time(&self, _: &mut CallContext) -> WebIdlResult<Option<f64>> {
+ Ok(self.paint_timing_mixin.presentation_time())
+ }
+}
+
+/// https://w3c.github.io/paint-timing/#report-paint-timing
+///
+/// # Safety
+///
+/// `vm` must be the live VM, and `paint_type` a raw AK::Utf16String that C++ hands over.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_paint_timing_create_performance_paint_timing(
+ vm: *mut c_void,
+ paint_type: usize,
+ rendering_update_end_time: f64,
+ has_presentation_time: bool,
+ presentation_time: f64,
+) -> *mut c_void {
+ // SAFETY: The caller passes the live VM and hands over the string.
+ let (vm, paint_type) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(paint_type)) };
+ let paint_timing_info =
+ PaintTimingInfo::from_abi(rendering_update_end_time, has_presentation_time, presentation_time);
+ cell_into_abi(PerformancePaintTiming::create(vm, paint_type, paint_timing_info))
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/exports.rs
index e3993ab379e..6a8b9f86033 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/exports.rs
@@ -9,7 +9,7 @@
use core::ffi::c_void;
use crate::bindings::interface::{cell_into_abi, realm_arguments};
-use crate::performance_timeline::performance_entry::CppPerformanceEntry;
+use crate::performance_timeline::performance_entry::AnyPerformanceEntry;
use crate::performance_timeline::performance_timeline::PerformanceTimeline;
/// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
@@ -37,7 +37,7 @@ pub unsafe extern "C" fn web_rust_performance_timeline_queue_performance_entry(
entry: *mut c_void,
) {
// SAFETY: The caller passes the live VM, a live realm and a live entry.
- let ((vm, realm), entry) = unsafe { (realm_arguments(vm, realm), CppPerformanceEntry::from_raw(entry)) };
+ let ((vm, realm), entry) = unsafe { (realm_arguments(vm, realm), AnyPerformanceEntry::from_abi(entry)) };
PerformanceTimeline::of(vm, realm).queue_performance_entry(vm, &entry);
}
@@ -54,22 +54,6 @@ pub unsafe extern "C" fn web_rust_performance_timeline_add_performance_entry(
check_if_performance_buffer_is_full: bool,
) {
// SAFETY: The caller passes the live VM, a live realm and a live entry.
- let ((vm, realm), entry) = unsafe { (realm_arguments(vm, realm), CppPerformanceEntry::from_raw(entry)) };
+ let ((vm, realm), entry) = unsafe { (realm_arguments(vm, realm), AnyPerformanceEntry::from_abi(entry)) };
PerformanceTimeline::of(vm, realm).add_performance_entry(vm, &entry, check_if_performance_buffer_is_full);
}
-
-/// https://w3c.github.io/resource-timing/#dfn-add-a-performanceresourcetiming-entry
-///
-/// # Safety
-///
-/// As for web_rust_performance_timeline_queue_performance_entry(), with a PerformanceResourceTiming.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn web_rust_performance_timeline_add_resource_timing_entry(
- vm: *mut c_void,
- realm: *mut c_void,
- entry: *mut c_void,
-) {
- // SAFETY: The caller passes the live VM, a live realm and a live entry.
- let ((vm, realm), entry) = unsafe { (realm_arguments(vm, realm), CppPerformanceEntry::from_raw(entry)) };
- PerformanceTimeline::of(vm, realm).add_resource_timing_entry(vm, &entry);
-}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs
index f75931b0295..3384f689d2a 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs
@@ -7,96 +7,202 @@
//! PerformanceEntry, https://w3c.github.io/performance-timeline/#the-performanceentry-interface
+use core::cell::Cell;
use core::ffi::c_void;
use ak::Utf16String;
-use libjs_rust::api::{MarkedVec, Trace};
+use libjs_rust::api::{MarkedVec, ThrowCompletionOr, Trace, Value};
-use crate::bindings::CallContext;
-use crate::bindings::conversions::CppInterface;
-use crate::bindings::cpp_cell::CppCell;
-use crate::css::css_rule::wrap_cpp_cell;
+use crate::bindings::conversions::ToJs;
+use crate::bindings::interface::{Inherits, Ref, Wrappable, cell_from_abi, cell_if_abi, wrap};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::event_timing::performance_event_timing::PerformanceEventTiming;
+use crate::html::visibility_state_entry::VisibilityStateEntry;
+use crate::largest_contentful_paint::largest_contentful_paint::LargestContentfulPaint;
+use crate::navigation_timing::performance_navigation_timing::PerformanceNavigationTiming;
+use crate::paint_timing::performance_paint_timing::PerformancePaintTiming;
use crate::performance_timeline::performance_observer::PerformanceObserverInit;
+use crate::resource_timing::performance_resource_timing::PerformanceResourceTiming;
+use crate::user_timing::performance_mark::PerformanceMark;
+use crate::user_timing::performance_measure::PerformanceMeasure;
-unsafe extern "C" {
- fn web_performance_timeline_entry_name(entry: *mut c_void) -> usize;
- fn web_performance_timeline_entry_entry_type(entry: *mut c_void) -> usize;
- fn web_performance_timeline_entry_start_time(entry: *mut c_void) -> f64;
- fn web_performance_timeline_entry_should_add_entry(
- entry: *mut c_void,
- has_options: bool,
- has_duration_threshold: bool,
- duration_threshold: f64,
- ) -> bool;
+/// https://w3c.github.io/performance-timeline/#dom-performanceentry
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceEntry {
+ name: Utf16String,
+ entry_type: Utf16String,
+ start_time: f64,
+ duration: Cell<f64>,
+ object: Cell<Option<AnyPerformanceEntry>>,
}
-/// https://w3c.github.io/performance-timeline/#dom-performanceentry
-#[derive(Clone, Trace)]
+impl Wrappable for PerformanceEntry {}
+
+impl PerformanceEntry {
+ pub(crate) fn new(name: Utf16String, entry_type: Utf16String, start_time: f64, duration: f64) -> Self {
+ Self {
+ name,
+ entry_type,
+ start_time,
+ duration: Cell::new(duration),
+ object: Cell::new(None),
+ }
+ }
+
+ pub(crate) fn set_object(&self, object: AnyPerformanceEntry) {
+ self.object.set(Some(object));
+ }
+
+ pub(crate) fn object(&self) -> AnyPerformanceEntry {
+ self.object
+ .get()
+ .expect("every entry is part of an object of an interface that inherits from PerformanceEntry")
+ }
+
+ pub(crate) fn name(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ Ok(self.object().name())
+ }
+
+ pub(crate) fn entry_type(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ Ok(self.object().entry_type())
+ }
+
+ pub(crate) fn start_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ Ok(self.object().start_time())
+ }
+
+ pub(crate) fn duration(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ Ok(self.object().duration())
+ }
+
+ pub(crate) fn set_duration(&self, duration: f64) {
+ self.duration.set(duration);
+ }
+}
+
+#[derive(Clone, Copy, Trace)]
#[gc(crate = libjs_rust)]
-pub(crate) struct CppPerformanceEntry(CppCell);
+pub(crate) enum AnyPerformanceEntry {
+ LargestContentfulPaint(Ref<LargestContentfulPaint>),
+ PerformanceEventTiming(Ref<PerformanceEventTiming>),
+ PerformanceMark(Ref<PerformanceMark>),
+ PerformanceMeasure(Ref<PerformanceMeasure>),
+ PerformanceNavigationTiming(Ref<PerformanceNavigationTiming>),
+ PerformancePaintTiming(Ref<PerformancePaintTiming>),
+ PerformanceResourceTiming(Ref<PerformanceResourceTiming>),
+ VisibilityStateEntry(Ref<VisibilityStateEntry>),
+}
-impl CppPerformanceEntry {
+macro_rules! for_each_entry {
+ ($any:expr, $object:ident => $expression:expr) => {
+ match $any {
+ AnyPerformanceEntry::LargestContentfulPaint($object) => $expression,
+ AnyPerformanceEntry::PerformanceEventTiming($object) => $expression,
+ AnyPerformanceEntry::PerformanceMark($object) => $expression,
+ AnyPerformanceEntry::PerformanceMeasure($object) => $expression,
+ AnyPerformanceEntry::PerformanceNavigationTiming($object) => $expression,
+ AnyPerformanceEntry::PerformancePaintTiming($object) => $expression,
+ AnyPerformanceEntry::PerformanceResourceTiming($object) => $expression,
+ AnyPerformanceEntry::VisibilityStateEntry($object) => $expression,
+ }
+ };
+}
+
+impl ToJs for AnyPerformanceEntry {
+ fn to_js(self, cx: &CallContext) -> ThrowCompletionOr<Value> {
+ Ok(Value::from_object(for_each_entry!(self, object => wrap(cx, object))))
+ }
+}
+
+impl AnyPerformanceEntry {
/// # Safety
///
- /// `entry` must be a live PerformanceEntry.
- pub(crate) unsafe fn from_raw(entry: *mut c_void) -> Self {
- // SAFETY: The caller passes a live PerformanceEntry.
- Self(unsafe { CppCell::from_raw(entry) })
+ /// `cell` must be the live cell of an object of an interface that inherits from PerformanceEntry.
+ pub(crate) unsafe fn from_abi(cell: *mut c_void) -> Self {
+ // SAFETY: The caller passes a live cell.
+ unsafe {
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::LargestContentfulPaint(object);
+ }
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::PerformanceEventTiming(object);
+ }
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::PerformanceMark(object);
+ }
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::PerformanceMeasure(object);
+ }
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::PerformanceNavigationTiming(object);
+ }
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::PerformancePaintTiming(object);
+ }
+ if let Some(object) = cell_if_abi(cell) {
+ return Self::PerformanceResourceTiming(object);
+ }
+ Self::VisibilityStateEntry(cell_from_abi(cell))
+ }
}
- pub(crate) fn as_ptr(&self) -> *mut c_void {
- self.0.as_ptr()
+ pub(crate) fn entry(&self) -> &PerformanceEntry {
+ match self {
+ Self::LargestContentfulPaint(object) => object.parent(),
+ Self::PerformanceEventTiming(object) => object.parent(),
+ Self::PerformanceMark(object) => object.parent(),
+ Self::PerformanceMeasure(object) => object.parent(),
+ Self::PerformanceNavigationTiming(object) => {
+ let resource_timing: &PerformanceResourceTiming = object.parent();
+ resource_timing.parent()
+ }
+ Self::PerformancePaintTiming(object) => object.parent(),
+ Self::PerformanceResourceTiming(object) => object.parent(),
+ Self::VisibilityStateEntry(object) => object.parent(),
+ }
}
- /// https://w3c.github.io/performance-timeline/#dom-performanceentry-name
+ // https://w3c.github.io/performance-timeline/#dom-performanceentry-name
pub(crate) fn name(&self) -> Utf16String {
- // SAFETY: The entry is live, and LibWeb hands over a copy of its name.
- unsafe { Utf16String::from_raw_owned(web_performance_timeline_entry_name(self.as_ptr())) }
+ // This attribute must return the value it is initialized to.
+ self.entry().name.clone()
}
- /// https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype
+ // https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype
pub(crate) fn entry_type(&self) -> Utf16String {
- // SAFETY: The entry is live, and LibWeb hands over a copy of its entry type.
- unsafe { Utf16String::from_raw_owned(web_performance_timeline_entry_entry_type(self.as_ptr())) }
+ // This attribute must return the value it is initialized to.
+ self.entry().entry_type.clone()
}
- /// https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime
+ // https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime
pub(crate) fn start_time(&self) -> f64 {
- // SAFETY: The entry is live.
- unsafe { web_performance_timeline_entry_start_time(self.as_ptr()) }
+ // This attribute must return the value it is initialized to.
+ self.entry().start_time
}
- /// https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- pub(crate) fn should_add_entry(&self, options: Option<&PerformanceObserverInit>) -> bool {
- let duration_threshold = options.and_then(|options| options.duration_threshold);
- // SAFETY: The entry is live.
- unsafe {
- web_performance_timeline_entry_should_add_entry(
- self.as_ptr(),
- options.is_some(),
- duration_threshold.is_some(),
- duration_threshold.unwrap_or_default(),
- )
+ // https://w3c.github.io/performance-timeline/#dom-performanceentry-duration
+ pub(crate) fn duration(&self) -> f64 {
+ if let Self::PerformanceNavigationTiming(entry) = self {
+ return entry.duration();
}
- }
- pub(crate) fn wrap(&self, cx: &CallContext) -> CppInterface {
- wrap_cpp_cell(cx, &self.0)
+ // The getter steps for the duration attribute are to return 0 if this’s end time is 0; otherwise this’s end time
+ // - this’s startTime.
+ // NB: The specs that set the duration attribute keep theirs.
+ self.entry().duration.get()
}
-}
-pub(crate) fn wrap_entries<'vm>(
- cx: &CallContext<'vm>,
- entries: &MarkedVec<'_, CppPerformanceEntry>,
-) -> MarkedVec<'vm, CppInterface> {
- let wrappers = MarkedVec::with_capacity(cx.vm(), entries.len());
- for entry in entries.values().iter() {
- wrappers.push(entry.wrap(cx));
+ /// https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
+ pub(crate) fn should_add_entry(&self, options: Option<&PerformanceObserverInit>) -> bool {
+ match self {
+ Self::PerformanceEventTiming(entry) => entry.should_add_entry(options),
+ _ => true,
+ }
}
- wrappers
}
-pub(crate) fn sort_in_chronological_order(entries: &MarkedVec<'_, CppPerformanceEntry>) {
+pub(crate) fn sort_in_chronological_order(entries: &MarkedVec<'_, AnyPerformanceEntry>) {
entries
.values_mut()
.sort_by(|left, right| left.start_time().total_cmp(&right.start_time()));
@@ -105,10 +211,10 @@ pub(crate) fn sort_in_chronological_order(entries: &MarkedVec<'_, CppPerformance
// https://w3c.github.io/performance-timeline/#dfn-filter-buffer-by-name-and-type
pub(crate) fn filter_buffer_by_name_and_type<'vm>(
cx: &CallContext<'vm>,
- buffer: &[CppPerformanceEntry],
+ buffer: &[AnyPerformanceEntry],
name: Option<&Utf16String>,
r#type: Option<&Utf16String>,
-) -> MarkedVec<'vm, CppPerformanceEntry> {
+) -> MarkedVec<'vm, AnyPerformanceEntry> {
// 1. Let result be an initially empty list.
let result = MarkedVec::new(cx.vm());
@@ -125,7 +231,7 @@ pub(crate) fn filter_buffer_by_name_and_type<'vm>(
}
// 3. append entry to result.
- result.push(entry.clone());
+ result.push(*entry);
}
// 3. Sort results's entries in chronological order with respect to startTime
@@ -134,3 +240,36 @@ pub(crate) fn filter_buffer_by_name_and_type<'vm>(
// 4. Return result.
result
}
+
+/// https://w3c.github.io/performance-timeline/#dom-performanceentry-name
+///
+/// # Safety
+///
+/// `entry` must be the live cell of an object of an interface that inherits from PerformanceEntry.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_performance_entry_name(entry: *mut c_void) -> usize {
+ // SAFETY: The caller passes a live entry.
+ unsafe { AnyPerformanceEntry::from_abi(entry) }.name().into_raw()
+}
+
+/// https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime
+///
+/// # Safety
+///
+/// As for web_rust_performance_entry_name().
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_performance_entry_start_time(entry: *mut c_void) -> f64 {
+ // SAFETY: The caller passes a live entry.
+ unsafe { AnyPerformanceEntry::from_abi(entry) }.start_time()
+}
+
+/// https://w3c.github.io/performance-timeline/#dom-performanceentry-duration
+///
+/// # Safety
+///
+/// As for web_rust_performance_entry_name().
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_performance_entry_duration(entry: *mut c_void) -> f64 {
+ // SAFETY: The caller passes a live entry.
+ unsafe { AnyPerformanceEntry::from_abi(entry) }.duration()
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry_tuple.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry_tuple.rs
index 1a7e3213ece..e0eb287420f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry_tuple.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry_tuple.rs
@@ -9,7 +9,7 @@ use ak::Utf16String;
use libjs_rust::api::{DeferGc, Trace};
use crate::performance_timeline::entry_types::SupportedEntryType;
-use crate::performance_timeline::performance_entry::CppPerformanceEntry;
+use crate::performance_timeline::performance_entry::AnyPerformanceEntry;
// https://w3c.github.io/performance-timeline/#dfn-performance-entry-buffer-map
#[derive(Trace)]
@@ -21,7 +21,7 @@ pub(crate) struct PerformanceEntryTuple {
// https://w3c.github.io/performance-timeline/#dfn-performance-entry-buffer
// A performance entry buffer to store PerformanceEntry objects, that is initially empty.
- pub(crate) performance_entry_buffer: Vec<CppPerformanceEntry>,
+ pub(crate) performance_entry_buffer: Vec<AnyPerformanceEntry>,
// https://w3c.github.io/performance-timeline/#dfn-maxbuffersize
// An integer maxBufferSize, initialized to the registry value for this entry type.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer.rs
index 2cbb08894cf..fe87da34b5f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer.rs
@@ -13,12 +13,12 @@ use ak::Utf16String;
use libjs_rust::api::{Gc, GcRefCell, MarkedVec, PropertyKey, Realm, ThrowCompletionOr, Trace, Value, Vm};
use crate::bindings::callback::CallbackFunction;
-use crate::bindings::conversions::{CppInterface, ToJs, frozen_array_to_js, sequence_to_js};
+use crate::bindings::conversions::{ToJs, frozen_array_to_js, sequence_to_js};
use crate::bindings::interface::{Ref, Wrappable, allocate, create_dictionary_object, realm_is_window, wrap};
use crate::bindings::realm_data::realm_data;
use crate::bindings::{CallContext, Exception, WebIdlResult};
use crate::performance_timeline::entry_types::supported_entry_types;
-use crate::performance_timeline::performance_entry::{CppPerformanceEntry, wrap_entries};
+use crate::performance_timeline::performance_entry::AnyPerformanceEntry;
use crate::performance_timeline::performance_observer_entry_list::PerformanceObserverEntryList;
use crate::performance_timeline::performance_timeline::PerformanceTimeline;
@@ -52,7 +52,7 @@ pub(crate) struct PerformanceObserver {
// https://w3c.github.io/performance-timeline/#dfn-observer-buffer
// A PerformanceEntryList object called the observer buffer that is initially empty.
- observer_buffer: GcRefCell<Vec<CppPerformanceEntry>>,
+ observer_buffer: GcRefCell<Vec<AnyPerformanceEntry>>,
// https://w3c.github.io/performance-timeline/#dfn-observer-type
// A DOMString observer type which is initially "undefined".
@@ -243,7 +243,7 @@ impl PerformanceObserver {
// 1. If should add entry with entry and options as parameters returns true, append entry to the
// observer buffer.
if entry.should_add_entry(Some(&options)) {
- observer_buffer.push(entry.clone());
+ observer_buffer.push(*entry);
}
}
});
@@ -271,13 +271,16 @@ impl PerformanceObserver {
}
// https://w3c.github.io/performance-timeline/#dom-performanceobserver-takerecords
- pub(crate) fn take_records<'vm>(&self, cx: &mut CallContext<'vm>) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ pub(crate) fn take_records<'vm>(
+ &self,
+ cx: &mut CallContext<'vm>,
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// The takeRecords() method must return a copy of this's observer buffer, and also empty this's observer buffer.
let records = self.take_observer_buffer(cx.vm());
- Ok(wrap_entries(cx, &records))
+ Ok(records)
}
- pub(crate) fn take_observer_buffer<'vm>(&self, vm: &'vm Vm) -> MarkedVec<'vm, CppPerformanceEntry> {
+ pub(crate) fn take_observer_buffer<'vm>(&self, vm: &'vm Vm) -> MarkedVec<'vm, AnyPerformanceEntry> {
let records = MarkedVec::new(vm);
let mut buffer = self.observer_buffer.borrow_mut(vm);
records.extend_from_slice(&buffer);
@@ -321,7 +324,7 @@ impl PerformanceObserver {
self.options_list.borrow()
}
- pub(crate) fn append_to_observer_buffer(&self, vm: &Vm, entry: CppPerformanceEntry) {
+ pub(crate) fn append_to_observer_buffer(&self, vm: &Vm, entry: AnyPerformanceEntry) {
self.observer_buffer.borrow_mut(vm).push(entry);
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer_entry_list.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer_entry_list.rs
index 77073b56b38..b8216df399d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer_entry_list.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_observer_entry_list.rs
@@ -10,12 +10,9 @@
use ak::Utf16String;
use libjs_rust::api::{Gc, MarkedVec, Realm, Trace, Vm};
-use crate::bindings::conversions::CppInterface;
use crate::bindings::interface::{Ref, Wrappable, allocate};
use crate::bindings::{CallContext, WebIdlResult};
-use crate::performance_timeline::performance_entry::{
- CppPerformanceEntry, filter_buffer_by_name_and_type, wrap_entries,
-};
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, filter_buffer_by_name_and_type};
// https://w3c.github.io/performance-timeline/#performanceobserverentrylist-interface
#[derive(Trace)]
@@ -23,7 +20,7 @@ use crate::performance_timeline::performance_entry::{
pub(crate) struct PerformanceObserverEntryList {
realm: Gc<Realm>,
// https://w3c.github.io/performance-timeline/#dfn-entry-list
- entry_list: Vec<CppPerformanceEntry>,
+ entry_list: Vec<AnyPerformanceEntry>,
}
impl Wrappable for PerformanceObserverEntryList {
@@ -33,7 +30,7 @@ impl Wrappable for PerformanceObserverEntryList {
}
impl PerformanceObserverEntryList {
- pub(crate) fn create(vm: &Vm, realm: Gc<Realm>, entry_list: &MarkedVec<'_, CppPerformanceEntry>) -> Ref<Self> {
+ pub(crate) fn create(vm: &Vm, realm: Gc<Realm>, entry_list: &MarkedVec<'_, AnyPerformanceEntry>) -> Ref<Self> {
allocate(vm, |_| Self {
realm,
entry_list: entry_list.to_vec(),
@@ -41,11 +38,14 @@ impl PerformanceObserverEntryList {
}
// https://w3c.github.io/performance-timeline/#dom-performanceobserverentrylist-getentries
- pub(crate) fn get_entries<'vm>(&self, cx: &mut CallContext<'vm>) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ pub(crate) fn get_entries<'vm>(
+ &self,
+ cx: &mut CallContext<'vm>,
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// Returns a PerformanceEntryList object returned by filter buffer by name and type algorithm with this's entry list,
// name and type set to null.
let entries = filter_buffer_by_name_and_type(cx, &self.entry_list, None, None);
- Ok(wrap_entries(cx, &entries))
+ Ok(entries)
}
// https://w3c.github.io/performance-timeline/#dom-performanceobserverentrylist-getentriesbytype
@@ -53,11 +53,11 @@ impl PerformanceObserverEntryList {
&self,
cx: &mut CallContext<'vm>,
r#type: Utf16String,
- ) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// Returns a PerformanceEntryList object returned by filter buffer by name and type algorithm with this's entry list,
// name set to null, and type set to the method's input type parameter.
let entries = filter_buffer_by_name_and_type(cx, &self.entry_list, None, Some(&r#type));
- Ok(wrap_entries(cx, &entries))
+ Ok(entries)
}
// https://w3c.github.io/performance-timeline/#dom-performanceobserverentrylist-getentriesbyname
@@ -66,11 +66,11 @@ impl PerformanceObserverEntryList {
cx: &mut CallContext<'vm>,
name: Utf16String,
r#type: Option<Utf16String>,
- ) -> WebIdlResult<MarkedVec<'vm, CppInterface>> {
+ ) -> WebIdlResult<MarkedVec<'vm, AnyPerformanceEntry>> {
// Returns a PerformanceEntryList object returned by filter buffer by name and type algorithm with this's entry list,
// name set to the method input name parameter, and type set to null if optional entryType is omitted, or set to the
// method's input type parameter otherwise.
let entries = filter_buffer_by_name_and_type(cx, &self.entry_list, Some(&name), r#type.as_ref());
- Ok(wrap_entries(cx, &entries))
+ Ok(entries)
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_timeline.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_timeline.rs
index 6aecce99b71..d5c6bf33a49 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_timeline.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_timeline.rs
@@ -26,7 +26,7 @@ use crate::bindings::realm_data::realm_data;
use crate::high_resolution_time::performance::Performance;
use crate::performance_timeline::entry_types::supported_entry_types;
use crate::performance_timeline::performance_entry::{
- CppPerformanceEntry, filter_buffer_by_name_and_type, sort_in_chronological_order,
+ AnyPerformanceEntry, filter_buffer_by_name_and_type, sort_in_chronological_order,
};
use crate::performance_timeline::performance_entry_tuple::PerformanceEntryTuple;
use crate::performance_timeline::performance_observer::PerformanceObserver;
@@ -68,7 +68,7 @@ pub(crate) struct PerformanceTimeline {
// A resource timing secondary buffer current size which is initially 0.
// https://w3c.github.io/resource-timing/#dfn-resource-timing-secondary-buffer
// A resource timing secondary buffer to store PerformanceResourceTiming objects that is initially empty.
- resource_timing_secondary_buffer: GcRefCell<Vec<CppPerformanceEntry>>,
+ resource_timing_secondary_buffer: GcRefCell<Vec<AnyPerformanceEntry>>,
}
static PERFORMANCE_TIMELINE_CLASS: EmbedderClass<PerformanceTimeline> = EmbedderClass::new("PerformanceTimeline");
@@ -148,7 +148,7 @@ impl PerformanceTimeline {
}
// https://w3c.github.io/performance-timeline/#dfn-queue-a-performanceentry
- pub(crate) fn queue_performance_entry(&self, vm: &Vm, new_entry: &CppPerformanceEntry) {
+ pub(crate) fn queue_performance_entry(&self, vm: &Vm, new_entry: &AnyPerformanceEntry) {
// 1. Let interested observers be an initially empty set of PerformanceObserver objects.
let interested_observers = MarkedVec::new(vm);
@@ -180,7 +180,7 @@ impl PerformanceTimeline {
// 5. For each observer in interested observers:
for observer in interested_observers.values().iter() {
// 1. Append newEntry to observer's observer buffer.
- observer.append_to_observer_buffer(vm, new_entry.clone());
+ observer.append_to_observer_buffer(vm, *new_entry);
}
// AD-HOC: Steps 6-9 are not here because other engines do not add to the performance entry buffer when queuing
@@ -205,7 +205,7 @@ impl PerformanceTimeline {
pub(crate) fn add_performance_entry(
&self,
vm: &Vm,
- new_entry: &CppPerformanceEntry,
+ new_entry: &AnyPerformanceEntry,
check_if_performance_buffer_is_full: bool,
) {
// 6. Let tuple be the relevant performance entry tuple of entryType and relevantGlobal.
@@ -227,7 +227,7 @@ impl PerformanceTimeline {
// 9. If isBufferFull is false and shouldAdd is true, append newEntry to tuple's performance entry buffer.
if !is_buffer_full && should_add {
- tuple.performance_entry_buffer.push(new_entry.clone());
+ tuple.performance_entry_buffer.push(*new_entry);
}
});
}
@@ -255,7 +255,7 @@ impl PerformanceTimeline {
cx: &CallContext<'vm>,
name: Option<&Utf16String>,
r#type: Option<&Utf16String>,
- ) -> MarkedVec<'vm, CppPerformanceEntry> {
+ ) -> MarkedVec<'vm, AnyPerformanceEntry> {
// 1. Let result be an initially empty list.
let result = MarkedVec::new(cx.vm());
@@ -410,7 +410,7 @@ impl PerformanceTimeline {
}
// https://w3c.github.io/resource-timing/#dfn-add-a-performanceresourcetiming-entry
- pub(crate) fn add_resource_timing_entry(&self, vm: &Vm, new_entry: &CppPerformanceEntry) {
+ pub(crate) fn add_resource_timing_entry(&self, vm: &Vm, new_entry: &AnyPerformanceEntry) {
// 1. If can add resource timing entry returns true and resource timing buffer full event pending flag is false,
// run the following substeps:
if self.can_add_resource_timing_entry() && !self.resource_timing_buffer_full_event_pending.get() {
@@ -441,9 +441,7 @@ impl PerformanceTimeline {
// 3. Add new entry to the resource timing secondary buffer.
// 4. Increase resource timing secondary buffer current size by 1.
- self.resource_timing_secondary_buffer
- .borrow_mut(vm)
- .push(new_entry.clone());
+ self.resource_timing_secondary_buffer.borrow_mut(vm).push(*new_entry);
}
// https://w3c.github.io/resource-timing/#dfn-can-add-resource-timing-entry
diff --git a/Libraries/LibWeb/Bindings/Rust/src/resource_timing/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/resource_timing/mod.rs
new file mode 100644
index 00000000000..cbea92e539d
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/resource_timing/mod.rs
@@ -0,0 +1,9 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! Resource Timing, https://w3c.github.io/resource-timing/
+
+pub(crate) mod performance_resource_timing;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/resource_timing/performance_resource_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/resource_timing/performance_resource_timing.rs
new file mode 100644
index 00000000000..be4e389248a
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/resource_timing/performance_resource_timing.rs
@@ -0,0 +1,524 @@
+/*
+ * Copyright (c) 2025, Luke Wilde <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! PerformanceResourceTiming, https://w3c.github.io/resource-timing/#dom-performanceresourcetiming
+
+use core::ffi::c_void;
+
+use ak::{Utf16FlyString, Utf16String};
+use libjs_rust::api::{Gc, MarkedVec, Realm, Trace, Vm};
+
+use crate::bindings::conversions::ByteString;
+use crate::bindings::environment_settings_object::relevant_settings_object;
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate, realm_arguments};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::fetch::infrastructure::fetch_timing_info::CppFetchTimingInfo;
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
+use crate::performance_timeline::performance_timeline::PerformanceTimeline;
+use crate::server_timing::performance_server_timing::{PerformanceServerTiming, parse_a_server_timing_header_field};
+
+/// https://w3c.github.io/resource-timing/#dom-renderblockingstatustype
+#[derive(Clone, Copy)]
+pub(crate) enum RenderBlockingStatusType {
+ Blocking,
+ NonBlocking,
+}
+
+/// https://fetch.spec.whatwg.org/#concept-response-cache-state
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub(crate) enum CacheState {
+ Local,
+ Validated,
+}
+
+impl CacheState {
+ pub(crate) fn from_abi(cache_state: u8) -> Option<Self> {
+ match cache_state {
+ 0 => None,
+ 1 => Some(Self::Local),
+ 2 => Some(Self::Validated),
+ _ => unreachable!("C++ passes a cache state"),
+ }
+ }
+}
+
+/// https://fetch.spec.whatwg.org/#response-body-info
+pub(crate) struct ResponseBodyInfo {
+ pub(crate) encoded_size: u64,
+ pub(crate) decoded_size: u64,
+ pub(crate) content_type: Utf16String,
+}
+
+#[repr(C)]
+pub(crate) struct ResponseBodyInfoAbi {
+ encoded_size: u64,
+ decoded_size: u64,
+ content_type: usize,
+}
+
+impl ResponseBodyInfoAbi {
+ /// # Safety
+ ///
+ /// The content type must be a raw string that C++ hands over.
+ pub(crate) unsafe fn into_body_info(self) -> ResponseBodyInfo {
+ ResponseBodyInfo {
+ encoded_size: self.encoded_size,
+ decoded_size: self.decoded_size,
+ // SAFETY: The caller hands over the string.
+ content_type: unsafe { Utf16String::from_raw_owned(self.content_type) },
+ }
+ }
+}
+
+/// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceResourceTiming {
+ entry: PerformanceEntry,
+ initiator_type: Utf16String,
+ #[gc(untraced)]
+ timing_info: CppFetchTimingInfo,
+ time_origin: f64,
+ #[gc(untraced)]
+ response_body_info: ResponseBodyInfo,
+ #[gc(untraced)]
+ cache_mode: Option<CacheState>,
+ response_status: u16,
+ delivery_type: Utf16String,
+}
+
+impl Wrappable for PerformanceResourceTiming {}
+
+impl Inherits<PerformanceEntry> for PerformanceResourceTiming {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+// https://w3c.github.io/resource-timing/#dfn-convert-fetch-timestamp
+pub(crate) fn convert_fetch_timestamp(time_stamp: f64, time_origin: f64) -> f64 {
+ // 1. If ts is zero, return zero.
+ if time_stamp == 0.0 {
+ return 0.0;
+ }
+
+ // 2. Otherwise, return the relative high resolution coarse time given ts and global.
+ time_stamp - time_origin
+}
+
+impl PerformanceResourceTiming {
+ // https://w3c.github.io/resource-timing/#dfn-setup-the-resource-timing-entry
+ #[expect(clippy::too_many_arguments, reason = "these are the inputs of the algorithm")]
+ pub(crate) fn setup_the_resource_timing_entry(
+ entry: PerformanceEntry,
+ time_origin: f64,
+ initiator_type: Utf16String,
+ timing_info: CppFetchTimingInfo,
+ cache_mode: Option<CacheState>,
+ body_info: ResponseBodyInfo,
+ response_status: u16,
+ mut delivery_type: Utf16String,
+ ) -> Self {
+ // 1. Assert that cacheMode is the empty string, "local", or "validated".
+
+ // 2. Set entry's initiator type to initiatorType.
+ // 3. Set entry's requested URL to requestedURL.
+ // NB: The entry's name, which it was created with, is its requested URL.
+ // 4. Set entry's timing info to timingInfo.
+ // 5. Set entry's response body info to bodyInfo.
+ // 6. Set entry's cache mode to cacheMode.
+ // 7. Set entry's response status to responseStatus.
+
+ // 8. If deliveryType is the empty string and cacheMode is not, then set deliveryType to "cache".
+ if delivery_type.is_empty() && cache_mode.is_some() {
+ delivery_type = Utf16String::from_utf8("cache");
+ }
+
+ // 9. Set entry's delivery type to deliveryType.
+ Self {
+ entry,
+ initiator_type,
+ timing_info,
+ time_origin,
+ response_body_info: body_info,
+ cache_mode,
+ response_status,
+ delivery_type,
+ }
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-initiatortype
+ pub(crate) fn initiator_type(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The initiatorType getter steps are to return the initiator type for this.
+ Ok(self.initiator_type.clone())
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-deliverytype
+ pub(crate) fn delivery_type(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The deliveryType getter steps are to return the delivery type for this.
+ Ok(self.delivery_type.clone())
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-nexthopprotocol
+ pub(crate) fn next_hop_protocol(&self, _: &mut CallContext) -> WebIdlResult<ByteString> {
+ // The nextHopProtocol getter steps are to isomorphic decode this's timing info's final connection timing info's
+ // ALPN negotiated protocol. See Recording connection timing info for more info.
+ // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
+ // the Timing-Allow-Origin check fails. We return empty string in this case.
+ Ok(ByteString::from_bytes(self.timing_info.alpn_negotiated_protocol()))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-workerstart
+ pub(crate) fn worker_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The workerStart getter steps are to convert fetch timestamp for this's timing info's final service worker start
+ // time and the relevant global object for this. See HTTP fetch for more info.
+ Ok(convert_fetch_timestamp(
+ self.timing_info.read().final_service_worker_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-redirectstart
+ pub(crate) fn redirect_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ if let AnyPerformanceEntry::PerformanceNavigationTiming(entry) = self.entry.object() {
+ return Ok(entry.redirect_start());
+ }
+ Ok(self.resource_timing_redirect_start())
+ }
+
+ pub(crate) fn resource_timing_redirect_start(&self) -> f64 {
+ // The redirectStart getter steps are to convert fetch timestamp for this's timing info's redirect start time and
+ // the relevant global object for this. See HTTP-redirect fetch for more info.
+ convert_fetch_timestamp(self.timing_info.read().redirect_start_time, self.time_origin)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-redirectend
+ pub(crate) fn redirect_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ if let AnyPerformanceEntry::PerformanceNavigationTiming(entry) = self.entry.object() {
+ return Ok(entry.redirect_end());
+ }
+ Ok(self.resource_timing_redirect_end())
+ }
+
+ pub(crate) fn resource_timing_redirect_end(&self) -> f64 {
+ // The redirectEnd getter steps are to convert fetch timestamp for this's timing info's redirect end time and the
+ // relevant global object for this. See HTTP-redirect fetch for more info.
+ convert_fetch_timestamp(self.timing_info.read().redirect_end_time, self.time_origin)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-fetchstart
+ pub(crate) fn fetch_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The fetchStart getter steps are to convert fetch timestamp for this's timing info's post-redirect start time and
+ // the relevant global object for this. See HTTP fetch for more info.
+ Ok(convert_fetch_timestamp(
+ self.timing_info.read().post_redirect_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-domainlookupstart
+ pub(crate) fn domain_lookup_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The domainLookupStart getter steps are to convert fetch timestamp for this's timing info's final connection
+ // timing info's domain lookup start time and the relevant global object for this. See Recording connection timing
+ // info for more info.
+ // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
+ // the Timing-Allow-Origin check fails. We return 0.0 in this case.
+ let Some(connection_timing_info) = self.timing_info.read().final_connection_timing_info() else {
+ return Ok(0.0);
+ };
+
+ Ok(convert_fetch_timestamp(
+ connection_timing_info.domain_lookup_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-domainlookupend
+ pub(crate) fn domain_lookup_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The domainLookupEnd getter steps are to convert fetch timestamp for this's timing info's final connection timing
+ // info's domain lookup end time and the relevant global object for this. See Recording connection timing info for
+ // more info.
+ // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
+ // the Timing-Allow-Origin check fails. We return 0.0 in this case.
+ let Some(connection_timing_info) = self.timing_info.read().final_connection_timing_info() else {
+ return Ok(0.0);
+ };
+
+ Ok(convert_fetch_timestamp(
+ connection_timing_info.domain_lookup_end_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-connectstart
+ pub(crate) fn connect_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The connectStart getter steps are to convert fetch timestamp for this's timing info's final connection timing
+ // info's connection start time and the relevant global object for this. See Recording connection timing info for
+ // more info.
+ // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
+ // the Timing-Allow-Origin check fails. We return 0.0 in this case.
+ let Some(connection_timing_info) = self.timing_info.read().final_connection_timing_info() else {
+ return Ok(0.0);
+ };
+
+ Ok(convert_fetch_timestamp(
+ connection_timing_info.connection_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-connectend
+ pub(crate) fn connect_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The connectEnd getter steps are to convert fetch timestamp for this's timing info's final connection timing
+ // info's connection end time and the relevant global object for this. See Recording connection timing info for
+ // more info.
+ // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
+ // the Timing-Allow-Origin check fails. We return 0.0 in this case.
+ let Some(connection_timing_info) = self.timing_info.read().final_connection_timing_info() else {
+ return Ok(0.0);
+ };
+
+ Ok(convert_fetch_timestamp(
+ connection_timing_info.connection_end_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-secureconnectionstart
+ pub(crate) fn secure_connection_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The secureConnectionStart getter steps are to convert fetch timestamp for this's timing info's final connection
+ // timing info's secure connection start time and the relevant global object for this. See Recording connection
+ // timing info for more info.
+ // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
+ // the Timing-Allow-Origin check fails. We return 0.0 in this case.
+ let Some(connection_timing_info) = self.timing_info.read().final_connection_timing_info() else {
+ return Ok(0.0);
+ };
+
+ Ok(convert_fetch_timestamp(
+ connection_timing_info.secure_connection_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-requeststart
+ pub(crate) fn request_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The requestStart getter steps are to convert fetch timestamp for this's timing info's final network-request
+ // start time and the relevant global object for this. See HTTP fetch for more info.
+ Ok(convert_fetch_timestamp(
+ self.timing_info.read().final_network_request_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-finalresponseheadersstart
+ pub(crate) fn final_response_headers_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The finalResponseHeadersStart getter steps are to convert fetch timestamp for this's timing info's final
+ // network-response start time and the relevant global object for this. See HTTP fetch for more info.
+ Ok(convert_fetch_timestamp(
+ self.timing_info.read().final_network_response_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-firstinterimresponsestart
+ pub(crate) fn first_interim_response_start(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The firstInterimResponseStart getter steps are to convert fetch timestamp for this's timing info's first interim
+ // network-response start time and the relevant global object for this. See HTTP fetch for more info.
+ Ok(convert_fetch_timestamp(
+ self.timing_info.read().first_interim_network_response_start_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responsestart
+ pub(crate) fn response_start(&self, cx: &mut CallContext) -> WebIdlResult<f64> {
+ // The responseStart getter steps are to return this's firstInterimResponseStart if it is not 0;
+ // Otherwise this's finalResponseHeadersStart.
+ let first_interim_response_start_time = self.first_interim_response_start(cx)?;
+ if first_interim_response_start_time != 0.0 {
+ return Ok(first_interim_response_start_time);
+ }
+
+ self.final_response_headers_start(cx)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responseend
+ pub(crate) fn response_end(&self, _: &mut CallContext) -> WebIdlResult<f64> {
+ // The responseEnd getter steps are to convert fetch timestamp for this's timing info's end time and the relevant
+ // global object for this. See fetch for more info.
+ Ok(convert_fetch_timestamp(
+ self.timing_info.read().end_time,
+ self.time_origin,
+ ))
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-encodedbodysize
+ pub(crate) fn encoded_body_size(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // The encodedBodySize getter steps are to return this's resource info's encoded size.
+ Ok(self.response_body_info.encoded_size)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-decodedbodysize
+ pub(crate) fn decoded_body_size(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ // The decodedBodySize getter steps are to return this's resource info's decoded size.
+ Ok(self.response_body_info.decoded_size)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize
+ pub(crate) fn transfer_size(&self, _: &mut CallContext) -> WebIdlResult<u64> {
+ if let Some(cache_mode) = self.cache_mode {
+ // 1. If this's cache mode is "local", then return 0.
+ if cache_mode == CacheState::Local {
+ return Ok(0);
+ }
+
+ // 2. If this's cache mode is "validated", then return 300.
+ if cache_mode == CacheState::Validated {
+ return Ok(300);
+ }
+ }
+
+ // 3. Return this's response body info's encoded size plus 300.
+ // Spec Note: The constant number added to transferSize replaces exposing the total byte size of the HTTP headers,
+ // as that may expose the presence of certain cookies. See this issue: https://github.com/w3c/resource-timing/issues/238
+ Ok(self.response_body_info.encoded_size + 300)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responsestatus
+ pub(crate) fn response_status(&self, _: &mut CallContext) -> WebIdlResult<u16> {
+ // The responseStatus getter steps are to return this's response status.
+ // Spec Note: responseStatus is determined in Fetch. For a cross-origin no-cors request it would be 0 because the
+ // response would be an opaque filtered response.
+ Ok(self.response_status)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-renderblockingstatus
+ pub(crate) fn render_blocking_status(&self, _: &mut CallContext) -> WebIdlResult<RenderBlockingStatusType> {
+ // The renderBlockingStatus getter steps are to return blocking if this's timing info's render-blocking is true;
+ // otherwise non-blocking.
+ if self.timing_info.read().render_blocking {
+ return Ok(RenderBlockingStatusType::Blocking);
+ }
+ Ok(RenderBlockingStatusType::NonBlocking)
+ }
+
+ // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-contenttype
+ pub(crate) fn content_type(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The contentType getter steps are to return this's resource info's content type.
+ Ok(self.response_body_info.content_type.clone())
+ }
+
+ // https://w3c.github.io/server-timing/#dom-performanceresourcetiming-servertiming
+ pub(crate) fn server_timing<'vm>(
+ &self,
+ cx: &mut CallContext<'vm>,
+ ) -> WebIdlResult<MarkedVec<'vm, Ref<PerformanceServerTiming>>> {
+ // The serverTiming getter steps are the following:
+ // 1. Let entries be a new list.
+ let entries = MarkedVec::new(cx.vm());
+
+ // 2. For each field in this’s timing info’s server-timing headers:
+ for field in self.timing_info.server_timing_headers() {
+ // 1. Let metric be the result of parsing field.
+ let metric = parse_a_server_timing_header_field(&field);
+
+ // 2. If metric is not null, append metric to entries.
+ if let Some(metric) = metric {
+ entries.push(allocate(cx.vm(), |_| metric));
+ }
+ }
+
+ // 3. Return entries.
+ Ok(entries)
+ }
+}
+
+// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
+#[expect(clippy::too_many_arguments, reason = "these are the inputs of the algorithm")]
+fn mark_resource_timing(
+ vm: &Vm,
+ timing_info: CppFetchTimingInfo,
+ requested_url: Utf16String,
+ initiator_type: Utf16String,
+ realm: Gc<Realm>,
+ cache_mode: Option<CacheState>,
+ body_info: ResponseBodyInfo,
+ response_status: u16,
+ delivery_type: Utf16String,
+) {
+ // 1. Create a PerformanceResourceTiming object entry.
+ let time_origin = relevant_settings_object(realm.global_object()).time_origin();
+ let timing = timing_info.read();
+ let converted_start_time = convert_fetch_timestamp(timing.start_time, time_origin);
+ let converted_end_time = convert_fetch_timestamp(timing.end_time, time_origin);
+ let entry = PerformanceEntry::new(
+ requested_url,
+ Utf16String::from_utf8("resource"),
+ converted_start_time,
+ converted_end_time - converted_start_time,
+ );
+
+ // Setup the resource timing entry for entry, given initiatorType, requestedURL, timingInfo, cacheMode, bodyInfo, responseStatus, and deliveryType.
+ let entry = PerformanceResourceTiming::setup_the_resource_timing_entry(
+ entry,
+ time_origin,
+ initiator_type,
+ timing_info,
+ cache_mode,
+ body_info,
+ response_status,
+ delivery_type,
+ );
+ let entry = allocate(vm, |_| entry);
+ let entry = AnyPerformanceEntry::PerformanceResourceTiming(entry);
+ entry.entry().set_object(entry);
+
+ // 3. Queue entry.
+ let timeline = PerformanceTimeline::of(vm, realm);
+ timeline.queue_performance_entry(vm, &entry);
+
+ // 4. Add entry to global's performance entry buffer.
+ timeline.add_resource_timing_entry(vm, &entry);
+}
+
+/// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
+///
+/// # Safety
+///
+/// `vm` must be the live VM, `realm` the live realm of the global object, `timing_info` a fetch timing info that LibWeb
+/// hands over a reference to, `requested_url` and the content type of `body_info` raw AK::Utf16Strings that LibWeb hands
+/// over, and `initiator_type` and `delivery_type` raw AK::Utf16FlyStrings that LibWeb lends for the call.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_resource_timing_mark_resource_timing(
+ vm: *mut c_void,
+ realm: *mut c_void,
+ timing_info: *mut c_void,
+ requested_url: usize,
+ initiator_type: usize,
+ cache_mode: u8,
+ body_info: ResponseBodyInfoAbi,
+ response_status: u16,
+ delivery_type: usize,
+) {
+ // SAFETY: The caller passes the live VM and a live realm.
+ let (vm, realm) = unsafe { realm_arguments(vm, realm) };
+ // SAFETY: The caller hands over a reference to the timing info and the strings, and lends the fly strings.
+ unsafe {
+ mark_resource_timing(
+ vm,
+ CppFetchTimingInfo::adopt(timing_info),
+ Utf16String::from_raw_owned(requested_url),
+ Utf16FlyString::from_raw_borrowed(initiator_type).into(),
+ realm,
+ CacheState::from_abi(cache_mode),
+ body_info.into_body_info(),
+ response_status,
+ Utf16FlyString::from_raw_borrowed(delivery_type).into(),
+ );
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/server_timing/performance_server_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/server_timing/performance_server_timing.rs
index 1668e250e0f..9e1d9e299e0 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/server_timing/performance_server_timing.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/server_timing/performance_server_timing.rs
@@ -6,16 +6,15 @@
//! PerformanceServerTiming, https://w3c.github.io/server-timing/#the-performanceservertiming-interface
-use core::ffi::c_void;
use std::collections::HashMap;
use ak::{GenericLexer, Utf16String};
use libhttp_rust::http::{
collect_an_http_quoted_string_extracting_the_value, is_http_tab_or_space, is_http_token_code_point,
};
-use libjs_rust::api::{Trace, Vm};
+use libjs_rust::api::Trace;
-use crate::bindings::interface::{Wrappable, allocate, cell_into_abi};
+use crate::bindings::interface::Wrappable;
use crate::bindings::{CallContext, WebIdlResult};
use crate::html::numbers::parse_floating_point_number;
@@ -39,7 +38,7 @@ fn consume_token<'a>(lexer: &mut GenericLexer<'a, u8>) -> &'a [u8] {
//
// Parameter names are matched ASCII case-insensitively, only the first instance of each parameter is
// considered, and extraneous characters after a metric name or a parameter value are ignored.
-fn parse_a_server_timing_header_field(field: &[u8]) -> Option<PerformanceServerTiming> {
+pub(crate) fn parse_a_server_timing_header_field(field: &[u8]) -> Option<PerformanceServerTiming> {
let mut lexer = GenericLexer::new(field);
lexer.ignore_while(is_http_tab_or_space);
@@ -129,19 +128,3 @@ impl PerformanceServerTiming {
))
}
}
-
-/// # Safety
-///
-/// `vm` must be the live VM.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn web_performance_server_timing_parse_a_server_timing_header_field(
- vm: *mut c_void,
- field: ak::Span<'_, u8>,
-) -> *mut c_void {
- let Some(metric) = parse_a_server_timing_header_field(field.as_slice()) else {
- return core::ptr::null_mut();
- };
- // SAFETY: The caller passes the live VM.
- let vm = unsafe { &*vm.cast::<Vm>() };
- cell_into_abi(allocate(vm, |_| metric))
-}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_mark.rs b/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_mark.rs
index ca35d14ecba..027f798ae0a 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_mark.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_mark.rs
@@ -10,49 +10,118 @@
use core::ffi::c_void;
use ak::Utf16String;
-use libjs_rust::api::{Gc, RawNativeFunctionResult, Realm, Value};
+use libjs_rust::api::{Gc, Realm, Trace, Value, utf16_formatted};
-use crate::bindings::WebIdlResult;
-use crate::performance_timeline::performance_entry::CppPerformanceEntry;
+use crate::bindings::global_object::window_from_global_object;
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate};
+use crate::bindings::{CallContext, Exception, WebIdlResult};
+use crate::html::window_or_worker_global_scope::structured_clone;
+use crate::navigation_timing::performance_timing::is_performance_timing_attribute;
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
unsafe extern "C" {
- fn web_user_timing_performance_mark_create(
- global_object: *mut c_void,
- mark_name: usize,
- has_detail: bool,
- detail: u64,
- has_start_time: bool,
- start_time: f64,
- entry: *mut *mut c_void,
- ) -> RawNativeFunctionResult;
+ fn web_high_resolution_time_current_high_resolution_time(global_object: *mut c_void) -> f64;
}
-// https://w3c.github.io/user-timing/#ref-for-dom-performancemarkoptions-1
+// https://w3c.github.io/user-timing/#dictdef-performancemarkoptions
pub(crate) struct PerformanceMarkOptions {
pub(crate) detail: Option<Value>,
pub(crate) start_time: Option<f64>,
}
+/// https://w3c.github.io/user-timing/#dom-performancemark
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceMark {
+ entry: PerformanceEntry,
+ /// https://w3c.github.io/user-timing/#dom-performancemark-detail
+ detail: Value,
+}
+
+impl Wrappable for PerformanceMark {}
+
+impl Inherits<PerformanceEntry> for PerformanceMark {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+impl PerformanceMark {
+ pub(crate) fn construct(
+ cx: &mut CallContext,
+ mark_name: Utf16String,
+ mark_options: PerformanceMarkOptions,
+ ) -> WebIdlResult<Ref<Self>> {
+ run_the_performance_mark_constructor(cx, cx.realm(), mark_name, &mark_options)
+ }
+
+ // https://w3c.github.io/user-timing/#dom-performancemark-detail
+ pub(crate) fn detail(&self, _: &mut CallContext) -> WebIdlResult<Value> {
+ // NB: The detail was structured-cloned when this entry was created, so it is returned as is.
+ Ok(self.detail)
+ }
+}
+
/// https://w3c.github.io/user-timing/#dfn-performancemark-constructor
pub(crate) fn run_the_performance_mark_constructor(
- realm: Gc<Realm>,
- mark_name: &Utf16String,
+ cx: &CallContext,
+ relevant_realm: Gc<Realm>,
+ mark_name: Utf16String,
mark_options: &PerformanceMarkOptions,
-) -> WebIdlResult<CppPerformanceEntry> {
- let mut entry = core::ptr::null_mut();
- // SAFETY: The global object and the detail are live, the name is lent for the call, and LibWeb writes a live entry.
- unsafe {
- web_user_timing_performance_mark_create(
- realm.global_object().as_ptr().cast(),
- mark_name.raw_identity(),
- mark_options.detail.is_some(),
- mark_options.detail.unwrap_or(Value::UNDEFINED).to_raw(),
- mark_options.start_time.is_some(),
- mark_options.start_time.unwrap_or_default(),
- &raw mut entry,
- )
+) -> WebIdlResult<Ref<PerformanceMark>> {
+ let vm = cx.vm();
+ let current_global_object = vm
+ .current_realm()
+ .expect("the constructor runs in a realm")
+ .global_object();
+
+ // 1. If the current global object is a Window object and markName uses the same name as a read only attribute in the PerformanceTiming interface, throw a SyntaxError.
+ if window_from_global_object(current_global_object).is_some() && is_performance_timing_attribute(&mark_name) {
+ return Err(Exception::syntax_error(utf16_formatted(
+ "'{}' markName cannot be used in a Window context because it is part of the PerformanceTiming interface",
+ &[&mark_name],
+ )));
+ }
+
+ // NOTE: Step 2 (creating the entry) is done after determining values, as we set the values once during creation and never change them after.
+
+ // 3. Set entry's name attribute to markName.
+ let name = mark_name;
+
+ // 4. Set entry's entryType attribute to DOMString "mark".
+ let entry_type = Utf16String::from_utf8("mark");
+
+ // 5. Set entry's startTime attribute as follows:
+ // 1. If markOptions's startTime member is present, then:
+ let start_time = if let Some(start_time) = mark_options.start_time {
+ // 1. If markOptions's startTime is negative, throw a TypeError.
+ if start_time < 0.0 {
+ return Err(Exception::type_error("startTime cannot be negative"));
+ }
+
+ // 2. Otherwise, set entry's startTime to the value of markOptions's startTime.
+ start_time
}
- .into_completion()?;
- // SAFETY: LibWeb wrote the live entry that it created.
- Ok(unsafe { CppPerformanceEntry::from_raw(entry) })
+ // 2. Otherwise, set it to the value that would be returned by the Performance object's now() method.
+ else {
+ // SAFETY: The current global object is live.
+ unsafe { web_high_resolution_time_current_high_resolution_time(current_global_object.as_ptr().cast()) }
+ };
+
+ // 6. Set entry's duration attribute to 0.
+ let duration = 0.0;
+
+ // 2. Create a new PerformanceMark object (entry).
+ let detail = match mark_options.detail {
+ Some(detail) if !detail.is_null() => structured_clone(&CallContext::new(vm, relevant_realm), detail, &[])?,
+ _ => Value::NULL,
+ };
+
+ let entry = allocate(vm, |_| PerformanceMark {
+ entry: PerformanceEntry::new(name, entry_type, start_time, duration),
+ detail,
+ });
+ let any_entry = AnyPerformanceEntry::PerformanceMark(entry);
+ any_entry.entry().set_object(any_entry);
+ Ok(entry)
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_measure.rs b/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_measure.rs
index 4960217223f..d69225626a4 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_measure.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/user_timing/performance_measure.rs
@@ -7,21 +7,12 @@
//! PerformanceMeasure, https://w3c.github.io/user-timing/#performancemeasure
-use core::ffi::c_void;
-
use ak::Utf16String;
-use libjs_rust::api::Value;
-
-use crate::performance_timeline::performance_entry::CppPerformanceEntry;
+use libjs_rust::api::{Trace, Value, Vm};
-unsafe extern "C" {
- fn web_user_timing_performance_measure_create(
- measure_name: usize,
- start_time: f64,
- duration: f64,
- detail: u64,
- ) -> *mut c_void;
-}
+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::performance_timeline::performance_entry::{AnyPerformanceEntry, PerformanceEntry};
// https://w3c.github.io/user-timing/#extensions-performance-interface
#[derive(Default)]
@@ -38,19 +29,45 @@ pub(crate) enum DOMStringOrDouble {
Double(f64),
}
-pub(crate) fn create_performance_measure(
- measure_name: &Utf16String,
- start_time: f64,
- duration: f64,
+/// https://w3c.github.io/user-timing/#performancemeasure
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct PerformanceMeasure {
+ entry: PerformanceEntry,
+ /// https://w3c.github.io/user-timing/#dom-performancemeasure-detail
detail: Value,
-) -> CppPerformanceEntry {
- // SAFETY: The detail is live, the name is lent for the call, and LibWeb returns a live entry.
- unsafe {
- CppPerformanceEntry::from_raw(web_user_timing_performance_measure_create(
- measure_name.raw_identity(),
- start_time,
- duration,
- detail.to_raw(),
- ))
+}
+
+impl Wrappable for PerformanceMeasure {}
+
+impl Inherits<PerformanceEntry> for PerformanceMeasure {
+ fn parent(&self) -> &PerformanceEntry {
+ &self.entry
+ }
+}
+
+impl PerformanceMeasure {
+ // https://w3c.github.io/user-timing/#dom-performancemeasure-detail
+ pub(crate) fn detail(&self, _: &mut CallContext) -> WebIdlResult<Value> {
+ // NB: The detail was structured-cloned when this entry was created, so it is returned as is.
+ Ok(self.detail)
+ }
+}
+
+impl PerformanceMeasure {
+ pub(crate) fn create(
+ vm: &Vm,
+ measure_name: Utf16String,
+ start_time: f64,
+ duration: f64,
+ detail: Value,
+ ) -> Ref<Self> {
+ let entry = allocate(vm, |_| Self {
+ entry: PerformanceEntry::new(measure_name, Utf16String::from_utf8("measure"), start_time, duration),
+ detail,
+ });
+ let any_entry = AnyPerformanceEntry::PerformanceMeasure(entry);
+ any_entry.entry().set_object(any_entry);
+ entry
}
}
diff --git a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
index 2c9f81405a4..366659c1541 100644
--- a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
+++ b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
@@ -29,6 +29,7 @@
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/HTML/WorkerGlobalScope.h>
+#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
@@ -111,10 +112,15 @@ bool web_bindings_document_is_fully_active(DOM::Document*);
bool web_bindings_document_has_focus(DOM::Document*);
bool web_bindings_document_has_been_destroyed(DOM::Document*);
URL::FFI::RustUrl web_bindings_document_url(DOM::Document*);
+void web_bindings_document_load_timing_info(DOM::Document const*, DOM::DocumentLoadTimingInfo*);
+void web_bindings_document_previous_document_unload_timing(DOM::Document const*, DOM::DocumentUnloadTimingInfo*);
+NavigationTiming::PerformanceNavigationTiming* web_bindings_document_navigation_timing_entry(DOM::Document const*);
+void web_bindings_document_set_navigation_timing_entry(DOM::Document*, NavigationTiming::PerformanceNavigationTiming*);
HTML::WorkerGlobalScope* web_bindings_worker_global_scope_from_global_object(JSObject* global_object);
HTML::EnvironmentSettingsObject* web_bindings_relevant_settings_object(JSObject* global_object);
JSObject* web_bindings_environment_settings_object_global_object(HTML::EnvironmentSettingsObject*);
JS::Realm* web_bindings_environment_settings_object_realm(HTML::EnvironmentSettingsObject*);
+double web_bindings_environment_settings_object_time_origin(HTML::EnvironmentSettingsObject*);
void web_bindings_environment_settings_object_id(HTML::EnvironmentSettingsObject*, void* ctx, void (*on_id)(void*, ReadonlyBytes));
bool web_bindings_worker_global_scope_is_closing(HTML::WorkerGlobalScope*);
void web_bindings_set_has_pending_activity(void* realm, DOM::EventTarget*, bool has_pending_activity);
@@ -250,6 +256,26 @@ URL::FFI::RustUrl web_bindings_document_url(DOM::Document* document)
return document->url().to_rust();
}
+void web_bindings_document_load_timing_info(DOM::Document const* document, DOM::DocumentLoadTimingInfo* load_timing_info)
+{
+ *load_timing_info = document->load_timing_info();
+}
+
+void web_bindings_document_previous_document_unload_timing(DOM::Document const* document, DOM::DocumentUnloadTimingInfo* unload_timing)
+{
+ *unload_timing = document->previous_document_unload_timing();
+}
+
+NavigationTiming::PerformanceNavigationTiming* web_bindings_document_navigation_timing_entry(DOM::Document const* document)
+{
+ return document->navigation_timing_entry().ptr();
+}
+
+void web_bindings_document_set_navigation_timing_entry(DOM::Document* document, NavigationTiming::PerformanceNavigationTiming* entry)
+{
+ document->set_navigation_timing_entry(*entry);
+}
+
HTML::EnvironmentSettingsObject* web_bindings_relevant_settings_object(JSObject* global_object)
{
return &HTML::relevant_settings_object(*JS::HostABI::object_from_abi(global_object));
@@ -265,6 +291,11 @@ JS::Realm* web_bindings_environment_settings_object_realm(HTML::EnvironmentSetti
return &settings_object->realm();
}
+double web_bindings_environment_settings_object_time_origin(HTML::EnvironmentSettingsObject* settings_object)
+{
+ return settings_object->time_origin();
+}
+
void web_bindings_environment_settings_object_id(HTML::EnvironmentSettingsObject* settings_object, void* ctx, void (*on_id)(void*, ReadonlyBytes))
{
on_id(ctx, settings_object->id.to_string().bytes());
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 61427927139..bbce0e1ab25 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -699,10 +699,7 @@ set(SOURCES
MediaSourceExtensions/SourceBufferList.cpp
MixedContent/AbstractOperations.cpp
Namespace.cpp
- NavigationTiming/EntryNames.cpp
- NavigationTiming/PerformanceNavigation.cpp
NavigationTiming/PerformanceNavigationTiming.cpp
- NavigationTiming/PerformanceTiming.cpp
NotificationsAPI/Notification.cpp
NotificationsAPI/NotificationPermission.cpp
Page/AutoScrollHandler.cpp
@@ -731,7 +728,6 @@ set(SOURCES
Painting/Scrolling.cpp
Painting/ScrollSnap.cpp
Painting/SvgPaintResources.cpp
- PerformanceTimeline/EntryTypes.cpp
PerformanceTimeline/PerformanceEntry.cpp
PermissionsAPI/Permissions.cpp
PermissionsAPI/PermissionStore.cpp
@@ -755,7 +751,6 @@ set(SOURCES
Selection/Selection.cpp
Selection/CaretNavigation.cpp
Selection/SelectionModifier.cpp
- ServerTiming/PerformanceServerTiming.cpp
ServiceWorker/Cache.cpp
ServiceWorker/CacheStorage.cpp
ServiceWorker/EventNames.cpp
@@ -914,8 +909,6 @@ set(SOURCES
UIEvents/TouchList.cpp
UIEvents/UIEvent.cpp
UIEvents/WheelEvent.cpp
- UserTiming/PerformanceMark.cpp
- UserTiming/PerformanceMeasure.cpp
ViewTransition/ViewTransition.cpp
WebLocks/AbstractOperations.cpp
WebLocks/LockManager.cpp
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 6078bdca0eb..7dd61d4d183 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -666,7 +666,7 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type
// 4. Create the navigation timing entry for document, given fullTimingInfo, redirectCount, navigationTimingType,
// navigationParams's response's service worker timing info, and navigationParams's response's body info.
- NavigationTiming::PerformanceNavigationTiming::create_navigation_timing_entry(
+ NavigationTiming::create_the_navigation_timing_entry(
*document,
full_timing_info,
redirect_count,
@@ -679,7 +679,7 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type
// 16. Create the navigation timing entry for document, with navigationParams's response's timing info,
// redirectCount, navigationParams's navigation timing type, and navigationParams's response's service worker timing info.
else {
- NavigationTiming::PerformanceNavigationTiming::create_navigation_timing_entry(
+ NavigationTiming::create_the_navigation_timing_entry(
*document,
timing_info,
redirect_count,
diff --git a/Libraries/LibWeb/EventTiming/EventTiming.cpp b/Libraries/LibWeb/EventTiming/EventTiming.cpp
index 0bdce839de0..cae7c61368e 100644
--- a/Libraries/LibWeb/EventTiming/EventTiming.cpp
+++ b/Libraries/LibWeb/EventTiming/EventTiming.cpp
@@ -21,7 +21,6 @@
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Page/Page.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/InputEvent.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
@@ -549,7 +548,7 @@ static void set_event_timing_entry_duration(PerformanceEventTiming& timing_entry
if (!state.has_dispatched_input_event && timing_entry.interaction_id() != 0) {
// 1. Let firstInputEntry be a copy of timingEntry.
// 2. Set firstInputEntry's entryType to "first-input".
- auto first_input_entry = timing_entry.copy_with_entry_type(PerformanceTimeline::EntryTypes::first_input);
+ auto first_input_entry = timing_entry.copy_with_entry_type("first-input"_utf16_fly_string);
// 3. Queue firstInputEntry.
window.queue_performance_entry(first_input_entry);
diff --git a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp
index 42cd526ad62..503da99cb79 100644
--- a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp
+++ b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp
@@ -4,97 +4,77 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
-#include <LibWeb/DOM/Element.h>
+#include <LibJS/HostClassBuilder.h>
+#include <LibJS/Runtime/VM.h>
#include <LibWeb/DOM/Event.h>
+#include <LibWeb/DOM/Node.h>
#include <LibWeb/EventTiming/PerformanceEventTiming.h>
-#include <LibWeb/PaintTiming/PaintTiming.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
namespace Web::EventTiming {
-GC_DEFINE_ALLOCATOR(PerformanceEventTiming);
+extern "C" {
+// Defined in Bindings/Rust/src/event_timing/performance_event_timing.rs.
+PerformanceEventTiming* web_rust_event_timing_create_performance_event_timing(JSVM*, FlatPtr name, double start_time, double processing_start, bool cancelable, u64 interaction_id);
+PerformanceEventTiming* web_rust_event_timing_copy_with_entry_type(JSVM*, PerformanceEventTiming const*, FlatPtr entry_type);
+bool web_rust_event_timing_has_duration(PerformanceEventTiming const*);
+void web_rust_event_timing_set_duration(PerformanceEventTiming*, double duration);
+void web_rust_event_timing_set_processing_end(PerformanceEventTiming*, double processing_end);
+void web_rust_event_timing_set_event_target(JSVM*, PerformanceEventTiming*, DOM::Node*);
+void web_rust_event_timing_set_target_selector(PerformanceEventTiming*, FlatPtr target_selector);
+u64 web_rust_event_timing_interaction_id(PerformanceEventTiming const*);
+void web_rust_event_timing_set_interaction_id(PerformanceEventTiming*, u64 interaction_id);
+}
// https://w3c.github.io/event-timing/#initialize-event-timing
GC::Ref<PerformanceEventTiming> PerformanceEventTiming::create(DOM::Event const& event, HighResolutionTime::DOMHighResTimeStamp processing_start, WebIDL::UnsignedLongLong interaction_id)
{
- // 2. Let timingEntry be a new PerformanceEventTiming object with event's relevant realm.
- // 3. Set timingEntry's name to event's type attribute value.
- // 4. Set timingEntry's entryType to "event".
- // 5. Set timingEntry's startTime to event's timeStamp attribute value.
- // 6. Set timingEntry's processingStart to processingStart.
- // 7. Set timingEntry's cancelable to event's cancelable attribute value.
- // 8. Set timingEntry's interactionId to interactionId.
- return GC::Heap::the().allocate<PerformanceEventTiming>(Utf16String::from_utf16(event.type().view()), PerformanceTimeline::EntryTypes::event, event.time_stamp(), processing_start, event.cancelable(), interaction_id);
+ return *web_rust_event_timing_create_performance_event_timing(
+ JS::HostABI::vm_to_abi(JS::VM::the()),
+ Utf16String::from_utf16(event.type().view()).into_raw(),
+ event.time_stamp(),
+ processing_start,
+ event.cancelable(),
+ interaction_id);
}
-PerformanceEventTiming::PerformanceEventTiming(Utf16String const& name, Utf16FlyString const& entry_type, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp processing_start, bool cancelable, WebIDL::UnsignedLongLong interaction_id)
- : PerformanceTimeline::PerformanceEntry(name, start_time, 0)
- , m_entry_type(entry_type)
- , m_processing_start(processing_start)
- , m_cancelable(cancelable)
- , m_interaction_id(interaction_id)
+GC::Ref<PerformanceEventTiming> PerformanceEventTiming::copy_with_entry_type(Utf16FlyString const& entry_type) const
{
+ return *web_rust_event_timing_copy_with_entry_type(JS::HostABI::vm_to_abi(JS::VM::the()), this, entry_type.raw_identity());
}
-PerformanceEventTiming::~PerformanceEventTiming() = default;
-
-GC::Ref<PerformanceEventTiming> PerformanceEventTiming::copy_with_entry_type(Utf16FlyString const& entry_type) const
+bool PerformanceEventTiming::has_duration() const
{
- auto copy = GC::Heap::the().allocate<PerformanceEventTiming>(name(), entry_type, start_time(), m_processing_start, m_cancelable, m_interaction_id);
- copy->m_duration = m_duration;
- copy->m_has_duration = m_has_duration;
- copy->m_processing_end = m_processing_end;
- copy->m_event_target = m_event_target;
- copy->m_target_selector = m_target_selector;
- return copy;
+ return web_rust_event_timing_has_duration(this);
}
-// https://w3c.github.io/event-timing/#dom-performanceeventtiming-target
-GC::Ptr<DOM::Node> PerformanceEventTiming::target() const
+void PerformanceEventTiming::set_duration(HighResolutionTime::DOMHighResTimeStamp duration)
{
- // 1. If this's eventTarget is not exposed for paint timing given null, return null.
- // NB: Only elements can be exposed for paint timing.
- auto const* element = as_if<DOM::Element>(m_event_target.ptr());
- if (!element || !PaintTiming::is_exposed_for_paint_timing(*element, nullptr))
- return nullptr;
-
- // 2. Return this's eventTarget.
- return m_event_target;
+ web_rust_event_timing_set_duration(this, duration);
}
-// https://w3c.github.io/event-timing/#should-add-performanceeventtiming
-PerformanceTimeline::ShouldAddEntry PerformanceEventTiming::should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> options) const
+void PerformanceEventTiming::set_processing_end(HighResolutionTime::DOMHighResTimeStamp processing_end)
{
- // 1. If entry's entryType attribute value equals to "first-input", return true.
- if (entry_type() == PerformanceTimeline::EntryTypes::first_input)
- return PerformanceTimeline::ShouldAddEntry::Yes;
-
- // 2. Assert that entry's entryType attribute value equals "event".
- VERIFY(entry_type() == PerformanceTimeline::EntryTypes::event);
-
- // 3. Let minDuration be computed as follows:
- HighResolutionTime::DOMHighResTimeStamp min_duration = 0;
+ web_rust_event_timing_set_processing_end(this, processing_end);
+}
- // 1. If options is not present or if options's durationThreshold is not present, let minDuration be 104.
- if (!options.has_value() || !options->duration_threshold.has_value())
- min_duration = 104;
- // 2. Otherwise, let minDuration be the maximum between 16 and options's durationThreshold value.
- else
- min_duration = max(16.0, options->duration_threshold.value());
+void PerformanceEventTiming::set_event_target(GC::Ptr<DOM::Node> event_target)
+{
+ web_rust_event_timing_set_event_target(JS::HostABI::vm_to_abi(JS::VM::the()), this, event_target.ptr());
+}
- // 4. If entry's duration attribute value is greater than or equal to minDuration, return true.
- if (duration() >= min_duration)
- return PerformanceTimeline::ShouldAddEntry::Yes;
+void PerformanceEventTiming::set_target_selector(Utf16String target_selector)
+{
+ web_rust_event_timing_set_target_selector(this, move(target_selector).into_raw());
+}
- // 5. Otherwise, return false.
- return PerformanceTimeline::ShouldAddEntry::No;
+WebIDL::UnsignedLongLong PerformanceEventTiming::interaction_id() const
+{
+ return web_rust_event_timing_interaction_id(this);
}
-void PerformanceEventTiming::visit_edges(GC::Cell::Visitor& visitor)
+void PerformanceEventTiming::set_interaction_id(WebIDL::UnsignedLongLong interaction_id)
{
- Base::visit_edges(visitor);
- visitor.visit(m_event_target);
+ web_rust_event_timing_set_interaction_id(this, interaction_id);
}
}
diff --git a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h
index 959bba9f690..25a9bd7de34 100644
--- a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h
+++ b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h
@@ -6,6 +6,8 @@
#pragma once
+#include <AK/Utf16FlyString.h>
+#include <LibWeb/Bindings/PerformanceEventTiming.h>
#include <LibWeb/Forward.h>
#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
#include <LibWebCommon/WebIDL/Types.h>
@@ -14,65 +16,21 @@ namespace Web::EventTiming {
// https://w3c.github.io/event-timing/#sec-performance-event-timing
class PerformanceEventTiming final : public PerformanceTimeline::PerformanceEntry {
- WEB_WRAPPABLE(PerformanceEventTiming, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(PerformanceEventTiming);
+ WEB_RUST_INTERFACE(PerformanceEventTiming, performance_event_timing)
public:
static GC::Ref<PerformanceEventTiming> create(DOM::Event const&, HighResolutionTime::DOMHighResTimeStamp processing_start, WebIDL::UnsignedLongLong interaction_id);
- virtual ~PerformanceEventTiming();
-
// A copy of this entry, with the given entry type.
GC::Ref<PerformanceEventTiming> copy_with_entry_type(Utf16FlyString const& entry_type) const;
- virtual Utf16FlyString const& entry_type() const override { return m_entry_type; }
-
- virtual HighResolutionTime::DOMHighResTimeStamp duration() const override { return m_duration; }
- void set_duration(HighResolutionTime::DOMHighResTimeStamp duration)
- {
- m_duration = duration;
- m_has_duration = true;
- }
- bool has_duration() const { return m_has_duration; }
-
- HighResolutionTime::DOMHighResTimeStamp processing_start() const { return m_processing_start; }
-
- HighResolutionTime::DOMHighResTimeStamp processing_end() const { return m_processing_end; }
- void set_processing_end(HighResolutionTime::DOMHighResTimeStamp processing_end) { m_processing_end = processing_end; }
-
- bool cancelable() const { return m_cancelable; }
-
- GC::Ptr<DOM::Node> target() const;
- void set_event_target(GC::Ptr<DOM::Node> event_target) { m_event_target = event_target; }
-
- Utf16String const& target_selector() const { return m_target_selector; }
- void set_target_selector(Utf16String target_selector) { m_target_selector = move(target_selector); }
-
- WebIDL::UnsignedLongLong interaction_id() const { return m_interaction_id; }
- void set_interaction_id(WebIDL::UnsignedLongLong interaction_id) { m_interaction_id = interaction_id; }
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override;
-
-private:
- PerformanceEventTiming(Utf16String const& name, Utf16FlyString const& entry_type, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp processing_start, bool cancelable, WebIDL::UnsignedLongLong interaction_id);
-
- virtual void visit_edges(GC::Cell::Visitor&) override;
-
- // NB: An entry is "event", unless it is the copy of an entry that is queued as the first input.
- Utf16FlyString m_entry_type;
-
- HighResolutionTime::DOMHighResTimeStamp m_duration { 0 };
- bool m_has_duration { false };
- HighResolutionTime::DOMHighResTimeStamp m_processing_start { 0 };
- HighResolutionTime::DOMHighResTimeStamp m_processing_end { 0 };
- bool m_cancelable { false };
-
- // https://w3c.github.io/event-timing/#eventtarget
- GC::Ptr<DOM::Node> m_event_target;
-
- Utf16String m_target_selector;
- WebIDL::UnsignedLongLong m_interaction_id { 0 };
+ bool has_duration() const;
+ void set_duration(HighResolutionTime::DOMHighResTimeStamp);
+ void set_processing_end(HighResolutionTime::DOMHighResTimeStamp);
+ void set_event_target(GC::Ptr<DOM::Node>);
+ void set_target_selector(Utf16String);
+ WebIDL::UnsignedLongLong interaction_id() const;
+ void set_interaction_id(WebIDL::UnsignedLongLong);
};
}
diff --git a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.idl b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.idl
index 883bb4d229f..5f1a5d390ff 100644
--- a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.idl
+++ b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/event-timing/#sec-performance-event-timing
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface PerformanceEventTiming : PerformanceEntry {
readonly attribute DOMHighResTimeStamp processingStart;
readonly attribute DOMHighResTimeStamp processingEnd;
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index c4ea0f3cf58..7f0015f20e0 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -1163,7 +1163,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// request’s URL, request’s initiator type, global, cacheState, bodyInfo, and responseStatus.
if (fetch_params->request()->initiator_type().has_value()) {
auto initiator_type = Infrastructure::initiator_type_to_string(fetch_params->request()->initiator_type().value());
- ResourceTiming::PerformanceResourceTiming::mark_resource_timing(timing_info, utf16_string_from_url_ascii(fetch_params->request()->url().serialize()), initiator_type, global, cache_state, body_info, response_status);
+ ResourceTiming::mark_resource_timing(timing_info, utf16_string_from_url_ascii(fetch_params->request()->url().serialize()), initiator_type, global, cache_state, body_info, response_status);
}
}));
});
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp
index 892afaad707..0e3e456dd4b 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp
@@ -76,4 +76,75 @@ void FetchTimingInfo::update_final_timings(Requests::RequestTimingInfo const& fi
m_final_network_response_start_time = coarsened_response_start_time;
}
+// The values of a FetchTimingInfo, as Bindings/Rust/src/fetch/infrastructure/fetch_timing_info.rs reads them.
+struct FetchTimingInfoABI {
+ HighResolutionTime::DOMHighResTimeStamp start_time;
+ HighResolutionTime::DOMHighResTimeStamp redirect_start_time;
+ HighResolutionTime::DOMHighResTimeStamp redirect_end_time;
+ HighResolutionTime::DOMHighResTimeStamp post_redirect_start_time;
+ HighResolutionTime::DOMHighResTimeStamp final_service_worker_start_time;
+ HighResolutionTime::DOMHighResTimeStamp final_network_request_start_time;
+ HighResolutionTime::DOMHighResTimeStamp first_interim_network_response_start_time;
+ HighResolutionTime::DOMHighResTimeStamp final_network_response_start_time;
+ HighResolutionTime::DOMHighResTimeStamp end_time;
+ HighResolutionTime::DOMHighResTimeStamp domain_lookup_start_time;
+ HighResolutionTime::DOMHighResTimeStamp domain_lookup_end_time;
+ HighResolutionTime::DOMHighResTimeStamp connection_start_time;
+ HighResolutionTime::DOMHighResTimeStamp connection_end_time;
+ HighResolutionTime::DOMHighResTimeStamp secure_connection_start_time;
+ bool has_final_connection_timing_info;
+ bool render_blocking;
+};
+
+extern "C" {
+void web_fetch_timing_info_read(FetchTimingInfo const*, FetchTimingInfoABI*);
+void web_fetch_timing_info_alpn_negotiated_protocol(FetchTimingInfo const*, void* context, void (*callback)(void*, ReadonlyBytes));
+void web_fetch_timing_info_for_each_server_timing_header(FetchTimingInfo const*, void* context, void (*callback)(void*, ReadonlyBytes));
+void web_fetch_timing_info_unref(FetchTimingInfo*);
+}
+
+extern "C" {
+
+void web_fetch_timing_info_read(FetchTimingInfo const* timing_info, FetchTimingInfoABI* values)
+{
+ auto const& connection_timing_info = timing_info->final_connection_timing_info();
+ *values = {
+ .start_time = timing_info->start_time(),
+ .redirect_start_time = timing_info->redirect_start_time(),
+ .redirect_end_time = timing_info->redirect_end_time(),
+ .post_redirect_start_time = timing_info->post_redirect_start_time(),
+ .final_service_worker_start_time = timing_info->final_service_worker_start_time(),
+ .final_network_request_start_time = timing_info->final_network_request_start_time(),
+ .first_interim_network_response_start_time = timing_info->first_interim_network_response_start_time(),
+ .final_network_response_start_time = timing_info->final_network_response_start_time(),
+ .end_time = timing_info->end_time(),
+ .domain_lookup_start_time = connection_timing_info.has_value() ? connection_timing_info->domain_lookup_start_time : 0,
+ .domain_lookup_end_time = connection_timing_info.has_value() ? connection_timing_info->domain_lookup_end_time : 0,
+ .connection_start_time = connection_timing_info.has_value() ? connection_timing_info->connection_start_time : 0,
+ .connection_end_time = connection_timing_info.has_value() ? connection_timing_info->connection_end_time : 0,
+ .secure_connection_start_time = connection_timing_info.has_value() ? connection_timing_info->secure_connection_start_time : 0,
+ .has_final_connection_timing_info = connection_timing_info.has_value(),
+ .render_blocking = timing_info->render_blocking(),
+ };
+}
+
+void web_fetch_timing_info_alpn_negotiated_protocol(FetchTimingInfo const* timing_info, void* context, void (*callback)(void*, ReadonlyBytes))
+{
+ auto const& connection_timing_info = timing_info->final_connection_timing_info();
+ if (connection_timing_info.has_value())
+ callback(context, connection_timing_info->alpn_negotiated_protocol.bytes());
+}
+
+void web_fetch_timing_info_for_each_server_timing_header(FetchTimingInfo const* timing_info, void* context, void (*callback)(void*, ReadonlyBytes))
+{
+ for (auto const& header : timing_info->server_timing_headers())
+ callback(context, header.bytes());
+}
+
+void web_fetch_timing_info_unref(FetchTimingInfo* timing_info)
+{
+ timing_info->unref();
+}
+}
+
}
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 98b587069e9..21987c63489 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -979,9 +979,7 @@ namespace Web::MimeSniff {
namespace Web::NavigationTiming {
-class PerformanceNavigation;
class PerformanceNavigationTiming;
-class PerformanceTiming;
}
@@ -1205,13 +1203,6 @@ class URLSearchParams;
}
-namespace Web::UserTiming {
-
-class PerformanceMark;
-class PerformanceMeasure;
-
-}
-
namespace Web::ViewTransition {
class ViewTransition;
diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
index a83de500d6c..3ee0204b7c0 100644
--- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
@@ -307,7 +307,7 @@ void run_iframe_load_event_steps(HTMLIFrameElement& element)
// 4. Mark resource timing given fallbackTimingInfo, the result of parsing element's pending resource-timing
// URL, "iframe", global, the empty string, a new response body info, and 0.
// FIXME: Our URL is already parsed, how are we supposed to parse it?
- ResourceTiming::PerformanceResourceTiming::mark_resource_timing(
+ ResourceTiming::mark_resource_timing(
fallback_timing_info,
utf16_string_from_url_ascii(element.pending_resource_timing_url()->to_string()),
"iframe"_utf16_fly_string,
diff --git a/Libraries/LibWeb/HTML/VisibilityStateEntry.cpp b/Libraries/LibWeb/HTML/VisibilityStateEntry.cpp
index 7c739abf3a1..2a464b6e024 100644
--- a/Libraries/LibWeb/HTML/VisibilityStateEntry.cpp
+++ b/Libraries/LibWeb/HTML/VisibilityStateEntry.cpp
@@ -4,36 +4,24 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
+#include <LibJS/HostClassBuilder.h>
+#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/Document.h>
#include <LibWeb/HTML/VisibilityStateEntry.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
namespace Web::HTML {
-GC_DEFINE_ALLOCATOR(VisibilityStateEntry);
-
-// https://html.spec.whatwg.org/multipage/interaction.html#visibilitystateentry
-VisibilityStateEntry::VisibilityStateEntry(VisibilityState visibility_state, HighResolutionTime::DOMHighResTimeStamp timestamp)
- // The name getter steps are to return this's visibility state.
- // The startTime getter steps are to return this's timestamp.
- // The duration getter steps are to return zero.
- : PerformanceTimeline::PerformanceEntry(Bindings::idl_enum_to_string(visibility_state), timestamp, 0)
-{
+extern "C" {
+// Defined in Bindings/Rust/src/html/visibility_state_entry.rs.
+VisibilityStateEntry* web_rust_html_create_visibility_state_entry(JSVM*, FlatPtr visibility_state, double timestamp);
}
-VisibilityStateEntry::~VisibilityStateEntry() = default;
-
GC::Ref<VisibilityStateEntry> VisibilityStateEntry::create(VisibilityState visibility_state, HighResolutionTime::DOMHighResTimeStamp timestamp)
{
- return GC::Heap::the().allocate<VisibilityStateEntry>(visibility_state, timestamp);
-}
-
-// https://html.spec.whatwg.org/multipage/interaction.html#dom-visibilitystateentry-entrytype
-Utf16FlyString const& VisibilityStateEntry::entry_type() const
-{
- // The entryType getter steps are to return "visibility-state".
- return PerformanceTimeline::EntryTypes::visibility_state;
+ return *web_rust_html_create_visibility_state_entry(
+ JS::HostABI::vm_to_abi(JS::VM::the()),
+ Bindings::idl_enum_to_string(visibility_state).into_raw(),
+ timestamp);
}
}
diff --git a/Libraries/LibWeb/HTML/VisibilityStateEntry.h b/Libraries/LibWeb/HTML/VisibilityStateEntry.h
index ce631fd4877..037a76a0cae 100644
--- a/Libraries/LibWeb/HTML/VisibilityStateEntry.h
+++ b/Libraries/LibWeb/HTML/VisibilityStateEntry.h
@@ -6,6 +6,7 @@
#pragma once
+#include <LibWeb/Bindings/VisibilityStateEntry.h>
#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
#include <LibWebCommon/HTML/VisibilityState.h>
@@ -13,21 +14,10 @@ namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/interaction.html#visibilitystateentry
class VisibilityStateEntry final : public PerformanceTimeline::PerformanceEntry {
- WEB_WRAPPABLE(VisibilityStateEntry, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(VisibilityStateEntry);
+ WEB_RUST_INTERFACE(VisibilityStateEntry, visibility_state_entry)
public:
- virtual ~VisibilityStateEntry() override;
-
static GC::Ref<VisibilityStateEntry> create(VisibilityState, HighResolutionTime::DOMHighResTimeStamp timestamp);
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
-
-private:
- VisibilityStateEntry(VisibilityState, HighResolutionTime::DOMHighResTimeStamp timestamp);
};
}
diff --git a/Libraries/LibWeb/HTML/VisibilityStateEntry.idl b/Libraries/LibWeb/HTML/VisibilityStateEntry.idl
index 48dfd7d05ff..d88b536bb5c 100644
--- a/Libraries/LibWeb/HTML/VisibilityStateEntry.idl
+++ b/Libraries/LibWeb/HTML/VisibilityStateEntry.idl
@@ -1,5 +1,5 @@
// https://html.spec.whatwg.org/multipage/interaction.html#visibilitystateentry
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface VisibilityStateEntry : PerformanceEntry {
[Default] object toJSON();
};
diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
index 4dda6a67216..4487ae1cd36 100644
--- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
+++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
@@ -64,7 +64,6 @@
#include <LibWeb/Infra/SerializedURL.h>
#include <LibWeb/LargestContentfulPaint/LargestContentfulPaint.h>
#include <LibWeb/Loader/LoaderConfig.h>
-#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/PaintTiming/PerformancePaintTiming.h>
@@ -72,7 +71,6 @@
#include <LibWeb/PermissionsAPI/PermissionStatus.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/Platform/ImageCodecPlugin.h>
-#include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
#include <LibWeb/SVG/SVGDecodedImageData.h>
#include <LibWeb/SVG/SVGImageElement.h>
#include <LibWeb/ServiceWorker/CacheStorage.h>
@@ -233,7 +231,6 @@ JSCompletion web_rust_structured_clone(JSVM*, void* realm, JSValue, JSObject* co
HighResolutionTime::Performance* web_rust_performance_timeline_performance(JSVM*, void* realm);
void web_rust_performance_timeline_queue_performance_entry(JSVM*, void* realm, PerformanceTimeline::PerformanceEntry*);
void web_rust_performance_timeline_add_performance_entry(JSVM*, void* realm, PerformanceTimeline::PerformanceEntry*, bool check_if_performance_buffer_is_full);
-void web_rust_performance_timeline_add_resource_timing_entry(JSVM*, void* realm, PerformanceTimeline::PerformanceEntry*);
}
// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone
@@ -1070,12 +1067,6 @@ void WindowOrWorkerGlobalScopeMixin::add_performance_entry(GC::Ref<PerformanceTi
web_rust_performance_timeline_add_performance_entry(JS::HostABI::vm_to_abi(realm.vm()), &realm, new_entry.ptr(), check_if_performance_buffer_is_full == CheckIfPerformanceBufferIsFull::Yes);
}
-void WindowOrWorkerGlobalScopeMixin::add_resource_timing_entry(Badge<ResourceTiming::PerformanceResourceTiming>, GC::Ref<ResourceTiming::PerformanceResourceTiming> entry)
-{
- auto& realm = relevant_realm(*this);
- web_rust_performance_timeline_add_resource_timing_entry(JS::HostABI::vm_to_abi(realm.vm()), &realm, entry.ptr());
-}
-
void WindowOrWorkerGlobalScopeMixin::register_event_source(Badge<EventSource>, GC::Ref<EventSource> event_source)
{
m_registered_event_sources.set(event_source);
diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
index 490347f77d7..92e21c43d17 100644
--- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
+++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
@@ -67,8 +67,6 @@ public:
void queue_performance_entry(GC::Ref<PerformanceTimeline::PerformanceEntry> new_entry);
void add_performance_entry(GC::Ref<PerformanceTimeline::PerformanceEntry> new_entry, CheckIfPerformanceBufferIsFull check_if_performance_buffer_is_full = CheckIfPerformanceBufferIsFull::No);
- void add_resource_timing_entry(Badge<ResourceTiming::PerformanceResourceTiming>, GC::Ref<ResourceTiming::PerformanceResourceTiming> entry);
-
void register_event_source(Badge<EventSource>, GC::Ref<EventSource>);
void register_permission_status(PermissionsAPI::PermissionStatus&);
void unregister_event_source(Badge<EventSource>, GC::Ref<EventSource>);
diff --git a/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp b/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
index b1247f5d5a4..5899dec0409 100644
--- a/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
+++ b/Libraries/LibWeb/HighResolutionTime/TimeOrigin.cpp
@@ -16,6 +16,8 @@ namespace Web::HighResolutionTime {
extern "C" {
double web_high_resolution_time_current_high_resolution_time(JSObject* global_object);
double web_high_resolution_time_get_time_origin_timestamp(JSObject* global_object);
+double web_high_resolution_time_estimated_monotonic_time_of_the_unix_epoch();
+double web_high_resolution_time_coarsen_time(double timestamp);
}
// https://w3c.github.io/hr-time/#dfn-estimated-monotonic-time-of-the-unix-epoch
@@ -136,6 +138,16 @@ double web_high_resolution_time_get_time_origin_timestamp(JSObject* global_objec
{
return get_time_origin_timestamp(*JS::HostABI::object_from_abi(global_object));
}
+
+double web_high_resolution_time_estimated_monotonic_time_of_the_unix_epoch()
+{
+ return estimated_monotonic_time_of_the_unix_epoch();
+}
+
+double web_high_resolution_time_coarsen_time(double timestamp)
+{
+ return coarsen_time(timestamp);
+}
}
}
diff --git a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp
index 631c0e842f7..8b7d8eae5dc 100644
--- a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp
+++ b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp
@@ -4,7 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
+#include <LibJS/HostClassBuilder.h>
+#include <LibJS/Runtime/VM.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Text.h>
@@ -16,57 +17,26 @@
#include <LibWeb/PaintTiming/PaintTiming.h>
#include <LibWeb/Painting/BoxModelMetrics.h>
#include <LibWeb/Painting/BoxViews.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
namespace Web::LargestContentfulPaint {
-GC_DEFINE_ALLOCATOR(LargestContentfulPaint);
-
-GC::Ref<LargestContentfulPaint> LargestContentfulPaint::create(PaintTiming::PaintTimingInfo paint_timing_info, WebIDL::UnsignedLong size, Utf16String url, Utf16String id, HighResolutionTime::DOMHighResTimeStamp load_time, GC::Ref<DOM::Element> element)
-{
- return GC::Heap::the().allocate<LargestContentfulPaint>(paint_timing_info, size, move(url), move(id), load_time, element);
-}
-
-// https://w3c.github.io/largest-contentful-paint/#sec-largest-contentful-paint-interface
-LargestContentfulPaint::LargestContentfulPaint(PaintTiming::PaintTimingInfo paint_timing_info, WebIDL::UnsignedLong size, Utf16String url, Utf16String id, HighResolutionTime::DOMHighResTimeStamp load_time, GC::Ref<DOM::Element> element)
- // The name attribute's getter must return the empty string.
- // The startTime attribute's getter must return the value of this's renderTime.
- // The duration attribute's getter must return 0.
- : PerformanceTimeline::PerformanceEntry(Utf16String {}, PaintTiming::default_paint_timestamp(paint_timing_info), 0)
- , PaintTiming::PaintTimingMixin(paint_timing_info)
- , m_size(size)
- , m_load_time(load_time)
- , m_id(move(id))
- , m_url(move(url))
- , m_element(element)
-{
+extern "C" {
+// Defined in Bindings/Rust/src/largest_contentful_paint/largest_contentful_paint.rs.
+LargestContentfulPaint* web_rust_largest_contentful_paint_create(JSVM*, double rendering_update_end_time, bool has_presentation_time, double presentation_time, u32 size, FlatPtr url, FlatPtr id, double load_time, DOM::Element*);
}
-LargestContentfulPaint::~LargestContentfulPaint() = default;
-
-Utf16FlyString const& LargestContentfulPaint::entry_type() const
-{
- // The entryType attribute's getter must return the DOMString "largest-contentful-paint".
- return PerformanceTimeline::EntryTypes::largest_contentful_paint;
-}
-
-// https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-rendertime
-HighResolutionTime::DOMHighResTimeStamp LargestContentfulPaint::render_time() const
-{
- // The renderTime attribute must return the default paint timestamp given this's paint timing info.
- return PaintTiming::default_paint_timestamp(paint_timing_info());
-}
-
-// https://w3c.github.io/largest-contentful-paint/#dom-largestcontentfulpaint-element
-GC::Ptr<DOM::Element> LargestContentfulPaint::element() const
+GC::Ref<LargestContentfulPaint> LargestContentfulPaint::create(PaintTiming::PaintTimingInfo paint_timing_info, WebIDL::UnsignedLong size, Utf16String url, Utf16String id, HighResolutionTime::DOMHighResTimeStamp load_time, GC::Ref<DOM::Element> element)
{
- // 1. If this's element is not exposed for paint timing given null, return null.
- auto element = m_element.ptr();
- if (!element || !PaintTiming::is_exposed_for_paint_timing(*element, nullptr))
- return nullptr;
-
- // 2. Return this's element.
- return element;
+ return *web_rust_largest_contentful_paint_create(
+ JS::HostABI::vm_to_abi(JS::VM::the()),
+ paint_timing_info.rendering_update_end_time,
+ paint_timing_info.implementation_defined_presentation_time.has_value(),
+ paint_timing_info.implementation_defined_presentation_time.value_or(0),
+ size,
+ move(url).into_raw(),
+ move(id).into_raw(),
+ load_time,
+ element.ptr());
}
// https://w3c.github.io/largest-contentful-paint/#effective-visual-size-result
diff --git a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.h b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.h
index 3118c9daa04..1b077cddde4 100644
--- a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.h
+++ b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.h
@@ -6,6 +6,7 @@
#pragma once
+#include <LibWeb/Bindings/LargestContentfulPaint.h>
#include <LibWeb/Forward.h>
#include <LibWeb/PaintTiming/DocumentPaintTimingState.h>
#include <LibWeb/PaintTiming/PaintTimingMixin.h>
@@ -15,47 +16,11 @@
namespace Web::LargestContentfulPaint {
// https://w3c.github.io/largest-contentful-paint/#sec-largest-contentful-paint-interface
-class LargestContentfulPaint final
- : public PerformanceTimeline::PerformanceEntry
- , public PaintTiming::PaintTimingMixin {
- WEB_WRAPPABLE(LargestContentfulPaint, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(LargestContentfulPaint);
+class LargestContentfulPaint final : public PerformanceTimeline::PerformanceEntry {
+ WEB_RUST_INTERFACE(LargestContentfulPaint, largest_contentful_paint)
public:
static GC::Ref<LargestContentfulPaint> create(PaintTiming::PaintTimingInfo, WebIDL::UnsignedLong size, Utf16String url, Utf16String id, HighResolutionTime::DOMHighResTimeStamp load_time, GC::Ref<DOM::Element>);
-
- virtual ~LargestContentfulPaint() override;
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
-
- HighResolutionTime::DOMHighResTimeStamp load_time() const { return m_load_time; }
- HighResolutionTime::DOMHighResTimeStamp render_time() const;
- WebIDL::UnsignedLong size() const { return m_size; }
- Utf16String const& id() const { return m_id; }
- Utf16String const& url() const { return m_url; }
- GC::Ptr<DOM::Element> element() const;
-
-private:
- LargestContentfulPaint(PaintTiming::PaintTimingInfo, WebIDL::UnsignedLong size, Utf16String url, Utf16String id, HighResolutionTime::DOMHighResTimeStamp load_time, GC::Ref<DOM::Element>);
-
- // https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-size
- WebIDL::UnsignedLong m_size { 0 };
-
- // https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-loadtime
- HighResolutionTime::DOMHighResTimeStamp m_load_time { 0 };
-
- // https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-id
- Utf16String m_id;
-
- // https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-url
- Utf16String m_url;
-
- // https://w3c.github.io/largest-contentful-paint/#largestcontentfulpaint-element
- // NB: Held weakly, as the element getter returns null for an element that is not connected.
- GC::Weak<DOM::Element> m_element;
};
// https://w3c.github.io/largest-contentful-paint/#report-largest-contentful-paint
diff --git a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.idl b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.idl
index d4bf895f381..37436900d70 100644
--- a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.idl
+++ b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/largest-contentful-paint/#sec-largest-contentful-paint-interface
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface LargestContentfulPaint : PerformanceEntry {
readonly attribute DOMHighResTimeStamp loadTime;
readonly attribute DOMHighResTimeStamp renderTime;
diff --git a/Libraries/LibWeb/NavigationTiming/EntryNames.cpp b/Libraries/LibWeb/NavigationTiming/EntryNames.cpp
deleted file mode 100644
index d17783afe09..00000000000
--- a/Libraries/LibWeb/NavigationTiming/EntryNames.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibWeb/NavigationTiming/EntryNames.h>
-
-namespace Web::NavigationTiming::EntryNames {
-
-#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) \
- Utf16FlyString const& name = *new Utf16FlyString(#name##_utf16_fly_string);
-ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
-#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
-
-}
diff --git a/Libraries/LibWeb/NavigationTiming/EntryNames.h b/Libraries/LibWeb/NavigationTiming/EntryNames.h
deleted file mode 100644
index 6a2cf8aba93..00000000000
--- a/Libraries/LibWeb/NavigationTiming/EntryNames.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Utf16FlyString.h>
-
-namespace Web::NavigationTiming::EntryNames {
-
-#define ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(connectEnd, connect_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(connectStart, connect_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domainLookupEnd, domain_lookup_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domainLookupStart, domain_lookup_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domComplete, dom_complete) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domContentLoadedEventEnd, dom_content_loaded_event_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domContentLoadedEventStart, dom_content_loaded_event_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domInteractive, dom_interactive) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(domLoading, dom_loading) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(fetchStart, fetch_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(loadEventEnd, load_event_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(loadEventStart, load_event_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(navigationStart, navigation_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(redirectEnd, redirect_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(redirectStart, redirect_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(requestStart, request_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(responseEnd, response_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(responseStart, response_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(secureConnectionStart, secure_connection_start) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(unloadEventEnd, unload_event_end) \
- __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(unloadEventStart, unload_event_start)
-
-#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) extern Utf16FlyString const& name;
-ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
-#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
-
-}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.cpp b/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.cpp
deleted file mode 100644
index 0bdeed67c75..00000000000
--- a/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2024, Colin Reeder <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibGC/Heap.h>
-#include <LibWeb/DOM/Document.h>
-#include <LibWeb/HTML/Window.h>
-#include <LibWeb/NavigationTiming/PerformanceNavigation.h>
-#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
-
-namespace Web::NavigationTiming {
-
-extern "C" {
-PerformanceNavigation* web_navigation_timing_performance_navigation_create(HTML::Window*);
-}
-
-GC_DEFINE_ALLOCATOR(PerformanceNavigation);
-
-GC::Ref<PerformanceNavigation> PerformanceNavigation::create(HTML::Window& window)
-{
- return GC::Heap::the().allocate<PerformanceNavigation>(window);
-}
-
-PerformanceNavigation::PerformanceNavigation(HTML::Window& window)
- : m_window(window)
-{
-}
-
-PerformanceNavigation::~PerformanceNavigation() = default;
-
-void PerformanceNavigation::visit_edges(GC::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_window);
-}
-
-GC::Ptr<PerformanceNavigationTiming> PerformanceNavigation::navigation_timing_entry() const
-{
- return m_window->associated_document().navigation_timing_entry();
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancenavigation-type
-u16 PerformanceNavigation::type() const
-{
- // This attribute must return the type of the last non-redirect navigation. It must have one of the following
- // navigation type values.
- auto entry = navigation_timing_entry();
- if (!entry)
- return TYPE_NAVIGATE;
-
- switch (entry->type()) {
- case Bindings::NavigationTimingType::Navigate:
- return TYPE_NAVIGATE;
- case Bindings::NavigationTimingType::Reload:
- return TYPE_RELOAD;
- case Bindings::NavigationTimingType::BackForward:
- return TYPE_BACK_FORWARD;
- }
- VERIFY_NOT_REACHED();
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancenavigation-redirectcount
-u16 PerformanceNavigation::redirect_count() const
-{
- // This attribute must return the number of redirects since the last non-redirect navigation. If there is no
- // redirect or there is any redirect that is not from the same origin as the destination document, this attribute
- // must return zero.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
-
- return entry->redirect_count();
-}
-
-PerformanceNavigation* web_navigation_timing_performance_navigation_create(HTML::Window* window)
-{
- return PerformanceNavigation::create(*window).ptr();
-}
-
-}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.h b/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.h
deleted file mode 100644
index 66ca9663ac3..00000000000
--- a/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2024, Colin Reeder <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/Forward.h>
-
-namespace Web::NavigationTiming {
-
-// https://w3c.github.io/navigation-timing/#the-performancenavigation-interface
-class PerformanceNavigation final : public Bindings::GCAllocatedWrappable {
- WEB_WRAPPABLE(PerformanceNavigation, Bindings::GCAllocatedWrappable);
- GC_DECLARE_ALLOCATOR(PerformanceNavigation);
-
-public:
- static constexpr u16 TYPE_NAVIGATE = 0;
- static constexpr u16 TYPE_RELOAD = 1;
- static constexpr u16 TYPE_BACK_FORWARD = 2;
- static constexpr u16 TYPE_RESERVED = 255;
-
- static GC::Ref<PerformanceNavigation> create(HTML::Window&);
-
- ~PerformanceNavigation();
-
- u16 type() const;
- u16 redirect_count() const;
-
-private:
- explicit PerformanceNavigation(HTML::Window&);
-
- virtual void visit_edges(GC::Cell::Visitor&) override;
-
- GC::Ptr<PerformanceNavigationTiming> navigation_timing_entry() const;
-
- GC::Ref<HTML::Window> m_window;
-};
-
-}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.idl b/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.idl
index 309291777d4..1b5658dcd20 100644
--- a/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.idl
+++ b/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.idl
@@ -1,4 +1,4 @@
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface PerformanceNavigation {
const unsigned short TYPE_NAVIGATE = 0;
const unsigned short TYPE_RELOAD = 1;
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.cpp b/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.cpp
index 0a88c79e4b0..ad2aaed507f 100644
--- a/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.cpp
+++ b/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.cpp
@@ -4,129 +4,34 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
+#include <LibJS/HostClassBuilder.h>
#include <LibWeb/DOM/Document.h>
+#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
+#include <LibWeb/Infra/SerializedURL.h>
#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
namespace Web::NavigationTiming {
-GC_DEFINE_ALLOCATOR(PerformanceNavigationTiming);
-
-PerformanceNavigationTiming::PerformanceNavigationTiming(DOM::Document& document, Utf16String const& name, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin, u16 redirect_count, Bindings::NavigationTimingType navigation_type)
- : PerformanceResourceTiming(name, 0, 0, move(timing_info), time_origin)
- , m_document(document)
- , m_redirect_count(redirect_count)
- , m_navigation_type(navigation_type)
-{
-}
-
-PerformanceNavigationTiming::~PerformanceNavigationTiming() = default;
-
-void PerformanceNavigationTiming::visit_edges(GC::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_document);
-}
-
-// https://w3c.github.io/navigation-timing/#dfn-create-the-navigation-timing-entry
-void PerformanceNavigationTiming::create_navigation_timing_entry(DOM::Document& document, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, u16 redirect_count, Bindings::NavigationTimingType navigation_type, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo body_info, Fetch::Infrastructure::Status response_status)
-{
- // 1. Let global be document's relevant global object.
- auto& global = HTML::relevant_global_object(document);
-
- // 2. Let navigationTimingEntry be a new PerformanceNavigationTiming object in global's realm.
- auto time_origin = HTML::relevant_settings_object(global).time_origin();
- auto entry = GC::Heap::the().allocate<PerformanceNavigationTiming>(document, utf16_string_from_url_ascii(document.url().serialize()), timing_info, time_origin, redirect_count, navigation_type);
-
- // 3. Setup the resource timing entry for navigationTimingEntry given "navigation", document's URL, fetchTiming,
- // cacheMode, and bodyInfo.
- entry->setup_the_resource_timing_entry(PerformanceTimeline::EntryTypes::navigation, utf16_string_from_url_ascii(document.url().serialize()), move(timing_info), cache_mode, move(body_info), response_status);
-
- // 4-8. The document load timing, previous document unload timing, redirect count, and navigation type are stored by
- // the entry. Service worker timing is not yet implemented.
-
- // 9. Set document's navigation timing entry to navigationTimingEntry.
- document.set_navigation_timing_entry(entry);
-
- // 10-11. Critical-CH restart timing and not-restored reasons are not yet implemented.
-
- // 12. Add navigationTimingEntry to global's performance entry buffer.
- HTML::relevant_window_or_worker_global_scope(global).add_performance_entry(entry);
-}
-
-Utf16FlyString const& PerformanceNavigationTiming::entry_type() const
-{
- return PerformanceTimeline::EntryTypes::navigation;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::duration() const
-{
- return load_event_end();
-}
-
-// https://w3c.github.io/navigation-timing/#PerformanceResourceTiming
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::redirect_start() const
-{
- // 1. If this's redirect count is 0, return 0.
- if (m_redirect_count == 0)
- return 0;
-
- // 2. Otherwise return this's redirectStart.
- return Base::redirect_start();
-}
-
-// https://w3c.github.io/navigation-timing/#PerformanceResourceTiming
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::redirect_end() const
-{
- // 1. If this's redirect count is 0, return 0.
- if (m_redirect_count == 0)
- return 0;
-
- // 2. Otherwise return this's redirectEnd.
- return Base::redirect_end();
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::unload_event_start() const
-{
- return m_document->previous_document_unload_timing().unload_event_start_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::unload_event_end() const
-{
- return m_document->previous_document_unload_timing().unload_event_end_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::dom_interactive() const
-{
- return m_document->load_timing_info().dom_interactive_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::dom_content_loaded_event_start() const
-{
- return m_document->load_timing_info().dom_content_loaded_event_start_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::dom_content_loaded_event_end() const
-{
- return m_document->load_timing_info().dom_content_loaded_event_end_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::dom_complete() const
-{
- return m_document->load_timing_info().dom_complete_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::load_event_start() const
-{
- return m_document->load_timing_info().load_event_start_time;
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceNavigationTiming::load_event_end() const
-{
- return m_document->load_timing_info().load_event_end_time;
+extern "C" {
+// Defined in Bindings/Rust/src/navigation_timing/performance_navigation_timing.rs.
+void web_rust_navigation_timing_create_the_navigation_timing_entry(JSVM*, void* realm, DOM::Document*, FlatPtr document_url, Fetch::Infrastructure::FetchTimingInfo*, u16 redirect_count, u8 navigation_type, u8 cache_mode, ResourceTiming::ResponseBodyInfoABI body_info, u16 response_status);
+}
+
+void create_the_navigation_timing_entry(DOM::Document& document, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, u16 redirect_count, Bindings::NavigationTimingType navigation_type, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo const& body_info, Fetch::Infrastructure::Status response_status)
+{
+ auto& realm = HTML::relevant_realm(document);
+ web_rust_navigation_timing_create_the_navigation_timing_entry(
+ JS::HostABI::vm_to_abi(realm.vm()),
+ &realm,
+ &document,
+ utf16_string_from_url_ascii(document.url().serialize()).into_raw(),
+ &timing_info.leak_ref(),
+ redirect_count,
+ to_underlying(navigation_type),
+ ResourceTiming::cache_state_to_abi(cache_mode),
+ ResourceTiming::response_body_info_to_abi(body_info),
+ response_status);
}
}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.h b/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.h
index 4a1e5a551a5..220b5bb5903 100644
--- a/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.h
+++ b/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.h
@@ -7,47 +7,17 @@
#pragma once
#include <LibWeb/Bindings/PerformanceNavigationTiming.h>
+#include <LibWeb/Forward.h>
#include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
namespace Web::NavigationTiming {
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming
class PerformanceNavigationTiming final : public ResourceTiming::PerformanceResourceTiming {
- WEB_WRAPPABLE(PerformanceNavigationTiming, ResourceTiming::PerformanceResourceTiming);
- GC_DECLARE_ALLOCATOR(PerformanceNavigationTiming);
-
-public:
- virtual ~PerformanceNavigationTiming() override;
-
- static void create_navigation_timing_entry(DOM::Document&, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo>, u16 redirect_count, Bindings::NavigationTimingType, Optional<Fetch::Infrastructure::Response::CacheState> const&, Fetch::Infrastructure::Response::BodyInfo, Fetch::Infrastructure::Status);
-
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
- virtual HighResolutionTime::DOMHighResTimeStamp duration() const override;
- virtual HighResolutionTime::DOMHighResTimeStamp redirect_start() const override;
- virtual HighResolutionTime::DOMHighResTimeStamp redirect_end() const override;
-
- HighResolutionTime::DOMHighResTimeStamp unload_event_start() const;
- HighResolutionTime::DOMHighResTimeStamp unload_event_end() const;
- HighResolutionTime::DOMHighResTimeStamp dom_interactive() const;
- HighResolutionTime::DOMHighResTimeStamp dom_content_loaded_event_start() const;
- HighResolutionTime::DOMHighResTimeStamp dom_content_loaded_event_end() const;
- HighResolutionTime::DOMHighResTimeStamp dom_complete() const;
- HighResolutionTime::DOMHighResTimeStamp load_event_start() const;
- HighResolutionTime::DOMHighResTimeStamp load_event_end() const;
- Bindings::NavigationTimingType type() const { return m_navigation_type; }
- u16 redirect_count() const { return m_redirect_count; }
- HighResolutionTime::DOMHighResTimeStamp critical_ch_restart() const { return 0; }
-
-private:
- PerformanceNavigationTiming(DOM::Document&, Utf16String const& name, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo>, HighResolutionTime::DOMHighResTimeStamp time_origin, u16 redirect_count, Bindings::NavigationTimingType);
-
- virtual void visit_edges(GC::Cell::Visitor&) override;
-
- GC::Ref<DOM::Document> m_document;
- u16 m_redirect_count { 0 };
- Bindings::NavigationTimingType m_navigation_type { Bindings::NavigationTimingType::Navigate };
+ WEB_RUST_INTERFACE(PerformanceNavigationTiming, performance_navigation_timing)
};
+// https://w3c.github.io/navigation-timing/#dfn-create-the-navigation-timing-entry
+void create_the_navigation_timing_entry(DOM::Document&, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo>, u16 redirect_count, Bindings::NavigationTimingType, Optional<Fetch::Infrastructure::Response::CacheState> const&, Fetch::Infrastructure::Response::BodyInfo const&, Fetch::Infrastructure::Status);
+
}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.idl b/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.idl
index d9fb4389cc1..c1d298dfed1 100644
--- a/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.idl
+++ b/Libraries/LibWeb/NavigationTiming/PerformanceNavigationTiming.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface PerformanceNavigationTiming : PerformanceResourceTiming {
readonly attribute DOMHighResTimeStamp unloadEventStart;
readonly attribute DOMHighResTimeStamp unloadEventEnd;
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp b/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp
deleted file mode 100644
index e144b577024..00000000000
--- a/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * Copyright (c) 2021, Andreas Kling <[email protected]>
- * Copyright (c) 2025, Tim Ledbetter <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibGC/Heap.h>
-#include <LibJS/HostClassBuilder.h>
-#include <LibWeb/HighResolutionTime/TimeOrigin.h>
-#include <LibWeb/NavigationTiming/EntryNames.h>
-#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
-#include <LibWeb/NavigationTiming/PerformanceTiming.h>
-
-namespace Web::NavigationTiming {
-
-extern "C" {
-PerformanceTiming* web_navigation_timing_performance_timing_create(HTML::Window*);
-bool web_navigation_timing_is_performance_timing_attribute(FlatPtr name);
-u64 web_navigation_timing_performance_timing_attribute(PerformanceTiming*, FlatPtr name);
-}
-
-GC_DEFINE_ALLOCATOR(PerformanceTiming);
-
-GC::Ref<PerformanceTiming> PerformanceTiming::create(HTML::Window& window)
-{
- return GC::Heap::the().allocate<PerformanceTiming>(window);
-}
-
-PerformanceTiming::PerformanceTiming(HTML::Window& window)
- : m_window(window)
-{
-}
-
-PerformanceTiming::~PerformanceTiming() = default;
-
-void PerformanceTiming::visit_edges(GC::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_window);
-}
-
-// All time values are measured in milliseconds since midnight of January 1, 1970 (UTC).
-u64 PerformanceTiming::monotonic_timestamp_to_wall_time_milliseconds(HighResolutionTime::DOMHighResTimeStamp timestamp) const
-{
- if (timestamp == 0)
- return 0;
-
- auto wall_time = timestamp - HighResolutionTime::estimated_monotonic_time_of_the_unix_epoch();
- auto coarsened_time = HighResolutionTime::coarsen_time(wall_time);
- return static_cast<u64>(coarsened_time);
-}
-
-// The document's time origin is its navigation start time, so a timestamp relative to it becomes monotonic by adding
-// that back. A fetch phase coinciding with navigation start is 0 relative to the time origin without being unset.
-u64 PerformanceTiming::fetch_phase_to_wall_time_milliseconds(HighResolutionTime::DOMHighResTimeStamp relative_timestamp) const
-{
- return monotonic_timestamp_to_wall_time_milliseconds(relative_timestamp + document().load_timing_info().navigation_start_time);
-}
-
-u64 PerformanceTiming::relative_timestamp_to_wall_time_milliseconds(HighResolutionTime::DOMHighResTimeStamp relative_timestamp) const
-{
- if (relative_timestamp == 0)
- return 0;
-
- return fetch_phase_to_wall_time_milliseconds(relative_timestamp);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-navigationstart
-u64 PerformanceTiming::navigation_start() const
-{
- // This attribute must return the time immediately after the user agent finishes prompting to unload the previous
- // document. If there is no previous document, this attribute must return the time the current document is created.
- return monotonic_timestamp_to_wall_time_milliseconds(document().load_timing_info().navigation_start_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-unloadeventstart
-u64 PerformanceTiming::unload_event_start() const
-{
- // If the previous document and the current document have the same origin, this attribute must return the time
- // immediately before the user agent starts the unload event of the previous document. If there is no previous
- // document or the previous document has a different origin than the current document, this attribute must return
- // zero.
- return relative_timestamp_to_wall_time_milliseconds(document().previous_document_unload_timing().unload_event_start_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-unloadeventend
-u64 PerformanceTiming::unload_event_end() const
-{
- // If the previous document and the current document have the same origin, this attribute must return the time
- // immediately after the user agent finishes the unload event of the previous document. If there is no previous
- // document or the previous document has a different origin than the current document or the unload is not yet
- // completed, this attribute must return zero.
- return relative_timestamp_to_wall_time_milliseconds(document().previous_document_unload_timing().unload_event_end_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-redirectstart
-u64 PerformanceTiming::redirect_start() const
-{
- // If there are HTTP redirects when navigating and if all the redirects are from the same origin, this attribute
- // must return the starting time of the fetch that initiates the redirect. Otherwise, this attribute must return
- // zero.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
-
- if (entry->redirect_count() == 0)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->redirect_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-redirectend
-u64 PerformanceTiming::redirect_end() const
-{
- // If there are HTTP redirects when navigating and all redirects are from the same origin, this attribute must
- // return the time immediately after receiving the last byte of the response of the last redirect. Otherwise, this
- // attribute must return zero.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
-
- if (entry->redirect_count() == 0)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->redirect_end());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-fetchstart
-u64 PerformanceTiming::fetch_start() const
-{
- // If the new resource is to be fetched using a "GET" request method, fetchStart must return the time immediately
- // before the user agent starts checking the HTTP cache. Otherwise, it must return the time when the user agent
- // starts fetching the resource.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
-
- return fetch_phase_to_wall_time_milliseconds(entry->fetch_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-domainlookupstart
-u64 PerformanceTiming::domain_lookup_start() const
-{
- // This attribute must return the time immediately before the user agent starts the domain name lookup for the
- // current document.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->domain_lookup_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-domainlookupend
-u64 PerformanceTiming::domain_lookup_end() const
-{
- // This attribute must return the time immediately after the user agent finishes the domain name lookup for the
- // current document.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->domain_lookup_end());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-connectstart
-u64 PerformanceTiming::connect_start() const
-{
- // This attribute must return the time immediately before the user agent start establishing the connection to the
- // server to retrieve the document.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->connect_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-connectend
-u64 PerformanceTiming::connect_end() const
-{
- // This attribute must return the time immediately after the user agent finishes establishing the connection to
- // the server to retrieve the current document.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->connect_end());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-secureconnectionstart
-u64 PerformanceTiming::secure_connection_start() const
-{
- // When this attribute is available, if the scheme of the current page is "https", this attribute must return the
- // time immediately before the user agent starts the handshake process to secure the current connection. If this
- // attribute is available but HTTPS is not used, this attribute must return zero.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return relative_timestamp_to_wall_time_milliseconds(entry->secure_connection_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-requeststart
-u64 PerformanceTiming::request_start() const
-{
- // This attribute must return the time immediately before the user agent starts requesting the current document
- // from the server, or HTTP cache or from local resources.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->request_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-responsestart
-u64 PerformanceTiming::response_start() const
-{
- // This attribute must return the time immediately after the user agent receives the first byte of the response
- // from the server, or HTTP cache or from local resources.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return fetch_phase_to_wall_time_milliseconds(entry->response_start());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-responseend
-u64 PerformanceTiming::response_end() const
-{
- // This attribute must return the time immediately after the user agent receives the last byte of the current
- // document or immediately before the transport connection is closed, whichever comes first.
- auto entry = navigation_timing_entry();
- if (!entry)
- return 0;
- return relative_timestamp_to_wall_time_milliseconds(entry->response_end());
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-domloading
-u64 PerformanceTiming::dom_loading() const
-{
- // This attribute must return the time immediately before the user agent sets the current document readiness to
- // "loading".
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().dom_loading_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-dominteractive
-u64 PerformanceTiming::dom_interactive() const
-{
- // This attribute must return the time immediately before the user agent sets the current document readiness to
- // "interactive".
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().dom_interactive_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-domcontentloadedeventstart
-u64 PerformanceTiming::dom_content_loaded_event_start() const
-{
- // This attribute must return the time immediately before the user agent fires the DOMContentLoaded event at the
- // Document.
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().dom_content_loaded_event_start_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-domcontentloadedeventend
-u64 PerformanceTiming::dom_content_loaded_event_end() const
-{
- // This attribute must return the time immediately after the document's DOMContentLoaded event completes.
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().dom_content_loaded_event_end_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-domcomplete
-u64 PerformanceTiming::dom_complete() const
-{
- // This attribute must return the time immediately before the user agent sets the current document readiness to
- // "complete".
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().dom_complete_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-loadeventstart
-u64 PerformanceTiming::load_event_start() const
-{
- // This attribute must return the time immediately before the load event of the current document is fired. It must
- // return zero when the load event is not fired yet.
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().load_event_start_time);
-}
-
-// https://w3c.github.io/navigation-timing/#dom-performancetiming-loadeventend
-u64 PerformanceTiming::load_event_end() const
-{
- // This attribute must return the time when the load event of the current document is completed. It must return
- // zero when the load event is not fired or is not completed.
- return relative_timestamp_to_wall_time_milliseconds(document().load_timing_info().load_event_end_time);
-}
-
-extern "C" {
-
-PerformanceTiming* web_navigation_timing_performance_timing_create(HTML::Window* window)
-{
- return PerformanceTiming::create(*window).ptr();
-}
-
-bool web_navigation_timing_is_performance_timing_attribute(FlatPtr name)
-{
- auto attribute_name = Utf16String::from_raw(name);
-#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(camel_case_name, _) \
- if (attribute_name.utf16_view() == EntryNames::camel_case_name.view()) \
- return true;
- ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
-#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
- return false;
-}
-
-u64 web_navigation_timing_performance_timing_attribute(PerformanceTiming* timing, FlatPtr name)
-{
- auto attribute_name = Utf16String::from_raw(name);
-#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(camel_case_name, snake_case_name) \
- if (attribute_name.utf16_view() == EntryNames::camel_case_name.view()) \
- return timing->snake_case_name();
- ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
-#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
- VERIFY_NOT_REACHED();
-}
-}
-
-}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h b/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h
deleted file mode 100644
index 9d3a3a0f698..00000000000
--- a/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2021, Andreas Kling <[email protected]>
- * Copyright (c) 2025, Tim Ledbetter <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/DOM/Document.h>
-#include <LibWeb/HTML/Window.h>
-
-namespace Web::NavigationTiming {
-
-// https://w3c.github.io/navigation-timing/#the-performancetiming-interface
-class PerformanceTiming final : public Bindings::GCAllocatedWrappable {
- WEB_WRAPPABLE(PerformanceTiming, Bindings::GCAllocatedWrappable);
- GC_DECLARE_ALLOCATOR(PerformanceTiming);
-
-public:
- using AllowOwnPtr = TrueType;
-
- static GC::Ref<PerformanceTiming> create(HTML::Window&);
-
- ~PerformanceTiming();
-
- u64 navigation_start() const;
- u64 unload_event_start() const;
- u64 unload_event_end() const;
- u64 redirect_start() const;
- u64 redirect_end() const;
- u64 fetch_start() const;
- u64 domain_lookup_start() const;
- u64 domain_lookup_end() const;
- u64 connect_start() const;
- u64 connect_end() const;
- u64 secure_connection_start() const;
- u64 request_start() const;
- u64 response_start() const;
- u64 response_end() const;
- u64 dom_loading() const;
- u64 dom_interactive() const;
- u64 dom_content_loaded_event_start() const;
- u64 dom_content_loaded_event_end() const;
- u64 dom_complete() const;
- u64 load_event_start() const;
- u64 load_event_end() const;
-
-private:
- explicit PerformanceTiming(HTML::Window&);
-
- virtual void visit_edges(GC::Cell::Visitor&) override;
-
- DOM::Document const& document() const { return m_window->associated_document(); }
- GC::Ptr<PerformanceNavigationTiming> navigation_timing_entry() const { return document().navigation_timing_entry(); }
-
- u64 monotonic_timestamp_to_wall_time_milliseconds(HighResolutionTime::DOMHighResTimeStamp) const;
- u64 fetch_phase_to_wall_time_milliseconds(HighResolutionTime::DOMHighResTimeStamp) const;
- u64 relative_timestamp_to_wall_time_milliseconds(HighResolutionTime::DOMHighResTimeStamp) const;
-
- GC::Ref<HTML::Window> m_window;
-};
-
-}
diff --git a/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl b/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl
index f8b31c0ca8f..bfc07fc8e66 100644
--- a/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl
+++ b/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/navigation-timing/#dom-performancetiming
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface PerformanceTiming {
readonly attribute unsigned long long navigationStart;
diff --git a/Libraries/LibWeb/PaintTiming/PaintTiming.cpp b/Libraries/LibWeb/PaintTiming/PaintTiming.cpp
index 6537ff05f8b..11219ac8e74 100644
--- a/Libraries/LibWeb/PaintTiming/PaintTiming.cpp
+++ b/Libraries/LibWeb/PaintTiming/PaintTiming.cpp
@@ -33,6 +33,10 @@
namespace Web::PaintTiming {
+extern "C" {
+bool web_paint_timing_is_exposed_for_paint_timing(DOM::Node const*);
+}
+
void PendingImageRecord::visit_edges(GC::Cell::Visitor& visitor) const
{
visitor.visit(element);
@@ -665,4 +669,13 @@ void DocumentPaintTimingState::visit_edges(GC::Cell::Visitor& visitor)
visitor.visit(text_nodes_pending_first_paint);
}
+extern "C" {
+
+bool web_paint_timing_is_exposed_for_paint_timing(DOM::Node const* node)
+{
+ auto const* element = as_if<DOM::Element>(node);
+ return element && is_exposed_for_paint_timing(*element, nullptr);
+}
+}
+
}
diff --git a/Libraries/LibWeb/PaintTiming/PaintTimingMixin.h b/Libraries/LibWeb/PaintTiming/PaintTimingMixin.h
index 6f6251fd66a..2faa47554da 100644
--- a/Libraries/LibWeb/PaintTiming/PaintTimingMixin.h
+++ b/Libraries/LibWeb/PaintTiming/PaintTimingMixin.h
@@ -20,44 +20,4 @@ struct PaintTimingInfo {
Optional<HighResolutionTime::DOMHighResTimeStamp> implementation_defined_presentation_time;
};
-// https://w3c.github.io/paint-timing/#default-paint-timestamp
-inline HighResolutionTime::DOMHighResTimeStamp default_paint_timestamp(PaintTimingInfo const& paint_timing_info)
-{
- // To get the default paint timestamp for a paint timing info paintTimingInfo, return paintTimingInfo's
- // implementation-defined presentation time if it is non-null, otherwise paintTimingInfo's rendering update end time.
- return paint_timing_info.implementation_defined_presentation_time.value_or(paint_timing_info.rendering_update_end_time);
-}
-
-// https://w3c.github.io/paint-timing/#sec-PaintTimingMixin
-class PaintTimingMixin {
-public:
- // https://w3c.github.io/paint-timing/#dom-painttimingmixin-painttime
- HighResolutionTime::DOMHighResTimeStamp paint_time() const
- {
- // The paintTime attribute's getter step is to return this's paint timing info's rendering update end time.
- return m_paint_timing_info.rendering_update_end_time;
- }
-
- // https://w3c.github.io/paint-timing/#dom-painttimingmixin-presentationtime
- Optional<HighResolutionTime::DOMHighResTimeStamp> presentation_time() const
- {
- // The presentationTime attribute's getter step, if exists, is to return this's paint timing info's
- // implementation-defined presentation time.
- return m_paint_timing_info.implementation_defined_presentation_time;
- }
-
- PaintTimingInfo const& paint_timing_info() const { return m_paint_timing_info; }
-
-protected:
- explicit PaintTimingMixin(PaintTimingInfo paint_timing_info)
- : m_paint_timing_info(paint_timing_info)
- {
- }
-
-private:
- // https://w3c.github.io/paint-timing/#painttimingmixin-paint-timing-info
- // NB: Every object that includes this mixin is created with a paint timing info, so it is never null here.
- PaintTimingInfo m_paint_timing_info;
-};
-
}
diff --git a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cpp b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cpp
index d1771e23c9e..349ca731345 100644
--- a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cpp
+++ b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.cpp
@@ -4,37 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
+#include <LibJS/HostClassBuilder.h>
+#include <LibJS/Runtime/VM.h>
#include <LibWeb/PaintTiming/PerformancePaintTiming.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
namespace Web::PaintTiming {
-GC_DEFINE_ALLOCATOR(PerformancePaintTiming);
-
-// https://w3c.github.io/paint-timing/#report-paint-timing
-PerformancePaintTiming::PerformancePaintTiming(Utf16String const& paint_type, PaintTimingInfo paint_timing_info)
- // 1. Set newEntry's name attribute to paintType.
- // 3. Set newEntry's startTime attribute to the default paint timestamp given paintTimingInfo.
- // 4. Set newEntry's duration attribute to 0.
- : PerformanceTimeline::PerformanceEntry(paint_type, default_paint_timestamp(paint_timing_info), 0)
- // 2. Set newEntry's paint timing info to paintTimingInfo.
- , PaintTimingMixin(paint_timing_info)
-{
+extern "C" {
+// Defined in Bindings/Rust/src/paint_timing/performance_paint_timing.rs.
+PerformancePaintTiming* web_rust_paint_timing_create_performance_paint_timing(JSVM*, FlatPtr paint_type, double rendering_update_end_time, bool has_presentation_time, double presentation_time);
}
-PerformancePaintTiming::~PerformancePaintTiming() = default;
-
GC::Ref<PerformancePaintTiming> PerformancePaintTiming::create(Utf16String const& paint_type, PaintTimingInfo paint_timing_info)
{
- return GC::Heap::the().allocate<PerformancePaintTiming>(paint_type, paint_timing_info);
-}
-
-// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming
-Utf16FlyString const& PerformancePaintTiming::entry_type() const
-{
- // The entryType attribute's getter must return "paint".
- return PerformanceTimeline::EntryTypes::paint;
+ return *web_rust_paint_timing_create_performance_paint_timing(
+ JS::HostABI::vm_to_abi(JS::VM::the()),
+ Utf16String { paint_type }.into_raw(),
+ paint_timing_info.rendering_update_end_time,
+ paint_timing_info.implementation_defined_presentation_time.has_value(),
+ paint_timing_info.implementation_defined_presentation_time.value_or(0));
}
}
diff --git a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.h b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.h
index 1a0238e589d..45cea4e237d 100644
--- a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.h
+++ b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.h
@@ -6,30 +6,18 @@
#pragma once
+#include <LibWeb/Bindings/PerformancePaintTiming.h>
#include <LibWeb/PaintTiming/PaintTimingMixin.h>
#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
namespace Web::PaintTiming {
// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming
-class PerformancePaintTiming final
- : public PerformanceTimeline::PerformanceEntry
- , public PaintTimingMixin {
- WEB_WRAPPABLE(PerformancePaintTiming, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(PerformancePaintTiming);
+class PerformancePaintTiming final : public PerformanceTimeline::PerformanceEntry {
+ WEB_RUST_INTERFACE(PerformancePaintTiming, performance_paint_timing)
public:
- virtual ~PerformancePaintTiming() override;
-
static GC::Ref<PerformancePaintTiming> create(Utf16String const& paint_type, PaintTimingInfo);
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
-
-private:
- PerformancePaintTiming(Utf16String const& paint_type, PaintTimingInfo);
};
}
diff --git a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idl b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idl
index a7fd236515e..f5ac4e0847a 100644
--- a/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idl
+++ b/Libraries/LibWeb/PaintTiming/PerformancePaintTiming.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/paint-timing/#sec-PerformancePaintTiming
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface PerformancePaintTiming : PerformanceEntry {
[Default] object toJSON();
};
diff --git a/Libraries/LibWeb/PerformanceTimeline/EntryTypes.cpp b/Libraries/LibWeb/PerformanceTimeline/EntryTypes.cpp
deleted file mode 100644
index 872996e1e18..00000000000
--- a/Libraries/LibWeb/PerformanceTimeline/EntryTypes.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
-
-namespace Web::PerformanceTimeline::EntryTypes {
-
-#define __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(name, type) \
- Utf16FlyString const& name = *new Utf16FlyString(type##_utf16_fly_string);
-ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPES
-#undef __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE
-
-}
diff --git a/Libraries/LibWeb/PerformanceTimeline/EntryTypes.h b/Libraries/LibWeb/PerformanceTimeline/EntryTypes.h
deleted file mode 100644
index fababeef25c..00000000000
--- a/Libraries/LibWeb/PerformanceTimeline/EntryTypes.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Utf16FlyString.h>
-
-namespace Web::PerformanceTimeline::EntryTypes {
-
-// https://w3c.github.io/timing-entrytypes-registry/#registry
-#define ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPES \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(element, "element") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(event, "event") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(first_input, "first-input") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(largest_contentful_paint, "largest-contentful-paint") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(layout_shift, "layout-shift") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(longtask, "longtask") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(mark, "mark") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(measure, "measure") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(navigation, "navigation") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(paint, "paint") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(resource, "resource") \
- __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(visibility_state, "visibility-state")
-
-#define __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(name, type) extern Utf16FlyString const& name;
-ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPES
-#undef __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE
-
-}
diff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp
index 6f4df8c2bb4..0b709fbffed 100644
--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp
+++ b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp
@@ -9,57 +9,25 @@
namespace Web::PerformanceTimeline {
extern "C" {
-FlatPtr web_performance_timeline_entry_name(PerformanceEntry*);
-FlatPtr web_performance_timeline_entry_entry_type(PerformanceEntry*);
-double web_performance_timeline_entry_start_time(PerformanceEntry*);
-bool web_performance_timeline_entry_should_add_entry(PerformanceEntry*, bool has_options, bool has_duration_threshold, double duration_threshold);
+// Defined in Bindings/Rust/src/performance_timeline/performance_entry.rs.
+FlatPtr web_rust_performance_entry_name(PerformanceEntry const*);
+double web_rust_performance_entry_start_time(PerformanceEntry const*);
+double web_rust_performance_entry_duration(PerformanceEntry const*);
}
-PerformanceEntry::PerformanceEntry(String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration)
- : m_name(Utf16String::from_utf8(name))
- , m_start_time(start_time)
- , m_duration(duration)
+Utf16String PerformanceEntry::name() const
{
+ return Utf16String::adopt_raw(web_rust_performance_entry_name(this));
}
-PerformanceEntry::PerformanceEntry(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration)
- : m_name(name)
- , m_start_time(start_time)
- , m_duration(duration)
+HighResolutionTime::DOMHighResTimeStamp PerformanceEntry::start_time() const
{
+ return web_rust_performance_entry_start_time(this);
}
-PerformanceEntry::~PerformanceEntry() = default;
-
-extern "C" {
-
-FlatPtr web_performance_timeline_entry_name(PerformanceEntry* entry)
+HighResolutionTime::DOMHighResTimeStamp PerformanceEntry::duration() const
{
- return Utf16String { entry->name() }.into_raw();
-}
-
-FlatPtr web_performance_timeline_entry_entry_type(PerformanceEntry* entry)
-{
- return entry->entry_type().to_utf16_string().into_raw();
-}
-
-double web_performance_timeline_entry_start_time(PerformanceEntry* entry)
-{
- return entry->start_time();
-}
-
-bool web_performance_timeline_entry_should_add_entry(PerformanceEntry* entry, bool has_options, bool has_duration_threshold, double duration_threshold)
-{
- Optional<PerformanceObserverInit> options;
- if (has_options) {
- options = PerformanceObserverInit {};
- if (has_duration_threshold)
- options->duration_threshold = duration_threshold;
- }
- if (options.has_value())
- return entry->should_add_entry(*options) == ShouldAddEntry::Yes;
- return entry->should_add_entry() == ShouldAddEntry::Yes;
-}
+ return web_rust_performance_entry_duration(this);
}
}
diff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h
index 76ef18f52fb..9df46943b50 100644
--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h
+++ b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h
@@ -6,52 +6,23 @@
#pragma once
-#include <AK/Optional.h>
-#include <AK/String.h>
-#include <LibWeb/Bindings/Wrappable.h>
+#include <AK/Utf16String.h>
+#include <LibWeb/Bindings/PerformanceEntry.h>
+#include <LibWeb/Bindings/RustInterface.h>
+#include <LibWeb/Export.h>
#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>
namespace Web::PerformanceTimeline {
-struct PerformanceObserverInit {
- Optional<HighResolutionTime::DOMHighResTimeStamp> duration_threshold;
-};
-
-enum class ShouldAddEntry {
- No,
- Yes,
-};
-
-// https://www.w3.org/TR/performance-timeline/#dom-performanceentry
-class PerformanceEntry : public Bindings::GCAllocatedWrappable {
- WEB_WRAPPABLE(PerformanceEntry, Bindings::GCAllocatedWrappable);
+// https://w3c.github.io/performance-timeline/#dom-performanceentry
+// The C++ side of a PerformanceEntry, which is implemented in Rust (Libraries/LibWeb/Bindings/Rust/src).
+class WEB_API PerformanceEntry : public Bindings::RustInterfaceCell {
+ WEB_RUST_INTERFACE(PerformanceEntry, performance_entry)
public:
- virtual ~PerformanceEntry();
-
- // https://www.w3.org/TR/performance-timeline/#dom-performanceentry-entrytype
- virtual Utf16FlyString const& entry_type() const = 0;
-
- Utf16String const& name() const { return m_name; }
- HighResolutionTime::DOMHighResTimeStamp start_time() const { return m_start_time; }
- virtual HighResolutionTime::DOMHighResTimeStamp duration() const { return m_duration; }
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceObserverInit const&> = {}) const = 0;
-
-protected:
- PerformanceEntry(String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration);
- PerformanceEntry(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration);
-
-private:
- // https://www.w3.org/TR/performance-timeline/#dom-performanceentry-name
- Utf16String m_name;
-
- // https://www.w3.org/TR/performance-timeline/#dom-performanceentry-starttime
- HighResolutionTime::DOMHighResTimeStamp m_start_time { 0.0 };
-
- // https://www.w3.org/TR/performance-timeline/#dom-performanceentry-duration
- HighResolutionTime::DOMHighResTimeStamp m_duration { 0.0 };
+ Utf16String name() const;
+ HighResolutionTime::DOMHighResTimeStamp start_time() const;
+ HighResolutionTime::DOMHighResTimeStamp duration() const;
};
}
diff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.idl b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.idl
index 28e9f71c423..c47dc1a8e6e 100644
--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.idl
+++ b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.idl
@@ -1,8 +1,8 @@
// https://w3c.github.io/performance-timeline/#dom-performanceentry
-[Exposed=(Window,Worker)]
+[Exposed=(Window,Worker), ImplementedIn=Rust]
interface PerformanceEntry {
readonly attribute DOMString name;
- readonly attribute [FlyString] DOMString entryType;
+ readonly attribute DOMString entryType;
readonly attribute DOMHighResTimeStamp startTime;
readonly attribute DOMHighResTimeStamp duration;
[Default] object toJSON();
diff --git a/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.cpp b/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.cpp
index cab03805771..0d516439429 100644
--- a/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.cpp
+++ b/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.cpp
@@ -4,370 +4,53 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
+#include <LibJS/HostClassBuilder.h>
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
#include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
-#include <LibWeb/ServerTiming/PerformanceServerTiming.h>
namespace Web::ResourceTiming {
-GC_DEFINE_ALLOCATOR(PerformanceResourceTiming);
-
-PerformanceResourceTiming::PerformanceResourceTiming(String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin)
- : PerformanceTimeline::PerformanceEntry(name, start_time, duration)
- , m_timing_info(move(timing_info))
- , m_time_origin(time_origin)
-{
-}
-
-PerformanceResourceTiming::PerformanceResourceTiming(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin)
- : PerformanceTimeline::PerformanceEntry(name, start_time, duration)
- , m_timing_info(move(timing_info))
- , m_time_origin(time_origin)
-{
-}
-
-PerformanceResourceTiming::~PerformanceResourceTiming() = default;
-
-GC::Ref<PerformanceResourceTiming> PerformanceResourceTiming::create(String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin)
-{
- return GC::Heap::the().allocate<PerformanceResourceTiming>(name, start_time, duration, move(timing_info), time_origin);
-}
-
-GC::Ref<PerformanceResourceTiming> PerformanceResourceTiming::create(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin)
-{
- return GC::Heap::the().allocate<PerformanceResourceTiming>(name, start_time, duration, move(timing_info), time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dfn-entrytype
-Utf16FlyString const& PerformanceResourceTiming::entry_type() const
-{
- // entryType
- // The entryType getter steps are to return the DOMString "resource".
- return PerformanceTimeline::EntryTypes::resource;
-}
-
-// https://w3c.github.io/resource-timing/#dfn-convert-fetch-timestamp
-HighResolutionTime::DOMHighResTimeStamp convert_fetch_timestamp(HighResolutionTime::DOMHighResTimeStamp time_stamp, HighResolutionTime::DOMHighResTimeStamp time_origin)
-{
- // 1. If ts is zero, return zero.
- if (time_stamp == 0.0)
- return 0.0;
-
- // 2. Otherwise, return the relative high resolution coarse time given ts and global.
- return time_stamp - time_origin;
-}
-
-// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
-void PerformanceResourceTiming::mark_resource_timing(NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, Utf16String const& requested_url, Utf16FlyString const& initiator_type, JS::Object& global, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo body_info, Fetch::Infrastructure::Status response_status, Utf16FlyString delivery_type)
-{
- // 1. Create a PerformanceResourceTiming object entry.
- auto* window_or_worker = HTML::window_or_worker_global_scope_from_global_object(global);
- VERIFY(window_or_worker);
-
- // https://w3c.github.io/resource-timing/#dfn-name
- // name
- // The name getter steps are to return this's requested URL.
-
- // https://w3c.github.io/resource-timing/#dfn-starttime
- // startTime
- // The startTime getter steps are to convert fetch timestamp for this's timing info's start time and this's relevant global object.
-
- // https://w3c.github.io/resource-timing/#dfn-duration
- // duration
- // The duration getter steps are to return this's timing info's end time minus this's timing info's start time.
- auto time_origin = HTML::relevant_settings_object(global).time_origin();
- auto converted_start_time = convert_fetch_timestamp(timing_info->start_time(), time_origin);
- auto converted_end_time = convert_fetch_timestamp(timing_info->end_time(), time_origin);
- auto entry = PerformanceResourceTiming::create(requested_url, converted_start_time, converted_end_time - converted_start_time, timing_info, time_origin);
-
- // Setup the resource timing entry for entry, given initiatorType, requestedURL, timingInfo, cacheMode, bodyInfo, responseStatus, and deliveryType.
- entry->setup_the_resource_timing_entry(initiator_type, requested_url, move(timing_info), cache_mode, move(body_info), response_status, delivery_type);
-
- // 3. Queue entry.
- window_or_worker->queue_performance_entry(entry);
-
- // 4. Add entry to global's performance entry buffer.
- window_or_worker->add_resource_timing_entry({}, entry);
-}
-
-// https://www.w3.org/TR/resource-timing/#dfn-setup-the-resource-timing-entry
-void PerformanceResourceTiming::setup_the_resource_timing_entry(Utf16FlyString const& initiator_type, Utf16String const& requested_url, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo body_info, Fetch::Infrastructure::Status response_status, Utf16FlyString delivery_type)
-{
- // 2. Setup the resource timing entry for entry, given initiatorType, requestedURL, timingInfo, cacheMode, bodyInfo, responseStatus, and deliveryType.
- // https://w3c.github.io/resource-timing/#dfn-setup-the-resource-timing-entry
-
- // 1. Assert that cacheMode is the empty string, "local", or "validated".
-
- // 2. Set entry's initiator type to initiatorType.
- m_initiator_type = initiator_type;
-
- // 3. Set entry's requested URL to requestedURL.
- m_requested_url = requested_url;
-
- // 4. Set entry's timing info to timingInfo.
- m_timing_info = move(timing_info);
-
- // 5. Set entry's response body info to bodyInfo.
- m_response_body_info = move(body_info);
-
- // 6. Set entry's cache mode to cacheMode.
- m_cache_mode = cache_mode;
-
- // 7. Set entry's response status to responseStatus.
- m_response_status = response_status;
-
- // 8. If deliveryType is the empty string and cacheMode is not, then set deliveryType to "cache".
- if (delivery_type.is_empty() && cache_mode.has_value())
- delivery_type = "cache"_utf16_fly_string;
-
- // 9. Set entry's delivery type to deliveryType.
- m_delivery_type = delivery_type;
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-nexthopprotocol
-ByteString PerformanceResourceTiming::next_hop_protocol() const
-{
- // The nextHopProtocol getter steps are to isomorphic decode this's timing info's final connection timing info's
- // ALPN negotiated protocol. See Recording connection timing info for more info.
- // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
- // the Timing-Allow-Origin check fails. We return empty string in this case.
- if (!m_timing_info->final_connection_timing_info().has_value())
- return {};
-
- return m_timing_info->final_connection_timing_info()->alpn_negotiated_protocol;
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-workerstart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::worker_start() const
-{
- // The workerStart getter steps are to convert fetch timestamp for this's timing info's final service worker start
- // time and the relevant global object for this. See HTTP fetch for more info.
- return convert_fetch_timestamp(m_timing_info->final_service_worker_start_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-redirectstart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::redirect_start() const
-{
- // The redirectStart getter steps are to convert fetch timestamp for this's timing info's redirect start time and
- // the relevant global object for this. See HTTP-redirect fetch for more info.
- return convert_fetch_timestamp(m_timing_info->redirect_start_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-redirectend
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::redirect_end() const
-{
- // The redirectEnd getter steps are to convert fetch timestamp for this's timing info's redirect end time and the
- // relevant global object for this. See HTTP-redirect fetch for more info.
- return convert_fetch_timestamp(m_timing_info->redirect_end_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-fetchstart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::fetch_start() const
-{
- // The fetchStart getter steps are to convert fetch timestamp for this's timing info's post-redirect start time and
- // the relevant global object for this. See HTTP fetch for more info.
- return convert_fetch_timestamp(m_timing_info->post_redirect_start_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-domainlookupstart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::domain_lookup_start() const
-{
- // The domainLookupStart getter steps are to convert fetch timestamp for this's timing info's final connection
- // timing info's domain lookup start time and the relevant global object for this. See Recording connection timing
- // info for more info.
- // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
- // the Timing-Allow-Origin check fails. We return 0.0 in this case.
- if (!m_timing_info->final_connection_timing_info().has_value())
- return 0.0;
-
- return convert_fetch_timestamp(m_timing_info->final_connection_timing_info()->domain_lookup_start_time, m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-domainlookupend
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::domain_lookup_end() const
-{
- // The domainLookupEnd getter steps are to convert fetch timestamp for this's timing info's final connection timing
- // info's domain lookup end time and the relevant global object for this. See Recording connection timing info for
- // more info.
- // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
- // the Timing-Allow-Origin check fails. We return 0.0 in this case.
- if (!m_timing_info->final_connection_timing_info().has_value())
- return 0.0;
-
- return convert_fetch_timestamp(m_timing_info->final_connection_timing_info()->domain_lookup_end_time, m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-connectstart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::connect_start() const
-{
- // The connectStart getter steps are to convert fetch timestamp for this's timing info's final connection timing
- // info's connection start time and the relevant global object for this. See Recording connection timing info for
- // more info.
- // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
- // the Timing-Allow-Origin check fails. We return 0.0 in this case.
- if (!m_timing_info->final_connection_timing_info().has_value())
- return 0.0;
-
- return convert_fetch_timestamp(m_timing_info->final_connection_timing_info()->connection_start_time, m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-connectend
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::connect_end() const
-{
- // The connectEnd getter steps are to convert fetch timestamp for this's timing info's final connection timing
- // info's connection end time and the relevant global object for this. See Recording connection timing info for
- // more info.
- // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
- // the Timing-Allow-Origin check fails. We return 0.0 in this case.
- if (!m_timing_info->final_connection_timing_info().has_value())
- return 0.0;
-
- return convert_fetch_timestamp(m_timing_info->final_connection_timing_info()->connection_end_time, m_time_origin);
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::secure_connection_start() const
-{
- // The secureConnectionStart getter steps are to convert fetch timestamp for this's timing info's final connection
- // timing info's secure connection start time and the relevant global object for this. See Recording connection
- // timing info for more info.
- // NOTE: "final connection timing info" can be null, e.g. if this is the timing of a cross-origin resource and
- // the Timing-Allow-Origin check fails. We return 0.0 in this case.
- if (!m_timing_info->final_connection_timing_info().has_value())
- return 0.0;
-
- return convert_fetch_timestamp(m_timing_info->final_connection_timing_info()->secure_connection_start_time, m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-requeststart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::request_start() const
-{
- // The requestStart getter steps are to convert fetch timestamp for this's timing info's final network-request
- // start time and the relevant global object for this. See HTTP fetch for more info.
- return convert_fetch_timestamp(m_timing_info->final_network_request_start_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-finalresponseheadersstart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::final_response_headers_start() const
-{
- // The finalResponseHeadersStart getter steps are to convert fetch timestamp for this's timing info's final
- // network-response start time and the relevant global object for this. See HTTP fetch for more info.
- return convert_fetch_timestamp(m_timing_info->final_network_response_start_time(), m_time_origin);
-}
-
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::first_interim_response_start() const
-{
- // The firstInterimResponseStart getter steps are to convert fetch timestamp for this's timing info's first interim
- // network-response start time and the relevant global object for this. See HTTP fetch for more info.
- return convert_fetch_timestamp(m_timing_info->first_interim_network_response_start_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responsestart
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::response_start() const
-{
- // The responseStart getter steps are to return this's firstInterimResponseStart if it is not 0;
- // Otherwise this's finalResponseHeadersStart.
- auto first_interim_response_start_time = first_interim_response_start();
- if (first_interim_response_start_time != 0.0)
- return first_interim_response_start_time;
-
- return final_response_headers_start();
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responseend
-HighResolutionTime::DOMHighResTimeStamp PerformanceResourceTiming::response_end() const
-{
- // The responseEnd getter steps are to convert fetch timestamp for this's timing info's end time and the relevant
- // global object for this. See fetch for more info.
- return convert_fetch_timestamp(m_timing_info->end_time(), m_time_origin);
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-encodedbodysize
-u64 PerformanceResourceTiming::encoded_body_size() const
-{
- // The encodedBodySize getter steps are to return this's resource info's encoded size.
- return m_response_body_info.encoded_size;
+extern "C" {
+// Defined in Bindings/Rust/src/resource_timing/performance_resource_timing.rs.
+void web_rust_resource_timing_mark_resource_timing(JSVM*, void* realm, Fetch::Infrastructure::FetchTimingInfo*, FlatPtr requested_url, FlatPtr initiator_type, u8 cache_mode, ResponseBodyInfoABI body_info, u16 response_status, FlatPtr delivery_type);
}
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-decodedbodysize
-u64 PerformanceResourceTiming::decoded_body_size() const
+ResponseBodyInfoABI response_body_info_to_abi(Fetch::Infrastructure::Response::BodyInfo const& body_info)
{
- // The decodedBodySize getter steps are to return this's resource info's decoded size.
- return m_response_body_info.decoded_size;
+ return {
+ .encoded_size = body_info.encoded_size,
+ .decoded_size = body_info.decoded_size,
+ .content_type = Utf16String { body_info.content_type }.into_raw(),
+ };
}
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize
-u64 PerformanceResourceTiming::transfer_size() const
+u8 cache_state_to_abi(Optional<Fetch::Infrastructure::Response::CacheState> const& cache_state)
{
- if (m_cache_mode.has_value()) {
- // 1. If this's cache mode is "local", then return 0.
- if (m_cache_mode.value() == Fetch::Infrastructure::Response::CacheState::Local)
- return 0;
-
- // 2. If this's cache mode is "validated", then return 300.
- if (m_cache_mode.value() == Fetch::Infrastructure::Response::CacheState::Validated)
- return 300;
+ if (!cache_state.has_value())
+ return 0;
+ switch (*cache_state) {
+ case Fetch::Infrastructure::Response::CacheState::Local:
+ return 1;
+ case Fetch::Infrastructure::Response::CacheState::Validated:
+ return 2;
}
-
- // 3. Return this's response body info's encoded size plus 300.
- // Spec Note: The constant number added to transferSize replaces exposing the total byte size of the HTTP headers,
- // as that may expose the presence of certain cookies. See this issue: https://github.com/w3c/resource-timing/issues/238
- return m_response_body_info.encoded_size + 300;
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responsestatus
-Fetch::Infrastructure::Status PerformanceResourceTiming::response_status() const
-{
- // The responseStatus getter steps are to return this's response status.
- // Spec Note: responseStatus is determined in Fetch. For a cross-origin no-cors request it would be 0 because the
- // response would be an opaque filtered response.
- return m_response_status;
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-renderblockingstatus
-bool PerformanceResourceTiming::is_render_blocking() const
-{
- // The renderBlockingStatus getter steps are to return blocking if this's timing info's render-blocking is true;
- // otherwise non-blocking.
- return m_timing_info->render_blocking();
-}
-
-RenderBlockingStatusType PerformanceResourceTiming::render_blocking_status() const
-{
- if (is_render_blocking())
- return RenderBlockingStatusType::Blocking;
- return RenderBlockingStatusType::NonBlocking;
-}
-
-// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-contenttype
-Utf16String const& PerformanceResourceTiming::content_type() const
-{
- // The contentType getter steps are to return this's resource info's content type.
- return m_response_body_info.content_type;
-}
-
-// https://w3c.github.io/server-timing/#dom-performanceresourcetiming-servertiming
-GC::RootVector<GC::Ref<ServerTiming::PerformanceServerTiming>> PerformanceResourceTiming::server_timing() const
-{
- // The serverTiming getter steps are the following:
- // 1. Let entries be a new list.
- GC::RootVector<GC::Ref<ServerTiming::PerformanceServerTiming>> entries;
-
- // 2. For each field in this’s timing info’s server-timing headers:
- for (auto const& field : m_timing_info->server_timing_headers()) {
- // 1. Let metric be the result of parsing field.
- auto metric = ServerTiming::PerformanceServerTiming::parse_a_server_timing_header_field(field);
-
- // 2. If metric is not null, append metric to entries.
- if (metric)
- entries.append(*metric);
- }
-
- // 3. Return entries.
- return entries;
+ VERIFY_NOT_REACHED();
+}
+
+void mark_resource_timing(NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, Utf16String const& requested_url, Utf16FlyString const& initiator_type, JS::Object& global, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo const& body_info, Fetch::Infrastructure::Status response_status, Utf16FlyString const& delivery_type)
+{
+ auto& realm = HTML::relevant_realm(global);
+ web_rust_resource_timing_mark_resource_timing(
+ JS::HostABI::vm_to_abi(realm.vm()),
+ &realm,
+ &timing_info.leak_ref(),
+ Utf16String { requested_url }.into_raw(),
+ initiator_type.raw_identity(),
+ cache_state_to_abi(cache_mode),
+ response_body_info_to_abi(body_info),
+ response_status,
+ delivery_type.raw_identity());
}
}
diff --git a/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.h b/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.h
index 51ed707b6e4..cb3742d7ea4 100644
--- a/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.h
+++ b/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.h
@@ -6,91 +6,31 @@
#pragma once
-#include <AK/FlyString.h>
-#include <LibGC/RootVector.h>
+#include <AK/Utf16FlyString.h>
+#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PerformanceResourceTiming.h>
#include <LibWeb/Export.h>
-#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
-namespace Web::ServerTiming {
-
-class PerformanceServerTiming;
-
-}
-
namespace Web::ResourceTiming {
-using RenderBlockingStatusType = Bindings::RenderBlockingStatusType;
-
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming
class WEB_API PerformanceResourceTiming : public PerformanceTimeline::PerformanceEntry {
- WEB_WRAPPABLE(PerformanceResourceTiming, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(PerformanceResourceTiming);
-
-public:
- virtual ~PerformanceResourceTiming() override;
-
- static GC::Ref<PerformanceResourceTiming> create(String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin);
- static GC::Ref<PerformanceResourceTiming> create(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin);
-
- static void mark_resource_timing(NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, Utf16String const& requested_url, Utf16FlyString const& initiator_type, JS::Object& global, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo body_info, Fetch::Infrastructure::Status response_status, Utf16FlyString delivery_type = ""_utf16_fly_string);
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
-
- // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-initiatortype
- Utf16FlyString const& initiator_type() const { return m_initiator_type; }
-
- // https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-deliverytype
- Utf16FlyString const& delivery_type() const { return m_delivery_type; }
-
- ByteString next_hop_protocol() const;
-
- virtual HighResolutionTime::DOMHighResTimeStamp worker_start() const;
- virtual HighResolutionTime::DOMHighResTimeStamp redirect_start() const;
- virtual HighResolutionTime::DOMHighResTimeStamp redirect_end() const;
- virtual HighResolutionTime::DOMHighResTimeStamp fetch_start() const;
- HighResolutionTime::DOMHighResTimeStamp domain_lookup_start() const;
- HighResolutionTime::DOMHighResTimeStamp domain_lookup_end() const;
- HighResolutionTime::DOMHighResTimeStamp connect_start() const;
- HighResolutionTime::DOMHighResTimeStamp connect_end() const;
- HighResolutionTime::DOMHighResTimeStamp secure_connection_start() const;
- HighResolutionTime::DOMHighResTimeStamp request_start() const;
- HighResolutionTime::DOMHighResTimeStamp final_response_headers_start() const;
- HighResolutionTime::DOMHighResTimeStamp first_interim_response_start() const;
- HighResolutionTime::DOMHighResTimeStamp response_start() const;
- HighResolutionTime::DOMHighResTimeStamp response_end() const;
- u64 encoded_body_size() const;
- u64 decoded_body_size() const;
- u64 transfer_size() const;
- Fetch::Infrastructure::Status response_status() const;
- RenderBlockingStatusType render_blocking_status() const;
- bool is_render_blocking() const;
- Utf16String const& content_type() const;
-
- GC::RootVector<GC::Ref<ServerTiming::PerformanceServerTiming>> server_timing() const;
-
-protected:
- PerformanceResourceTiming(String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin);
- PerformanceResourceTiming(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, HighResolutionTime::DOMHighResTimeStamp time_origin);
-
- void setup_the_resource_timing_entry(Utf16FlyString const& initiator_type, Utf16String const& requested_url, NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo body_info, Fetch::Infrastructure::Status response_status, Utf16FlyString delivery_type = ""_utf16_fly_string);
+ WEB_RUST_INTERFACE(PerformanceResourceTiming, performance_resource_timing)
+};
-private:
- Utf16FlyString m_initiator_type;
- Utf16String m_requested_url;
- NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo> m_timing_info;
- HighResolutionTime::DOMHighResTimeStamp m_time_origin { 0.0 };
- Fetch::Infrastructure::Response::BodyInfo m_response_body_info;
- Optional<Fetch::Infrastructure::Response::CacheState> m_cache_mode;
- Fetch::Infrastructure::Status m_response_status;
- Utf16FlyString m_delivery_type;
+// The ABI of a response body info, as Bindings/Rust/src/resource_timing/performance_resource_timing.rs takes it.
+struct ResponseBodyInfoABI {
+ u64 encoded_size;
+ u64 decoded_size;
+ FlatPtr content_type;
};
-HighResolutionTime::DOMHighResTimeStamp convert_fetch_timestamp(HighResolutionTime::DOMHighResTimeStamp time_stamp, HighResolutionTime::DOMHighResTimeStamp time_origin);
+ResponseBodyInfoABI response_body_info_to_abi(Fetch::Infrastructure::Response::BodyInfo const&);
+u8 cache_state_to_abi(Optional<Fetch::Infrastructure::Response::CacheState> const&);
+
+// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
+WEB_API void mark_resource_timing(NonnullRefPtr<Fetch::Infrastructure::FetchTimingInfo>, Utf16String const& requested_url, Utf16FlyString const& initiator_type, JS::Object& global, Optional<Fetch::Infrastructure::Response::CacheState> const& cache_mode, Fetch::Infrastructure::Response::BodyInfo const&, Fetch::Infrastructure::Status response_status, Utf16FlyString const& delivery_type = ""_utf16_fly_string);
}
diff --git a/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.idl b/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.idl
index 41b8d153320..d1c32a6333a 100644
--- a/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.idl
+++ b/Libraries/LibWeb/ResourceTiming/PerformanceResourceTiming.idl
@@ -5,7 +5,7 @@ enum RenderBlockingStatusType {
};
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming
-[Exposed=(Window,Worker)]
+[Exposed=(Window,Worker), ImplementedIn=Rust]
interface PerformanceResourceTiming : PerformanceEntry {
readonly attribute DOMString initiatorType;
readonly attribute DOMString deliveryType;
diff --git a/Libraries/LibWeb/ServerTiming/PerformanceServerTiming.cpp b/Libraries/LibWeb/ServerTiming/PerformanceServerTiming.cpp
deleted file mode 100644
index 5aeb849fae4..00000000000
--- a/Libraries/LibWeb/ServerTiming/PerformanceServerTiming.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibJS/HostClassBuilder.h>
-#include <LibJS/Runtime/VM.h>
-#include <LibWeb/ServerTiming/PerformanceServerTiming.h>
-
-namespace Web::ServerTiming {
-
-extern "C" {
-
-// Defined in Bindings/Rust/src/server_timing/performance_server_timing.rs.
-void* web_performance_server_timing_parse_a_server_timing_header_field(JSVM*, ReadonlyBytes field);
-}
-
-GC::Ptr<PerformanceServerTiming> PerformanceServerTiming::parse_a_server_timing_header_field(StringView field)
-{
- return static_cast<PerformanceServerTiming*>(web_performance_server_timing_parse_a_server_timing_header_field(JS::HostABI::vm_to_abi(JS::VM::the()), field.bytes()));
-}
-
-}
diff --git a/Libraries/LibWeb/ServerTiming/PerformanceServerTiming.h b/Libraries/LibWeb/ServerTiming/PerformanceServerTiming.h
deleted file mode 100644
index 2bcb9f51999..00000000000
--- a/Libraries/LibWeb/ServerTiming/PerformanceServerTiming.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/StringView.h>
-#include <LibGC/Ptr.h>
-#include <LibWeb/Bindings/PerformanceServerTiming.h>
-#include <LibWeb/Bindings/RustInterface.h>
-
-namespace Web::ServerTiming {
-
-// https://w3c.github.io/server-timing/#the-performanceservertiming-interface
-class PerformanceServerTiming : public Bindings::RustInterfaceCell {
- WEB_RUST_INTERFACE(PerformanceServerTiming, performance_server_timing)
-
-public:
- static GC::Ptr<PerformanceServerTiming> parse_a_server_timing_header_field(StringView field);
-};
-
-}
diff --git a/Libraries/LibWeb/UserTiming/PerformanceMark.cpp b/Libraries/LibWeb/UserTiming/PerformanceMark.cpp
deleted file mode 100644
index 7a6a7fd6485..00000000000
--- a/Libraries/LibWeb/UserTiming/PerformanceMark.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibGC/Heap.h>
-#include <LibJS/HostClassBuilder.h>
-#include <LibJS/Runtime/Object.h>
-#include <LibWeb/Bindings/PerformanceMark.h>
-#include <LibWeb/Bindings/RustSerialization.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/HTML/StructuredSerialize.h>
-#include <LibWeb/HTML/Window.h>
-#include <LibWeb/NavigationTiming/EntryNames.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
-#include <LibWeb/UserTiming/PerformanceMark.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-
-namespace Web::UserTiming {
-
-extern "C" {
-JSCompletion web_user_timing_performance_mark_create(JSObject* global_object, FlatPtr mark_name, bool has_detail, JSValue detail, bool has_start_time, double start_time, PerformanceTimeline::PerformanceEntry** entry);
-}
-
-GC_DEFINE_ALLOCATOR(PerformanceMark);
-
-PerformanceMark::PerformanceMark(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail)
- : PerformanceTimeline::PerformanceEntry(name, start_time, duration)
- , m_detail(detail)
-{
-}
-
-PerformanceMark::~PerformanceMark() = default;
-
-// https://w3c.github.io/user-timing/#dfn-performancemark-constructor
-WebIDL::ExceptionOr<GC::Ref<PerformanceMark>> PerformanceMark::create_for_constructor(JS::Object& relevant_global_object, Utf16String const& mark_name, Bindings::PerformanceMarkOptions const& mark_options)
-{
- auto& current_global_object = HTML::current_global_object();
- auto& vm = relevant_global_object.vm();
-
- // 1. If the current global object is a Window object and markName uses the same name as a read only attribute in the PerformanceTiming interface, throw a SyntaxError.
- if (HTML::window_from_global_object(current_global_object)) {
- bool matched = false;
-
-#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) \
- if (mark_name.utf16_view() == NavigationTiming::EntryNames::name.view()) \
- matched = true;
- ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
-#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
-
- if (matched)
- return WebIDL::SyntaxError::create(Utf16String::formatted("'{}' markName cannot be used in a Window context because it is part of the PerformanceTiming interface", mark_name));
- }
-
- // NOTE: Step 2 (creating the entry) is done after determining values, as we set the values once during creation and never change them after.
-
- // 3. Set entry's name attribute to markName.
- auto const& name = mark_name;
-
- // 4. Set entry's entryType attribute to DOMString "mark".
- // NOTE: Already done via the `entry_type` virtual function.
-
- // 5. Set entry's startTime attribute as follows:
- HighResolutionTime::DOMHighResTimeStamp start_time { 0.0 };
-
- // 1. If markOptions's startTime member is present, then:
- if (mark_options.start_time.has_value()) {
- // 1. If markOptions's startTime is negative, throw a TypeError.
- if (mark_options.start_time.value() < 0.0)
- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "startTime cannot be negative"_utf16 };
-
- // 2. Otherwise, set entry's startTime to the value of markOptions's startTime.
- start_time = mark_options.start_time.value();
- }
- // 2. Otherwise, set it to the value that would be returned by the Performance object's now() method.
- else {
- start_time = HighResolutionTime::current_high_resolution_time(current_global_object);
- }
-
- // 6. Set entry's duration attribute to 0.
- constexpr HighResolutionTime::DOMHighResTimeStamp duration = 0.0;
-
- // 2. Create a new PerformanceMark object (entry).
- JS::Value detail;
- if (!mark_options.detail.has_value() || mark_options.detail->is_null()) {
- detail = JS::js_null();
- } else {
- auto record = TRY(HTML::structured_serialize(vm, *mark_options.detail));
- detail = TRY(HTML::structured_deserialize(vm, record, HTML::relevant_realm(relevant_global_object)));
- }
-
- return GC::Heap::the().allocate<PerformanceMark>(name, start_time, duration, detail);
-}
-
-Utf16FlyString const& PerformanceMark::entry_type() const
-{
- return PerformanceTimeline::EntryTypes::mark;
-}
-
-// https://w3c.github.io/user-timing/#dom-performancemark-detail
-WebIDL::ExceptionOr<JS::Value> PerformanceMark::detail(JS::Object const&) const
-{
- // NB: The detail was structured-cloned when this entry was created, so it is returned as is.
- return m_detail;
-}
-
-void PerformanceMark::visit_edges(JS::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_detail);
-}
-
-extern "C" {
-
-JSCompletion web_user_timing_performance_mark_create(JSObject* global_object, FlatPtr mark_name, bool has_detail, JSValue detail, bool has_start_time, double start_time, PerformanceTimeline::PerformanceEntry** entry)
-{
- auto& relevant_global_object = *JS::HostABI::object_from_abi(global_object);
- auto& realm = HTML::relevant_realm(relevant_global_object);
- Bindings::PerformanceMarkOptions mark_options;
- if (has_detail)
- mark_options.detail = JS::HostABI::value_from_abi(detail);
- if (has_start_time)
- mark_options.start_time = start_time;
- auto result = PerformanceMark::create_for_constructor(relevant_global_object, Utf16String::from_raw(mark_name), mark_options);
- if (result.is_exception())
- return Bindings::completion_to_abi(realm, result.release_error());
- *entry = result.release_value().ptr();
- return Bindings::completion_to_abi(realm, JS::js_undefined());
-}
-}
-
-}
diff --git a/Libraries/LibWeb/UserTiming/PerformanceMark.h b/Libraries/LibWeb/UserTiming/PerformanceMark.h
deleted file mode 100644
index 1efff3920f6..00000000000
--- a/Libraries/LibWeb/UserTiming/PerformanceMark.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Optional.h>
-#include <LibJS/Forward.h>
-#include <LibJS/Runtime/Value.h>
-#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>
-
-namespace Web::Bindings {
-
-struct PerformanceMarkOptions;
-
-}
-
-namespace Web::UserTiming {
-
-// https://w3c.github.io/user-timing/#dom-performancemark
-class PerformanceMark final : public PerformanceTimeline::PerformanceEntry {
- WEB_WRAPPABLE(PerformanceMark, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(PerformanceMark);
-
-public:
- virtual ~PerformanceMark();
-
- static WebIDL::ExceptionOr<GC::Ref<PerformanceMark>> create_for_constructor(JS::Object&, Utf16String const& mark_name, Bindings::PerformanceMarkOptions const& mark_options = {});
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
-
- WebIDL::ExceptionOr<JS::Value> detail(JS::Object const& relevant_global_object) const;
-
-private:
- PerformanceMark(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
-
- virtual void visit_edges(JS::Cell::Visitor&) override;
-
- // https://w3c.github.io/user-timing/#dom-performancemark-detail
- JS::Value m_detail { JS::js_null() };
-};
-
-}
diff --git a/Libraries/LibWeb/UserTiming/PerformanceMark.idl b/Libraries/LibWeb/UserTiming/PerformanceMark.idl
index 0879df1ce5c..bd3e1a837ad 100644
--- a/Libraries/LibWeb/UserTiming/PerformanceMark.idl
+++ b/Libraries/LibWeb/UserTiming/PerformanceMark.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/user-timing/#dom-performancemark
-[Exposed=(Window,Worker)]
+[Exposed=(Window,Worker), ImplementedIn=Rust]
interface PerformanceMark : PerformanceEntry {
constructor(DOMString markName, optional PerformanceMarkOptions markOptions = {});
readonly attribute any detail;
diff --git a/Libraries/LibWeb/UserTiming/PerformanceMeasure.cpp b/Libraries/LibWeb/UserTiming/PerformanceMeasure.cpp
deleted file mode 100644
index 519d4a3b37c..00000000000
--- a/Libraries/LibWeb/UserTiming/PerformanceMeasure.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibGC/Heap.h>
-#include <LibJS/HostClassBuilder.h>
-#include <LibWeb/HTML/Window.h>
-#include <LibWeb/HighResolutionTime/TimeOrigin.h>
-#include <LibWeb/NavigationTiming/EntryNames.h>
-#include <LibWeb/PerformanceTimeline/EntryTypes.h>
-#include <LibWeb/UserTiming/PerformanceMeasure.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-
-namespace Web::UserTiming {
-
-extern "C" {
-PerformanceTimeline::PerformanceEntry* web_user_timing_performance_measure_create(FlatPtr measure_name, double start_time, double duration, JSValue detail);
-}
-
-GC_DEFINE_ALLOCATOR(PerformanceMeasure);
-
-PerformanceMeasure::PerformanceMeasure(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail)
- : PerformanceTimeline::PerformanceEntry(name, start_time, duration)
- , m_detail(detail)
-{
-}
-
-PerformanceMeasure::~PerformanceMeasure() = default;
-
-GC::Ref<PerformanceMeasure> PerformanceMeasure::create(Utf16String const& measure_name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail)
-{
- return GC::Heap::the().allocate<PerformanceMeasure>(measure_name, start_time, duration, move(detail));
-}
-
-Utf16FlyString const& PerformanceMeasure::entry_type() const
-{
- return PerformanceTimeline::EntryTypes::measure;
-}
-
-// https://w3c.github.io/user-timing/#dom-performancemeasure-detail
-WebIDL::ExceptionOr<JS::Value> PerformanceMeasure::detail(JS::Object const&) const
-{
- // NB: The detail was structured-cloned when this entry was created, so it is returned as is.
- return m_detail;
-}
-
-void PerformanceMeasure::visit_edges(JS::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_detail);
-}
-
-extern "C" {
-
-PerformanceTimeline::PerformanceEntry* web_user_timing_performance_measure_create(FlatPtr measure_name, double start_time, double duration, JSValue detail)
-{
- return PerformanceMeasure::create(Utf16String::from_raw(measure_name), start_time, duration, JS::HostABI::value_from_abi(detail)).ptr();
-}
-}
-
-}
diff --git a/Libraries/LibWeb/UserTiming/PerformanceMeasure.h b/Libraries/LibWeb/UserTiming/PerformanceMeasure.h
deleted file mode 100644
index 6e6435ce155..00000000000
--- a/Libraries/LibWeb/UserTiming/PerformanceMeasure.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibJS/Forward.h>
-#include <LibJS/Runtime/Value.h>
-#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-
-namespace Web::UserTiming {
-
-// https://w3c.github.io/user-timing/#dom-performancemeasure
-class PerformanceMeasure final : public PerformanceTimeline::PerformanceEntry {
- WEB_WRAPPABLE(PerformanceMeasure, PerformanceTimeline::PerformanceEntry);
- GC_DECLARE_ALLOCATOR(PerformanceMeasure);
-
-public:
- virtual ~PerformanceMeasure();
-
- [[nodiscard]] static GC::Ref<PerformanceMeasure> create(Utf16String const& measure_name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
-
- // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
- virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override { return PerformanceTimeline::ShouldAddEntry::Yes; }
-
- virtual Utf16FlyString const& entry_type() const override;
-
- WebIDL::ExceptionOr<JS::Value> detail(JS::Object const& relevant_global_object) const;
-
-private:
- PerformanceMeasure(Utf16String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, JS::Value detail);
-
- virtual void visit_edges(JS::Cell::Visitor&) override;
-
- // https://w3c.github.io/user-timing/#dom-performancemeasure-detail
- JS::Value m_detail { JS::js_null() };
-};
-
-}
diff --git a/Libraries/LibWeb/UserTiming/PerformanceMeasure.idl b/Libraries/LibWeb/UserTiming/PerformanceMeasure.idl
index 61313415a32..1795e80c5ce 100644
--- a/Libraries/LibWeb/UserTiming/PerformanceMeasure.idl
+++ b/Libraries/LibWeb/UserTiming/PerformanceMeasure.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/user-timing/#performancemeasure
-[Exposed=(Window,Worker)]
+[Exposed=(Window,Worker), ImplementedIn=Rust]
interface PerformanceMeasure : PerformanceEntry {
readonly attribute any detail;
};