mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 293046 XMLHttpRequest.overrideMimeType() makes loading abort for non-XML
patch by Wladimir Palant <trev@gtchat.de> r=jst sr=darin
This commit is contained in:
parent
bf0613c434
commit
ee62d3bd19
@ -1136,7 +1136,16 @@ nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION(copyStream, "NS_NewByteInputStream lied");
|
||||
rv = xmlHttpRequest->mXMLParserStreamListener->OnDataAvailable(xmlHttpRequest->mReadRequest,xmlHttpRequest->mContext,copyStream,toOffset,count);
|
||||
nsresult parsingResult = xmlHttpRequest->mXMLParserStreamListener
|
||||
->OnDataAvailable(xmlHttpRequest->mReadRequest,
|
||||
xmlHttpRequest->mContext,
|
||||
copyStream, toOffset, count);
|
||||
|
||||
// No use to continue parsing if we failed here, but we
|
||||
// should still finish reading the stream
|
||||
if (NS_FAILED(parsingResult)) {
|
||||
xmlHttpRequest->mState &= ~XML_HTTP_REQUEST_PARSEBODY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1223,12 +1232,18 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mOverrideMimeType.IsEmpty()) {
|
||||
// If we are not overriding the mime type, we can gain a huge
|
||||
// performance win by not even trying to parse non-XML data. This
|
||||
// also protects us from the situation where we have an XML
|
||||
// document and sink, but HTML (or other) parser, which can
|
||||
// produce unreliable results.
|
||||
nsresult status;
|
||||
request->GetStatus(&status);
|
||||
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
if (!mOverrideMimeType.IsEmpty()) {
|
||||
channel->SetContentType(mOverrideMimeType);
|
||||
}
|
||||
|
||||
// We can gain a huge performance win by not even trying to
|
||||
// parse non-XML data. This also protects us from the situation
|
||||
// where we have an XML document and sink, but HTML (or other)
|
||||
// parser, which can produce unreliable results.
|
||||
nsCAutoString type;
|
||||
channel->GetContentType(type);
|
||||
|
||||
@ -1236,14 +1251,8 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
||||
mState &= ~XML_HTTP_REQUEST_PARSEBODY;
|
||||
}
|
||||
} else {
|
||||
nsresult status;
|
||||
request->GetStatus(&status);
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
channel->SetContentType(mOverrideMimeType);
|
||||
} else {
|
||||
// The request failed, so we shouldn't be parsing anyway
|
||||
mState &= ~XML_HTTP_REQUEST_PARSEBODY;
|
||||
}
|
||||
// The request failed, so we shouldn't be parsing anyway
|
||||
mState &= ~XML_HTTP_REQUEST_PARSEBODY;
|
||||
}
|
||||
|
||||
if (mState & XML_HTTP_REQUEST_PARSEBODY) {
|
||||
|
Loading…
Reference in New Issue
Block a user