Add python coverage module to third_party
[chromium-blink-merge.git] / chrome / common / extensions / api / file_system_provider.idl
blob3be685234ea453ee73d38c46509baa1458b99e0e
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.
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 [implemented_in="chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h"]
8 namespace fileSystemProvider {
9 // Error codes used by providing extensions in response to requests as well
10 // as in case of errors when calling methods of the API. For success, <code>
11 // OK</code> must 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,
32 // Mode of opening a file. Used by <code>onOpenFileRequested</code>.
33 enum OpenFileMode {
34 READ,
35 WRITE
38 // Type of a change detected on the observed directory.
39 enum ChangeType {
40 CHANGED,
41 DELETED
44 // Represents metadata of a file or a directory.
45 dictionary EntryMetadata {
46 // True if it is a directory.
47 boolean isDirectory;
49 // Name of this entry (not full path name).
50 DOMString name;
52 // File size in bytes.
53 double size;
55 // The last modified time of this entry.
56 [instanceOf=Date] object modificationTime;
58 // Mime type for the entry.
59 DOMString? mimeType;
61 // Thumbnail image as a data URI in either PNG, JPEG or WEBP format, at most
62 // 32 KB in size. Optional, but can be provided only when explicitly
63 // requested by the <code>onGetMetadataRequested</code> event.
64 DOMString? thumbnail;
67 // Represents a watcher.
68 dictionary Watcher {
69 // The path of the entry being observed.
70 DOMString entryPath;
72 // Whether watching should include all child entries recursively. It can be
73 // true for directories only.
74 boolean recursive;
76 // Tag used by the last notification for the watcher.
77 DOMString? lastTag;
80 // Represents a mounted file system.
81 dictionary FileSystemInfo {
82 // The identifier of the file system.
83 DOMString fileSystemId;
85 // A human-readable name for the file system.
86 DOMString displayName;
88 // Whether the file system supports operations which may change contents
89 // of the file system (such as creating, deleting or writing to files).
90 boolean writable;
92 // Whether the file system supports the <code>tag</code> field for observing
93 // directories.
94 [nodoc] boolean? supportsNotifyTag;
96 // List of watchers.
97 [nodoc] Watcher[] watchers;
100 // Options for the <code>mount()</code> method.
101 dictionary MountOptions {
102 // The string indentifier of the file system. Must be unique per each
103 // extension.
104 DOMString fileSystemId;
106 // A human-readable name for the file system.
107 DOMString displayName;
109 // Whether the file system supports operations which may change contents
110 // of the file system (such as creating, deleting or writing to files).
111 boolean? writable;
113 // Whether the file system supports the <code>tag</code> field for observed
114 // directories. Required in order to enable the internal cache.
115 [nodoc] boolean? supportsNotifyTag;
118 // Options for the <code>unmount()</code> method.
119 dictionary UnmountOptions {
120 // The identifier of the file system to be unmounted.
121 DOMString fileSystemId;
124 // Options for the <code>onUnmountRequested()</code> event.
125 dictionary UnmountRequestedOptions {
126 // The identifier of the file system to be unmounted.
127 DOMString fileSystemId;
128 long requestId;
131 // Options for the <code>onGetMetadataRequested()</code> event.
132 dictionary GetMetadataRequestedOptions {
133 // The identifier of the file system related to this operation.
134 DOMString fileSystemId;
136 // The unique identifier of this request.
137 long requestId;
139 // The path of the entry to fetch metadata about.
140 DOMString entryPath;
142 // Set to <code>true</code> if the thumbnail is requested.
143 boolean thumbnail;
146 // Options for the <code>onReadDirectoryRequested()</code> event.
147 dictionary ReadDirectoryRequestedOptions {
148 // The identifier of the file system related to this operation.
149 DOMString fileSystemId;
151 // The unique identifier of this request.
152 long requestId;
154 // The path of the directory which contents are requested.
155 DOMString directoryPath;
158 // Options for the <code>onOpenFileRequested()</code> event.
159 dictionary OpenFileRequestedOptions {
160 // The identifier of the file system related to this operation.
161 DOMString fileSystemId;
163 // A request ID which will be used by consecutive read/write and close
164 // requests.
165 long requestId;
167 // The path of the file to be opened.
168 DOMString filePath;
170 // Whether the file will be used for reading or writing.
171 OpenFileMode mode;
174 // Options for the <code>onCloseFileRequested()</code> event.
175 dictionary CloseFileRequestedOptions {
176 // The identifier of the file system related to this operation.
177 DOMString fileSystemId;
179 // The unique identifier of this request.
180 long requestId;
182 // A request ID used to open the file.
183 long openRequestId;
186 // Options for the <code>onReadFileRequested()</code> event.
187 dictionary ReadFileRequestedOptions {
188 // The identifier of the file system related to this operation.
189 DOMString fileSystemId;
191 // The unique identifier of this request.
192 long requestId;
194 // A request ID used to open the file.
195 long openRequestId;
197 // Position in the file (in bytes) to start reading from.
198 double offset;
200 // Number of bytes to be returned.
201 double length;
204 // Options for the <code>onCreateDirectoryRequested()</code> event.
205 dictionary CreateDirectoryRequestedOptions {
206 // The identifier of the file system related to this operation.
207 DOMString fileSystemId;
209 // The unique identifier of this request.
210 long requestId;
212 // The path of the directory to be created.
213 DOMString directoryPath;
215 // Whether the operation is recursive (for directories only).
216 boolean recursive;
219 // Options for the <code>onDeleteEntryRequested()</code> event.
220 dictionary DeleteEntryRequestedOptions {
221 // The identifier of the file system related to this operation.
222 DOMString fileSystemId;
224 // The unique identifier of this request.
225 long requestId;
227 // The path of the entry to be deleted.
228 DOMString entryPath;
230 // Whether the operation is recursive (for directories only).
231 boolean recursive;
234 // Options for the <code>onCreateFileRequested()</code> event.
235 dictionary CreateFileRequestedOptions {
236 // The identifier of the file system related to this operation.
237 DOMString fileSystemId;
239 // The unique identifier of this request.
240 long requestId;
242 // The path of the file to be created.
243 DOMString filePath;
246 // Options for the <code>onCopyEntryRequested()</code> event.
247 dictionary CopyEntryRequestedOptions {
248 // The identifier of the file system related to this operation.
249 DOMString fileSystemId;
251 // The unique identifier of this request.
252 long requestId;
254 // The source path of the entry to be copied.
255 DOMString sourcePath;
257 // The destination path for the copy operation.
258 DOMString targetPath;
261 // Options for the <code>onMoveEntryRequested()</code> event.
262 dictionary MoveEntryRequestedOptions {
263 // The identifier of the file system related to this operation.
264 DOMString fileSystemId;
266 // The unique identifier of this request.
267 long requestId;
269 // The source path of the entry to be moved into a new place.
270 DOMString sourcePath;
272 // The destination path for the copy operation.
273 DOMString targetPath;
276 // Options for the <code>onTruncateRequested()</code> event.
277 dictionary TruncateRequestedOptions {
278 // The identifier of the file system related to this operation.
279 DOMString fileSystemId;
281 // The unique identifier of this request.
282 long requestId;
284 // The path of the file to be truncated.
285 DOMString filePath;
287 // Number of bytes to be retained after the operation completes.
288 double length;
291 // Options for the <code>onWriteFileRequested()</code> event.
292 dictionary WriteFileRequestedOptions {
293 // The identifier of the file system related to this operation.
294 DOMString fileSystemId;
296 // The unique identifier of this request.
297 long requestId;
299 // A request ID used to open the file.
300 long openRequestId;
302 // Position in the file (in bytes) to start writing the bytes from.
303 double offset;
305 // Buffer of bytes to be written to the file.
306 ArrayBuffer data;
309 // Options for the <code>onAbortRequested()</code> event.
310 dictionary AbortRequestedOptions {
311 // The identifier of the file system related to this operation.
312 DOMString fileSystemId;
314 // The unique identifier of this request.
315 long requestId;
317 // An ID of the request to be aborted.
318 long operationRequestId;
321 // Options for the <code>onAddWatcherRequested()</code> event.
322 dictionary AddWatcherRequestedOptions {
323 // The identifier of the file system related to this operation.
324 DOMString fileSystemId;
326 // The unique identifier of this request.
327 long requestId;
329 // The path of the entry to be observed.
330 DOMString entryPath;
332 // Whether observing should include all child entries recursively. It can be
333 // true for directories only.
334 boolean recursive;
337 // Options for the <code>onRemoveWatcherRequested()</code> event.
338 dictionary RemoveWatcherRequestedOptions {
339 // The identifier of the file system related to this operation.
340 DOMString fileSystemId;
342 // The unique identifier of this request.
343 long requestId;
345 // The path of the watched entry.
346 DOMString entryPath;
348 // Mode of the watcher.
349 boolean recursive;
352 // Information about a change happened to an entry within the observed
353 // directory (including the entry itself).
354 dictionary Change {
355 // The path of the changed entry.
356 DOMString entryPath;
358 // The type of the change which happened to the entry.
359 ChangeType changeType;
362 // Options for the <code>Notify()</code> method.
363 dictionary NotifyOptions {
364 // The identifier of the file system related to this change.
365 DOMString fileSystemId;
367 // The path of the observed entry.
368 DOMString observedPath;
370 // Mode of the observed entry.
371 boolean recursive;
373 // The type of the change which happened to the observed entry. If it is
374 // DELETED, then the observed entry will be automatically removed from the
375 // list of observed entries.
376 ChangeType changeType;
378 // List of changes to entries within the observed directory (including the
379 // entry itself)
380 Change[]? changes;
382 // Tag for the notification. Required if the file system was mounted with
383 // the <code>supportsNotifyTag</code> option. Note, that this flag is
384 // necessary to provide notifications about changes which changed even
385 // when the system was shutdown.
386 DOMString? tag;
389 // Callback to receive the result of getAll() function.
390 callback GetAllCallback = void(FileSystemInfo[] fileSystems);
392 // Callback to be called by the providing extension in case of a success.
393 [nocompile] callback ProviderSuccessCallback = void();
395 // Callback to be called by the providing extension in case of an error.
396 [nocompile] callback ProviderErrorCallback = void(ProviderError error);
398 // Success callback for the <code>onGetMetadataRequested</code> event.
399 [nocompile] callback MetadataCallback = void(
400 EntryMetadata metadata);
402 // Success callback for the <code>onReadDirectoryRequested</code> event. If
403 // more entries will be returned, then <code>hasMore</code> must be true, and
404 // it has to be called again with additional entries. If no more entries are
405 // available, then <code>hasMore</code> must be set to false.
406 [nocompile] callback EntriesCallback = void(
407 EntryMetadata[] entries, boolean hasMore);
409 // Success callback for the <code>onReadFileRequested</code> event. If more
410 // data will be returned, then <code>hasMore</code> must be true, and it
411 // has to be called again with additional entries. If no more data is
412 // available, then <code>hasMore</code> must be set to false.
413 [nocompile] callback FileDataCallback = void(
414 ArrayBuffer data, boolean hasMore);
416 // A generic result callback to indicate success or failure.
417 callback ResultCallback = void();
419 interface Functions {
420 // Mounts a file system with the given <code>fileSystemId</code> and <code>
421 // displayName</code>. <code>displayName</code> will be shown in the left
422 // panel of Files.app. <code>displayName</code> can contain any characters
423 // including '/', but cannot be an empty string. <code>displayName</code>
424 // must be descriptive but doesn't have to be unique. The <code>fileSystemId
425 // </code> must not be an empty string.
427 // In case of an error, <code>chrome.runtime.lastError</code> will be set
428 // will a corresponding error code.
429 static void mount(MountOptions options,
430 optional ResultCallback callback);
432 // Unmounts a file system with the given <code>fileSystemId</code>. It
433 // must be called after <code>onUnmountRequested</code> is invoked. Also,
434 // the providing extension can decide to perform unmounting if not requested
435 // (eg. in case of lost connection, or a file error).
437 // In case of an error, <code>chrome.runtime.lastError</code> will be set
438 // will a corresponding error code.
439 static void unmount(UnmountOptions options,
440 optional ResultCallback callback);
442 // Returns all file systems mounted by the extension.
443 static void getAll(GetAllCallback callback);
445 // Notifies about changes in the watched directory at <code>
446 // observedPath</code> in <code>recursive</code mode. If the file system is
447 // mounted with <code>supportsNofityTag</code>, then <code>tag</code> must
448 // be provided, and all changes since the last notification always reported,
449 // even if the system was shutdown. The last tag can be obtained with <code>
450 // getAll()</code>. Note, that <code>tag</code> is required in order to
451 // enable the internal cache.
453 // Value of <code>tag</code> can be any string which is unique per call,
454 // so it's possible to identify the last registered notification. Eg. if
455 // the providing extension starts after a reboot, and the last registered
456 // notification's tag is equal to "123", then it should call notify() for
457 // all changes which happened since the change tagged as "123". It cannot
458 // be an empty string.
460 // Not all providers are able to provide a tag, but if the file system has
461 // a changelog, then the tag can be eg. a change number, or a revision
462 // number.
464 // Note that if a parent directory is removed, then all descendant entries
465 // are also removed, and if they are watched, then the API must be notified
466 // about the fact. Also, if a directory is renamed, then all descendant
467 // entries are in fact removed, as there is no entry under their original
468 // paths anymore.
470 // In case of an error, <code>chrome.runtime.lastError</code> will be set
471 // will a corresponding error code.
472 [nodoc] static void notify(NotifyOptions options,
473 optional ResultCallback callback);
476 interface Events {
477 // Raised when unmounting for the file system with the <code>fileSystemId
478 // </code> identifier is requested. In the response, the <code>unmount
479 // </code> API method must be called together with <code>successCallback
480 // </code>. If unmounting is not possible (eg. due to a pending operation),
481 // then <code>errorCallback</code> must be called.
482 [maxListeners=1] static void onUnmountRequested(
483 UnmountRequestedOptions options,
484 ProviderSuccessCallback successCallback,
485 ProviderErrorCallback errorCallback);
487 // Raised when metadata of a file or a directory at <code>entryPath</code>
488 // is requested. The metadata must be returned with the <code>
489 // successCallback</code> call. In case of an error, <code>errorCallback
490 // </code> must be called.
491 [maxListeners=1] static void onGetMetadataRequested(
492 GetMetadataRequestedOptions options,
493 MetadataCallback successCallback,
494 ProviderErrorCallback errorCallback);
496 // Raised when contents of a directory at <code>directoryPath</code> are
497 // requested. The results must be returned in chunks by calling the <code>
498 // successCallback</code> several times. In case of an error, <code>
499 // errorCallback</code> must be called.
500 [maxListeners=1] static void onReadDirectoryRequested(
501 ReadDirectoryRequestedOptions options,
502 EntriesCallback successCallback,
503 ProviderErrorCallback errorCallback);
505 // Raised when opening a file at <code>filePath</code> is requested. If the
506 // file does not exist, then the operation must fail.
507 [maxListeners=1] static void onOpenFileRequested(
508 OpenFileRequestedOptions options,
509 ProviderSuccessCallback successCallback,
510 ProviderErrorCallback errorCallback);
512 // Raised when opening a file previously opened with <code>openRequestId
513 // </code> is requested to be closed.
514 [maxListeners=1] static void onCloseFileRequested(
515 CloseFileRequestedOptions options,
516 ProviderSuccessCallback successCallback,
517 ProviderErrorCallback errorCallback);
519 // Raised when reading contents of a file opened previously with <code>
520 // openRequestId</code> is requested. The results must be returned in
521 // chunks by calling <code>successCallback</code> several times. In case of
522 // an error, <code>errorCallback</code> must be called.
523 [maxListeners=1] static void onReadFileRequested(
524 ReadFileRequestedOptions options,
525 FileDataCallback successCallback,
526 ProviderErrorCallback errorCallback);
528 // Raised when creating a directory is requested. The operation must fail
529 // with the EXISTS error if the target directory already exists.
530 // If <code>recursive</code> is true, then all of the missing directories
531 // on the directory path must be created.
532 [maxListeners=1] static void onCreateDirectoryRequested(
533 CreateDirectoryRequestedOptions options,
534 ProviderSuccessCallback successCallback,
535 ProviderErrorCallback errorCallback);
537 // Raised when deleting an entry is requested. If <code>recursive</code> is
538 // true, and the entry is a directory, then all of the entries inside
539 // must be recursively deleted as well.
540 [maxListeners=1] static void onDeleteEntryRequested(
541 DeleteEntryRequestedOptions options,
542 ProviderSuccessCallback successCallback,
543 ProviderErrorCallback errorCallback);
545 // Raised when creating a file is requested. If the file already exists,
546 // then <code>errorCallback</code> must be called with the <code>EXISTS
547 // </code> error code.
548 [maxListeners=1] static void onCreateFileRequested(
549 CreateFileRequestedOptions options,
550 ProviderSuccessCallback successCallback,
551 ProviderErrorCallback errorCallback);
553 // Raised when copying an entry (recursively if a directory) is requested.
554 // If an error occurs, then <code>errorCallback</code> must be called.
555 [maxListeners=1] static void onCopyEntryRequested(
556 CopyEntryRequestedOptions options,
557 ProviderSuccessCallback successCallback,
558 ProviderErrorCallback errorCallback);
560 // Raised when moving an entry (recursively if a directory) is requested.
561 // If an error occurs, then <code>errorCallback</code> must be called.
562 [maxListeners=1] static void onMoveEntryRequested(
563 MoveEntryRequestedOptions options,
564 ProviderSuccessCallback successCallback,
565 ProviderErrorCallback errorCallback);
567 // Raised when truncating a file to a desired length is requested.
568 // If an error occurs, then <code>errorCallback</code> must be called.
569 [maxListeners=1] static void onTruncateRequested(
570 TruncateRequestedOptions options,
571 ProviderSuccessCallback successCallback,
572 ProviderErrorCallback errorCallback);
574 // Raised when writing contents to a file opened previously with <code>
575 // openRequestId</code> is requested.
576 [maxListeners=1] static void onWriteFileRequested(
577 WriteFileRequestedOptions options,
578 ProviderSuccessCallback successCallback,
579 ProviderErrorCallback errorCallback);
581 // Raised when aborting an operation with <code>operationRequestId</code>
582 // is requested. The operation executed with <code>operationRequestId</code>
583 // must be immediately stopped and <code>successCallback</code> of this
584 // abort request executed. If aborting fails, then <code>errorCallback
585 // </code> must be called. Note, that callbacks of the aborted operation
586 // must not be called, as they will be ignored. Despite calling <code>
587 // errorCallback</code>, the request may be forcibly aborted.
588 [maxListeners=1] static void onAbortRequested(
589 AbortRequestedOptions options,
590 ProviderSuccessCallback successCallback,
591 ProviderErrorCallback errorCallback);
593 // Raised when setting a new directory watcher is requested. If an error
594 // occurs, then <code>errorCallback</code> must be called.
595 [maxListeners=1, nodoc] static void onAddWatcherRequested(
596 AddWatcherRequestedOptions options,
597 ProviderSuccessCallback successCallback,
598 ProviderErrorCallback errorCallback);
600 // Raised when the watcher should be removed. If an error occurs, then
601 // <code>errorCallback</code> must be called.
602 [maxListeners=1, nodoc] static void onRemoveWatcherRequested(
603 RemoveWatcherRequestedOptions options,
604 ProviderSuccessCallback successCallback,
605 ProviderErrorCallback errorCallback);