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:
Oonishi Atsushi 2012-05-09 18:46:12 -04:00
parent e6a700a873
commit 7fdeac46a5

View File

@ -312,10 +312,14 @@ nsFileChannel::MakeFileInputStream(nsIFile *file,
bool isDir;
nsresult rv = file->IsDirectory(&isDir);
if (NS_FAILED(rv)) {
// canonicalize error message
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
rv = NS_ERROR_FILE_NOT_FOUND;
return rv;
if (NS_ERROR_FILE_NOT_FOUND == rv ||
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == 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) {
@ -323,7 +327,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,
nsIFileInputStream::DEFER_OPEN);
if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) {
// Use file extension to infer content type
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv);
@ -407,8 +412,14 @@ nsFileChannel::OpenContentStream(bool async, nsIInputStream **result,
if (ContentLength64() < 0) {
PRInt64 size;
rv = file->GetFileSize(&size);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
if (NS_ERROR_FILE_NOT_FOUND == rv ||
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv) {
size = 0;
} else {
return rv;
}
}
SetContentLength64(size);
}
if (!contentType.IsEmpty())