mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Simplify AsyncResponseListener implementations.
This commit is contained in:
parent
c1aff0b678
commit
827f2b873c
3 changed files with 23 additions and 25 deletions
|
@ -31,7 +31,7 @@ use net_traits::{AsyncResponseListener, Metadata};
|
|||
use network_listener::PreInvoke;
|
||||
use parse::Parser;
|
||||
use script_task::{ScriptChan, ScriptTask};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cell::Cell;
|
||||
use std::default::Default;
|
||||
use url::Url;
|
||||
|
||||
|
@ -69,9 +69,9 @@ pub type Tokenizer = tokenizer::Tokenizer<TreeBuilder<JS<Node>, Sink>>;
|
|||
/// The context required for asynchronously fetching a document and parsing it progressively.
|
||||
pub struct ParserContext {
|
||||
/// The parser that initiated the request.
|
||||
parser: RefCell<Option<Trusted<ServoHTMLParser>>>,
|
||||
parser: Option<Trusted<ServoHTMLParser>>,
|
||||
/// Is this document a synthesized document for a single image?
|
||||
is_image_document: Cell<bool>,
|
||||
is_image_document: bool,
|
||||
/// The pipeline associated with this document.
|
||||
id: PipelineId,
|
||||
/// The subpage associated with this document.
|
||||
|
@ -86,8 +86,8 @@ impl ParserContext {
|
|||
pub fn new(id: PipelineId, subpage: Option<SubpageId>, script_chan: Box<ScriptChan + Send>,
|
||||
url: Url) -> ParserContext {
|
||||
ParserContext {
|
||||
parser: RefCell::new(None),
|
||||
is_image_document: Cell::new(false),
|
||||
parser: None,
|
||||
is_image_document: false,
|
||||
id: id,
|
||||
subpage: subpage,
|
||||
script_chan: script_chan,
|
||||
|
@ -109,12 +109,11 @@ impl AsyncResponseListener for ParserContext {
|
|||
|
||||
let parser = parser.r();
|
||||
let win = parser.window();
|
||||
*self.parser.borrow_mut() = Some(Trusted::new(win.r().get_cx(), parser,
|
||||
self.script_chan.clone()));
|
||||
self.parser = Some(Trusted::new(win.r().get_cx(), parser, self.script_chan.clone()));
|
||||
|
||||
match content_type {
|
||||
Some(ContentType(Mime(TopLevel::Image, _, _))) => {
|
||||
self.is_image_document.set(true);
|
||||
self.is_image_document = true;
|
||||
let page = format!("<html><body><img src='{}' /></body></html>",
|
||||
self.url.serialize());
|
||||
parser.pending_input.borrow_mut().push(page);
|
||||
|
@ -138,10 +137,10 @@ impl AsyncResponseListener for ParserContext {
|
|||
}
|
||||
|
||||
fn data_available(&mut self, payload: Vec<u8>) {
|
||||
if !self.is_image_document.get() {
|
||||
if !self.is_image_document {
|
||||
// FIXME: use Vec<u8> (html5ever #34)
|
||||
let data = UTF_8.decode(&payload, DecoderTrap::Replace).unwrap();
|
||||
let parser = match self.parser.borrow().as_ref() {
|
||||
let parser = match self.parser.as_ref() {
|
||||
Some(parser) => parser.root(),
|
||||
None => return,
|
||||
};
|
||||
|
@ -150,7 +149,7 @@ impl AsyncResponseListener for ParserContext {
|
|||
}
|
||||
|
||||
fn response_complete(&mut self, status: Result<(), String>) {
|
||||
let parser = match self.parser.borrow().as_ref() {
|
||||
let parser = match self.parser.as_ref() {
|
||||
Some(parser) => parser.root(),
|
||||
None => return,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue