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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return 0; | 244 return 0; |
245 | 245 |
246 if (!m_createdDocument) { | 246 if (!m_createdDocument) { |
247 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); | 247 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); |
248 | 248 |
249 // The W3C spec requires the final MIME type to be some valid XML type,
or text/html. | 249 // The W3C spec requires the final MIME type to be some valid XML type,
or text/html. |
250 // If it is text/html, then the responseType of "document" must have bee
n supplied explicitly. | 250 // If it is text/html, then the responseType of "document" must have bee
n supplied explicitly. |
251 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) | 251 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) |
252 || (isHTML && m_responseTypeCode == ResponseTypeDefault) | 252 || (isHTML && m_responseTypeCode == ResponseTypeDefault) |
253 || executionContext()->isWorkerGlobalScope()) { | 253 || executionContext()->isWorkerGlobalScope()) { |
254 m_responseDocument = 0; | 254 m_responseDocument = nullptr; |
255 } else { | 255 } else { |
256 DocumentInit init = DocumentInit::fromContext(document()->contextDoc
ument(), m_url); | 256 DocumentInit init = DocumentInit::fromContext(document()->contextDoc
ument(), m_url); |
257 if (isHTML) | 257 if (isHTML) |
258 m_responseDocument = HTMLDocument::create(init); | 258 m_responseDocument = HTMLDocument::create(init); |
259 else | 259 else |
260 m_responseDocument = Document::create(init); | 260 m_responseDocument = Document::create(init); |
261 // FIXME: Set Last-Modified. | 261 // FIXME: Set Last-Modified. |
262 m_responseDocument->setContent(m_responseText.flattenToString()); | 262 m_responseDocument->setContent(m_responseText.flattenToString()); |
263 m_responseDocument->setSecurityOrigin(securityOrigin()); | 263 m_responseDocument->setSecurityOrigin(securityOrigin()); |
264 m_responseDocument->setContextFeatures(document()->contextFeatures()
); | 264 m_responseDocument->setContextFeatures(document()->contextFeatures()
); |
265 if (!m_responseDocument->wellFormed()) | 265 if (!m_responseDocument->wellFormed()) |
266 m_responseDocument = 0; | 266 m_responseDocument = nullptr; |
267 } | 267 } |
268 m_createdDocument = true; | 268 m_createdDocument = true; |
269 } | 269 } |
270 | 270 |
271 return m_responseDocument.get(); | 271 return m_responseDocument.get(); |
272 } | 272 } |
273 | 273 |
274 Blob* XMLHttpRequest::responseBlob() | 274 Blob* XMLHttpRequest::responseBlob() |
275 { | 275 { |
276 ASSERT(m_responseTypeCode == ResponseTypeBlob); | 276 ASSERT(m_responseTypeCode == ResponseTypeBlob); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 m_requestEntityBody = FormData::create(data, length); | 760 m_requestEntityBody = FormData::create(data, length); |
761 if (m_upload) | 761 if (m_upload) |
762 m_requestEntityBody->setAlwaysStream(true); | 762 m_requestEntityBody->setAlwaysStream(true); |
763 } | 763 } |
764 | 764 |
765 createRequest(exceptionState); | 765 createRequest(exceptionState); |
766 } | 766 } |
767 | 767 |
768 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex
ceptionState& exceptionState) | 768 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex
ceptionState& exceptionState) |
769 { | 769 { |
770 m_requestEntityBody = formData ? formData->deepCopy() : 0; | 770 m_requestEntityBody = formData ? formData->deepCopy() : nullptr; |
771 createRequest(exceptionState); | 771 createRequest(exceptionState); |
772 m_exceptionCode = exceptionState.code(); | 772 m_exceptionCode = exceptionState.code(); |
773 } | 773 } |
774 | 774 |
775 void XMLHttpRequest::createRequest(ExceptionState& exceptionState) | 775 void XMLHttpRequest::createRequest(ExceptionState& exceptionState) |
776 { | 776 { |
777 // Only GET request is supported for blob URL. | 777 // Only GET request is supported for blob URL. |
778 if (m_url.protocolIs("blob") && m_method != "GET") { | 778 if (m_url.protocolIs("blob") && m_method != "GET") { |
779 exceptionState.throwDOMException(NetworkError, "'GET' is the only method
allowed for 'blob:' URLs."); | 779 exceptionState.throwDOMException(NetworkError, "'GET' is the only method
allowed for 'blob:' URLs."); |
780 return; | 780 return; |
(...skipping 20 matching lines...) Expand all Loading... |
801 ResourceRequest request(m_url); | 801 ResourceRequest request(m_url); |
802 request.setHTTPMethod(m_method); | 802 request.setHTTPMethod(m_method); |
803 request.setTargetType(ResourceRequest::TargetIsXHR); | 803 request.setTargetType(ResourceRequest::TargetIsXHR); |
804 | 804 |
805 // When "blob" is specified for the responseType attribute, | 805 // When "blob" is specified for the responseType attribute, |
806 // we redirect the downloaded data to a file-handle directly | 806 // we redirect the downloaded data to a file-handle directly |
807 // and get the file-path as the result. | 807 // and get the file-path as the result. |
808 if (responseTypeCode() == ResponseTypeBlob) | 808 if (responseTypeCode() == ResponseTypeBlob) |
809 request.setDownloadToFile(true); | 809 request.setDownloadToFile(true); |
810 | 810 |
811 InspectorInstrumentation::willLoadXHR(executionContext(), this, this, m_meth
od, m_url, m_async, m_requestEntityBody ? m_requestEntityBody->deepCopy() : 0, m
_requestHeaders, m_includeCredentials); | 811 InspectorInstrumentation::willLoadXHR(executionContext(), this, this, m_meth
od, m_url, m_async, m_requestEntityBody ? m_requestEntityBody->deepCopy() : null
ptr, m_requestHeaders, m_includeCredentials); |
812 | 812 |
813 if (m_requestEntityBody) { | 813 if (m_requestEntityBody) { |
814 ASSERT(m_method != "GET"); | 814 ASSERT(m_method != "GET"); |
815 ASSERT(m_method != "HEAD"); | 815 ASSERT(m_method != "HEAD"); |
816 request.setHTTPBody(m_requestEntityBody.release()); | 816 request.setHTTPBody(m_requestEntityBody.release()); |
817 } | 817 } |
818 | 818 |
819 if (m_requestHeaders.size() > 0) | 819 if (m_requestHeaders.size() > 0) |
820 request.addHTTPHeaderFields(m_requestHeaders); | 820 request.addHTTPHeaderFields(m_requestHeaders); |
821 | 821 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 { | 951 { |
952 // FIXME: when we add the support for multi-part XHR, we will have to | 952 // FIXME: when we add the support for multi-part XHR, we will have to |
953 // be careful with this initialization. | 953 // be careful with this initialization. |
954 m_receivedLength = 0; | 954 m_receivedLength = 0; |
955 | 955 |
956 m_response = ResourceResponse(); | 956 m_response = ResourceResponse(); |
957 | 957 |
958 m_responseText.clear(); | 958 m_responseText.clear(); |
959 | 959 |
960 m_createdDocument = false; | 960 m_createdDocument = false; |
961 m_responseDocument = 0; | 961 m_responseDocument = nullptr; |
962 | 962 |
963 m_responseBlob = 0; | 963 m_responseBlob = nullptr; |
964 | 964 |
965 m_responseStream = 0; | 965 m_responseStream = nullptr; |
966 | 966 |
967 // These variables may referred by the response accessors. So, we can clear | 967 // These variables may referred by the response accessors. So, we can clear |
968 // this only when we clear the response holder variables above. | 968 // this only when we clear the response holder variables above. |
969 m_binaryResponseBuilder.clear(); | 969 m_binaryResponseBuilder.clear(); |
970 m_responseArrayBuffer.clear(); | 970 m_responseArrayBuffer.clear(); |
971 } | 971 } |
972 | 972 |
973 void XMLHttpRequest::clearRequest() | 973 void XMLHttpRequest::clearRequest() |
974 { | 974 { |
975 m_requestHeaders.clear(); | 975 m_requestHeaders.clear(); |
976 m_requestEntityBody = 0; | 976 m_requestEntityBody = nullptr; |
977 } | 977 } |
978 | 978 |
979 void XMLHttpRequest::handleDidFailGeneric() | 979 void XMLHttpRequest::handleDidFailGeneric() |
980 { | 980 { |
981 clearResponse(); | 981 clearResponse(); |
982 clearRequest(); | 982 clearRequest(); |
983 | 983 |
984 m_error = true; | 984 m_error = true; |
985 } | 985 } |
986 | 986 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 m_responseStream->finalize(); | 1262 m_responseStream->finalize(); |
1263 | 1263 |
1264 clearVariablesForLoading(); | 1264 clearVariablesForLoading(); |
1265 | 1265 |
1266 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this
, identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumb
er); | 1266 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this
, identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumb
er); |
1267 | 1267 |
1268 // Prevent dropProtection releasing the last reference, and retain |this| un
til the end of this method. | 1268 // Prevent dropProtection releasing the last reference, and retain |this| un
til the end of this method. |
1269 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this); | 1269 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this); |
1270 | 1270 |
1271 if (m_loader) { | 1271 if (m_loader) { |
1272 m_loader = 0; | 1272 m_loader = nullptr; |
1273 dropProtection(); | 1273 dropProtection(); |
1274 } | 1274 } |
1275 | 1275 |
1276 changeState(DONE); | 1276 changeState(DONE); |
1277 } | 1277 } |
1278 | 1278 |
1279 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
g totalBytesToBeSent) | 1279 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
g totalBytesToBeSent) |
1280 { | 1280 { |
1281 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen
t, totalBytesToBeSent); | 1281 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen
t, totalBytesToBeSent); |
1282 | 1282 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 { | 1423 { |
1424 return EventTargetNames::XMLHttpRequest; | 1424 return EventTargetNames::XMLHttpRequest; |
1425 } | 1425 } |
1426 | 1426 |
1427 ExecutionContext* XMLHttpRequest::executionContext() const | 1427 ExecutionContext* XMLHttpRequest::executionContext() const |
1428 { | 1428 { |
1429 return ActiveDOMObject::executionContext(); | 1429 return ActiveDOMObject::executionContext(); |
1430 } | 1430 } |
1431 | 1431 |
1432 } // namespace WebCore | 1432 } // namespace WebCore |
OLD | NEW |