diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index aa9a0baa7ce..aaf9a87a4ab 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -88,7 +88,8 @@ pub struct Document { window: @mut Window, doctype: DocumentType, idmap: HashMap, - implementation: Option<@mut DOMImplementation> + implementation: Option<@mut DOMImplementation>, + content_type: DOMString } impl Document { @@ -109,7 +110,7 @@ impl Document { abstract } - pub fn new_inherited(window: @mut Window, doctype: DocumentType) -> Document { + pub fn new_inherited(window: @mut Window, doctype: DocumentType, content_type: Option) -> Document { let node_type = match doctype { HTML => HTMLDocumentTypeId, SVG | XML => PlainDocumentTypeId @@ -120,19 +121,28 @@ impl Document { window: window, doctype: doctype, idmap: HashMap::new(), - implementation: None + implementation: None, + content_type: match content_type { + Some(string) => string.clone(), + None => match doctype { + // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument + HTML => ~"text/html", + // http://dom.spec.whatwg.org/#concept-document-content-type + SVG | XML => ~"application/xml" + } + } } } - pub fn new(window: @mut Window, doctype: DocumentType) -> AbstractDocument { - let document = Document::new_inherited(window, doctype); + pub fn new(window: @mut Window, doctype: DocumentType, content_type: Option) -> AbstractDocument { + let document = Document::new_inherited(window, doctype, content_type); Document::reflect_document(@mut document, window, DocumentBinding::Wrap) } } impl Document { pub fn Constructor(owner: @mut Window) -> Fallible { - Ok(Document::new(owner, XML)) + Ok(Document::new(owner, XML, None)) } } @@ -164,6 +174,11 @@ impl Document { self.implementation.unwrap() } + // http://dom.spec.whatwg.org/#dom-document-content_type + pub fn ContentType(&self) -> DOMString { + self.content_type.clone() + } + pub fn GetDoctype(&self) -> Option { self.node.children().find(|child| child.is_doctype()) } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 2cbed7cdfee..33a97be5c55 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -62,16 +62,13 @@ impl DOMImplementation { // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument pub fn CreateHTMLDocument(&self, title: Option) -> AbstractDocument { - // Step 1. + // Step 1-2. let abstract_doc = HTMLDocument::new(self.owner); assert!(abstract_doc.document().doctype == HTML); let abstract_node = AbstractNode::from_document(abstract_doc); assert!(abstract_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId)); - // Step 2. - // FIXME: https://github.com/mozilla/servo/pull/1519 - { // Step 3. let doc_type = DocumentType::new(~"html", None, None, abstract_doc); diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index e9bc170b6cb..c7515c549ea 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::DOMParserBinding; use dom::bindings::codegen::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; use dom::bindings::utils::{DOMString, Fallible, Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::FailureUnknown; -use dom::document::{AbstractDocument, Document, XML}; +use dom::document::{AbstractDocument, Document}; use dom::htmldocument::HTMLDocument; use dom::window::Window; @@ -41,7 +41,7 @@ impl DOMParser { Ok(HTMLDocument::new(self.owner)) } Text_xml => { - Ok(Document::new(self.owner, XML)) + Document::Constructor(self.owner) } _ => { Err(FailureUnknown) diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 4a8ac7d8158..6443be08985 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -20,7 +20,7 @@ pub struct HTMLDocument { impl HTMLDocument { pub fn new_inherited(window: @mut Window) -> HTMLDocument { HTMLDocument { - parent: Document::new_inherited(window, HTML) + parent: Document::new_inherited(window, HTML, None) } } diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index 4f7fafee7b4..2637afdaf34 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -30,7 +30,7 @@ interface Document : Node { // readonly attribute DOMString documentURI; // readonly attribute DOMString compatMode; // readonly attribute DOMString characterSet; - // readonly attribute DOMString contentType; + readonly attribute DOMString contentType; readonly attribute DocumentType? doctype; readonly attribute Element? documentElement; diff --git a/src/test/html/content/harness.js b/src/test/html/content/harness.js index 0697376df4f..ade4536a879 100644 --- a/src/test/html/content/harness.js +++ b/src/test/html/content/harness.js @@ -22,6 +22,7 @@ function _printer(opstr, op) { var is = _printer("==", function (a,b) { return a == b; }); var is_a = _printer("is a", function (a,b) { return a instanceof b; }); +var is_not_a = _printer("is not a", function (a,b) { return !(a instanceof b); }); var is_in = _printer("is in", function (a,b) { return a in b; }); var is_not_in = _printer("is not in", function (a,b) { return !(a in b); }); var as_str_is = _printer("as string is", function (a,b) { return String(a) == b; }); diff --git a/src/test/html/content/test_document_contenttype.html b/src/test/html/content/test_document_contenttype.html new file mode 100644 index 00000000000..ede2696f98a --- /dev/null +++ b/src/test/html/content/test_document_contenttype.html @@ -0,0 +1,22 @@ + + + + + + +