Bug 661582: XHR.response should return a Blob, not a File. r=sicking

This commit is contained in:
Kyle Huey 2011-06-30 14:42:15 -07:00
parent 938ba969e8
commit 3d981011e9
2 changed files with 30 additions and 5 deletions

View File

@ -1620,9 +1620,21 @@ void nsXMLHttpRequest::CreateResponseBlob(nsIRequest *request)
if (cc) {
cc->GetCacheToken(getter_AddRefs(cacheToken));
}
mResponseBlob = new nsDOMFile(file,
NS_ConvertASCIItoUTF16(contentType),
cacheToken);
NS_ConvertASCIItoUTF16 wideContentType(contentType);
nsCOMPtr<nsIDOMBlob> blob =
new nsDOMFile(file, wideContentType, cacheToken);
// XXXkhuey this is a complete hack ... but we need to get 6 out the door
// The response blob here should not be a File object, it should only
// be a Blob. Unfortunately, because nsDOMFile has grown through
// accretion over the years and is in dangerous need of a refactoring,
// slicing it is the easiest way to get there ...
PRUint64 size = 0;
blob->GetSize(&size);
blob->MozSlice(0, size, wideContentType, 2, getter_AddRefs(mResponseBlob));
mResponseBody.Truncate();
mResponseBodyUnicode.SetIsVoid(PR_TRUE);
}
@ -1893,9 +1905,20 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
void *blobData = PR_Malloc(blobLen);
if (blobData) {
memcpy(blobData, mResponseBody.BeginReading(), blobLen);
mResponseBlob =
NS_ConvertASCIItoUTF16 wideContentType(contentType);
nsCOMPtr<nsIDOMBlob> blob =
new nsDOMMemoryFile(blobData, blobLen, EmptyString(),
NS_ConvertASCIItoUTF16(contentType));
wideContentType);
// XXXkhuey this is a complete hack ... but we need to get 6 out the door
// The response blob here should not be a File object, it should only
// be a Blob. Unfortunately, because nsDOMFile has grown through
// accretion over the years and is in dangerous need of a refactoring,
// slicing it is the easiest way to get there ...
blob->MozSlice(0, blobLen, wideContentType,
2, getter_AddRefs(mResponseBlob));
mResponseBody.Truncate();
}
NS_ASSERTION(mResponseBodyUnicode.IsVoid(),

View File

@ -160,6 +160,8 @@ checkResponseTextAccessThrows(xhr);
checkResponseXMLAccessThrows(xhr);
b = xhr.response;
ok(b, "should have a non-null blob");
ok(b instanceof Blob, "should be a Blob");
ok(!(b instanceof File), "should not be a File");
is(b.size, "hello pass\n".length, "wrong blob size");
var fr = new FileReader();