From 2071ba46809dacd05777a30167c0b89451720bc0 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Fri, 22 Sep 2017 07:18:14 +0200 Subject: [PATCH] Bug 1397145 - Remove the support for moz-blob type in XHR, r=smaug --- dom/base/crashtests/crashtests.list | 1 - dom/base/crashtests/xhr_abortinprogress.html | 23 --- dom/webidl/XMLHttpRequest.webidl | 1 - dom/xhr/XMLHttpRequestMainThread.cpp | 91 ++-------- dom/xhr/XMLHttpRequestMainThread.h | 3 - dom/xhr/tests/test_XHR.html | 156 +++++++++--------- dom/xhr/tests/test_xhr_progressevents.html | 1 - .../meta/XMLHttpRequest/historical.html.ini | 3 - toolkit/components/telemetry/Histograms.json | 9 - 9 files changed, 87 insertions(+), 201 deletions(-) delete mode 100644 dom/base/crashtests/xhr_abortinprogress.html diff --git a/dom/base/crashtests/crashtests.list b/dom/base/crashtests/crashtests.list index 7f34a77f6433..4f46c2950c35 100644 --- a/dom/base/crashtests/crashtests.list +++ b/dom/base/crashtests/crashtests.list @@ -217,7 +217,6 @@ pref(clipboard.autocopy,true) load 1370737.html pref(dom.IntersectionObserver.enabled,true) load 1370968.html load 1377826.html 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_html_nullresponse.html load 1383478.html diff --git a/dom/base/crashtests/xhr_abortinprogress.html b/dom/base/crashtests/xhr_abortinprogress.html deleted file mode 100644 index 5345e9bf2539..000000000000 --- a/dom/base/crashtests/xhr_abortinprogress.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - diff --git a/dom/webidl/XMLHttpRequest.webidl b/dom/webidl/XMLHttpRequest.webidl index 4b2006e358d3..d903cd1088aa 100644 --- a/dom/webidl/XMLHttpRequest.webidl +++ b/dom/webidl/XMLHttpRequest.webidl @@ -25,7 +25,6 @@ enum XMLHttpRequestResponseType { // Mozilla-specific stuff "moz-chunked-text", "moz-chunked-arraybuffer", - "moz-blob" }; /** diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 9a54e6e0987e..1ab885668405 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -315,7 +315,6 @@ XMLHttpRequestMainThread::ResetResponse() TruncateResponseText(); mResponseBlob = nullptr; mBlobStorage = nullptr; - mBlobSet = nullptr; mResultArrayBuffer = nullptr; mArrayBufferBuilder.reset(); mResultJSON.setUndefined(); @@ -682,31 +681,6 @@ XMLHttpRequestMainThread::CreateResponseParsedJSON(JSContext* aCx) 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> subImpls(mBlobSet->GetBlobImpls()); - RefPtr 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) { 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. - if (aResponseType == XMLHttpRequestResponseType::Moz_blob) { - Telemetry::Accumulate(Telemetry::MOZ_BLOB_IN_XHR, 1); - } else if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text) { + if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text) { Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_TEXT_IN_XHR, 1); } else if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) { Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_ARRAYBUFFER_IN_XHR, 1); @@ -818,17 +790,10 @@ XMLHttpRequestMainThread::GetResponse(JSContext* aCx, return; } case XMLHttpRequestResponseType::Blob: - case XMLHttpRequestResponseType::Moz_blob: { if (mState != State::done) { - if (mResponseType != XMLHttpRequestResponseType::Moz_blob) { - aResponse.setNull(); - return; - } - - if (!mResponseBlob) { - CreatePartialBlob(aRv); - } + aResponse.setNull(); + return; } if (!mResponseBlob) { @@ -1715,13 +1680,6 @@ XMLHttpRequestMainThread::StreamReaderFunc(nsIInputStream* in, if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Blob) { xmlHttpRequest->MaybeCreateBlobStorage(); 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 && !xmlHttpRequest->mIsMappedArrayBuffer) || xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) { @@ -1885,7 +1843,6 @@ XMLHttpRequestMainThread::LocalFileToBlobCompleted(Blob* aBlob) mResponseBlob = aBlob; mBlobStorage = nullptr; - mBlobSet = nullptr; NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty"); ChangeStateToDone(); @@ -1908,8 +1865,7 @@ XMLHttpRequestMainThread::OnDataAvailable(nsIRequest *request, nsresult rv; nsCOMPtr localFile; - if ((mResponseType == XMLHttpRequestResponseType::Blob || - mResponseType == XMLHttpRequestResponseType::Moz_blob)) { + if (mResponseType == XMLHttpRequestResponseType::Blob) { rv = GetLocalFileFromChannel(request, getter_AddRefs(localFile)); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -1917,7 +1873,6 @@ XMLHttpRequestMainThread::OnDataAvailable(nsIRequest *request, if (localFile) { mBlobStorage = nullptr; - mBlobSet = nullptr; NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty"); // 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 // be set to NS_OK. if (status == NS_ERROR_FILE_ALREADY_EXISTS && - (mResponseType == XMLHttpRequestResponseType::Blob || - mResponseType == XMLHttpRequestResponseType::Moz_blob)) { + mResponseType == XMLHttpRequestResponseType::Blob) { nsCOMPtr file; nsresult rv = GetLocalFileFromChannel(request, getter_AddRefs(file)); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -2308,41 +2262,18 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest *request, nsISupports *ctxt, } if (NS_SUCCEEDED(status) && - (mResponseType == XMLHttpRequestResponseType::Blob || - mResponseType == XMLHttpRequestResponseType::Moz_blob) && + mResponseType == XMLHttpRequestResponseType::Blob && !waitingForBlobCreation) { // Smaller files may be written in cache map instead of separate files. // Also, no-store response cannot be written in persistent cache. nsAutoCString contentType; mChannel->GetContentType(contentType); - if (mResponseType == XMLHttpRequestResponseType::Blob) { - // mBlobStorage can be null if the channel is non-file non-cacheable - // and if the response length is zero. - MaybeCreateBlobStorage(); - mBlobStorage->GetBlobWhenReady(GetOwner(), contentType, this); - 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> subImpls(mBlobSet->GetBlobImpls()); - RefPtr 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); - } + // mBlobStorage can be null if the channel is non-file non-cacheable + // and if the response length is zero. + MaybeCreateBlobStorage(); + mBlobStorage->GetBlobWhenReady(GetOwner(), contentType, this); + waitingForBlobCreation = true; NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty"); NS_ASSERTION(mResponseText.IsEmpty(), "mResponseText should be empty"); diff --git a/dom/xhr/XMLHttpRequestMainThread.h b/dom/xhr/XMLHttpRequestMainThread.h index d12a92700fe3..a684b0c06f64 100644 --- a/dom/xhr/XMLHttpRequestMainThread.h +++ b/dom/xhr/XMLHttpRequestMainThread.h @@ -526,7 +526,6 @@ protected: uint32_t count, uint32_t *writeCount); nsresult CreateResponseParsedJSON(JSContext* aCx); - void CreatePartialBlob(ErrorResult& aRv); // Change the state of the object with this. The broadcast argument // determines if the onreadystatechange listener should be called. nsresult ChangeState(State aState, bool aBroadcast = true); @@ -666,8 +665,6 @@ protected: RefPtr mResponseBlob; // We stream data to mBlobStorage when response type is "blob". RefPtr mBlobStorage; - // We stream data to mBlobSet when response type is "moz-blob". - nsAutoPtr mBlobSet; nsString mOverrideMimeType; diff --git a/dom/xhr/tests/test_XHR.html b/dom/xhr/tests/test_XHR.html index a39b1839ad06..15c29c7ca72f 100644 --- a/dom/xhr/tests/test_XHR.html +++ b/dom/xhr/tests/test_XHR.html @@ -276,92 +276,88 @@ while (xhr.readyState != 4) { checkXHRStatus(); // test response (responseType='blob') -var responseTypes = ['blob', 'moz-blob']; -for (var i = 0; i < responseTypes.length; i++) { - var t = responseTypes[i]; - // with a simple text file - xhr = new XMLHttpRequest(); - xhr.open("GET", 'file_XHR_pass2.txt'); - xhr.responseType = t; - xhr.onloadend = continueTest; - xhr.send(null); - yield undefined; - is(xhr.status, 200, "wrong status"); - checkResponseTextAccessThrows(xhr); - checkResponseXMLAccessThrows(xhr); - var 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"); +// with a simple text file +xhr = new XMLHttpRequest(); +xhr.open("GET", 'file_XHR_pass2.txt'); +xhr.responseType = 'blob'; +xhr.onloadend = continueTest; +xhr.send(null); +yield undefined; +is(xhr.status, 200, "wrong status"); +checkResponseTextAccessThrows(xhr); +checkResponseXMLAccessThrows(xhr); +var 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(); - fr.onload = continueTest; - fr.readAsBinaryString(b); - yield undefined; - ok(fr.result, "hello pass\n", "wrong values"); +var fr = new FileReader(); +fr.onload = continueTest; +fr.readAsBinaryString(b); +yield undefined; +ok(fr.result, "hello pass\n", "wrong values"); - // with a binary file - xhr = new XMLHttpRequest(); - xhr.open("GET", 'file_XHR_binary1.bin', true); - xhr.send(null); - xhr.onreadystatechange = continueTest; - 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(); +// with a binary file +xhr = new XMLHttpRequest(); +xhr.open("GET", 'file_XHR_binary1.bin', true); +xhr.send(null); +xhr.onreadystatechange = continueTest; +while(xhr.readyState != 2) yield undefined; - var u8 = new Uint8Array(fr.result); - for (var i = 0; i < 65536; i++) { - if (u8[i] !== (i & 255)) { - break; - } +is(xhr.status, 200, "wrong status"); +xhr.responseType = 'blob'; + +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(); client.open("GET", "file_XHR_pass1.xml", true); diff --git a/dom/xhr/tests/test_xhr_progressevents.html b/dom/xhr/tests/test_xhr_progressevents.html index 7d02b76cf439..c1b43c345602 100644 --- a/dom/xhr/tests/test_xhr_progressevents.html +++ b/dom/xhr/tests/test_xhr_progressevents.html @@ -132,7 +132,6 @@ function* runTests() { var responseTypes = [{ type: "text", text: true }, { type: "arraybuffer", text: false, nodata: 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: "json", text: true, nodata: true }, { type: "", text: true }, diff --git a/testing/web-platform/meta/XMLHttpRequest/historical.html.ini b/testing/web-platform/meta/XMLHttpRequest/historical.html.ini index 71a18b28698f..ad3e49b967c0 100644 --- a/testing/web-platform/meta/XMLHttpRequest/historical.html.ini +++ b/testing/web-platform/meta/XMLHttpRequest/historical.html.ini @@ -1,8 +1,5 @@ [historical.html] type: testharness - [Support for responseType = moz-blob] - expected: FAIL - [Support for responseType = moz-chunked-text] expected: FAIL diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 6406815bf7e8..fc95df148393 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -12963,15 +12963,6 @@ "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." }, - "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": { "record_in_processes": ["main", "content"], "alert_emails": ["amarchesini@mozilla.com"],