| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 void XMLHttpRequest::dispatchReadyStateChangeEvent() | 423 void XMLHttpRequest::dispatchReadyStateChangeEvent() |
| 424 { | 424 { |
| 425 if (!executionContext()) | 425 if (!executionContext()) |
| 426 return; | 426 return; |
| 427 | 427 |
| 428 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispat
chXHRReadyStateChangeEvent(executionContext(), this); | 428 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispat
chXHRReadyStateChangeEvent(executionContext(), this); |
| 429 | 429 |
| 430 if (m_async || (m_state <= OPENED || m_state == DONE)) | 430 if (m_async || (m_state <= OPENED || m_state == DONE)) { |
| 431 m_progressEventThrottle.dispatchReadyStateChangeEvent(XMLHttpRequestProg
ressEvent::create(EventTypeNames::readystatechange), m_state == DONE ? FlushProg
ressEvent : DoNotFlushProgressEvent); | 431 ProgressEventAction flushAction = DoNotFlushProgressEvent; |
| 432 if (m_state == DONE) { |
| 433 if (m_error) |
| 434 flushAction = FlushDeferredProgressEvent; |
| 435 else |
| 436 flushAction = FlushProgressEvent; |
| 437 } |
| 438 m_progressEventThrottle.dispatchReadyStateChangeEvent(XMLHttpRequestProg
ressEvent::create(EventTypeNames::readystatechange), flushAction); |
| 439 } |
| 432 | 440 |
| 433 InspectorInstrumentation::didDispatchXHRReadyStateChangeEvent(cookie); | 441 InspectorInstrumentation::didDispatchXHRReadyStateChangeEvent(cookie); |
| 434 if (m_state == DONE && !m_error) { | 442 if (m_state == DONE && !m_error) { |
| 435 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDi
spatchXHRLoadEvent(executionContext(), this); | 443 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDi
spatchXHRLoadEvent(executionContext(), this); |
| 436 m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::creat
e(EventTypeNames::load)); | 444 m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::creat
e(EventTypeNames::load)); |
| 437 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie); | 445 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie); |
| 438 m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::creat
e(EventTypeNames::loadend)); | 446 m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::creat
e(EventTypeNames::loadend)); |
| 439 } | 447 } |
| 440 } | 448 } |
| 441 | 449 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 bool sendFlag = m_loader; | 857 bool sendFlag = m_loader; |
| 850 | 858 |
| 851 if (!internalAbort()) | 859 if (!internalAbort()) |
| 852 return; | 860 return; |
| 853 | 861 |
| 854 clearResponse(); | 862 clearResponse(); |
| 855 | 863 |
| 856 // Clear headers as required by the spec | 864 // Clear headers as required by the spec |
| 857 m_requestHeaders.clear(); | 865 m_requestHeaders.clear(); |
| 858 | 866 |
| 859 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) { | 867 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) { |
| 860 // No readystatechange event is dispatched. | 868 ASSERT(!m_loader); |
| 861 m_state = UNSENT; | 869 handleRequestError(0, EventTypeNames::abort); |
| 862 return; | |
| 863 } | 870 } |
| 864 | |
| 865 ASSERT(!m_loader); | |
| 866 changeState(DONE); | |
| 867 m_state = UNSENT; | 871 m_state = UNSENT; |
| 868 | |
| 869 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(EventTypeNames::abort)); | |
| 870 if (!m_uploadComplete) { | |
| 871 m_uploadComplete = true; | |
| 872 if (m_upload && m_uploadEventsAllowed) | |
| 873 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(EventTypeNames::abort)); | |
| 874 } | |
| 875 } | 872 } |
| 876 | 873 |
| 877 void XMLHttpRequest::clearVariablesForLoading() | 874 void XMLHttpRequest::clearVariablesForLoading() |
| 878 { | 875 { |
| 879 // FIXME: when we add the support for multi-part XHR, we will have to think
be careful with this initialization. | 876 // FIXME: when we add the support for multi-part XHR, we will have to think
be careful with this initialization. |
| 880 m_receivedLength = 0; | 877 m_receivedLength = 0; |
| 881 m_decoder = 0; | 878 m_decoder = 0; |
| 882 | 879 |
| 883 m_responseEncoding = String(); | 880 m_responseEncoding = String(); |
| 884 } | 881 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLe
ngth; | 968 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLe
ngth; |
| 972 unsigned long long total = lengthComputable ? expectedLength : 0; | 969 unsigned long long total = lengthComputable ? expectedLength : 0; |
| 973 | 970 |
| 974 m_progressEventThrottle.dispatchProgressEvent(lengthComputable, m_receivedLe
ngth, total); | 971 m_progressEventThrottle.dispatchProgressEvent(lengthComputable, m_receivedLe
ngth, total); |
| 975 } | 972 } |
| 976 | 973 |
| 977 void XMLHttpRequest::handleNetworkError() | 974 void XMLHttpRequest::handleNetworkError() |
| 978 { | 975 { |
| 979 LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); | 976 LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); |
| 980 | 977 |
| 981 m_exceptionCode = NetworkError; | |
| 982 | |
| 983 handleDidFailGeneric(); | 978 handleDidFailGeneric(); |
| 984 | 979 handleRequestError(NetworkError, EventTypeNames::error); |
| 985 if (m_async) { | |
| 986 changeState(DONE); | |
| 987 dispatchEventAndLoadEnd(EventTypeNames::error); | |
| 988 } else { | |
| 989 m_state = DONE; | |
| 990 } | |
| 991 | |
| 992 internalAbort(); | 980 internalAbort(); |
| 993 } | 981 } |
| 994 | 982 |
| 995 void XMLHttpRequest::handleDidCancel() | 983 void XMLHttpRequest::handleDidCancel() |
| 996 { | 984 { |
| 997 LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); | 985 LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); |
| 998 | 986 |
| 999 m_exceptionCode = AbortError; | 987 handleDidFailGeneric(); |
| 988 handleRequestError(AbortError, EventTypeNames::abort); |
| 989 } |
| 1000 | 990 |
| 1001 handleDidFailGeneric(); | 991 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
cString& type) |
| 992 { |
| 993 LOG(Network, "XMLHttpRequest %p handleRequestError()", this); |
| 1002 | 994 |
| 1003 if (!m_async) { | 995 // The request error steps for event 'type' and exception 'exceptionCode'. |
| 996 |
| 997 if (!m_async && exceptionCode) { |
| 1004 m_state = DONE; | 998 m_state = DONE; |
| 999 m_exceptionCode = exceptionCode; |
| 1005 return; | 1000 return; |
| 1006 } | 1001 } |
| 1002 // With m_error set, the state change steps are minimal: any pending |
| 1003 // progress event is flushed + a readystatechange is dispatched. |
| 1004 // No new progress events dispatched; as required, that happens at |
| 1005 // the end here. |
| 1006 ASSERT(m_error); |
| 1007 changeState(DONE); | 1007 changeState(DONE); |
| 1008 | 1008 |
| 1009 dispatchEventAndLoadEnd(EventTypeNames::abort); | 1009 if (!m_uploadComplete) { |
| 1010 m_uploadComplete = true; |
| 1011 if (m_upload && m_uploadEventsAllowed) |
| 1012 m_upload->handleRequestError(type); |
| 1013 } |
| 1014 |
| 1015 dispatchThrottledProgressEvent(); |
| 1016 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(type)); |
| 1010 } | 1017 } |
| 1011 | 1018 |
| 1012 void XMLHttpRequest::dropProtectionSoon() | 1019 void XMLHttpRequest::dropProtectionSoon() |
| 1013 { | 1020 { |
| 1014 m_dropProtectionRunner.runAsync(); | 1021 m_dropProtectionRunner.runAsync(); |
| 1015 } | 1022 } |
| 1016 | 1023 |
| 1017 void XMLHttpRequest::dropProtection() | 1024 void XMLHttpRequest::dropProtection() |
| 1018 { | 1025 { |
| 1019 unsetPendingActivity(this); | 1026 unsetPendingActivity(this); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 void XMLHttpRequest::handleDidTimeout() | 1332 void XMLHttpRequest::handleDidTimeout() |
| 1326 { | 1333 { |
| 1327 LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); | 1334 LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); |
| 1328 | 1335 |
| 1329 // internalAbort() calls dropProtection(), which may release the last refere
nce. | 1336 // internalAbort() calls dropProtection(), which may release the last refere
nce. |
| 1330 RefPtr<XMLHttpRequest> protect(this); | 1337 RefPtr<XMLHttpRequest> protect(this); |
| 1331 | 1338 |
| 1332 if (!internalAbort()) | 1339 if (!internalAbort()) |
| 1333 return; | 1340 return; |
| 1334 | 1341 |
| 1335 m_exceptionCode = TimeoutError; | |
| 1336 | |
| 1337 handleDidFailGeneric(); | 1342 handleDidFailGeneric(); |
| 1338 | 1343 handleRequestError(TimeoutError, EventTypeNames::timeout); |
| 1339 if (!m_async) { | |
| 1340 m_state = DONE; | |
| 1341 return; | |
| 1342 } | |
| 1343 changeState(DONE); | |
| 1344 | |
| 1345 dispatchEventAndLoadEnd(EventTypeNames::timeout); | |
| 1346 } | 1344 } |
| 1347 | 1345 |
| 1348 void XMLHttpRequest::suspend() | 1346 void XMLHttpRequest::suspend() |
| 1349 { | 1347 { |
| 1350 m_progressEventThrottle.suspend(); | 1348 m_progressEventThrottle.suspend(); |
| 1351 } | 1349 } |
| 1352 | 1350 |
| 1353 void XMLHttpRequest::resume() | 1351 void XMLHttpRequest::resume() |
| 1354 { | 1352 { |
| 1355 m_progressEventThrottle.resume(); | 1353 m_progressEventThrottle.resume(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1370 { | 1368 { |
| 1371 return EventTargetNames::XMLHttpRequest; | 1369 return EventTargetNames::XMLHttpRequest; |
| 1372 } | 1370 } |
| 1373 | 1371 |
| 1374 ExecutionContext* XMLHttpRequest::executionContext() const | 1372 ExecutionContext* XMLHttpRequest::executionContext() const |
| 1375 { | 1373 { |
| 1376 return ActiveDOMObject::executionContext(); | 1374 return ActiveDOMObject::executionContext(); |
| 1377 } | 1375 } |
| 1378 | 1376 |
| 1379 } // namespace WebCore | 1377 } // namespace WebCore |
| OLD | NEW |