| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> | 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> |
| 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> | 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> |
| 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. | 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. |
| 6 * Copyright (C) 2012 Intel Corporation | 6 * Copyright (C) 2012 Intel Corporation |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 { | 216 { |
| 217 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { | 217 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { |
| 218 es.throwDOMException(InvalidStateError); | 218 es.throwDOMException(InvalidStateError); |
| 219 return ScriptString(); | 219 return ScriptString(); |
| 220 } | 220 } |
| 221 if (m_error || (m_state != LOADING && m_state != DONE)) | 221 if (m_error || (m_state != LOADING && m_state != DONE)) |
| 222 return ScriptString(); | 222 return ScriptString(); |
| 223 return m_responseText; | 223 return m_responseText; |
| 224 } | 224 } |
| 225 | 225 |
| 226 ScriptString XMLHttpRequest::responseJsonSource(ExceptionState& es) |
| 227 { |
| 228 if (m_responseTypeCode != ResponseTypeJson) { |
| 229 es.throwDOMException(InvalidStateError); |
| 230 return ScriptString(); |
| 231 } |
| 232 if (m_error || m_state != DONE) |
| 233 return ScriptString(); |
| 234 return m_responseText; |
| 235 } |
| 236 |
| 226 Document* XMLHttpRequest::responseXML(ExceptionState& es) | 237 Document* XMLHttpRequest::responseXML(ExceptionState& es) |
| 227 { | 238 { |
| 228 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { | 239 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { |
| 229 es.throwDOMException(InvalidStateError); | 240 es.throwDOMException(InvalidStateError); |
| 230 return 0; | 241 return 0; |
| 231 } | 242 } |
| 232 | 243 |
| 233 if (m_error || m_state != DONE) | 244 if (m_error || m_state != DONE) |
| 234 return 0; | 245 return 0; |
| 235 | 246 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 if (!m_async && scriptExecutionContext()->isDocument() && m_url.protocolIsIn
HTTPFamily()) { | 350 if (!m_async && scriptExecutionContext()->isDocument() && m_url.protocolIsIn
HTTPFamily()) { |
| 340 logConsoleError(scriptExecutionContext(), "XMLHttpRequest.responseType c
annot be changed for synchronous HTTP(S) requests made from the window context."
); | 351 logConsoleError(scriptExecutionContext(), "XMLHttpRequest.responseType c
annot be changed for synchronous HTTP(S) requests made from the window context."
); |
| 341 es.throwDOMException(InvalidAccessError); | 352 es.throwDOMException(InvalidAccessError); |
| 342 return; | 353 return; |
| 343 } | 354 } |
| 344 | 355 |
| 345 if (responseType == "") | 356 if (responseType == "") |
| 346 m_responseTypeCode = ResponseTypeDefault; | 357 m_responseTypeCode = ResponseTypeDefault; |
| 347 else if (responseType == "text") | 358 else if (responseType == "text") |
| 348 m_responseTypeCode = ResponseTypeText; | 359 m_responseTypeCode = ResponseTypeText; |
| 360 else if (responseType == "json") |
| 361 m_responseTypeCode = ResponseTypeJson; |
| 349 else if (responseType == "document") | 362 else if (responseType == "document") |
| 350 m_responseTypeCode = ResponseTypeDocument; | 363 m_responseTypeCode = ResponseTypeDocument; |
| 351 else if (responseType == "blob") | 364 else if (responseType == "blob") |
| 352 m_responseTypeCode = ResponseTypeBlob; | 365 m_responseTypeCode = ResponseTypeBlob; |
| 353 else if (responseType == "arraybuffer") | 366 else if (responseType == "arraybuffer") |
| 354 m_responseTypeCode = ResponseTypeArrayBuffer; | 367 m_responseTypeCode = ResponseTypeArrayBuffer; |
| 355 else | 368 else |
| 356 ASSERT_NOT_REACHED(); | 369 ASSERT_NOT_REACHED(); |
| 357 } | 370 } |
| 358 | 371 |
| 359 String XMLHttpRequest::responseType() | 372 String XMLHttpRequest::responseType() |
| 360 { | 373 { |
| 361 switch (m_responseTypeCode) { | 374 switch (m_responseTypeCode) { |
| 362 case ResponseTypeDefault: | 375 case ResponseTypeDefault: |
| 363 return ""; | 376 return ""; |
| 364 case ResponseTypeText: | 377 case ResponseTypeText: |
| 365 return "text"; | 378 return "text"; |
| 379 case ResponseTypeJson: |
| 380 return "json"; |
| 366 case ResponseTypeDocument: | 381 case ResponseTypeDocument: |
| 367 return "document"; | 382 return "document"; |
| 368 case ResponseTypeBlob: | 383 case ResponseTypeBlob: |
| 369 return "blob"; | 384 return "blob"; |
| 370 case ResponseTypeArrayBuffer: | 385 case ResponseTypeArrayBuffer: |
| 371 return "arraybuffer"; | 386 return "arraybuffer"; |
| 372 } | 387 } |
| 373 return ""; | 388 return ""; |
| 374 } | 389 } |
| 375 | 390 |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 } | 1142 } |
| 1128 | 1143 |
| 1129 void XMLHttpRequest::didReceiveData(const char* data, int len) | 1144 void XMLHttpRequest::didReceiveData(const char* data, int len) |
| 1130 { | 1145 { |
| 1131 if (m_error) | 1146 if (m_error) |
| 1132 return; | 1147 return; |
| 1133 | 1148 |
| 1134 if (m_state < HEADERS_RECEIVED) | 1149 if (m_state < HEADERS_RECEIVED) |
| 1135 changeState(HEADERS_RECEIVED); | 1150 changeState(HEADERS_RECEIVED); |
| 1136 | 1151 |
| 1137 bool useDecoder = m_responseTypeCode == ResponseTypeDefault || m_responseTyp
eCode == ResponseTypeText || m_responseTypeCode == ResponseTypeDocument; | 1152 bool useDecoder = m_responseTypeCode == ResponseTypeDefault || m_responseTyp
eCode == ResponseTypeText || m_responseTypeCode == ResponseTypeJson || m_respons
eTypeCode == ResponseTypeDocument; |
| 1138 | 1153 |
| 1139 if (useDecoder && !m_decoder) { | 1154 if (useDecoder && !m_decoder) { |
| 1140 if (!m_responseEncoding.isEmpty()) | 1155 if (m_responseTypeCode == ResponseTypeJson) |
| 1156 m_decoder = TextResourceDecoder::create("application/json", "UTF-8")
; |
| 1157 else if (!m_responseEncoding.isEmpty()) |
| 1141 m_decoder = TextResourceDecoder::create("text/plain", m_responseEnco
ding); | 1158 m_decoder = TextResourceDecoder::create("text/plain", m_responseEnco
ding); |
| 1142 // allow TextResourceDecoder to look inside the m_response if it's XML o
r HTML | 1159 // allow TextResourceDecoder to look inside the m_response if it's XML o
r HTML |
| 1143 else if (responseIsXML()) { | 1160 else if (responseIsXML()) { |
| 1144 m_decoder = TextResourceDecoder::create("application/xml"); | 1161 m_decoder = TextResourceDecoder::create("application/xml"); |
| 1145 // Don't stop on encoding errors, unlike it is done for other kinds
of XML resources. This matches the behavior of previous WebKit versions, Firefox
and Opera. | 1162 // Don't stop on encoding errors, unlike it is done for other kinds
of XML resources. This matches the behavior of previous WebKit versions, Firefox
and Opera. |
| 1146 m_decoder->useLenientXMLDecoding(); | 1163 m_decoder->useLenientXMLDecoding(); |
| 1147 } else if (equalIgnoringCase(responseMIMEType(), "text/html")) | 1164 } else if (equalIgnoringCase(responseMIMEType(), "text/html")) |
| 1148 m_decoder = TextResourceDecoder::create("text/html", "UTF-8"); | 1165 m_decoder = TextResourceDecoder::create("text/html", "UTF-8"); |
| 1149 else | 1166 else |
| 1150 m_decoder = TextResourceDecoder::create("text/plain", "UTF-8"); | 1167 m_decoder = TextResourceDecoder::create("text/plain", "UTF-8"); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 { | 1268 { |
| 1252 return &m_eventTargetData; | 1269 return &m_eventTargetData; |
| 1253 } | 1270 } |
| 1254 | 1271 |
| 1255 EventTargetData* XMLHttpRequest::ensureEventTargetData() | 1272 EventTargetData* XMLHttpRequest::ensureEventTargetData() |
| 1256 { | 1273 { |
| 1257 return &m_eventTargetData; | 1274 return &m_eventTargetData; |
| 1258 } | 1275 } |
| 1259 | 1276 |
| 1260 } // namespace WebCore | 1277 } // namespace WebCore |
| OLD | NEW |