Bug 282432 - Calling asyncOpen on a file channel should notify about file not found errors asynchronously instead of throwing from asyncOpen. r=bz
This commit is contained in:
@@ -273,7 +273,8 @@ nsFileChannel::nsFileChannel(nsIURI *uri)
|
||||
nsresult
|
||||
nsFileChannel::MakeFileInputStream(nsIFile *file,
|
||||
nsCOMPtr<nsIInputStream> &stream,
|
||||
nsCString &contentType)
|
||||
nsCString &contentType,
|
||||
bool async)
|
||||
{
|
||||
// we accept that this might result in a disk hit to stat the file
|
||||
bool isDir;
|
||||
@@ -282,7 +283,14 @@ nsFileChannel::MakeFileInputStream(nsIFile *file,
|
||||
// canonicalize error message
|
||||
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
|
||||
rv = NS_ERROR_FILE_NOT_FOUND;
|
||||
return rv;
|
||||
|
||||
if (async && (NS_ERROR_FILE_NOT_FOUND == rv)) {
|
||||
// We don't return "Not Found" errors here. Since we could not find
|
||||
// the file, it's not a directory anyway.
|
||||
isDir = false;
|
||||
} else {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDir) {
|
||||
@@ -290,7 +298,8 @@ nsFileChannel::MakeFileInputStream(nsIFile *file,
|
||||
if (NS_SUCCEEDED(rv) && !HasContentTypeHint())
|
||||
contentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
|
||||
} else {
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file);
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file, -1, -1,
|
||||
async? nsIFileInputStream::DEFER_OPEN : 0);
|
||||
if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) {
|
||||
// Use file extension to infer content type
|
||||
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv);
|
||||
@@ -364,7 +373,7 @@ nsFileChannel::OpenContentStream(bool async, nsIInputStream **result,
|
||||
SetContentType(NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM));
|
||||
} else {
|
||||
nsAutoCString contentType;
|
||||
rv = MakeFileInputStream(file, stream, contentType);
|
||||
rv = MakeFileInputStream(file, stream, contentType, async);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
@@ -374,8 +383,15 @@ nsFileChannel::OpenContentStream(bool async, nsIInputStream **result,
|
||||
if (mContentLength < 0) {
|
||||
int64_t size;
|
||||
rv = file->GetFileSize(&size);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) {
|
||||
if (async &&
|
||||
(NS_ERROR_FILE_NOT_FOUND == rv ||
|
||||
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv)) {
|
||||
size = 0;
|
||||
} else {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
mContentLength = size;
|
||||
}
|
||||
if (!contentType.IsEmpty())
|
||||
|
||||
@@ -28,7 +28,7 @@ protected:
|
||||
// NOTE: If the channel has a type hint set, contentType will be left
|
||||
// untouched. The caller should not use it in that case.
|
||||
nsresult MakeFileInputStream(nsIFile *file, nsCOMPtr<nsIInputStream> &stream,
|
||||
nsCString &contentType);
|
||||
nsCString &contentType, bool async);
|
||||
|
||||
virtual nsresult OpenContentStream(bool async, nsIInputStream **result,
|
||||
nsIChannel** channel);
|
||||
|
||||
Reference in New Issue
Block a user