Add PerformanceResourceTiming: TimingAllowCheck

The purpose of this commit is to implement https://w3c.github.io/resource-timing/#dfn-timing-allow-check
This commit is contained in:
Javed Nissar 2019-09-17 17:58:06 -04:00
parent 4159f01feb
commit bb8166bb97
2 changed files with 50 additions and 3 deletions

View file

@ -232,6 +232,8 @@ impl FetchTaskTarget for IpcSender<FetchResponseMsg> {
} else {
let _ = self.send(FetchResponseMsg::ProcessResponseEOF(Ok(response
.get_resource_timing()
.lock()
.unwrap()
.clone())));
}
}
@ -459,6 +461,7 @@ pub struct ResourceCorsData {
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct ResourceFetchTiming {
pub domain_lookup_start: u64,
pub timing_check_passed: bool,
pub timing_type: ResourceTimingType,
/// Number of redirects until final resource (currently limited to 20)
pub redirect_count: u16,
@ -508,6 +511,7 @@ impl ResourceFetchTiming {
pub fn new(timing_type: ResourceTimingType) -> ResourceFetchTiming {
ResourceFetchTiming {
timing_type: timing_type,
timing_check_passed: true,
domain_lookup_start: 0,
redirect_count: 0,
request_start: 0,
@ -524,6 +528,13 @@ impl ResourceFetchTiming {
// TODO currently this is being set with precise time ns when it should be time since
// time origin (as described in Performance::now)
pub fn set_attribute(&mut self, attribute: ResourceAttribute) {
let should_attribute_always_be_updated = match attribute {
ResourceAttribute::FetchStart | ResourceAttribute::ResponseEnd => true,
_ => false,
};
if !self.timing_check_passed && !should_attribute_always_be_updated {
return;
}
match attribute {
ResourceAttribute::DomainLookupStart => self.domain_lookup_start = precise_time_ns(),
ResourceAttribute::RedirectCount(count) => self.redirect_count = count,
@ -547,6 +558,17 @@ impl ResourceFetchTiming {
ResourceAttribute::ResponseEnd => self.response_end = precise_time_ns(),
}
}
pub fn mark_timing_check_failed(&mut self) {
self.timing_check_passed = false;
self.domain_lookup_start = 0;
self.redirect_count = 0;
self.request_start = 0;
self.response_start = 0;
self.redirect_start = 0;
self.connect_start = 0;
self.connect_end = 0;
}
}
/// Metadata about a loaded resource, such as is obtained from HTTP headers.