mirror of
https://github.com/servo/servo.git
synced 2025-07-28 09:40:33 +01:00
Use FetchCanceller for document loads
This commit is contained in:
parent
78c8b4232f
commit
3900f5e616
11 changed files with 51 additions and 24 deletions
|
@ -1110,9 +1110,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
||||||
FromScriptMsg::PipelineExited => {
|
FromScriptMsg::PipelineExited => {
|
||||||
self.handle_pipeline_exited(source_pipeline_id);
|
self.handle_pipeline_exited(source_pipeline_id);
|
||||||
}
|
}
|
||||||
FromScriptMsg::InitiateNavigateRequest(req_init) => {
|
FromScriptMsg::InitiateNavigateRequest(req_init, cancel_chan) => {
|
||||||
debug!("constellation got initiate navigate request message");
|
debug!("constellation got initiate navigate request message");
|
||||||
self.handle_navigate_request(source_pipeline_id, req_init);
|
self.handle_navigate_request(source_pipeline_id, req_init, cancel_chan);
|
||||||
}
|
}
|
||||||
FromScriptMsg::ScriptLoadedURLInIFrame(load_info) => {
|
FromScriptMsg::ScriptLoadedURLInIFrame(load_info) => {
|
||||||
debug!("constellation got iframe URL load message {:?} {:?} {:?}",
|
debug!("constellation got iframe URL load message {:?} {:?} {:?}",
|
||||||
|
@ -1689,14 +1689,15 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
||||||
|
|
||||||
fn handle_navigate_request(&self,
|
fn handle_navigate_request(&self,
|
||||||
id: PipelineId,
|
id: PipelineId,
|
||||||
req_init: RequestInit) {
|
req_init: RequestInit,
|
||||||
|
cancel_chan: IpcReceiver<()>) {
|
||||||
let listener = NetworkListener::new(
|
let listener = NetworkListener::new(
|
||||||
req_init,
|
req_init,
|
||||||
id,
|
id,
|
||||||
self.public_resource_threads.clone(),
|
self.public_resource_threads.clone(),
|
||||||
self.network_listener_sender.clone());
|
self.network_listener_sender.clone());
|
||||||
|
|
||||||
listener.initiate_fetch();
|
listener.initiate_fetch(Some(cancel_chan));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The script thread associated with pipeline_id has loaded a URL in an iframe via script. This
|
// The script thread associated with pipeline_id has loaded a URL in an iframe via script. This
|
||||||
|
|
|
@ -41,7 +41,7 @@ impl NetworkListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initiate_fetch(&self) {
|
pub fn initiate_fetch(&self, cancel_chan: Option<ipc::IpcReceiver<()>>) {
|
||||||
let (ipc_sender, ipc_receiver) = ipc::channel().expect("Failed to create IPC channel!");
|
let (ipc_sender, ipc_receiver) = ipc::channel().expect("Failed to create IPC channel!");
|
||||||
|
|
||||||
let mut listener = NetworkListener {
|
let mut listener = NetworkListener {
|
||||||
|
@ -64,7 +64,7 @@ impl NetworkListener {
|
||||||
|
|
||||||
CoreResourceMsg::Fetch(
|
CoreResourceMsg::Fetch(
|
||||||
listener.req_init.clone(),
|
listener.req_init.clone(),
|
||||||
FetchChannels::ResponseMsg(ipc_sender, None))
|
FetchChannels::ResponseMsg(ipc_sender, cancel_chan))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,7 +108,11 @@ impl NetworkListener {
|
||||||
referrer: metadata.referrer.clone(),
|
referrer: metadata.referrer.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.initiate_fetch();
|
// XXXManishearth we don't have the cancel_chan anymore and
|
||||||
|
// can't use it here.
|
||||||
|
//
|
||||||
|
// Ideally the Fetch code would handle manual redirects on its own
|
||||||
|
self.initiate_fetch(None);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
// Response should be processed by script thread.
|
// Response should be processed by script thread.
|
||||||
|
|
|
@ -91,6 +91,7 @@ use dom::windowproxy::WindowProxy;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use encoding_rs::{Encoding, UTF_8};
|
use encoding_rs::{Encoding, UTF_8};
|
||||||
use euclid::Point2D;
|
use euclid::Point2D;
|
||||||
|
use fetch::FetchCanceller;
|
||||||
use html5ever::{LocalName, Namespace, QualName};
|
use html5ever::{LocalName, Namespace, QualName};
|
||||||
use hyper::header::{Header, SetCookie};
|
use hyper::header::{Header, SetCookie};
|
||||||
use hyper_serde::Serde;
|
use hyper_serde::Serde;
|
||||||
|
@ -360,6 +361,8 @@ pub struct Document {
|
||||||
form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
|
form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
|
||||||
interactive_time: DomRefCell<InteractiveMetrics>,
|
interactive_time: DomRefCell<InteractiveMetrics>,
|
||||||
tti_window: DomRefCell<InteractiveWindow>,
|
tti_window: DomRefCell<InteractiveWindow>,
|
||||||
|
/// RAII canceller for Fetch
|
||||||
|
canceller: FetchCanceller,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
@ -2165,7 +2168,8 @@ impl Document {
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
doc_loader: DocumentLoader,
|
doc_loader: DocumentLoader,
|
||||||
referrer: Option<String>,
|
referrer: Option<String>,
|
||||||
referrer_policy: Option<ReferrerPolicy>)
|
referrer_policy: Option<ReferrerPolicy>,
|
||||||
|
canceller: FetchCanceller)
|
||||||
-> Document {
|
-> Document {
|
||||||
let url = url.unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap());
|
let url = url.unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap());
|
||||||
|
|
||||||
|
@ -2270,6 +2274,7 @@ impl Document {
|
||||||
form_id_listener_map: Default::default(),
|
form_id_listener_map: Default::default(),
|
||||||
interactive_time: DomRefCell::new(interactive_time),
|
interactive_time: DomRefCell::new(interactive_time),
|
||||||
tti_window: DomRefCell::new(InteractiveWindow::new()),
|
tti_window: DomRefCell::new(InteractiveWindow::new()),
|
||||||
|
canceller: canceller,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2288,7 +2293,8 @@ impl Document {
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
docloader,
|
docloader,
|
||||||
None,
|
None,
|
||||||
None))
|
None,
|
||||||
|
Default::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &Window,
|
pub fn new(window: &Window,
|
||||||
|
@ -2302,7 +2308,8 @@ impl Document {
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
doc_loader: DocumentLoader,
|
doc_loader: DocumentLoader,
|
||||||
referrer: Option<String>,
|
referrer: Option<String>,
|
||||||
referrer_policy: Option<ReferrerPolicy>)
|
referrer_policy: Option<ReferrerPolicy>,
|
||||||
|
canceller: FetchCanceller)
|
||||||
-> DomRoot<Document> {
|
-> DomRoot<Document> {
|
||||||
let document = reflect_dom_object(
|
let document = reflect_dom_object(
|
||||||
Box::new(Document::new_inherited(
|
Box::new(Document::new_inherited(
|
||||||
|
@ -2317,7 +2324,8 @@ impl Document {
|
||||||
source,
|
source,
|
||||||
doc_loader,
|
doc_loader,
|
||||||
referrer,
|
referrer,
|
||||||
referrer_policy
|
referrer_policy,
|
||||||
|
canceller
|
||||||
)),
|
)),
|
||||||
window,
|
window,
|
||||||
DocumentBinding::Wrap
|
DocumentBinding::Wrap
|
||||||
|
@ -2474,7 +2482,8 @@ impl Document {
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
DocumentLoader::new(&self.loader()),
|
DocumentLoader::new(&self.loader()),
|
||||||
None,
|
None,
|
||||||
None);
|
None,
|
||||||
|
Default::default());
|
||||||
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
|
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
|
||||||
new_doc
|
new_doc
|
||||||
})
|
})
|
||||||
|
|
|
@ -137,7 +137,8 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
loader,
|
loader,
|
||||||
None,
|
None,
|
||||||
None);
|
None,
|
||||||
|
Default::default());
|
||||||
|
|
||||||
{
|
{
|
||||||
// Step 3.
|
// Step 3.
|
||||||
|
|
|
@ -70,7 +70,8 @@ impl DOMParserMethods for DOMParser {
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader,
|
loader,
|
||||||
None,
|
None,
|
||||||
None);
|
None,
|
||||||
|
Default::default());
|
||||||
ServoParser::parse_html_document(&document, s, url);
|
ServoParser::parse_html_document(&document, s, url);
|
||||||
document.set_ready_state(DocumentReadyState::Complete);
|
document.set_ready_state(DocumentReadyState::Complete);
|
||||||
Ok(document)
|
Ok(document)
|
||||||
|
@ -88,7 +89,8 @@ impl DOMParserMethods for DOMParser {
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
loader,
|
loader,
|
||||||
None,
|
None,
|
||||||
None);
|
None,
|
||||||
|
Default::default());
|
||||||
ServoParser::parse_xml_document(&document, s, url);
|
ServoParser::parse_xml_document(&document, s, url);
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1814,7 +1814,7 @@ impl Node {
|
||||||
is_html_doc, None,
|
is_html_doc, None,
|
||||||
None, DocumentActivity::Inactive,
|
None, DocumentActivity::Inactive,
|
||||||
DocumentSource::NotFromParser, loader,
|
DocumentSource::NotFromParser, loader,
|
||||||
None, None);
|
None, None, Default::default());
|
||||||
DomRoot::upcast::<Node>(document)
|
DomRoot::upcast::<Node>(document)
|
||||||
},
|
},
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
|
|
|
@ -138,7 +138,8 @@ impl ServoParser {
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader,
|
loader,
|
||||||
None,
|
None,
|
||||||
None);
|
None,
|
||||||
|
Default::default());
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
document.set_quirks_mode(context_document.quirks_mode());
|
document.set_quirks_mode(context_document.quirks_mode());
|
||||||
|
|
|
@ -48,7 +48,8 @@ impl XMLDocument {
|
||||||
source,
|
source,
|
||||||
doc_loader,
|
doc_loader,
|
||||||
None,
|
None,
|
||||||
None),
|
None,
|
||||||
|
Default::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1261,7 +1261,8 @@ impl XMLHttpRequest {
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
docloader,
|
docloader,
|
||||||
None,
|
None,
|
||||||
None)
|
None,
|
||||||
|
Default::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_response_headers(&self) -> Headers {
|
fn filter_response_headers(&self) -> Headers {
|
||||||
|
|
|
@ -62,6 +62,7 @@ use dom::worker::TrustedWorkerAddress;
|
||||||
use dom::worklet::WorkletThreadPool;
|
use dom::worklet::WorkletThreadPool;
|
||||||
use dom::workletglobalscope::WorkletGlobalScopeInit;
|
use dom::workletglobalscope::WorkletGlobalScopeInit;
|
||||||
use euclid::{Point2D, Vector2D, Rect};
|
use euclid::{Point2D, Vector2D, Rect};
|
||||||
|
use fetch::FetchCanceller;
|
||||||
use hyper::header::{ContentType, HttpDate, Headers, LastModified};
|
use hyper::header::{ContentType, HttpDate, Headers, LastModified};
|
||||||
use hyper::header::ReferrerPolicy as ReferrerPolicyHeader;
|
use hyper::header::ReferrerPolicy as ReferrerPolicyHeader;
|
||||||
use hyper::mime::{Mime, SubLevel, TopLevel};
|
use hyper::mime::{Mime, SubLevel, TopLevel};
|
||||||
|
@ -170,6 +171,8 @@ struct InProgressLoad {
|
||||||
navigation_start: u64,
|
navigation_start: u64,
|
||||||
/// High res timestamp reporting the time when the browser started this load.
|
/// High res timestamp reporting the time when the browser started this load.
|
||||||
navigation_start_precise: u64,
|
navigation_start_precise: u64,
|
||||||
|
/// For cancelling the fetch
|
||||||
|
canceller: FetchCanceller,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InProgressLoad {
|
impl InProgressLoad {
|
||||||
|
@ -198,6 +201,7 @@ impl InProgressLoad {
|
||||||
origin: origin,
|
origin: origin,
|
||||||
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
|
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
|
||||||
navigation_start_precise: navigation_start_precise,
|
navigation_start_precise: navigation_start_precise,
|
||||||
|
canceller: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2215,7 +2219,8 @@ impl ScriptThread {
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader,
|
loader,
|
||||||
referrer,
|
referrer,
|
||||||
referrer_policy);
|
referrer_policy,
|
||||||
|
incomplete.canceller);
|
||||||
document.set_ready_state(DocumentReadyState::Loading);
|
document.set_ready_state(DocumentReadyState::Loading);
|
||||||
|
|
||||||
self.documents.borrow_mut().insert(incomplete.pipeline_id, &*document);
|
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
|
/// 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.
|
/// 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 id = incomplete.pipeline_id.clone();
|
||||||
let req_init = RequestInit {
|
let req_init = RequestInit {
|
||||||
url: load_data.url.clone(),
|
url: load_data.url.clone(),
|
||||||
|
@ -2557,7 +2562,9 @@ impl ScriptThread {
|
||||||
let context = ParserContext::new(id, load_data.url);
|
let context = ParserContext::new(id, load_data.url);
|
||||||
self.incomplete_parser_contexts.borrow_mut().push((id, context));
|
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);
|
self.incomplete_loads.borrow_mut().push(incomplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use canvas_traits::canvas::CanvasMsg;
|
||||||
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
|
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
|
||||||
use euclid::{Point2D, Size2D, TypedSize2D};
|
use euclid::{Point2D, Size2D, TypedSize2D};
|
||||||
use gfx_traits::Epoch;
|
use gfx_traits::Epoch;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||||
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, TraversalDirection};
|
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, TraversalDirection};
|
||||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
||||||
use net_traits::CoreResourceMsg;
|
use net_traits::CoreResourceMsg;
|
||||||
|
@ -71,7 +71,7 @@ pub enum LogEntry {
|
||||||
pub enum ScriptMsg {
|
pub enum ScriptMsg {
|
||||||
/// Requests are sent to constellation and fetches are checked manually
|
/// Requests are sent to constellation and fetches are checked manually
|
||||||
/// for cross-origin loads
|
/// for cross-origin loads
|
||||||
InitiateNavigateRequest(RequestInit),
|
InitiateNavigateRequest(RequestInit, /* cancellation_chan */ IpcReceiver<()>),
|
||||||
/// Broadcast a storage event to every same-origin pipeline.
|
/// Broadcast a storage event to every same-origin pipeline.
|
||||||
/// The strings are key, old value and new value.
|
/// The strings are key, old value and new value.
|
||||||
BroadcastStorageEvent(StorageType, ServoUrl, Option<String>, Option<String>, Option<String>),
|
BroadcastStorageEvent(StorageType, ServoUrl, Option<String>, Option<String>, Option<String>),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue