mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
parent
f7877008d2
commit
e2bfdb30a0
5 changed files with 55 additions and 13 deletions
|
@ -59,6 +59,7 @@ use std::collections::hashmap::HashMap;
|
||||||
use std::ascii::StrAsciiExt;
|
use std::ascii::StrAsciiExt;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use time;
|
||||||
|
|
||||||
#[deriving(PartialEq,Encodable)]
|
#[deriving(PartialEq,Encodable)]
|
||||||
pub enum IsHTMLDocument {
|
pub enum IsHTMLDocument {
|
||||||
|
@ -74,6 +75,7 @@ pub struct Document {
|
||||||
idmap: Traceable<RefCell<HashMap<DOMString, Vec<JS<Element>>>>>,
|
idmap: Traceable<RefCell<HashMap<DOMString, Vec<JS<Element>>>>>,
|
||||||
implementation: Cell<Option<JS<DOMImplementation>>>,
|
implementation: Cell<Option<JS<DOMImplementation>>>,
|
||||||
content_type: DOMString,
|
content_type: DOMString,
|
||||||
|
last_modified: Traceable<RefCell<Option<DOMString>>>,
|
||||||
pub encoding_name: Traceable<RefCell<DOMString>>,
|
pub encoding_name: Traceable<RefCell<DOMString>>,
|
||||||
pub is_html_document: bool,
|
pub is_html_document: bool,
|
||||||
url: Untraceable<Url>,
|
url: Untraceable<Url>,
|
||||||
|
@ -146,6 +148,7 @@ pub trait DocumentHelpers {
|
||||||
fn url<'a>(&'a self) -> &'a Url;
|
fn url<'a>(&'a self) -> &'a Url;
|
||||||
fn quirks_mode(&self) -> QuirksMode;
|
fn quirks_mode(&self) -> QuirksMode;
|
||||||
fn set_quirks_mode(&self, mode: QuirksMode);
|
fn set_quirks_mode(&self, mode: QuirksMode);
|
||||||
|
fn set_last_modified(&self, value: DOMString);
|
||||||
fn set_encoding_name(&self, name: DOMString);
|
fn set_encoding_name(&self, name: DOMString);
|
||||||
fn content_changed(&self);
|
fn content_changed(&self);
|
||||||
fn damage_and_reflow(&self, damage: DocumentDamageLevel);
|
fn damage_and_reflow(&self, damage: DocumentDamageLevel);
|
||||||
|
@ -168,6 +171,10 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
||||||
self.quirks_mode.deref().set(mode);
|
self.quirks_mode.deref().set(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_last_modified(&self, value: DOMString) {
|
||||||
|
*self.last_modified.deref().borrow_mut() = Some(value);
|
||||||
|
}
|
||||||
|
|
||||||
fn set_encoding_name(&self, name: DOMString) {
|
fn set_encoding_name(&self, name: DOMString) {
|
||||||
*self.encoding_name.deref().borrow_mut() = name;
|
*self.encoding_name.deref().borrow_mut() = name;
|
||||||
}
|
}
|
||||||
|
@ -278,6 +285,7 @@ impl Document {
|
||||||
NonHTMLDocument => "application/xml".to_string()
|
NonHTMLDocument => "application/xml".to_string()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
last_modified: Traceable::new(RefCell::new(None)),
|
||||||
url: Untraceable::new(url),
|
url: Untraceable::new(url),
|
||||||
// http://dom.spec.whatwg.org/#concept-document-quirks
|
// http://dom.spec.whatwg.org/#concept-document-quirks
|
||||||
quirks_mode: Untraceable::new(Cell::new(NoQuirks)),
|
quirks_mode: Untraceable::new(Cell::new(NoQuirks)),
|
||||||
|
@ -569,6 +577,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#dom-document-lastmodified
|
||||||
|
fn LastModified(&self) -> DOMString {
|
||||||
|
match *self.last_modified.borrow() {
|
||||||
|
Some(ref t) => t.clone(),
|
||||||
|
None => time::now().strftime("%m/%d/%Y %H:%M:%S"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-document-createrange
|
// http://dom.spec.whatwg.org/#dom-document-createrange
|
||||||
fn CreateRange(&self) -> Temporary<Range> {
|
fn CreateRange(&self) -> Temporary<Range> {
|
||||||
Range::new(self)
|
Range::new(self)
|
||||||
|
|
|
@ -49,6 +49,7 @@ interface Document : Node {
|
||||||
|
|
||||||
/* http://www.whatwg.org/specs/web-apps/current-work/#the-document-object */
|
/* http://www.whatwg.org/specs/web-apps/current-work/#the-document-object */
|
||||||
partial interface Document {
|
partial interface Document {
|
||||||
|
readonly attribute DOMString lastModified;
|
||||||
[SetterThrows]
|
[SetterThrows]
|
||||||
attribute DOMString title;
|
attribute DOMString title;
|
||||||
[SetterThrows]
|
[SetterThrows]
|
||||||
|
|
|
@ -33,6 +33,8 @@ use std::cell::RefCell;
|
||||||
use std::comm::{channel, Sender, Receiver};
|
use std::comm::{channel, Sender, Receiver};
|
||||||
use style::Stylesheet;
|
use style::Stylesheet;
|
||||||
use url::{Url, UrlParser};
|
use url::{Url, UrlParser};
|
||||||
|
use http::headers::HeaderEnum;
|
||||||
|
use time;
|
||||||
|
|
||||||
macro_rules! handle_element(
|
macro_rules! handle_element(
|
||||||
($document: expr,
|
($document: expr,
|
||||||
|
@ -158,6 +160,30 @@ fn js_script_listener(to_parent: Sender<HtmlDiscoveryMessage>,
|
||||||
assert!(to_parent.send_opt(HtmlDiscoveredScript(result_vec)).is_ok());
|
assert!(to_parent.send_opt(HtmlDiscoveredScript(result_vec)).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parses an RFC 2616 compliant date/time string, and returns a localized
|
||||||
|
// date/time string in a format suitable for document.lastModified.
|
||||||
|
fn parse_last_modified(timestamp: &str) -> String {
|
||||||
|
let format = "%m/%d/%Y %H:%M:%S";
|
||||||
|
|
||||||
|
// RFC 822, updated by RFC 1123
|
||||||
|
match time::strptime(timestamp, "%a, %d %b %Y %T %Z") {
|
||||||
|
Ok(t) => return t.to_local().strftime(format),
|
||||||
|
Err(_) => ()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 850, obsoleted by RFC 1036
|
||||||
|
match time::strptime(timestamp, "%A, %d-%b-%y %T %Z") {
|
||||||
|
Ok(t) => return t.to_local().strftime(format),
|
||||||
|
Err(_) => ()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ANSI C's asctime() format
|
||||||
|
match time::strptime(timestamp, "%c") {
|
||||||
|
Ok(t) => t.to_local().strftime(format),
|
||||||
|
Err(_) => String::from_str("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized
|
// Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized
|
||||||
// via atomization (issue #85).
|
// via atomization (issue #85).
|
||||||
|
|
||||||
|
@ -323,6 +349,18 @@ pub fn parse_html(page: &Page,
|
||||||
|
|
||||||
debug!("Fetched page; metadata is {:?}", load_response.metadata);
|
debug!("Fetched page; metadata is {:?}", load_response.metadata);
|
||||||
|
|
||||||
|
load_response.metadata.headers.map(|headers| {
|
||||||
|
let header = headers.iter().find(|h|
|
||||||
|
h.header_name().as_slice().to_ascii_lower() == "last-modified".to_string()
|
||||||
|
);
|
||||||
|
|
||||||
|
match header {
|
||||||
|
Some(h) => document.set_last_modified(
|
||||||
|
parse_last_modified(h.header_value().as_slice())),
|
||||||
|
None => {},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
let base_url = &load_response.metadata.final_url;
|
let base_url = &load_response.metadata.final_url;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
[document-lastModified-01.html]
|
|
||||||
type: testharness
|
|
||||||
[Date returned by lastModified is in the user\'s local time zone.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Date returned by lastModified is in the form "MM/DD/YYYY hh:mm:ss".]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[document-lastModified.html]
|
|
||||||
type: testharness
|
|
||||||
[lastModified should return the last modified date and time]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue