mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Updated content_type of Document and XMLDocument from DOCString to Mime
This commit is contained in:
parent
1662fd7357
commit
d02422408e
6 changed files with 23 additions and 21 deletions
|
@ -98,6 +98,7 @@ use ipc_channel::ipc::{self, IpcSender};
|
||||||
use js::jsapi::{JSContext, JSObject, JSRuntime};
|
use js::jsapi::{JSContext, JSObject, JSRuntime};
|
||||||
use js::jsapi::JS_GetRuntime;
|
use js::jsapi::JS_GetRuntime;
|
||||||
use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric};
|
use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric};
|
||||||
|
use mime::{Mime, TopLevel, SubLevel};
|
||||||
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId};
|
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId};
|
||||||
use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy};
|
use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy};
|
||||||
use net_traits::CookieSource::NonHTTP;
|
use net_traits::CookieSource::NonHTTP;
|
||||||
|
@ -236,7 +237,8 @@ pub struct Document {
|
||||||
node: Node,
|
node: Node,
|
||||||
window: Dom<Window>,
|
window: Dom<Window>,
|
||||||
implementation: MutNullableDom<DOMImplementation>,
|
implementation: MutNullableDom<DOMImplementation>,
|
||||||
content_type: DOMString,
|
#[ignore_malloc_size_of = "type from external crate"]
|
||||||
|
content_type: Mime,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
encoding: Cell<&'static Encoding>,
|
encoding: Cell<&'static Encoding>,
|
||||||
has_browsing_context: bool,
|
has_browsing_context: bool,
|
||||||
|
@ -2197,7 +2199,7 @@ impl Document {
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
origin: MutableOrigin,
|
origin: MutableOrigin,
|
||||||
is_html_document: IsHTMLDocument,
|
is_html_document: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<Mime>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
activity: DocumentActivity,
|
activity: DocumentActivity,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
|
@ -2222,12 +2224,12 @@ impl Document {
|
||||||
has_browsing_context: has_browsing_context == HasBrowsingContext::Yes,
|
has_browsing_context: has_browsing_context == HasBrowsingContext::Yes,
|
||||||
implementation: Default::default(),
|
implementation: Default::default(),
|
||||||
content_type: match content_type {
|
content_type: match content_type {
|
||||||
Some(string) => string,
|
Some(mime_data) => mime_data,
|
||||||
None => DOMString::from(match is_html_document {
|
None => Mime::from(match is_html_document {
|
||||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
// 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
|
// 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,
|
last_modified: last_modified,
|
||||||
|
@ -2339,7 +2341,7 @@ impl Document {
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
origin: MutableOrigin,
|
origin: MutableOrigin,
|
||||||
doctype: IsHTMLDocument,
|
doctype: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<Mime>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
activity: DocumentActivity,
|
activity: DocumentActivity,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
|
@ -2889,7 +2891,7 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-content_type
|
// https://dom.spec.whatwg.org/#dom-document-content_type
|
||||||
fn ContentType(&self) -> DOMString {
|
fn ContentType(&self) -> DOMString {
|
||||||
self.content_type.clone()
|
DOMString::from(self.content_type.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-doctype
|
// https://dom.spec.whatwg.org/#dom-document-doctype
|
||||||
|
@ -2969,7 +2971,8 @@ impl DocumentMethods for Document {
|
||||||
local_name.make_ascii_lowercase();
|
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)
|
ns!(html)
|
||||||
} else {
|
} else {
|
||||||
ns!()
|
ns!()
|
||||||
|
|
|
@ -24,6 +24,7 @@ use dom::node::Node;
|
||||||
use dom::text::Text;
|
use dom::text::Text;
|
||||||
use dom::xmldocument::XMLDocument;
|
use dom::xmldocument::XMLDocument;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use mime::{Mime, TopLevel, SubLevel};
|
||||||
use script_traits::DocumentActivity;
|
use script_traits::DocumentActivity;
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#domimplementation
|
// https://dom.spec.whatwg.org/#domimplementation
|
||||||
|
@ -72,9 +73,9 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
let namespace = namespace_from_domstring(maybe_namespace.to_owned());
|
let namespace = namespace_from_domstring(maybe_namespace.to_owned());
|
||||||
|
|
||||||
let content_type = match namespace {
|
let content_type = match namespace {
|
||||||
ns!(html) => "application/xhtml+xml",
|
ns!(html) => Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_string()), vec![]),
|
||||||
ns!(svg) => "image/svg+xml",
|
ns!(svg) => Mime(TopLevel::Image, SubLevel::Ext("svg+xml".to_string()), vec![]),
|
||||||
_ => "application/xml"
|
_ => Mime(TopLevel::Application, SubLevel::Xml, vec![])
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
|
@ -83,7 +84,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
None,
|
None,
|
||||||
self.document.origin().clone(),
|
self.document.origin().clone(),
|
||||||
IsHTMLDocument::NonHTMLDocument,
|
IsHTMLDocument::NonHTMLDocument,
|
||||||
Some(DOMString::from(content_type)),
|
Some(content_type),
|
||||||
None,
|
None,
|
||||||
DocumentActivity::Inactive,
|
DocumentActivity::Inactive,
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl DOMParserMethods for DOMParser {
|
||||||
ty: DOMParserBinding::SupportedType)
|
ty: DOMParserBinding::SupportedType)
|
||||||
-> Fallible<DomRoot<Document>> {
|
-> Fallible<DomRoot<Document>> {
|
||||||
let url = self.window.get_url();
|
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 doc = self.window.Document();
|
||||||
let loader = DocumentLoader::new(&*doc.loader());
|
let loader = DocumentLoader::new(&*doc.loader());
|
||||||
match ty {
|
match ty {
|
||||||
|
|
|
@ -16,6 +16,7 @@ use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use js::jsapi::JSContext;
|
use js::jsapi::JSContext;
|
||||||
use js::jsapi::JSObject;
|
use js::jsapi::JSObject;
|
||||||
|
use mime::Mime;
|
||||||
use script_traits::DocumentActivity;
|
use script_traits::DocumentActivity;
|
||||||
use servo_url::{MutableOrigin, ServoUrl};
|
use servo_url::{MutableOrigin, ServoUrl};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
@ -32,7 +33,7 @@ impl XMLDocument {
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
origin: MutableOrigin,
|
origin: MutableOrigin,
|
||||||
is_html_document: IsHTMLDocument,
|
is_html_document: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<Mime>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
activity: DocumentActivity,
|
activity: DocumentActivity,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
|
@ -59,7 +60,7 @@ impl XMLDocument {
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
origin: MutableOrigin,
|
origin: MutableOrigin,
|
||||||
doctype: IsHTMLDocument,
|
doctype: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<Mime>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
activity: DocumentActivity,
|
activity: DocumentActivity,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
|
|
|
@ -1271,10 +1271,7 @@ impl XMLHttpRequest {
|
||||||
Ok(parsed) => Some(parsed),
|
Ok(parsed) => Some(parsed),
|
||||||
Err(_) => None // Step 7
|
Err(_) => None // Step 7
|
||||||
};
|
};
|
||||||
let mime_type = self.final_mime_type();
|
let content_type = self.final_mime_type();
|
||||||
let content_type = mime_type.map(|mime|{
|
|
||||||
DOMString::from(format!("{}", mime))
|
|
||||||
});
|
|
||||||
Document::new(win,
|
Document::new(win,
|
||||||
HasBrowsingContext::No,
|
HasBrowsingContext::No,
|
||||||
parsed_url,
|
parsed_url,
|
||||||
|
|
|
@ -2183,7 +2183,7 @@ impl ScriptThread {
|
||||||
|
|
||||||
let content_type = metadata.content_type
|
let content_type = metadata.content_type
|
||||||
.as_ref()
|
.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(),
|
let loader = DocumentLoader::new_with_threads(self.resource_threads.clone(),
|
||||||
Some(final_url.clone()));
|
Some(final_url.clone()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue