| 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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 | 701 |
| 702 m_error = false; | 702 m_error = false; |
| 703 return true; | 703 return true; |
| 704 } | 704 } |
| 705 | 705 |
| 706 void XMLHttpRequest::send( | 706 void XMLHttpRequest::send( |
| 707 const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringOrFormData& body, | 707 const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringOrFormData& body, |
| 708 ExceptionState& exceptionState) { | 708 ExceptionState& exceptionState) { |
| 709 InspectorInstrumentation::willSendXMLHttpOrFetchNetworkRequest( | 709 probe::willSendXMLHttpOrFetchNetworkRequest(getExecutionContext(), url()); |
| 710 getExecutionContext(), url()); | |
| 711 | 710 |
| 712 if (body.isNull()) { | 711 if (body.isNull()) { |
| 713 send(String(), exceptionState); | 712 send(String(), exceptionState); |
| 714 return; | 713 return; |
| 715 } | 714 } |
| 716 | 715 |
| 717 if (body.isArrayBuffer()) { | 716 if (body.isArrayBuffer()) { |
| 718 send(body.getAsArrayBuffer(), exceptionState); | 717 send(body.getAsArrayBuffer(), exceptionState); |
| 719 return; | 718 return; |
| 720 } | 719 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 DCHECK(getExecutionContext()); | 928 DCHECK(getExecutionContext()); |
| 930 ExecutionContext& executionContext = *getExecutionContext(); | 929 ExecutionContext& executionContext = *getExecutionContext(); |
| 931 | 930 |
| 932 m_sendFlag = true; | 931 m_sendFlag = true; |
| 933 // The presence of upload event listeners forces us to use preflighting | 932 // The presence of upload event listeners forces us to use preflighting |
| 934 // because POSTing to an URL that does not permit cross origin requests should | 933 // because POSTing to an URL that does not permit cross origin requests should |
| 935 // look exactly like POSTing to an URL that does not respond at all. | 934 // look exactly like POSTing to an URL that does not respond at all. |
| 936 // Also, only async requests support upload progress events. | 935 // Also, only async requests support upload progress events. |
| 937 bool uploadEvents = false; | 936 bool uploadEvents = false; |
| 938 if (m_async) { | 937 if (m_async) { |
| 939 InspectorInstrumentation::asyncTaskScheduled( | 938 probe::asyncTaskScheduled(&executionContext, "XMLHttpRequest.send", this, |
| 940 &executionContext, "XMLHttpRequest.send", this, true); | 939 true); |
| 941 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); | 940 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); |
| 942 // Event handler could have invalidated this send operation, | 941 // Event handler could have invalidated this send operation, |
| 943 // (re)setting the send flag and/or initiating another send | 942 // (re)setting the send flag and/or initiating another send |
| 944 // operation; leave quietly if so. | 943 // operation; leave quietly if so. |
| 945 if (!m_sendFlag || m_loader) | 944 if (!m_sendFlag || m_loader) |
| 946 return; | 945 return; |
| 947 if (httpBody && m_upload) { | 946 if (httpBody && m_upload) { |
| 948 uploadEvents = m_upload->hasEventListeners(); | 947 uploadEvents = m_upload->hasEventListeners(); |
| 949 m_upload->dispatchEvent( | 948 m_upload->dispatchEvent( |
| 950 ProgressEvent::create(EventTypeNames::loadstart, false, 0, 0)); | 949 ProgressEvent::create(EventTypeNames::loadstart, false, 0, 0)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); | 982 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); |
| 984 request.setFetchCredentialsMode( | 983 request.setFetchCredentialsMode( |
| 985 includeCredentials ? WebURLRequest::FetchCredentialsModeInclude | 984 includeCredentials ? WebURLRequest::FetchCredentialsModeInclude |
| 986 : WebURLRequest::FetchCredentialsModeSameOrigin); | 985 : WebURLRequest::FetchCredentialsModeSameOrigin); |
| 987 request.setServiceWorkerMode(m_isIsolatedWorld | 986 request.setServiceWorkerMode(m_isIsolatedWorld |
| 988 ? WebURLRequest::ServiceWorkerMode::None | 987 ? WebURLRequest::ServiceWorkerMode::None |
| 989 : WebURLRequest::ServiceWorkerMode::All); | 988 : WebURLRequest::ServiceWorkerMode::All); |
| 990 request.setExternalRequestStateFromRequestorAddressSpace( | 989 request.setExternalRequestStateFromRequestorAddressSpace( |
| 991 executionContext.securityContext().addressSpace()); | 990 executionContext.securityContext().addressSpace()); |
| 992 | 991 |
| 993 InspectorInstrumentation::willLoadXHR( | 992 probe::willLoadXHR(&executionContext, this, this, m_method, m_url, m_async, |
| 994 &executionContext, this, this, m_method, m_url, m_async, | 993 httpBody ? httpBody->deepCopy() : nullptr, |
| 995 httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, | 994 m_requestHeaders, includeCredentials); |
| 996 includeCredentials); | |
| 997 | 995 |
| 998 if (httpBody) { | 996 if (httpBody) { |
| 999 DCHECK_NE(m_method, HTTPNames::GET); | 997 DCHECK_NE(m_method, HTTPNames::GET); |
| 1000 DCHECK_NE(m_method, HTTPNames::HEAD); | 998 DCHECK_NE(m_method, HTTPNames::HEAD); |
| 1001 request.setHTTPBody(std::move(httpBody)); | 999 request.setHTTPBody(std::move(httpBody)); |
| 1002 } | 1000 } |
| 1003 | 1001 |
| 1004 if (m_requestHeaders.size() > 0) | 1002 if (m_requestHeaders.size() > 0) |
| 1005 request.addHTTPHeaderFields(m_requestHeaders); | 1003 request.addHTTPHeaderFields(m_requestHeaders); |
| 1006 | 1004 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 DCHECK(!m_loader); | 1085 DCHECK(!m_loader); |
| 1088 handleRequestError(0, EventTypeNames::abort, receivedLength, | 1086 handleRequestError(0, EventTypeNames::abort, receivedLength, |
| 1089 expectedLength); | 1087 expectedLength); |
| 1090 } | 1088 } |
| 1091 } | 1089 } |
| 1092 if (m_state == kDone) | 1090 if (m_state == kDone) |
| 1093 m_state = kUnsent; | 1091 m_state = kUnsent; |
| 1094 } | 1092 } |
| 1095 | 1093 |
| 1096 void XMLHttpRequest::dispose() { | 1094 void XMLHttpRequest::dispose() { |
| 1097 InspectorInstrumentation::detachClientRequest(getExecutionContext(), this); | 1095 probe::detachClientRequest(getExecutionContext(), this); |
| 1098 m_progressEventThrottle->stop(); | 1096 m_progressEventThrottle->stop(); |
| 1099 internalAbort(); | 1097 internalAbort(); |
| 1100 } | 1098 } |
| 1101 | 1099 |
| 1102 void XMLHttpRequest::clearVariablesForLoading() { | 1100 void XMLHttpRequest::clearVariablesForLoading() { |
| 1103 if (m_blobLoader) { | 1101 if (m_blobLoader) { |
| 1104 m_blobLoader->cancel(); | 1102 m_blobLoader->cancel(); |
| 1105 m_blobLoader = nullptr; | 1103 m_blobLoader = nullptr; |
| 1106 } | 1104 } |
| 1107 | 1105 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 long long receivedLength, | 1185 long long receivedLength, |
| 1188 long long expectedLength) { | 1186 long long expectedLength) { |
| 1189 bool lengthComputable = | 1187 bool lengthComputable = |
| 1190 expectedLength > 0 && receivedLength <= expectedLength; | 1188 expectedLength > 0 && receivedLength <= expectedLength; |
| 1191 unsigned long long loaded = | 1189 unsigned long long loaded = |
| 1192 receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0; | 1190 receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0; |
| 1193 unsigned long long total = | 1191 unsigned long long total = |
| 1194 lengthComputable ? static_cast<unsigned long long>(expectedLength) : 0; | 1192 lengthComputable ? static_cast<unsigned long long>(expectedLength) : 0; |
| 1195 | 1193 |
| 1196 ExecutionContext* context = getExecutionContext(); | 1194 ExecutionContext* context = getExecutionContext(); |
| 1197 InspectorInstrumentation::AsyncTask asyncTask(context, this, m_async); | 1195 probe::AsyncTask asyncTask(context, this, m_async); |
| 1198 m_progressEventThrottle->dispatchProgressEvent(type, lengthComputable, loaded, | 1196 m_progressEventThrottle->dispatchProgressEvent(type, lengthComputable, loaded, |
| 1199 total); | 1197 total); |
| 1200 if (m_async && type == EventTypeNames::loadend) | 1198 if (m_async && type == EventTypeNames::loadend) |
| 1201 InspectorInstrumentation::asyncTaskCanceled(context, this); | 1199 probe::asyncTaskCanceled(context, this); |
| 1202 } | 1200 } |
| 1203 | 1201 |
| 1204 void XMLHttpRequest::dispatchProgressEventFromSnapshot( | 1202 void XMLHttpRequest::dispatchProgressEventFromSnapshot( |
| 1205 const AtomicString& type) { | 1203 const AtomicString& type) { |
| 1206 dispatchProgressEvent(type, m_receivedLength, | 1204 dispatchProgressEvent(type, m_receivedLength, |
| 1207 m_response.expectedContentLength()); | 1205 m_response.expectedContentLength()); |
| 1208 } | 1206 } |
| 1209 | 1207 |
| 1210 void XMLHttpRequest::handleNetworkError() { | 1208 void XMLHttpRequest::handleNetworkError() { |
| 1211 NETWORK_DVLOG(1) << this << " handleNetworkError()"; | 1209 NETWORK_DVLOG(1) << this << " handleNetworkError()"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1234 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, | 1232 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, |
| 1235 expectedLength); | 1233 expectedLength); |
| 1236 } | 1234 } |
| 1237 | 1235 |
| 1238 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, | 1236 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, |
| 1239 const AtomicString& type, | 1237 const AtomicString& type, |
| 1240 long long receivedLength, | 1238 long long receivedLength, |
| 1241 long long expectedLength) { | 1239 long long expectedLength) { |
| 1242 NETWORK_DVLOG(1) << this << " handleRequestError()"; | 1240 NETWORK_DVLOG(1) << this << " handleRequestError()"; |
| 1243 | 1241 |
| 1244 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, this, | 1242 probe::didFailXHRLoading(getExecutionContext(), this, this, m_method, m_url); |
| 1245 m_method, m_url); | |
| 1246 | 1243 |
| 1247 m_sendFlag = false; | 1244 m_sendFlag = false; |
| 1248 if (!m_async) { | 1245 if (!m_async) { |
| 1249 DCHECK(exceptionCode); | 1246 DCHECK(exceptionCode); |
| 1250 m_state = kDone; | 1247 m_state = kDone; |
| 1251 m_exceptionCode = exceptionCode; | 1248 m_exceptionCode = exceptionCode; |
| 1252 return; | 1249 return; |
| 1253 } | 1250 } |
| 1254 | 1251 |
| 1255 // With m_error set, the state change steps are minimal: any pending | 1252 // With m_error set, the state change steps are minimal: any pending |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 | 1606 |
| 1610 if (!m_responseDocument->wellFormed()) | 1607 if (!m_responseDocument->wellFormed()) |
| 1611 m_responseDocument = nullptr; | 1608 m_responseDocument = nullptr; |
| 1612 | 1609 |
| 1613 m_parsedResponse = true; | 1610 m_parsedResponse = true; |
| 1614 | 1611 |
| 1615 endLoading(); | 1612 endLoading(); |
| 1616 } | 1613 } |
| 1617 | 1614 |
| 1618 void XMLHttpRequest::endLoading() { | 1615 void XMLHttpRequest::endLoading() { |
| 1619 InspectorInstrumentation::didFinishXHRLoading(getExecutionContext(), this, | 1616 probe::didFinishXHRLoading(getExecutionContext(), this, this, m_method, |
| 1620 this, m_method, m_url); | 1617 m_url); |
| 1621 | 1618 |
| 1622 if (m_loader) { | 1619 if (m_loader) { |
| 1623 // Set |m_error| in order to suppress the cancel notification (see | 1620 // Set |m_error| in order to suppress the cancel notification (see |
| 1624 // XMLHttpRequest::didFail). | 1621 // XMLHttpRequest::didFail). |
| 1625 AutoReset<bool> scope(&m_error, true); | 1622 AutoReset<bool> scope(&m_error, true); |
| 1626 m_loader.release()->cancel(); | 1623 m_loader.release()->cancel(); |
| 1627 } | 1624 } |
| 1628 | 1625 |
| 1629 m_sendFlag = false; | 1626 m_sendFlag = false; |
| 1630 changeState(kDone); | 1627 changeState(kDone); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 visitor->traceWrappers(m_responseDocument); | 1856 visitor->traceWrappers(m_responseDocument); |
| 1860 visitor->traceWrappers(m_responseArrayBuffer); | 1857 visitor->traceWrappers(m_responseArrayBuffer); |
| 1861 XMLHttpRequestEventTarget::traceWrappers(visitor); | 1858 XMLHttpRequestEventTarget::traceWrappers(visitor); |
| 1862 } | 1859 } |
| 1863 | 1860 |
| 1864 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { | 1861 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { |
| 1865 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); | 1862 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); |
| 1866 } | 1863 } |
| 1867 | 1864 |
| 1868 } // namespace blink | 1865 } // namespace blink |
| OLD | NEW |