Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 26114005: Revert 159087 "Revert 159004 "Merge 158146 "[XHR] Abort method e..." (Closed) Base URL: svn://svn.chromium.org/blink/branches/chromium/1599/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 internalAbort(); 453 if (!internalAbort())
454 return;
455
454 State previousState = m_state; 456 State previousState = m_state;
455 m_state = UNSENT; 457 m_state = UNSENT;
456 m_error = false; 458 m_error = false;
457 m_uploadComplete = false; 459 m_uploadComplete = false;
458 460
459 // clear stuff from possible previous load 461 // clear stuff from possible previous load
460 clearResponse(); 462 clearResponse();
461 clearRequest(); 463 clearRequest();
462 464
463 ASSERT(m_state == UNSENT); 465 ASSERT(m_state == UNSENT);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 es.throwDOMException(m_exceptionCode); 778 es.throwDOMException(m_exceptionCode);
777 } 779 }
778 780
779 void XMLHttpRequest::abort() 781 void XMLHttpRequest::abort()
780 { 782 {
781 // internalAbort() calls dropProtection(), which may release the last refere nce. 783 // internalAbort() calls dropProtection(), which may release the last refere nce.
782 RefPtr<XMLHttpRequest> protect(this); 784 RefPtr<XMLHttpRequest> protect(this);
783 785
784 bool sendFlag = m_loader; 786 bool sendFlag = m_loader;
785 787
786 internalAbort(); 788 if (!internalAbort())
789 return;
787 790
788 clearResponseBuffers(); 791 clearResponseBuffers();
789 792
790 // Clear headers as required by the spec 793 // Clear headers as required by the spec
791 m_requestHeaders.clear(); 794 m_requestHeaders.clear();
792 795
793 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) 796 if ((m_state <= OPENED && !sendFlag) || m_state == DONE)
794 m_state = UNSENT; 797 m_state = UNSENT;
795 else { 798 else {
796 ASSERT(!m_loader); 799 ASSERT(!m_loader);
797 changeState(DONE); 800 changeState(DONE);
798 m_state = UNSENT; 801 m_state = UNSENT;
799 } 802 }
800 803
801 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().abortEvent)); 804 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().abortEvent));
802 if (!m_uploadComplete) { 805 if (!m_uploadComplete) {
803 m_uploadComplete = true; 806 m_uploadComplete = true;
804 if (m_upload && m_uploadEventsAllowed) 807 if (m_upload && m_uploadEventsAllowed)
805 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); 808 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent));
806 } 809 }
807 } 810 }
808 811
809 void XMLHttpRequest::internalAbort() 812 bool XMLHttpRequest::internalAbort()
810 { 813 {
811 bool hadLoader = m_loader; 814 bool hadLoader = m_loader;
812 815
813 m_error = true; 816 m_error = true;
814 817
815 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. 818 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization.
816 m_receivedLength = 0; 819 m_receivedLength = 0;
817 820
818 if (hadLoader) { 821 if (hadLoader) {
819 m_loader->cancel(); 822 // Cancelling the ThreadableLoader m_loader may result in calling
820 m_loader = 0; 823 // window.onload synchronously. If such an onload handler contains
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();
821 } 835 }
822 836
823 m_decoder = 0; 837 m_decoder = 0;
824 838
825 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); 839 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this);
826 840
827 if (hadLoader) 841 if (hadLoader)
828 dropProtectionSoon(); 842 dropProtectionSoon();
843
844 return !m_loader;
829 } 845 }
830 846
831 void XMLHttpRequest::clearResponse() 847 void XMLHttpRequest::clearResponse()
832 { 848 {
833 m_response = ResourceResponse(); 849 m_response = ResourceResponse();
834 clearResponseBuffers(); 850 clearResponseBuffers();
835 } 851 }
836 852
837 void XMLHttpRequest::clearResponseBuffers() 853 void XMLHttpRequest::clearResponseBuffers()
838 { 854 {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 else 1195 else
1180 // Firefox calls readyStateChanged every time it receives data, 4449 442 1196 // Firefox calls readyStateChanged every time it receives data, 4449 442
1181 callReadyStateChangeListener(); 1197 callReadyStateChangeListener();
1182 } 1198 }
1183 } 1199 }
1184 1200
1185 void XMLHttpRequest::didTimeout() 1201 void XMLHttpRequest::didTimeout()
1186 { 1202 {
1187 // internalAbort() calls dropProtection(), which may release the last refere nce. 1203 // internalAbort() calls dropProtection(), which may release the last refere nce.
1188 RefPtr<XMLHttpRequest> protect(this); 1204 RefPtr<XMLHttpRequest> protect(this);
1189 internalAbort(); 1205 if (!internalAbort())
1206 return;
1190 1207
1191 clearResponse(); 1208 clearResponse();
1192 clearRequest(); 1209 clearRequest();
1193 1210
1194 m_error = true; 1211 m_error = true;
1195 m_exceptionCode = TimeoutError; 1212 m_exceptionCode = TimeoutError;
1196 1213
1197 if (!m_async) { 1214 if (!m_async) {
1198 m_state = DONE; 1215 m_state = DONE;
1199 m_exceptionCode = TimeoutError; 1216 m_exceptionCode = TimeoutError;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 { 1267 {
1251 return &m_eventTargetData; 1268 return &m_eventTargetData;
1252 } 1269 }
1253 1270
1254 EventTargetData* XMLHttpRequest::ensureEventTargetData() 1271 EventTargetData* XMLHttpRequest::ensureEventTargetData()
1255 { 1272 {
1256 return &m_eventTargetData; 1273 return &m_eventTargetData;
1257 } 1274 }
1258 1275
1259 } // namespace WebCore 1276 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698