Bug 1397145 - Remove the support for moz-blob type in XHR, r=smaug

This commit is contained in:
Andrea Marchesini 2017-09-22 07:18:14 +02:00
Родитель e3c9cbb969
Коммит 2071ba4680
9 изменённых файлов: 87 добавлений и 201 удалений

Просмотреть файл

@ -217,7 +217,6 @@ pref(clipboard.autocopy,true) load 1370737.html
pref(dom.IntersectionObserver.enabled,true) load 1370968.html pref(dom.IntersectionObserver.enabled,true) load 1370968.html
load 1377826.html load 1377826.html
skip-if(stylo&&isDebugBuild&&winWidget) load structured_clone_container_throws.html # Bug 1383845 skip-if(stylo&&isDebugBuild&&winWidget) load structured_clone_container_throws.html # Bug 1383845
HTTP(..) load xhr_abortinprogress.html
load xhr_empty_datauri.html load xhr_empty_datauri.html
load xhr_html_nullresponse.html load xhr_html_nullresponse.html
load 1383478.html load 1383478.html

Просмотреть файл

@ -1,23 +0,0 @@
<!DOCTYPE html>
<html class="reftest-wait">
<meta charset=UTF-8>
<script>"use strict";
(function(){
var req = new XMLHttpRequest();
req.open('GET', '?' + Date.now());
req.responseType = 'moz-blob';
var b = null;
req.onprogress = function(e) {
b = req.response;
};
req.onreadystatechange = function(e) {
if (req.readyState == 3) {
req.abort();
}
if (req.readyState == 4) {
document.documentElement.removeAttribute('class');
}
};
req.send();
})();
</script>

Просмотреть файл

@ -25,7 +25,6 @@ enum XMLHttpRequestResponseType {
// Mozilla-specific stuff // Mozilla-specific stuff
"moz-chunked-text", "moz-chunked-text",
"moz-chunked-arraybuffer", "moz-chunked-arraybuffer",
"moz-blob"
}; };
/** /**

Просмотреть файл

@ -315,7 +315,6 @@ XMLHttpRequestMainThread::ResetResponse()
TruncateResponseText(); TruncateResponseText();
mResponseBlob = nullptr; mResponseBlob = nullptr;
mBlobStorage = nullptr; mBlobStorage = nullptr;
mBlobSet = nullptr;
mResultArrayBuffer = nullptr; mResultArrayBuffer = nullptr;
mArrayBufferBuilder.reset(); mArrayBufferBuilder.reset();
mResultJSON.setUndefined(); mResultJSON.setUndefined();
@ -682,31 +681,6 @@ XMLHttpRequestMainThread::CreateResponseParsedJSON(JSContext* aCx)
return NS_OK; return NS_OK;
} }
void
XMLHttpRequestMainThread::CreatePartialBlob(ErrorResult& aRv)
{
// mBlobSet can be null if the request has been canceled
if (!mBlobSet) {
return;
}
nsAutoCString contentType;
if (mState == State::done) {
mChannel->GetContentType(contentType);
}
nsTArray<RefPtr<BlobImpl>> subImpls(mBlobSet->GetBlobImpls());
RefPtr<BlobImpl> blobImpl =
MultipartBlobImpl::Create(Move(subImpls),
NS_ConvertASCIItoUTF16(contentType),
aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mResponseBlob = Blob::Create(GetOwner(), blobImpl);
}
NS_IMETHODIMP XMLHttpRequestMainThread::GetResponseType(nsAString& aResponseType) NS_IMETHODIMP XMLHttpRequestMainThread::GetResponseType(nsAString& aResponseType)
{ {
MOZ_ASSERT(mResponseType < XMLHttpRequestResponseType::EndGuard_); MOZ_ASSERT(mResponseType < XMLHttpRequestResponseType::EndGuard_);
@ -755,9 +729,7 @@ XMLHttpRequestMainThread::SetResponseType(XMLHttpRequestResponseType aResponseTy
} }
// We want to get rid of this moz-only types. Bug 1335365. // We want to get rid of this moz-only types. Bug 1335365.
if (aResponseType == XMLHttpRequestResponseType::Moz_blob) { if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text) {
Telemetry::Accumulate(Telemetry::MOZ_BLOB_IN_XHR, 1);
} else if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text) {
Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_TEXT_IN_XHR, 1); Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_TEXT_IN_XHR, 1);
} else if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) { } else if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_ARRAYBUFFER_IN_XHR, 1); Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_ARRAYBUFFER_IN_XHR, 1);
@ -818,17 +790,10 @@ XMLHttpRequestMainThread::GetResponse(JSContext* aCx,
return; return;
} }
case XMLHttpRequestResponseType::Blob: case XMLHttpRequestResponseType::Blob:
case XMLHttpRequestResponseType::Moz_blob:
{ {
if (mState != State::done) { if (mState != State::done) {
if (mResponseType != XMLHttpRequestResponseType::Moz_blob) { aResponse.setNull();
aResponse.setNull(); return;
return;
}
if (!mResponseBlob) {
CreatePartialBlob(aRv);
}
} }
if (!mResponseBlob) { if (!mResponseBlob) {
@ -1715,13 +1680,6 @@ XMLHttpRequestMainThread::StreamReaderFunc(nsIInputStream* in,
if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Blob) { if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Blob) {
xmlHttpRequest->MaybeCreateBlobStorage(); xmlHttpRequest->MaybeCreateBlobStorage();
rv = xmlHttpRequest->mBlobStorage->Append(fromRawSegment, count); rv = xmlHttpRequest->mBlobStorage->Append(fromRawSegment, count);
} else if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_blob) {
if (!xmlHttpRequest->mBlobSet) {
xmlHttpRequest->mBlobSet = new BlobSet();
}
rv = xmlHttpRequest->mBlobSet->AppendVoidPtr(fromRawSegment, count);
// Clear the cache so that the blob size is updated.
xmlHttpRequest->mResponseBlob = nullptr;
} else if ((xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Arraybuffer && } else if ((xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
!xmlHttpRequest->mIsMappedArrayBuffer) || !xmlHttpRequest->mIsMappedArrayBuffer) ||
xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) { xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
@ -1885,7 +1843,6 @@ XMLHttpRequestMainThread::LocalFileToBlobCompleted(Blob* aBlob)
mResponseBlob = aBlob; mResponseBlob = aBlob;
mBlobStorage = nullptr; mBlobStorage = nullptr;
mBlobSet = nullptr;
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty"); NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
ChangeStateToDone(); ChangeStateToDone();
@ -1908,8 +1865,7 @@ XMLHttpRequestMainThread::OnDataAvailable(nsIRequest *request,
nsresult rv; nsresult rv;
nsCOMPtr<nsIFile> localFile; nsCOMPtr<nsIFile> localFile;
if ((mResponseType == XMLHttpRequestResponseType::Blob || if (mResponseType == XMLHttpRequestResponseType::Blob) {
mResponseType == XMLHttpRequestResponseType::Moz_blob)) {
rv = GetLocalFileFromChannel(request, getter_AddRefs(localFile)); rv = GetLocalFileFromChannel(request, getter_AddRefs(localFile));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
@ -1917,7 +1873,6 @@ XMLHttpRequestMainThread::OnDataAvailable(nsIRequest *request,
if (localFile) { if (localFile) {
mBlobStorage = nullptr; mBlobStorage = nullptr;
mBlobSet = nullptr;
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty"); NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
// The nsIStreamListener contract mandates us to read from the stream // The nsIStreamListener contract mandates us to read from the stream
@ -2271,8 +2226,7 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
// blob. We have this error because we canceled the channel. The status will // blob. We have this error because we canceled the channel. The status will
// be set to NS_OK. // be set to NS_OK.
if (status == NS_ERROR_FILE_ALREADY_EXISTS && if (status == NS_ERROR_FILE_ALREADY_EXISTS &&
(mResponseType == XMLHttpRequestResponseType::Blob || mResponseType == XMLHttpRequestResponseType::Blob) {
mResponseType == XMLHttpRequestResponseType::Moz_blob)) {
nsCOMPtr<nsIFile> file; nsCOMPtr<nsIFile> file;
nsresult rv = GetLocalFileFromChannel(request, getter_AddRefs(file)); nsresult rv = GetLocalFileFromChannel(request, getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -2308,41 +2262,18 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
} }
if (NS_SUCCEEDED(status) && if (NS_SUCCEEDED(status) &&
(mResponseType == XMLHttpRequestResponseType::Blob || mResponseType == XMLHttpRequestResponseType::Blob &&
mResponseType == XMLHttpRequestResponseType::Moz_blob) &&
!waitingForBlobCreation) { !waitingForBlobCreation) {
// Smaller files may be written in cache map instead of separate files. // Smaller files may be written in cache map instead of separate files.
// Also, no-store response cannot be written in persistent cache. // Also, no-store response cannot be written in persistent cache.
nsAutoCString contentType; nsAutoCString contentType;
mChannel->GetContentType(contentType); mChannel->GetContentType(contentType);
if (mResponseType == XMLHttpRequestResponseType::Blob) { // mBlobStorage can be null if the channel is non-file non-cacheable
// mBlobStorage can be null if the channel is non-file non-cacheable // and if the response length is zero.
// and if the response length is zero. MaybeCreateBlobStorage();
MaybeCreateBlobStorage(); mBlobStorage->GetBlobWhenReady(GetOwner(), contentType, this);
mBlobStorage->GetBlobWhenReady(GetOwner(), contentType, this); waitingForBlobCreation = true;
waitingForBlobCreation = true;
} else {
// mBlobSet can be null if the channel is non-file non-cacheable
// and if the response length is zero.
if (!mBlobSet) {
mBlobSet = new BlobSet();
}
ErrorResult error;
nsTArray<RefPtr<BlobImpl>> subImpls(mBlobSet->GetBlobImpls());
RefPtr<BlobImpl> blobImpl =
MultipartBlobImpl::Create(Move(subImpls),
NS_ConvertASCIItoUTF16(contentType),
error);
mBlobSet = nullptr;
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
mResponseBlob = Blob::Create(GetOwner(), blobImpl);
}
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty"); NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
NS_ASSERTION(mResponseText.IsEmpty(), "mResponseText should be empty"); NS_ASSERTION(mResponseText.IsEmpty(), "mResponseText should be empty");

Просмотреть файл

@ -526,7 +526,6 @@ protected:
uint32_t count, uint32_t count,
uint32_t *writeCount); uint32_t *writeCount);
nsresult CreateResponseParsedJSON(JSContext* aCx); nsresult CreateResponseParsedJSON(JSContext* aCx);
void CreatePartialBlob(ErrorResult& aRv);
// Change the state of the object with this. The broadcast argument // Change the state of the object with this. The broadcast argument
// determines if the onreadystatechange listener should be called. // determines if the onreadystatechange listener should be called.
nsresult ChangeState(State aState, bool aBroadcast = true); nsresult ChangeState(State aState, bool aBroadcast = true);
@ -666,8 +665,6 @@ protected:
RefPtr<Blob> mResponseBlob; RefPtr<Blob> mResponseBlob;
// We stream data to mBlobStorage when response type is "blob". // We stream data to mBlobStorage when response type is "blob".
RefPtr<MutableBlobStorage> mBlobStorage; RefPtr<MutableBlobStorage> mBlobStorage;
// We stream data to mBlobSet when response type is "moz-blob".
nsAutoPtr<BlobSet> mBlobSet;
nsString mOverrideMimeType; nsString mOverrideMimeType;

Просмотреть файл

@ -276,92 +276,88 @@ while (xhr.readyState != 4) {
checkXHRStatus(); checkXHRStatus();
// test response (responseType='blob') // test response (responseType='blob')
var responseTypes = ['blob', 'moz-blob']; // with a simple text file
for (var i = 0; i < responseTypes.length; i++) { xhr = new XMLHttpRequest();
var t = responseTypes[i]; xhr.open("GET", 'file_XHR_pass2.txt');
// with a simple text file xhr.responseType = 'blob';
xhr = new XMLHttpRequest(); xhr.onloadend = continueTest;
xhr.open("GET", 'file_XHR_pass2.txt'); xhr.send(null);
xhr.responseType = t; yield undefined;
xhr.onloadend = continueTest; is(xhr.status, 200, "wrong status");
xhr.send(null); checkResponseTextAccessThrows(xhr);
yield undefined; checkResponseXMLAccessThrows(xhr);
is(xhr.status, 200, "wrong status"); var b = xhr.response;
checkResponseTextAccessThrows(xhr); ok(b, "should have a non-null blob");
checkResponseXMLAccessThrows(xhr); ok(b instanceof Blob, "should be a Blob");
var b = xhr.response; ok(!(b instanceof File), "should not be a File");
ok(b, "should have a non-null blob"); is(b.size, "hello pass\n".length, "wrong blob size");
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(); var fr = new FileReader();
fr.onload = continueTest; fr.onload = continueTest;
fr.readAsBinaryString(b); fr.readAsBinaryString(b);
yield undefined; yield undefined;
ok(fr.result, "hello pass\n", "wrong values"); ok(fr.result, "hello pass\n", "wrong values");
// with a binary file // with a binary file
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
xhr.open("GET", 'file_XHR_binary1.bin', true); xhr.open("GET", 'file_XHR_binary1.bin', true);
xhr.send(null); xhr.send(null);
xhr.onreadystatechange = continueTest; xhr.onreadystatechange = continueTest;
while(xhr.readyState != 2) while(xhr.readyState != 2)
yield undefined;
is(xhr.status, 200, "wrong status");
xhr.responseType = t;
while(xhr.readyState != 4)
yield undefined;
xhr.onreadystatechange = null;
b = xhr.response;
ok(b != null, "should have a non-null blob");
is(b.size, 12, "wrong blob size");
fr = new FileReader();
fr.readAsBinaryString(b);
xhr = null; // kill the XHR object
b = null;
SpecialPowers.gc();
fr.onload = continueTest;
yield undefined;
is(fr.result, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb", "wrong values");
// with a larger binary file
xhr = new XMLHttpRequest();
xhr.open("GET", 'file_XHR_binary2.bin', true);
xhr.responseType = t;
xhr.send(null);
xhr.onreadystatechange = continueTest;
while (xhr.readyState != 4)
yield undefined;
xhr.onreadystatechange = null;
var b = xhr.response;
ok(b != null, "should have a non-null blob");
is(b.size, 65536, "wrong blob size");
fr = new FileReader();
fr.readAsArrayBuffer(b);
fr.onload = continueTest;
xhr = null; // kill the XHR object
b = null;
SpecialPowers.gc();
yield undefined; yield undefined;
var u8 = new Uint8Array(fr.result); is(xhr.status, 200, "wrong status");
for (var i = 0; i < 65536; i++) { xhr.responseType = 'blob';
if (u8[i] !== (i & 255)) {
break; while(xhr.readyState != 4)
} yield undefined;
xhr.onreadystatechange = null;
b = xhr.response;
ok(b != null, "should have a non-null blob");
is(b.size, 12, "wrong blob size");
fr = new FileReader();
fr.readAsBinaryString(b);
xhr = null; // kill the XHR object
b = null;
SpecialPowers.gc();
fr.onload = continueTest;
yield undefined;
is(fr.result, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb", "wrong values");
// with a larger binary file
xhr = new XMLHttpRequest();
xhr.open("GET", 'file_XHR_binary2.bin', true);
xhr.responseType = 'blob';
xhr.send(null);
xhr.onreadystatechange = continueTest;
while (xhr.readyState != 4)
yield undefined;
xhr.onreadystatechange = null;
var b = xhr.response;
ok(b != null, "should have a non-null blob");
is(b.size, 65536, "wrong blob size");
fr = new FileReader();
fr.readAsArrayBuffer(b);
fr.onload = continueTest;
xhr = null; // kill the XHR object
b = null;
SpecialPowers.gc();
yield undefined;
var u8 = new Uint8Array(fr.result);
for (var i = 0; i < 65536; i++) {
if (u8[i] !== (i & 255)) {
break;
} }
is(i, 65536, "wrong value at offset " + i);
} }
is(i, 65536, "wrong value at offset " + i);
var client = new XMLHttpRequest(); var client = new XMLHttpRequest();
client.open("GET", "file_XHR_pass1.xml", true); client.open("GET", "file_XHR_pass1.xml", true);

Просмотреть файл

@ -132,7 +132,6 @@ function* runTests() {
var responseTypes = [{ type: "text", text: true }, var responseTypes = [{ type: "text", text: true },
{ type: "arraybuffer", text: false, nodata: true }, { type: "arraybuffer", text: false, nodata: true },
{ type: "blob", text: false, nodata: true, blob: true }, { type: "blob", text: false, nodata: true, blob: true },
{ type: "moz-blob", text: false, nodata: false, blob: true },
{ type: "document", text: true, nodata: true }, { type: "document", text: true, nodata: true },
{ type: "json", text: true, nodata: true }, { type: "json", text: true, nodata: true },
{ type: "", text: true }, { type: "", text: true },

Просмотреть файл

@ -1,8 +1,5 @@
[historical.html] [historical.html]
type: testharness type: testharness
[Support for responseType = moz-blob]
expected: FAIL
[Support for responseType = moz-chunked-text] [Support for responseType = moz-chunked-text]
expected: FAIL expected: FAIL

Просмотреть файл

@ -12963,15 +12963,6 @@
"bug_numbers": [1331804], "bug_numbers": [1331804],
"description": "The time a given main thread runnable took to run (in milliseconds). The key comes from the runnables nsINamed::name value." "description": "The time a given main thread runnable took to run (in milliseconds). The key comes from the runnables nsINamed::name value."
}, },
"MOZ_BLOB_IN_XHR": {
"record_in_processes": ["main", "content"],
"alert_emails": ["amarchesini@mozilla.com"],
"expires_in_version": "58",
"kind": "boolean",
"bug_numbers": [1335365],
"releaseChannelCollection": "opt-out",
"description": "XMLHttpRequest.responseType set to moz-blob"
},
"MOZ_CHUNKED_TEXT_IN_XHR": { "MOZ_CHUNKED_TEXT_IN_XHR": {
"record_in_processes": ["main", "content"], "record_in_processes": ["main", "content"],
"alert_emails": ["amarchesini@mozilla.com"], "alert_emails": ["amarchesini@mozilla.com"],