1// Copyright 2013 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.fileSystemProvider</code> API to create file systems, 6// that can be accessible from the file manager on Chrome OS. 7[platforms=("chromeos"), 8 implemented_in="chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h"] 9namespace fileSystemProvider { 10 // Error codes used by providing extensions in response to requests. For 11 // success, <code>OK</code> should be used. 12 enum ProviderError { 13 OK, 14 FAILED, 15 IN_USE, 16 EXISTS, 17 NOT_FOUND, 18 ACCESS_DENIED, 19 TOO_MANY_OPENED, 20 NO_MEMORY, 21 NO_SPACE, 22 NOT_A_DIRECTORY, 23 INVALID_OPERATION, 24 SECURITY, 25 ABORT, 26 NOT_A_FILE, 27 NOT_EMPTY, 28 INVALID_URL, 29 IO 30 }; 31 32 // Mode of opening a file. Used by <code>onOpenFileRequested</code>. 33 enum OpenFileMode { 34 READ, 35 WRITE 36 }; 37 38 // Represents metadata of a file or a directory. 39 dictionary EntryMetadata { 40 // True if it is a directory. 41 boolean isDirectory; 42 43 // Name of this entry (not full path name). 44 DOMString name; 45 46 // File size in bytes. 47 double size; 48 49 // The last modified time of this entry. 50 [instanceOf=Date] object modificationTime; 51 }; 52 53 // Options for the <code>mount()</code> method. 54 dictionary MountOptions { 55 DOMString fileSystemId; 56 DOMString displayName; 57 }; 58 59 // Options for the <code>unmount()</code> method. 60 dictionary UnmountOptions { 61 DOMString fileSystemId; 62 }; 63 64 // Options for the <code>onUnmountRequested()</code> event. 65 dictionary UnmountRequestedOptions { 66 DOMString fileSystemId; 67 long requestId; 68 }; 69 70 // Options for the <code>onGetMetadataRequested()</code> event. 71 dictionary GetMetadataRequestedOptions { 72 DOMString fileSystemId; 73 long requestId; 74 DOMString entryPath; 75 }; 76 77 // Options for the <code>onReadDirectoryRequested()</code> event. 78 dictionary ReadDirectoryRequestedOptions { 79 DOMString fileSystemId; 80 long requestId; 81 DOMString directoryPath; 82 }; 83 84 // Options for the <code>onOpenFileRequested()</code> event. 85 dictionary OpenFileRequestedOptions { 86 DOMString fileSystemId; 87 long requestId; 88 DOMString filePath; 89 OpenFileMode mode; 90 boolean create; 91 }; 92 93 // Options for the <code>onCloseFileRequested()</code> event. 94 dictionary CloseFileRequestedOptions { 95 DOMString fileSystemId; 96 long requestId; 97 long openRequestId; 98 }; 99 100 // Options for the <code>onReadFileRequested()</code> event. 101 dictionary ReadFileRequestedOptions { 102 DOMString fileSystemId; 103 long requestId; 104 long openRequestId; 105 double offset; 106 double length; 107 }; 108 109 // Callback to receive the result of mount() function. 110 callback MountCallback = void([nodoc, instanceOf=DOMError] object error); 111 112 // Callback to receive the result of unmount() function. 113 callback UnmountCallback = void([nodoc, instanceOf=DOMError] object error); 114 115 // Callback to be called by the providing extension in case of a success. 116 callback ProviderSuccessCallback = void(); 117 118 // Callback to be called by the providing extension in case of an error. 119 callback ProviderErrorCallback = void(ProviderError error); 120 121 // Callback to handle an error raised from the browser. 122 [nocompile] callback ErrorCallback = void([instanceOf=DOMError] object error); 123 124 // Success callback for the <code>onGetMetadataRequested</code> event. 125 callback MetadataCallback = void(EntryMetadata metadata); 126 127 // Success callback for the <code>onReadDirectoryRequested</code> event. If 128 // more entries will be returned, then <code>hasMore</code> must be true, and 129 // it has to be called again with additional entries. If no more entries are 130 // available, then <code>hasMore</code> must be set to false. 131 callback EntriesCallback = void(ResourceEntry[] entries, bool hasMore); 132 133 // Success callback for the <code>onReadFileRequested</code> event. If more 134 // data will be returned, then <code>hasMore</code> must be true, and it 135 // has to be called again with additional entries. If no more data is 136 // available, then <code>hasMore</code> must be set to false. 137 callback FileDataCallback = void(ArrayBuffer data, bool hasMore); 138 139 interface Functions { 140 // Mounts a file system with the given <code>fileSystemId</code> and <code> 141 // displayName</code>. <code>displayName</code> will be shown in the left 142 // panel of Files.app. <code>displayName</code> can contain any characters 143 // including '/', but cannot be an empty string. <code>displayName</code> 144 // should be descriptive but doesn't have to be unique. Duplicate display 145 // names are uniquified by adding suffix like "(1)" in the Files app UI. 146 // 147 // If a file system with the passed <code>fileSystemId</code> is already 148 // mounted by this extension, then <code>errorCallback</code> will be called 149 // with <code>ProviderError.EXISTS</code> value. The <code>fileSystemId 150 // </code> must not be an empty string. 151 static void mount(MountOptions options, 152 MountCallback successCallback, 153 [nocompile] ErrorCallback errorCallback); 154 155 // Unmounts a file system with the given <code>fileSystemId</code>. It 156 // should be called after <code>onUnmountRequested</code> is invoked. Also, 157 // the providing extension can decide to perform unmounting if not requested 158 // (eg. in case of lost connection, or a file error). If there is no file 159 // system with the requested id, or unmounting fails, then the 160 // <code>errorCallback</code> will be called. 161 static void unmount(UnmountOptions options, 162 UnmountCallback successCallback, 163 [nocompile] ErrorCallback errorCallback); 164 }; 165 166 interface Events { 167 // Raised when unmounting for the file system with the <code>fileSystemId 168 // </code> identifier is requested. In the response, the <code>unmount 169 // </code> API method should be called together with <code>successCallback 170 // </code>. If unmounting is not possible (eg. due to a pending operation), 171 // then <code>errorCallback</code> must be called. 172 [maxListeners=1] static void onUnmountRequested( 173 UnmountRequestedOptions options, 174 ProviderSuccessCallback successCallback, 175 ProviderErrorCallback errorCallback); 176 177 // Raised when metadata of a file or a directory at <code>entryPath</code> 178 // is requested. The metadata should be returned with the <code> 179 // successCallback</code> call. In case of an error, <code>errorCallback 180 // </code> must be called. 181 [maxListeners=1] static void onGetMetadataRequested( 182 GetMetadataRequestedOptions options, 183 MetadataCallback successCallback, 184 ProviderErrorCallback errorCallback); 185 186 // Raised when contents of a directory at <code>directoryPath</code> are 187 // requested. The results should be returned in chunks by calling the <code> 188 // successCallback</code> several times. In case of an error, <code> 189 // errorCallback</code> must be called. 190 [maxListeners=1] static void onReadDirectoryRequested( 191 ReadDirectoryRequestedOptions options, 192 EntriesCallback successCallback, 193 ProviderErrorCallback errorCallback); 194 195 // Raised when opening a file at <code>filePath</code> is requested. 196 // If <code>create</code> is set to <code>true</code> and the file does not 197 // exist, then it should be created. 198 [maxListeners=1] static void onOpenFileRequested( 199 OpenFileRequestedOptions options, 200 ProviderSuccessCallback successCallback, 201 ProviderErrorCallback errorCallback); 202 203 // Raised when opening a file previously opened with <code>openRequestId 204 // </code> is requested to be closed. 205 [maxListeners=1] static void onCloseFileRequested( 206 CloseFileRequestedOptions options, 207 ProviderSuccessCallback successCallback, 208 ProviderErrorCallback errorCallback); 209 210 // Raised when contents of a file opened previously with <code>openRequestId 211 // </code>. The results should be returned in chunks by calling <code> 212 // successCallback</code> several times. In case of an error, <code> 213 // errorCallback</code> must be called. 214 [maxListeners=1] static void onReadFileRequested( 215 ReadFileRequestedOptions options, 216 FileDataCallback successCallback, 217 ProviderErrorCallback errorCallback); 218 }; 219}; 220 221