diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 0db59106fff..71b3a26873c 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -102,7 +102,7 @@ pub struct Document { implementation: MutNullableJS, location: MutNullableJS, content_type: DOMString, - last_modified: DOMRefCell>, + last_modified: Option, encoding_name: DOMRefCell, is_html_document: bool, url: Url, @@ -197,7 +197,6 @@ pub trait DocumentHelpers<'a> { fn url(self) -> Url; fn quirks_mode(self) -> QuirksMode; fn set_quirks_mode(self, mode: QuirksMode); - fn set_last_modified(self, value: DOMString); fn set_encoding_name(self, name: DOMString); fn content_changed(self, node: JSRef, damage: NodeDamage); fn content_and_heritage_changed(self, node: JSRef, damage: NodeDamage); @@ -278,10 +277,6 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { } } - fn set_last_modified(self, value: DOMString) { - *self.last_modified.borrow_mut() = Some(value); - } - fn set_encoding_name(self, name: DOMString) { *self.encoding_name.borrow_mut() = name; } @@ -704,6 +699,7 @@ impl Document { url: Option, is_html_document: IsHTMLDocument, content_type: Option, + last_modified: Option, source: DocumentSource) -> Document { let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap()); @@ -728,7 +724,7 @@ impl Document { IsHTMLDocument::NonHTMLDocument => "application/xml".to_owned() } }, - last_modified: DOMRefCell::new(None), + last_modified: last_modified, url: url, // http://dom.spec.whatwg.org/#concept-document-quirks quirks_mode: Cell::new(NoQuirks), @@ -754,16 +750,18 @@ impl Document { pub fn Constructor(global: GlobalRef) -> Fallible> { Ok(Document::new(global.as_window(), None, IsHTMLDocument::NonHTMLDocument, None, - DocumentSource::NotFromParser)) + None, DocumentSource::NotFromParser)) } pub fn new(window: JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option, + last_modified: Option, source: DocumentSource) -> Temporary { let document = reflect_dom_object(box Document::new_inherited(window, url, doctype, - content_type, source), + content_type, last_modified, + source), GlobalRef::Window(window), DocumentBinding::Wrap).root(); @@ -1063,7 +1061,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/html/#dom-document-lastmodified fn LastModified(self) -> DOMString { - match *self.last_modified.borrow() { + match self.last_modified { Some(ref t) => t.clone(), None => format!("{}", time::now().strftime("%m/%d/%Y %H:%M:%S").unwrap()), } diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 09b1582fd40..3353e735dfd 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -74,7 +74,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // Step 1. let doc = Document::new(win.r(), None, IsHTMLDocument::NonHTMLDocument, - None, DocumentSource::NotFromParser).root(); + None, None, DocumentSource::NotFromParser).root(); // Step 2-3. let maybe_elem = if qname.is_empty() { None @@ -119,7 +119,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { let win = document.r().window().root(); // Step 1-2. - let doc = Document::new(win.r(), None, IsHTMLDocument::HTMLDocument, None, + let doc = Document::new(win.r(), None, IsHTMLDocument::HTMLDocument, None, None, DocumentSource::NotFromParser).root(); let doc_node: JSRef = NodeCast::from_ref(doc.r()); diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index 88429277f19..02ef2b78ff5 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -56,6 +56,7 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { let document = Document::new(window.r(), Some(url.clone()), IsHTMLDocument::HTMLDocument, Some(content_type), + None, DocumentSource::FromParser).root(); parse_html(document.r(), HTMLInput::InputString(s), &url); document.r().set_ready_state(DocumentReadyState::Complete); @@ -66,6 +67,7 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { Ok(Document::new(window.r(), Some(url.clone()), IsHTMLDocument::NonHTMLDocument, Some(content_type), + None, DocumentSource::NotFromParser)) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 1ce9cfeae9e..699477a5a2e 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1576,7 +1576,7 @@ impl Node { let window = document.window().root(); let document = Document::new(window.r(), Some(document.url()), is_html_doc, None, - DocumentSource::NotFromParser); + None, DocumentSource::NotFromParser); NodeCast::from_temporary(document) }, NodeTypeId::Element(..) => { diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 95b5a22369a..3041098e78c 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -66,6 +66,7 @@ use net::storage_task::StorageTask; use string_cache::Atom; use util::geometry::to_frac_px; use util::smallvec::SmallVec; +use util::str::DOMString; use util::task::{spawn_named, spawn_named_with_send_on_failure}; use util::task_state; @@ -979,19 +980,19 @@ impl ScriptTask { incomplete.subpage_id.map(|s| s.1), incomplete.window_size).root(); - let document = Document::new(window.r(), Some(final_url.clone()), - IsHTMLDocument::HTMLDocument, None, + let last_modified: Option = response.metadata.headers.as_ref().and_then(|headers| { + headers.get().map(|&LastModified(ref tm)| dom_last_modified(tm)) + }); + + let document = Document::new(window.r(), + Some(final_url.clone()), + IsHTMLDocument::HTMLDocument, + None, + last_modified, DocumentSource::FromParser).root(); window.r().init_browser_context(document.r(), frame_element.r()); - let last_modified = response.metadata.headers.as_ref().and_then(|headers| { - headers.get().map(|&LastModified(ref tm)| tm.clone()) - }); - if let Some(tm) = last_modified { - document.r().set_last_modified(dom_last_modified(&tm)); - } - // Create the root frame page.set_frame(Some(Frame { document: JS::from_rooted(document.r()),