2014-03-05 03:26:39 +00:00
|
|
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All functions on Directory that accept DOMString arguments for file or
|
|
|
|
* directory names only allow relative path to current directory itself. The
|
|
|
|
* path should be a descendent path like "path/to/file.txt" and not contain a
|
|
|
|
* segment of ".." or ".". So the paths aren't allowed to walk up the directory
|
|
|
|
* tree. For example, paths like "../foo", "..", "/foo/bar" or "foo/../bar" are
|
|
|
|
* not allowed.
|
2015-06-22 23:31:34 +00:00
|
|
|
*
|
|
|
|
* http://w3c.github.io/filesystem-api/#idl-def-Directory
|
|
|
|
* https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface
|
2014-03-05 03:26:39 +00:00
|
|
|
*/
|
2015-06-22 23:31:34 +00:00
|
|
|
[Exposed=Window]
|
2014-03-05 03:26:39 +00:00
|
|
|
interface Directory {
|
|
|
|
/*
|
|
|
|
* The leaf name of the directory.
|
|
|
|
*/
|
|
|
|
readonly attribute DOMString name;
|
|
|
|
|
2014-03-05 08:40:48 +00:00
|
|
|
/*
|
|
|
|
* Creates a new file or replaces an existing file with given data. The file
|
|
|
|
* should be a descendent of current directory.
|
|
|
|
*
|
|
|
|
* @param path The relative path of the new file to current directory.
|
|
|
|
* @param options It has two optional properties, 'ifExists' and 'data'.
|
|
|
|
* If 'ifExists' is 'fail' and the path already exists, createFile must fail;
|
|
|
|
* If 'ifExists' is 'replace', the path already exists, and is a file, create
|
|
|
|
* a new file to replace the existing one;
|
|
|
|
* If 'ifExists' is 'replace', the path already exists, but is a directory,
|
|
|
|
* createFile must fail.
|
|
|
|
* Otherwise, if no other error occurs, createFile will create a new file.
|
|
|
|
* The 'data' property contains the new file's content.
|
|
|
|
* @return If succeeds, the promise is resolved with the new created
|
|
|
|
* File object. Otherwise, rejected with a DOM error.
|
|
|
|
*/
|
2015-06-22 23:31:34 +00:00
|
|
|
[Pref="device.storage.enabled", NewObject]
|
2014-08-01 03:50:30 +00:00
|
|
|
Promise<File> createFile(DOMString path, optional CreateFileOptions options);
|
2014-03-05 08:40:48 +00:00
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
/*
|
|
|
|
* Creates a descendent directory. This method will create any intermediate
|
|
|
|
* directories specified by the path segments.
|
|
|
|
*
|
|
|
|
* @param path The relative path of the new directory to current directory.
|
|
|
|
* If path exists, createDirectory must fail.
|
|
|
|
* @return If succeeds, the promise is resolved with the new created
|
|
|
|
* Directory object. Otherwise, rejected with a DOM error.
|
|
|
|
*/
|
2015-06-22 23:31:34 +00:00
|
|
|
[Pref="device.storage.enabled", NewObject]
|
2014-08-01 03:50:30 +00:00
|
|
|
Promise<Directory> createDirectory(DOMString path);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets a descendent file or directory with the given path.
|
|
|
|
*
|
|
|
|
* @param path The descendent entry's relative path to current directory.
|
|
|
|
* @return If the path exists and no error occurs, the promise is resolved
|
|
|
|
* with a File or Directory object, depending on the entry's type. Otherwise,
|
|
|
|
* rejected with a DOM error.
|
|
|
|
*/
|
2015-06-22 23:31:34 +00:00
|
|
|
[Pref="device.storage.enabled", NewObject]
|
2014-08-01 03:50:30 +00:00
|
|
|
Promise<(File or Directory)> get(DOMString path);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deletes a file or an empty directory. The target must be a descendent of
|
|
|
|
* current directory.
|
|
|
|
* @param path If a DOM string is passed, it is the relative path of the
|
|
|
|
* target. Otherwise, the File or Directory object of the target should be
|
|
|
|
* passed.
|
|
|
|
* @return If the target is a non-empty directory, or if deleting the target
|
|
|
|
* fails, the promise is rejected with a DOM error. If the target did not
|
|
|
|
* exist, the promise is resolved with boolean false. If the target did exist
|
|
|
|
* and was successfully deleted, the promise is resolved with boolean true.
|
|
|
|
*/
|
2015-06-22 23:31:34 +00:00
|
|
|
[Pref="device.storage.enabled", NewObject]
|
2014-08-01 03:50:30 +00:00
|
|
|
Promise<boolean> remove((DOMString or File or Directory) path);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deletes a file or a directory recursively. The target should be a
|
|
|
|
* descendent of current directory.
|
|
|
|
* @param path If a DOM string is passed, it is the relative path of the
|
|
|
|
* target. Otherwise, the File or Directory object of the target should be
|
|
|
|
* passed.
|
|
|
|
* @return If the target exists, but deleting the target fails, the promise is
|
|
|
|
* rejected with a DOM error. If the target did not exist, the promise is
|
|
|
|
* resolved with boolean false. If the target did exist and was successfully
|
|
|
|
* deleted, the promise is resolved with boolean true.
|
|
|
|
*/
|
2015-06-22 23:31:34 +00:00
|
|
|
[Pref="device.storage.enabled", NewObject]
|
2014-08-01 03:50:30 +00:00
|
|
|
Promise<boolean> removeDeep((DOMString or File or Directory) path);
|
2014-03-05 03:26:39 +00:00
|
|
|
};
|
|
|
|
|
2015-06-22 23:31:34 +00:00
|
|
|
[Exposed=Window]
|
|
|
|
partial interface Directory {
|
|
|
|
// Already defined in the main interface declaration:
|
|
|
|
//readonly attribute DOMString name;
|
|
|
|
|
|
|
|
/*
|
2015-10-12 15:18:20 +00:00
|
|
|
* The path of the Directory (includes both its basename and leafname).
|
|
|
|
* The path begins with the name of the ancestor Directory that was
|
|
|
|
* originally exposed to content (say via a directory picker) and traversed
|
|
|
|
* to obtain this Directory. Full filesystem paths are not exposed to
|
|
|
|
* unprivilaged content.
|
2015-06-22 23:31:34 +00:00
|
|
|
*/
|
|
|
|
readonly attribute DOMString path;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Getter for the immediate children of this directory.
|
|
|
|
*/
|
|
|
|
Promise<sequence<(File or Directory)>> getFilesAndDirectories();
|
|
|
|
};
|
|
|
|
|
2014-03-05 08:40:48 +00:00
|
|
|
enum CreateIfExistsMode { "replace", "fail" };
|
|
|
|
|
|
|
|
dictionary CreateFileOptions {
|
|
|
|
CreateIfExistsMode ifExists = "fail";
|
|
|
|
(DOMString or Blob or ArrayBuffer or ArrayBufferView) data;
|
|
|
|
};
|