Use FetchCanceller for document loads

This commit is contained in:
Manish Goregaokar 2017-11-21 16:43:50 -08:00
parent 78c8b4232f
commit 3900f5e616
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
11 changed files with 51 additions and 24 deletions

View file

@ -62,6 +62,7 @@ use dom::worker::TrustedWorkerAddress;
use dom::worklet::WorkletThreadPool;
use dom::workletglobalscope::WorkletGlobalScopeInit;
use euclid::{Point2D, Vector2D, Rect};
use fetch::FetchCanceller;
use hyper::header::{ContentType, HttpDate, Headers, LastModified};
use hyper::header::ReferrerPolicy as ReferrerPolicyHeader;
use hyper::mime::{Mime, SubLevel, TopLevel};
@ -170,6 +171,8 @@ struct InProgressLoad {
navigation_start: u64,
/// High res timestamp reporting the time when the browser started this load.
navigation_start_precise: u64,
/// For cancelling the fetch
canceller: FetchCanceller,
}
impl InProgressLoad {
@ -198,6 +201,7 @@ impl InProgressLoad {
origin: origin,
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
navigation_start_precise: navigation_start_precise,
canceller: Default::default(),
}
}
}
@ -2215,7 +2219,8 @@ impl ScriptThread {
DocumentSource::FromParser,
loader,
referrer,
referrer_policy);
referrer_policy,
incomplete.canceller);
document.set_ready_state(DocumentReadyState::Loading);
self.documents.borrow_mut().insert(incomplete.pipeline_id, &*document);
@ -2536,7 +2541,7 @@ impl ScriptThread {
/// Instructs the constellation to fetch the document that will be loaded. Stores the InProgressLoad
/// argument until a notification is received that the fetch is complete.
fn pre_page_load(&self, incomplete: InProgressLoad, load_data: LoadData) {
fn pre_page_load(&self, mut incomplete: InProgressLoad, load_data: LoadData) {
let id = incomplete.pipeline_id.clone();
let req_init = RequestInit {
url: load_data.url.clone(),
@ -2557,7 +2562,9 @@ impl ScriptThread {
let context = ParserContext::new(id, load_data.url);
self.incomplete_parser_contexts.borrow_mut().push((id, context));
self.script_sender.send((id, ScriptMsg::InitiateNavigateRequest(req_init))).unwrap();
let cancel_chan = incomplete.canceller.initialize();
self.script_sender.send((id, ScriptMsg::InitiateNavigateRequest(req_init, cancel_chan))).unwrap();
self.incomplete_loads.borrow_mut().push(incomplete);
}