Bug 1750730 - Add WebIDL bindings for OPFS; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D136226
This commit is contained in:
Jan Varga 2022-01-24 12:11:29 +00:00
Родитель c94231024d
Коммит e0b6f02ea4
25 изменённых файлов: 749 добавлений и 2 удалений

Просмотреть файл

@ -284,6 +284,10 @@ DOMInterfaces = {
'concrete': True,
},
'FileSystemHandle': {
'concrete': True,
},
'FluentBundle': {
'nativeType': 'mozilla::intl::FluentBundle',
},

Просмотреть файл

@ -0,0 +1,105 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "FileSystemDirectoryHandle.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemDirectoryHandleBinding.h"
#include "mozilla/dom/FileSystemDirectoryIterator.h"
#include "mozilla/dom/FileSystemHandleBinding.h"
#include "mozilla/dom/Promise.h"
namespace mozilla::dom {
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(FileSystemDirectoryHandle,
FileSystemHandle)
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemDirectoryHandle, FileSystemHandle)
// WebIDL Boilerplate
JSObject* FileSystemDirectoryHandle::WrapObject(
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
return FileSystemDirectoryHandle_Binding::Wrap(aCx, this, aGivenProto);
}
// WebIDL Interface
FileSystemHandleKind FileSystemDirectoryHandle::Kind() {
return FileSystemHandleKind::Directory;
}
already_AddRefed<FileSystemDirectoryIterator>
FileSystemDirectoryHandle::Entries() {
return MakeRefPtr<FileSystemDirectoryIterator>(GetParentObject()).forget();
}
already_AddRefed<FileSystemDirectoryIterator>
FileSystemDirectoryHandle::Keys() {
return MakeRefPtr<FileSystemDirectoryIterator>(GetParentObject()).forget();
}
already_AddRefed<FileSystemDirectoryIterator>
FileSystemDirectoryHandle::Values() {
return MakeRefPtr<FileSystemDirectoryIterator>(GetParentObject()).forget();
}
already_AddRefed<Promise> FileSystemDirectoryHandle::GetFileHandle(
const nsAString& aName, const FileSystemGetFileOptions& aOptions) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
already_AddRefed<Promise> FileSystemDirectoryHandle::GetDirectoryHandle(
const nsAString& aName, const FileSystemGetDirectoryOptions& aOptions) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
already_AddRefed<Promise> FileSystemDirectoryHandle::RemoveEntry(
const nsAString& aName, const FileSystemRemoveOptions& aOptions) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
already_AddRefed<Promise> FileSystemDirectoryHandle::Resolve(
FileSystemHandle& aPossibleDescendant) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
} // namespace mozilla::dom

Просмотреть файл

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef DOM_FS_FILESYSTEMDIRECTORYHANDLE_H_
#define DOM_FS_FILESYSTEMDIRECTORYHANDLE_H_
#include "mozilla/dom/FileSystemHandle.h"
namespace mozilla::dom {
class FileSystemDirectoryIterator;
struct FileSystemGetFileOptions;
struct FileSystemGetDirectoryOptions;
struct FileSystemRemoveOptions;
class FileSystemDirectoryHandle final : public FileSystemHandle {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemDirectoryHandle,
FileSystemHandle)
// WebIDL Boilerplate
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL Interface
FileSystemHandleKind Kind() override;
[[nodiscard]] already_AddRefed<FileSystemDirectoryIterator> Entries();
[[nodiscard]] already_AddRefed<FileSystemDirectoryIterator> Keys();
[[nodiscard]] already_AddRefed<FileSystemDirectoryIterator> Values();
already_AddRefed<Promise> GetFileHandle(
const nsAString& aName, const FileSystemGetFileOptions& aOptions);
already_AddRefed<Promise> GetDirectoryHandle(
const nsAString& aName, const FileSystemGetDirectoryOptions& aOptions);
already_AddRefed<Promise> RemoveEntry(
const nsAString& aName, const FileSystemRemoveOptions& aOptions);
already_AddRefed<Promise> Resolve(FileSystemHandle& aPossibleDescendant);
private:
~FileSystemDirectoryHandle() = default;
};
} // namespace mozilla::dom
#endif // DOM_FS_FILESYSTEMDIRECTORYHANDLE_H_

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "FileSystemDirectoryIterator.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemDirectoryIteratorBinding.h"
#include "mozilla/dom/Promise.h"
namespace mozilla::dom {
FileSystemDirectoryIterator::FileSystemDirectoryIterator(
nsIGlobalObject* aGlobal)
: mGlobal(aGlobal) {}
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemDirectoryIterator)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemDirectoryIterator);
NS_IMPL_CYCLE_COLLECTING_RELEASE(FileSystemDirectoryIterator);
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemDirectoryIterator, mGlobal);
// WebIDL Boilerplate
nsIGlobalObject* FileSystemDirectoryIterator::GetParentObject() const {
return mGlobal;
}
JSObject* FileSystemDirectoryIterator::WrapObject(
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
return FileSystemDirectoryIterator_Binding::Wrap(aCx, this, aGivenProto);
}
// WebIDL Interface
already_AddRefed<Promise> FileSystemDirectoryIterator::Next() {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
} // namespace mozilla::dom

Просмотреть файл

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef DOM_FS_FILESYSTEMDIRECTORYITERATOR_H_
#define DOM_FS_FILESYSTEMDIRECTORYITERATOR_H_
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsWrapperCache.h"
class nsIGlobalObject;
namespace mozilla::dom {
class Promise;
class FileSystemDirectoryIterator : public nsISupports, public nsWrapperCache {
public:
explicit FileSystemDirectoryIterator(nsIGlobalObject* aGlobal);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileSystemDirectoryIterator)
// WebIDL Boilerplate
nsIGlobalObject* GetParentObject() const;
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL Interface
already_AddRefed<Promise> Next();
protected:
virtual ~FileSystemDirectoryIterator() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
};
} // namespace mozilla::dom
#endif // DOM_FS_FILESYSTEMDIRECTORYITERATOR_H_

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "FileSystemFileHandle.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemFileHandleBinding.h"
#include "mozilla/dom/FileSystemHandleBinding.h"
#include "mozilla/dom/Promise.h"
namespace mozilla::dom {
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(FileSystemFileHandle,
FileSystemHandle)
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemFileHandle, FileSystemHandle)
// WebIDL Boilerplate
JSObject* FileSystemFileHandle::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return FileSystemFileHandle_Binding::Wrap(aCx, this, aGivenProto);
}
// WebIDL Interface
FileSystemHandleKind FileSystemFileHandle::Kind() {
return FileSystemHandleKind::File;
}
already_AddRefed<Promise> FileSystemFileHandle::GetFile() {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
#ifdef MOZ_DOM_STREAMS
already_AddRefed<Promise> FileSystemFileHandle::CreateWritable(
const FileSystemCreateWritableOptions& aOptions) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
#endif
} // namespace mozilla::dom

Просмотреть файл

@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef DOM_FS_FILESYSTEMFILEHANDLE_H_
#define DOM_FS_FILESYSTEMFILEHANDLE_H_
#include "mozilla/dom/FileSystemHandle.h"
namespace mozilla::dom {
struct FileSystemCreateWritableOptions;
class FileSystemFileHandle final : public FileSystemHandle {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemFileHandle,
FileSystemHandle)
// WebIDL Boilerplate
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL interface
FileSystemHandleKind Kind() override;
already_AddRefed<Promise> GetFile();
#ifdef MOZ_DOM_STREAMS
already_AddRefed<Promise> CreateWritable(
const FileSystemCreateWritableOptions& aOptions);
#endif
private:
~FileSystemFileHandle() = default;
};
} // namespace mozilla::dom
#endif // DOM_FS_FILESYSTEMFILEHANDLE_H_

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "FileSystemHandle.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemHandleBinding.h"
#include "mozilla/dom/Promise.h"
namespace mozilla::dom {
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemHandle)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemHandle);
NS_IMPL_CYCLE_COLLECTING_RELEASE(FileSystemHandle);
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemHandle, mGlobal);
// WebIDL Boilerplate
nsIGlobalObject* FileSystemHandle::GetParentObject() const { return mGlobal; }
JSObject* FileSystemHandle::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return FileSystemHandle_Binding::Wrap(aCx, this, aGivenProto);
}
// WebIDL Interface
void FileSystemHandle::GetName(DOMString& aResult) { aResult.SetNull(); }
already_AddRefed<Promise> FileSystemHandle::IsSameEntry(
FileSystemHandle& aOther) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
} // namespace mozilla::dom

48
dom/fs/FileSystemHandle.h Normal file
Просмотреть файл

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef DOM_FS_FILESYSTEMHANDLE_H_
#define DOM_FS_FILESYSTEMHANDLE_H_
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsWrapperCache.h"
class nsIGlobalObject;
namespace mozilla::dom {
class DOMString;
enum class FileSystemHandleKind : uint8_t;
class Promise;
class FileSystemHandle : public nsISupports, public nsWrapperCache {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileSystemHandle)
// WebIDL Boilerplate
nsIGlobalObject* GetParentObject() const;
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL Interface
virtual FileSystemHandleKind Kind() = 0;
void GetName(DOMString& aResult);
already_AddRefed<Promise> IsSameEntry(FileSystemHandle& aOther);
protected:
virtual ~FileSystemHandle() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
};
} // namespace mozilla::dom
#endif // DOM_FS_FILESYSTEMHANDLE_H_

Просмотреть файл

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "FileSystemWritableFileStream.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemWritableFileStreamBinding.h"
#include "mozilla/dom/Promise.h"
namespace mozilla::dom {
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(FileSystemWritableFileStream,
WritableStream)
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemWritableFileStream, WritableStream)
// WebIDL Boilerplate
JSObject* FileSystemWritableFileStream::WrapObject(
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
return FileSystemWritableFileStream_Binding::Wrap(aCx, this, aGivenProto);
}
// WebIDL Interface
already_AddRefed<Promise> FileSystemWritableFileStream::Write(
const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
already_AddRefed<Promise> FileSystemWritableFileStream::Seek(
uint64_t aPosition) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
already_AddRefed<Promise> FileSystemWritableFileStream::Truncate(
uint64_t aSize) {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
} // namespace mozilla::dom

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_
#define DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_
#include "mozilla/dom/WritableStream.h"
namespace mozilla::dom {
class ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams;
class FileSystemWritableFileStream final : public WritableStream {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemWritableFileStream,
WritableStream)
// WebIDL Boilerplate
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL Interface
already_AddRefed<Promise> Write(
const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData);
already_AddRefed<Promise> Seek(uint64_t aPosition);
already_AddRefed<Promise> Truncate(uint64_t aSize);
private:
~FileSystemWritableFileStream() = default;
};
} // namespace mozilla::dom
#endif // DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_

31
dom/fs/moz.build Normal file
Просмотреть файл

@ -0,0 +1,31 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
EXPORTS.mozilla.dom += [
"FileSystemDirectoryHandle.h",
"FileSystemDirectoryIterator.h",
"FileSystemFileHandle.h",
"FileSystemHandle.h",
]
UNIFIED_SOURCES += [
"FileSystemDirectoryHandle.cpp",
"FileSystemDirectoryIterator.cpp",
"FileSystemFileHandle.cpp",
"FileSystemHandle.cpp",
]
if CONFIG["MOZ_DOM_STREAMS"]:
EXPORTS.mozilla.dom += [
"FileSystemWritableFileStream.h",
]
UNIFIED_SOURCES += [
"FileSystemWritableFileStream.cpp",
]
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul"

Просмотреть файл

@ -52,6 +52,7 @@ DIRS += [
"filehandle",
"filesystem",
"flex",
"fs",
"gamepad",
"geolocation",
"grid",

Просмотреть файл

@ -752,6 +752,19 @@ already_AddRefed<Promise> StorageManager::Estimate(ErrorResult& aRv) {
aRv);
}
already_AddRefed<Promise> StorageManager::GetDirectory() {
IgnoredErrorResult rv;
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StorageManager, mOwner)
NS_IMPL_CYCLE_COLLECTING_ADDREF(StorageManager)

Просмотреть файл

@ -42,6 +42,8 @@ class StorageManager final : public nsISupports, public nsWrapperCache {
already_AddRefed<Promise> Estimate(ErrorResult& aRv);
already_AddRefed<Promise> GetDirectory();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StorageManager)

Просмотреть файл

@ -29,13 +29,13 @@ class Promise;
class WritableStreamDefaultController;
class WritableStreamDefaultWriter;
class WritableStream final : public nsISupports, public nsWrapperCache {
class WritableStream : public nsISupports, public nsWrapperCache {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WritableStream)
protected:
~WritableStream();
virtual ~WritableStream();
public:
explicit WritableStream(const GlobalObject& aGlobal);

Просмотреть файл

@ -0,0 +1,35 @@
/* -*- 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/. */
dictionary FileSystemGetFileOptions {
boolean create = false;
};
dictionary FileSystemGetDirectoryOptions {
boolean create = false;
};
dictionary FileSystemRemoveOptions {
boolean recursive = false;
};
// TODO: Add Serializzable
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemDirectoryHandle : FileSystemHandle {
// This interface defines an async iterable, however that isn't supported yet
// by the bindings. So for now just explicitly define what an async iterable
// definition implies.
//async iterable<USVString, FileSystemHandle>;
FileSystemDirectoryIterator entries();
FileSystemDirectoryIterator keys();
FileSystemDirectoryIterator values();
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {});
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {});
Promise<void> removeEntry(USVString name, optional FileSystemRemoveOptions options = {});
Promise<sequence<USVString>?> resolve(FileSystemHandle possibleDescendant);
};

Просмотреть файл

@ -0,0 +1,11 @@
/* -*- 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/. */
// To implement FileSystemDirectoryHandle's async iteration until we can use
// a natively supported `async iterable`.
[Exposed=(Window,Worker), SecureContext, LegacyNoInterfaceObject]
interface FileSystemDirectoryIterator {
Promise<any> next();
};

Просмотреть файл

@ -0,0 +1,19 @@
/* -*- 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/. */
#ifdef MOZ_DOM_STREAMS
dictionary FileSystemCreateWritableOptions {
boolean keepExistingData = false;
};
#endif
// TODO: Add Serializable
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemFileHandle : FileSystemHandle {
Promise<File> getFile();
#ifdef MOZ_DOM_STREAMS
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {});
#endif
};

Просмотреть файл

@ -0,0 +1,18 @@
/* -*- 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/. */
enum FileSystemHandleKind {
"file",
"directory",
};
// TODO: Add Serializable
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemHandle {
readonly attribute FileSystemHandleKind kind;
readonly attribute USVString name;
Promise<boolean> isSameEntry(FileSystemHandle other);
};

Просмотреть файл

@ -0,0 +1,26 @@
/* -*- 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/. */
enum WriteCommandType {
"write",
"seek",
"truncate",
};
dictionary WriteParams {
required WriteCommandType type;
unsigned long long? size;
unsigned long long? position;
(BufferSource or Blob or USVString)? data;
};
typedef (BufferSource or Blob or USVString or WriteParams) FileSystemWriteChunkType;
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemWritableFileStream : WritableStream {
Promise<void> write(FileSystemWriteChunkType data);
Promise<void> seek(unsigned long long position);
Promise<void> truncate(unsigned long long size);
};

Просмотреть файл

@ -26,3 +26,9 @@ dictionary StorageEstimate {
unsigned long long usage;
unsigned long long quota;
};
[SecureContext]
partial interface StorageManager {
[Pref="dom.fs.enabled"]
Promise<FileSystemDirectoryHandle> getDirectory();
};

Просмотреть файл

@ -388,6 +388,7 @@ GENERATED_WEBIDL_FILES = [
PREPROCESSED_WEBIDL_FILES = [
"Animation.webidl",
"FileSystemFileHandle.webidl",
"Node.webidl",
"Window.webidl",
]
@ -545,9 +546,12 @@ WEBIDL_FILES = [
"FileReaderSync.webidl",
"FileSystem.webidl",
"FileSystemDirectoryEntry.webidl",
"FileSystemDirectoryHandle.webidl",
"FileSystemDirectoryIterator.webidl",
"FileSystemDirectoryReader.webidl",
"FileSystemEntry.webidl",
"FileSystemFileEntry.webidl",
"FileSystemHandle.webidl",
"FinalizationRegistry.webidl",
"FocusEvent.webidl",
"FontFace.webidl",
@ -1005,6 +1009,7 @@ WEBIDL_FILES = [
if CONFIG["MOZ_DOM_STREAMS"]:
WEBIDL_FILES += [
"FileSystemWritableFileStream.webidl",
"QueuingStrategy.webidl",
"ReadableByteStreamController.webidl",
"ReadableStream.webidl",

Просмотреть файл

@ -3456,6 +3456,12 @@
value: @IS_NOT_ANDROID@
mirror: always
# Whether the File System API is enabled
- name: dom.fs.enabled
type: RelaxedAtomicBool
value: false
mirror: always
# Should we abort LocalStorage requests when a sync message from parent is
# detected?
#

Просмотреть файл

@ -9,6 +9,7 @@
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsTHashMap.h"
#include "nsWrapperCache.h"
class nsIGlobalObject;