From 8131e31c4393bd4ba42fc061c02f08874411b9c8 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Thu, 12 Jun 2014 05:35:29 +0200 Subject: [PATCH] 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 --- dom/base/DOMException.cpp | 2 +- dom/base/StructuredCloneTags.h | 2 +- dom/base/domerr.msg | 8 +- dom/base/nsDOMWindowUtils.cpp | 10 +- dom/bindings/Bindings.conf | 18 +- dom/filehandle/File.cpp | 24 +- dom/filehandle/File.h | 8 +- dom/filehandle/FileHelper.cpp | 48 ++-- dom/filehandle/FileHelper.h | 12 +- dom/filehandle/FileRequest.cpp | 16 +- dom/filehandle/FileRequest.h | 16 +- dom/filehandle/FileService.cpp | 173 ++++++------ dom/filehandle/FileService.h | 42 +-- dom/filehandle/FileStreamWrappers.cpp | 6 +- dom/filehandle/LockedFile.cpp | 246 +++++++++--------- dom/filehandle/LockedFile.h | 50 ++-- dom/filehandle/MetadataHelper.cpp | 4 +- dom/filehandle/MetadataHelper.h | 4 +- .../{FileHandle.cpp => MutableFile.cpp} | 60 ++--- .../{FileHandle.h => MutableFile.h} | 26 +- dom/filehandle/moz.build | 4 +- dom/filehandle/test/helpers.js | 32 +++ dom/filehandle/test/mochitest.ini | 18 +- .../test/test_append_read_data.html | 42 +-- dom/filehandle/test/test_compat.html | 41 +++ ...es.html => test_filehandle_lifetimes.html} | 12 +- ... => test_filehandle_lifetimes_nested.html} | 14 +- ...ing.html => test_filehandle_ordering.html} | 24 +- dom/filehandle/test/test_getFile.html | 10 +- dom/filehandle/test/test_location.html | 34 +-- ...html => test_overlapping_filehandles.html} | 18 +- dom/filehandle/test/test_progress_events.html | 14 +- ...es.html => test_readonly_filehandles.html} | 34 +-- .../test/test_request_readyState.html | 14 +- dom/filehandle/test/test_stream_tracking.html | 16 +- .../test/test_success_events_after_abort.html | 16 +- dom/filehandle/test/test_truncate.html | 32 +-- dom/filehandle/test/test_workers.html | 12 +- dom/filehandle/test/test_write_read_data.html | 42 +-- dom/indexedDB/IDBDatabase.cpp | 16 +- dom/indexedDB/IDBDatabase.h | 9 +- .../{IDBFileHandle.cpp => IDBMutableFile.cpp} | 52 ++-- .../{IDBFileHandle.h => IDBMutableFile.h} | 22 +- dom/indexedDB/IDBObjectStore.cpp | 64 ++--- dom/indexedDB/IDBObjectStore.h | 6 +- dom/indexedDB/IndexedDatabaseManager.cpp | 6 +- dom/indexedDB/moz.build | 4 +- dom/indexedDB/test/test_filehandle_quota.html | 12 +- .../test/test_filehandle_serialization.html | 18 +- .../test/test_filehandle_store_snapshot.html | 16 +- dom/indexedDB/test/test_get_filehandle.html | 10 +- dom/quota/QuotaManager.cpp | 16 +- .../mochitest/general/test_interfaces.html | 8 +- dom/webidl/FileRequest.webidl | 5 +- dom/webidl/IDBDatabase.webidl | 6 +- ...ileHandle.webidl => IDBMutableFile.webidl} | 2 +- dom/webidl/LockedFile.webidl | 6 +- .../{FileHandle.webidl => MutableFile.webidl} | 4 +- dom/webidl/moz.build | 4 +- xpcom/base/ErrorList.h | 2 +- 60 files changed, 799 insertions(+), 693 deletions(-) rename dom/filehandle/{FileHandle.cpp => MutableFile.cpp} (70%) rename dom/filehandle/{FileHandle.h => MutableFile.h} (81%) create mode 100644 dom/filehandle/test/test_compat.html rename dom/filehandle/test/{test_lockedfile_lifetimes.html => test_filehandle_lifetimes.html} (76%) rename dom/filehandle/test/{test_lockedfile_lifetimes_nested.html => test_filehandle_lifetimes_nested.html} (80%) rename dom/filehandle/test/{test_lockedfile_ordering.html => test_filehandle_ordering.html} (58%) rename dom/filehandle/test/{test_overlapping_lockedfiles.html => test_overlapping_filehandles.html} (72%) rename dom/filehandle/test/{test_readonly_lockedfiles.html => test_readonly_filehandles.html} (53%) rename dom/indexedDB/{IDBFileHandle.cpp => IDBMutableFile.cpp} (67%) rename dom/indexedDB/{IDBFileHandle.h => IDBMutableFile.h} (76%) rename dom/webidl/{IDBFileHandle.webidl => IDBMutableFile.webidl} (89%) rename dom/webidl/{FileHandle.webidl => MutableFile.webidl} (83%) diff --git a/dom/base/DOMException.cpp b/dom/base/DOMException.cpp index a549bdd1eff..ea2d36959d9 100644 --- a/dom/base/DOMException.cpp +++ b/dom/base/DOMException.cpp @@ -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, diff --git a/dom/base/StructuredCloneTags.h b/dom/base/StructuredCloneTags.h index 238b124f94c..675264f9ab8 100644 --- a/dom/base/StructuredCloneTags.h +++ b/dom/base/StructuredCloneTags.h @@ -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. diff --git a/dom/base/domerr.msg b/dom/base/domerr.msg index 159671446b9..84444263538 100644 --- a/dom/base/domerr.msg +++ b/dom/base/domerr.msg @@ -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") diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 20a8672e716..c95180f1e57 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -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 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; } diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 0c93cbd0e6d..30a594f337d 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -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', }, diff --git a/dom/filehandle/File.cpp b/dom/filehandle/File.cpp index 7f7a7dd6573..3594bfe4df4 100644 --- a/dom/filehandle/File.cpp +++ b/dom/filehandle/File.cpp @@ -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); diff --git a/dom/filehandle/File.h b/dom/filehandle/File.h index 80762c58fcf..a0a588e6d50 100644 --- a/dom/filehandle/File.h +++ b/dom/filehandle/File.h @@ -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 mFile; - nsRefPtr mLockedFile; + nsRefPtr mFileHandle; bool mWholeFile; bool mStoredFile; diff --git a/dom/filehandle/FileHelper.cpp b/dom/filehandle/FileHelper.cpp index 8729ce51447..035196b3f49 100644 --- a/dom/filehandle/FileHelper.cpp +++ b/dom/filehandle/FileHelper.cpp @@ -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 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!"); } diff --git a/dom/filehandle/FileHelper.h b/dom/filehandle/FileHelper.h index e0d0abb659d..387d16279ef 100644 --- a/dom/filehandle/FileHelper.h +++ b/dom/filehandle/FileHelper.h @@ -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 mMutableFile; nsRefPtr mFileHandle; - nsRefPtr mLockedFile; nsRefPtr mFileRequest; nsRefPtr mListener; diff --git a/dom/filehandle/FileRequest.cpp b/dom/filehandle/FileRequest.cpp index f123e8eea0e..db10ff089f5 100644 --- a/dom/filehandle/FileRequest.cpp +++ b/dom/filehandle/FileRequest.cpp @@ -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::Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile, +FileRequest::Create(nsPIDOMWindow* aOwner, FileHandle* aFileHandle, bool aWrapAsDOMRequest) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); nsRefPtr 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 diff --git a/dom/filehandle/FileRequest.h b/dom/filehandle/FileRequest.h index 878c91eedd0..726612705e7 100644 --- a/dom/filehandle/FileRequest.h +++ b/dom/filehandle/FileRequest.h @@ -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 - 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 mLockedFile; + nsRefPtr mFileHandle; bool mWrapAsDOMRequest; }; diff --git a/dom/filehandle/FileService.cpp b/dom/filehandle/FileService.cpp index de4285473c8..35f12655362 100644 --- a/dom/filehandle/FileService.cpp +++ b/dom/filehandle/FileService.cpp @@ -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, 10> lockedFiles; - storageInfo->CollectRunningAndDelayedLockedFiles(aStorage, lockedFiles); + nsAutoTArray, 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 = - mLockedFileQueues.AppendElement(); - *lockedFileQueue = new LockedFileQueue(aLockedFile); - return lockedFileQueue->get(); + nsRefPtr* 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 = mLockedFileQueues[index]; - if (lockedFileQueue->mLockedFile == aLockedFile) { - return lockedFileQueue; + nsRefPtr& 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 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 >& aLockedFiles) + nsTArray>& 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); } } } diff --git a/dom/filehandle/FileService.h b/dom/filehandle/FileService.h index de6daf705e5..5a721eae267 100644 --- a/dom/filehandle/FileService.h +++ b/dom/filehandle/FileService.h @@ -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 >& 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 mLockedFile; + nsRefPtr mFileHandle; nsTArray > mQueue; nsRefPtr mCurrentHelper; }; @@ -109,7 +109,7 @@ private: DelayedEnqueueInfo(); ~DelayedEnqueueInfo(); - nsRefPtr mLockedFile; + nsRefPtr mFileHandle; nsRefPtr 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 >& aLockedFiles); + nsTArray>& aFileHandles); void LockFileForReading(const nsAString& aFileName) @@ -173,7 +173,7 @@ private: { } - nsTArray > mLockedFileQueues; + nsTArray> mFileHandleQueues; nsTArray mDelayedEnqueueInfos; nsTHashtable mFilesReading; nsTHashtable mFilesWriting; diff --git a/dom/filehandle/FileStreamWrappers.cpp b/dom/filehandle/FileStreamWrappers.cpp index 5d89e341542..f38c22c63f5 100644 --- a/dom/filehandle/FileStreamWrappers.cpp +++ b/dom/filehandle/FileStreamWrappers.cpp @@ -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 seekable = do_QueryInterface(mOutputStream); if (seekable) { diff --git a/dom/filehandle/LockedFile.cpp b/dom/filehandle/LockedFile.cpp index 4f91e60fd46..c94fd252888 100644 --- a/dom/filehandle/LockedFile.cpp +++ b/dom/filehandle/LockedFile.cpp @@ -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::Create(FileHandle* aFileHandle, +already_AddRefed +FileHandle::Create(MutableFile* aMutableFile, FileMode aMode, RequestMode aRequestMode) { - NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); + MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr lockedFile = new LockedFile(); + nsRefPtr 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 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 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 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 -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 -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 -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 -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 -LockedFile::Truncate(const Optional& aSize, ErrorResult& aRv) +FileHandle::Truncate(const Optional& 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& 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& aSize, ErrorResult& aRv) } already_AddRefed -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 -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 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 -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 -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 -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 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 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 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; diff --git a/dom/filehandle/LockedFile.h b/dom/filehandle/LockedFile.h index a3bb047a9b8..3a2c8a10b26 100644 --- a/dom/filehandle/LockedFile.h +++ b/dom/filehandle/LockedFile.h @@ -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 - Create(FileHandle* aFileHandle, + static already_AddRefed + 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 mFileHandle; + nsRefPtr mMutableFile; ReadyState mReadyState; FileMode mMode; RequestMode mRequestMode; uint64_t mLocation; uint32_t mPendingRequests; - nsTArray > mParallelStreams; + nsTArray> mParallelStreams; nsCOMPtr 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 mLockedFile; - nsTArray > mParallelStreams; + nsRefPtr mFileHandle; + nsTArray> mParallelStreams; nsCOMPtr mStream; bool mAborted; @@ -316,4 +322,4 @@ private: } // namespace dom } // namespace mozilla -#endif // mozilla_dom_LockedFile_h +#endif // mozilla_dom_FileHandle_h diff --git a/dom/filehandle/MetadataHelper.cpp b/dom/filehandle/MetadataHelper.cpp index ac1df2eaca4..8d9c95a6dfe 100644 --- a/dom/filehandle/MetadataHelper.cpp +++ b/dom/filehandle/MetadataHelper.cpp @@ -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 getter = new AsyncMetadataGetter(aStream, mParams, readWrite); diff --git a/dom/filehandle/MetadataHelper.h b/dom/filehandle/MetadataHelper.h index bd8c17da02e..d8560e346d1 100644 --- a/dom/filehandle/MetadataHelper.h +++ b/dom/filehandle/MetadataHelper.h @@ -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) { } diff --git a/dom/filehandle/FileHandle.cpp b/dom/filehandle/MutableFile.cpp similarity index 70% rename from dom/filehandle/FileHandle.cpp rename to dom/filehandle/MutableFile.cpp index 9282944b783..b24004af2f4 100644 --- a/dom/filehandle/FileHandle.cpp +++ b/dom/filehandle/MutableFile.cpp @@ -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 mFileHandle; + nsRefPtr 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 -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 -FileHandle::CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) +MutableFile::CreateFileObject(FileHandle* aFileHandle, uint32_t aFileSize) { nsCOMPtr 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 -FileHandle::Open(FileMode aMode, ErrorResult& aError) +already_AddRefed +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::Create(this, aMode); - if (!lockedFile) { + nsRefPtr 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 -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::Create(this, FileMode::Readonly, LockedFile::PARALLEL); - if (!lockedFile) { + nsRefPtr fileHandle = + FileHandle::Create(this, FileMode::Readonly, FileHandle::PARALLEL); + if (!fileHandle) { aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR); return nullptr; } nsRefPtr request = - FileRequest::Create(GetOwner(), lockedFile, /* aWrapAsDOMRequest */ true); + FileRequest::Create(GetOwner(), fileHandle, /* aWrapAsDOMRequest */ true); nsRefPtr params = new MetadataParameters(true, false); nsRefPtr 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 aVal) { nsCOMPtr domFile = - mFileHandle->CreateFileObject(mLockedFile, mParams->Size()); + mMutableFile->CreateFileObject(mFileHandle, mParams->Size()); nsresult rv = nsContentUtils::WrapNative(aCx, domFile, &NS_GET_IID(nsIDOMFile), aVal); diff --git a/dom/filehandle/FileHandle.h b/dom/filehandle/MutableFile.h similarity index 81% rename from dom/filehandle/FileHandle.h rename to dom/filehandle/MutableFile.h index 0416be63a3b..f17b34eaa44 100644 --- a/dom/filehandle/FileHandle.h +++ b/dom/filehandle/MutableFile.h @@ -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 - CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize); + CreateFileObject(FileHandle* aFileHandle, uint32_t aFileSize); // nsWrapperCache virtual JSObject* @@ -127,7 +127,7 @@ public: aType = mType; } - already_AddRefed + already_AddRefed Open(FileMode aMode, ErrorResult& aError); already_AddRefed @@ -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 diff --git a/dom/filehandle/moz.build b/dom/filehandle/moz.build index 4950b9a4558..833e55306c6 100644 --- a/dom/filehandle/moz.build +++ b/dom/filehandle/moz.build @@ -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 diff --git a/dom/filehandle/test/helpers.js b/dom/filehandle/test/helpers.js index f191a76706a..adbe8e2c389 100644 --- a/dom/filehandle/test/helpers.js +++ b/dom/filehandle/test/helpers.js @@ -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(); diff --git a/dom/filehandle/test/mochitest.ini b/dom/filehandle/test/mochitest.ini index f178487adbc..70654d771a9 100644 --- a/dom/filehandle/test/mochitest.ini +++ b/dom/filehandle/test/mochitest.ini @@ -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' diff --git a/dom/filehandle/test/test_append_read_data.html b/dom/filehandle/test/test_append_read_data.html index 8e388da4db7..9311051e2c6 100644 --- a/dom/filehandle/test/test_append_read_data.html +++ b/dom/filehandle/test/test_append_read_data.html @@ -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; diff --git a/dom/filehandle/test/test_compat.html b/dom/filehandle/test/test_compat.html new file mode 100644 index 00000000000..82a71595fe6 --- /dev/null +++ b/dom/filehandle/test/test_compat.html @@ -0,0 +1,41 @@ + + + + File Handle Test + + + + + + + + + + + + diff --git a/dom/filehandle/test/test_lockedfile_lifetimes.html b/dom/filehandle/test/test_filehandle_lifetimes.html similarity index 76% rename from dom/filehandle/test/test_lockedfile_lifetimes.html rename to dom/filehandle/test/test_filehandle_lifetimes.html index b25ee8efc3c..fd07354ae4e 100644 --- a/dom/filehandle/test/test_lockedfile_lifetimes.html +++ b/dom/filehandle/test/test_filehandle_lifetimes.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."); } } diff --git a/dom/filehandle/test/test_lockedfile_lifetimes_nested.html b/dom/filehandle/test/test_filehandle_lifetimes_nested.html similarity index 80% rename from dom/filehandle/test/test_lockedfile_lifetimes_nested.html rename to dom/filehandle/test/test_filehandle_lifetimes_nested.html index 448e6da0560..23fea6a7e6e 100644 --- a/dom/filehandle/test/test_lockedfile_lifetimes_nested.html +++ b/dom/filehandle/test/test_filehandle_lifetimes_nested.html @@ -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; diff --git a/dom/filehandle/test/test_lockedfile_ordering.html b/dom/filehandle/test/test_filehandle_ordering.html similarity index 58% rename from dom/filehandle/test/test_lockedfile_ordering.html rename to dom/filehandle/test/test_filehandle_ordering.html index 328902196c9..d8a226ff7e1 100644 --- a/dom/filehandle/test/test_lockedfile_ordering.html +++ b/dom/filehandle/test/test_filehandle_ordering.html @@ -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(); diff --git a/dom/filehandle/test/test_getFile.html b/dom/filehandle/test/test_getFile.html index 7eb6ed950bc..0774666e220 100644 --- a/dom/filehandle/test/test_getFile.html +++ b/dom/filehandle/test/test_getFile.html @@ -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"); diff --git a/dom/filehandle/test/test_location.html b/dom/filehandle/test/test_location.html index ee1b7e07235..0a735541388 100644 --- a/dom/filehandle/test/test_location.html +++ b/dom/filehandle/test/test_location.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("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(); diff --git a/dom/filehandle/test/test_overlapping_lockedfiles.html b/dom/filehandle/test/test_overlapping_filehandles.html similarity index 72% rename from dom/filehandle/test/test_overlapping_lockedfiles.html rename to dom/filehandle/test/test_overlapping_filehandles.html index 72d5b47a525..05b65b6dfd5 100644 --- a/dom/filehandle/test/test_overlapping_lockedfiles.html +++ b/dom/filehandle/test/test_overlapping_filehandles.html @@ -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++; diff --git a/dom/filehandle/test/test_progress_events.html b/dom/filehandle/test/test_progress_events.html index 929b1b1c8aa..b0875e92d64 100644 --- a/dom/filehandle/test/test_progress_events.html +++ b/dom/filehandle/test/test_progress_events.html @@ -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; diff --git a/dom/filehandle/test/test_readonly_lockedfiles.html b/dom/filehandle/test/test_readonly_filehandles.html similarity index 53% rename from dom/filehandle/test/test_readonly_lockedfiles.html rename to dom/filehandle/test/test_readonly_filehandles.html index 16ff037dbaf..e2d29da9688 100644 --- a/dom/filehandle/test/test_readonly_lockedfiles.html +++ b/dom/filehandle/test/test_readonly_filehandles.html @@ -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"); } } diff --git a/dom/filehandle/test/test_request_readyState.html b/dom/filehandle/test/test_request_readyState.html index b434583792d..e6ccf0d41b7 100644 --- a/dom/filehandle/test/test_request_readyState.html +++ b/dom/filehandle/test/test_request_readyState.html @@ -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; diff --git a/dom/filehandle/test/test_stream_tracking.html b/dom/filehandle/test/test_stream_tracking.html index 99fc5deb09f..890a9bcde0d 100644 --- a/dom/filehandle/test/test_stream_tracking.html +++ b/dom/filehandle/test/test_stream_tracking.html @@ -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."); } diff --git a/dom/filehandle/test/test_success_events_after_abort.html b/dom/filehandle/test/test_success_events_after_abort.html index e753fbb0df8..d45bfa6d0c9 100644 --- a/dom/filehandle/test/test_success_events_after_abort.html +++ b/dom/filehandle/test/test_success_events_after_abort.html @@ -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; diff --git a/dom/filehandle/test/test_truncate.html b/dom/filehandle/test/test_truncate.html index 28575c318f7..f2540564f6b 100644 --- a/dom/filehandle/test/test_truncate.html +++ b/dom/filehandle/test/test_truncate.html @@ -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; diff --git a/dom/filehandle/test/test_workers.html b/dom/filehandle/test/test_workers.html index 6b8a123026b..b3cdb3d864e 100644 --- a/dom/filehandle/test/test_workers.html +++ b/dom/filehandle/test/test_workers.html @@ -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; diff --git a/dom/filehandle/test/test_write_read_data.html b/dom/filehandle/test/test_write_read_data.html index e8cdc2dc5c9..f951b4b9650 100644 --- a/dom/filehandle/test/test_write_read_data.html +++ b/dom/filehandle/test/test_write_read_data.html @@ -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; diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index 438bc65c37b..8b393757c5f 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -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& aStoreNames, } already_AddRefed -IDBDatabase::MozCreateFileHandle(const nsAString& aName, - const Optional& aType, - ErrorResult& aRv) +IDBDatabase::CreateMutableFile(const nsAString& aName, + const Optional& aType, + ErrorResult& aRv) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -930,9 +930,9 @@ nsresult CreateFileHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle aVal) { - nsRefPtr fileHandle = - IDBFileHandle::Create(mName, mType, mDatabase, mFileInfo.forget()); - IDB_ENSURE_TRUE(fileHandle, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); + nsRefPtr 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); } diff --git a/dom/indexedDB/IDBDatabase.h b/dom/indexedDB/IDBDatabase.h index feb707673ae..69832f00427 100644 --- a/dom/indexedDB/IDBDatabase.h +++ b/dom/indexedDB/IDBDatabase.h @@ -225,9 +225,16 @@ public: return PersistenceTypeToStorage(mPersistenceType); } + already_AddRefed + CreateMutableFile(const nsAString& aName, const Optional& aType, + ErrorResult& aRv); + already_AddRefed MozCreateFileHandle(const nsAString& aName, const Optional& aType, - ErrorResult& aRv); + ErrorResult& aRv) + { + return CreateMutableFile(aName, aType, aRv); + } virtual void LastRelease() MOZ_OVERRIDE; diff --git a/dom/indexedDB/IDBFileHandle.cpp b/dom/indexedDB/IDBMutableFile.cpp similarity index 67% rename from dom/indexedDB/IDBFileHandle.cpp rename to dom/indexedDB/IDBMutableFile.cpp index b94cf1b713f..be8c2d548f3 100644 --- a/dom/indexedDB/IDBFileHandle.cpp +++ b/dom/indexedDB/IDBMutableFile.cpp @@ -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::Create(const nsAString& aName, - const nsAString& aType, - IDBDatabase* aDatabase, - already_AddRefed aFileInfo) +already_AddRefed +IDBMutableFile::Create(const nsAString& aName, + const nsAString& aType, + IDBDatabase* aDatabase, + already_AddRefed aFileInfo) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); nsRefPtr fileInfo(aFileInfo); NS_ASSERTION(fileInfo, "Null pointer!"); - nsRefPtr newFile = new IDBFileHandle(aDatabase); + nsRefPtr 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 -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 -IDBFileHandle::CreateFileObject(mozilla::dom::LockedFile* aLockedFile, +IDBMutableFile::CreateFileObject(mozilla::dom::FileHandle* aFileHandle, uint32_t aFileSize) { nsCOMPtr 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); } diff --git a/dom/indexedDB/IDBFileHandle.h b/dom/indexedDB/IDBMutableFile.h similarity index 76% rename from dom/indexedDB/IDBFileHandle.h rename to dom/indexedDB/IDBMutableFile.h index 56767309fec..fbe6fe5e38c 100644 --- a/dom/indexedDB/IDBFileHandle.h +++ b/dom/indexedDB/IDBMutableFile.h @@ -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 + static already_AddRefed Create(const nsAString& aName, const nsAString& aType, IDBDatabase* aDatabase, already_AddRefed aFileInfo); @@ -65,7 +65,7 @@ public: UnsetThreadLocals() MOZ_OVERRIDE; virtual already_AddRefed - 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__ diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 9b0df2d5a23..0401e6d986c 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -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 = aFile.mFileInfo; - nsRefPtr fileHandle = IDBFileHandle::Create(aData.name, + nsRefPtr 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 = fileHandle->GetFileInfo(); + MutableFile* mutableFile = nullptr; + if (NS_SUCCEEDED(UNWRAP_OBJECT(MutableFile, aObj, mutableFile))) { + nsRefPtr 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()) || diff --git a/dom/indexedDB/IDBObjectStore.h b/dom/indexedDB/IDBObjectStore.h index d53d5eebbfd..0d164c8ffae 100644 --- a/dom/indexedDB/IDBObjectStore.h +++ b/dom/indexedDB/IDBObjectStore.h @@ -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, diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp index 22babc6debb..6c6dd44cc4a 100644 --- a/dom/indexedDB/IndexedDatabaseManager.cpp +++ b/dom/indexedDB/IndexedDatabaseManager.cpp @@ -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) || diff --git a/dom/indexedDB/moz.build b/dom/indexedDB/moz.build index 866a60c69cc..ac32053995c 100644 --- a/dom/indexedDB/moz.build +++ b/dom/indexedDB/moz.build @@ -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', diff --git a/dom/indexedDB/test/test_filehandle_quota.html b/dom/indexedDB/test/test_filehandle_quota.html index 53bc46a12d8..fb64f1ca493 100644 --- a/dom/indexedDB/test/test_filehandle_quota.html +++ b/dom/indexedDB/test/test_filehandle_quota.html @@ -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"); diff --git a/dom/indexedDB/test/test_filehandle_serialization.html b/dom/indexedDB/test/test_filehandle_serialization.html index bfcc0c65df6..6ef2941dab0 100644 --- a/dom/indexedDB/test/test_filehandle_serialization.html +++ b/dom/indexedDB/test/test_filehandle_serialization.html @@ -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) { diff --git a/dom/indexedDB/test/test_filehandle_store_snapshot.html b/dom/indexedDB/test/test_filehandle_store_snapshot.html index 42dfaf0aaa3..12d48de91f8 100644 --- a/dom/indexedDB/test/test_filehandle_store_snapshot.html +++ b/dom/indexedDB/test/test_filehandle_store_snapshot.html @@ -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."); } diff --git a/dom/indexedDB/test/test_get_filehandle.html b/dom/indexedDB/test/test_get_filehandle.html index 5deafe411cd..d42642ccae9 100644 --- a/dom/indexedDB/test/test_get_filehandle.html +++ b/dom/indexedDB/test/test_get_filehandle.html @@ -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"); } } diff --git a/dom/quota/QuotaManager.cpp b/dom/quota/QuotaManager.cpp index 6ad0aeb08ee..8680643339e 100644 --- a/dom/quota/QuotaManager.cpp +++ b/dom/quota/QuotaManager.cpp @@ -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 runnable = - new WaitForLockedFilesToFinishRunnable(); + nsRefPtr 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!"); diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 112ddf590df..e4ce7e6d69f 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -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! diff --git a/dom/webidl/FileRequest.webidl b/dom/webidl/FileRequest.webidl index 3a9927b9354..320641a8854 100644 --- a/dom/webidl/FileRequest.webidl +++ b/dom/webidl/FileRequest.webidl @@ -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; }; + diff --git a/dom/webidl/IDBDatabase.webidl b/dom/webidl/IDBDatabase.webidl index d03c08be007..2401c555008 100644 --- a/dom/webidl/IDBDatabase.webidl +++ b/dom/webidl/IDBDatabase.webidl @@ -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 }; diff --git a/dom/webidl/IDBFileHandle.webidl b/dom/webidl/IDBMutableFile.webidl similarity index 89% rename from dom/webidl/IDBFileHandle.webidl rename to dom/webidl/IDBMutableFile.webidl index 5f9da55a12f..b926f79d301 100644 --- a/dom/webidl/IDBFileHandle.webidl +++ b/dom/webidl/IDBMutableFile.webidl @@ -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; }; diff --git a/dom/webidl/LockedFile.webidl b/dom/webidl/LockedFile.webidl index b1cf1dd517a..8c478d80bbe 100644 --- a/dom/webidl/LockedFile.webidl +++ b/dom/webidl/LockedFile.webidl @@ -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; diff --git a/dom/webidl/FileHandle.webidl b/dom/webidl/MutableFile.webidl similarity index 83% rename from dom/webidl/FileHandle.webidl rename to dom/webidl/MutableFile.webidl index a35bcbb1c0a..51d08e2af7b 100644 --- a/dom/webidl/FileHandle.webidl +++ b/dom/webidl/MutableFile.webidl @@ -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(); diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index bfd49880abf..a3f3c0148d3 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -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', diff --git a/xpcom/base/ErrorList.h b/xpcom/base/ErrorList.h index 7899634be50..bc2b8ce607c 100644 --- a/xpcom/base/ErrorList.h +++ b/xpcom/base/ErrorList.h @@ -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)),