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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 && !name.startsWith(staticData->m_secHeaderPrefix, false); | 443 && !name.startsWith(staticData->m_secHeaderPrefix, false); |
444 } | 444 } |
445 | 445 |
446 void XMLHttpRequest::open(const String& method, const KURL& url, ExceptionState&
es) | 446 void XMLHttpRequest::open(const String& method, const KURL& url, ExceptionState&
es) |
447 { | 447 { |
448 open(method, url, true, es); | 448 open(method, url, true, es); |
449 } | 449 } |
450 | 450 |
451 void XMLHttpRequest::open(const String& method, const KURL& url, bool async, Exc
eptionState& es) | 451 void XMLHttpRequest::open(const String& method, const KURL& url, bool async, Exc
eptionState& es) |
452 { | 452 { |
453 if (!internalAbort()) | 453 internalAbort(); |
454 return; | |
455 | |
456 State previousState = m_state; | 454 State previousState = m_state; |
457 m_state = UNSENT; | 455 m_state = UNSENT; |
458 m_error = false; | 456 m_error = false; |
459 m_uploadComplete = false; | 457 m_uploadComplete = false; |
460 | 458 |
461 // clear stuff from possible previous load | 459 // clear stuff from possible previous load |
462 clearResponse(); | 460 clearResponse(); |
463 clearRequest(); | 461 clearRequest(); |
464 | 462 |
465 ASSERT(m_state == UNSENT); | 463 ASSERT(m_state == UNSENT); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 es.throwDOMException(m_exceptionCode); | 776 es.throwDOMException(m_exceptionCode); |
779 } | 777 } |
780 | 778 |
781 void XMLHttpRequest::abort() | 779 void XMLHttpRequest::abort() |
782 { | 780 { |
783 // internalAbort() calls dropProtection(), which may release the last refere
nce. | 781 // internalAbort() calls dropProtection(), which may release the last refere
nce. |
784 RefPtr<XMLHttpRequest> protect(this); | 782 RefPtr<XMLHttpRequest> protect(this); |
785 | 783 |
786 bool sendFlag = m_loader; | 784 bool sendFlag = m_loader; |
787 | 785 |
788 if (!internalAbort()) | 786 internalAbort(); |
789 return; | |
790 | 787 |
791 clearResponseBuffers(); | 788 clearResponseBuffers(); |
792 | 789 |
793 // Clear headers as required by the spec | 790 // Clear headers as required by the spec |
794 m_requestHeaders.clear(); | 791 m_requestHeaders.clear(); |
795 | 792 |
796 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) | 793 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) |
797 m_state = UNSENT; | 794 m_state = UNSENT; |
798 else { | 795 else { |
799 ASSERT(!m_loader); | 796 ASSERT(!m_loader); |
800 changeState(DONE); | 797 changeState(DONE); |
801 m_state = UNSENT; | 798 m_state = UNSENT; |
802 } | 799 } |
803 | 800 |
804 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().abortEvent)); | 801 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().abortEvent)); |
805 if (!m_uploadComplete) { | 802 if (!m_uploadComplete) { |
806 m_uploadComplete = true; | 803 m_uploadComplete = true; |
807 if (m_upload && m_uploadEventsAllowed) | 804 if (m_upload && m_uploadEventsAllowed) |
808 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().abortEvent)); | 805 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().abortEvent)); |
809 } | 806 } |
810 } | 807 } |
811 | 808 |
812 bool XMLHttpRequest::internalAbort() | 809 void XMLHttpRequest::internalAbort() |
813 { | 810 { |
814 bool hadLoader = m_loader; | 811 bool hadLoader = m_loader; |
815 | 812 |
816 m_error = true; | 813 m_error = true; |
817 | 814 |
818 // FIXME: when we add the support for multi-part XHR, we will have to think
be careful with this initialization. | 815 // FIXME: when we add the support for multi-part XHR, we will have to think
be careful with this initialization. |
819 m_receivedLength = 0; | 816 m_receivedLength = 0; |
820 | 817 |
821 if (hadLoader) | 818 if (hadLoader) { |
822 // Cancelling the ThreadableLoader m_loader may result in calling | 819 m_loader->cancel(); |
823 // window.onload synchronously. If such an onload handler contains | 820 m_loader = 0; |
824 // open() call on the same XMLHttpRequest object, reentry happens. If | |
825 // m_loader is left to be non 0, internalAbort() call for the inner | |
826 // open() makes an extra dropProtection() call (when we're back to the | |
827 // outer open(), we'll call dropProtection()). To avoid that, clears | |
828 // m_loader before calling cancel. | |
829 // | |
830 // If, window.onload contains open() and send(), m_loader will be set to | |
831 // non 0 value. So, we cannot continue the outer open(). In such case, | |
832 // just abort the outer open() by returning false. | |
833 RefPtr<ThreadableLoader> loader = m_loader.release(); | |
834 loader->cancel(); | |
835 } | 821 } |
836 | 822 |
837 m_decoder = 0; | 823 m_decoder = 0; |
838 | 824 |
839 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); | 825 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); |
840 | 826 |
841 if (hadLoader) | 827 if (hadLoader) |
842 dropProtectionSoon(); | 828 dropProtectionSoon(); |
843 | |
844 return !m_loader; | |
845 } | 829 } |
846 | 830 |
847 void XMLHttpRequest::clearResponse() | 831 void XMLHttpRequest::clearResponse() |
848 { | 832 { |
849 m_response = ResourceResponse(); | 833 m_response = ResourceResponse(); |
850 clearResponseBuffers(); | 834 clearResponseBuffers(); |
851 } | 835 } |
852 | 836 |
853 void XMLHttpRequest::clearResponseBuffers() | 837 void XMLHttpRequest::clearResponseBuffers() |
854 { | 838 { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 else | 1179 else |
1196 // Firefox calls readyStateChanged every time it receives data, 4449
442 | 1180 // Firefox calls readyStateChanged every time it receives data, 4449
442 |
1197 callReadyStateChangeListener(); | 1181 callReadyStateChangeListener(); |
1198 } | 1182 } |
1199 } | 1183 } |
1200 | 1184 |
1201 void XMLHttpRequest::didTimeout() | 1185 void XMLHttpRequest::didTimeout() |
1202 { | 1186 { |
1203 // internalAbort() calls dropProtection(), which may release the last refere
nce. | 1187 // internalAbort() calls dropProtection(), which may release the last refere
nce. |
1204 RefPtr<XMLHttpRequest> protect(this); | 1188 RefPtr<XMLHttpRequest> protect(this); |
1205 if (!internalAbort()) | 1189 internalAbort(); |
1206 return; | |
1207 | 1190 |
1208 clearResponse(); | 1191 clearResponse(); |
1209 clearRequest(); | 1192 clearRequest(); |
1210 | 1193 |
1211 m_error = true; | 1194 m_error = true; |
1212 m_exceptionCode = TimeoutError; | 1195 m_exceptionCode = TimeoutError; |
1213 | 1196 |
1214 if (!m_async) { | 1197 if (!m_async) { |
1215 m_state = DONE; | 1198 m_state = DONE; |
1216 m_exceptionCode = TimeoutError; | 1199 m_exceptionCode = TimeoutError; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 { | 1250 { |
1268 return &m_eventTargetData; | 1251 return &m_eventTargetData; |
1269 } | 1252 } |
1270 | 1253 |
1271 EventTargetData* XMLHttpRequest::ensureEventTargetData() | 1254 EventTargetData* XMLHttpRequest::ensureEventTargetData() |
1272 { | 1255 { |
1273 return &m_eventTargetData; | 1256 return &m_eventTargetData; |
1274 } | 1257 } |
1275 | 1258 |
1276 } // namespace WebCore | 1259 } // namespace WebCore |
OLD | NEW |