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,
11 // <code>"OK"</code> must be used.
32 // Mode of opening a file. Used by $(ref:onOpenFileRequested).
38 // Type of a change detected on the observed directory.
44 // List of common actions. <code>"SHARE"</code> is for sharing files with
45 // others. <code>"SAVE_FOR_OFFLINE"</code> for pinning (saving for offline
46 // access). <code>"OFFLINE_NOT_NECESSARY"</code> for notifying that the file
47 // doesn't need to be stored for offline access anymore.
48 // Used by $(ref:onGetActionsRequested) and $(ref:onExecuteActionRequested).
51 OFFLINE_NOT_NECESSARY
,
55 // Represents metadata of a file or a directory.
56 dictionary EntryMetadata
{
57 // True if it is a directory.
60 // Name of this entry (not full path name). Must not contain '/'. For root
64 // File size in bytes.
67 // The last modified time of this entry.
68 [instanceOf
=Date
] object modificationTime
;
70 // Mime type for the entry.
73 // Thumbnail image as a data URI in either PNG, JPEG or WEBP format, at most
74 // 32 KB in size. Optional, but can be provided only when explicitly
75 // requested by the $(ref:onGetMetadataRequested) event.
79 // Represents a watcher.
81 // The path of the entry being observed.
84 // Whether watching should include all child entries recursively. It can be
85 // true for directories only.
88 // Tag used by the last notification for the watcher.
92 // Represents an opened file.
93 dictionary OpenedFile
{
94 // A request ID to be be used by consecutive read/write and close requests.
97 // The path of the opened file.
100 // Whether the file was opened for reading or writing.
104 // Represents a mounted file system.
105 dictionary FileSystemInfo
{
106 // The identifier of the file system.
107 DOMString fileSystemId
;
109 // A human-readable name for the file system.
110 DOMString displayName
;
112 // Whether the file system supports operations which may change contents
113 // of the file system (such as creating, deleting or writing to files).
116 // The maximum number of files that can be opened at once. If 0, then not
118 long openedFilesLimit
;
120 // List of currently opened files.
121 OpenedFile
[] openedFiles
;
123 // Whether the file system supports the <code>tag</code> field for observing
125 boolean? supportsNotifyTag
;
131 // Options for the $(ref:mount) method.
132 dictionary MountOptions
{
133 // The string indentifier of the file system. Must be unique per each
135 DOMString fileSystemId
;
137 // A human-readable name for the file system.
138 DOMString displayName
;
140 // Whether the file system supports operations which may change contents
141 // of the file system (such as creating, deleting or writing to files).
144 // The maximum number of files that can be opened at once. If not specified,
145 // or 0, then not limited.
146 long? openedFilesLimit
;
148 // Whether the file system supports the <code>tag</code> field for observed
150 boolean? supportsNotifyTag
;
153 // Options for the $(ref:unmount) method.
154 dictionary UnmountOptions
{
155 // The identifier of the file system to be unmounted.
156 DOMString fileSystemId
;
159 // Options for the $(ref:onUnmountRequested) event.
160 dictionary UnmountRequestedOptions
{
161 // The identifier of the file system to be unmounted.
162 DOMString fileSystemId
;
164 // The unique identifier of this request.
168 // Options for the $(ref:onGetMetadataRequested) event.
169 dictionary GetMetadataRequestedOptions
{
170 // The identifier of the file system related to this operation.
171 DOMString fileSystemId
;
173 // The unique identifier of this request.
176 // The path of the entry to fetch metadata about.
179 // Set to <code>true</code> if the thumbnail is requested.
183 // Options for the $(ref:onGetActionsRequested) event.
184 dictionary GetActionsRequestedOptions
{
185 // The identifier of the file system related to this operation.
186 DOMString fileSystemId
;
188 // The unique identifier of this request.
191 // The path of the entry to return the list of actions for.
195 // Options for the $(ref:onReadDirectoryRequested) event.
196 dictionary ReadDirectoryRequestedOptions
{
197 // The identifier of the file system related to this operation.
198 DOMString fileSystemId
;
200 // The unique identifier of this request.
203 // The path of the directory which contents are requested.
204 DOMString directoryPath
;
207 // Options for the $(ref:onOpenFileRequested) event.
208 dictionary OpenFileRequestedOptions
{
209 // The identifier of the file system related to this operation.
210 DOMString fileSystemId
;
212 // A request ID which will be used by consecutive read/write and close
216 // The path of the file to be opened.
219 // Whether the file will be used for reading or writing.
223 // Options for the $(ref:onCloseFileRequested) event.
224 dictionary CloseFileRequestedOptions
{
225 // The identifier of the file system related to this operation.
226 DOMString fileSystemId
;
228 // The unique identifier of this request.
231 // A request ID used to open the file.
235 // Options for the $(ref:onReadFileRequested) event.
236 dictionary ReadFileRequestedOptions
{
237 // The identifier of the file system related to this operation.
238 DOMString fileSystemId
;
240 // The unique identifier of this request.
243 // A request ID used to open the file.
246 // Position in the file (in bytes) to start reading from.
249 // Number of bytes to be returned.
253 // Options for the $(ref:onCreateDirectoryRequested) event.
254 dictionary CreateDirectoryRequestedOptions
{
255 // The identifier of the file system related to this operation.
256 DOMString fileSystemId
;
258 // The unique identifier of this request.
261 // The path of the directory to be created.
262 DOMString directoryPath
;
264 // Whether the operation is recursive (for directories only).
268 // Options for the $(ref:onDeleteEntryRequested) event.
269 dictionary DeleteEntryRequestedOptions
{
270 // The identifier of the file system related to this operation.
271 DOMString fileSystemId
;
273 // The unique identifier of this request.
276 // The path of the entry to be deleted.
279 // Whether the operation is recursive (for directories only).
283 // Options for the $(ref:onCreateFileRequested) event.
284 dictionary CreateFileRequestedOptions
{
285 // The identifier of the file system related to this operation.
286 DOMString fileSystemId
;
288 // The unique identifier of this request.
291 // The path of the file to be created.
295 // Options for the $(ref:onCopyEntryRequested) event.
296 dictionary CopyEntryRequestedOptions
{
297 // The identifier of the file system related to this operation.
298 DOMString fileSystemId
;
300 // The unique identifier of this request.
303 // The source path of the entry to be copied.
304 DOMString sourcePath
;
306 // The destination path for the copy operation.
307 DOMString targetPath
;
310 // Options for the $(ref:onMoveEntryRequested) event.
311 dictionary MoveEntryRequestedOptions
{
312 // The identifier of the file system related to this operation.
313 DOMString fileSystemId
;
315 // The unique identifier of this request.
318 // The source path of the entry to be moved into a new place.
319 DOMString sourcePath
;
321 // The destination path for the copy operation.
322 DOMString targetPath
;
325 // Options for the $(ref:onTruncateRequested) event.
326 dictionary TruncateRequestedOptions
{
327 // The identifier of the file system related to this operation.
328 DOMString fileSystemId
;
330 // The unique identifier of this request.
333 // The path of the file to be truncated.
336 // Number of bytes to be retained after the operation completes.
340 // Options for the $(ref:onWriteFileRequested) event.
341 dictionary WriteFileRequestedOptions
{
342 // The identifier of the file system related to this operation.
343 DOMString fileSystemId
;
345 // The unique identifier of this request.
348 // A request ID used to open the file.
351 // Position in the file (in bytes) to start writing the bytes from.
354 // Buffer of bytes to be written to the file.
358 // Options for the $(ref:onAbortRequested) event.
359 dictionary AbortRequestedOptions
{
360 // The identifier of the file system related to this operation.
361 DOMString fileSystemId
;
363 // The unique identifier of this request.
366 // An ID of the request to be aborted.
367 long operationRequestId
;
370 // Options for the $(ref:onAddWatcherRequested) event.
371 dictionary AddWatcherRequestedOptions
{
372 // The identifier of the file system related to this operation.
373 DOMString fileSystemId
;
375 // The unique identifier of this request.
378 // The path of the entry to be observed.
381 // Whether observing should include all child entries recursively. It can be
382 // true for directories only.
386 // Options for the $(ref:onRemoveWatcherRequested) event.
387 dictionary RemoveWatcherRequestedOptions
{
388 // The identifier of the file system related to this operation.
389 DOMString fileSystemId
;
391 // The unique identifier of this request.
394 // The path of the watched entry.
397 // Mode of the watcher.
401 // Information about an action for an entry.
403 // The identifier of the action. Any string or $(ref:CommonActionId) for
407 // The title of the action. It may be ignored for common actions.
411 // Options for the $(ref:onExecuteActionRequested) event.
412 dictionary ExecuteActionRequestedOptions
{
413 // The identifier of the file system related to this operation.
414 DOMString fileSystemId
;
416 // The unique identifier of this request.
419 // The path of the entry to be used for the action.
422 // The identifier of the action to be executed.
426 // Information about a change happened to an entry within the observed
427 // directory (including the entry itself).
429 // The path of the changed entry.
432 // The type of the change which happened to the entry.
433 ChangeType changeType
;
436 // Options for the $(ref:notify) method.
437 dictionary NotifyOptions
{
438 // The identifier of the file system related to this change.
439 DOMString fileSystemId
;
441 // The path of the observed entry.
442 DOMString observedPath
;
444 // Mode of the observed entry.
447 // The type of the change which happened to the observed entry. If it is
448 // DELETED, then the observed entry will be automatically removed from the
449 // list of observed entries.
450 ChangeType changeType
;
452 // List of changes to entries within the observed directory (including the
456 // Tag for the notification. Required if the file system was mounted with
457 // the <code>supportsNotifyTag</code> option. Note, that this flag is
458 // necessary to provide notifications about changes which changed even
459 // when the system was shutdown.
463 // Options for the $(ref:onConfigureRequested) event.
464 dictionary ConfigureRequestedOptions
{
465 // The identifier of the file system to be configured.
466 DOMString fileSystemId
;
468 // The unique identifier of this request.
472 // Callback to receive the result of $(ref:getAll) function.
473 callback GetAllCallback
= void(FileSystemInfo
[] fileSystems
);
475 // Callback to receive the result of $(ref:get) function.
476 callback GetCallback
= void(FileSystemInfo fileSystem
);
478 // Callback to be called by the providing extension in case of a success.
479 [nocompile
] callback ProviderSuccessCallback
= void();
481 // Callback to be called by the providing extension in case of an error.
482 [nocompile
] callback ProviderErrorCallback
= void(ProviderError error
);
484 // Success callback for the $(ref:onGetMetadataRequested) event.
485 [nocompile
] callback MetadataCallback
= void(EntryMetadata metadata
);
487 // Success callback for the $(ref:onGetActionsRequested) event.
488 [nocompile
, nodoc
] callback ActionsCallback
= void(Action
[] actions
);
490 // Success callback for the $(ref:onReadDirectoryRequested) event. If more
491 // entries will be returned, then <code>hasMore</code> must be true, and it
492 // has to be called again with additional entries. If no more entries are
493 // available, then <code>hasMore</code> must be set to false.
494 [nocompile
] callback EntriesCallback
= void(
495 EntryMetadata
[] entries
, boolean hasMore
);
497 // Success callback for the $(ref:onReadFileRequested) event. If more
498 // data will be returned, then <code>hasMore</code> must be true, and it
499 // has to be called again with additional entries. If no more data is
500 // available, then <code>hasMore</code> must be set to false.
501 [nocompile
] callback FileDataCallback
= void(
502 ArrayBuffer data
, boolean hasMore
);
504 // A generic result callback to indicate success or failure.
505 callback ResultCallback
= void();
507 interface Functions
{
508 // Mounts a file system with the given <code>fileSystemId</code> and
509 // <code>displayName</code>. <code>displayName</code> will be shown in the
510 // left panel of Files.app. <code>displayName</code> can contain any
511 // characters including '/', but cannot be an empty string.
512 // <code>displayName</code> must be descriptive but doesn't have to be
513 // unique. The <code>fileSystemId</code> must not be an empty string.
515 // Depending on the type of the file system being mounted, the
516 // <code>source</code> option must be set appropriately.
518 // In case of an error, $(ref:runtime.lastError) will be set with a
519 // corresponding error code.
520 static
void mount
(MountOptions options
,
521 optional ResultCallback
callback);
523 // Unmounts a file system with the given <code>fileSystemId</code>. It
524 // must be called after $(ref:onUnmountRequested) is invoked. Also,
525 // the providing extension can decide to perform unmounting if not requested
526 // (eg. in case of lost connection, or a file error).
528 // In case of an error, $(ref:runtime.lastError) will be set with a
529 // corresponding error code.
530 static
void unmount
(UnmountOptions options
,
531 optional ResultCallback
callback);
533 // Returns all file systems mounted by the extension.
534 static
void getAll
(GetAllCallback
callback);
536 // Returns information about a file system with the passed
537 // <code>fileSystemId</code>.
538 static
void get
(DOMString fileSystemId
, GetCallback
callback);
540 // Notifies about changes in the watched directory at
541 // <code>observedPath</code> in <code>recursive</code> mode. If the file
542 // system is mounted with <code>supportsNofityTag</code>, then
543 // <code>tag</code> must be provided, and all changes since the last
544 // notification always reported, even if the system was shutdown. The last
545 // tag can be obtained with $(ref:getAll).
547 // To use, the <code>file_system_provider.notify</code> manifest option
548 // must be set to true.
550 // Value of <code>tag</code> can be any string which is unique per call,
551 // so it's possible to identify the last registered notification. Eg. if
552 // the providing extension starts after a reboot, and the last registered
553 // notification's tag is equal to "123", then it should call $(ref:notify)
554 // for all changes which happened since the change tagged as "123". It
555 // cannot be an empty string.
557 // Not all providers are able to provide a tag, but if the file system has
558 // a changelog, then the tag can be eg. a change number, or a revision
561 // Note that if a parent directory is removed, then all descendant entries
562 // are also removed, and if they are watched, then the API must be notified
563 // about the fact. Also, if a directory is renamed, then all descendant
564 // entries are in fact removed, as there is no entry under their original
567 // In case of an error, $(ref:runtime.lastError) will be set
568 // will a corresponding error code.
569 static
void notify
(NotifyOptions options
,
570 optional ResultCallback
callback);
574 // Raised when unmounting for the file system with the
575 // <code>fileSystemId</code> identifier is requested. In the response, the
576 // $(ref:unmount) API method must be called together with
577 // <code>successCallback</code>. If unmounting is not possible (eg. due to
578 // a pending operation), then <code>errorCallback</code> must be called.
579 [maxListeners
=1] static
void onUnmountRequested
(
580 UnmountRequestedOptions options
,
581 ProviderSuccessCallback successCallback
,
582 ProviderErrorCallback errorCallback
);
584 // Raised when metadata of a file or a directory at <code>entryPath</code>
585 // is requested. The metadata must be returned with the
586 // <code>successCallback</code> call. In case of an error,
587 // <code>errorCallback</code> must be called.
588 [maxListeners
=1] static
void onGetMetadataRequested
(
589 GetMetadataRequestedOptions options
,
590 MetadataCallback successCallback
,
591 ProviderErrorCallback errorCallback
);
593 // Raised when list of actions for of a file or a directory at
594 // <code>entryPath</code>s requested. The actions must be returned with the
595 // <code>successCallback</code> call. In case of an error,
596 // <code>errorCallback</code> must be called.
597 [maxListeners
=1, nodoc
] static
void onGetActionsRequested
(
598 GetActionsRequestedOptions options
,
599 ActionsCallback successCallback
,
600 ProviderErrorCallback errorCallback
);
602 // Raised when contents of a directory at <code>directoryPath</code> are
603 // requested. The results must be returned in chunks by calling the
604 // <code>successCallback</code> several times. In case of an error,
605 // <code>errorCallback</code> must be called.
606 [maxListeners
=1] static
void onReadDirectoryRequested
(
607 ReadDirectoryRequestedOptions options
,
608 EntriesCallback successCallback
,
609 ProviderErrorCallback errorCallback
);
611 // Raised when opening a file at <code>filePath</code> is requested. If the
612 // file does not exist, then the operation must fail. Maximum number of
613 // files opened at once can be specified with <code>MountOptions</code>.
614 [maxListeners
=1] static
void onOpenFileRequested
(
615 OpenFileRequestedOptions options
,
616 ProviderSuccessCallback successCallback
,
617 ProviderErrorCallback errorCallback
);
619 // Raised when opening a file previously opened with
620 // <code>openRequestId</code> is requested to be closed.
621 [maxListeners
=1] static
void onCloseFileRequested
(
622 CloseFileRequestedOptions options
,
623 ProviderSuccessCallback successCallback
,
624 ProviderErrorCallback errorCallback
);
626 // Raised when reading contents of a file opened previously with
627 // <code>openRequestId</code> is requested. The results must be returned in
628 // chunks by calling <code>successCallback</code> several times. In case of
629 // an error, <code>errorCallback</code> must be called.
630 [maxListeners
=1] static
void onReadFileRequested
(
631 ReadFileRequestedOptions options
,
632 FileDataCallback successCallback
,
633 ProviderErrorCallback errorCallback
);
635 // Raised when creating a directory is requested. The operation must fail
636 // with the EXISTS error if the target directory already exists.
637 // If <code>recursive</code> is true, then all of the missing directories
638 // on the directory path must be created.
639 [maxListeners
=1] static
void onCreateDirectoryRequested
(
640 CreateDirectoryRequestedOptions options
,
641 ProviderSuccessCallback successCallback
,
642 ProviderErrorCallback errorCallback
);
644 // Raised when deleting an entry is requested. If <code>recursive</code> is
645 // true, and the entry is a directory, then all of the entries inside
646 // must be recursively deleted as well.
647 [maxListeners
=1] static
void onDeleteEntryRequested
(
648 DeleteEntryRequestedOptions options
,
649 ProviderSuccessCallback successCallback
,
650 ProviderErrorCallback errorCallback
);
652 // Raised when creating a file is requested. If the file already exists,
653 // then <code>errorCallback</code> must be called with the
654 // <code>"EXISTS"</code> error code.
655 [maxListeners
=1] static
void onCreateFileRequested
(
656 CreateFileRequestedOptions options
,
657 ProviderSuccessCallback successCallback
,
658 ProviderErrorCallback errorCallback
);
660 // Raised when copying an entry (recursively if a directory) is requested.
661 // If an error occurs, then <code>errorCallback</code> must be called.
662 [maxListeners
=1] static
void onCopyEntryRequested
(
663 CopyEntryRequestedOptions options
,
664 ProviderSuccessCallback successCallback
,
665 ProviderErrorCallback errorCallback
);
667 // Raised when moving an entry (recursively if a directory) is requested.
668 // If an error occurs, then <code>errorCallback</code> must be called.
669 [maxListeners
=1] static
void onMoveEntryRequested
(
670 MoveEntryRequestedOptions options
,
671 ProviderSuccessCallback successCallback
,
672 ProviderErrorCallback errorCallback
);
674 // Raised when truncating a file to a desired length is requested.
675 // If an error occurs, then <code>errorCallback</code> must be called.
676 [maxListeners
=1] static
void onTruncateRequested
(
677 TruncateRequestedOptions options
,
678 ProviderSuccessCallback successCallback
,
679 ProviderErrorCallback errorCallback
);
681 // Raised when writing contents to a file opened previously with
682 // <code>openRequestId</code> is requested.
683 [maxListeners
=1] static
void onWriteFileRequested
(
684 WriteFileRequestedOptions options
,
685 ProviderSuccessCallback successCallback
,
686 ProviderErrorCallback errorCallback
);
688 // Raised when aborting an operation with <code>operationRequestId</code>
689 // is requested. The operation executed with <code>operationRequestId</code>
690 // must be immediately stopped and <code>successCallback</code> of this
691 // abort request executed. If aborting fails, then
692 // <code>errorCallback</code> must be called. Note, that callbacks of the
693 // aborted operation must not be called, as they will be ignored. Despite
694 // calling <code>errorCallback</code>, the request may be forcibly aborted.
695 [maxListeners
=1] static
void onAbortRequested
(
696 AbortRequestedOptions options
,
697 ProviderSuccessCallback successCallback
,
698 ProviderErrorCallback errorCallback
);
700 // Raised when showing a configuration dialog for <code>fileSystemId</code>
701 // is requested. If it's handled, the
702 // <code>file_system_provider.configurable</code> manfiest option must be
704 [maxListeners
=1] static
void onConfigureRequested
(
705 ConfigureRequestedOptions options
,
706 ProviderSuccessCallback successCallback
,
707 ProviderErrorCallback errorCallback
);
709 // Raised when showing a dialog for mounting a new file system is requested.
710 // If the extension/app is a file handler, then this event shouldn't be
711 // handled. Instead <code>app.runtime.onLaunched</code> should be handled in
712 // order to mount new file systems when a file is opened. For multiple
713 // mounts, the <code>file_system_provider.multiple_mounts</code> manifest
714 // option must be set to true.
715 [maxListeners
=1] static
void onMountRequested
(
716 ProviderSuccessCallback successCallback
,
717 ProviderErrorCallback errorCallback
);
719 // Raised when setting a new directory watcher is requested. If an error
720 // occurs, then <code>errorCallback</code> must be called.
721 [maxListeners
=1] static
void onAddWatcherRequested
(
722 AddWatcherRequestedOptions options
,
723 ProviderSuccessCallback successCallback
,
724 ProviderErrorCallback errorCallback
);
726 // Raised when the watcher should be removed. If an error occurs, then
727 // <code>errorCallback</code> must be called.
728 [maxListeners
=1] static
void onRemoveWatcherRequested
(
729 RemoveWatcherRequestedOptions options
,
730 ProviderSuccessCallback successCallback
,
731 ProviderErrorCallback errorCallback
);
733 // Raised when executing an action for a file or a directory is requested.
734 // After the action is completed, <code>successCallback</code> must be
735 // called. On error, <code>errorCallback</code> must be called.
736 [maxListeners
=1, nodoc
] static
void onExecuteActionRequested
(
737 ExecuteActionRequestedOptions options
,
738 ProviderSuccessCallback successCallback
,
739 ProviderErrorCallback errorCallback
);