1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Use the <code>chrome.fileSystem</code> API to create, read, navigate,
6 // and write to the user's local file system. With this API, Chrome Apps can
7 // read and write to a user-selected location. For example, a text editor app
8 // can use the API to read and write local documents. All failures are notified
9 // via chrome.runtime.lastError.
10 namespace fileSystem
{
11 dictionary AcceptOption
{
12 // This is the optional text description for this option. If not present,
13 // a description will be automatically generated; typically containing an
14 // expanded list of valid extensions (e.g. "text/html" may expand to
16 DOMString? description
;
18 // Mime-types to accept, e.g. "image/jpeg" or "audio/*". One of mimeTypes or
19 // extensions must contain at least one valid element.
20 DOMString
[]? mimeTypes
;
22 // Extensions to accept, e.g. "jpg", "gif", "crx".
23 DOMString
[]? extensions
;
26 enum ChooseEntryType
{
28 // Prompts the user to open an existing file and returns a FileEntry on
29 // success. From Chrome 31 onwards, the FileEntry will be writable if the
30 // application has the 'write' permission under 'fileSystem'; otherwise, the
31 // FileEntry will be read-only.
34 // Prompts the user to open an existing file and returns a writable
35 // FileEntry on success. Calls using this type will fail with a runtime
36 // error if the application doesn't have the 'write' permission under
40 // Prompts the user to open an existing file or a new file and returns a
41 // writable FileEntry on success. Calls using this type will fail with a
42 // runtime error if the application doesn't have the 'write' permission
43 // under 'fileSystem'.
46 // Prompts the user to open a directory and returns a DirectoryEntry on
47 // success. Calls using this type will fail with a runtime error if the
48 // application doesn't have the 'directory' permission under 'fileSystem'.
49 // If the application has the 'write' permission under 'fileSystem', the
50 // returned DirectoryEntry will be writable; otherwise it will be read-only.
55 // Type of a change happened to a child entry within a tracked directory.
56 enum ChildChangeType
{
62 dictionary ChooseEntryOptions
{
63 // Type of the prompt to show. The default is 'openFile'.
64 ChooseEntryType? type
;
66 // The suggested file name that will be presented to the user as the
67 // default name to read or write. This is optional.
68 DOMString? suggestedName
;
70 // The optional list of accept options for this file opener. Each option
71 // will be presented as a unique group to the end-user.
72 AcceptOption
[]? accepts
;
74 // Whether to accept all file types, in addition to the options specified
75 // in the accepts argument. The default is true. If the accepts field is
76 // unset or contains no valid entries, this will always be reset to true.
77 boolean? acceptsAllTypes
;
79 // Whether to accept multiple files. This is only supported for openFile and
80 // openWritableFile. The callback to chooseEntry will be called with a list
81 // of entries if this is set to true. Otherwise it will be called with a
83 boolean? acceptsMultiple
;
86 dictionary RequestFileSystemOptions
{
87 // The ID of the requested volume.
90 // Whether the requested file system should be writeable, or read-only.
91 // By default read-only.
95 // Represents a mounted volume, which can be accessed via <code>chrome.
96 // fileSystem.requestFileSystem</code>.
102 // Change to an entry within a tracked directory.
103 [nodoc
] dictionary ChildChange
{
104 [instanceOf
=Entry] object entry;
105 ChildChangeType type
;
108 // Event notifying about an inserted or a removed volume from the system.
109 dictionary VolumeListChangedEvent
{
113 // Event notifying about a change in a file or a directory, including its
115 [nodoc
] dictionary EntryChangedEvent
{
117 [instanceOf
=Entry] object target
;
119 // List of changed entries within the tracked directory in order they
120 // happened. May not be available for some types of file systems.
121 ChildChange
[]? childChanges
;
124 // Event notifying about a tracked file or a directory being removed.
125 [nodoc
] dictionary EntryRemovedEvent
{
126 [instanceOf
=Entry] object target
;
129 callback GetDisplayPathCallback
= void (DOMString displayPath
);
130 callback EntryCallback
= void ([instanceOf
=Entry] object entry);
131 callback EntriesCallback
= void (
132 [instanceOf
=Entry] optional object entry,
133 [instanceOf
=FileEntry
] optional object[] fileEntries
);
134 callback IsWritableCallback
= void (boolean isWritable
);
135 callback IsRestorableCallback
= void (boolean isRestorable
);
136 [nodoc
] callback GetObservedEntriesCallback
= void (
137 [instanceOf
=Entry] object[] entries
);
138 callback RequestFileSystemCallback
= void(
139 [instanceOf
=FileSystem
] optional object fileSystem
);
140 callback GetVolumeListCallback
= void(optional Volume
[] volumes
);
142 interface Functions
{
143 // Get the display path of an Entry object. The display path is based on
144 // the full path of the file or directory on the local file system, but may
145 // be made more readable for display purposes.
146 static
void getDisplayPath
([instanceOf
=Entry] object entry,
147 GetDisplayPathCallback
callback);
149 // Get a writable Entry from another Entry. This call will fail with a
150 // runtime error if the application does not have the 'write' permission
151 // under 'fileSystem'. If entry is a DirectoryEntry, this call will fail if
152 // the application does not have the 'directory' permission under
154 static
void getWritableEntry
([instanceOf
=Entry] object entry,
155 EntryCallback
callback);
157 // Gets whether this Entry is writable or not.
158 static
void isWritableEntry
([instanceOf
=Entry] object entry,
159 IsWritableCallback
callback);
161 // Ask the user to choose a file or directory.
162 static
void chooseEntry
(optional ChooseEntryOptions options
,
163 EntriesCallback
callback);
165 // Returns the file entry with the given id if it can be restored. This call
166 // will fail with a runtime error otherwise.
167 static
void restoreEntry
(DOMString
id, EntryCallback
callback);
169 // Returns whether the app has permission to restore the entry with the
171 static
void isRestorable
(DOMString
id, IsRestorableCallback
callback);
173 // Returns an id that can be passed to restoreEntry to regain access to a
174 // given file entry. Only the 500 most recently used entries are retained,
175 // where calls to retainEntry and restoreEntry count as use. If the app has
176 // the 'retainEntries' permission under 'fileSystem', entries are retained
177 // indefinitely. Otherwise, entries are retained only while the app is
178 // running and across restarts.
179 static DOMString retainEntry
([instanceOf
=Entry] object entry);
181 // Requests access to a file system for a volume represented by <code>
182 // options.volumeId</code>. If <code>options.writable</code> is set to true,
183 // then the file system will be writable. Otherwise, it will be read-only.
184 // The <code>writable</code> option requires the <code>
185 // "fileSystem": {"write"}</code> permission in the manifest. Available to
186 // kiosk apps running in kiosk session only. For manual-launch kiosk mode, a
187 // confirmation dialog will be shown on top of the active app window.
188 // In case of an error, <code>fileSystem</code> will be undefined, and
189 // <code>chrome.runtime.lastError</code> will be set.
190 static
void requestFileSystem
(RequestFileSystemOptions options
,
191 RequestFileSystemCallback
callback);
193 // Returns a list of volumes available for <code>requestFileSystem()</code>.
194 // The <code>"fileSystem": {"requestFileSystem"}</code> manifest permission
195 // is required. Available to kiosk apps running in the kiosk session only.
196 // In case of an error, <code>volumes</code> will be undefined, and <code>
197 // chrome.runtime.lastError</code> will be set.
198 static
void getVolumeList
(GetVolumeListCallback
callback);
200 // Observes a directory entry. Emits an event if the tracked directory is
201 // changed (including the list of files on it), or removed. If <code>
202 // recursive</code> is set to true, then also all accessible subdirectories
203 // will be tracked. Observers are automatically removed once the extension
204 // is closed or suspended, unless <code>entry</code> is retained using
205 // <code>chrome.fileSystem.retainEntry</code>.
207 // In such case of retained entries, the observer stays active across
208 // restarts until <code>unobserveEntry</code> is explicitly called. Note,
209 // that once the <code>entry</code> is not retained anymore, the observer
210 // will be removed automatically. Observed entries are also automatically
211 // restored when either <code>getObservers</code> is called, or an observing
212 // event for it is invoked.
213 [nodoc
] static
void observeDirectory
(
214 [instanceOf
=DirectoryEntry
] object entry,
215 optional boolean recursive
);
217 // Unobserves a previously observed either a file or a directory.
218 [nodoc
] static
void unobserveEntry
([instanceOf
=Entry] object entry);
220 // Lists all observed entries.
221 [nodoc
] static
void getObservedEntries
(GetObservedEntriesCallback
callback);
225 // Called when a list of available volumes is changed.
226 static
void onVolumeListChanged
(VolumeListChangedEvent event
);
228 // Called when an observed entry is changed.
229 [nodoc
] static
void onEntryChanged
(EntryChangedEvent event
);
231 // Called when an observed entry is removed.
232 [nodoc
] static
void onEntryRemoved
(EntryRemovedEvent event
);