Bug 771498 - FileHandle: getFile() should return a DOMRequest (instead of a FileRequest). r=sicking

This commit is contained in:
Jan Varga 2012-07-10 07:07:01 +02:00
parent 6e9f5a8a5b
commit 29df615c5e
7 changed files with 50 additions and 20 deletions

View File

@ -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 =
FileRequest::Create(GetOwner(), lockedFile);
nsRefPtr<FileRequest> request =
FileRequest::Create(GetOwner(), lockedFile, false);
nsRefPtr<MetadataParameters> params = new MetadataParameters();
params->Init(true, false);
nsRefPtr<GetFileHelper> 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<nsIDOMDOMRequest> result = static_cast<DOMRequest*>(request);
result.forget(_retval);
return NS_OK;
}

View File

@ -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>
FileRequest::Create(nsIDOMWindow* aOwner,
LockedFile* aLockedFile)
LockedFile* aLockedFile,
bool aIsFileRequest)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsRefPtr<FileRequest> 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)

View File

@ -29,7 +29,7 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileRequest, DOMRequest)
static already_AddRefed<FileRequest>
Create(nsIDOMWindow* aOwner, LockedFile* aLockedFile);
Create(nsIDOMWindow* aOwner, LockedFile* aLockedFile, bool aIsFileRequest);
// nsIDOMEventTarget
virtual nsresult
@ -55,6 +55,7 @@ private:
RootResultVal();
nsRefPtr<LockedFile> mLockedFile;
bool mIsFileRequest;
NS_DECL_EVENT_HANDLER(progress)
};

View File

@ -439,7 +439,7 @@ already_AddRefed<FileRequest>
LockedFile::GenerateFileRequest()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
return FileRequest::Create(GetOwner(), this);
return FileRequest::Create(GetOwner(), this, true);
}
bool

View File

@ -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]

View File

@ -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");

View File

@ -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;