script/dom/filesystem/
filesystemdirectoryentry.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::cell::DomRefCell;
8use script_bindings::reflector::reflect_dom_object;
9
10use crate::dom::bindings::callback::RootedCallback;
11use crate::dom::bindings::codegen::Bindings::FileSystemDirectoryEntryBinding::{
12 FileSystemDirectoryEntryMethods, FileSystemFlags,
13};
14use crate::dom::bindings::codegen::Bindings::FileSystemEntryBinding::{
15 ErrorCallback, FileSystemEntryCallback,
16};
17use crate::dom::bindings::reflector::DomGlobal;
18use crate::dom::bindings::root::{Dom, DomRoot};
19use crate::dom::bindings::str::USVString;
20use crate::dom::filesystem::FileSystem;
21use crate::dom::filesystemdirectoryreader::FileSystemDirectoryReader;
22use crate::dom::filesystementry::FileSystemEntry;
23use crate::dom::globalscope::GlobalScope;
24
25#[dom_struct]
26pub(crate) struct FileSystemDirectoryEntry {
27 filesystementry: FileSystemEntry,
28 children: DomRefCell<Vec<Dom<FileSystemEntry>>>,
29}
30
31impl FileSystemDirectoryEntry {
32 fn new_inherited(name: USVString, full_path: USVString) -> FileSystemDirectoryEntry {
33 FileSystemDirectoryEntry {
34 filesystementry: FileSystemEntry::new_inherited(name, full_path, false),
35 children: DomRefCell::new(Vec::new()),
36 }
37 }
38
39 pub(crate) fn new(
40 cx: &mut JSContext,
41 global: &GlobalScope,
42 name: USVString,
43 full_path: USVString,
44 ) -> DomRoot<FileSystemDirectoryEntry> {
45 reflect_dom_object(
46 cx,
47 Box::new(FileSystemDirectoryEntry::new_inherited(name, full_path)),
48 global,
49 )
50 }
51
52 pub(crate) fn set_filesystem(&self, fs: &FileSystem) {
53 self.filesystementry.set_filesystem(fs);
54 }
55
56 pub(crate) fn push_child(&self, child: &FileSystemEntry) {
57 self.children.borrow_mut().push(Dom::from_ref(child));
58 }
59
60 pub(crate) fn children(&self) -> Vec<DomRoot<FileSystemEntry>> {
61 self.children
62 .borrow()
63 .iter()
64 .map(|child| DomRoot::from_ref(&**child))
65 .collect()
66 }
67}
68
69impl FileSystemDirectoryEntryMethods<crate::DomTypeHolder> for FileSystemDirectoryEntry {
70 fn CreateReader(&self, cx: &mut JSContext) -> DomRoot<FileSystemDirectoryReader> {
72 FileSystemDirectoryReader::new(cx, &self.global(), self)
73 }
74
75 fn GetFile(
77 &self,
78 _path: Option<Option<USVString>>,
79 _options: &FileSystemFlags,
80 _success_callback: Option<RootedCallback<FileSystemEntryCallback>>,
81 _error_callback: Option<RootedCallback<ErrorCallback>>,
82 ) {
83 }
85
86 fn GetDirectory(
88 &self,
89 _path: Option<Option<USVString>>,
90 _options: &FileSystemFlags,
91 _success_callback: Option<RootedCallback<FileSystemEntryCallback>>,
92 _error_callback: Option<RootedCallback<ErrorCallback>>,
93 ) {
94 }
96}