servo: Merge #10647 - Finish hooking up XML parser (from cbrewster:parse_xml); r=jdm

This is a work in progress PR for #10581. I just want to make sure I am headed in the right direction.

cc @jdm

Source-Repo: https://github.com/servo/servo
Source-Revision: daa1a2a0a82d336205dae340d705ea6c0bed4ed2
This commit is contained in:
Connor Brewster 2016-04-27 07:50:54 -07:00
Родитель 56bef9c48f
Коммит a169b8b4a6
7 изменённых файлов: 62 добавлений и 35 удалений

Просмотреть файл

@ -27,7 +27,7 @@ canvas_traits = {path = "../canvas_traits"}
js = {git = "https://github.com/servo/rust-mozjs"}
angle = {git = "https://github.com/emilio/angle", branch = "servo"}
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
xml5ever = {git = "https://github.com/Ygg01/xml5ever", features = ["unstable"]}
xml5ever = {version = "0.1.2", features = ["unstable"]}
gfx_traits = {path = "../gfx_traits"}
webrender_traits = {git = "https://github.com/servo/webrender_traits"}
app_units = {version = "0.2.3", features = ["plugins"]}

Просмотреть файл

@ -127,6 +127,8 @@ impl ServoXMLParser {
if !pending_input.is_empty() {
let chunk = pending_input.remove(0);
self.tokenizer.borrow_mut().feed(chunk.into());
} else {
self.tokenizer.borrow_mut().run();
}
// Document parsing is blocked on an external resource.

Просмотреть файл

@ -11,11 +11,13 @@ use dom::comment::Comment;
use dom::document::Document;
use dom::documenttype::DocumentType;
use dom::element::{Element, ElementCreator};
use dom::htmlscriptelement::HTMLScriptElement;
use dom::node::Node;
use dom::processinginstruction::ProcessingInstruction;
use dom::servoxmlparser;
use dom::servoxmlparser::ServoXMLParser;
use dom::text::Text;
use html5ever;
use msg::constellation_msg::PipelineId;
use parse::Parser;
use std::borrow::Cow;
@ -24,7 +26,7 @@ use url::Url;
use util::str::DOMString;
use xml5ever::tendril::StrTendril;
use xml5ever::tokenizer::{Attribute, QName};
use xml5ever::tree_builder::{NodeOrText, TreeSink};
use xml5ever::tree_builder::{NextParserState, NodeOrText, TreeSink};
impl<'a> TreeSink for servoxmlparser::Sink {
type Handle = JS<Node>;
@ -101,6 +103,24 @@ impl<'a> TreeSink for servoxmlparser::Sink {
doc);
JS::from_ref(pi.upcast())
}
fn mark_script_already_started(&mut self, node: Self::Handle) {
let script = node.downcast::<HTMLScriptElement>();
if let Some(script) = script {
script.mark_already_started();
}
}
fn complete_script(&mut self, node: Self::Handle) -> NextParserState {
let script = node.downcast::<HTMLScriptElement>();
if let Some(script) = script {
return match script.prepare() {
html5ever::tree_builder::NextParserState::Continue => NextParserState::Continue,
html5ever::tree_builder::NextParserState::Suspend => NextParserState::Suspend
};
}
NextParserState::Continue
}
}
@ -119,4 +139,3 @@ pub fn parse_xml(document: &Document,
};
parser.parse_chunk(String::from(input));
}

Просмотреть файл

@ -1510,23 +1510,22 @@ impl ScriptThread {
headers.get().map(|&LastModified(HttpDate(ref tm))| dom_last_modified(tm))
});
let content_type = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) => {
Some(DOMString::from("text/xml"))
let content_type = metadata.content_type.as_ref().and_then(|&ContentType(ref mimetype)| {
match *mimetype {
Mime(TopLevel::Application, SubLevel::Xml, _) |
Mime(TopLevel::Application, SubLevel::Ext(_), _) |
Mime(TopLevel::Text, SubLevel::Xml, _) |
Mime(TopLevel::Text, SubLevel::Plain, _) => Some(DOMString::from(mimetype.to_string())),
_ => None,
}
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => {
Some(DOMString::from("text/plain"))
}
_ => None
};
});
let loader = DocumentLoader::new_with_thread(self.resource_thread.clone(),
Some(page.pipeline()),
Some(incomplete.url.clone()));
let is_html_document = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Application, SubLevel::Xml, _))) |
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) =>
IsHTMLDocument::NonHTMLDocument,
_ => IsHTMLDocument::HTMLDocument,
@ -1587,19 +1586,26 @@ impl ScriptThread {
document.set_https_state(metadata.https_state);
match metadata.content_type {
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) => {
parse_xml(document.r(),
parse_input,
final_url,
xml::ParseContext::Owner(Some(incomplete.pipeline_id)));
}
_ => {
parse_html(document.r(),
parse_input,
final_url,
ParseContext::Owner(Some(incomplete.pipeline_id)));
}
let is_xml = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Application, SubLevel::Ext(ref sub_level), _)))
if sub_level.ends_with("+xml") => true,
Some(ContentType(Mime(TopLevel::Application, SubLevel::Xml, _))) |
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) => true,
_ => false,
};
if is_xml {
parse_xml(document.r(),
parse_input,
final_url,
xml::ParseContext::Owner(Some(incomplete.pipeline_id)));
} else {
parse_html(document.r(),
parse_input,
final_url,
ParseContext::Owner(Some(incomplete.pipeline_id)));
}
if incomplete.is_frozen {

6
servo/components/servo/Cargo.lock сгенерированный
Просмотреть файл

@ -1837,7 +1837,7 @@ dependencies = [
"uuid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
"websocket 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"xml5ever 0.1.1 (git+https://github.com/Ygg01/xml5ever)",
"xml5ever 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2523,8 +2523,8 @@ dependencies = [
[[package]]
name = "xml5ever"
version = "0.1.1"
source = "git+https://github.com/Ygg01/xml5ever#a51a6df18f384ecfb0a99b288c267178cf68f7f7"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mac 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

6
servo/ports/cef/Cargo.lock сгенерированный
Просмотреть файл

@ -1705,7 +1705,7 @@ dependencies = [
"uuid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
"websocket 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"xml5ever 0.1.1 (git+https://github.com/Ygg01/xml5ever)",
"xml5ever 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2389,8 +2389,8 @@ dependencies = [
[[package]]
name = "xml5ever"
version = "0.1.1"
source = "git+https://github.com/Ygg01/xml5ever#a51a6df18f384ecfb0a99b288c267178cf68f7f7"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mac 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

6
servo/ports/gonk/Cargo.lock сгенерированный
Просмотреть файл

@ -1688,7 +1688,7 @@ dependencies = [
"uuid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
"websocket 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"xml5ever 0.1.1 (git+https://github.com/Ygg01/xml5ever)",
"xml5ever 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2340,8 +2340,8 @@ dependencies = [
[[package]]
name = "xml5ever"
version = "0.1.1"
source = "git+https://github.com/Ygg01/xml5ever#a51a6df18f384ecfb0a99b288c267178cf68f7f7"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mac 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",