diff options
author | Zhen Zhang <izgzhen@gmail.com> | 2016-05-17 12:52:35 +0800 |
---|---|---|
committer | Zhen Zhang <izgzhen@gmail.com> | 2016-06-01 09:47:07 +0800 |
commit | 43ad4ba5857dbcd1a31aaf7e441c5cfe4fe1b84f (patch) | |
tree | ef221985dfe1d3ed54e7a2af31903d8b1dbf40e4 /components/script/dom/file.rs | |
parent | d53507f747f7122dc520f5e4a374ee1ad955aa5d (diff) | |
download | servo-43ad4ba5857dbcd1a31aaf7e441c5cfe4fe1b84f.tar.gz servo-43ad4ba5857dbcd1a31aaf7e441c5cfe4fe1b84f.zip |
Add file backend support for Blob and related
Changes include:
- Add BlobImpl to Blob, and related caching mechanism
- Expose ResourceThreads to document_loader, workerglobalscope, worker, and global
- Fix encode_multipart_form_data
- Other small fixes to accommodate the above changes
Diffstat (limited to 'components/script/dom/file.rs')
-rw-r--r-- | components/script/dom/file.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs index e8cdf89de54..c0ddd74233f 100644 --- a/components/script/dom/file.rs +++ b/components/script/dom/file.rs @@ -5,15 +5,14 @@ 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::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; -use dom::blob::{Blob, DataSlice, blob_parts_to_bytes}; +use dom::blob::{Blob, BlobImpl, DataSlice, blob_parts_to_bytes}; use dom::window::Window; use net_traits::filemanager_thread::SelectedFile; -use std::sync::Arc; use time; #[dom_struct] @@ -24,10 +23,10 @@ pub struct File { } impl File { - fn new_inherited(slice: DataSlice, name: DOMString, + fn new_inherited(blob_impl: BlobImpl, name: DOMString, modified: Option<i64>, typeString: &str) -> File { File { - blob: Blob::new_inherited(slice, typeString), + blob: Blob::new_inherited(blob_impl, typeString), name: name, // https://w3c.github.io/FileAPI/#dfn-lastModified modified: match modified { @@ -40,9 +39,9 @@ impl File { } } - pub fn new(global: GlobalRef, slice: DataSlice, + pub fn new(global: GlobalRef, blob_impl: BlobImpl, name: DOMString, modified: Option<i64>, typeString: &str) -> Root<File> { - reflect_dom_object(box File::new_inherited(slice, name, modified, typeString), + reflect_dom_object(box File::new_inherited(blob_impl, name, modified, typeString), global, FileBinding::Wrap) } @@ -51,11 +50,9 @@ impl File { pub fn new_from_selected(window: &Window, selected: SelectedFile) -> Root<File> { let name = DOMString::from(selected.filename.to_str().expect("File name encoding error")); - let slice = DataSlice::empty(); - let global = GlobalRef::Window(window); - File::new(global, slice, name, Some(selected.modified as i64), "") + File::new(global, BlobImpl::new_from_file(selected.id), name, Some(selected.modified as i64), "") } // https://w3c.github.io/FileAPI/#file-constructor @@ -64,14 +61,17 @@ impl File { filename: DOMString, filePropertyBag: &FileBinding::FilePropertyBag) -> Fallible<Root<File>> { - let bytes: Vec<u8> = blob_parts_to_bytes(fileBits); + let bytes: Vec<u8> = match blob_parts_to_bytes(fileBits) { + Ok(bytes) => bytes, + Err(_) => return Err(Error::InvalidCharacter), + }; let ref blobPropertyBag = filePropertyBag.parent; let typeString = blobPropertyBag.get_typestring(); - let slice = DataSlice::new(Arc::new(bytes), None, None); + let slice = DataSlice::from_bytes(bytes); let modified = filePropertyBag.lastModified; - Ok(File::new(global, slice, filename, modified, &typeString)) + Ok(File::new(global, BlobImpl::new_from_slice(slice), filename, modified, &typeString)) } pub fn name(&self) -> &DOMString { |