aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/file.rs
diff options
context:
space:
mode:
authorZhen Zhang <izgzhen@gmail.com>2016-05-10 20:23:17 +0800
committerZhen Zhang <izgzhen@gmail.com>2016-05-11 22:35:21 +0800
commit87fec3e026484d84b34cfa989dcbc6173bdcc161 (patch)
tree6808ddc2a491a29369696dc2d335ddfee38bfd3e /components/script/dom/file.rs
parentf43009333fb919421e584e38af3e8aaa0ff4fd1e (diff)
downloadservo-87fec3e026484d84b34cfa989dcbc6173bdcc161.tar.gz
servo-87fec3e026484d84b34cfa989dcbc6173bdcc161.zip
Implement missing interfaces of File DOM object
Diffstat (limited to 'components/script/dom/file.rs')
-rw-r--r--components/script/dom/file.rs51
1 files changed, 42 insertions, 9 deletions
diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs
index 598537cbe00..9667182671a 100644
--- a/components/script/dom/file.rs
+++ b/components/script/dom/file.rs
@@ -4,45 +4,78 @@
use dom::bindings::codegen::Bindings::FileBinding;
use dom::bindings::codegen::Bindings::FileBinding::FileMethods;
+use dom::bindings::codegen::UnionTypes::BlobOrString;
+use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
-use dom::blob::Blob;
+use dom::blob::{Blob, DataSlice, blob_parts_to_bytes};
use std::sync::Arc;
+use time;
use util::str::DOMString;
#[dom_struct]
pub struct File {
blob: Blob,
name: DOMString,
+ modified: i64,
}
impl File {
- fn new_inherited(file_bits: &Blob, name: DOMString) -> File {
- // TODO: FilePropertyBag
- let mut bytes = Vec::new();
- bytes.extend_from_slice(file_bits.get_data().get_all_bytes().as_slice());
-
+ fn new_inherited(slice: DataSlice, name: DOMString,
+ modified: Option<i64>, typeString: &str) -> File {
File {
- blob: Blob::new_inherited(Arc::new(bytes), None, None, ""),
+ blob: Blob::new_inherited(slice, typeString),
name: name,
+ // https://w3c.github.io/FileAPI/#dfn-lastModified
+ modified: match modified {
+ Some(m) => m,
+ None => {
+ let time = time::get_time();
+ time.sec * 1000 + (time.nsec / 1000000) as i64
+ }
+ },
}
}
- pub fn new(global: GlobalRef, file_bits: &Blob, name: DOMString) -> Root<File> {
- reflect_dom_object(box File::new_inherited(file_bits, name),
+ pub fn new(global: GlobalRef, slice: DataSlice,
+ name: DOMString, modified: Option<i64>, typeString: &str) -> Root<File> {
+ reflect_dom_object(box File::new_inherited(slice, name, modified, typeString),
global,
FileBinding::Wrap)
}
+ // https://w3c.github.io/FileAPI/#file-constructor
+ pub fn Constructor(global: GlobalRef,
+ fileBits: Vec<BlobOrString>,
+ filename: DOMString,
+ filePropertyBag: &FileBinding::FilePropertyBag)
+ -> Fallible<Root<File>> {
+ let bytes: Vec<u8> = blob_parts_to_bytes(fileBits);
+
+ let ref blobPropertyBag = filePropertyBag.parent;
+ let typeString = blobPropertyBag.get_typestring();
+
+ let slice = DataSlice::new(Arc::new(bytes), None, None);
+ let modified = filePropertyBag.lastModified;
+ Ok(File::new(global, slice, filename, modified, &typeString))
+ }
+
pub fn name(&self) -> &DOMString {
&self.name
}
+
}
impl FileMethods for File {
+
// https://w3c.github.io/FileAPI/#dfn-name
fn Name(&self) -> DOMString {
self.name.clone()
}
+
+ // https://w3c.github.io/FileAPI/#dfn-lastModified
+ fn LastModified(&self) -> i64 {
+ self.modified
+ }
}