aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/blob.rs
blob: 71f83dffd9633bbbd89ed4e366d6b82e7798bbaa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::InheritTypes::FileDerived;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Temporary;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::Fallible;
use dom::bindings::codegen::Bindings::BlobBinding;

#[jstraceable]
pub enum BlobType {
    BlobTypeId,
    FileTypeId
}

#[jstraceable]
#[must_root]
pub struct Blob {
    reflector_: Reflector,
    type_: BlobType
}

impl Blob {
    pub fn new_inherited() -> Blob {
        Blob {
            reflector_: Reflector::new(),
            type_: BlobTypeId
        }
    }

    pub fn new(global: &GlobalRef) -> Temporary<Blob> {
        reflect_dom_object(box Blob::new_inherited(),
                           global,
                           BlobBinding::Wrap)
    }

    pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<Blob>> {
        Ok(Blob::new(global))
    }
}

impl Reflectable for Blob {
    fn reflector<'a>(&'a self) -> &'a Reflector {
        &self.reflector_
    }
}

impl FileDerived for Blob {
    fn is_file(&self) -> bool {
        match self.type_ {
            FileTypeId => true,
            _ => false
        }
    }
}