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. 4 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 15 // "*.html, *.htm"). 16 DOMString? description; 17 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; 21 22 // Extensions to accept, e.g. "jpg", "gif", "crx". 23 DOMString[]? extensions; 24 }; 25 26 enum ChooseEntryType { 27 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. 32 openFile, 33 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 37 // 'fileSystem'. 38 openWritableFile, 39 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'. 44 saveFile, 45 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. 51 // New in Chrome 31. 52 openDirectory 53 }; 54 55 // Type of a change happened to a child entry within a tracked directory. 56 enum ChildChangeType { 57 created, 58 removed, 59 changed 60 }; 61 62 dictionary ChooseEntryOptions { 63 // Type of the prompt to show. The default is 'openFile'. 64 ChooseEntryType? type; 65 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; 69 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; 73 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; 78 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 82 // single Entry. 83 boolean? acceptsMultiple; 84 }; 85 86 // Change to an entry within a tracked directory. 87 dictionary ChildChange { 88 [instanceOf=Entry] object entry; 89 ChildChangeType type; 90 }; 91 92 // Event notifying about a change in a file or a directory, including its 93 // contents. 94 dictionary EntryChangedEvent { 95 // Tracked entry. 96 [instanceOf=Entry] object target; 97 98 // List of changed entries within the tracked directory in order they 99 // happened. May not be available for some types of file systems. 100 ChildChange[]? childChanges; 101 }; 102 103 // Event notifying about a tracked file or a directory being removed. 104 dictionary EntryRemovedEvent { 105 [instanceOf=Entry] object target; 106 }; 107 108 callback GetDisplayPathCallback = void (DOMString displayPath); 109 callback EntryCallback = void ([instanceOf=Entry] object entry); 110 callback EntriesCallback = void ( 111 [instanceOf=Entry] optional object entry, 112 [instanceOf=FileEntry] optional object[] fileEntries); 113 callback IsWritableCallback = void (boolean isWritable); 114 callback IsRestorableCallback = void (boolean isRestorable); 115 callback GetObservedEntriesCallback = void ( 116 [instanceOf=Entry] object[] entries); 117 118 interface Functions { 119 // Get the display path of an Entry object. The display path is based on 120 // the full path of the file or directory on the local file system, but may 121 // be made more readable for display purposes. 122 static void getDisplayPath([instanceOf=Entry] object entry, 123 GetDisplayPathCallback callback); 124 125 // Get a writable Entry from another Entry. This call will fail with a 126 // runtime error if the application does not have the 'write' permission 127 // under 'fileSystem'. If entry is a DirectoryEntry, this call will fail if 128 // the application does not have the 'directory' permission under 129 // 'fileSystem'. 130 static void getWritableEntry([instanceOf=Entry] object entry, 131 EntryCallback callback); 132 133 // Gets whether this Entry is writable or not. 134 static void isWritableEntry([instanceOf=Entry] object entry, 135 IsWritableCallback callback); 136 137 // Ask the user to choose a file or directory. 138 static void chooseEntry(optional ChooseEntryOptions options, 139 EntriesCallback callback); 140 141 // Returns the file entry with the given id if it can be restored. This call 142 // will fail with a runtime error otherwise. 143 static void restoreEntry(DOMString id, EntryCallback callback); 144 145 // Returns whether the app has permission to restore the entry with the 146 // given id. 147 static void isRestorable(DOMString id, IsRestorableCallback callback); 148 149 // Returns an id that can be passed to restoreEntry to regain access to a 150 // given file entry. Only the 500 most recently used entries are retained, 151 // where calls to retainEntry and restoreEntry count as use. If the app has 152 // the 'retainEntries' permission under 'fileSystem', entries are retained 153 // indefinitely. Otherwise, entries are retained only while the app is 154 // running and across restarts. 155 static DOMString retainEntry([instanceOf=Entry] object entry); 156 157 // Observes a directory entry. Emits an event if the tracked directory is 158 // changed (including the list of files on it), or removed. If <code> 159 // recursive</code> is set to true, then also all accessible subdirectories 160 // will be tracked. Observers are automatically removed once the extension 161 // is closed or suspended, unless <code>entry</code> is retained using 162 // <code>chrome.fileSystem.retainEntry</code>. 163 // 164 // In such case of retained entries, the observer stays active across 165 // restarts until <code>unobserveEntry</code> is explicitly called. Note, 166 // that once the <code>entry</code> is not retained anymore, the observer 167 // will be removed automatically. Observed entries are also automatically 168 // restored when either <code>getObservers</code> is called, or an observing 169 // event for it is invoked. 170 [nodoc] static void observeDirectory( 171 [instanceOf=DirectoryEntry] object entry, 172 optional boolean recursive); 173 174 // Unobserves a previously observed either a file or a directory. 175 [nodoc] static void unobserveEntry([instanceOf=Entry] object entry); 176 177 // Lists all observed entries. 178 [nodoc] static void getObservedEntries(GetObservedEntriesCallback callback); 179 }; 180 181 interface Events { 182 // Called when an observed entry is changed. 183 [nodoc] static void onEntryChanged(EntryChangedEvent event); 184 185 // Called when an observed entry is removed. 186 [nodoc] static void onEntryRemoved(EntryRemovedEvent event); 187 }; 188 }; 189