mirror of
https://github.com/servo/servo.git
synced 2025-07-30 02:30:21 +01:00
Move last chunk received logic to ServoParser
This commit is contained in:
parent
e1a1bf46ca
commit
881f7f4de7
4 changed files with 25 additions and 33 deletions
|
@ -200,12 +200,15 @@ impl AsyncResponseListener for ParserContext {
|
||||||
debug!("Failed to load page URL {}, error: {:?}", self.url, err);
|
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()));
|
.finish_load(LoadType::PageSource(self.url.clone()));
|
||||||
|
|
||||||
parser.r().last_chunk_received().set(true);
|
servo_parser.mark_last_chunk_received();
|
||||||
if !parser.r().is_suspended() {
|
if !parser.is_suspended() {
|
||||||
parser.r().parse_sync();
|
parser.parse_sync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,8 +223,6 @@ pub struct ServoHTMLParser {
|
||||||
tokenizer: DOMRefCell<Tokenizer>,
|
tokenizer: DOMRefCell<Tokenizer>,
|
||||||
/// True if this parser should avoid passing any further data to the tokenizer.
|
/// True if this parser should avoid passing any further data to the tokenizer.
|
||||||
suspended: Cell<bool>,
|
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
|
/// The pipeline associated with this parse, unavailable if this parse does not
|
||||||
/// correspond to a page load.
|
/// correspond to a page load.
|
||||||
pipeline: Option<PipelineId>,
|
pipeline: Option<PipelineId>,
|
||||||
|
@ -268,10 +269,9 @@ impl ServoHTMLParser {
|
||||||
let tok = tokenizer::Tokenizer::new(tb, Default::default());
|
let tok = tokenizer::Tokenizer::new(tb, Default::default());
|
||||||
|
|
||||||
let parser = ServoHTMLParser {
|
let parser = ServoHTMLParser {
|
||||||
servoparser: ServoParser::new_inherited(document),
|
servoparser: ServoParser::new_inherited(document, false),
|
||||||
tokenizer: DOMRefCell::new(tok),
|
tokenizer: DOMRefCell::new(tok),
|
||||||
suspended: Cell::new(false),
|
suspended: Cell::new(false),
|
||||||
last_chunk_received: Cell::new(false),
|
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -302,10 +302,9 @@ impl ServoHTMLParser {
|
||||||
let tok = tokenizer::Tokenizer::new(tb, tok_opts);
|
let tok = tokenizer::Tokenizer::new(tb, tok_opts);
|
||||||
|
|
||||||
let parser = ServoHTMLParser {
|
let parser = ServoHTMLParser {
|
||||||
servoparser: ServoParser::new_inherited(document),
|
servoparser: ServoParser::new_inherited(document, true),
|
||||||
tokenizer: DOMRefCell::new(tok),
|
tokenizer: DOMRefCell::new(tok),
|
||||||
suspended: Cell::new(false),
|
suspended: Cell::new(false),
|
||||||
last_chunk_received: Cell::new(true),
|
|
||||||
pipeline: None,
|
pipeline: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -360,7 +359,7 @@ impl ServoHTMLParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.last_chunk_received.get() {
|
if self.upcast().last_chunk_received() {
|
||||||
self.finish();
|
self.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,10 +382,6 @@ impl ServoHTMLParser {
|
||||||
pub fn is_suspended(&self) -> bool {
|
pub fn is_suspended(&self) -> bool {
|
||||||
self.suspended.get()
|
self.suspended.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_chunk_received(&self) -> &Cell<bool> {
|
|
||||||
&self.last_chunk_received
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Tracer {
|
struct Tracer {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::reflector::Reflector;
|
use dom::bindings::reflector::Reflector;
|
||||||
use dom::bindings::js::JS;
|
use dom::bindings::js::JS;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
use std::cell::Cell;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct ServoParser {
|
pub struct ServoParser {
|
||||||
|
@ -14,14 +15,17 @@ pub struct ServoParser {
|
||||||
document: JS<Document>,
|
document: JS<Document>,
|
||||||
/// Input chunks received but not yet passed to the parser.
|
/// Input chunks received but not yet passed to the parser.
|
||||||
pending_input: DOMRefCell<Vec<String>>,
|
pending_input: DOMRefCell<Vec<String>>,
|
||||||
|
/// Whether to expect any further input from the associated network request.
|
||||||
|
last_chunk_received: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServoParser {
|
impl ServoParser {
|
||||||
pub fn new_inherited(document: &Document) -> Self {
|
pub fn new_inherited(document: &Document, last_chunk_received: bool) -> Self {
|
||||||
ServoParser {
|
ServoParser {
|
||||||
reflector: Reflector::new(),
|
reflector: Reflector::new(),
|
||||||
document: JS::from_ref(document),
|
document: JS::from_ref(document),
|
||||||
pending_input: DOMRefCell::new(vec![]),
|
pending_input: DOMRefCell::new(vec![]),
|
||||||
|
last_chunk_received: Cell::new(last_chunk_received),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,4 +49,12 @@ impl ServoParser {
|
||||||
Some(pending_input.remove(0))
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,6 @@ pub struct ServoXMLParser {
|
||||||
tokenizer: DOMRefCell<Tokenizer>,
|
tokenizer: DOMRefCell<Tokenizer>,
|
||||||
/// True if this parser should avoid passing any further data to the tokenizer.
|
/// True if this parser should avoid passing any further data to the tokenizer.
|
||||||
suspended: Cell<bool>,
|
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
|
/// The pipeline associated with this parse, unavailable if this parse does not
|
||||||
/// correspond to a page load.
|
/// correspond to a page load.
|
||||||
pipeline: Option<PipelineId>,
|
pipeline: Option<PipelineId>,
|
||||||
|
@ -83,10 +81,9 @@ impl ServoXMLParser {
|
||||||
let tok = tokenizer::XmlTokenizer::new(tb, Default::default());
|
let tok = tokenizer::XmlTokenizer::new(tb, Default::default());
|
||||||
|
|
||||||
let parser = ServoXMLParser {
|
let parser = ServoXMLParser {
|
||||||
servoparser: ServoParser::new_inherited(document),
|
servoparser: ServoParser::new_inherited(document, false),
|
||||||
tokenizer: DOMRefCell::new(tok),
|
tokenizer: DOMRefCell::new(tok),
|
||||||
suspended: Cell::new(false),
|
suspended: Cell::new(false),
|
||||||
last_chunk_received: Cell::new(false),
|
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,7 +130,7 @@ impl ServoXMLParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.last_chunk_received.get() {
|
if self.upcast().last_chunk_received() {
|
||||||
self.finish();
|
self.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,10 +143,6 @@ impl ServoXMLParser {
|
||||||
self.tokenizer.borrow_mut().end()
|
self.tokenizer.borrow_mut().end()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_chunk_received(&self) -> &Cell<bool> {
|
|
||||||
&self.last_chunk_received
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn tokenizer(&self) -> &DOMRefCell<Tokenizer> {
|
pub fn tokenizer(&self) -> &DOMRefCell<Tokenizer> {
|
||||||
&self.tokenizer
|
&self.tokenizer
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ use dom::servohtmlparser::ServoHTMLParser;
|
||||||
use dom::servoparser::ServoParser;
|
use dom::servoparser::ServoParser;
|
||||||
use dom::servoxmlparser::ServoXMLParser;
|
use dom::servoxmlparser::ServoXMLParser;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use std::cell::Cell;
|
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
@ -159,12 +158,5 @@ impl<'a> ParserRef<'a> {
|
||||||
ParserRef::XML(parser) => parser.parse_sync(),
|
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue