Skip to content

Commit

Permalink
Mark the page source as loaded only after parsing is done
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Jan 19, 2017
1 parent d5442b8 commit cb008d4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
18 changes: 11 additions & 7 deletions components/script/dom/document.rs
Expand Up @@ -132,6 +132,7 @@ use style::restyle_hints::RestyleHint;
use style::selector_parser::{RestyleDamage, Snapshot};
use style::str::{split_html_space_chars, str_join};
use style::stylesheets::Stylesheet;
use task_source::TaskSource;
use time;
use url::percent_encoding::percent_decode;

Expand Down Expand Up @@ -1572,13 +1573,11 @@ impl Document {
}

if !self.loader.borrow().is_blocked() && !self.loader.borrow().events_inhibited() {
// Schedule a task to fire a "load" event (if no blocking loads have arrived in the mean time)
// NOTE: we can end up executing this code more than once, in case more blocking loads arrive.
self.loader.borrow_mut().inhibit_events();
// Schedule a task to fire a "load" event.
debug!("Document loads are complete.");
let win = self.window();
let msg = MainThreadScriptMsg::DocumentLoadsComplete(
win.upcast::<GlobalScope>().pipeline_id());
win.main_thread_script_chan().send(msg).unwrap();
let handler = box DocumentProgressHandler::new(Trusted::new(self));
self.window.dom_manipulation_task_source().queue(handler, self.window.upcast()).unwrap();
}
}

Expand Down Expand Up @@ -3314,6 +3313,9 @@ impl DocumentProgressHandler {

fn dispatch_load(&self) {
let document = self.addr.root();
if document.browsing_context().is_none() {
return;
}
let window = document.window();
let event = Event::new(window.upcast(),
atom!("load"),
Expand All @@ -3331,7 +3333,6 @@ impl DocumentProgressHandler {
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd
update_with_current_time_ms(&document.load_event_end);


window.reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
ReflowReason::DocumentLoaded);
Expand All @@ -3349,6 +3350,9 @@ impl Runnable for DocumentProgressHandler {
if window.is_alive() {
self.set_ready_state_complete();
self.dispatch_load();
if let Some(fragment) = document.url().fragment() {
document.check_and_scroll_fragment(fragment);
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/servoparser/html.rs
Expand Up @@ -93,6 +93,10 @@ impl Tokenizer {
self.inner.end();
}

pub fn url(&self) -> &ServoUrl {
&self.inner.sink().sink().base_url
}

pub fn set_plaintext_state(&mut self) {
self.inner.set_plaintext_state();
}
Expand Down
18 changes: 13 additions & 5 deletions components/script/dom/servoparser/mod.rs
Expand Up @@ -110,7 +110,8 @@ impl ServoParser {
let url = context_document.url();

// Step 1.
let loader = DocumentLoader::new(&*context_document.loader());
let loader = DocumentLoader::new_with_threads(context_document.loader().resource_threads().clone(),
Some(url.clone()));
let document = Document::new(window, None, Some(url.clone()),
context_document.origin().alias(),
IsHTMLDocument::HTMLDocument,
Expand Down Expand Up @@ -351,14 +352,17 @@ impl ServoParser {
self.document.set_current_parser(None);

if self.pipeline.is_some() {
// Initial reflow.
self.document.disarm_reflow_timeout();
self.document.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
let window = self.document.window();
window.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
}

// Step 3.
// Steps 3-12 are in another castle.
let url = self.tokenizer.borrow().url().clone();
self.document.process_deferred_scripts();
self.document.finish_load(LoadType::PageSource(url));
}
}

Expand Down Expand Up @@ -401,6 +405,13 @@ impl Tokenizer {
}
}

fn url(&self) -> &ServoUrl {
match *self {
Tokenizer::Html(ref tokenizer) => tokenizer.url(),
Tokenizer::Xml(ref tokenizer) => tokenizer.url(),
}
}

fn set_plaintext_state(&mut self) {
match *self {
Tokenizer::Html(ref mut tokenizer) => tokenizer.set_plaintext_state(),
Expand Down Expand Up @@ -558,9 +569,6 @@ impl FetchResponseListener for ParserContext {
debug!("Failed to load page URL {}, error: {:?}", self.url, err);
}

parser.document
.finish_load(LoadType::PageSource(self.url.clone()));

parser.last_chunk_received.set(true);
if !parser.suspended.get() {
parser.parse_sync();
Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/servoparser/xml.rs
Expand Up @@ -71,6 +71,10 @@ impl Tokenizer {
pub fn end(&mut self) {
self.inner.end()
}

pub fn url(&self) -> &ServoUrl {
&self.inner.sink().sink().base_url
}
}

#[allow(unsafe_code)]
Expand Down
2 changes: 1 addition & 1 deletion components/script/script_thread.rs
Expand Up @@ -1771,7 +1771,7 @@ impl ScriptThread {
});

let loader = DocumentLoader::new_with_threads(self.resource_threads.clone(),
Some(incomplete.url.clone()));
Some(final_url.clone()));

let is_html_document = match metadata.content_type {
Some(Serde(ContentType(Mime(TopLevel::Application, SubLevel::Ext(ref sub_level), _))))
Expand Down

0 comments on commit cb008d4

Please sign in to comment.