Move last chunk received logic to ServoParser

This commit is contained in:
Anthony Ramine 2016-10-08 15:55:04 +02:00
parent e1a1bf46ca
commit 881f7f4de7
4 changed files with 25 additions and 33 deletions

View file

@ -200,12 +200,15 @@ impl AsyncResponseListener for ParserContext {
debug!("Failed to load page URL {}, error: {:?}", self.url, err);
}
parser.r().as_servo_parser().document()
let parser = parser.r();
let servo_parser = parser.as_servo_parser();
servo_parser.document()
.finish_load(LoadType::PageSource(self.url.clone()));
parser.r().last_chunk_received().set(true);
if !parser.r().is_suspended() {
parser.r().parse_sync();
servo_parser.mark_last_chunk_received();
if !parser.is_suspended() {
parser.parse_sync();
}
}
}
@ -220,8 +223,6 @@ pub struct ServoHTMLParser {
tokenizer: DOMRefCell<Tokenizer>,
/// True if this parser should avoid passing any further data to the tokenizer.
suspended: Cell<bool>,
/// Whether to expect any further input from the associated network request.
last_chunk_received: Cell<bool>,
/// The pipeline associated with this parse, unavailable if this parse does not
/// correspond to a page load.
pipeline: Option<PipelineId>,
@ -268,10 +269,9 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, Default::default());
let parser = ServoHTMLParser {
servoparser: ServoParser::new_inherited(document),
servoparser: ServoParser::new_inherited(document, false),
tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
last_chunk_received: Cell::new(false),
pipeline: pipeline,
};
@ -302,10 +302,9 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, tok_opts);
let parser = ServoHTMLParser {
servoparser: ServoParser::new_inherited(document),
servoparser: ServoParser::new_inherited(document, true),
tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
last_chunk_received: Cell::new(true),
pipeline: None,
};
@ -360,7 +359,7 @@ impl ServoHTMLParser {
}
}
if self.last_chunk_received.get() {
if self.upcast().last_chunk_received() {
self.finish();
}
}
@ -383,10 +382,6 @@ impl ServoHTMLParser {
pub fn is_suspended(&self) -> bool {
self.suspended.get()
}
pub fn last_chunk_received(&self) -> &Cell<bool> {
&self.last_chunk_received
}
}
struct Tracer {

View file

@ -6,6 +6,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::reflector::Reflector;
use dom::bindings::js::JS;
use dom::document::Document;
use std::cell::Cell;
#[dom_struct]
pub struct ServoParser {
@ -14,14 +15,17 @@ pub struct ServoParser {
document: JS<Document>,
/// Input chunks received but not yet passed to the parser.
pending_input: DOMRefCell<Vec<String>>,
/// Whether to expect any further input from the associated network request.
last_chunk_received: Cell<bool>,
}
impl ServoParser {
pub fn new_inherited(document: &Document) -> Self {
pub fn new_inherited(document: &Document, last_chunk_received: bool) -> Self {
ServoParser {
reflector: Reflector::new(),
document: JS::from_ref(document),
pending_input: DOMRefCell::new(vec![]),
last_chunk_received: Cell::new(last_chunk_received),
}
}
@ -45,4 +49,12 @@ impl ServoParser {
Some(pending_input.remove(0))
}
}
pub fn last_chunk_received(&self) -> bool {
self.last_chunk_received.get()
}
pub fn mark_last_chunk_received(&self) {
self.last_chunk_received.set(true)
}
}

View file

@ -38,8 +38,6 @@ pub struct ServoXMLParser {
tokenizer: DOMRefCell<Tokenizer>,
/// True if this parser should avoid passing any further data to the tokenizer.
suspended: Cell<bool>,
/// Whether to expect any further input from the associated network request.
last_chunk_received: Cell<bool>,
/// The pipeline associated with this parse, unavailable if this parse does not
/// correspond to a page load.
pipeline: Option<PipelineId>,
@ -83,10 +81,9 @@ impl ServoXMLParser {
let tok = tokenizer::XmlTokenizer::new(tb, Default::default());
let parser = ServoXMLParser {
servoparser: ServoParser::new_inherited(document),
servoparser: ServoParser::new_inherited(document, false),
tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
last_chunk_received: Cell::new(false),
pipeline: pipeline,
};
@ -133,7 +130,7 @@ impl ServoXMLParser {
}
}
if self.last_chunk_received.get() {
if self.upcast().last_chunk_received() {
self.finish();
}
}
@ -146,10 +143,6 @@ impl ServoXMLParser {
self.tokenizer.borrow_mut().end()
}
pub fn last_chunk_received(&self) -> &Cell<bool> {
&self.last_chunk_received
}
pub fn tokenizer(&self) -> &DOMRefCell<Tokenizer> {
&self.tokenizer
}

View file

@ -9,7 +9,6 @@ use dom::servohtmlparser::ServoHTMLParser;
use dom::servoparser::ServoParser;
use dom::servoxmlparser::ServoXMLParser;
use dom::window::Window;
use std::cell::Cell;
use std::cell::UnsafeCell;
use std::ptr;
@ -159,12 +158,5 @@ impl<'a> ParserRef<'a> {
ParserRef::XML(parser) => parser.parse_sync(),
}
}
pub fn last_chunk_received(&self) -> &Cell<bool> {
match *self {
ParserRef::HTML(parser) => parser.last_chunk_received(),
ParserRef::XML(parser) => parser.last_chunk_received(),
}
}
}