// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Use the chrome.fileSystemProvider
API to create file systems,
// that can be accessible from the file manager on Chrome OS.
[platforms=("chromeos"),
implemented_in="chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h"]
namespace fileSystemProvider {
// Error codes used by providing extensions in response to requests. For
// success, OK
must be used.
enum ProviderError {
OK,
FAILED,
IN_USE,
EXISTS,
NOT_FOUND,
ACCESS_DENIED,
TOO_MANY_OPENED,
NO_MEMORY,
NO_SPACE,
NOT_A_DIRECTORY,
INVALID_OPERATION,
SECURITY,
NOT_A_FILE,
NOT_EMPTY,
INVALID_URL,
IO
};
// Mode of opening a file. Used by onOpenFileRequested
.
enum OpenFileMode {
READ,
WRITE
};
// Represents metadata of a file or a directory.
dictionary EntryMetadata {
// True if it is a directory.
boolean isDirectory;
// Name of this entry (not full path name).
DOMString name;
// File size in bytes.
double size;
// The last modified time of this entry.
[instanceOf=Date] object modificationTime;
// Mime type for the entry.
DOMString? mimeType;
// Thumbnail image as a data URI in either PNG, JPEG or WEBP format, at most
// 32 KB in size. Optional, but can be provided only when explicitly
// requested by the onGetMetadataRequested
event.
DOMString? thumbnail;
};
// Represents a mounted file system.
dictionary FileSystemInfo {
// The identifier of the file system.
DOMString fileSystemId;
// A human-readable name for the file system.
DOMString displayName;
// Whether the file system supports operations which may change contents
// of the file system (such as creating, deleting or writing to files).
boolean writable;
};
// Options for the mount()
method.
dictionary MountOptions {
// The string indentifier of the file system. Must be unique per each
// extension.
DOMString fileSystemId;
// A human-readable name for the file system.
DOMString displayName;
// Whether the file system supports operations which may change contents
// of the file system (such as creating, deleting or writing to files).
boolean? writable;
};
// Options for the unmount()
method.
dictionary UnmountOptions {
// The identifier of the file system to be unmounted.
DOMString fileSystemId;
};
// Options for the onUnmountRequested()
event.
dictionary UnmountRequestedOptions {
// The identifier of the file system to be unmounted.
DOMString fileSystemId;
long requestId;
};
// Options for the onGetMetadataRequested()
event.
dictionary GetMetadataRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The path of the entry to fetch metadata about.
DOMString entryPath;
// Set to true
if the thumbnail is requested.
boolean thumbnail;
};
// Options for the onReadDirectoryRequested()
event.
dictionary ReadDirectoryRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The path of the directory which contents are requested.
DOMString directoryPath;
};
// Options for the onOpenFileRequested()
event.
dictionary OpenFileRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// A request ID which will be used by consecutive read/write and close
// requests.
long requestId;
// The path of the file to be opened.
DOMString filePath;
// Whether the file will be used for reading or writing.
OpenFileMode mode;
};
// Options for the onCloseFileRequested()
event.
dictionary CloseFileRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// A request ID used to open the file.
long openRequestId;
};
// Options for the onReadFileRequested()
event.
dictionary ReadFileRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// A request ID used to open the file.
long openRequestId;
// Position in the file (in bytes) to start reading from.
double offset;
// Number of bytes to be returned.
double length;
};
// Options for the onCreateDirectoryRequested()
event.
dictionary CreateDirectoryRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The path of the directory to be created.
DOMString directoryPath;
// Whether the operation is recursive (for directories only).
boolean recursive;
};
// Options for the onDeleteEntryRequested()
event.
dictionary DeleteEntryRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The path of the entry to be deleted.
DOMString entryPath;
// Whether the operation is recursive (for directories only).
boolean recursive;
};
// Options for the onCreateFileRequested()
event.
dictionary CreateFileRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The path of the file to be created.
DOMString filePath;
};
// Options for the onCopyEntryRequested()
event.
dictionary CopyEntryRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The source path of the entry to be copied.
DOMString sourcePath;
// The destination path for the copy operation.
DOMString targetPath;
};
// Options for the onMoveEntryRequested()
event.
dictionary MoveEntryRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The source path of the entry to be moved into a new place.
DOMString sourcePath;
// The destination path for the copy operation.
DOMString targetPath;
};
// Options for the onTruncateRequested()
event.
dictionary TruncateRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// The path of the file to be truncated.
DOMString filePath;
// Number of bytes to be retained after the operation completes.
double length;
};
// Options for the onWriteFileRequested()
event.
dictionary WriteFileRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// A request ID used to open the file.
long openRequestId;
// Position in the file (in bytes) to start writing the bytes from.
double offset;
// Buffer of bytes to be written to the file.
ArrayBuffer data;
};
// Options for the onAbortRequested()
event.
dictionary AbortRequestedOptions {
// The identifier of the file system related to this operation.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
// An ID of the request to be aborted.
long operationRequestId;
};
// Callback to receive the result of mount() function.
callback MountCallback = void([nodoc, instanceOf=DOMError] object error);
// Callback to receive the result of unmount() function.
callback UnmountCallback = void([nodoc, instanceOf=DOMError] object error);
// Callback to receive the result of getAll() function.
callback GetAllCallback = void(FileSystemInfo[] fileSystems);
// Callback to handle an error raised from the browser.
[nocompile] callback ErrorCallback = void([instanceOf=DOMError] object error);
// Callback to be called by the providing extension in case of a success.
[nocompile] callback ProviderSuccessCallback = void();
// Callback to be called by the providing extension in case of an error.
[nocompile] callback ProviderErrorCallback = void(ProviderError error);
// Success callback for the onGetMetadataRequested
event.
[nocompile] callback MetadataCallback = void(
EntryMetadata metadata);
// Success callback for the onReadDirectoryRequested
event. If
// more entries will be returned, then hasMore
must be true, and
// it has to be called again with additional entries. If no more entries are
// available, then hasMore
must be set to false.
[nocompile] callback EntriesCallback = void(
EntryMetadata[] entries, boolean hasMore);
// Success callback for the onReadFileRequested
event. If more
// data will be returned, then hasMore
must be true, and it
// has to be called again with additional entries. If no more data is
// available, then hasMore
must be set to false.
[nocompile] callback FileDataCallback = void(
ArrayBuffer data, boolean hasMore);
interface Functions {
// Mounts a file system with the given fileSystemId
and
// displayName
. displayName
will be shown in the left
// panel of Files.app. displayName
can contain any characters
// including '/', but cannot be an empty string. displayName
// must be descriptive but doesn't have to be unique. Duplicate display
// names are uniquified by adding suffix like "(1)" in the Files app UI.
//
// If a file system with the passed fileSystemId
is already
// mounted by this extension, then errorCallback
will be called
// with ProviderError.EXISTS
value. The fileSystemId
//
must not be an empty string.
static void mount(MountOptions options,
MountCallback successCallback,
[nocompile] ErrorCallback errorCallback);
// Unmounts a file system with the given fileSystemId
. It
// must be called after onUnmountRequested
is invoked. Also,
// the providing extension can decide to perform unmounting if not requested
// (eg. in case of lost connection, or a file error). If there is no file
// system with the requested id, or unmounting fails, then the
// errorCallback
will be called.
static void unmount(UnmountOptions options,
UnmountCallback successCallback,
[nocompile] ErrorCallback errorCallback);
// Returns all file systems mounted by the extension.
static void getAll(GetAllCallback callback);
};
interface Events {
// Raised when unmounting for the file system with the fileSystemId
//
identifier is requested. In the response, the unmount
//
API method must be called together with successCallback
//
. If unmounting is not possible (eg. due to a pending operation),
// then errorCallback
must be called.
[maxListeners=1] static void onUnmountRequested(
UnmountRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when metadata of a file or a directory at entryPath
// is requested. The metadata must be returned with the
// successCallback
call. In case of an error, errorCallback
//
must be called.
[maxListeners=1] static void onGetMetadataRequested(
GetMetadataRequestedOptions options,
MetadataCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when contents of a directory at directoryPath
are
// requested. The results must be returned in chunks by calling the
// successCallback
several times. In case of an error,
// errorCallback
must be called.
[maxListeners=1] static void onReadDirectoryRequested(
ReadDirectoryRequestedOptions options,
EntriesCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when opening a file at filePath
is requested. If the
// file does not exist, then the operation must fail.
[maxListeners=1] static void onOpenFileRequested(
OpenFileRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when opening a file previously opened with openRequestId
//
is requested to be closed.
[maxListeners=1] static void onCloseFileRequested(
CloseFileRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when reading contents of a file opened previously with
// openRequestId
is requested. The results must be returned in
// chunks by calling successCallback
several times. In case of
// an error, errorCallback
must be called.
[maxListeners=1] static void onReadFileRequested(
ReadFileRequestedOptions options,
FileDataCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when creating a directory is requested. The operation must fail
// with the EXISTS error if the target directory already exists.
// If recursive
is true, then all of the missing directories
// on the directory path must be created.
[maxListeners=1] static void onCreateDirectoryRequested(
CreateDirectoryRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when deleting an entry is requested. If recursive
is
// true, and the entry is a directory, then all of the entries inside
// must be recursively deleted as well.
[maxListeners=1] static void onDeleteEntryRequested(
DeleteEntryRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when creating a file is requested. If the file already exists,
// then errorCallback
must be called with the EXISTS
//
error code.
[maxListeners=1] static void onCreateFileRequested(
CreateFileRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when copying an entry (recursively if a directory) is requested.
// If an error occurs, then errorCallback
must be called.
[maxListeners=1] static void onCopyEntryRequested(
CopyEntryRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when moving an entry (recursively if a directory) is requested.
// If an error occurs, then errorCallback
must be called.
[maxListeners=1] static void onMoveEntryRequested(
MoveEntryRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when truncating a file to a desired length is requested.
// If an error occurs, then errorCallback
must be called.
[maxListeners=1] static void onTruncateRequested(
TruncateRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when writing contents to a file opened previously with
// openRequestId
is requested.
[maxListeners=1] static void onWriteFileRequested(
WriteFileRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when aborting an operation with operationRequestId
// is requested. The operation executed with operationRequestId
// must be immediately stopped and successCallback
of this
// abort request executed. If aborting fails, then errorCallback
//
must be called. Note, that callbacks of the aborted operation
// must not be called, as they will be ignored. Despite calling
// errorCallback
, the request may be forcibly aborted.
[maxListeners=1] static void onAbortRequested(
AbortRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
};
};