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

@ -91,6 +91,7 @@ use dom::windowproxy::WindowProxy;
use dom_struct::dom_struct;
use encoding_rs::{Encoding, UTF_8};
use euclid::Point2D;
use fetch::FetchCanceller;
use html5ever::{LocalName, Namespace, QualName};
use hyper::header::{Header, SetCookie};
use hyper_serde::Serde;
@ -360,6 +361,8 @@ pub struct Document {
form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
interactive_time: DomRefCell<InteractiveMetrics>,
tti_window: DomRefCell<InteractiveWindow>,
/// RAII canceller for Fetch
canceller: FetchCanceller,
}
#[derive(JSTraceable, MallocSizeOf)]
@ -2165,7 +2168,8 @@ impl Document {
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>)
referrer_policy: Option<ReferrerPolicy>,
canceller: FetchCanceller)
-> Document {
let url = url.unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap());
@ -2270,6 +2274,7 @@ impl Document {
form_id_listener_map: Default::default(),
interactive_time: DomRefCell::new(interactive_time),
tti_window: DomRefCell::new(InteractiveWindow::new()),
canceller: canceller,
}
}
@ -2288,7 +2293,8 @@ impl Document {
DocumentSource::NotFromParser,
docloader,
None,
None))
None,
Default::default()))
}
pub fn new(window: &Window,
@ -2302,7 +2308,8 @@ impl Document {
source: DocumentSource,
doc_loader: DocumentLoader,
referrer: Option<String>,
referrer_policy: Option<ReferrerPolicy>)
referrer_policy: Option<ReferrerPolicy>,
canceller: FetchCanceller)
-> DomRoot<Document> {
let document = reflect_dom_object(
Box::new(Document::new_inherited(
@ -2317,7 +2324,8 @@ impl Document {
source,
doc_loader,
referrer,
referrer_policy
referrer_policy,
canceller
)),
window,
DocumentBinding::Wrap
@ -2474,7 +2482,8 @@ impl Document {
DocumentSource::NotFromParser,
DocumentLoader::new(&self.loader()),
None,
None);
None,
Default::default());
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
new_doc
})

View file

@ -137,7 +137,8 @@ impl DOMImplementationMethods for DOMImplementation {
DocumentSource::NotFromParser,
loader,
None,
None);
None,
Default::default());
{
// Step 3.

View file

@ -70,7 +70,8 @@ impl DOMParserMethods for DOMParser {
DocumentSource::FromParser,
loader,
None,
None);
None,
Default::default());
ServoParser::parse_html_document(&document, s, url);
document.set_ready_state(DocumentReadyState::Complete);
Ok(document)
@ -88,7 +89,8 @@ impl DOMParserMethods for DOMParser {
DocumentSource::NotFromParser,
loader,
None,
None);
None,
Default::default());
ServoParser::parse_xml_document(&document, s, url);
Ok(document)
}

View file

@ -1814,7 +1814,7 @@ impl Node {
is_html_doc, None,
None, DocumentActivity::Inactive,
DocumentSource::NotFromParser, loader,
None, None);
None, None, Default::default());
DomRoot::upcast::<Node>(document)
},
NodeTypeId::Element(..) => {

View file

@ -138,7 +138,8 @@ impl ServoParser {
DocumentSource::FromParser,
loader,
None,
None);
None,
Default::default());
// Step 2.
document.set_quirks_mode(context_document.quirks_mode());

View file

@ -48,7 +48,8 @@ impl XMLDocument {
source,
doc_loader,
None,
None),
None,
Default::default()),
}
}

View file

@ -1261,7 +1261,8 @@ impl XMLHttpRequest {
DocumentSource::FromParser,
docloader,
None,
None)
None,
Default::default())
}
fn filter_response_headers(&self) -> Headers {

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);
}