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
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

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

@ -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
"moz-chunked-text",
"moz-chunked-arraybuffer",
"moz-blob"
};
/**

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

@ -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<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)
{
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,19 +790,12 @@ 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);
}
}
if (!mResponseBlob) {
aResponse.setNull();
return;
@ -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<nsIFile> 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<nsIFile> 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<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(mResponseText.IsEmpty(), "mResponseText should be empty");

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

@ -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<Blob> mResponseBlob;
// We stream data to mBlobStorage when response type is "blob".
RefPtr<MutableBlobStorage> mBlobStorage;
// We stream data to mBlobSet when response type is "moz-blob".
nsAutoPtr<BlobSet> mBlobSet;
nsString mOverrideMimeType;

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

@ -276,13 +276,10 @@ 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.responseType = 'blob';
xhr.onloadend = continueTest;
xhr.send(null);
yield undefined;
@ -310,7 +307,7 @@ for (var i = 0; i < responseTypes.length; i++) {
yield undefined;
is(xhr.status, 200, "wrong status");
xhr.responseType = t;
xhr.responseType = 'blob';
while(xhr.readyState != 4)
yield undefined;
@ -333,7 +330,7 @@ for (var i = 0; i < responseTypes.length; i++) {
// with a larger binary file
xhr = new XMLHttpRequest();
xhr.open("GET", 'file_XHR_binary2.bin', true);
xhr.responseType = t;
xhr.responseType = 'blob';
xhr.send(null);
xhr.onreadystatechange = continueTest;
@ -361,7 +358,6 @@ for (var i = 0; i < responseTypes.length; i++) {
}
}
is(i, 65536, "wrong value at offset " + i);
}
var client = new XMLHttpRequest();
client.open("GET", "file_XHR_pass1.xml", true);

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

@ -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 },

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

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

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

@ -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"],