Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2004)

Unified Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 21600002: Add json responseType support to XMLHttpRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | Source/core/xml/XMLHttpRequest.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/xml/XMLHttpRequest.cpp
diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
index f61ccecb5197a0b09cc824fd4449325aec40d271..17f9b163b0be769f42c51f68bd898d1696082956 100644
--- a/Source/core/xml/XMLHttpRequest.cpp
+++ b/Source/core/xml/XMLHttpRequest.cpp
@@ -224,6 +224,17 @@ ScriptString XMLHttpRequest::responseText(ExceptionState& es)
return m_responseText;
}
+ScriptString XMLHttpRequest::responseJSONSource(ExceptionState& es)
+{
+ if (m_responseTypeCode != ResponseTypeJSON) {
+ es.throwDOMException(InvalidStateError);
+ return ScriptString();
+ }
+ if (m_error || m_state != DONE)
+ return ScriptString();
+ return m_responseText;
+}
+
Document* XMLHttpRequest::responseXML(ExceptionState& es)
{
if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != ResponseTypeDocument) {
@@ -340,6 +351,8 @@ void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState&
m_responseTypeCode = ResponseTypeDefault;
else if (responseType == "text")
m_responseTypeCode = ResponseTypeText;
+ else if (responseType == "json")
+ m_responseTypeCode = ResponseTypeJSON;
else if (responseType == "document")
m_responseTypeCode = ResponseTypeDocument;
else if (responseType == "blob")
@@ -357,6 +370,8 @@ String XMLHttpRequest::responseType()
return "";
case ResponseTypeText:
return "text";
+ case ResponseTypeJSON:
+ return "json";
case ResponseTypeDocument:
return "document";
case ResponseTypeBlob:
@@ -1129,10 +1144,12 @@ void XMLHttpRequest::didReceiveData(const char* data, int len)
if (m_state < HEADERS_RECEIVED)
changeState(HEADERS_RECEIVED);
- bool useDecoder = m_responseTypeCode == ResponseTypeDefault || m_responseTypeCode == ResponseTypeText || m_responseTypeCode == ResponseTypeDocument;
+ bool useDecoder = m_responseTypeCode == ResponseTypeDefault || m_responseTypeCode == ResponseTypeText || m_responseTypeCode == ResponseTypeJSON || m_responseTypeCode == ResponseTypeDocument;
if (useDecoder && !m_decoder) {
- if (!m_responseEncoding.isEmpty())
+ if (m_responseTypeCode == ResponseTypeJSON)
+ m_decoder = TextResourceDecoder::create("application/json", "UTF-8");
+ else if (!m_responseEncoding.isEmpty())
m_decoder = TextResourceDecoder::create("text/plain", m_responseEncoding);
// allow TextResourceDecoder to look inside the m_response if it's XML or HTML
else if (responseIsXML()) {
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | Source/core/xml/XMLHttpRequest.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698