From 29df615c5eabc86fbf945c91af92754135e3f2d8 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Tue, 10 Jul 2012 07:07:01 +0200 Subject: [PATCH] Bug 771498 - FileHandle: getFile() should return a DOMRequest (instead of a FileRequest). r=sicking --- dom/file/FileHandle.cpp | 12 ++++++----- dom/file/FileRequest.cpp | 11 ++++++---- dom/file/FileRequest.h | 3 ++- dom/file/LockedFile.cpp | 2 +- dom/file/nsIDOMFileHandle.idl | 6 +++--- dom/file/test/test_stream_tracking.html | 21 +++++++++++++++++-- .../test/test_filehandle_store_snapshot.html | 15 +++++++++---- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/dom/file/FileHandle.cpp b/dom/file/FileHandle.cpp index 345932051662..3f3bacf60244 100644 --- a/dom/file/FileHandle.cpp +++ b/dom/file/FileHandle.cpp @@ -124,7 +124,7 @@ FileHandle::Open(const nsAString& aMode, } NS_IMETHODIMP -FileHandle::GetFile(nsIDOMFileRequest** _retval) +FileHandle::GetFile(nsIDOMDOMRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -137,19 +137,21 @@ FileHandle::GetFile(nsIDOMFileRequest** _retval) LockedFile::Create(this, LockedFile::READ_ONLY, LockedFile::PARALLEL); NS_ENSURE_TRUE(lockedFile, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR); - nsRefPtr fileRequest = - FileRequest::Create(GetOwner(), lockedFile); + nsRefPtr request = + FileRequest::Create(GetOwner(), lockedFile, false); nsRefPtr params = new MetadataParameters(); params->Init(true, false); nsRefPtr helper = - new GetFileHelper(lockedFile, fileRequest, params, this); + new GetFileHelper(lockedFile, request, params, this); nsresult rv = helper->Enqueue(); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR); - fileRequest.forget(_retval); + nsCOMPtr result = static_cast(request); + result.forget(_retval); + return NS_OK; } diff --git a/dom/file/FileRequest.cpp b/dom/file/FileRequest.cpp index cbb3c508e20f..33dd5f9cbd61 100644 --- a/dom/file/FileRequest.cpp +++ b/dom/file/FileRequest.cpp @@ -18,7 +18,7 @@ USING_FILE_NAMESPACE FileRequest::FileRequest(nsIDOMWindow* aWindow) -: DOMRequest(aWindow) +: DOMRequest(aWindow), mIsFileRequest(true) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); } @@ -31,12 +31,14 @@ FileRequest::~FileRequest() // static already_AddRefed FileRequest::Create(nsIDOMWindow* aOwner, - LockedFile* aLockedFile) + LockedFile* aLockedFile, + bool aIsFileRequest) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); nsRefPtr request = new FileRequest(aOwner); request->mLockedFile = aLockedFile; + request->mIsFileRequest = aIsFileRequest; return request.forget(); } @@ -125,8 +127,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FileRequest, DOMRequest) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileRequest) - NS_INTERFACE_MAP_ENTRY(nsIDOMFileRequest) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(FileRequest) + NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFileRequest, mIsFileRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(FileRequest, mIsFileRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(DOMRequest, !mIsFileRequest) NS_INTERFACE_MAP_END_INHERITING(DOMRequest) NS_IMPL_ADDREF_INHERITED(FileRequest, DOMRequest) diff --git a/dom/file/FileRequest.h b/dom/file/FileRequest.h index ee1888264182..ec85c7c854df 100644 --- a/dom/file/FileRequest.h +++ b/dom/file/FileRequest.h @@ -29,7 +29,7 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileRequest, DOMRequest) static already_AddRefed - Create(nsIDOMWindow* aOwner, LockedFile* aLockedFile); + Create(nsIDOMWindow* aOwner, LockedFile* aLockedFile, bool aIsFileRequest); // nsIDOMEventTarget virtual nsresult @@ -55,6 +55,7 @@ private: RootResultVal(); nsRefPtr mLockedFile; + bool mIsFileRequest; NS_DECL_EVENT_HANDLER(progress) }; diff --git a/dom/file/LockedFile.cpp b/dom/file/LockedFile.cpp index c9307714b48c..ae222b661ed5 100644 --- a/dom/file/LockedFile.cpp +++ b/dom/file/LockedFile.cpp @@ -439,7 +439,7 @@ already_AddRefed LockedFile::GenerateFileRequest() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - return FileRequest::Create(GetOwner(), this); + return FileRequest::Create(GetOwner(), this, true); } bool diff --git a/dom/file/nsIDOMFileHandle.idl b/dom/file/nsIDOMFileHandle.idl index 8da1beb10f6f..a94b78821f31 100644 --- a/dom/file/nsIDOMFileHandle.idl +++ b/dom/file/nsIDOMFileHandle.idl @@ -18,11 +18,11 @@ class FileInfo; [ptr] native FileInfo(mozilla::dom::indexedDB::FileInfo); +interface nsIDOMDOMRequest; interface nsIDOMEventListener; -interface nsIDOMFileRequest; interface nsIDOMLockedFile; -[scriptable, builtinclass, uuid(0dc9c73c-4e44-4430-8898-85f61a70b1d2)] +[scriptable, builtinclass, uuid(882ad3d0-6fb1-4841-8e17-0ba17b11edc8)] interface nsIDOMFileHandle : nsISupports { readonly attribute DOMString name; @@ -34,7 +34,7 @@ interface nsIDOMFileHandle : nsISupports nsIDOMLockedFile open([optional /* "readonly" */] in DOMString mode); - nsIDOMFileRequest + nsIDOMDOMRequest getFile(); [notxpcom] diff --git a/dom/file/test/test_stream_tracking.html b/dom/file/test/test_stream_tracking.html index 03c48068f8b2..1fee51d70b71 100644 --- a/dom/file/test/test_stream_tracking.html +++ b/dom/file/test/test_stream_tracking.html @@ -55,6 +55,10 @@ is(e.name, "LockedFileInactiveError", "Good error."); is(e.code, 0, "Good error code."); } + + if (resultBuffer2) { + testGenerator.next(); + } } let reader2 = new FileReader(); @@ -63,10 +67,23 @@ reader2.onload = function(event) { resultBuffer2 = event.target.result; + + let reader = new FileReader(); + try { + reader.readAsArrayBuffer(file); + ok(false, "Should have thrown!"); + } + catch (e) { + ok(e instanceof DOMException, "Got exception."); + is(e.name, "LockedFileInactiveError", "Good error."); + is(e.code, 0, "Good error code."); + } + + if (resultBuffer1) { + testGenerator.next(); + } } - lockedFile = event.target.lockedFile; - lockedFile.oncomplete = grabEventAndContinueHandler; yield; ok(compareBuffers(resultBuffer1, testBuffer), "Correct data"); diff --git a/dom/indexedDB/test/test_filehandle_store_snapshot.html b/dom/indexedDB/test/test_filehandle_store_snapshot.html index 6205bce04c87..d29247830300 100644 --- a/dom/indexedDB/test/test_filehandle_store_snapshot.html +++ b/dom/indexedDB/test/test_filehandle_store_snapshot.html @@ -59,9 +59,6 @@ let file = event.target.result; - lockedFile = event.target.lockedFile; - is(lockedFile.active, true, "Correct active state"); - let trans = db.transaction([objectStoreName], READ_WRITE); let objectStore = trans.objectStore(objectStoreName); @@ -69,7 +66,17 @@ request.onsuccess = grabEventAndContinueHandler; event = yield; - is(lockedFile.active, false, "Correct open state"); + // At this moment, the file should not be readable anymore. + let reader = new FileReader(); + try { + reader.readAsArrayBuffer(file); + ok(false, "Should have thrown!"); + } + catch (e) { + ok(e instanceof DOMException, "Got exception."); + is(e.name, "LockedFileInactiveError", "Good error."); + is(e.code, 0, "Good error code."); + } request = objectStore.get(42); request.onsuccess = grabEventAndContinueHandler;