aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/file.rs
diff options
context:
space:
mode:
authorGregory Terzian <gterzian@users.noreply.github.com>2019-09-01 03:18:42 +0800
committerGregory Terzian <gterzian@users.noreply.github.com>2019-12-11 22:46:50 +0800
commit6e8a85482c2068d4dbccb992954271f725570f91 (patch)
treeb30f6d82a018df0b196fa4d47d3b6667d708313e /components/script/dom/file.rs
parent7aa68c8fe7ca0865a7323ab1e5b9526efa588ca2 (diff)
downloadservo-6e8a85482c2068d4dbccb992954271f725570f91.tar.gz
servo-6e8a85482c2068d4dbccb992954271f725570f91.zip
re-structure blob, structured serialization
Diffstat (limited to 'components/script/dom/file.rs')
-rw-r--r--components/script/dom/file.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs
index 87ae3336fec..ed4753a58b3 100644
--- a/components/script/dom/file.rs
+++ b/components/script/dom/file.rs
@@ -10,11 +10,12 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
-use crate::dom::blob::{blob_parts_to_bytes, Blob, BlobImpl};
+use crate::dom::blob::{blob_parts_to_bytes, normalize_type_string, Blob};
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use net_traits::filemanager_thread::SelectedFile;
+use script_traits::serializable::BlobImpl;
#[dom_struct]
pub struct File {
@@ -25,14 +26,9 @@ pub struct File {
impl File {
#[allow(unrooted_must_root)]
- fn new_inherited(
- blob_impl: BlobImpl,
- name: DOMString,
- modified: Option<i64>,
- type_string: &str,
- ) -> File {
+ fn new_inherited(blob_impl: &BlobImpl, name: DOMString, modified: Option<i64>) -> File {
File {
- blob: Blob::new_inherited(blob_impl, type_string.to_owned()),
+ blob: Blob::new_inherited(blob_impl),
name: name,
// https://w3c.github.io/FileAPI/#dfn-lastModified
modified: match modified {
@@ -51,13 +47,14 @@ impl File {
blob_impl: BlobImpl,
name: DOMString,
modified: Option<i64>,
- typeString: &str,
) -> DomRoot<File> {
- reflect_dom_object(
- Box::new(File::new_inherited(blob_impl, name, modified, typeString)),
+ let file = reflect_dom_object(
+ Box::new(File::new_inherited(&blob_impl, name, modified)),
global,
FileBinding::Wrap,
- )
+ );
+ global.track_file(&file, blob_impl);
+ file
}
// Construct from selected file message from file manager thread
@@ -71,10 +68,14 @@ impl File {
File::new(
window.upcast(),
- BlobImpl::new_from_file(selected.id, selected.filename, selected.size),
+ BlobImpl::new_from_file(
+ selected.id,
+ selected.filename,
+ selected.size,
+ normalize_type_string(&selected.type_string.to_string()),
+ ),
name,
Some(selected.modified as i64),
- &selected.type_string,
)
}
@@ -91,18 +92,17 @@ impl File {
};
let ref blobPropertyBag = filePropertyBag.parent;
- let ref typeString = blobPropertyBag.type_;
let modified = filePropertyBag.lastModified;
// NOTE: Following behaviour might be removed in future,
// see https://github.com/w3c/FileAPI/issues/41
let replaced_filename = DOMString::from_string(filename.replace("/", ":"));
+ let type_string = normalize_type_string(&blobPropertyBag.type_.to_string());
Ok(File::new(
global,
- BlobImpl::new_from_bytes(bytes),
+ BlobImpl::new_from_bytes(bytes, type_string),
replaced_filename,
modified,
- typeString,
))
}