зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1265767 - Subset of Blink FileSystem API - patch 3 - FileEntry methods, r=smaug
This commit is contained in:
Родитель
5a7749a26f
Коммит
52fbfbc75d
|
@ -5,6 +5,7 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "DirectoryEntry.h"
|
||||
#include "ErrorCallbackRunnable.h"
|
||||
#include "mozilla/dom/Directory.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -48,5 +49,18 @@ DirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const
|
|||
mDirectory->GetPath(aPath, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
DirectoryEntry::RemoveRecursively(VoidCallback& aSuccessCallback,
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
|
||||
{
|
||||
if (aErrorCallback.WasPassed()) {
|
||||
RefPtr<ErrorCallbackRunnable> runnable =
|
||||
new ErrorCallbackRunnable(GetParentObject(),
|
||||
&aErrorCallback.Value());
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
NS_WARN_IF(NS_FAILED(rv));
|
||||
}
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
|
|
@ -65,11 +65,7 @@ public:
|
|||
|
||||
void
|
||||
RemoveRecursively(VoidCallback& aSuccessCallback,
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const;
|
||||
|
||||
private:
|
||||
~DirectoryEntry();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "Entry.h"
|
||||
#include "DirectoryEntry.h"
|
||||
#include "FileEntry.h"
|
||||
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
|
|
@ -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/. */
|
||||
|
||||
#ifndef mozilla_dom_ErrorCallbackRunnable_h
|
||||
#define mozilla_dom_ErrorCallbackRunnable_h
|
||||
|
||||
#include "mozilla/dom/DOMError.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ErrorCallbackRunnable final : public Runnable
|
||||
{
|
||||
public:
|
||||
explicit ErrorCallbackRunnable(nsIGlobalObject* aGlobalObject,
|
||||
ErrorCallback* aCallback)
|
||||
: mGlobal(aGlobalObject)
|
||||
, mCallback(aCallback)
|
||||
{
|
||||
MOZ_ASSERT(aGlobalObject);
|
||||
MOZ_ASSERT(aCallback);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
Run() override
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
|
||||
if (NS_WARN_IF(!window)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<DOMError> error =
|
||||
new DOMError(window, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
mCallback->HandleEvent(*error);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
RefPtr<ErrorCallback> mCallback;
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
#endif // mozilla_dom_ErrorCallbackRunnable_h
|
|
@ -5,11 +5,39 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "FileEntry.h"
|
||||
#include "ErrorCallbackRunnable.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
namespace {
|
||||
|
||||
class BlobCallbackRunnable final : public Runnable
|
||||
{
|
||||
public:
|
||||
BlobCallbackRunnable(BlobCallback* aCallback, File* aFile)
|
||||
: mCallback(aCallback)
|
||||
, mFile(aFile)
|
||||
{
|
||||
MOZ_ASSERT(aCallback);
|
||||
MOZ_ASSERT(aFile);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
Run() override
|
||||
{
|
||||
mCallback->HandleEvent(mFile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<BlobCallback> mCallback;
|
||||
RefPtr<File> mFile;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileEntry, Entry, mFile)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(FileEntry, Entry)
|
||||
|
@ -48,5 +76,28 @@ FileEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const
|
|||
mFile->GetPath(aPath);
|
||||
}
|
||||
|
||||
void
|
||||
FileEntry::CreateWriter(VoidCallback& aSuccessCallback,
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
|
||||
{
|
||||
if (aErrorCallback.WasPassed()) {
|
||||
RefPtr<ErrorCallbackRunnable> runnable =
|
||||
new ErrorCallbackRunnable(GetParentObject(),
|
||||
&aErrorCallback.Value());
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
NS_WARN_IF(NS_FAILED(rv));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FileEntry::GetFile(BlobCallback& aSuccessCallback,
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
|
||||
{
|
||||
RefPtr<BlobCallbackRunnable> runnable =
|
||||
new BlobCallbackRunnable(&aSuccessCallback, mFile);
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
NS_WARN_IF(NS_FAILED(rv));
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
|
|
@ -39,19 +39,11 @@ public:
|
|||
|
||||
void
|
||||
CreateWriter(VoidCallback& aSuccessCallback,
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const;
|
||||
|
||||
void
|
||||
GetFile(BlobCallback& aSuccessCallback,
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const;
|
||||
|
||||
private:
|
||||
~FileEntry();
|
||||
|
|
|
@ -62,6 +62,25 @@ function test_fileEntry() {
|
|||
next();
|
||||
}
|
||||
|
||||
function test_fileEntry_file() {
|
||||
fileEntry.file(function(file) {
|
||||
ok(file, "We have a file here!");
|
||||
is(file.name, fileEntry.name, "Same file name.");
|
||||
next();
|
||||
}, function() {
|
||||
ok(false, "Something when wrong!");
|
||||
});
|
||||
}
|
||||
|
||||
function test_fileEntry_createWriter() {
|
||||
fileEntry.createWriter(function(file) {
|
||||
ok(false, "Something when wrong!");
|
||||
}, function() {
|
||||
ok(true, "We don't support createWrite");
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
function test_directoryEntry() {
|
||||
ok("name" in directoryEntry, "We have a name.");
|
||||
ok("fullPath" in directoryEntry, "We have a fullPath.");
|
||||
|
@ -77,6 +96,9 @@ var tests = [
|
|||
test_entries,
|
||||
|
||||
test_fileEntry,
|
||||
test_fileEntry_file,
|
||||
test_fileEntry_createWriter,
|
||||
|
||||
test_directoryEntry,
|
||||
];
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ interface DirectoryEntry : Entry {
|
|||
[Throws]
|
||||
void getDirectory(DOMString? path, optional FileSystemFlags options, optional EntryCallback successCallback, optional ErrorCallback errorCallback);
|
||||
|
||||
[Throws]
|
||||
// This method is not implemented. ErrorCallback will be called with
|
||||
// NS_ERROR_DOM_NOT_SUPPORTED_ERR.
|
||||
void removeRecursively(VoidCallback successCallback, optional ErrorCallback errorCallback);
|
||||
};
|
||||
|
||||
|
@ -78,11 +79,11 @@ callback interface BlobCallback {
|
|||
[NoInterfaceObject]
|
||||
interface FileEntry : Entry {
|
||||
// the successCallback should be a FileWriteCallback but this method is not
|
||||
// implemented.
|
||||
[Throws]
|
||||
// implemented. ErrorCallback will be called with
|
||||
// NS_ERROR_DOM_NOT_SUPPORTED_ERR.
|
||||
void createWriter (VoidCallback successCallback, optional ErrorCallback errorCallback);
|
||||
|
||||
[Throws,BinaryName="GetFile"]
|
||||
[BinaryName="GetFile"]
|
||||
void file (BlobCallback successCallback, optional ErrorCallback errorCallback);
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче