| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 SecurityOrigin* XMLHttpRequest::securityOrigin() const | 207 SecurityOrigin* XMLHttpRequest::securityOrigin() const |
| 208 { | 208 { |
| 209 return m_securityOrigin ? m_securityOrigin.get() : scriptExecutionContext()-
>securityOrigin(); | 209 return m_securityOrigin ? m_securityOrigin.get() : scriptExecutionContext()-
>securityOrigin(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 XMLHttpRequest::State XMLHttpRequest::readyState() const | 212 XMLHttpRequest::State XMLHttpRequest::readyState() const |
| 213 { | 213 { |
| 214 return m_state; | 214 return m_state; |
| 215 } | 215 } |
| 216 | 216 |
| 217 String XMLHttpRequest::responseText(ExceptionCode& ec) | 217 ScriptString XMLHttpRequest::responseText(ExceptionCode& ec) |
| 218 { | 218 { |
| 219 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { | 219 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { |
| 220 ec = INVALID_STATE_ERR; | 220 ec = INVALID_STATE_ERR; |
| 221 return ""; | 221 return ScriptString(); |
| 222 } | 222 } |
| 223 return m_responseBuilder.toStringPreserveCapacity(); | 223 return m_responseText; |
| 224 } | 224 } |
| 225 | 225 |
| 226 Document* XMLHttpRequest::responseXML(ExceptionCode& ec) | 226 Document* XMLHttpRequest::responseXML(ExceptionCode& ec) |
| 227 { | 227 { |
| 228 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { | 228 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { |
| 229 ec = INVALID_STATE_ERR; | 229 ec = INVALID_STATE_ERR; |
| 230 return 0; | 230 return 0; |
| 231 } | 231 } |
| 232 | 232 |
| 233 if (m_error || m_state != DONE) | 233 if (m_error || m_state != DONE) |
| 234 return 0; | 234 return 0; |
| 235 | 235 |
| 236 if (!m_createdDocument) { | 236 if (!m_createdDocument) { |
| 237 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); | 237 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); |
| 238 | 238 |
| 239 // The W3C spec requires the final MIME type to be some valid XML type,
or text/html. | 239 // The W3C spec requires the final MIME type to be some valid XML type,
or text/html. |
| 240 // If it is text/html, then the responseType of "document" must have bee
n supplied explicitly. | 240 // If it is text/html, then the responseType of "document" must have bee
n supplied explicitly. |
| 241 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) | 241 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) |
| 242 || (isHTML && m_responseTypeCode == ResponseTypeDefault) | 242 || (isHTML && m_responseTypeCode == ResponseTypeDefault) |
| 243 || scriptExecutionContext()->isWorkerContext()) { | 243 || scriptExecutionContext()->isWorkerContext()) { |
| 244 m_responseDocument = 0; | 244 m_responseDocument = 0; |
| 245 } else { | 245 } else { |
| 246 if (isHTML) | 246 if (isHTML) |
| 247 m_responseDocument = HTMLDocument::create(0, m_url); | 247 m_responseDocument = HTMLDocument::create(0, m_url); |
| 248 else | 248 else |
| 249 m_responseDocument = Document::create(0, m_url); | 249 m_responseDocument = Document::create(0, m_url); |
| 250 // FIXME: Set Last-Modified. | 250 // FIXME: Set Last-Modified. |
| 251 m_responseDocument->setContent(m_responseBuilder.toStringPreserveCap
acity()); | 251 m_responseDocument->setContent(m_responseText.flattenToString()); |
| 252 m_responseDocument->setSecurityOrigin(securityOrigin()); | 252 m_responseDocument->setSecurityOrigin(securityOrigin()); |
| 253 m_responseDocument->setContextFeatures(document()->contextFeatures()
); | 253 m_responseDocument->setContextFeatures(document()->contextFeatures()
); |
| 254 if (!m_responseDocument->wellFormed()) | 254 if (!m_responseDocument->wellFormed()) |
| 255 m_responseDocument = 0; | 255 m_responseDocument = 0; |
| 256 } | 256 } |
| 257 m_createdDocument = true; | 257 m_createdDocument = true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 return m_responseDocument.get(); | 260 return m_responseDocument.get(); |
| 261 } | 261 } |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 839 } |
| 840 | 840 |
| 841 void XMLHttpRequest::clearResponse() | 841 void XMLHttpRequest::clearResponse() |
| 842 { | 842 { |
| 843 m_response = ResourceResponse(); | 843 m_response = ResourceResponse(); |
| 844 clearResponseBuffers(); | 844 clearResponseBuffers(); |
| 845 } | 845 } |
| 846 | 846 |
| 847 void XMLHttpRequest::clearResponseBuffers() | 847 void XMLHttpRequest::clearResponseBuffers() |
| 848 { | 848 { |
| 849 m_responseBuilder.clear(); | 849 m_responseText.clear(); |
| 850 m_createdDocument = false; | 850 m_createdDocument = false; |
| 851 m_responseDocument = 0; | 851 m_responseDocument = 0; |
| 852 m_responseBlob = 0; | 852 m_responseBlob = 0; |
| 853 m_binaryResponseBuilder.clear(); | 853 m_binaryResponseBuilder.clear(); |
| 854 m_responseArrayBuffer.clear(); | 854 m_responseArrayBuffer.clear(); |
| 855 } | 855 } |
| 856 | 856 |
| 857 void XMLHttpRequest::clearRequest() | 857 void XMLHttpRequest::clearRequest() |
| 858 { | 858 { |
| 859 m_requestHeaders.clear(); | 859 m_requestHeaders.clear(); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 | 1085 |
| 1086 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) | 1086 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
| 1087 { | 1087 { |
| 1088 if (m_error) | 1088 if (m_error) |
| 1089 return; | 1089 return; |
| 1090 | 1090 |
| 1091 if (m_state < HEADERS_RECEIVED) | 1091 if (m_state < HEADERS_RECEIVED) |
| 1092 changeState(HEADERS_RECEIVED); | 1092 changeState(HEADERS_RECEIVED); |
| 1093 | 1093 |
| 1094 if (m_decoder) | 1094 if (m_decoder) |
| 1095 m_responseBuilder.append(m_decoder->flush()); | 1095 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); |
| 1096 | 1096 |
| 1097 m_responseBuilder.shrinkToFit(); | 1097 InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this
, identifier, m_responseText, m_url, m_lastSendURL, m_lastSendLineNumber); |
| 1098 | |
| 1099 InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this
, identifier, m_responseBuilder.toStringPreserveCapacity(), m_url, m_lastSendURL
, m_lastSendLineNumber); | |
| 1100 | 1098 |
| 1101 bool hadLoader = m_loader; | 1099 bool hadLoader = m_loader; |
| 1102 m_loader = 0; | 1100 m_loader = 0; |
| 1103 | 1101 |
| 1104 changeState(DONE); | 1102 changeState(DONE); |
| 1105 m_decoder = 0; | 1103 m_decoder = 0; |
| 1106 | 1104 |
| 1107 if (hadLoader) | 1105 if (hadLoader) |
| 1108 dropProtection(); | 1106 dropProtection(); |
| 1109 } | 1107 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 m_decoder = TextResourceDecoder::create("text/plain", "UTF-8"); | 1159 m_decoder = TextResourceDecoder::create("text/plain", "UTF-8"); |
| 1162 } | 1160 } |
| 1163 | 1161 |
| 1164 if (!len) | 1162 if (!len) |
| 1165 return; | 1163 return; |
| 1166 | 1164 |
| 1167 if (len == -1) | 1165 if (len == -1) |
| 1168 len = strlen(data); | 1166 len = strlen(data); |
| 1169 | 1167 |
| 1170 if (useDecoder) | 1168 if (useDecoder) |
| 1171 m_responseBuilder.append(m_decoder->decode(data, len)); | 1169 m_responseText = m_responseText.concatenateWith(m_decoder->decode(data,
len)); |
| 1172 else if (m_responseTypeCode == ResponseTypeArrayBuffer || m_responseTypeCode
== ResponseTypeBlob) { | 1170 else if (m_responseTypeCode == ResponseTypeArrayBuffer || m_responseTypeCode
== ResponseTypeBlob) { |
| 1173 // Buffer binary data. | 1171 // Buffer binary data. |
| 1174 if (!m_binaryResponseBuilder) | 1172 if (!m_binaryResponseBuilder) |
| 1175 m_binaryResponseBuilder = SharedBuffer::create(); | 1173 m_binaryResponseBuilder = SharedBuffer::create(); |
| 1176 m_binaryResponseBuilder->append(data, len); | 1174 m_binaryResponseBuilder->append(data, len); |
| 1177 } | 1175 } |
| 1178 | 1176 |
| 1179 if (!m_error) { | 1177 if (!m_error) { |
| 1180 long long expectedLength = m_response.expectedContentLength(); | 1178 long long expectedLength = m_response.expectedContentLength(); |
| 1181 m_receivedLength += len; | 1179 m_receivedLength += len; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 info.addMember(m_url, "url"); | 1277 info.addMember(m_url, "url"); |
| 1280 info.addMember(m_method, "method"); | 1278 info.addMember(m_method, "method"); |
| 1281 info.addMember(m_requestHeaders, "requestHeaders"); | 1279 info.addMember(m_requestHeaders, "requestHeaders"); |
| 1282 info.addMember(m_requestEntityBody, "requestEntityBody"); | 1280 info.addMember(m_requestEntityBody, "requestEntityBody"); |
| 1283 info.addMember(m_mimeTypeOverride, "mimeTypeOverride"); | 1281 info.addMember(m_mimeTypeOverride, "mimeTypeOverride"); |
| 1284 info.addMember(m_responseBlob, "responseBlob"); | 1282 info.addMember(m_responseBlob, "responseBlob"); |
| 1285 info.addMember(m_loader, "loader"); | 1283 info.addMember(m_loader, "loader"); |
| 1286 info.addMember(m_response, "response"); | 1284 info.addMember(m_response, "response"); |
| 1287 info.addMember(m_responseEncoding, "responseEncoding"); | 1285 info.addMember(m_responseEncoding, "responseEncoding"); |
| 1288 info.addMember(m_decoder, "decoder"); | 1286 info.addMember(m_decoder, "decoder"); |
| 1289 info.addMember(m_responseBuilder, "responseBuilder"); | 1287 info.addMember(m_responseText, "responseText"); |
| 1290 info.addMember(m_responseDocument, "responseDocument"); | 1288 info.addMember(m_responseDocument, "responseDocument"); |
| 1291 info.addMember(m_binaryResponseBuilder, "binaryResponseBuilder"); | 1289 info.addMember(m_binaryResponseBuilder, "binaryResponseBuilder"); |
| 1292 info.addMember(m_responseArrayBuffer, "responseArrayBuffer"); | 1290 info.addMember(m_responseArrayBuffer, "responseArrayBuffer"); |
| 1293 info.addMember(m_lastSendURL, "lastSendURL"); | 1291 info.addMember(m_lastSendURL, "lastSendURL"); |
| 1294 info.addMember(m_eventTargetData, "eventTargetData"); | 1292 info.addMember(m_eventTargetData, "eventTargetData"); |
| 1295 info.addMember(m_progressEventThrottle, "progressEventThrottle"); | 1293 info.addMember(m_progressEventThrottle, "progressEventThrottle"); |
| 1296 info.addMember(m_securityOrigin, "securityOrigin"); | 1294 info.addMember(m_securityOrigin, "securityOrigin"); |
| 1297 } | 1295 } |
| 1298 | 1296 |
| 1299 } // namespace WebCore | 1297 } // namespace WebCore |
| OLD | NEW |