Bug 1761089: Add support for getFile() to FileSystemHandles in OPFS r=dom-storage-reviewers,jari

Depends on D154482

Differential Revision: https://phabricator.services.mozilla.com/D146986
This commit is contained in:
Randell Jesup 2022-09-12 15:01:19 +00:00
Родитель 43840bc958
Коммит 095bc04f10
4 изменённых файлов: 53 добавлений и 21 удалений

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

@ -53,7 +53,7 @@ already_AddRefed<Promise> FileSystemFileHandle::GetFile(ErrorResult& aError) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
mRequestHandler->GetFile(mManager, mMetadata, promise);
return promise.forget();
}

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

@ -8,6 +8,7 @@
#include "FileSystemEntryMetadataArray.h"
#include "fs/FileSystemConstants.h"
#include "mozilla/dom/BlobImpl.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemAccessHandleChild.h"
#include "mozilla/dom/FileSystemDirectoryHandle.h"
@ -17,6 +18,7 @@
#include "mozilla/dom/FileSystemManager.h"
#include "mozilla/dom/FileSystemManagerChild.h"
#include "mozilla/dom/FileSystemSyncAccessHandle.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/quota/QuotaCommon.h"
@ -35,20 +37,6 @@ using mozilla::ipc::RejectCallback;
namespace {
// TODO: This is just a dummy implementation
RefPtr<File> MakeGetFileResult(nsIGlobalObject* aGlobal, const nsString& aName,
const nsString& aType,
int64_t aLastModifiedMilliSeconds,
nsTArray<Name>&& aPath, IPCBlob&& /* aFile */,
RefPtr<FileSystemManager>& aManager) {
// TODO: Replace with a real implementation
RefPtr<File> result = File::CreateMemoryFileWithCustomLastModified(
aGlobal, static_cast<void*>(new uint8_t[1]), sizeof(uint8_t), aName,
aType, aLastModifiedMilliSeconds);
return result;
}
bool MakeResolution(nsIGlobalObject* aGlobal,
FileSystemGetEntriesResponse&& aResponse,
const bool& /* aResult */,
@ -123,10 +111,12 @@ RefPtr<File> MakeResolution(nsIGlobalObject* aGlobal,
const Name& aName,
RefPtr<FileSystemManager>& aManager) {
auto& fileProperties = aResponse.get_FileSystemFileProperties();
return MakeGetFileResult(aGlobal, aName, fileProperties.type(),
fileProperties.last_modified_ms(),
std::move(fileProperties.path()),
std::move(fileProperties.file()), aManager);
RefPtr<File> result;
RefPtr<BlobImpl> blobImpl;
QM_TRY(OkIf(blobImpl = IPCBlobUtils::Deserialize(fileProperties.file())),
result);
result = File::Create(aGlobal, blobImpl);
return result;
}
template <class TResponse, class... Args>

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

@ -8,9 +8,11 @@
#include "FileSystemDatabaseManager.h"
#include "mozilla/Maybe.h"
#include "mozilla/dom/FileBlobImpl.h"
#include "mozilla/dom/FileSystemAccessHandleParent.h"
#include "mozilla/dom/FileSystemDataManager.h"
#include "mozilla/dom/FileSystemTypes.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/QMResult.h"
#include "mozilla/dom/quota/ForwardDecls.h"
#include "mozilla/dom/quota/QuotaCommon.h"
@ -173,7 +175,47 @@ IPCResult FileSystemManagerParent::RecvGetFile(
FileSystemGetFileRequest&& aRequest, GetFileResolver&& aResolver) {
AssertIsOnIOTarget();
FileSystemGetFileResponse response(NS_ERROR_NOT_IMPLEMENTED);
// XXX Spec https://www.w3.org/TR/FileAPI/#dfn-file wants us to snapshot the
// state of the file at getFile() time
// You can create a File with getFile() even if the file is locked
// XXX factor out this part of the code for accesshandle/ and getfile
nsString type;
TimeStamp lastModified;
nsTArray<Name> userPath;
nsCOMPtr<nsIFile> fileObject;
FileSystemEntryPair pair = {mRootEntry, aRequest.entryId()};
auto rv = mDataManager->MutableDatabaseManagerPtr()->GetFile(
pair, type, lastModified, userPath, fileObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
FileSystemGetFileResponse response(rv);
aResolver(response);
return IPC_OK();
}
if (MOZ_LOG_TEST(gOPFSLog, mozilla::LogLevel::Debug)) {
nsAutoString path;
if (NS_SUCCEEDED(fileObject->GetPath(path))) {
LOG(("Opening %s", NS_ConvertUTF16toUTF8(path).get()));
}
}
RefPtr<BlobImpl> blob = MakeRefPtr<FileBlobImpl>(fileObject);
if (blob) {
IPCBlob ipcBlob;
rv = IPCBlobUtils::Serialize(blob, ipcBlob);
if (NS_SUCCEEDED(rv)) {
FileSystemGetFileResponse response(
(FileSystemFileProperties(lastModified, ipcBlob, type, userPath)));
aResolver(response);
return IPC_OK();
}
} else {
rv = NS_ERROR_FILE_NOT_FOUND;
}
LOG(("Failed!"));
FileSystemGetFileResponse response(rv);
aResolver(response);
return IPC_OK();

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

@ -160,7 +160,7 @@ nsresult GetFileAttributes(const FileSystemConnection& aConnection,
const nsLiteralCString getFileLocation =
"SELECT type FROM Files INNER JOIN Entries USING(handle) WHERE handle = :entryId;"_ns;
// TODO: Request this from filemanager who makes the system call
// TODO: bug 1790391: Request this from filemanager who makes the system call
aLastModifiedMilliSeconds = 0;
QM_TRY_UNWRAP(ResultStatement stmt,