зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1177688, part 3 - Implement .getFilesAndDirectories() and .path for DOM Directory objects. r=baku
This commit is contained in:
Родитель
0a4023ea4b
Коммит
0c5c4e6854
|
@ -9,6 +9,7 @@
|
|||
#include "CreateDirectoryTask.h"
|
||||
#include "CreateFileTask.h"
|
||||
#include "FileSystemPermissionRequest.h"
|
||||
#include "GetDirectoryListingTask.h"
|
||||
#include "GetFileOrDirectoryTask.h"
|
||||
#include "RemoveTask.h"
|
||||
|
||||
|
@ -222,6 +223,34 @@ Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
|
|||
return task->GetPromise();
|
||||
}
|
||||
|
||||
void
|
||||
Directory::GetPath(nsAString& aRetval) const
|
||||
{
|
||||
if (mPath.IsEmpty()) {
|
||||
// The Directory ctor removes any trailing '/'; this is the root directory.
|
||||
aRetval.AssignLiteral(FILESYSTEM_DOM_PATH_SEPARATOR);
|
||||
} else {
|
||||
aRetval = Substring(mPath, 0,
|
||||
mPath.RFindChar(FileSystemUtils::kSeparatorChar) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Directory::GetFilesAndDirectories()
|
||||
{
|
||||
nsresult error = NS_OK;
|
||||
nsString realPath;
|
||||
ErrorResult rv;
|
||||
nsRefPtr<GetDirectoryListingTask> task =
|
||||
new GetDirectoryListingTask(mFileSystem, mPath, rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
task->SetError(error);
|
||||
FileSystemPermissionRequest::RequestForTask(task);
|
||||
return task->GetPromise();
|
||||
}
|
||||
|
||||
FileSystemBase*
|
||||
Directory::GetFileSystem() const
|
||||
{
|
||||
|
|
|
@ -77,6 +77,14 @@ public:
|
|||
already_AddRefed<Promise>
|
||||
RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
|
||||
|
||||
// From https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface :
|
||||
|
||||
void
|
||||
GetPath(nsAString& aRetval) const;
|
||||
|
||||
already_AddRefed<Promise>
|
||||
GetFilesAndDirectories();
|
||||
|
||||
// =========== End WebIDL bindings.============
|
||||
|
||||
FileSystemBase*
|
||||
|
|
|
@ -374,6 +374,8 @@ var interfaceNamesInGlobalScope =
|
|||
{ name: "DeviceStorage", desktop: false},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "DeviceStorageChangeEvent", desktop: false},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"Directory",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "DisplayPortInputPort", b2g: true, permission: ["inputport"]},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -11,8 +11,11 @@
|
|||
* 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.
|
||||
*
|
||||
* http://w3c.github.io/filesystem-api/#idl-def-Directory
|
||||
* https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface
|
||||
*/
|
||||
[NoInterfaceObject]
|
||||
[Exposed=Window]
|
||||
interface Directory {
|
||||
/*
|
||||
* The leaf name of the directory.
|
||||
|
@ -35,7 +38,7 @@ interface Directory {
|
|||
* @return If succeeds, the promise is resolved with the new created
|
||||
* File object. Otherwise, rejected with a DOM error.
|
||||
*/
|
||||
[NewObject]
|
||||
[Pref="device.storage.enabled", NewObject]
|
||||
Promise<File> createFile(DOMString path, optional CreateFileOptions options);
|
||||
|
||||
/*
|
||||
|
@ -47,7 +50,7 @@ interface Directory {
|
|||
* @return If succeeds, the promise is resolved with the new created
|
||||
* Directory object. Otherwise, rejected with a DOM error.
|
||||
*/
|
||||
[NewObject]
|
||||
[Pref="device.storage.enabled", NewObject]
|
||||
Promise<Directory> createDirectory(DOMString path);
|
||||
|
||||
/*
|
||||
|
@ -58,7 +61,7 @@ interface Directory {
|
|||
* with a File or Directory object, depending on the entry's type. Otherwise,
|
||||
* rejected with a DOM error.
|
||||
*/
|
||||
[NewObject]
|
||||
[Pref="device.storage.enabled", NewObject]
|
||||
Promise<(File or Directory)> get(DOMString path);
|
||||
|
||||
/*
|
||||
|
@ -72,7 +75,7 @@ interface Directory {
|
|||
* exist, the promise is resolved with boolean false. If the target did exist
|
||||
* and was successfully deleted, the promise is resolved with boolean true.
|
||||
*/
|
||||
[NewObject]
|
||||
[Pref="device.storage.enabled", NewObject]
|
||||
Promise<boolean> remove((DOMString or File or Directory) path);
|
||||
|
||||
/*
|
||||
|
@ -86,10 +89,26 @@ interface Directory {
|
|||
* resolved with boolean false. If the target did exist and was successfully
|
||||
* deleted, the promise is resolved with boolean true.
|
||||
*/
|
||||
[NewObject]
|
||||
[Pref="device.storage.enabled", NewObject]
|
||||
Promise<boolean> removeDeep((DOMString or File or Directory) path);
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
partial interface Directory {
|
||||
// Already defined in the main interface declaration:
|
||||
//readonly attribute DOMString name;
|
||||
|
||||
/*
|
||||
* The base name of the directory (a relative path excluding the leaf name).
|
||||
*/
|
||||
readonly attribute DOMString path;
|
||||
|
||||
/*
|
||||
* Getter for the immediate children of this directory.
|
||||
*/
|
||||
Promise<sequence<(File or Directory)>> getFilesAndDirectories();
|
||||
};
|
||||
|
||||
enum CreateIfExistsMode { "replace", "fail" };
|
||||
|
||||
dictionary CreateFileOptions {
|
||||
|
|
Загрузка…
Ссылка в новой задаче