refactored performance timing to align with updated spec

refactoring with ResourceFetchMetadata

implemented deprecated window.timing functionality

created ResourceTimingListener trait

fixed w3c links in navigation timing

updated include.ini to run resource timing tests on ci
This commit is contained in:
ddh 2018-03-12 22:24:41 +00:00
parent 3fe83f1d06
commit 26007fddd3
103 changed files with 1881 additions and 322 deletions

View file

@ -25,16 +25,18 @@ use crate::dom::blob::Blob;
use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlsourceelement::HTMLSourceElement;
use crate::dom::htmlvideoelement::HTMLVideoElement;
use crate::dom::mediaerror::MediaError;
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, UnbindContext};
use crate::dom::performanceresourcetiming::InitiatorType;
use crate::dom::promise::Promise;
use crate::dom::virtualmethods::VirtualMethods;
use crate::fetch::FetchCanceller;
use crate::microtask::{Microtask, MicrotaskRunnable};
use crate::network_listener::{NetworkListener, PreInvoke};
use crate::network_listener::{self, NetworkListener, PreInvoke, ResourceTimingListener};
use crate::script_thread::ScriptThread;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
@ -46,8 +48,8 @@ use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use mime::{self, Mime};
use net_traits::request::{CredentialsMode, Destination, RequestInit};
use net_traits::NetworkError;
use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata, FetchResponseListener, Metadata};
use net_traits::{NetworkError, ResourceFetchTiming, ResourceTimingType};
use script_layout_interface::HTMLMediaData;
use servo_media::player::frame::{Frame, FrameRenderer};
use servo_media::player::{PlaybackState, Player, PlayerEvent, StreamType};
@ -706,7 +708,10 @@ impl HTMLMediaElement {
..RequestInit::default()
};
let context = Arc::new(Mutex::new(HTMLMediaElementContext::new(self)));
let context = Arc::new(Mutex::new(HTMLMediaElementContext::new(
self,
self.resource_url.borrow().as_ref().unwrap().clone(),
)));
let (action_sender, action_receiver) = ipc::channel().unwrap();
let window = window_from_node(self);
let (task_source, canceller) = window
@ -1459,6 +1464,10 @@ struct HTMLMediaElementContext {
next_progress_event: Timespec,
/// True if this response is invalid and should be ignored.
ignore_response: bool,
/// timing data for this resource
resource_timing: ResourceFetchTiming,
/// url for the resource
url: ServoUrl,
}
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
@ -1527,7 +1536,7 @@ impl FetchResponseListener for HTMLMediaElementContext {
}
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
fn process_response_eof(&mut self, status: Result<(), NetworkError>) {
fn process_response_eof(&mut self, status: Result<ResourceFetchTiming, NetworkError>) {
if self.ignore_response {
// An error was received previously, skip processing the payload.
return;
@ -1579,6 +1588,35 @@ impl FetchResponseListener for HTMLMediaElementContext {
elem.queue_dedicated_media_source_failure_steps();
}
}
fn resource_timing_mut(&mut self) -> &mut ResourceFetchTiming {
&mut self.resource_timing
}
fn resource_timing(&self) -> &ResourceFetchTiming {
&self.resource_timing
}
fn submit_resource_timing(&mut self) {
network_listener::submit_timing(self)
}
}
impl ResourceTimingListener for HTMLMediaElementContext {
fn resource_timing_information(&self) -> (InitiatorType, ServoUrl) {
let initiator_type = InitiatorType::LocalName(
self.elem
.root()
.upcast::<Element>()
.local_name()
.to_string(),
);
(initiator_type, self.url.clone())
}
fn resource_timing_global(&self) -> DomRoot<GlobalScope> {
(document_from_node(&*self.elem.root()).global())
}
}
impl PreInvoke for HTMLMediaElementContext {
@ -1589,13 +1627,15 @@ impl PreInvoke for HTMLMediaElementContext {
}
impl HTMLMediaElementContext {
fn new(elem: &HTMLMediaElement) -> HTMLMediaElementContext {
fn new(elem: &HTMLMediaElement, url: ServoUrl) -> HTMLMediaElementContext {
HTMLMediaElementContext {
elem: Trusted::new(elem),
metadata: None,
generation_id: elem.generation_id.get(),
next_progress_event: time::get_time() + Duration::milliseconds(350),
ignore_response: false,
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
url: url,
}
}
}