Truly independent web browser
LibWeb: Initialize resource timing entries as Resource Timing now does
Shannon Booth19c26fd46530
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.rsindex 4184c37669e..32fb1c6dafa 100644--- a/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation_timing.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/navigation_timing/performance_navigation_timing.rs@@ -11,12 +11,11 @@ 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_entry::AnyPerformanceEntry;use crate::performance_timeline::performance_timeline::PerformanceTimeline;use crate::resource_timing::performance_resource_timing::{CacheState, PerformanceResourceTiming, ResponseBodyInfo, ResponseBodyInfoAbi,@@ -61,11 +60,23 @@ impl Inherits<PerformanceResourceTiming> for PerformanceNavigationTiming {}impl PerformanceNavigationTiming {+ // https://w3c.github.io/navigation-timing/#performanceentry+ pub(crate) fn entry_type(&self) -> Utf16String {+ // The entryType getter step is to return the DOMString "navigation".+ Utf16String::from_utf8("navigation")+ }++ // https://w3c.github.io/navigation-timing/#performanceentry+ pub(crate) fn start_time(&self) -> f64 {+ // The startTime getter step is to return a DOMHighResTimeStamp with a time value of 0.+ 0.0+ }+// https://w3c.github.io/navigation-timing/#performanceentrypub(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+ self.document.load_timing_info().load_event_end_time - self.start_time()}// https://w3c.github.io/navigation-timing/#PerformanceResourceTiming@@ -179,15 +190,12 @@ fn create_the_navigation_timing_entry(// 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,+ realm,Utf16String::from_utf8("navigation"),+ document_url,timing_info,cache_mode,body_info,diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rsindex 3384f689d2a..66d58b81a7c 100644--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs@@ -50,6 +50,21 @@ impl PerformanceEntry {}}+ // https://w3c.github.io/performance-timeline/#dfn-initialize-a-performanceentry+ pub(crate) fn initialize(start_time: f64, entry_type: Utf16String, name: Utf16String, end_time: f64) -> Self {+ // 1. Assert: entryType is defined in the entry type registry.+ // 2. Initialize entry’s startTime to startTime.+ // 3. Initialize entry’s entryType to entryType.+ // 4. Initialize entry’s name to name.+ // 5. Initialize entry’s end time to endTime.+ // NB: Neither the end time nor startTime change after this, so the result of the duration getter steps is kept+ // instead: https://w3c.github.io/performance-timeline/#dom-performanceentry-duration+ // 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.+ let duration = if end_time == 0.0 { 0.0 } else { end_time - start_time };+ Self::new(name, entry_type, start_time, duration)+ }+pub(crate) fn set_object(&self, object: AnyPerformanceEntry) {self.object.set(Some(object));}@@ -171,12 +186,20 @@ impl AnyPerformanceEntry {// https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytypepub(crate) fn entry_type(&self) -> Utf16String {+ if let Self::PerformanceNavigationTiming(entry) = self {+ return entry.entry_type();+ }+// This attribute must return the value it is initialized to.self.entry().entry_type.clone()}// https://w3c.github.io/performance-timeline/#dom-performanceentry-starttimepub(crate) fn start_time(&self) -> f64 {+ if let Self::PerformanceNavigationTiming(entry) = self {+ return entry.start_time();+ }+// This attribute must return the value it is initialized to.self.entry().start_time}@@ -189,7 +212,7 @@ impl AnyPerformanceEntry {// 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.+ // NB: initialize() keeps the result of these steps, and the specs that set the duration attribute keep theirs.self.entry().duration.get()}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.rsindex be4e389248a..e5a03a0bffb 100644--- a/Libraries/LibWeb/Bindings/Rust/src/resource_timing/performance_resource_timing.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/resource_timing/performance_resource_timing.rs@@ -114,9 +114,9 @@ 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,+ realm: Gc<Realm>,initiator_type: Utf16String,+ requested_url: Utf16String,timing_info: CppFetchTimingInfo,cache_mode: Option<CacheState>,body_info: ResponseBodyInfo,@@ -125,20 +125,34 @@ impl PerformanceResourceTiming {) -> 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.+ // 2. Let global be entry's relevant global object.+ // NB: The realm is that of global.+ let time_origin = relevant_settings_object(realm.global_object()).time_origin();++ // 3. Initialize entry given the result of converting timingInfo's start time given global, "resource",+ // requestedURL, and the result of converting timingInfo's end time given global.+ let timing = timing_info.read();+ let entry = PerformanceEntry::initialize(+ convert_fetch_timestamp(timing.start_time, time_origin),+ Utf16String::from_utf8("resource"),+ requested_url,+ convert_fetch_timestamp(timing.end_time, time_origin),+ );++ // 4. Set entry's initiator type to initiatorType.+ // 5. Set entry's requested URL to requestedURL.+ // NB: The entry's name, which step 3 initialized, is its requested URL.+ // 6. Set entry's timing info to timingInfo.+ // 7. Set entry's resource info to bodyInfo.+ // 8. Set entry's cache mode to cacheMode.+ // 9. Set entry's response status to responseStatus.- // 8. If deliveryType is the empty string and cacheMode is not, then set deliveryType to "cache".+ // 10. 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.+ // 11. Set entry's delivery type to deliveryType.Self {entry,initiator_type,@@ -451,23 +465,13 @@ fn mark_resource_timing(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.+ // 1. Create a PerformanceResourceTiming object entry in global's realm.+ // 2. 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,+ realm,initiator_type,+ requested_url,timing_info,cache_mode,body_info,