Chromium Code Reviews| Index: Source/core/xml/XMLHttpRequest.cpp |
| diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp |
| index 34497abe48d105b98a6f34586ee1b6e6b3f01e11..06069702b3faaa79555bce13e3ce04ae12b5386b 100644 |
| --- a/Source/core/xml/XMLHttpRequest.cpp |
| +++ b/Source/core/xml/XMLHttpRequest.cpp |
| @@ -189,7 +189,7 @@ ScriptString XMLHttpRequest::responseJSONSource() |
| void XMLHttpRequest::initResponseDocument() |
| { |
| - AtomicString mimeType = responseMIMEType(); |
| + AtomicString mimeType = finalMIMEType(); |
|
sof
2014/08/11 12:19:37
Shouldn't this be finalMIMETypeWithFallback() for
tyoshino (SeeGerritForStatus)
2014/08/11 13:10:46
Wow, good catch! Done.
|
| bool isHTML = equalIgnoringCase(mimeType, "text/html"); |
| // The W3C spec requires the final MIME type to be some valid XML type, or text/html. |
| @@ -258,7 +258,10 @@ Blob* XMLHttpRequest::responseBlob() |
| // empty one. |
| if (!filePath.isEmpty() && m_downloadedBlobLength) { |
| blobData->appendFile(filePath); |
| - blobData->setContentType(responseMIMEType()); // responseMIMEType defaults to text/xml which may be incorrect. |
| + // FIXME: finalMIMETypeWithFallback() defaults to text/xml which |
| + // may be incorrect. Replace it with finalMIMEType() after |
| + // compatibility investigation. |
| + blobData->setContentType(finalMIMETypeWithFallback()); |
| } |
| m_responseBlob = Blob::create(BlobDataHandle::create(blobData.release(), m_downloadedBlobLength)); |
| } |
| @@ -878,7 +881,7 @@ void XMLHttpRequest::clearVariablesForLoading() |
| { |
| m_decoder.clear(); |
| - m_responseEncoding = String(); |
| + m_finalCharset = String(); |
| } |
| bool XMLHttpRequest::internalAbort() |
| @@ -1029,6 +1032,9 @@ void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi |
| void XMLHttpRequest::overrideMimeType(const AtomicString& override) |
| { |
| + // FIXME: This method must throw an InvalidStateError exception when the |
| + // XHR is in the LOADING or DONE state. http://crbug.com/402375 |
| + |
| m_mimeTypeOverride = override; |
| } |
| @@ -1125,24 +1131,32 @@ const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name) |
| return m_response.httpHeaderField(name); |
| } |
| -AtomicString XMLHttpRequest::responseMIMEType() const |
| +AtomicString XMLHttpRequest::finalMIMEType() const |
| { |
| - AtomicString mimeType = extractMIMETypeFromMediaType(m_mimeTypeOverride); |
| - if (mimeType.isEmpty()) { |
| - if (m_response.isHTTP()) |
| - mimeType = extractMIMETypeFromMediaType(m_response.httpHeaderField("Content-Type")); |
| - else |
| - mimeType = m_response.mimeType(); |
| - } |
| - if (mimeType.isEmpty()) |
| - mimeType = AtomicString("text/xml", AtomicString::ConstructFromLiteral); |
| + AtomicString overriddenType = extractMIMETypeFromMediaType(m_mimeTypeOverride); |
| + if (!overriddenType.isEmpty()) |
| + return overriddenType; |
| + |
| + if (m_response.isHTTP()) |
| + return extractMIMETypeFromMediaType(m_response.httpHeaderField("Content-Type")); |
| + |
| + return m_response.mimeType(); |
| +} |
| + |
| +AtomicString XMLHttpRequest::finalMIMETypeWithFallback() const |
| +{ |
| + AtomicString finalType = finalMIMEType(); |
| + if (!finalType.isEmpty()) |
| + return finalType; |
| - return mimeType; |
| + // FIXME: This fallback is not specified in the final MIME type algorithm |
| + // of the XHR spec. Move this to more appropriate place. |
| + return AtomicString("text/xml", AtomicString::ConstructFromLiteral); |
| } |
| bool XMLHttpRequest::responseIsXML() const |
| { |
| - return DOMImplementation::isXMLMIMEType(responseMIMEType()); |
| + return DOMImplementation::isXMLMIMEType(finalMIMETypeWithFallback()); |
| } |
| int XMLHttpRequest::status() const |
| @@ -1249,11 +1263,11 @@ void XMLHttpRequest::didReceiveResponse(unsigned long identifier, const Resource |
| m_response = response; |
| if (!m_mimeTypeOverride.isEmpty()) { |
| m_response.setHTTPHeaderField("Content-Type", m_mimeTypeOverride); |
| - m_responseEncoding = extractCharsetFromMediaType(m_mimeTypeOverride); |
| + m_finalCharset = extractCharsetFromMediaType(m_mimeTypeOverride); |
| } |
| - if (m_responseEncoding.isEmpty()) |
| - m_responseEncoding = response.textEncodingName(); |
| + if (m_finalCharset.isEmpty()) |
| + m_finalCharset = response.textEncodingName(); |
| } |
| PassOwnPtr<TextResourceDecoder> XMLHttpRequest::createDecoder() const |
| @@ -1261,8 +1275,8 @@ PassOwnPtr<TextResourceDecoder> XMLHttpRequest::createDecoder() const |
| if (m_responseTypeCode == ResponseTypeJSON) |
| return TextResourceDecoder::create("application/json", "UTF-8"); |
| - if (!m_responseEncoding.isEmpty()) |
| - return TextResourceDecoder::create("text/plain", m_responseEncoding); |
| + if (!m_finalCharset.isEmpty()) |
| + return TextResourceDecoder::create("text/plain", m_finalCharset); |
| // allow TextResourceDecoder to look inside the m_response if it's XML or HTML |
| if (responseIsXML()) { |
| @@ -1275,7 +1289,7 @@ PassOwnPtr<TextResourceDecoder> XMLHttpRequest::createDecoder() const |
| return decoder.release(); |
| } |
| - if (equalIgnoringCase(responseMIMEType(), "text/html")) |
| + if (equalIgnoringCase(finalMIMEType(), "text/html")) |
| return TextResourceDecoder::create("text/html", "UTF-8"); |
| return TextResourceDecoder::create("text/plain", "UTF-8"); |
| @@ -1310,7 +1324,7 @@ void XMLHttpRequest::didReceiveData(const char* data, int len) |
| m_binaryResponseBuilder->append(data, len); |
| } else if (m_responseTypeCode == ResponseTypeLegacyStream) { |
| if (!m_responseStream) |
| - m_responseStream = Stream::create(executionContext(), responseMIMEType()); |
| + m_responseStream = Stream::create(executionContext(), finalMIMEType()); |
| m_responseStream->addData(data, len); |
| } |