| Index: Source/core/xml/XMLHttpRequest.cpp
|
| diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
|
| index 34497abe48d105b98a6f34586ee1b6e6b3f01e11..913bb1241aa0400e5e697c1cf40bbbc3ca44fab0 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 = finalResponseMIMETypeWithFallback();
|
| 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: finalResponseMIMETypeWithFallback() defaults to text/xml
|
| + // which may be incorrect. Replace it with finalResponseMIMEType()
|
| + // after compatibility investigation.
|
| + blobData->setContentType(finalResponseMIMETypeWithFallback());
|
| }
|
| m_responseBlob = Blob::create(BlobDataHandle::create(blobData.release(), m_downloadedBlobLength));
|
| }
|
| @@ -878,7 +881,7 @@ void XMLHttpRequest::clearVariablesForLoading()
|
| {
|
| m_decoder.clear();
|
|
|
| - m_responseEncoding = String();
|
| + m_finalResponseCharset = 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::finalResponseMIMEType() 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::finalResponseMIMETypeWithFallback() const
|
| +{
|
| + AtomicString finalType = finalResponseMIMEType();
|
| + 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(finalResponseMIMETypeWithFallback());
|
| }
|
|
|
| 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_finalResponseCharset = extractCharsetFromMediaType(m_mimeTypeOverride);
|
| }
|
|
|
| - if (m_responseEncoding.isEmpty())
|
| - m_responseEncoding = response.textEncodingName();
|
| + if (m_finalResponseCharset.isEmpty())
|
| + m_finalResponseCharset = 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_finalResponseCharset.isEmpty())
|
| + return TextResourceDecoder::create("text/plain", m_finalResponseCharset);
|
|
|
| // 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(finalResponseMIMEType(), "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(), finalResponseMIMEType());
|
| m_responseStream->addData(data, len);
|
| }
|
|
|
|
|