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 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 m_binaryResponseBuilder.clear(); | 883 m_binaryResponseBuilder.clear(); |
884 m_responseArrayBuffer.clear(); | 884 m_responseArrayBuffer.clear(); |
885 } | 885 } |
886 | 886 |
887 void XMLHttpRequest::clearRequest() | 887 void XMLHttpRequest::clearRequest() |
888 { | 888 { |
889 m_requestHeaders.clear(); | 889 m_requestHeaders.clear(); |
890 m_requestEntityBody = 0; | 890 m_requestEntityBody = 0; |
891 } | 891 } |
892 | 892 |
893 void XMLHttpRequest::genericError() | 893 void XMLHttpRequest::handleDidFailGeneric() |
894 { | 894 { |
895 clearResponse(); | 895 clearResponse(); |
896 clearRequest(); | 896 clearRequest(); |
| 897 |
897 m_error = true; | 898 m_error = true; |
898 | |
899 changeState(DONE); | |
900 } | 899 } |
901 | 900 |
902 void XMLHttpRequest::networkError() | 901 void XMLHttpRequest::dispatchEventAndLoadEnd(const AtomicString& type) |
903 { | 902 { |
904 genericError(); | |
905 if (!m_uploadComplete) { | 903 if (!m_uploadComplete) { |
906 m_uploadComplete = true; | 904 m_uploadComplete = true; |
907 if (m_upload && m_uploadEventsAllowed) | 905 if (m_upload && m_uploadEventsAllowed) |
908 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().errorEvent)); | 906 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(type)); |
909 } | 907 } |
910 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().errorEvent)); | 908 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(type)); |
| 909 } |
| 910 |
| 911 void XMLHttpRequest::handleNetworkError() |
| 912 { |
| 913 m_exceptionCode = NetworkError; |
| 914 |
| 915 handleDidFailGeneric(); |
| 916 |
| 917 if (m_async) { |
| 918 changeState(DONE); |
| 919 dispatchEventAndLoadEnd(eventNames().errorEvent); |
| 920 } else { |
| 921 m_state = DONE; |
| 922 } |
| 923 |
911 internalAbort(); | 924 internalAbort(); |
912 } | 925 } |
913 | 926 |
914 void XMLHttpRequest::abortError() | 927 void XMLHttpRequest::handleDidCancel() |
915 { | 928 { |
916 genericError(); | 929 m_exceptionCode = AbortError; |
917 if (!m_uploadComplete) { | 930 |
918 m_uploadComplete = true; | 931 handleDidFailGeneric(); |
919 if (m_upload && m_uploadEventsAllowed) | 932 |
920 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().abortEvent)); | 933 if (!m_async) { |
| 934 m_state = DONE; |
| 935 return; |
921 } | 936 } |
922 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().abortEvent)); | 937 changeState(DONE); |
| 938 |
| 939 dispatchEventAndLoadEnd(eventNames().abortEvent); |
923 } | 940 } |
924 | 941 |
925 void XMLHttpRequest::dropProtectionSoon() | 942 void XMLHttpRequest::dropProtectionSoon() |
926 { | 943 { |
927 if (m_protectionTimer.isActive()) | 944 if (m_protectionTimer.isActive()) |
928 return; | 945 return; |
929 m_protectionTimer.startOneShot(0); | 946 m_protectionTimer.startOneShot(0); |
930 } | 947 } |
931 | 948 |
932 void XMLHttpRequest::dropProtection(Timer<XMLHttpRequest>*) | 949 void XMLHttpRequest::dropProtection(Timer<XMLHttpRequest>*) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 if (m_state == OPENED) { | 1097 if (m_state == OPENED) { |
1081 // See comments in status() above. | 1098 // See comments in status() above. |
1082 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToGet("
statusText", "XMLHttpRequest", "the object's state must not be OPENED.")); | 1099 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToGet("
statusText", "XMLHttpRequest", "the object's state must not be OPENED.")); |
1083 } | 1100 } |
1084 | 1101 |
1085 return String(); | 1102 return String(); |
1086 } | 1103 } |
1087 | 1104 |
1088 void XMLHttpRequest::didFail(const ResourceError& error) | 1105 void XMLHttpRequest::didFail(const ResourceError& error) |
1089 { | 1106 { |
1090 | |
1091 // If we are already in an error state, for instance we called abort(), bail
out early. | 1107 // If we are already in an error state, for instance we called abort(), bail
out early. |
1092 if (m_error) | 1108 if (m_error) |
1093 return; | 1109 return; |
1094 | 1110 |
1095 if (error.isCancellation()) { | 1111 if (error.isCancellation()) { |
1096 m_exceptionCode = AbortError; | 1112 handleDidCancel(); |
1097 abortError(); | |
1098 return; | 1113 return; |
1099 } | 1114 } |
1100 | 1115 |
1101 if (error.isTimeout()) { | 1116 if (error.isTimeout()) { |
1102 didTimeout(); | 1117 handleDidTimeout(); |
1103 return; | 1118 return; |
1104 } | 1119 } |
1105 | 1120 |
1106 // Network failures are already reported to Web Inspector by ResourceLoader. | 1121 // Network failures are already reported to Web Inspector by ResourceLoader. |
1107 if (error.domain() == errorDomainWebKitInternal) | 1122 if (error.domain() == errorDomainWebKitInternal) |
1108 logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load "
+ error.failingURL() + ". " + error.localizedDescription()); | 1123 logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load "
+ error.failingURL() + ". " + error.localizedDescription()); |
1109 | 1124 |
1110 m_exceptionCode = NetworkError; | 1125 handleNetworkError(); |
1111 networkError(); | |
1112 } | 1126 } |
1113 | 1127 |
1114 void XMLHttpRequest::didFailRedirectCheck() | 1128 void XMLHttpRequest::didFailRedirectCheck() |
1115 { | 1129 { |
1116 networkError(); | 1130 handleNetworkError(); |
1117 } | 1131 } |
1118 | 1132 |
1119 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) | 1133 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
1120 { | 1134 { |
1121 if (m_error) | 1135 if (m_error) |
1122 return; | 1136 return; |
1123 | 1137 |
1124 if (m_state < HEADERS_RECEIVED) | 1138 if (m_state < HEADERS_RECEIVED) |
1125 changeState(HEADERS_RECEIVED); | 1139 changeState(HEADERS_RECEIVED); |
1126 | 1140 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 } | 1244 } |
1231 | 1245 |
1232 if (m_state != LOADING) | 1246 if (m_state != LOADING) |
1233 changeState(LOADING); | 1247 changeState(LOADING); |
1234 else | 1248 else |
1235 // Firefox calls readyStateChanged every time it receives data, 4449
442 | 1249 // Firefox calls readyStateChanged every time it receives data, 4449
442 |
1236 callReadyStateChangeListener(); | 1250 callReadyStateChangeListener(); |
1237 } | 1251 } |
1238 } | 1252 } |
1239 | 1253 |
1240 void XMLHttpRequest::didTimeout() | 1254 void XMLHttpRequest::handleDidTimeout() |
1241 { | 1255 { |
1242 // internalAbort() calls dropProtection(), which may release the last refere
nce. | 1256 // internalAbort() calls dropProtection(), which may release the last refere
nce. |
1243 RefPtr<XMLHttpRequest> protect(this); | 1257 RefPtr<XMLHttpRequest> protect(this); |
1244 internalAbort(); | 1258 internalAbort(); |
1245 | 1259 |
1246 clearResponse(); | 1260 m_exceptionCode = TimeoutError; |
1247 clearRequest(); | |
1248 | 1261 |
1249 m_error = true; | 1262 handleDidFailGeneric(); |
1250 m_exceptionCode = TimeoutError; | |
1251 | 1263 |
1252 if (!m_async) { | 1264 if (!m_async) { |
1253 m_state = DONE; | 1265 m_state = DONE; |
1254 m_exceptionCode = TimeoutError; | |
1255 return; | 1266 return; |
1256 } | 1267 } |
1257 | |
1258 changeState(DONE); | 1268 changeState(DONE); |
1259 | 1269 |
1260 if (!m_uploadComplete) { | 1270 dispatchEventAndLoadEnd(eventNames().timeoutEvent); |
1261 m_uploadComplete = true; | |
1262 if (m_upload && m_uploadEventsAllowed) | |
1263 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().timeoutEvent)); | |
1264 } | |
1265 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().timeoutEvent)); | |
1266 } | 1271 } |
1267 | 1272 |
1268 bool XMLHttpRequest::canSuspend() const | 1273 bool XMLHttpRequest::canSuspend() const |
1269 { | 1274 { |
1270 return !m_loader; | 1275 return !m_loader; |
1271 } | 1276 } |
1272 | 1277 |
1273 void XMLHttpRequest::suspend(ReasonForSuspension) | 1278 void XMLHttpRequest::suspend(ReasonForSuspension) |
1274 { | 1279 { |
1275 m_progressEventThrottle.suspend(); | 1280 m_progressEventThrottle.suspend(); |
(...skipping 19 matching lines...) Expand all Loading... |
1295 { | 1300 { |
1296 return eventNames().interfaceForXMLHttpRequest; | 1301 return eventNames().interfaceForXMLHttpRequest; |
1297 } | 1302 } |
1298 | 1303 |
1299 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const | 1304 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const |
1300 { | 1305 { |
1301 return ActiveDOMObject::scriptExecutionContext(); | 1306 return ActiveDOMObject::scriptExecutionContext(); |
1302 } | 1307 } |
1303 | 1308 |
1304 } // namespace WebCore | 1309 } // namespace WebCore |
OLD | NEW |