зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1006485 - Part a: Rename FileHandle to MutableFile and LockedFile to FileHandle; r=bent
--HG-- rename : dom/filehandle/FileHandle.cpp => dom/filehandle/MutableFile.cpp rename : dom/filehandle/FileHandle.h => dom/filehandle/MutableFile.h rename : dom/filehandle/test/test_lockedfile_lifetimes.html => dom/filehandle/test/test_filehandle_lifetimes.html rename : dom/filehandle/test/test_lockedfile_lifetimes_nested.html => dom/filehandle/test/test_filehandle_lifetimes_nested.html rename : dom/filehandle/test/test_lockedfile_ordering.html => dom/filehandle/test/test_filehandle_ordering.html rename : dom/filehandle/test/test_overlapping_lockedfiles.html => dom/filehandle/test/test_overlapping_filehandles.html rename : dom/filehandle/test/test_readonly_lockedfiles.html => dom/filehandle/test/test_readonly_filehandles.html rename : dom/indexedDB/IDBFileHandle.cpp => dom/indexedDB/IDBMutableFile.cpp rename : dom/indexedDB/IDBFileHandle.h => dom/indexedDB/IDBMutableFile.h rename : dom/webidl/IDBFileHandle.webidl => dom/webidl/IDBMutableFile.webidl rename : dom/webidl/FileHandle.webidl => dom/webidl/MutableFile.webidl
This commit is contained in:
Родитель
ae3dab62d4
Коммит
55b6d367ce
|
@ -69,7 +69,7 @@ enum DOM4ErrorTypeCodeMap {
|
|||
NotReadableError = 0,
|
||||
|
||||
/* FileHandle API errors */
|
||||
LockedFileInactiveError = 0,
|
||||
FileHandleInactiveError = 0,
|
||||
|
||||
/* WebCrypto errors https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-DataError */
|
||||
OperationError = 0,
|
||||
|
|
|
@ -23,7 +23,7 @@ enum StructuredCloneTags {
|
|||
SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE,
|
||||
|
||||
SCTAG_DOM_FILELIST,
|
||||
SCTAG_DOM_FILEHANDLE,
|
||||
SCTAG_DOM_MUTABLEFILE,
|
||||
SCTAG_DOM_FILE,
|
||||
|
||||
// These tags are used for both main thread and workers.
|
||||
|
|
|
@ -128,11 +128,11 @@ DOM_MSG_DEF(NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT , "Factory does not support s
|
|||
DOM_MSG_DEF(NS_ERROR_FACTORY_EXISTS , "Factory already exists")
|
||||
|
||||
DOM4_MSG_DEF(UnknownError, "The operation failed for reasons unrelated to the file storage itself and not covered by any other error code.", NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR)
|
||||
DOM4_MSG_DEF(LockedFileInactiveError, "A request was placed against a locked file which is currently not active, or which is finished.", NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR)
|
||||
DOM4_MSG_DEF(ReadOnlyError, "A mutation operation was attempted in a READ_ONLY locked file.", NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR)
|
||||
DOM4_MSG_DEF(FileHandleInactiveError, "A request was placed against a file handle which is currently not active, or which is finished.", NS_ERROR_DOM_FILEHANDLE_INACTIVE_ERR)
|
||||
DOM4_MSG_DEF(ReadOnlyError, "A mutation operation was attempted in a READ_ONLY file handle.", NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR)
|
||||
|
||||
DOM4_MSG_DEF(InvalidStateError, "A mutation operation was attempted on a file storage that did not allow mutations.", NS_ERROR_DOM_FILEHANDLE_NOT_ALLOWED_ERR)
|
||||
DOM4_MSG_DEF(AbortError, "A request was aborted, for example through a call to LockedFile.abort.", NS_ERROR_DOM_FILEHANDLE_ABORT_ERR)
|
||||
DOM4_MSG_DEF(QuotaExceededError, "The current locked file exceeded its quota limitations.", NS_ERROR_DOM_FILEHANDLE_QUOTA_ERR)
|
||||
DOM4_MSG_DEF(AbortError, "A request was aborted, for example through a call to FileHandle.abort.", NS_ERROR_DOM_FILEHANDLE_ABORT_ERR)
|
||||
DOM4_MSG_DEF(QuotaExceededError, "The current file handle exceeded its quota limitations.", NS_ERROR_DOM_FILEHANDLE_QUOTA_ERR)
|
||||
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_JS_EXCEPTION, "A callback threw an exception")
|
||||
|
|
|
@ -65,11 +65,11 @@
|
|||
#include "mozilla/layers/ShadowLayers.h"
|
||||
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/FileHandle.h"
|
||||
#include "mozilla/dom/FileHandleBinding.h"
|
||||
#include "mozilla/dom/TabChild.h"
|
||||
#include "mozilla/dom/IDBFactoryBinding.h"
|
||||
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
|
||||
#include "mozilla/dom/MutableFile.h"
|
||||
#include "mozilla/dom/MutableFileBinding.h"
|
||||
#include "mozilla/dom/quota/PersistenceType.h"
|
||||
#include "mozilla/dom/quota/QuotaManager.h"
|
||||
#include "nsDOMBlobBuilder.h"
|
||||
|
@ -3025,9 +3025,9 @@ nsDOMWindowUtils::GetFileId(JS::Handle<JS::Value> aFile, JSContext* aCx,
|
|||
if (!aFile.isPrimitive()) {
|
||||
JSObject* obj = aFile.toObjectOrNull();
|
||||
|
||||
FileHandle* fileHandle = nullptr;
|
||||
if (NS_SUCCEEDED(UNWRAP_OBJECT(FileHandle, obj, fileHandle))) {
|
||||
*aResult = fileHandle->GetFileId();
|
||||
MutableFile* mutableFile = nullptr;
|
||||
if (NS_SUCCEEDED(UNWRAP_OBJECT(MutableFile, obj, mutableFile))) {
|
||||
*aResult = mutableFile->GetFileId();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'FileHandle': {
|
||||
'nativeType': 'mozilla::dom::FileHandle'
|
||||
'nativeType': 'mozilla::dom::FileHandle',
|
||||
},
|
||||
|
||||
'FileList': {
|
||||
|
@ -638,10 +638,6 @@ DOMInterfaces = {
|
|||
'nativeType': 'mozilla::dom::indexedDB::IDBFactory',
|
||||
},
|
||||
|
||||
'IDBFileHandle': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBFileHandle',
|
||||
},
|
||||
|
||||
'IDBIndex': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBIndex',
|
||||
'binaryNames': {
|
||||
|
@ -655,6 +651,10 @@ DOMInterfaces = {
|
|||
'wrapperCache': False,
|
||||
},
|
||||
|
||||
'IDBMutableFile': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBMutableFile',
|
||||
},
|
||||
|
||||
'IDBObjectStore': {
|
||||
'nativeType': 'mozilla::dom::indexedDB::IDBObjectStore',
|
||||
'implicitJSContext': [ 'createIndex' ],
|
||||
|
@ -736,10 +736,6 @@ DOMInterfaces = {
|
|||
'register': False
|
||||
},
|
||||
|
||||
'LockedFile': {
|
||||
'nativeType': 'mozilla::dom::LockedFile',
|
||||
},
|
||||
|
||||
'MediaList': {
|
||||
'nativeType': 'nsMediaList',
|
||||
'headerFile': 'nsIMediaList.h',
|
||||
|
@ -875,6 +871,10 @@ DOMInterfaces = {
|
|||
'nativeType': 'mozilla::dom::Voicemail',
|
||||
},
|
||||
|
||||
'MutableFile': {
|
||||
'nativeType': 'mozilla::dom::MutableFile'
|
||||
},
|
||||
|
||||
'MutationObserver': {
|
||||
'nativeType': 'nsDOMMutationObserver',
|
||||
},
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "File.h"
|
||||
|
||||
#include "LockedFile.h"
|
||||
#include "FileHandle.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
|
@ -17,25 +17,25 @@ using indexedDB::IndexedDatabaseManager;
|
|||
|
||||
// Create as a file
|
||||
File::File(const nsAString& aName, const nsAString& aContentType,
|
||||
uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile)
|
||||
uint64_t aLength, nsIFile* aFile, FileHandle* aFileHandle)
|
||||
: nsDOMFileCC(aName, aContentType, aLength),
|
||||
mFile(aFile), mLockedFile(aLockedFile),
|
||||
mFile(aFile), mFileHandle(aFileHandle),
|
||||
mWholeFile(true), mStoredFile(false)
|
||||
{
|
||||
MOZ_ASSERT(mFile, "Null file!");
|
||||
MOZ_ASSERT(mLockedFile, "Null locked file!");
|
||||
MOZ_ASSERT(mFileHandle, "Null file handle!");
|
||||
}
|
||||
|
||||
// Create as a stored file
|
||||
File::File(const nsAString& aName, const nsAString& aContentType,
|
||||
uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile,
|
||||
uint64_t aLength, nsIFile* aFile, FileHandle* aFileHandle,
|
||||
FileInfo* aFileInfo)
|
||||
: nsDOMFileCC(aName, aContentType, aLength),
|
||||
mFile(aFile), mLockedFile(aLockedFile),
|
||||
mFile(aFile), mFileHandle(aFileHandle),
|
||||
mWholeFile(true), mStoredFile(true)
|
||||
{
|
||||
MOZ_ASSERT(mFile, "Null file!");
|
||||
MOZ_ASSERT(mLockedFile, "Null locked file!");
|
||||
MOZ_ASSERT(mFileHandle, "Null file handle!");
|
||||
mFileInfos.AppendElement(aFileInfo);
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,11 @@ File::File(const nsAString& aName, const nsAString& aContentType,
|
|||
File::File(const File* aOther, uint64_t aStart, uint64_t aLength,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFileCC(aContentType, aOther->mStart + aStart, aLength),
|
||||
mFile(aOther->mFile), mLockedFile(aOther->mLockedFile),
|
||||
mFile(aOther->mFile), mFileHandle(aOther->mFileHandle),
|
||||
mWholeFile(false), mStoredFile(aOther->mStoredFile)
|
||||
{
|
||||
NS_ASSERTION(mFile, "Null file!");
|
||||
NS_ASSERTION(mLockedFile, "Null locked file!");
|
||||
MOZ_ASSERT(mFile, "Null file!");
|
||||
MOZ_ASSERT(mFileHandle, "Null file handle!");
|
||||
|
||||
if (mStoredFile) {
|
||||
FileInfo* fileInfo;
|
||||
|
@ -69,7 +69,7 @@ File::~File()
|
|||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC,
|
||||
mLockedFile)
|
||||
mFileHandle)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC)
|
||||
|
@ -82,7 +82,7 @@ File::GetInternalStream(nsIInputStream **aStream)
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsresult rv = mLockedFile->OpenInputStream(mWholeFile, mStart, mLength,
|
||||
nsresult rv = mFileHandle->OpenInputStream(mWholeFile, mStart, mLength,
|
||||
aStream);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class LockedFile;
|
||||
class FileHandle;
|
||||
|
||||
class File : public nsDOMFileCC
|
||||
{
|
||||
|
@ -27,11 +27,11 @@ public:
|
|||
|
||||
// Create as a file
|
||||
File(const nsAString& aName, const nsAString& aContentType,
|
||||
uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile);
|
||||
uint64_t aLength, nsIFile* aFile, FileHandle* aFileHandle);
|
||||
|
||||
// Create as a stored file
|
||||
File(const nsAString& aName, const nsAString& aContentType,
|
||||
uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile,
|
||||
uint64_t aLength, nsIFile* aFile, FileHandle* aFileHandle,
|
||||
FileInfo* aFileInfo);
|
||||
|
||||
// Overrides
|
||||
|
@ -72,7 +72,7 @@ protected:
|
|||
|
||||
private:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
nsRefPtr<LockedFile> mLockedFile;
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
|
||||
bool mWholeFile;
|
||||
bool mStoredFile;
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include "FileRequest.h"
|
||||
#include "FileService.h"
|
||||
#include "js/Value.h"
|
||||
#include "LockedFile.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "MutableFile.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIRequest.h"
|
||||
|
@ -22,14 +22,14 @@ namespace dom {
|
|||
|
||||
namespace {
|
||||
|
||||
LockedFile* gCurrentLockedFile = nullptr;
|
||||
FileHandle* gCurrentFileHandle = nullptr;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
FileHelper::FileHelper(LockedFile* aLockedFile,
|
||||
FileHelper::FileHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest)
|
||||
: mFileHandle(aLockedFile->mFileHandle),
|
||||
mLockedFile(aLockedFile),
|
||||
: mMutableFile(aFileHandle->mMutableFile),
|
||||
mFileHandle(aFileHandle),
|
||||
mFileRequest(aFileRequest),
|
||||
mResultCode(NS_OK),
|
||||
mFinished(false)
|
||||
|
@ -39,7 +39,7 @@ FileHelper::FileHelper(LockedFile* aLockedFile,
|
|||
|
||||
FileHelper::~FileHelper()
|
||||
{
|
||||
MOZ_ASSERT(!mFileHandle && !mLockedFile && !mFileRequest && !mListener &&
|
||||
MOZ_ASSERT(!mMutableFile && !mFileHandle && !mFileRequest && !mListener &&
|
||||
!mRequest, "Should have cleared this!");
|
||||
}
|
||||
|
||||
|
@ -53,11 +53,11 @@ FileHelper::Enqueue()
|
|||
FileService* service = FileService::GetOrCreate();
|
||||
NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
|
||||
|
||||
nsresult rv = service->Enqueue(mLockedFile, this);
|
||||
nsresult rv = service->Enqueue(mFileHandle, this);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mLockedFile) {
|
||||
mLockedFile->OnNewRequest();
|
||||
if (mFileHandle) {
|
||||
mFileHandle->OnNewRequest();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -75,11 +75,11 @@ FileHelper::AsyncRun(FileHelperListener* aListener)
|
|||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsISupports> stream;
|
||||
if (mLockedFile->mRequestMode == LockedFile::PARALLEL) {
|
||||
rv = mLockedFile->CreateParallelStream(getter_AddRefs(stream));
|
||||
if (mFileHandle->mRequestMode == FileHandle::PARALLEL) {
|
||||
rv = mFileHandle->CreateParallelStream(getter_AddRefs(stream));
|
||||
}
|
||||
else {
|
||||
rv = mLockedFile->GetOrCreateStream(getter_AddRefs(stream));
|
||||
rv = mFileHandle->GetOrCreateStream(getter_AddRefs(stream));
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -129,7 +129,7 @@ FileHelper::OnStreamProgress(uint64_t aProgress, uint64_t aProgressMax)
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mLockedFile->IsAborted()) {
|
||||
if (mFileHandle->IsAborted()) {
|
||||
NS_ASSERTION(mRequest, "Should have a request!\n");
|
||||
|
||||
nsresult rv = mRequest->Cancel(NS_BINDING_ABORTED);
|
||||
|
@ -146,12 +146,12 @@ FileHelper::OnStreamProgress(uint64_t aProgress, uint64_t aProgressMax)
|
|||
}
|
||||
|
||||
// static
|
||||
LockedFile*
|
||||
FileHelper::GetCurrentLockedFile()
|
||||
FileHandle*
|
||||
FileHelper::GetCurrentFileHandle()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return gCurrentLockedFile;
|
||||
return gCurrentFileHandle;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -169,8 +169,8 @@ FileHelper::ReleaseObjects()
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
mMutableFile = nullptr;
|
||||
mFileHandle = nullptr;
|
||||
mLockedFile = nullptr;
|
||||
mFileRequest = nullptr;
|
||||
mListener = nullptr;
|
||||
mRequest = nullptr;
|
||||
|
@ -187,14 +187,14 @@ FileHelper::Finish()
|
|||
|
||||
mFinished = true;
|
||||
|
||||
if (mLockedFile->IsAborted()) {
|
||||
if (mFileHandle->IsAborted()) {
|
||||
// Always fire a "error" event with ABORT_ERR if the transaction was
|
||||
// aborted, even if the request succeeded or failed with another error.
|
||||
mResultCode = NS_ERROR_DOM_FILEHANDLE_ABORT_ERR;
|
||||
}
|
||||
|
||||
LockedFile* oldLockedFile = gCurrentLockedFile;
|
||||
gCurrentLockedFile = mLockedFile;
|
||||
FileHandle* oldFileHandle = gCurrentFileHandle;
|
||||
gCurrentFileHandle = mFileHandle;
|
||||
|
||||
if (mFileRequest) {
|
||||
nsresult rv = mFileRequest->NotifyHelperCompleted(this);
|
||||
|
@ -203,16 +203,16 @@ FileHelper::Finish()
|
|||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(gCurrentLockedFile == mLockedFile, "Should be unchanged!");
|
||||
gCurrentLockedFile = oldLockedFile;
|
||||
MOZ_ASSERT(gCurrentFileHandle == mFileHandle, "Should be unchanged!");
|
||||
gCurrentFileHandle = oldFileHandle;
|
||||
|
||||
mLockedFile->OnRequestFinished();
|
||||
mFileHandle->OnRequestFinished();
|
||||
|
||||
mListener->OnFileHelperComplete(this);
|
||||
|
||||
ReleaseObjects();
|
||||
|
||||
MOZ_ASSERT(!(mFileHandle || mLockedFile || mFileRequest || mListener ||
|
||||
MOZ_ASSERT(!(mMutableFile || mFileHandle || mFileRequest || mListener ||
|
||||
mRequest), "Subclass didn't call FileHelper::ReleaseObjects!");
|
||||
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class FileHelper;
|
||||
class FileHandle;
|
||||
class FileHelper;
|
||||
class FileRequest;
|
||||
class FileOutputStreamWrapper;
|
||||
class LockedFile;
|
||||
class MutableFile;
|
||||
|
||||
class FileHelperListener
|
||||
{
|
||||
|
@ -63,11 +63,11 @@ public:
|
|||
void
|
||||
OnStreamDestroy();
|
||||
|
||||
static LockedFile*
|
||||
GetCurrentLockedFile();
|
||||
static FileHandle*
|
||||
GetCurrentFileHandle();
|
||||
|
||||
protected:
|
||||
FileHelper(LockedFile* aLockedFile, FileRequest* aRequest);
|
||||
FileHelper(FileHandle* aFileHandle, FileRequest* aRequest);
|
||||
|
||||
virtual ~FileHelper();
|
||||
|
||||
|
@ -83,8 +83,8 @@ protected:
|
|||
void
|
||||
Finish();
|
||||
|
||||
nsRefPtr<MutableFile> mMutableFile;
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
nsRefPtr<LockedFile> mLockedFile;
|
||||
nsRefPtr<FileRequest> mFileRequest;
|
||||
|
||||
nsRefPtr<FileHelperListener> mListener;
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#include "FileRequest.h"
|
||||
|
||||
#include "FileHandle.h"
|
||||
#include "FileHelper.h"
|
||||
#include "js/RootingAPI.h"
|
||||
#include "jsapi.h"
|
||||
#include "LockedFile.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "mozilla/dom/FileRequestBinding.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
|
@ -38,13 +38,13 @@ FileRequest::~FileRequest()
|
|||
|
||||
// static
|
||||
already_AddRefed<FileRequest>
|
||||
FileRequest::Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile,
|
||||
FileRequest::Create(nsPIDOMWindow* aOwner, FileHandle* aFileHandle,
|
||||
bool aWrapAsDOMRequest)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsRefPtr<FileRequest> request = new FileRequest(aOwner);
|
||||
request->mLockedFile = aLockedFile;
|
||||
request->mFileHandle = aFileHandle;
|
||||
request->mWrapAsDOMRequest = aWrapAsDOMRequest;
|
||||
|
||||
return request.forget();
|
||||
|
@ -56,7 +56,7 @@ FileRequest::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
aVisitor.mCanHandle = true;
|
||||
aVisitor.mParentTarget = mLockedFile;
|
||||
aVisitor.mParentTarget = mFileHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ FileRequest::NotifyHelperCompleted(FileHelper* aFileHelper)
|
|||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileRequest, DOMRequest,
|
||||
mLockedFile)
|
||||
mFileHandle)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileRequest)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
|
||||
|
@ -121,11 +121,11 @@ FileRequest::WrapObject(JSContext* aCx)
|
|||
return FileRequestBinding::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
LockedFile*
|
||||
FileRequest::GetLockedFile() const
|
||||
FileHandle*
|
||||
FileRequest::GetFileHandle() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
return mLockedFile;
|
||||
return mFileHandle;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -21,8 +21,8 @@ class EventChainPreVisitor;
|
|||
|
||||
namespace dom {
|
||||
|
||||
class FileHandle;
|
||||
class FileHelper;
|
||||
class LockedFile;
|
||||
|
||||
class FileRequest : public DOMRequest
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileRequest, DOMRequest)
|
||||
|
||||
static already_AddRefed<FileRequest>
|
||||
Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile,
|
||||
Create(nsPIDOMWindow* aOwner, FileHandle* aFileHandle,
|
||||
bool aWrapAsDOMRequest);
|
||||
|
||||
// nsIDOMEventTarget
|
||||
|
@ -53,8 +53,14 @@ public:
|
|||
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
||||
|
||||
// WebIDL
|
||||
LockedFile*
|
||||
GetLockedFile() const;
|
||||
FileHandle*
|
||||
GetFileHandle() const;
|
||||
|
||||
FileHandle*
|
||||
GetLockedFile() const
|
||||
{
|
||||
return GetFileHandle();
|
||||
}
|
||||
|
||||
IMPL_EVENT_HANDLER(progress)
|
||||
|
||||
|
@ -65,7 +71,7 @@ protected:
|
|||
void
|
||||
FireProgressEvent(uint64_t aLoaded, uint64_t aTotal);
|
||||
|
||||
nsRefPtr<LockedFile> mLockedFile;
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
|
||||
bool mWrapAsDOMRequest;
|
||||
};
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include "FileService.h"
|
||||
|
||||
#include "FileHandle.h"
|
||||
#include "LockedFile.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "MutableFile.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
@ -146,20 +146,20 @@ FileService::IsShuttingDown()
|
|||
}
|
||||
|
||||
nsresult
|
||||
FileService::Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper)
|
||||
FileService::Enqueue(FileHandle* aFileHandle, FileHelper* aFileHelper)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aLockedFile, "Null pointer!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(aFileHandle, "Null pointer!");
|
||||
|
||||
FileHandle* fileHandle = aLockedFile->mFileHandle;
|
||||
MutableFile* mutableFile = aFileHandle->mMutableFile;
|
||||
|
||||
if (fileHandle->IsInvalid()) {
|
||||
if (mutableFile->IsInvalid()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
const nsACString& storageId = fileHandle->mStorageId;
|
||||
const nsAString& fileName = fileHandle->mFileName;
|
||||
bool modeIsWrite = aLockedFile->mMode == FileMode::Readwrite;
|
||||
const nsACString& storageId = mutableFile->mStorageId;
|
||||
const nsAString& fileName = mutableFile->mFileName;
|
||||
bool modeIsWrite = aFileHandle->mMode == FileMode::Readwrite;
|
||||
|
||||
StorageInfo* storageInfo;
|
||||
if (!mStorageInfos.Get(storageId, &storageInfo)) {
|
||||
|
@ -170,11 +170,11 @@ FileService::Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper)
|
|||
storageInfo = newStorageInfo.forget();
|
||||
}
|
||||
|
||||
LockedFileQueue* existingLockedFileQueue =
|
||||
storageInfo->GetLockedFileQueue(aLockedFile);
|
||||
FileHandleQueue* existingFileHandleQueue =
|
||||
storageInfo->GetFileHandleQueue(aFileHandle);
|
||||
|
||||
if (existingLockedFileQueue) {
|
||||
existingLockedFileQueue->Enqueue(aFileHelper);
|
||||
if (existingFileHandleQueue) {
|
||||
existingFileHandleQueue->Enqueue(aFileHelper);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -193,11 +193,11 @@ FileService::Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper)
|
|||
}
|
||||
|
||||
if (lockedForWriting || (lockedForReading && modeIsWrite)) {
|
||||
storageInfo->CreateDelayedEnqueueInfo(aLockedFile, aFileHelper);
|
||||
storageInfo->CreateDelayedEnqueueInfo(aFileHandle, aFileHelper);
|
||||
}
|
||||
else {
|
||||
LockedFileQueue* lockedFileQueue =
|
||||
storageInfo->CreateLockedFileQueue(aLockedFile);
|
||||
FileHandleQueue* fileHandleQueue =
|
||||
storageInfo->CreateFileHandleQueue(aFileHandle);
|
||||
|
||||
if (aFileHelper) {
|
||||
// Enqueue() will queue the file helper if there's already something
|
||||
|
@ -209,10 +209,10 @@ FileService::Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper)
|
|||
// callbacks when something fails. We're propagating the error here,
|
||||
// however there's no need to eventually remove storageInfo from
|
||||
// the hash table. Code behind AsyncRun() will take care of it. The last
|
||||
// item in the code path is NotifyLockedFileCompleted() which removes
|
||||
// storageInfo from the hash table if there are no locked files for
|
||||
// item in the code path is NotifyFileHandleCompleted() which removes
|
||||
// storageInfo from the hash table if there are no file handles for
|
||||
// the file storage.
|
||||
nsresult rv = lockedFileQueue->Enqueue(aFileHelper);
|
||||
nsresult rv = fileHandleQueue->Enqueue(aFileHelper);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
@ -221,23 +221,23 @@ FileService::Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper)
|
|||
}
|
||||
|
||||
void
|
||||
FileService::NotifyLockedFileCompleted(LockedFile* aLockedFile)
|
||||
FileService::NotifyFileHandleCompleted(FileHandle* aFileHandle)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aLockedFile, "Null pointer!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(aFileHandle, "Null pointer!");
|
||||
|
||||
FileHandle* fileHandle = aLockedFile->mFileHandle;
|
||||
const nsACString& storageId = fileHandle->mStorageId;
|
||||
MutableFile* mutableFile = aFileHandle->mMutableFile;
|
||||
const nsACString& storageId = mutableFile->mStorageId;
|
||||
|
||||
StorageInfo* storageInfo;
|
||||
if (!mStorageInfos.Get(storageId, &storageInfo)) {
|
||||
NS_ERROR("We don't know anyting about this locked file?!");
|
||||
NS_ERROR("We don't know anyting about this file handle?!");
|
||||
return;
|
||||
}
|
||||
|
||||
storageInfo->RemoveLockedFileQueue(aLockedFile);
|
||||
storageInfo->RemoveFileHandleQueue(aFileHandle);
|
||||
|
||||
if (!storageInfo->HasRunningLockedFiles()) {
|
||||
if (!storageInfo->HasRunningFileHandles()) {
|
||||
mStorageInfos.Remove(storageId);
|
||||
|
||||
// See if we need to fire any complete callbacks.
|
||||
|
@ -272,7 +272,7 @@ FileService::WaitForStoragesToComplete(
|
|||
}
|
||||
|
||||
void
|
||||
FileService::AbortLockedFilesForStorage(nsIOfflineStorage* aStorage)
|
||||
FileService::AbortFileHandlesForStorage(nsIOfflineStorage* aStorage)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(aStorage, "Null pointer!");
|
||||
|
@ -282,17 +282,17 @@ FileService::AbortLockedFilesForStorage(nsIOfflineStorage* aStorage)
|
|||
return;
|
||||
}
|
||||
|
||||
nsAutoTArray<nsRefPtr<LockedFile>, 10> lockedFiles;
|
||||
storageInfo->CollectRunningAndDelayedLockedFiles(aStorage, lockedFiles);
|
||||
nsAutoTArray<nsRefPtr<FileHandle>, 10> fileHandles;
|
||||
storageInfo->CollectRunningAndDelayedFileHandles(aStorage, fileHandles);
|
||||
|
||||
for (uint32_t index = 0; index < lockedFiles.Length(); index++) {
|
||||
for (uint32_t index = 0; index < fileHandles.Length(); index++) {
|
||||
ErrorResult ignored;
|
||||
lockedFiles[index]->Abort(ignored);
|
||||
fileHandles[index]->Abort(ignored);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
FileService::HasLockedFilesForStorage(nsIOfflineStorage* aStorage)
|
||||
FileService::HasFileHandlesForStorage(nsIOfflineStorage* aStorage)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(aStorage, "Null pointer!");
|
||||
|
@ -302,7 +302,7 @@ FileService::HasLockedFilesForStorage(nsIOfflineStorage* aStorage)
|
|||
return false;
|
||||
}
|
||||
|
||||
return storageInfo->HasRunningLockedFiles(aStorage);
|
||||
return storageInfo->HasRunningFileHandles(aStorage);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(FileService, nsIObserver)
|
||||
|
@ -334,22 +334,22 @@ FileService::MaybeFireCallback(StoragesCompleteCallback& aCallback)
|
|||
return true;
|
||||
}
|
||||
|
||||
FileService::LockedFileQueue::LockedFileQueue(LockedFile* aLockedFile)
|
||||
: mLockedFile(aLockedFile)
|
||||
FileService::FileHandleQueue::FileHandleQueue(FileHandle* aFileHandle)
|
||||
: mFileHandle(aFileHandle)
|
||||
{
|
||||
NS_ASSERTION(aLockedFile, "Null pointer!");
|
||||
MOZ_ASSERT(aFileHandle, "Null pointer!");
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(FileService::LockedFileQueue)
|
||||
NS_IMPL_RELEASE(FileService::LockedFileQueue)
|
||||
NS_IMPL_ADDREF(FileService::FileHandleQueue)
|
||||
NS_IMPL_RELEASE(FileService::FileHandleQueue)
|
||||
|
||||
nsresult
|
||||
FileService::LockedFileQueue::Enqueue(FileHelper* aFileHelper)
|
||||
FileService::FileHandleQueue::Enqueue(FileHelper* aFileHelper)
|
||||
{
|
||||
mQueue.AppendElement(aFileHelper);
|
||||
|
||||
nsresult rv;
|
||||
if (mLockedFile->mRequestMode == LockedFile::PARALLEL) {
|
||||
if (mFileHandle->mRequestMode == FileHandle::PARALLEL) {
|
||||
rv = aFileHelper->AsyncRun(this);
|
||||
}
|
||||
else {
|
||||
|
@ -361,9 +361,10 @@ FileService::LockedFileQueue::Enqueue(FileHelper* aFileHelper)
|
|||
}
|
||||
|
||||
void
|
||||
FileService::LockedFileQueue::OnFileHelperComplete(FileHelper* aFileHelper)
|
||||
FileService::
|
||||
FileHandleQueue::OnFileHelperComplete(FileHelper* aFileHelper)
|
||||
{
|
||||
if (mLockedFile->mRequestMode == LockedFile::PARALLEL) {
|
||||
if (mFileHandle->mRequestMode == FileHandle::PARALLEL) {
|
||||
int32_t index = mQueue.IndexOf(aFileHelper);
|
||||
NS_ASSERTION(index != -1, "We don't know anything about this helper!");
|
||||
|
||||
|
@ -382,7 +383,7 @@ FileService::LockedFileQueue::OnFileHelperComplete(FileHelper* aFileHelper)
|
|||
}
|
||||
|
||||
nsresult
|
||||
FileService::LockedFileQueue::ProcessQueue()
|
||||
FileService::FileHandleQueue::ProcessQueue()
|
||||
{
|
||||
if (mQueue.IsEmpty() || mCurrentHelper) {
|
||||
return NS_OK;
|
||||
|
@ -405,63 +406,63 @@ FileService::DelayedEnqueueInfo::~DelayedEnqueueInfo()
|
|||
{
|
||||
}
|
||||
|
||||
FileService::LockedFileQueue*
|
||||
FileService::StorageInfo::CreateLockedFileQueue(LockedFile* aLockedFile)
|
||||
FileService::FileHandleQueue*
|
||||
FileService::StorageInfo::CreateFileHandleQueue(FileHandle* aFileHandle)
|
||||
{
|
||||
nsRefPtr<LockedFileQueue>* lockedFileQueue =
|
||||
mLockedFileQueues.AppendElement();
|
||||
*lockedFileQueue = new LockedFileQueue(aLockedFile);
|
||||
return lockedFileQueue->get();
|
||||
nsRefPtr<FileHandleQueue>* fileHandleQueue =
|
||||
mFileHandleQueues.AppendElement();
|
||||
*fileHandleQueue = new FileHandleQueue(aFileHandle);
|
||||
return fileHandleQueue->get();
|
||||
}
|
||||
|
||||
FileService::LockedFileQueue*
|
||||
FileService::StorageInfo::GetLockedFileQueue(LockedFile* aLockedFile)
|
||||
FileService::FileHandleQueue*
|
||||
FileService::StorageInfo::GetFileHandleQueue(FileHandle* aFileHandle)
|
||||
{
|
||||
uint32_t count = mLockedFileQueues.Length();
|
||||
uint32_t count = mFileHandleQueues.Length();
|
||||
for (uint32_t index = 0; index < count; index++) {
|
||||
nsRefPtr<LockedFileQueue>& lockedFileQueue = mLockedFileQueues[index];
|
||||
if (lockedFileQueue->mLockedFile == aLockedFile) {
|
||||
return lockedFileQueue;
|
||||
nsRefPtr<FileHandleQueue>& fileHandleQueue = mFileHandleQueues[index];
|
||||
if (fileHandleQueue->mFileHandle == aFileHandle) {
|
||||
return fileHandleQueue;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
FileService::StorageInfo::RemoveLockedFileQueue(LockedFile* aLockedFile)
|
||||
FileService::StorageInfo::RemoveFileHandleQueue(FileHandle* aFileHandle)
|
||||
{
|
||||
for (uint32_t index = 0; index < mDelayedEnqueueInfos.Length(); index++) {
|
||||
if (mDelayedEnqueueInfos[index].mLockedFile == aLockedFile) {
|
||||
NS_ASSERTION(!mDelayedEnqueueInfos[index].mFileHelper, "Should be null!");
|
||||
if (mDelayedEnqueueInfos[index].mFileHandle == aFileHandle) {
|
||||
MOZ_ASSERT(!mDelayedEnqueueInfos[index].mFileHelper, "Should be null!");
|
||||
mDelayedEnqueueInfos.RemoveElementAt(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t lockedFileCount = mLockedFileQueues.Length();
|
||||
uint32_t fileHandleCount = mFileHandleQueues.Length();
|
||||
|
||||
// We can't just remove entries from lock hash tables, we have to rebuild
|
||||
// them instead. Multiple LockedFile objects may lock the same file
|
||||
// them instead. Multiple FileHandle objects may lock the same file
|
||||
// (one entry can represent multiple locks).
|
||||
|
||||
mFilesReading.Clear();
|
||||
mFilesWriting.Clear();
|
||||
|
||||
for (uint32_t index = 0, count = lockedFileCount; index < count; index++) {
|
||||
LockedFile* lockedFile = mLockedFileQueues[index]->mLockedFile;
|
||||
if (lockedFile == aLockedFile) {
|
||||
NS_ASSERTION(count == lockedFileCount, "More than one match?!");
|
||||
for (uint32_t index = 0, count = fileHandleCount; index < count; index++) {
|
||||
FileHandle* fileHandle = mFileHandleQueues[index]->mFileHandle;
|
||||
if (fileHandle == aFileHandle) {
|
||||
MOZ_ASSERT(count == fileHandleCount, "More than one match?!");
|
||||
|
||||
mLockedFileQueues.RemoveElementAt(index);
|
||||
mFileHandleQueues.RemoveElementAt(index);
|
||||
index--;
|
||||
count--;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const nsAString& fileName = lockedFile->mFileHandle->mFileName;
|
||||
const nsAString& fileName = fileHandle->mMutableFile->mFileName;
|
||||
|
||||
if (lockedFile->mMode == FileMode::Readwrite) {
|
||||
if (fileHandle->mMode == FileMode::Readwrite) {
|
||||
if (!IsFileLockedForWriting(fileName)) {
|
||||
LockFileForWriting(fileName);
|
||||
}
|
||||
|
@ -473,15 +474,15 @@ FileService::StorageInfo::RemoveLockedFileQueue(LockedFile* aLockedFile)
|
|||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(mLockedFileQueues.Length() == lockedFileCount - 1,
|
||||
"Didn't find the locked file we were looking for!");
|
||||
MOZ_ASSERT(mFileHandleQueues.Length() == fileHandleCount - 1,
|
||||
"Didn't find the file handle we were looking for!");
|
||||
|
||||
nsTArray<DelayedEnqueueInfo> delayedEnqueueInfos;
|
||||
delayedEnqueueInfos.SwapElements(mDelayedEnqueueInfos);
|
||||
|
||||
for (uint32_t index = 0; index < delayedEnqueueInfos.Length(); index++) {
|
||||
DelayedEnqueueInfo& delayedEnqueueInfo = delayedEnqueueInfos[index];
|
||||
if (NS_FAILED(gInstance->Enqueue(delayedEnqueueInfo.mLockedFile,
|
||||
if (NS_FAILED(gInstance->Enqueue(delayedEnqueueInfo.mFileHandle,
|
||||
delayedEnqueueInfo.mFileHelper))) {
|
||||
NS_WARNING("Enqueue failed!");
|
||||
}
|
||||
|
@ -489,11 +490,11 @@ FileService::StorageInfo::RemoveLockedFileQueue(LockedFile* aLockedFile)
|
|||
}
|
||||
|
||||
bool
|
||||
FileService::StorageInfo::HasRunningLockedFiles(nsIOfflineStorage* aStorage)
|
||||
FileService::StorageInfo::HasRunningFileHandles(nsIOfflineStorage* aStorage)
|
||||
{
|
||||
for (uint32_t index = 0; index < mLockedFileQueues.Length(); index++) {
|
||||
LockedFile* lockedFile = mLockedFileQueues[index]->mLockedFile;
|
||||
if (lockedFile->mFileHandle->Storage() == aStorage) {
|
||||
for (uint32_t index = 0; index < mFileHandleQueues.Length(); index++) {
|
||||
FileHandle* fileHandle = mFileHandleQueues[index]->mFileHandle;
|
||||
if (fileHandle->mMutableFile->Storage() == aStorage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -501,31 +502,31 @@ FileService::StorageInfo::HasRunningLockedFiles(nsIOfflineStorage* aStorage)
|
|||
}
|
||||
|
||||
FileService::DelayedEnqueueInfo*
|
||||
FileService::StorageInfo::CreateDelayedEnqueueInfo(LockedFile* aLockedFile,
|
||||
FileService::StorageInfo::CreateDelayedEnqueueInfo(FileHandle* aFileHandle,
|
||||
FileHelper* aFileHelper)
|
||||
{
|
||||
DelayedEnqueueInfo* info = mDelayedEnqueueInfos.AppendElement();
|
||||
info->mLockedFile = aLockedFile;
|
||||
info->mFileHandle = aFileHandle;
|
||||
info->mFileHelper = aFileHelper;
|
||||
return info;
|
||||
}
|
||||
|
||||
void
|
||||
FileService::StorageInfo::CollectRunningAndDelayedLockedFiles(
|
||||
FileService::StorageInfo::CollectRunningAndDelayedFileHandles(
|
||||
nsIOfflineStorage* aStorage,
|
||||
nsTArray<nsRefPtr<LockedFile> >& aLockedFiles)
|
||||
nsTArray<nsRefPtr<FileHandle>>& aFileHandles)
|
||||
{
|
||||
for (uint32_t index = 0; index < mLockedFileQueues.Length(); index++) {
|
||||
LockedFile* lockedFile = mLockedFileQueues[index]->mLockedFile;
|
||||
if (lockedFile->mFileHandle->Storage() == aStorage) {
|
||||
aLockedFiles.AppendElement(lockedFile);
|
||||
for (uint32_t index = 0; index < mFileHandleQueues.Length(); index++) {
|
||||
FileHandle* fileHandle = mFileHandleQueues[index]->mFileHandle;
|
||||
if (fileHandle->mMutableFile->Storage() == aStorage) {
|
||||
aFileHandles.AppendElement(fileHandle);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < mDelayedEnqueueInfos.Length(); index++) {
|
||||
LockedFile* lockedFile = mDelayedEnqueueInfos[index].mLockedFile;
|
||||
if (lockedFile->mFileHandle->Storage() == aStorage) {
|
||||
aLockedFiles.AppendElement(lockedFile);
|
||||
FileHandle* fileHandle = mDelayedEnqueueInfos[index].mFileHandle;
|
||||
if (fileHandle->mMutableFile->Storage() == aStorage) {
|
||||
aFileHandles.AppendElement(fileHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class nsIRunnable;
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class LockedFile;
|
||||
class FileHandle;
|
||||
|
||||
class FileService MOZ_FINAL : public nsIObserver
|
||||
{
|
||||
|
@ -50,20 +50,20 @@ public:
|
|||
IsShuttingDown();
|
||||
|
||||
nsresult
|
||||
Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper);
|
||||
Enqueue(FileHandle* aFileHandle, FileHelper* aFileHelper);
|
||||
|
||||
void
|
||||
NotifyLockedFileCompleted(LockedFile* aLockedFile);
|
||||
NotifyFileHandleCompleted(FileHandle* aFileHandle);
|
||||
|
||||
void
|
||||
WaitForStoragesToComplete(nsTArray<nsCOMPtr<nsIOfflineStorage> >& aStorages,
|
||||
nsIRunnable* aCallback);
|
||||
|
||||
void
|
||||
AbortLockedFilesForStorage(nsIOfflineStorage* aStorage);
|
||||
AbortFileHandlesForStorage(nsIOfflineStorage* aStorage);
|
||||
|
||||
bool
|
||||
HasLockedFilesForStorage(nsIOfflineStorage* aStorage);
|
||||
HasFileHandlesForStorage(nsIOfflineStorage* aStorage);
|
||||
|
||||
nsIEventTarget*
|
||||
StreamTransportTarget()
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
class LockedFileQueue MOZ_FINAL : public FileHelperListener
|
||||
class FileHandleQueue MOZ_FINAL : public FileHelperListener
|
||||
{
|
||||
friend class FileService;
|
||||
|
||||
|
@ -92,14 +92,14 @@ private:
|
|||
|
||||
private:
|
||||
inline
|
||||
LockedFileQueue(LockedFile* aLockedFile);
|
||||
FileHandleQueue(FileHandle* aFileHandle);
|
||||
|
||||
nsresult
|
||||
ProcessQueue();
|
||||
|
||||
ThreadSafeAutoRefCnt mRefCnt;
|
||||
NS_DECL_OWNINGTHREAD
|
||||
nsRefPtr<LockedFile> mLockedFile;
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
nsTArray<nsRefPtr<FileHelper> > mQueue;
|
||||
nsRefPtr<FileHelper> mCurrentHelper;
|
||||
};
|
||||
|
@ -109,7 +109,7 @@ private:
|
|||
DelayedEnqueueInfo();
|
||||
~DelayedEnqueueInfo();
|
||||
|
||||
nsRefPtr<LockedFile> mLockedFile;
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
nsRefPtr<FileHelper> mFileHelper;
|
||||
};
|
||||
|
||||
|
@ -118,31 +118,31 @@ private:
|
|||
friend class FileService;
|
||||
|
||||
public:
|
||||
inline LockedFileQueue*
|
||||
CreateLockedFileQueue(LockedFile* aLockedFile);
|
||||
inline FileHandleQueue*
|
||||
CreateFileHandleQueue(FileHandle* aFileHandle);
|
||||
|
||||
inline LockedFileQueue*
|
||||
GetLockedFileQueue(LockedFile* aLockedFile);
|
||||
inline FileHandleQueue*
|
||||
GetFileHandleQueue(FileHandle* aFileHandle);
|
||||
|
||||
void
|
||||
RemoveLockedFileQueue(LockedFile* aLockedFile);
|
||||
RemoveFileHandleQueue(FileHandle* aFileHandle);
|
||||
|
||||
bool
|
||||
HasRunningLockedFiles()
|
||||
HasRunningFileHandles()
|
||||
{
|
||||
return !mLockedFileQueues.IsEmpty();
|
||||
return !mFileHandleQueues.IsEmpty();
|
||||
}
|
||||
|
||||
inline bool
|
||||
HasRunningLockedFiles(nsIOfflineStorage* aStorage);
|
||||
HasRunningFileHandles(nsIOfflineStorage* aStorage);
|
||||
|
||||
inline DelayedEnqueueInfo*
|
||||
CreateDelayedEnqueueInfo(LockedFile* aLockedFile, FileHelper* aFileHelper);
|
||||
CreateDelayedEnqueueInfo(FileHandle* aFileHandle, FileHelper* aFileHelper);
|
||||
|
||||
inline void
|
||||
CollectRunningAndDelayedLockedFiles(
|
||||
CollectRunningAndDelayedFileHandles(
|
||||
nsIOfflineStorage* aStorage,
|
||||
nsTArray<nsRefPtr<LockedFile> >& aLockedFiles);
|
||||
nsTArray<nsRefPtr<FileHandle>>& aFileHandles);
|
||||
|
||||
void
|
||||
LockFileForReading(const nsAString& aFileName)
|
||||
|
@ -173,7 +173,7 @@ private:
|
|||
{
|
||||
}
|
||||
|
||||
nsTArray<nsRefPtr<LockedFileQueue> > mLockedFileQueues;
|
||||
nsTArray<nsRefPtr<FileHandleQueue>> mFileHandleQueues;
|
||||
nsTArray<DelayedEnqueueInfo> mDelayedEnqueueInfos;
|
||||
nsTHashtable<nsStringHashKey> mFilesReading;
|
||||
nsTHashtable<nsStringHashKey> mFilesWriting;
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#include "FileStreamWrappers.h"
|
||||
|
||||
#include "FileHandle.h"
|
||||
#include "FileHelper.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "MutableFile.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIRunnable.h"
|
||||
|
@ -252,7 +252,7 @@ FileOutputStreamWrapper::Close()
|
|||
if (!mFirstTime) {
|
||||
NS_ASSERTION(PR_GetCurrentThread() == mWriteThread,
|
||||
"Unsetting thread locals on wrong thread!");
|
||||
mFileHelper->mFileHandle->UnsetThreadLocals();
|
||||
mFileHelper->mMutableFile->UnsetThreadLocals();
|
||||
}
|
||||
|
||||
if (mFlags & NOTIFY_CLOSE) {
|
||||
|
@ -283,7 +283,7 @@ FileOutputStreamWrapper::Write(const char* aBuf, uint32_t aCount,
|
|||
#ifdef DEBUG
|
||||
mWriteThread = PR_GetCurrentThread();
|
||||
#endif
|
||||
mFileHelper->mFileHandle->SetThreadLocals();
|
||||
mFileHelper->mMutableFile->SetThreadLocals();
|
||||
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mOutputStream);
|
||||
if (seekable) {
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* 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 "LockedFile.h"
|
||||
#include "FileHandle.h"
|
||||
|
||||
#include "AsyncHelper.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileHelper.h"
|
||||
#include "FileRequest.h"
|
||||
#include "FileService.h"
|
||||
|
@ -15,8 +14,9 @@
|
|||
#include "MemoryStreams.h"
|
||||
#include "MetadataHelper.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "mozilla/dom/LockedFileBinding.h"
|
||||
#include "mozilla/dom/FileHandleBinding.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "MutableFile.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
|
@ -44,14 +44,14 @@ NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
|||
class ReadHelper : public FileHelper
|
||||
{
|
||||
public:
|
||||
ReadHelper(LockedFile* aLockedFile,
|
||||
ReadHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest,
|
||||
uint64_t aLocation,
|
||||
uint64_t aSize)
|
||||
: FileHelper(aLockedFile, aFileRequest),
|
||||
: FileHelper(aFileHandle, aFileRequest),
|
||||
mLocation(aLocation), mSize(aSize)
|
||||
{
|
||||
NS_ASSERTION(mSize, "Passed zero size!");
|
||||
MOZ_ASSERT(mSize, "Passed zero size!");
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -74,12 +74,12 @@ protected:
|
|||
class ReadTextHelper : public ReadHelper
|
||||
{
|
||||
public:
|
||||
ReadTextHelper(LockedFile* aLockedFile,
|
||||
ReadTextHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest,
|
||||
uint64_t aLocation,
|
||||
uint64_t aSize,
|
||||
const nsAString& aEncoding)
|
||||
: ReadHelper(aLockedFile, aFileRequest, aLocation, aSize),
|
||||
: ReadHelper(aFileHandle, aFileRequest, aLocation, aSize),
|
||||
mEncoding(aEncoding)
|
||||
{ }
|
||||
|
||||
|
@ -94,15 +94,15 @@ private:
|
|||
class WriteHelper : public FileHelper
|
||||
{
|
||||
public:
|
||||
WriteHelper(LockedFile* aLockedFile,
|
||||
WriteHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest,
|
||||
uint64_t aLocation,
|
||||
nsIInputStream* aStream,
|
||||
uint64_t aLength)
|
||||
: FileHelper(aLockedFile, aFileRequest),
|
||||
: FileHelper(aFileHandle, aFileRequest),
|
||||
mLocation(aLocation), mStream(aStream), mLength(aLength)
|
||||
{
|
||||
NS_ASSERTION(mLength, "Passed zero length!");
|
||||
MOZ_ASSERT(mLength, "Passed zero length!");
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -117,10 +117,10 @@ private:
|
|||
class TruncateHelper : public FileHelper
|
||||
{
|
||||
public:
|
||||
TruncateHelper(LockedFile* aLockedFile,
|
||||
TruncateHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest,
|
||||
uint64_t aOffset)
|
||||
: FileHelper(aLockedFile, aFileRequest),
|
||||
: FileHelper(aFileHandle, aFileRequest),
|
||||
mOffset(aOffset)
|
||||
{ }
|
||||
|
||||
|
@ -137,7 +137,7 @@ private:
|
|||
{ }
|
||||
protected:
|
||||
nsresult
|
||||
DoStreamWork(nsISupports* aStream);
|
||||
DoStreamWork(nsISupports* aStream) MOZ_OVERRIDE;
|
||||
|
||||
uint64_t mOffset;
|
||||
};
|
||||
|
@ -148,9 +148,9 @@ private:
|
|||
class FlushHelper : public FileHelper
|
||||
{
|
||||
public:
|
||||
FlushHelper(LockedFile* aLockedFile,
|
||||
FlushHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest)
|
||||
: FileHelper(aLockedFile, aFileRequest)
|
||||
: FileHelper(aFileHandle, aFileRequest)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
|
@ -165,18 +165,18 @@ private:
|
|||
{ }
|
||||
protected:
|
||||
nsresult
|
||||
DoStreamWork(nsISupports* aStream);
|
||||
DoStreamWork(nsISupports* aStream) MOZ_OVERRIDE;
|
||||
};
|
||||
};
|
||||
|
||||
class OpenStreamHelper : public FileHelper
|
||||
{
|
||||
public:
|
||||
OpenStreamHelper(LockedFile* aLockedFile,
|
||||
OpenStreamHelper(FileHandle* aFileHandle,
|
||||
bool aWholeFile,
|
||||
uint64_t aStart,
|
||||
uint64_t aLength)
|
||||
: FileHelper(aLockedFile, nullptr),
|
||||
: FileHelper(aFileHandle, nullptr),
|
||||
mWholeFile(aWholeFile), mStart(aStart), mLength(aLength)
|
||||
{ }
|
||||
|
||||
|
@ -214,39 +214,39 @@ CreateGenericEvent(EventTarget* aEventOwner,
|
|||
} // anonymous namespace
|
||||
|
||||
// static
|
||||
already_AddRefed<LockedFile>
|
||||
LockedFile::Create(FileHandle* aFileHandle,
|
||||
already_AddRefed<FileHandle>
|
||||
FileHandle::Create(MutableFile* aMutableFile,
|
||||
FileMode aMode,
|
||||
RequestMode aRequestMode)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsRefPtr<LockedFile> lockedFile = new LockedFile();
|
||||
nsRefPtr<FileHandle> fileHandle = new FileHandle();
|
||||
|
||||
lockedFile->BindToOwner(aFileHandle);
|
||||
fileHandle->BindToOwner(aMutableFile);
|
||||
|
||||
lockedFile->mFileHandle = aFileHandle;
|
||||
lockedFile->mMode = aMode;
|
||||
lockedFile->mRequestMode = aRequestMode;
|
||||
fileHandle->mMutableFile = aMutableFile;
|
||||
fileHandle->mMode = aMode;
|
||||
fileHandle->mRequestMode = aRequestMode;
|
||||
|
||||
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
|
||||
NS_ENSURE_TRUE(appShell, nullptr);
|
||||
|
||||
nsresult rv = appShell->RunBeforeNextEvent(lockedFile);
|
||||
nsresult rv = appShell->RunBeforeNextEvent(fileHandle);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
lockedFile->mCreating = true;
|
||||
fileHandle->mCreating = true;
|
||||
|
||||
FileService* service = FileService::GetOrCreate();
|
||||
NS_ENSURE_TRUE(service, nullptr);
|
||||
|
||||
rv = service->Enqueue(lockedFile, nullptr);
|
||||
rv = service->Enqueue(fileHandle, nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
return lockedFile.forget();
|
||||
return fileHandle.forget();
|
||||
}
|
||||
|
||||
LockedFile::LockedFile()
|
||||
FileHandle::FileHandle()
|
||||
: mReadyState(INITIAL),
|
||||
mMode(FileMode::Readonly),
|
||||
mRequestMode(NORMAL),
|
||||
|
@ -255,72 +255,71 @@ LockedFile::LockedFile()
|
|||
mAborted(false),
|
||||
mCreating(false)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
LockedFile::~LockedFile()
|
||||
FileHandle::~FileHandle()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(LockedFile, DOMEventTargetHelper,
|
||||
mFileHandle)
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileHandle, DOMEventTargetHelper,
|
||||
mMutableFile)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(LockedFile)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileHandle)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIRunnable)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(LockedFile, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(LockedFile, DOMEventTargetHelper)
|
||||
NS_IMPL_ADDREF_INHERITED(FileHandle, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(FileHandle, DOMEventTargetHelper)
|
||||
|
||||
nsresult
|
||||
LockedFile::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
||||
FileHandle::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
aVisitor.mCanHandle = true;
|
||||
aVisitor.mParentTarget = mFileHandle;
|
||||
aVisitor.mParentTarget = mMutableFile;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
LockedFile::OnNewRequest()
|
||||
FileHandle::OnNewRequest()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
if (!mPendingRequests) {
|
||||
NS_ASSERTION(mReadyState == INITIAL,
|
||||
"Reusing a locked file!");
|
||||
MOZ_ASSERT(mReadyState == INITIAL, "Reusing a file handle!");
|
||||
mReadyState = LOADING;
|
||||
}
|
||||
++mPendingRequests;
|
||||
}
|
||||
|
||||
void
|
||||
LockedFile::OnRequestFinished()
|
||||
FileHandle::OnRequestFinished()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(mPendingRequests, "Mismatched calls!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(mPendingRequests, "Mismatched calls!");
|
||||
--mPendingRequests;
|
||||
if (!mPendingRequests) {
|
||||
NS_ASSERTION(mAborted || mReadyState == LOADING,
|
||||
"Bad state!");
|
||||
mReadyState = LockedFile::FINISHING;
|
||||
MOZ_ASSERT(mAborted || mReadyState == LOADING, "Bad state!");
|
||||
mReadyState = FileHandle::FINISHING;
|
||||
Finish();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
LockedFile::CreateParallelStream(nsISupports** aStream)
|
||||
FileHandle::CreateParallelStream(nsISupports** aStream)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mFileHandle->IsInvalid()) {
|
||||
if (mMutableFile->IsInvalid()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> stream =
|
||||
mFileHandle->CreateStream(mFileHandle->mFile, mMode == FileMode::Readonly);
|
||||
mMutableFile->CreateStream(mMutableFile->mFile,
|
||||
mMode == FileMode::Readonly);
|
||||
NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
|
||||
|
||||
mParallelStreams.AppendElement(stream);
|
||||
|
@ -330,17 +329,18 @@ LockedFile::CreateParallelStream(nsISupports** aStream)
|
|||
}
|
||||
|
||||
nsresult
|
||||
LockedFile::GetOrCreateStream(nsISupports** aStream)
|
||||
FileHandle::GetOrCreateStream(nsISupports** aStream)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mFileHandle->IsInvalid()) {
|
||||
if (mMutableFile->IsInvalid()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (!mStream) {
|
||||
nsCOMPtr<nsISupports> stream =
|
||||
mFileHandle->CreateStream(mFileHandle->mFile, mMode == FileMode::Readonly);
|
||||
mMutableFile->CreateStream(mMutableFile->mFile,
|
||||
mMode == FileMode::Readonly);
|
||||
NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
|
||||
|
||||
stream.swap(mStream);
|
||||
|
@ -353,35 +353,35 @@ LockedFile::GetOrCreateStream(nsISupports** aStream)
|
|||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::GenerateFileRequest()
|
||||
FileHandle::GenerateFileRequest()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
return FileRequest::Create(GetOwner(), this, /* aWrapAsDOMRequest */ false);
|
||||
}
|
||||
|
||||
bool
|
||||
LockedFile::IsOpen() const
|
||||
FileHandle::IsOpen() const
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// If we haven't started anything then we're open.
|
||||
if (mReadyState == INITIAL) {
|
||||
NS_ASSERTION(FileHelper::GetCurrentLockedFile() != this,
|
||||
"This should be some other locked file (or null)!");
|
||||
MOZ_ASSERT(FileHelper::GetCurrentFileHandle() != this,
|
||||
"This should be some other file handle (or null)!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we've already started then we need to check to see if we still have the
|
||||
// mCreating flag set. If we do (i.e. we haven't returned to the event loop
|
||||
// from the time we were created) then we are open. Otherwise check the
|
||||
// currently running locked files to see if it's the same. We only allow other
|
||||
// requests to be made if this locked file is currently running.
|
||||
// currently running file handles to see if it's the same. We only allow other
|
||||
// requests to be made if this file handle is currently running.
|
||||
if (mReadyState == LOADING) {
|
||||
if (mCreating) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (FileHelper::GetCurrentLockedFile() == this) {
|
||||
if (FileHelper::GetCurrentFileHandle() == this) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -391,16 +391,16 @@ LockedFile::IsOpen() const
|
|||
|
||||
// virtual
|
||||
JSObject*
|
||||
LockedFile::WrapObject(JSContext* aCx)
|
||||
FileHandle::WrapObject(JSContext* aCx)
|
||||
{
|
||||
return LockedFileBinding::Wrap(aCx, this);
|
||||
return FileHandleBinding::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::GetMetadata(const DOMFileMetadataParameters& aParameters,
|
||||
FileHandle::GetMetadata(const DOMFileMetadataParameters& aParameters,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// Common state checking
|
||||
if (!CheckState(aRv)) {
|
||||
|
@ -433,9 +433,9 @@ LockedFile::GetMetadata(const DOMFileMetadataParameters& aParameters,
|
|||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::ReadAsArrayBuffer(uint64_t aSize, ErrorResult& aRv)
|
||||
FileHandle::ReadAsArrayBuffer(uint64_t aSize, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// State and argument checking for read
|
||||
if (!CheckStateAndArgumentsForRead(aSize, aRv)) {
|
||||
|
@ -464,10 +464,10 @@ LockedFile::ReadAsArrayBuffer(uint64_t aSize, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::ReadAsText(uint64_t aSize, const nsAString& aEncoding,
|
||||
FileHandle::ReadAsText(uint64_t aSize, const nsAString& aEncoding,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// State and argument checking for read
|
||||
if (!CheckStateAndArgumentsForRead(aSize, aRv)) {
|
||||
|
@ -496,9 +496,9 @@ LockedFile::ReadAsText(uint64_t aSize, const nsAString& aEncoding,
|
|||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::Truncate(const Optional<uint64_t>& aSize, ErrorResult& aRv)
|
||||
FileHandle::Truncate(const Optional<uint64_t>& aSize, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// State checking for write
|
||||
if (!CheckStateForWrite(aRv)) {
|
||||
|
@ -509,7 +509,7 @@ LockedFile::Truncate(const Optional<uint64_t>& aSize, ErrorResult& aRv)
|
|||
uint64_t location;
|
||||
if (aSize.WasPassed()) {
|
||||
// Just in case someone calls us from C++
|
||||
NS_ASSERTION(aSize.Value() != UINT64_MAX, "Passed wrong size!");
|
||||
MOZ_ASSERT(aSize.Value() != UINT64_MAX, "Passed wrong size!");
|
||||
location = aSize.Value();
|
||||
} else {
|
||||
if (mLocation == UINT64_MAX) {
|
||||
|
@ -542,9 +542,9 @@ LockedFile::Truncate(const Optional<uint64_t>& aSize, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::Flush(ErrorResult& aRv)
|
||||
FileHandle::Flush(ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// State checking for write
|
||||
if (!CheckStateForWrite(aRv)) {
|
||||
|
@ -569,16 +569,16 @@ LockedFile::Flush(ErrorResult& aRv)
|
|||
}
|
||||
|
||||
void
|
||||
LockedFile::Abort(ErrorResult& aRv)
|
||||
FileHandle::Abort(ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// This method is special enough for not using generic state checking methods.
|
||||
|
||||
// We can't use IsOpen here since we need it to be possible to call Abort()
|
||||
// even from outside of transaction callbacks.
|
||||
if (mReadyState != LockedFile::INITIAL &&
|
||||
mReadyState != LockedFile::LOADING) {
|
||||
if (mReadyState != FileHandle::INITIAL &&
|
||||
mReadyState != FileHandle::LOADING) {
|
||||
aRv.Throw(NS_ERROR_DOM_FILEHANDLE_NOT_ALLOWED_ERR);
|
||||
return;
|
||||
}
|
||||
|
@ -596,9 +596,9 @@ LockedFile::Abort(ErrorResult& aRv)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LockedFile::Run()
|
||||
FileHandle::Run()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// We're back at the event loop, no longer newborn.
|
||||
mCreating = false;
|
||||
|
@ -616,12 +616,12 @@ LockedFile::Run()
|
|||
}
|
||||
|
||||
nsresult
|
||||
LockedFile::OpenInputStream(bool aWholeFile, uint64_t aStart, uint64_t aLength,
|
||||
FileHandle::OpenInputStream(bool aWholeFile, uint64_t aStart, uint64_t aLength,
|
||||
nsIInputStream** aResult)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(mRequestMode == PARALLEL,
|
||||
"Don't call me in other than parallel mode!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(mRequestMode == PARALLEL,
|
||||
"Don't call me in other than parallel mode!");
|
||||
|
||||
// Common state checking
|
||||
ErrorResult error;
|
||||
|
@ -648,10 +648,10 @@ LockedFile::OpenInputStream(bool aWholeFile, uint64_t aStart, uint64_t aLength,
|
|||
}
|
||||
|
||||
bool
|
||||
LockedFile::CheckState(ErrorResult& aRv)
|
||||
FileHandle::CheckState(ErrorResult& aRv)
|
||||
{
|
||||
if (!IsOpen()) {
|
||||
aRv.Throw(NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR);
|
||||
aRv.Throw(NS_ERROR_DOM_FILEHANDLE_INACTIVE_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -659,7 +659,7 @@ LockedFile::CheckState(ErrorResult& aRv)
|
|||
}
|
||||
|
||||
bool
|
||||
LockedFile::CheckStateAndArgumentsForRead(uint64_t aSize, ErrorResult& aRv)
|
||||
FileHandle::CheckStateAndArgumentsForRead(uint64_t aSize, ErrorResult& aRv)
|
||||
{
|
||||
// Common state checking
|
||||
if (!CheckState(aRv)) {
|
||||
|
@ -682,7 +682,7 @@ LockedFile::CheckStateAndArgumentsForRead(uint64_t aSize, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
bool
|
||||
LockedFile::CheckStateForWrite(ErrorResult& aRv)
|
||||
FileHandle::CheckStateForWrite(ErrorResult& aRv)
|
||||
{
|
||||
// Common state checking
|
||||
if (!CheckState(aRv)) {
|
||||
|
@ -699,7 +699,7 @@ LockedFile::CheckStateForWrite(ErrorResult& aRv)
|
|||
}
|
||||
|
||||
already_AddRefed<FileRequest>
|
||||
LockedFile::WriteInternal(nsIInputStream* aInputStream, uint64_t aInputLength,
|
||||
FileHandle::WriteInternal(nsIInputStream* aInputStream, uint64_t aInputLength,
|
||||
bool aAppend, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
@ -734,14 +734,14 @@ LockedFile::WriteInternal(nsIInputStream* aInputStream, uint64_t aInputLength,
|
|||
}
|
||||
|
||||
nsresult
|
||||
LockedFile::Finish()
|
||||
FileHandle::Finish()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsRefPtr<FinishHelper> helper(new FinishHelper(this));
|
||||
|
||||
FileService* service = FileService::Get();
|
||||
NS_ASSERTION(service, "This should never be null");
|
||||
MOZ_ASSERT(service, "This should never be null");
|
||||
|
||||
nsIEventTarget* target = service->StreamTransportTarget();
|
||||
|
||||
|
@ -753,7 +753,7 @@ LockedFile::Finish()
|
|||
|
||||
// static
|
||||
already_AddRefed<nsIInputStream>
|
||||
LockedFile::GetInputStream(const ArrayBuffer& aValue, uint64_t* aInputLength,
|
||||
FileHandle::GetInputStream(const ArrayBuffer& aValue, uint64_t* aInputLength,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
aValue.ComputeLengthAndData();
|
||||
|
@ -773,7 +773,7 @@ LockedFile::GetInputStream(const ArrayBuffer& aValue, uint64_t* aInputLength,
|
|||
|
||||
// static
|
||||
already_AddRefed<nsIInputStream>
|
||||
LockedFile::GetInputStream(nsIDOMBlob* aValue, uint64_t* aInputLength,
|
||||
FileHandle::GetInputStream(nsIDOMBlob* aValue, uint64_t* aInputLength,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
uint64_t length;
|
||||
|
@ -794,7 +794,7 @@ LockedFile::GetInputStream(nsIDOMBlob* aValue, uint64_t* aInputLength,
|
|||
|
||||
// static
|
||||
already_AddRefed<nsIInputStream>
|
||||
LockedFile::GetInputStream(const nsAString& aValue, uint64_t* aInputLength,
|
||||
FileHandle::GetInputStream(const nsAString& aValue, uint64_t* aInputLength,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ConvertUTF16toUTF8 cstr(aValue);
|
||||
|
@ -809,12 +809,12 @@ LockedFile::GetInputStream(const nsAString& aValue, uint64_t* aInputLength,
|
|||
return stream.forget();
|
||||
}
|
||||
|
||||
FinishHelper::FinishHelper(LockedFile* aLockedFile)
|
||||
: mLockedFile(aLockedFile),
|
||||
mAborted(aLockedFile->mAborted)
|
||||
FinishHelper::FinishHelper(FileHandle* aFileHandle)
|
||||
: mFileHandle(aFileHandle),
|
||||
mAborted(aFileHandle->mAborted)
|
||||
{
|
||||
mParallelStreams.SwapElements(aLockedFile->mParallelStreams);
|
||||
mStream.swap(aLockedFile->mStream);
|
||||
mParallelStreams.SwapElements(aFileHandle->mParallelStreams);
|
||||
mStream.swap(aFileHandle->mStream);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(FinishHelper, nsIRunnable)
|
||||
|
@ -823,35 +823,35 @@ NS_IMETHODIMP
|
|||
FinishHelper::Run()
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
mLockedFile->mReadyState = LockedFile::DONE;
|
||||
mFileHandle->mReadyState = FileHandle::DONE;
|
||||
|
||||
FileService* service = FileService::Get();
|
||||
if (service) {
|
||||
service->NotifyLockedFileCompleted(mLockedFile);
|
||||
service->NotifyFileHandleCompleted(mFileHandle);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
if (mAborted) {
|
||||
event = CreateGenericEvent(mLockedFile, NS_LITERAL_STRING("abort"),
|
||||
event = CreateGenericEvent(mFileHandle, NS_LITERAL_STRING("abort"),
|
||||
true, false);
|
||||
}
|
||||
else {
|
||||
event = CreateGenericEvent(mLockedFile, NS_LITERAL_STRING("complete"),
|
||||
event = CreateGenericEvent(mFileHandle, NS_LITERAL_STRING("complete"),
|
||||
false, false);
|
||||
}
|
||||
NS_ENSURE_TRUE(event, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
||||
|
||||
bool dummy;
|
||||
if (NS_FAILED(mLockedFile->DispatchEvent(event, &dummy))) {
|
||||
if (NS_FAILED(mFileHandle->DispatchEvent(event, &dummy))) {
|
||||
NS_WARNING("Dispatch failed!");
|
||||
}
|
||||
|
||||
mLockedFile = nullptr;
|
||||
mFileHandle = nullptr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mLockedFile->mFileHandle->IsInvalid()) {
|
||||
if (mFileHandle->mMutableFile->IsInvalid()) {
|
||||
mAborted = true;
|
||||
}
|
||||
|
||||
|
@ -891,7 +891,7 @@ ReadHelper::Init()
|
|||
nsresult
|
||||
ReadHelper::DoAsyncRun(nsISupports* aStream)
|
||||
{
|
||||
NS_ASSERTION(aStream, "Passed a null stream!");
|
||||
MOZ_ASSERT(aStream, "Passed a null stream!");
|
||||
|
||||
uint32_t flags = FileStreamWrapper::NOTIFY_PROGRESS;
|
||||
|
||||
|
@ -899,7 +899,7 @@ ReadHelper::DoAsyncRun(nsISupports* aStream)
|
|||
new FileInputStreamWrapper(aStream, this, mLocation, mSize, flags);
|
||||
|
||||
FileService* service = FileService::Get();
|
||||
NS_ASSERTION(service, "This should never be null");
|
||||
MOZ_ASSERT(service, "This should never be null");
|
||||
|
||||
nsIEventTarget* target = service->StreamTransportTarget();
|
||||
|
||||
|
@ -966,7 +966,7 @@ ReadTextHelper::GetSuccessResult(JSContext* aCx,
|
|||
nsresult
|
||||
WriteHelper::DoAsyncRun(nsISupports* aStream)
|
||||
{
|
||||
NS_ASSERTION(aStream, "Passed a null stream!");
|
||||
MOZ_ASSERT(aStream, "Passed a null stream!");
|
||||
|
||||
uint32_t flags = FileStreamWrapper::NOTIFY_PROGRESS;
|
||||
|
||||
|
@ -974,7 +974,7 @@ WriteHelper::DoAsyncRun(nsISupports* aStream)
|
|||
new FileOutputStreamWrapper(aStream, this, mLocation, mLength, flags);
|
||||
|
||||
FileService* service = FileService::Get();
|
||||
NS_ASSERTION(service, "This should never be null");
|
||||
MOZ_ASSERT(service, "This should never be null");
|
||||
|
||||
nsIEventTarget* target = service->StreamTransportTarget();
|
||||
|
||||
|
@ -995,7 +995,7 @@ WriteHelper::DoAsyncRun(nsISupports* aStream)
|
|||
nsresult
|
||||
TruncateHelper::DoAsyncRun(nsISupports* aStream)
|
||||
{
|
||||
NS_ASSERTION(aStream, "Passed a null stream!");
|
||||
MOZ_ASSERT(aStream, "Passed a null stream!");
|
||||
|
||||
nsRefPtr<AsyncTruncator> truncator = new AsyncTruncator(aStream, mOffset);
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ TruncateHelper::AsyncTruncator::DoStreamWork(nsISupports* aStream)
|
|||
nsresult
|
||||
FlushHelper::DoAsyncRun(nsISupports* aStream)
|
||||
{
|
||||
NS_ASSERTION(aStream, "Passed a null stream!");
|
||||
MOZ_ASSERT(aStream, "Passed a null stream!");
|
||||
|
||||
nsRefPtr<AsyncFlusher> flusher = new AsyncFlusher(aStream);
|
||||
|
||||
|
@ -1046,7 +1046,7 @@ FlushHelper::AsyncFlusher::DoStreamWork(nsISupports* aStream)
|
|||
nsresult
|
||||
OpenStreamHelper::DoAsyncRun(nsISupports* aStream)
|
||||
{
|
||||
NS_ASSERTION(aStream, "Passed a null stream!");
|
||||
MOZ_ASSERT(aStream, "Passed a null stream!");
|
||||
|
||||
uint32_t flags = FileStreamWrapper::NOTIFY_CLOSE |
|
||||
FileStreamWrapper::NOTIFY_DESTROY;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* 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_LockedFile_h
|
||||
#define mozilla_dom_LockedFile_h
|
||||
#ifndef mozilla_dom_FileHandle_h
|
||||
#define mozilla_dom_FileHandle_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "MainThreadUtils.h"
|
||||
|
@ -35,14 +35,14 @@ class EventChainPreVisitor;
|
|||
namespace dom {
|
||||
|
||||
class DOMFileMetadataParameters;
|
||||
class FileHandle;
|
||||
class FileHelper;
|
||||
class FileRequest;
|
||||
class FileService;
|
||||
class FinishHelper;
|
||||
class MetadataHelper;
|
||||
class MutableFile;
|
||||
|
||||
class LockedFile : public DOMEventTargetHelper,
|
||||
class FileHandle : public DOMEventTargetHelper,
|
||||
public nsIRunnable
|
||||
{
|
||||
friend class FileHelper;
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LockedFile, DOMEventTargetHelper)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper)
|
||||
|
||||
enum RequestMode
|
||||
{
|
||||
|
@ -70,8 +70,8 @@ public:
|
|||
DONE
|
||||
};
|
||||
|
||||
static already_AddRefed<LockedFile>
|
||||
Create(FileHandle* aFileHandle,
|
||||
static already_AddRefed<FileHandle>
|
||||
Create(MutableFile* aMutableFile,
|
||||
FileMode aMode,
|
||||
RequestMode aRequestMode = NORMAL);
|
||||
|
||||
|
@ -94,10 +94,10 @@ public:
|
|||
return mAborted;
|
||||
}
|
||||
|
||||
FileHandle*
|
||||
Handle() const
|
||||
MutableFile*
|
||||
File() const
|
||||
{
|
||||
return mFileHandle;
|
||||
return mMutableFile;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -115,12 +115,18 @@ public:
|
|||
return GetOwner();
|
||||
}
|
||||
|
||||
FileHandle*
|
||||
GetFileHandle() const
|
||||
MutableFile*
|
||||
GetMutableFile() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return Handle();
|
||||
return File();
|
||||
}
|
||||
|
||||
MutableFile*
|
||||
GetFileHandle() const
|
||||
{
|
||||
return GetMutableFile();
|
||||
}
|
||||
|
||||
FileMode
|
||||
|
@ -205,8 +211,8 @@ public:
|
|||
IMPL_EVENT_HANDLER(error)
|
||||
|
||||
private:
|
||||
LockedFile();
|
||||
~LockedFile();
|
||||
FileHandle();
|
||||
~FileHandle();
|
||||
|
||||
void
|
||||
OnNewRequest();
|
||||
|
@ -279,14 +285,14 @@ private:
|
|||
GetInputStream(const nsAString& aValue, uint64_t* aInputLength,
|
||||
ErrorResult& aRv);
|
||||
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
nsRefPtr<MutableFile> mMutableFile;
|
||||
ReadyState mReadyState;
|
||||
FileMode mMode;
|
||||
RequestMode mRequestMode;
|
||||
uint64_t mLocation;
|
||||
uint32_t mPendingRequests;
|
||||
|
||||
nsTArray<nsCOMPtr<nsISupports> > mParallelStreams;
|
||||
nsTArray<nsCOMPtr<nsISupports>> mParallelStreams;
|
||||
nsCOMPtr<nsISupports> mStream;
|
||||
|
||||
bool mAborted;
|
||||
|
@ -295,19 +301,19 @@ private:
|
|||
|
||||
class FinishHelper MOZ_FINAL : public nsIRunnable
|
||||
{
|
||||
friend class LockedFile;
|
||||
friend class FileHandle;
|
||||
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
private:
|
||||
FinishHelper(LockedFile* aLockedFile);
|
||||
FinishHelper(FileHandle* aFileHandle);
|
||||
~FinishHelper()
|
||||
{ }
|
||||
|
||||
nsRefPtr<LockedFile> mLockedFile;
|
||||
nsTArray<nsCOMPtr<nsISupports> > mParallelStreams;
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
nsTArray<nsCOMPtr<nsISupports>> mParallelStreams;
|
||||
nsCOMPtr<nsISupports> mStream;
|
||||
|
||||
bool mAborted;
|
||||
|
@ -316,4 +322,4 @@ private:
|
|||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_LockedFile_h
|
||||
#endif // mozilla_dom_FileHandle_h
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#include "MetadataHelper.h"
|
||||
|
||||
#include "FileHandle.h"
|
||||
#include "js/Value.h"
|
||||
#include "js/RootingAPI.h"
|
||||
#include "jsapi.h"
|
||||
#include "LockedFile.h"
|
||||
#include "mozilla/dom/FileModeBinding.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIFileStreams.h"
|
||||
|
@ -21,7 +21,7 @@ namespace dom {
|
|||
nsresult
|
||||
MetadataHelper::DoAsyncRun(nsISupports* aStream)
|
||||
{
|
||||
bool readWrite = mLockedFile->mMode == FileMode::Readwrite;
|
||||
bool readWrite = mFileHandle->mMode == FileMode::Readwrite;
|
||||
|
||||
nsRefPtr<AsyncMetadataGetter> getter =
|
||||
new AsyncMetadataGetter(aStream, mParams, readWrite);
|
||||
|
|
|
@ -76,10 +76,10 @@ private:
|
|||
class MetadataHelper : public FileHelper
|
||||
{
|
||||
public:
|
||||
MetadataHelper(LockedFile* aLockedFile,
|
||||
MetadataHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest,
|
||||
MetadataParameters* aParams)
|
||||
: FileHelper(aLockedFile, aFileRequest),
|
||||
: FileHelper(aFileHandle, aFileRequest),
|
||||
mParams(aParams)
|
||||
{ }
|
||||
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
* 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 "FileHandle.h"
|
||||
#include "MutableFile.h"
|
||||
|
||||
#include "File.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileRequest.h"
|
||||
#include "FileService.h"
|
||||
#include "LockedFile.h"
|
||||
#include "MetadataHelper.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/dom/FileHandleBinding.h"
|
||||
#include "mozilla/dom/MutableFileBinding.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
@ -30,12 +30,12 @@ namespace {
|
|||
class GetFileHelper : public MetadataHelper
|
||||
{
|
||||
public:
|
||||
GetFileHelper(LockedFile* aLockedFile,
|
||||
GetFileHelper(FileHandle* aFileHandle,
|
||||
FileRequest* aFileRequest,
|
||||
MetadataParameters* aParams,
|
||||
FileHandle* aFileHandle)
|
||||
: MetadataHelper(aLockedFile, aFileRequest, aParams),
|
||||
mFileHandle(aFileHandle)
|
||||
MutableFile* aMutableFile)
|
||||
: MetadataHelper(aFileHandle, aFileRequest, aParams),
|
||||
mMutableFile(aMutableFile)
|
||||
{ }
|
||||
|
||||
virtual nsresult
|
||||
|
@ -45,40 +45,40 @@ public:
|
|||
virtual void
|
||||
ReleaseObjects() MOZ_OVERRIDE
|
||||
{
|
||||
mFileHandle = nullptr;
|
||||
mMutableFile = nullptr;
|
||||
|
||||
MetadataHelper::ReleaseObjects();
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<FileHandle> mFileHandle;
|
||||
nsRefPtr<MutableFile> mMutableFile;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
FileHandle::FileHandle(nsPIDOMWindow* aWindow)
|
||||
MutableFile::MutableFile(nsPIDOMWindow* aWindow)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
{
|
||||
}
|
||||
|
||||
FileHandle::FileHandle(DOMEventTargetHelper* aOwner)
|
||||
MutableFile::MutableFile(DOMEventTargetHelper* aOwner)
|
||||
: DOMEventTargetHelper(aOwner)
|
||||
{
|
||||
}
|
||||
|
||||
FileHandle::~FileHandle()
|
||||
MutableFile::~MutableFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
FileHandle::IsShuttingDown()
|
||||
MutableFile::IsShuttingDown()
|
||||
{
|
||||
return FileService::IsShuttingDown();
|
||||
}
|
||||
|
||||
// virtual
|
||||
already_AddRefed<nsISupports>
|
||||
FileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
|
||||
MutableFile::CreateStream(nsIFile* aFile, bool aReadOnly)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -103,23 +103,23 @@ FileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
|
|||
|
||||
// virtual
|
||||
already_AddRefed<nsIDOMFile>
|
||||
FileHandle::CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize)
|
||||
MutableFile::CreateFileObject(FileHandle* aFileHandle, uint32_t aFileSize)
|
||||
{
|
||||
nsCOMPtr<nsIDOMFile> file =
|
||||
new File(mName, mType, aFileSize, mFile, aLockedFile);
|
||||
new File(mName, mType, aFileSize, mFile, aFileHandle);
|
||||
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
// virtual
|
||||
JSObject*
|
||||
FileHandle::WrapObject(JSContext* aCx)
|
||||
MutableFile::WrapObject(JSContext* aCx)
|
||||
{
|
||||
return FileHandleBinding::Wrap(aCx, this);
|
||||
return MutableFileBinding::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
already_AddRefed<LockedFile>
|
||||
FileHandle::Open(FileMode aMode, ErrorResult& aError)
|
||||
already_AddRefed<FileHandle>
|
||||
MutableFile::Open(FileMode aMode, ErrorResult& aError)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -128,17 +128,17 @@ FileHandle::Open(FileMode aMode, ErrorResult& aError)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<LockedFile> lockedFile = LockedFile::Create(this, aMode);
|
||||
if (!lockedFile) {
|
||||
nsRefPtr<FileHandle> fileHandle = FileHandle::Create(this, aMode);
|
||||
if (!fileHandle) {
|
||||
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return lockedFile.forget();
|
||||
return fileHandle.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
FileHandle::GetFile(ErrorResult& aError)
|
||||
MutableFile::GetFile(ErrorResult& aError)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -147,20 +147,20 @@ FileHandle::GetFile(ErrorResult& aError)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<LockedFile> lockedFile =
|
||||
LockedFile::Create(this, FileMode::Readonly, LockedFile::PARALLEL);
|
||||
if (!lockedFile) {
|
||||
nsRefPtr<FileHandle> fileHandle =
|
||||
FileHandle::Create(this, FileMode::Readonly, FileHandle::PARALLEL);
|
||||
if (!fileHandle) {
|
||||
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<FileRequest> request =
|
||||
FileRequest::Create(GetOwner(), lockedFile, /* aWrapAsDOMRequest */ true);
|
||||
FileRequest::Create(GetOwner(), fileHandle, /* aWrapAsDOMRequest */ true);
|
||||
|
||||
nsRefPtr<MetadataParameters> params = new MetadataParameters(true, false);
|
||||
|
||||
nsRefPtr<GetFileHelper> helper =
|
||||
new GetFileHelper(lockedFile, request, params, this);
|
||||
new GetFileHelper(fileHandle, request, params, this);
|
||||
|
||||
nsresult rv = helper->Enqueue();
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -176,7 +176,7 @@ GetFileHelper::GetSuccessResult(JSContext* aCx,
|
|||
JS::MutableHandle<JS::Value> aVal)
|
||||
{
|
||||
nsCOMPtr<nsIDOMFile> domFile =
|
||||
mFileHandle->CreateFileObject(mLockedFile, mParams->Size());
|
||||
mMutableFile->CreateFileObject(mFileHandle, mParams->Size());
|
||||
|
||||
nsresult rv =
|
||||
nsContentUtils::WrapNative(aCx, domFile, &NS_GET_IID(nsIDOMFile), aVal);
|
|
@ -4,8 +4,8 @@
|
|||
* 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_FileHandle_h
|
||||
#define mozilla_dom_FileHandle_h
|
||||
#ifndef mozilla_dom_MutableFile_h
|
||||
#define mozilla_dom_MutableFile_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
@ -26,8 +26,8 @@ class ErrorResult;
|
|||
namespace dom {
|
||||
|
||||
class DOMRequest;
|
||||
class FileHandle;
|
||||
class FileService;
|
||||
class LockedFile;
|
||||
class FinishHelper;
|
||||
class FileHelper;
|
||||
|
||||
|
@ -36,16 +36,16 @@ class FileInfo;
|
|||
} // namespace indexedDB
|
||||
|
||||
/**
|
||||
* This class provides a default FileHandle implementation, but it can be also
|
||||
* This class provides a default MutableFile implementation, but it can be also
|
||||
* subclassed. The subclass can override implementation of GetFileId,
|
||||
* GetFileInfo, IsShuttingDown, IsInvalid, CreateStream, SetThreadLocals,
|
||||
* UnsetThreadLocals and CreateFileObject.
|
||||
* (for example IDBFileHandle provides IndexedDB specific implementation).
|
||||
* (for example IDBMutableFile provides IndexedDB specific implementation).
|
||||
*/
|
||||
class FileHandle : public DOMEventTargetHelper
|
||||
class MutableFile : public DOMEventTargetHelper
|
||||
{
|
||||
friend class FileHandle;
|
||||
friend class FileService;
|
||||
friend class LockedFile;
|
||||
friend class FinishHelper;
|
||||
friend class FileHelper;
|
||||
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
}
|
||||
|
||||
virtual already_AddRefed<nsIDOMFile>
|
||||
CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize);
|
||||
CreateFileObject(FileHandle* aFileHandle, uint32_t aFileSize);
|
||||
|
||||
// nsWrapperCache
|
||||
virtual JSObject*
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
aType = mType;
|
||||
}
|
||||
|
||||
already_AddRefed<LockedFile>
|
||||
already_AddRefed<FileHandle>
|
||||
Open(FileMode aMode, ErrorResult& aError);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
|
@ -137,11 +137,11 @@ public:
|
|||
IMPL_EVENT_HANDLER(error)
|
||||
|
||||
protected:
|
||||
FileHandle(nsPIDOMWindow* aWindow);
|
||||
MutableFile(nsPIDOMWindow* aWindow);
|
||||
|
||||
FileHandle(DOMEventTargetHelper* aOwner);
|
||||
MutableFile(DOMEventTargetHelper* aOwner);
|
||||
|
||||
virtual ~FileHandle();
|
||||
virtual ~MutableFile();
|
||||
|
||||
nsString mName;
|
||||
nsString mType;
|
||||
|
@ -155,4 +155,4 @@ protected:
|
|||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FileHandle_h
|
||||
#endif // mozilla_dom_MutableFile_h
|
|
@ -12,7 +12,7 @@ EXPORTS.mozilla.dom += [
|
|||
'FileHelper.h',
|
||||
'FileRequest.h',
|
||||
'FileService.h',
|
||||
'LockedFile.h',
|
||||
'MutableFile.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
|
@ -23,9 +23,9 @@ UNIFIED_SOURCES += [
|
|||
'FileRequest.cpp',
|
||||
'FileService.cpp',
|
||||
'FileStreamWrappers.cpp',
|
||||
'LockedFile.cpp',
|
||||
'MemoryStreams.cpp',
|
||||
'MetadataHelper.cpp',
|
||||
'MutableFile.cpp',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
|
|
@ -98,6 +98,38 @@ function resetUnlimitedQuota(url)
|
|||
removePermission("indexedDB-unlimited", url);
|
||||
}
|
||||
|
||||
function getMutableFile(fileStorageKey, name)
|
||||
{
|
||||
var requestService = SpecialPowers.getDOMRequestService();
|
||||
var request = requestService.createRequest(window);
|
||||
|
||||
switch (fileStorageKey) {
|
||||
case IndexedDatabaseKey:
|
||||
var dbname = window.location.pathname;
|
||||
indexedDB.open(dbname, 1).onsuccess = function(event) {
|
||||
var db = event.target.result;
|
||||
db.createMutableFile(name).onsuccess = function(event) {
|
||||
var fileHandle = event.target.result;
|
||||
requestService.fireSuccess(request, fileHandle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceStorageKey:
|
||||
var dbname = window.location.pathname;
|
||||
indexedDB.open(dbname, 1).onsuccess = function(event) {
|
||||
var db = event.target.result;
|
||||
db.createMutableFile(name).onsuccess = function(event) {
|
||||
var fileHandle = event.target.result;
|
||||
requestService.fireSuccess(request, fileHandle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
function getFileHandle(fileStorageKey, name)
|
||||
{
|
||||
var requestService = SpecialPowers.getDOMRequestService();
|
||||
|
|
|
@ -6,22 +6,24 @@ support-files =
|
|||
|
||||
[test_append_read_data.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_compat.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_filehandle_lifetimes.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_filehandle_lifetimes_nested.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_filehandle_ordering.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_getFile.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_getFileId.html]
|
||||
[test_location.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_lockedfile_lifetimes.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_lockedfile_lifetimes_nested.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_lockedfile_ordering.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_overlapping_lockedfiles.html]
|
||||
[test_overlapping_filehandles.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_progress_events.html]
|
||||
skip-if = buildapp == 'b2g' # b2g(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:109) b2g-debug(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:109) b2g-desktop(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:109)
|
||||
[test_readonly_lockedfiles.html]
|
||||
[test_readonly_filehandles.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
[test_request_readyState.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
|
|
|
@ -22,65 +22,65 @@
|
|||
var testBlob = getBlob("binary/random", testBuffer);
|
||||
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let location = 0;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
|
||||
request = lockedFile.append(testString);
|
||||
ok(lockedFile.location === null, "Correct location");
|
||||
request = fileHandle.append(testString);
|
||||
ok(fileHandle.location === null, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.location = 0;
|
||||
request = lockedFile.readAsText(testString.length);
|
||||
fileHandle.location = 0;
|
||||
request = fileHandle.readAsText(testString.length);
|
||||
location += testString.length
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let resultString = event.target.result;
|
||||
ok(resultString == testString, "Correct string data");
|
||||
|
||||
request = lockedFile.append(testBuffer);
|
||||
ok(lockedFile.location === null, "Correct location");
|
||||
request = fileHandle.append(testBuffer);
|
||||
ok(fileHandle.location === null, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.location = location;
|
||||
request = lockedFile.readAsArrayBuffer(testBuffer.byteLength);
|
||||
fileHandle.location = location;
|
||||
request = fileHandle.readAsArrayBuffer(testBuffer.byteLength);
|
||||
location += testBuffer.byteLength;
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let resultBuffer = event.target.result;
|
||||
ok(compareBuffers(resultBuffer, testBuffer), "Correct array buffer data");
|
||||
|
||||
request = lockedFile.append(testBlob);
|
||||
ok(lockedFile.location === null, "Correct location");
|
||||
request = fileHandle.append(testBlob);
|
||||
ok(fileHandle.location === null, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.location = location;
|
||||
request = lockedFile.readAsArrayBuffer(testBlob.size);
|
||||
fileHandle.location = location;
|
||||
request = fileHandle.readAsArrayBuffer(testBlob.size);
|
||||
location += testBlob.size;
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
resultBuffer = event.target.result;
|
||||
ok(compareBuffers(resultBuffer, testBuffer), "Correct blob data");
|
||||
|
||||
request = lockedFile.getMetadata({ size: true });
|
||||
request = fileHandle.getMetadata({ size: true });
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>File Handle Test</title>
|
||||
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open();
|
||||
ok(lockedFile.fileHandle === fileHandle, "Correct property");
|
||||
|
||||
request = lockedFile.getMetadata({ size: true });
|
||||
ok(request.lockedFile === lockedFile, "Correct property");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield undefined;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="runTest();"></body>
|
||||
|
||||
</html>
|
|
@ -13,25 +13,25 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open();
|
||||
let fileHandle = mutableFile.open();
|
||||
continueToNextStep();
|
||||
yield undefined;
|
||||
|
||||
try {
|
||||
lockedFile.getMetadata({ size: true });
|
||||
fileHandle.getMetadata({ size: true });
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(e instanceof DOMException, "Got exception.");
|
||||
is(e.name, "LockedFileInactiveError", "Good error.");
|
||||
is(e.name, "FileHandleInactiveError", "Good error.");
|
||||
is(e.code, 0, "Good error code.");
|
||||
}
|
||||
}
|
|
@ -13,17 +13,17 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open();
|
||||
let fileHandle = mutableFile.open();
|
||||
|
||||
let lockedFile2;
|
||||
let fileHandle2;
|
||||
|
||||
let comp = SpecialPowers.wrap(SpecialPowers.Components);
|
||||
let thread = comp.classes["@mozilla.org/thread-manager;1"]
|
||||
|
@ -35,14 +35,14 @@
|
|||
thread.dispatch(function() {
|
||||
eventHasRun = true;
|
||||
|
||||
lockedFile2 = fileHandle.open();
|
||||
fileHandle2 = mutableFile.open();
|
||||
}, SpecialPowers.Ci.nsIThread.DISPATCH_NORMAL);
|
||||
|
||||
while (!eventHasRun) {
|
||||
thread.processNextEvent(false);
|
||||
}
|
||||
|
||||
ok(lockedFile2, "Non-null lockedFile2");
|
||||
ok(fileHandle2, "Non-null fileHandle2");
|
||||
|
||||
continueToNextStep();
|
||||
yield undefined;
|
|
@ -13,32 +13,32 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile1 = fileHandle.open("readwrite");
|
||||
let lockedFile2 = fileHandle.open("readwrite");
|
||||
let fileHandle1 = mutableFile.open("readwrite");
|
||||
let fileHandle2 = mutableFile.open("readwrite");
|
||||
|
||||
let request1 = lockedFile2.write("2");
|
||||
let request2 = lockedFile1.write("1");
|
||||
let request1 = fileHandle2.write("2");
|
||||
let request2 = fileHandle1.write("1");
|
||||
|
||||
lockedFile1.oncomplete = grabEventAndContinueHandler;
|
||||
lockedFile2.oncomplete = grabEventAndContinueHandler;
|
||||
fileHandle1.oncomplete = grabEventAndContinueHandler;
|
||||
fileHandle2.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
yield undefined;
|
||||
yield undefined;
|
||||
|
||||
let lockedFile3 = fileHandle.open("readonly");
|
||||
let request3 = lockedFile3.readAsText(1);
|
||||
let fileHandle3 = mutableFile.open("readonly");
|
||||
let request3 = fileHandle3.readAsText(1);
|
||||
request3.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield undefined;
|
||||
is(event.target.result, "2", "Locked files were ordered properly.");
|
||||
is(event.target.result, "2", "File handles were ordered properly.");
|
||||
}
|
||||
|
||||
finishTest();
|
|
@ -13,17 +13,19 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
request = fileHandle.getFile();
|
||||
request = mutableFile.getFile();
|
||||
ok(request instanceof DOMRequest, "Correct interface");
|
||||
ok(!(request instanceof FileRequest), "Correct interface");
|
||||
ok(!('fileHandle' in request), "Property should not exist");
|
||||
ok(request.fileHandle === undefined, "Property should not exist");
|
||||
ok(!('lockedFile' in request), "Property should not exist");
|
||||
ok(request.lockedFile === undefined, "Property should not exist");
|
||||
ok(!('onprogress' in request), "Property should not exist");
|
||||
|
|
|
@ -13,25 +13,25 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
is(lockedFile.location, 0, "Correct location");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
is(fileHandle.location, 0, "Correct location");
|
||||
|
||||
lockedFile.location = 100000;
|
||||
is(lockedFile.location, 100000, "Correct location");
|
||||
fileHandle.location = 100000;
|
||||
is(fileHandle.location, 100000, "Correct location");
|
||||
|
||||
lockedFile.location = null;
|
||||
ok(lockedFile.location === null, "Correct location");
|
||||
fileHandle.location = null;
|
||||
ok(fileHandle.location === null, "Correct location");
|
||||
|
||||
try {
|
||||
lockedFile.readAsArrayBuffer(1);
|
||||
fileHandle.readAsArrayBuffer(1);
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -41,7 +41,7 @@
|
|||
}
|
||||
|
||||
try {
|
||||
lockedFile.readAsText(1);
|
||||
fileHandle.readAsText(1);
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -51,7 +51,7 @@
|
|||
}
|
||||
|
||||
try {
|
||||
lockedFile.write({});
|
||||
fileHandle.write({});
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -60,14 +60,14 @@
|
|||
is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
|
||||
}
|
||||
|
||||
request = lockedFile.append("foo");
|
||||
request = fileHandle.append("foo");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
ok(lockedFile.location === null, "Correct location");
|
||||
ok(fileHandle.location === null, "Correct location");
|
||||
|
||||
try {
|
||||
lockedFile.truncate();
|
||||
fileHandle.truncate();
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -76,11 +76,11 @@
|
|||
is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
|
||||
}
|
||||
|
||||
request = lockedFile.truncate(0);
|
||||
request = fileHandle.truncate(0);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(lockedFile.location, 0, "Correct location");
|
||||
is(fileHandle.location, 0, "Correct location");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
|
|
|
@ -13,36 +13,36 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
for (let i = 0; i < 50; i++) {
|
||||
let stepNumber = 0;
|
||||
|
||||
request = fileHandle.open("readwrite").append("string1");
|
||||
request = mutableFile.open("readwrite").append("string1");
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 1, "This callback came first");
|
||||
stepNumber++;
|
||||
event.target.lockedFile.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.fileHandle.oncomplete = grabEventAndContinueHandler;
|
||||
}
|
||||
|
||||
request = fileHandle.open("readwrite").append("string2");
|
||||
request = mutableFile.open("readwrite").append("string2");
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 2, "This callback came second");
|
||||
stepNumber++;
|
||||
event.target.lockedFile.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.fileHandle.oncomplete = grabEventAndContinueHandler;
|
||||
}
|
||||
|
||||
request = fileHandle.open("readwrite").append("string3");
|
||||
request = mutableFile.open("readwrite").append("string3");
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 3, "This callback came third");
|
||||
stepNumber++;
|
||||
event.target.lockedFile.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.fileHandle.oncomplete = grabEventAndContinueHandler;
|
||||
}
|
||||
|
||||
stepNumber++;
|
|
@ -15,19 +15,19 @@
|
|||
var testBuffer = getRandomBuffer(100000);
|
||||
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
|
||||
let sum = 0;
|
||||
|
||||
request = lockedFile.write(testBuffer);
|
||||
request = fileHandle.write(testBuffer);
|
||||
request.onprogress = function(event) {
|
||||
let loaded = event.loaded;
|
||||
let total = event.total;
|
||||
|
@ -42,8 +42,8 @@
|
|||
|
||||
sum = 0;
|
||||
|
||||
lockedFile.location = 0;
|
||||
request = lockedFile.readAsArrayBuffer(testBuffer.byteLength);
|
||||
fileHandle.location = 0;
|
||||
request = fileHandle.readAsArrayBuffer(testBuffer.byteLength);
|
||||
request.onprogress = function(event) {
|
||||
let loaded = event.loaded;
|
||||
let total = event.total;
|
||||
|
|
|
@ -13,50 +13,50 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
request = fileHandle.open("readwrite").write({});
|
||||
request = mutableFile.open("readwrite").write({});
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(event.target.lockedFile.mode, "readwrite", "Correct mode");
|
||||
is(event.target.fileHandle.mode, "readwrite", "Correct mode");
|
||||
|
||||
try {
|
||||
fileHandle.open().write({});
|
||||
ok(false, "Writing to a readonly locked file should fail!");
|
||||
mutableFile.open().write({});
|
||||
ok(false, "Writing to a readonly file handle should fail!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Writing to a readonly locked file failed");
|
||||
ok(true, "Writing to a readonly file handle failed");
|
||||
}
|
||||
|
||||
try {
|
||||
fileHandle.open().append({});
|
||||
ok(false, "Appending to a readonly locked file should fail!");
|
||||
mutableFile.open().append({});
|
||||
ok(false, "Appending to a readonly file handle should fail!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Appending to a readonly locked file failed");
|
||||
ok(true, "Appending to a readonly file handle failed");
|
||||
}
|
||||
|
||||
try {
|
||||
fileHandle.open().truncate({});
|
||||
ok(false, "Truncating a readonly locked file should fail!");
|
||||
mutableFile.open().truncate({});
|
||||
ok(false, "Truncating a readonly file handle should fail!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Truncating a readonly locked file failed");
|
||||
ok(true, "Truncating a readonly file handle failed");
|
||||
}
|
||||
|
||||
try {
|
||||
fileHandle.open().flush({});
|
||||
ok(false, "Flushing a readonly locked file should fail!");
|
||||
mutableFile.open().flush({});
|
||||
ok(false, "Flushing a readonly file handle should fail!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Flushing a readonly locked file failed");
|
||||
ok(true, "Flushing a readonly file handle failed");
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
is(request.readyState, "pending", "Correct readyState");
|
||||
|
||||
request.onerror = errorHandler;
|
||||
|
@ -22,11 +22,11 @@
|
|||
|
||||
is(request.readyState, "done", "Correct readyState");
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
request = lockedFile.write("string");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
request = fileHandle.write("string");
|
||||
is(request.readyState, "pending", "Correct readyState");
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
@ -34,8 +34,8 @@
|
|||
|
||||
is(request.readyState, "done", "Correct readyState");
|
||||
|
||||
lockedFile.location = 0;
|
||||
request = lockedFile.readAsText(6);
|
||||
fileHandle.location = 0;
|
||||
request = fileHandle.readAsText(6);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
is(request.readyState, "pending", "Correct readyState");
|
||||
event = yield undefined;
|
||||
|
|
|
@ -15,21 +15,21 @@
|
|||
var testBuffer = getRandomBuffer(100000);
|
||||
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
|
||||
request = lockedFile.write(testBuffer);
|
||||
request = fileHandle.write(testBuffer);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
request = fileHandle.getFile();
|
||||
request = mutableFile.getFile();
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
|||
}
|
||||
catch (e) {
|
||||
ok(e instanceof DOMException, "Got exception.");
|
||||
is(e.name, "LockedFileInactiveError", "Good error.");
|
||||
is(e.name, "FileHandleInactiveError", "Good error.");
|
||||
is(e.code, 0, "Good error code.");
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
|||
}
|
||||
catch (e) {
|
||||
ok(e instanceof DOMException, "Got exception.");
|
||||
is(e.name, "LockedFileInactiveError", "Good error.");
|
||||
is(e.name, "FileHandleInactiveError", "Good error.");
|
||||
is(e.code, 0, "Good error code.");
|
||||
}
|
||||
|
||||
|
|
|
@ -13,22 +13,22 @@
|
|||
function testSteps()
|
||||
{
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open();
|
||||
let fileHandle = mutableFile.open();
|
||||
|
||||
lockedFile.oncomplete = unexpectedSuccessHandler;
|
||||
lockedFile.onabort = grabEventAndContinueHandler;
|
||||
fileHandle.oncomplete = unexpectedSuccessHandler;
|
||||
fileHandle.onabort = grabEventAndContinueHandler;
|
||||
|
||||
let sawError = false;
|
||||
|
||||
request = lockedFile.getMetadata({ size: true });
|
||||
request = fileHandle.getMetadata({ size: true });
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onerror = function(event) {
|
||||
is(event.target.error.name, "AbortError", "Good error");
|
||||
|
@ -36,7 +36,7 @@
|
|||
event.stopPropagation();
|
||||
}
|
||||
|
||||
lockedFile.abort();
|
||||
fileHandle.abort();
|
||||
|
||||
event = yield undefined;
|
||||
|
||||
|
|
|
@ -15,53 +15,53 @@
|
|||
var testBuffer = getRandomBuffer(100000);
|
||||
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.bin");
|
||||
let request = getMutableFile(fileStorage.key, "test.bin");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
request = lockedFile.write(testBuffer);
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
request = fileHandle.write(testBuffer);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(lockedFile.location, 100000, "Correct location");
|
||||
is(fileHandle.location, 100000, "Correct location");
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
let location = lockedFile.location - 10000;
|
||||
lockedFile.location = location;
|
||||
let location = fileHandle.location - 10000;
|
||||
fileHandle.location = location;
|
||||
|
||||
request = lockedFile.truncate();
|
||||
request = fileHandle.truncate();
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
|
||||
request = lockedFile.getMetadata({ size: true });
|
||||
request = fileHandle.getMetadata({ size: true });
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(event.target.result.size, location, "Correct size");
|
||||
}
|
||||
|
||||
request = lockedFile.write(testBuffer);
|
||||
request = fileHandle.write(testBuffer);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let location = lockedFile.location;
|
||||
let location = fileHandle.location;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
location -= 10000;
|
||||
|
||||
request = lockedFile.truncate(location);
|
||||
request = fileHandle.truncate(location);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
|
||||
request = lockedFile.getMetadata({ size: true });
|
||||
request = fileHandle.getMetadata({ size: true });
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
|
|
@ -15,21 +15,21 @@
|
|||
var testBuffer = getRandomBuffer(100000);
|
||||
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
|
||||
request = lockedFile.write(testBuffer);
|
||||
request = fileHandle.write(testBuffer);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
request = fileHandle.getFile();
|
||||
request = mutableFile.getFile();
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
|
|
@ -22,65 +22,65 @@
|
|||
var testBlob = getBlob("binary/random", testBuffer);
|
||||
|
||||
for each (let fileStorage in fileStorages) {
|
||||
let request = getFileHandle(fileStorage.key, "test.txt");
|
||||
let request = getMutableFile(fileStorage.key, "test.txt");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let location = 0;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
|
||||
request = lockedFile.write(testString);
|
||||
request = fileHandle.write(testString);
|
||||
location += testString.length;
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.location = 0;
|
||||
request = lockedFile.readAsText(testString.length);
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
fileHandle.location = 0;
|
||||
request = fileHandle.readAsText(testString.length);
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let resultString = event.target.result;
|
||||
ok(resultString == testString, "Correct string data");
|
||||
|
||||
request = lockedFile.write(testBuffer);
|
||||
request = fileHandle.write(testBuffer);
|
||||
location += testBuffer.byteLength;
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.location -= testBuffer.byteLength;
|
||||
request = lockedFile.readAsArrayBuffer(testBuffer.byteLength);
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
fileHandle.location -= testBuffer.byteLength;
|
||||
request = fileHandle.readAsArrayBuffer(testBuffer.byteLength);
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let resultBuffer = event.target.result;
|
||||
ok(compareBuffers(resultBuffer, testBuffer), "Correct array buffer data");
|
||||
|
||||
request = lockedFile.write(testBlob);
|
||||
request = fileHandle.write(testBlob);
|
||||
location += testBlob.size;
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.location -= testBlob.size;
|
||||
request = lockedFile.readAsArrayBuffer(testBlob.size);
|
||||
is(lockedFile.location, location, "Correct location");
|
||||
fileHandle.location -= testBlob.size;
|
||||
request = fileHandle.readAsArrayBuffer(testBlob.size);
|
||||
is(fileHandle.location, location, "Correct location");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
resultBuffer = event.target.result;
|
||||
ok(compareBuffers(resultBuffer, testBuffer), "Correct blob data");
|
||||
|
||||
request = lockedFile.getMetadata({ size: true });
|
||||
request = fileHandle.getMetadata({ size: true });
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include "DatabaseInfo.h"
|
||||
#include "IDBEvents.h"
|
||||
#include "IDBFactory.h"
|
||||
#include "IDBFileHandle.h"
|
||||
#include "IDBIndex.h"
|
||||
#include "IDBMutableFile.h"
|
||||
#include "IDBObjectStore.h"
|
||||
#include "IDBTransaction.h"
|
||||
#include "IDBFactory.h"
|
||||
|
@ -684,9 +684,9 @@ IDBDatabase::Transaction(const Sequence<nsString>& aStoreNames,
|
|||
}
|
||||
|
||||
already_AddRefed<IDBRequest>
|
||||
IDBDatabase::MozCreateFileHandle(const nsAString& aName,
|
||||
const Optional<nsAString>& aType,
|
||||
ErrorResult& aRv)
|
||||
IDBDatabase::CreateMutableFile(const nsAString& aName,
|
||||
const Optional<nsAString>& aType,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
|
@ -930,9 +930,9 @@ nsresult
|
|||
CreateFileHelper::GetSuccessResult(JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aVal)
|
||||
{
|
||||
nsRefPtr<IDBFileHandle> fileHandle =
|
||||
IDBFileHandle::Create(mName, mType, mDatabase, mFileInfo.forget());
|
||||
IDB_ENSURE_TRUE(fileHandle, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
nsRefPtr<IDBMutableFile> mutableFile =
|
||||
IDBMutableFile::Create(mName, mType, mDatabase, mFileInfo.forget());
|
||||
IDB_ENSURE_TRUE(mutableFile, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, fileHandle), aVal);
|
||||
return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, mutableFile), aVal);
|
||||
}
|
||||
|
|
|
@ -225,9 +225,16 @@ public:
|
|||
return PersistenceTypeToStorage(mPersistenceType);
|
||||
}
|
||||
|
||||
already_AddRefed<IDBRequest>
|
||||
CreateMutableFile(const nsAString& aName, const Optional<nsAString>& aType,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<IDBRequest>
|
||||
MozCreateFileHandle(const nsAString& aName, const Optional<nsAString>& aType,
|
||||
ErrorResult& aRv);
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
return CreateMutableFile(aName, aType, aRv);
|
||||
}
|
||||
|
||||
virtual void LastRelease() MOZ_OVERRIDE;
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
* 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 "IDBFileHandle.h"
|
||||
#include "IDBMutableFile.h"
|
||||
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/IDBFileHandleBinding.h"
|
||||
#include "mozilla/dom/IDBMutableFileBinding.h"
|
||||
#include "mozilla/dom/quota/FileStreams.h"
|
||||
#include "mozilla/dom/quota/QuotaManager.h"
|
||||
|
||||
|
@ -36,32 +36,32 @@ GetFileFor(FileInfo* aFileInfo)
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
IDBFileHandle::IDBFileHandle(IDBDatabase* aOwner)
|
||||
: FileHandle(aOwner)
|
||||
IDBMutableFile::IDBMutableFile(IDBDatabase* aOwner)
|
||||
: MutableFile(aOwner)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(IDBFileHandle, FileHandle, mDatabase)
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(IDBMutableFile, MutableFile, mDatabase)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBFileHandle)
|
||||
NS_INTERFACE_MAP_END_INHERITING(FileHandle)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBMutableFile)
|
||||
NS_INTERFACE_MAP_END_INHERITING(MutableFile)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(IDBFileHandle, FileHandle)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBFileHandle, FileHandle)
|
||||
NS_IMPL_ADDREF_INHERITED(IDBMutableFile, MutableFile)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBMutableFile, MutableFile)
|
||||
|
||||
// static
|
||||
already_AddRefed<IDBFileHandle>
|
||||
IDBFileHandle::Create(const nsAString& aName,
|
||||
const nsAString& aType,
|
||||
IDBDatabase* aDatabase,
|
||||
already_AddRefed<FileInfo> aFileInfo)
|
||||
already_AddRefed<IDBMutableFile>
|
||||
IDBMutableFile::Create(const nsAString& aName,
|
||||
const nsAString& aType,
|
||||
IDBDatabase* aDatabase,
|
||||
already_AddRefed<FileInfo> aFileInfo)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsRefPtr<FileInfo> fileInfo(aFileInfo);
|
||||
NS_ASSERTION(fileInfo, "Null pointer!");
|
||||
|
||||
nsRefPtr<IDBFileHandle> newFile = new IDBFileHandle(aDatabase);
|
||||
nsRefPtr<IDBMutableFile> newFile = new IDBMutableFile(aDatabase);
|
||||
|
||||
newFile->mName = aName;
|
||||
newFile->mType = aType;
|
||||
|
@ -79,25 +79,25 @@ IDBFileHandle::Create(const nsAString& aName,
|
|||
}
|
||||
|
||||
bool
|
||||
IDBFileHandle::IsShuttingDown()
|
||||
IDBMutableFile::IsShuttingDown()
|
||||
{
|
||||
return QuotaManager::IsShuttingDown() || FileHandle::IsShuttingDown();
|
||||
return QuotaManager::IsShuttingDown() || MutableFile::IsShuttingDown();
|
||||
}
|
||||
|
||||
bool
|
||||
IDBFileHandle::IsInvalid()
|
||||
IDBMutableFile::IsInvalid()
|
||||
{
|
||||
return mDatabase->IsInvalidated();
|
||||
}
|
||||
|
||||
nsIOfflineStorage*
|
||||
IDBFileHandle::Storage()
|
||||
IDBMutableFile::Storage()
|
||||
{
|
||||
return mDatabase;
|
||||
}
|
||||
|
||||
already_AddRefed<nsISupports>
|
||||
IDBFileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
|
||||
IDBMutableFile::CreateStream(nsIFile* aFile, bool aReadOnly)
|
||||
{
|
||||
PersistenceType persistenceType = mDatabase->Type();
|
||||
const nsACString& group = mDatabase->Group();
|
||||
|
@ -123,31 +123,31 @@ IDBFileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
|
|||
}
|
||||
|
||||
void
|
||||
IDBFileHandle::SetThreadLocals()
|
||||
IDBMutableFile::SetThreadLocals()
|
||||
{
|
||||
MOZ_ASSERT(mDatabase->GetOwner(), "Should have owner!");
|
||||
QuotaManager::SetCurrentWindow(mDatabase->GetOwner());
|
||||
}
|
||||
|
||||
void
|
||||
IDBFileHandle::UnsetThreadLocals()
|
||||
IDBMutableFile::UnsetThreadLocals()
|
||||
{
|
||||
QuotaManager::SetCurrentWindow(nullptr);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMFile>
|
||||
IDBFileHandle::CreateFileObject(mozilla::dom::LockedFile* aLockedFile,
|
||||
IDBMutableFile::CreateFileObject(mozilla::dom::FileHandle* aFileHandle,
|
||||
uint32_t aFileSize)
|
||||
{
|
||||
nsCOMPtr<nsIDOMFile> file =
|
||||
new File(mName, mType, aFileSize, mFile, aLockedFile, mFileInfo);
|
||||
new File(mName, mType, aFileSize, mFile, aFileHandle, mFileInfo);
|
||||
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
// virtual
|
||||
JSObject*
|
||||
IDBFileHandle::WrapObject(JSContext* aCx)
|
||||
IDBMutableFile::WrapObject(JSContext* aCx)
|
||||
{
|
||||
return IDBFileHandleBinding::Wrap(aCx, this);
|
||||
return IDBMutableFileBinding::Wrap(aCx, this);
|
||||
}
|
|
@ -4,32 +4,32 @@
|
|||
* 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_indexeddb_idbfilehandle_h__
|
||||
#define mozilla_dom_indexeddb_idbfilehandle_h__
|
||||
#ifndef mozilla_dom_indexeddb_idbmutablefile_h__
|
||||
#define mozilla_dom_indexeddb_idbmutablefile_h__
|
||||
|
||||
#include "IndexedDatabase.h"
|
||||
|
||||
#include "MainThreadUtils.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/FileHandle.h"
|
||||
#include "mozilla/dom/indexedDB/FileInfo.h"
|
||||
#include "mozilla/dom/MutableFile.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
BEGIN_INDEXEDDB_NAMESPACE
|
||||
|
||||
class IDBDatabase;
|
||||
|
||||
class IDBFileHandle : public FileHandle
|
||||
class IDBMutableFile : public MutableFile
|
||||
{
|
||||
typedef mozilla::dom::LockedFile LockedFile;
|
||||
typedef mozilla::dom::FileHandle FileHandle;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBFileHandle, FileHandle)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBMutableFile, MutableFile)
|
||||
|
||||
static already_AddRefed<IDBFileHandle>
|
||||
static already_AddRefed<IDBMutableFile>
|
||||
Create(const nsAString& aName, const nsAString& aType,
|
||||
IDBDatabase* aDatabase, already_AddRefed<FileInfo> aFileInfo);
|
||||
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
UnsetThreadLocals() MOZ_OVERRIDE;
|
||||
|
||||
virtual already_AddRefed<nsIDOMFile>
|
||||
CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) MOZ_OVERRIDE;
|
||||
CreateFileObject(FileHandle* aFileHandle, uint32_t aFileSize) MOZ_OVERRIDE;
|
||||
|
||||
// nsWrapperCache
|
||||
virtual JSObject*
|
||||
|
@ -81,9 +81,9 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
IDBFileHandle(IDBDatabase* aOwner);
|
||||
IDBMutableFile(IDBDatabase* aOwner);
|
||||
|
||||
~IDBFileHandle()
|
||||
~IDBMutableFile()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -93,4 +93,4 @@ private:
|
|||
|
||||
END_INDEXEDDB_NAMESPACE
|
||||
|
||||
#endif // mozilla_dom_indexeddb_idbfilehandle_h__
|
||||
#endif // mozilla_dom_indexeddb_idbmutablefile_h__
|
|
@ -15,7 +15,7 @@
|
|||
#include "jsfriendapi.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/nsIContentParent.h"
|
||||
#include "mozilla/dom/FileHandleBinding.h"
|
||||
#include "mozilla/dom/MutableFileBinding.h"
|
||||
#include "mozilla/dom/StructuredCloneTags.h"
|
||||
#include "mozilla/dom/TabChild.h"
|
||||
#include "mozilla/dom/ipc/Blob.h"
|
||||
|
@ -34,9 +34,9 @@
|
|||
#include "AsyncConnectionHelper.h"
|
||||
#include "IDBCursor.h"
|
||||
#include "IDBEvents.h"
|
||||
#include "IDBFileHandle.h"
|
||||
#include "IDBIndex.h"
|
||||
#include "IDBKeyRange.h"
|
||||
#include "IDBMutableFile.h"
|
||||
#include "IDBTransaction.h"
|
||||
#include "DatabaseInfo.h"
|
||||
#include "KeyPath.h"
|
||||
|
@ -63,7 +63,7 @@ using mozilla::NativeEndian;
|
|||
|
||||
BEGIN_INDEXEDDB_NAMESPACE
|
||||
|
||||
struct FileHandleData
|
||||
struct MutableFileData
|
||||
{
|
||||
nsString type;
|
||||
nsString name;
|
||||
|
@ -779,19 +779,19 @@ ResolveMysteryBlob(nsIDOMBlob* aBlob, const nsString& aContentType,
|
|||
class MainThreadDeserializationTraits
|
||||
{
|
||||
public:
|
||||
static JSObject* CreateAndWrapFileHandle(JSContext* aCx,
|
||||
IDBDatabase* aDatabase,
|
||||
StructuredCloneFile& aFile,
|
||||
const FileHandleData& aData)
|
||||
static JSObject* CreateAndWrapMutableFile(JSContext* aCx,
|
||||
IDBDatabase* aDatabase,
|
||||
StructuredCloneFile& aFile,
|
||||
const MutableFileData& aData)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsRefPtr<FileInfo>& fileInfo = aFile.mFileInfo;
|
||||
|
||||
nsRefPtr<IDBFileHandle> fileHandle = IDBFileHandle::Create(aData.name,
|
||||
nsRefPtr<IDBMutableFile> mutableFile = IDBMutableFile::Create(aData.name,
|
||||
aData.type, aDatabase, fileInfo.forget());
|
||||
|
||||
return fileHandle->WrapObject(aCx);
|
||||
return mutableFile->WrapObject(aCx);
|
||||
}
|
||||
|
||||
static JSObject* CreateAndWrapBlobOrFile(JSContext* aCx,
|
||||
|
@ -881,12 +881,12 @@ public:
|
|||
class CreateIndexDeserializationTraits
|
||||
{
|
||||
public:
|
||||
static JSObject* CreateAndWrapFileHandle(JSContext* aCx,
|
||||
IDBDatabase* aDatabase,
|
||||
StructuredCloneFile& aFile,
|
||||
const FileHandleData& aData)
|
||||
static JSObject* CreateAndWrapMutableFile(JSContext* aCx,
|
||||
IDBDatabase* aDatabase,
|
||||
StructuredCloneFile& aFile,
|
||||
const MutableFileData& aData)
|
||||
{
|
||||
// FileHandle can't be used in index creation, so just make a dummy object.
|
||||
// MutableFile can't be used in index creation, so just make a dummy object.
|
||||
return JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr());
|
||||
}
|
||||
|
||||
|
@ -1404,10 +1404,10 @@ StructuredCloneReadString(JSStructuredCloneReader* aReader,
|
|||
|
||||
// static
|
||||
bool
|
||||
IDBObjectStore::ReadFileHandle(JSStructuredCloneReader* aReader,
|
||||
FileHandleData* aRetval)
|
||||
IDBObjectStore::ReadMutableFile(JSStructuredCloneReader* aReader,
|
||||
MutableFileData* aRetval)
|
||||
{
|
||||
static_assert(SCTAG_DOM_FILEHANDLE == 0xFFFF8004,
|
||||
static_assert(SCTAG_DOM_MUTABLEFILE == 0xFFFF8004,
|
||||
"Update me!");
|
||||
MOZ_ASSERT(aReader && aRetval);
|
||||
|
||||
|
@ -1443,7 +1443,7 @@ IDBObjectStore::ReadBlobOrFile(JSStructuredCloneReader* aReader,
|
|||
|
||||
aRetval->tag = aTag;
|
||||
|
||||
// If it's not a FileHandle, it's a Blob or a File.
|
||||
// If it's not a MutableFile, it's a Blob or a File.
|
||||
uint64_t size;
|
||||
if (!JS_ReadBytes(aReader, &size, sizeof(uint64_t))) {
|
||||
NS_WARNING("Failed to read size!");
|
||||
|
@ -1500,13 +1500,13 @@ IDBObjectStore::StructuredCloneReadCallback(JSContext* aCx,
|
|||
// so that if people accidentally change them they notice.
|
||||
static_assert(SCTAG_DOM_BLOB == 0xFFFF8001 &&
|
||||
SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE == 0xFFFF8002 &&
|
||||
SCTAG_DOM_FILEHANDLE == 0xFFFF8004 &&
|
||||
SCTAG_DOM_MUTABLEFILE == 0xFFFF8004 &&
|
||||
SCTAG_DOM_FILE == 0xFFFF8005,
|
||||
"You changed our structured clone tag values and just ate "
|
||||
"everyone's IndexedDB data. I hope you are happy.");
|
||||
|
||||
if (aTag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE ||
|
||||
aTag == SCTAG_DOM_FILEHANDLE ||
|
||||
aTag == SCTAG_DOM_MUTABLEFILE ||
|
||||
aTag == SCTAG_DOM_BLOB ||
|
||||
aTag == SCTAG_DOM_FILE) {
|
||||
StructuredCloneReadInfo* cloneReadInfo =
|
||||
|
@ -1520,14 +1520,14 @@ IDBObjectStore::StructuredCloneReadCallback(JSContext* aCx,
|
|||
StructuredCloneFile& file = cloneReadInfo->mFiles[aData];
|
||||
IDBDatabase* database = cloneReadInfo->mDatabase;
|
||||
|
||||
if (aTag == SCTAG_DOM_FILEHANDLE) {
|
||||
FileHandleData data;
|
||||
if (!ReadFileHandle(aReader, &data)) {
|
||||
if (aTag == SCTAG_DOM_MUTABLEFILE) {
|
||||
MutableFileData data;
|
||||
if (!ReadMutableFile(aReader, &data)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DeserializationTraits::CreateAndWrapFileHandle(aCx, database,
|
||||
file, data);
|
||||
return DeserializationTraits::CreateAndWrapMutableFile(aCx, database,
|
||||
file, data);
|
||||
}
|
||||
|
||||
BlobOrFileData data;
|
||||
|
@ -1572,25 +1572,25 @@ IDBObjectStore::StructuredCloneWriteCallback(JSContext* aCx,
|
|||
IDBTransaction* transaction = cloneWriteInfo->mTransaction;
|
||||
FileManager* fileManager = transaction->Database()->Manager();
|
||||
|
||||
FileHandle* fileHandle = nullptr;
|
||||
if (NS_SUCCEEDED(UNWRAP_OBJECT(FileHandle, aObj, fileHandle))) {
|
||||
nsRefPtr<FileInfo> fileInfo = fileHandle->GetFileInfo();
|
||||
MutableFile* mutableFile = nullptr;
|
||||
if (NS_SUCCEEDED(UNWRAP_OBJECT(MutableFile, aObj, mutableFile))) {
|
||||
nsRefPtr<FileInfo> fileInfo = mutableFile->GetFileInfo();
|
||||
|
||||
// Throw when trying to store non IDB file handles or IDB file handles
|
||||
// Throw when trying to store non IDB mutable files or IDB mutable files
|
||||
// across databases.
|
||||
if (!fileInfo || fileInfo->Manager() != fileManager) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 convType(fileHandle->Type());
|
||||
NS_ConvertUTF16toUTF8 convType(mutableFile->Type());
|
||||
uint32_t convTypeLength =
|
||||
NativeEndian::swapToLittleEndian(convType.Length());
|
||||
|
||||
NS_ConvertUTF16toUTF8 convName(fileHandle->Name());
|
||||
NS_ConvertUTF16toUTF8 convName(mutableFile->Name());
|
||||
uint32_t convNameLength =
|
||||
NativeEndian::swapToLittleEndian(convName.Length());
|
||||
|
||||
if (!JS_WriteUint32Pair(aWriter, SCTAG_DOM_FILEHANDLE,
|
||||
if (!JS_WriteUint32Pair(aWriter, SCTAG_DOM_MUTABLEFILE,
|
||||
cloneWriteInfo->mFiles.Length()) ||
|
||||
!JS_WriteBytes(aWriter, &convTypeLength, sizeof(uint32_t)) ||
|
||||
!JS_WriteBytes(aWriter, convType.get(), convType.Length()) ||
|
||||
|
|
|
@ -47,7 +47,7 @@ struct IndexInfo;
|
|||
struct IndexUpdateInfo;
|
||||
struct ObjectStoreInfo;
|
||||
|
||||
struct FileHandleData;
|
||||
struct MutableFileData;
|
||||
struct BlobOrFileData;
|
||||
|
||||
class IDBObjectStore MOZ_FINAL : public nsISupports,
|
||||
|
@ -387,8 +387,8 @@ protected:
|
|||
ClearStructuredCloneBuffer(JSAutoStructuredCloneBuffer& aBuffer);
|
||||
|
||||
static bool
|
||||
ReadFileHandle(JSStructuredCloneReader* aReader,
|
||||
FileHandleData* aRetval);
|
||||
ReadMutableFile(JSStructuredCloneReader* aReader,
|
||||
MutableFileData* aRetval);
|
||||
|
||||
static bool
|
||||
ReadBlobOrFile(JSStructuredCloneReader* aReader,
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
#include "mozilla/dom/IDBCursorBinding.h"
|
||||
#include "mozilla/dom/IDBDatabaseBinding.h"
|
||||
#include "mozilla/dom/IDBFactoryBinding.h"
|
||||
#include "mozilla/dom/IDBFileHandleBinding.h"
|
||||
#include "mozilla/dom/IDBKeyRangeBinding.h"
|
||||
#include "mozilla/dom/IDBIndexBinding.h"
|
||||
#include "mozilla/dom/IDBKeyRangeBinding.h"
|
||||
#include "mozilla/dom/IDBMutableFileBinding.h"
|
||||
#include "mozilla/dom/IDBObjectStoreBinding.h"
|
||||
#include "mozilla/dom/IDBOpenDBRequestBinding.h"
|
||||
#include "mozilla/dom/IDBRequestBinding.h"
|
||||
|
@ -419,9 +419,9 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
|
|||
!IDBCursorWithValueBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBDatabaseBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBFactoryBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBFileHandleBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBIndexBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBKeyRangeBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBMutableFileBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBObjectStoreBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBOpenDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!IDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
|
|
|
@ -22,9 +22,9 @@ EXPORTS.mozilla.dom.indexedDB += [
|
|||
'IDBDatabase.h',
|
||||
'IDBEvents.h',
|
||||
'IDBFactory.h',
|
||||
'IDBFileHandle.h',
|
||||
'IDBIndex.h',
|
||||
'IDBKeyRange.h',
|
||||
'IDBMutableFile.h',
|
||||
'IDBObjectStore.h',
|
||||
'IDBRequest.h',
|
||||
'IDBTransaction.h',
|
||||
|
@ -45,8 +45,8 @@ UNIFIED_SOURCES += [
|
|||
'IDBDatabase.cpp',
|
||||
'IDBEvents.cpp',
|
||||
'IDBFactory.cpp',
|
||||
'IDBFileHandle.cpp',
|
||||
'IDBKeyRange.cpp',
|
||||
'IDBMutableFile.cpp',
|
||||
'IDBRequest.cpp',
|
||||
'IDBTransaction.cpp',
|
||||
'IDBWrapperCache.cpp',
|
||||
|
|
|
@ -29,24 +29,24 @@
|
|||
|
||||
event = yield undefined;
|
||||
|
||||
request = db.mozCreateFileHandle("test.bin", "binary");
|
||||
request = db.createMutableFile("test.bin", "binary");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
|
||||
let blob = getNullBlob(DEFAULT_QUOTA);
|
||||
|
||||
request = lockedFile.write(blob);
|
||||
request = fileHandle.write(blob);
|
||||
request.addEventListener("error",
|
||||
new ExpectError("QuotaExceededError", true));
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
event = yield undefined;
|
||||
|
||||
lockedFile.oncomplete = grabEventAndContinueHandler;
|
||||
fileHandle.oncomplete = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "complete", "Got correct event type");
|
||||
|
|
|
@ -47,19 +47,19 @@
|
|||
|
||||
let db1 = databases[0];
|
||||
|
||||
let request = db1.mozCreateFileHandle("random.bin", "binary/random");
|
||||
let request = db1.createMutableFile("random.bin", "binary/random");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
is(getFileId(fileHandle), 1, "Correct file id");
|
||||
is(fileHandle.name, "random.bin", "Correct name");
|
||||
is(fileHandle.type, "binary/random", "Correct type");
|
||||
let mutableFile = event.target.result;
|
||||
is(getFileId(mutableFile), 1, "Correct file id");
|
||||
is(mutableFile.name, "random.bin", "Correct name");
|
||||
is(mutableFile.type, "binary/random", "Correct type");
|
||||
|
||||
let trans = db1.transaction([objectStoreName], READ_WRITE);
|
||||
let objectStore = trans.objectStore(objectStoreName);
|
||||
|
||||
request = objectStore.add(fileHandle, 42);
|
||||
request = objectStore.add(mutableFile, 42);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
@ -69,8 +69,8 @@
|
|||
|
||||
let result = event.target.result;
|
||||
is(getFileId(result), 1, "Correct file id");
|
||||
is(result.name, fileHandle.name, "Correct name");
|
||||
is(result.type, fileHandle.type, "Correct type");
|
||||
is(result.name, mutableFile.name, "Correct name");
|
||||
is(result.type, mutableFile.type, "Correct type");
|
||||
|
||||
let db2 = databases[1];
|
||||
|
||||
|
@ -78,7 +78,7 @@
|
|||
objectStore = trans.objectStore(objectStoreName);
|
||||
|
||||
try {
|
||||
objectStore.add(fileHandle, 42);
|
||||
objectStore.add(mutableFile, 42);
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
@ -37,22 +37,22 @@
|
|||
|
||||
is(event.type, "success", "Got correct event type");
|
||||
|
||||
request = db.mozCreateFileHandle("random.bin", "binary/random");
|
||||
request = db.createMutableFile("random.bin", "binary/random");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
fileHandle.onerror = errorHandler;
|
||||
let mutableFile = event.target.result;
|
||||
mutableFile.onerror = errorHandler;
|
||||
|
||||
let lockedFile = fileHandle.open("readwrite");
|
||||
let fileHandle = mutableFile.open("readwrite");
|
||||
|
||||
is(getFileId(fileHandle), 1, "Correct file id");
|
||||
is(getFileId(mutableFile), 1, "Correct file id");
|
||||
|
||||
request = lockedFile.write(testFile);
|
||||
request = fileHandle.write(testFile);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
request = fileHandle.getFile();
|
||||
request = mutableFile.getFile();
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
|
@ -73,7 +73,7 @@
|
|||
}
|
||||
catch (e) {
|
||||
ok(e instanceof DOMException, "Got exception.");
|
||||
is(e.name, "LockedFileInactiveError", "Good error.");
|
||||
is(e.name, "FileHandleInactiveError", "Good error.");
|
||||
is(e.code, 0, "Good error code.");
|
||||
}
|
||||
|
||||
|
|
|
@ -23,20 +23,20 @@
|
|||
db.onerror = errorHandler;
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
request = db.mozCreateFileHandle("random.bin", "binary/random");
|
||||
request = db.createMutableFile("random.bin", "binary/random");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
let fileHandle = event.target.result;
|
||||
ok(fileHandle, "Got filehandle");
|
||||
let mutableFile = event.target.result;
|
||||
ok(mutableFile, "Got mutablefile");
|
||||
}
|
||||
else {
|
||||
try {
|
||||
db.mozCreateFileHandle("random.bin", "binary/random");
|
||||
db.createMutableFile("random.bin", "binary/random");
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "MozCreateFileHandle threw");
|
||||
ok(true, "CreateMutableFile threw");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -522,10 +522,10 @@ private:
|
|||
uint32_t mCountdown;
|
||||
};
|
||||
|
||||
class WaitForLockedFilesToFinishRunnable MOZ_FINAL : public nsRunnable
|
||||
class WaitForFileHandlesToFinishRunnable MOZ_FINAL : public nsRunnable
|
||||
{
|
||||
public:
|
||||
WaitForLockedFilesToFinishRunnable()
|
||||
WaitForFileHandlesToFinishRunnable()
|
||||
: mBusy(true)
|
||||
{ }
|
||||
|
||||
|
@ -1441,7 +1441,7 @@ QuotaManager::AbortCloseStoragesForWindow(nsPIDOMWindow* aWindow)
|
|||
}
|
||||
|
||||
if (utilized) {
|
||||
service->AbortLockedFilesForStorage(storage);
|
||||
service->AbortFileHandlesForStorage(storage);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
|
@ -1478,7 +1478,7 @@ QuotaManager::HasOpenTransactions(nsPIDOMWindow* aWindow)
|
|||
nsIOfflineStorage*& storage = storages[j];
|
||||
|
||||
if (storage->IsOwned(aWindow) &&
|
||||
((utilized && service->HasLockedFilesForStorage(storage)) ||
|
||||
((utilized && service->HasFileHandlesForStorage(storage)) ||
|
||||
(activated && client->HasTransactionsForStorage(storage)))) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2350,7 +2350,7 @@ QuotaManager::Observe(nsISupports* aSubject,
|
|||
FileService* service = FileService::Get();
|
||||
if (service) {
|
||||
// This should only wait for storages registered in this manager
|
||||
// to complete. Other storages may still have running locked files.
|
||||
// to complete. Other storages may still have running file handles.
|
||||
// If the necko service (thread pool) gets the shutdown notification
|
||||
// first then the sync loop won't be processed at all, otherwise it will
|
||||
// lock the main thread until all storages registered in this manager
|
||||
|
@ -2367,8 +2367,8 @@ QuotaManager::Observe(nsISupports* aSubject,
|
|||
liveStorages.Find(mLiveStorages, &indexes);
|
||||
|
||||
if (!liveStorages.IsEmpty()) {
|
||||
nsRefPtr<WaitForLockedFilesToFinishRunnable> runnable =
|
||||
new WaitForLockedFilesToFinishRunnable();
|
||||
nsRefPtr<WaitForFileHandlesToFinishRunnable> runnable =
|
||||
new WaitForFileHandlesToFinishRunnable();
|
||||
|
||||
service->WaitForStoragesToComplete(liveStorages, runnable);
|
||||
|
||||
|
@ -4000,7 +4000,7 @@ WaitForTransactionsToFinishRunnable::Run()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
WaitForLockedFilesToFinishRunnable::Run()
|
||||
WaitForFileHandlesToFinishRunnable::Run()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
|
|
|
@ -550,12 +550,12 @@ var interfaceNamesInGlobalScope =
|
|||
"IDBDatabase",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"IDBFactory",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"IDBFileHandle",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"IDBIndex",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"IDBKeyRange",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"IDBMutableFile",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"IDBObjectStore",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
@ -586,8 +586,6 @@ var interfaceNamesInGlobalScope =
|
|||
"LocalMediaStream",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"Location",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"LockedFile",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"MediaElementAudioSourceNode",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
@ -726,6 +724,8 @@ var interfaceNamesInGlobalScope =
|
|||
{name: "MozWifiP2pManager", b2g: true, permission: "wifi-manage"},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "MozWifiP2pStatusChangeEvent", b2g: true, permission: "wifi-manage"},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"MutableFile",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"MutationEvent",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
interface FileRequest : DOMRequest {
|
||||
readonly attribute LockedFile? lockedFile;
|
||||
readonly attribute FileHandle? fileHandle;
|
||||
// this is deprecated due to renaming in the spec
|
||||
readonly attribute FileHandle? lockedFile; // now fileHandle
|
||||
|
||||
attribute EventHandler onprogress;
|
||||
};
|
||||
|
||||
|
|
|
@ -45,5 +45,9 @@ partial interface IDBDatabase {
|
|||
readonly attribute StorageType storage;
|
||||
|
||||
[Throws]
|
||||
IDBRequest mozCreateFileHandle (DOMString name, optional DOMString type);
|
||||
IDBRequest createMutableFile (DOMString name, optional DOMString type);
|
||||
|
||||
// this is deprecated due to renaming in the spec
|
||||
[Throws]
|
||||
IDBRequest mozCreateFileHandle (DOMString name, optional DOMString type); // now createMutableFile
|
||||
};
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
* 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/. */
|
||||
|
||||
interface IDBFileHandle : FileHandle {
|
||||
interface IDBMutableFile : MutableFile {
|
||||
readonly attribute IDBDatabase database;
|
||||
};
|
|
@ -8,9 +8,11 @@ dictionary DOMFileMetadataParameters
|
|||
boolean lastModified = true;
|
||||
};
|
||||
|
||||
interface LockedFile : EventTarget
|
||||
interface FileHandle : EventTarget
|
||||
{
|
||||
readonly attribute FileHandle? fileHandle;
|
||||
readonly attribute MutableFile? mutableFile;
|
||||
// this is deprecated due to renaming in the spec
|
||||
readonly attribute MutableFile? fileHandle; // now mutableFile
|
||||
readonly attribute FileMode mode;
|
||||
readonly attribute boolean active;
|
||||
attribute unsigned long long? location;
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
* 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/. */
|
||||
|
||||
interface FileHandle : EventTarget {
|
||||
interface MutableFile : EventTarget {
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute DOMString type;
|
||||
|
||||
[Throws]
|
||||
LockedFile open(optional FileMode mode = "readonly");
|
||||
FileHandle open(optional FileMode mode = "readonly");
|
||||
|
||||
[Throws]
|
||||
DOMRequest getFile();
|
|
@ -203,9 +203,9 @@ WEBIDL_FILES = [
|
|||
'IDBDatabase.webidl',
|
||||
'IDBEnvironment.webidl',
|
||||
'IDBFactory.webidl',
|
||||
'IDBFileHandle.webidl',
|
||||
'IDBIndex.webidl',
|
||||
'IDBKeyRange.webidl',
|
||||
'IDBMutableFile.webidl',
|
||||
'IDBObjectStore.webidl',
|
||||
'IDBOpenDBRequest.webidl',
|
||||
'IDBRequest.webidl',
|
||||
|
@ -227,7 +227,6 @@ WEBIDL_FILES = [
|
|||
'LinkStyle.webidl',
|
||||
'LocalMediaStream.webidl',
|
||||
'Location.webidl',
|
||||
'LockedFile.webidl',
|
||||
'MediaElementAudioSourceNode.webidl',
|
||||
'MediaError.webidl',
|
||||
'MediaKeyError.webidl',
|
||||
|
@ -259,6 +258,7 @@ WEBIDL_FILES = [
|
|||
'MozPowerManager.webidl',
|
||||
'MozTimeManager.webidl',
|
||||
'MozWakeLock.webidl',
|
||||
'MutableFile.webidl',
|
||||
'MutationEvent.webidl',
|
||||
'MutationObserver.webidl',
|
||||
'NativeOSFileInternals.webidl',
|
||||
|
|
|
@ -811,7 +811,7 @@
|
|||
#define MODULE NS_ERROR_MODULE_DOM_FILEHANDLE
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR, FAILURE(1)),
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_NOT_ALLOWED_ERR, FAILURE(2)),
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_LOCKEDFILE_INACTIVE_ERR, FAILURE(3)),
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_INACTIVE_ERR, FAILURE(3)),
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_ABORT_ERR, FAILURE(4)),
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR, FAILURE(5)),
|
||||
ERROR(NS_ERROR_DOM_FILEHANDLE_QUOTA_ERR, FAILURE(6)),
|
||||
|
|
Загрузка…
Ссылка в новой задаче