From 7f97399fccc7422542c5cf2355edca8bb06b5c81 Mon Sep 17 00:00:00 2001 From: Nupur Baghel Date: Fri, 9 Feb 2018 05:02:19 -0500 Subject: [PATCH] servo: Merge #19972 - replaced content_type from DOCString to Mime (from paavininanda:Issue16483); r=jdm Replaced content_type from DomString to Mime --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #16483 (https://github.com/servo/servo/issues/16483). - [x] These changes do not require tests because they make changes to already existing files Source-Repo: https://github.com/servo/servo Source-Revision: 7e501f50f7ef71c6f877bb2ebbaaeaf0162b5f43 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 1561b203307f82f8731f63c95f91587181a3ef15 --- servo/components/script/dom/document.rs | 21 +++++++++++-------- .../script/dom/domimplementation.rs | 9 ++++---- servo/components/script/dom/domparser.rs | 2 +- servo/components/script/dom/xmldocument.rs | 5 +++-- servo/components/script/dom/xmlhttprequest.rs | 5 +---- servo/components/script/script_thread.rs | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/servo/components/script/dom/document.rs b/servo/components/script/dom/document.rs index 0ed2c25ff4b8..8df8ba23d9ad 100644 --- a/servo/components/script/dom/document.rs +++ b/servo/components/script/dom/document.rs @@ -98,6 +98,7 @@ use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{JSContext, JSObject, JSRuntime}; use js::jsapi::JS_GetRuntime; use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric}; +use mime::{Mime, TopLevel, SubLevel}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy}; use net_traits::CookieSource::NonHTTP; @@ -235,7 +236,8 @@ pub struct Document { node: Node, window: Dom, implementation: MutNullableDom, - content_type: DOMString, + #[ignore_malloc_size_of = "type from external crate"] + content_type: Mime, last_modified: Option, encoding: Cell<&'static Encoding>, has_browsing_context: bool, @@ -2195,7 +2197,7 @@ impl Document { url: Option, origin: MutableOrigin, is_html_document: IsHTMLDocument, - content_type: Option, + content_type: Option, last_modified: Option, activity: DocumentActivity, source: DocumentSource, @@ -2220,12 +2222,12 @@ impl Document { has_browsing_context: has_browsing_context == HasBrowsingContext::Yes, implementation: Default::default(), content_type: match content_type { - Some(string) => string, - None => DOMString::from(match is_html_document { + Some(mime_data) => mime_data, + None => Mime::from(match is_html_document { // https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument - IsHTMLDocument::HTMLDocument => "text/html", + IsHTMLDocument::HTMLDocument => Mime(TopLevel::Text, SubLevel::Html, vec![]), // https://dom.spec.whatwg.org/#concept-document-content-type - IsHTMLDocument::NonHTMLDocument => "application/xml", + IsHTMLDocument::NonHTMLDocument => Mime(TopLevel::Application, SubLevel::Xml, vec![]), }), }, last_modified: last_modified, @@ -2337,7 +2339,7 @@ impl Document { url: Option, origin: MutableOrigin, doctype: IsHTMLDocument, - content_type: Option, + content_type: Option, last_modified: Option, activity: DocumentActivity, source: DocumentSource, @@ -2887,7 +2889,7 @@ impl DocumentMethods for Document { // https://dom.spec.whatwg.org/#dom-document-content_type fn ContentType(&self) -> DOMString { - self.content_type.clone() + DOMString::from(self.content_type.to_string()) } // https://dom.spec.whatwg.org/#dom-document-doctype @@ -2967,7 +2969,8 @@ impl DocumentMethods for Document { local_name.make_ascii_lowercase(); } - let ns = if self.is_html_document || self.content_type == "application/xhtml+xml" { + let is_xhtml = self.content_type.0 == TopLevel::Application && self.content_type.1.as_str() == "xhtml+xml"; + let ns = if self.is_html_document || is_xhtml { ns!(html) } else { ns!() diff --git a/servo/components/script/dom/domimplementation.rs b/servo/components/script/dom/domimplementation.rs index c25908e67a70..c93182aab6ef 100644 --- a/servo/components/script/dom/domimplementation.rs +++ b/servo/components/script/dom/domimplementation.rs @@ -24,6 +24,7 @@ use dom::node::Node; use dom::text::Text; use dom::xmldocument::XMLDocument; use dom_struct::dom_struct; +use mime::{Mime, TopLevel, SubLevel}; use script_traits::DocumentActivity; // https://dom.spec.whatwg.org/#domimplementation @@ -72,9 +73,9 @@ impl DOMImplementationMethods for DOMImplementation { let namespace = namespace_from_domstring(maybe_namespace.to_owned()); let content_type = match namespace { - ns!(html) => "application/xhtml+xml", - ns!(svg) => "image/svg+xml", - _ => "application/xml" + ns!(html) => Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_string()), vec![]), + ns!(svg) => Mime(TopLevel::Image, SubLevel::Ext("svg+xml".to_string()), vec![]), + _ => Mime(TopLevel::Application, SubLevel::Xml, vec![]) }; // Step 1. @@ -83,7 +84,7 @@ impl DOMImplementationMethods for DOMImplementation { None, self.document.origin().clone(), IsHTMLDocument::NonHTMLDocument, - Some(DOMString::from(content_type)), + Some(content_type), None, DocumentActivity::Inactive, DocumentSource::NotFromParser, diff --git a/servo/components/script/dom/domparser.rs b/servo/components/script/dom/domparser.rs index c0de086569ac..2d293d0a1847 100644 --- a/servo/components/script/dom/domparser.rs +++ b/servo/components/script/dom/domparser.rs @@ -54,7 +54,7 @@ impl DOMParserMethods for DOMParser { ty: DOMParserBinding::SupportedType) -> Fallible> { let url = self.window.get_url(); - let content_type = DOMString::from(ty.as_str()); + let content_type = ty.as_str().parse().expect("Supported type is not a MIME type"); let doc = self.window.Document(); let loader = DocumentLoader::new(&*doc.loader()); match ty { diff --git a/servo/components/script/dom/xmldocument.rs b/servo/components/script/dom/xmldocument.rs index 68764eb1080b..abd5ed646351 100644 --- a/servo/components/script/dom/xmldocument.rs +++ b/servo/components/script/dom/xmldocument.rs @@ -16,6 +16,7 @@ use dom::window::Window; use dom_struct::dom_struct; use js::jsapi::JSContext; use js::jsapi::JSObject; +use mime::Mime; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; use std::ptr::NonNull; @@ -32,7 +33,7 @@ impl XMLDocument { url: Option, origin: MutableOrigin, is_html_document: IsHTMLDocument, - content_type: Option, + content_type: Option, last_modified: Option, activity: DocumentActivity, source: DocumentSource, @@ -59,7 +60,7 @@ impl XMLDocument { url: Option, origin: MutableOrigin, doctype: IsHTMLDocument, - content_type: Option, + content_type: Option, last_modified: Option, activity: DocumentActivity, source: DocumentSource, diff --git a/servo/components/script/dom/xmlhttprequest.rs b/servo/components/script/dom/xmlhttprequest.rs index 4e56661f0c44..33c62a38cd53 100644 --- a/servo/components/script/dom/xmlhttprequest.rs +++ b/servo/components/script/dom/xmlhttprequest.rs @@ -1271,10 +1271,7 @@ impl XMLHttpRequest { Ok(parsed) => Some(parsed), Err(_) => None // Step 7 }; - let mime_type = self.final_mime_type(); - let content_type = mime_type.map(|mime|{ - DOMString::from(format!("{}", mime)) - }); + let content_type = self.final_mime_type(); Document::new(win, HasBrowsingContext::No, parsed_url, diff --git a/servo/components/script/script_thread.rs b/servo/components/script/script_thread.rs index c6f9dda250c8..fd5fe44962fa 100644 --- a/servo/components/script/script_thread.rs +++ b/servo/components/script/script_thread.rs @@ -2183,7 +2183,7 @@ impl ScriptThread { let content_type = metadata.content_type .as_ref() - .map(|&Serde(ContentType(ref mimetype))| DOMString::from(mimetype.to_string())); + .map(|&Serde(ContentType(ref mimetype))| mimetype.clone()); let loader = DocumentLoader::new_with_threads(self.resource_threads.clone(), Some(final_url.clone()));