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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 m_error = false; | 756 m_error = false; |
757 | 757 |
758 if (m_async) { | 758 if (m_async) { |
759 if (m_upload) | 759 if (m_upload) |
760 request.setReportUploadProgress(true); | 760 request.setReportUploadProgress(true); |
761 | 761 |
762 // ThreadableLoader::create can return null here, for example if we're n
o longer attached to a page. | 762 // ThreadableLoader::create can return null here, for example if we're n
o longer attached to a page. |
763 // This is true while running onunload handlers. | 763 // This is true while running onunload handlers. |
764 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload
, <http://bugs.webkit.org/show_bug.cgi?id=10904>. | 764 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload
, <http://bugs.webkit.org/show_bug.cgi?id=10904>. |
765 // FIXME: Maybe create() can return null for other reasons too? | 765 // FIXME: Maybe create() can return null for other reasons too? |
| 766 ASSERT(!m_loader); |
766 m_loader = ThreadableLoader::create(scriptExecutionContext(), this, requ
est, options); | 767 m_loader = ThreadableLoader::create(scriptExecutionContext(), this, requ
est, options); |
767 if (m_loader) { | 768 if (m_loader) { |
768 // Neither this object nor the JavaScript wrapper should be deleted
while | 769 // Neither this object nor the JavaScript wrapper should be deleted
while |
769 // a request is in progress because we need to keep the listeners al
ive, | 770 // a request is in progress because we need to keep the listeners al
ive, |
770 // and they are referenced by the JavaScript wrapper. | 771 // and they are referenced by the JavaScript wrapper. |
| 772 |
| 773 // m_loader was null, so there should be no pending activity at this
point. |
| 774 ASSERT(!hasPendingActivity()); |
771 setPendingActivity(this); | 775 setPendingActivity(this); |
772 } | 776 } |
773 } else { | 777 } else { |
774 request.setPriority(ResourceLoadPriorityVeryHigh); | 778 request.setPriority(ResourceLoadPriorityVeryHigh); |
775 InspectorInstrumentation::willLoadXHRSynchronously(scriptExecutionContex
t()); | 779 InspectorInstrumentation::willLoadXHRSynchronously(scriptExecutionContex
t()); |
776 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re
quest, *this, options); | 780 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re
quest, *this, options); |
777 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext
()); | 781 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext
()); |
778 } | 782 } |
779 | 783 |
780 if (!m_exceptionCode && m_error) | 784 if (!m_exceptionCode && m_error) |
(...skipping 25 matching lines...) Expand all Loading... |
806 } | 810 } |
807 | 811 |
808 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().abortEvent)); | 812 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent:
:create(eventNames().abortEvent)); |
809 if (!m_uploadComplete) { | 813 if (!m_uploadComplete) { |
810 m_uploadComplete = true; | 814 m_uploadComplete = true; |
811 if (m_upload && m_uploadEventsAllowed) | 815 if (m_upload && m_uploadEventsAllowed) |
812 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().abortEvent)); | 816 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat
e(eventNames().abortEvent)); |
813 } | 817 } |
814 } | 818 } |
815 | 819 |
816 void XMLHttpRequest::internalAbort() | 820 void XMLHttpRequest::internalAbort(DropProtection async) |
817 { | 821 { |
818 bool hadLoader = m_loader; | |
819 | |
820 m_error = true; | 822 m_error = true; |
821 | 823 |
822 // FIXME: when we add the support for multi-part XHR, we will have to think
be careful with this initialization. | 824 // FIXME: when we add the support for multi-part XHR, we will have to think
be careful with this initialization. |
823 m_receivedLength = 0; | 825 m_receivedLength = 0; |
824 | |
825 if (hadLoader) { | |
826 m_loader->cancel(); | |
827 m_loader = 0; | |
828 } | |
829 | |
830 m_decoder = 0; | 826 m_decoder = 0; |
831 | 827 |
832 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); | 828 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); |
833 | 829 |
834 if (hadLoader) | 830 if (m_loader) { |
835 dropProtectionSoon(); | 831 m_loader->cancel(); |
| 832 m_loader = 0; |
| 833 |
| 834 if (async == DropProtectionAsync) |
| 835 dropProtectionSoon(); |
| 836 else |
| 837 dropProtection(); |
| 838 } |
836 } | 839 } |
837 | 840 |
838 void XMLHttpRequest::clearResponse() | 841 void XMLHttpRequest::clearResponse() |
839 { | 842 { |
840 m_response = ResourceResponse(); | 843 m_response = ResourceResponse(); |
841 clearResponseBuffers(); | 844 clearResponseBuffers(); |
842 } | 845 } |
843 | 846 |
844 void XMLHttpRequest::clearResponseBuffers() | 847 void XMLHttpRequest::clearResponseBuffers() |
845 { | 848 { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 return; | 1093 return; |
1091 | 1094 |
1092 if (m_state < HEADERS_RECEIVED) | 1095 if (m_state < HEADERS_RECEIVED) |
1093 changeState(HEADERS_RECEIVED); | 1096 changeState(HEADERS_RECEIVED); |
1094 | 1097 |
1095 if (m_decoder) | 1098 if (m_decoder) |
1096 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); | 1099 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); |
1097 | 1100 |
1098 InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this
, identifier, m_responseText, m_url, m_lastSendURL, m_lastSendLineNumber); | 1101 InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this
, identifier, m_responseText, m_url, m_lastSendURL, m_lastSendLineNumber); |
1099 | 1102 |
1100 bool hadLoader = m_loader; | 1103 // Prevent dropProtection releasing the last reference, and retain |this| un
til the end of this method. |
1101 m_loader = 0; | 1104 RefPtr<XMLHttpRequest> protect(this); |
| 1105 |
| 1106 if (m_loader) { |
| 1107 m_loader = 0; |
| 1108 dropProtection(); |
| 1109 } |
1102 | 1110 |
1103 changeState(DONE); | 1111 changeState(DONE); |
1104 m_responseEncoding = String(); | 1112 m_responseEncoding = String(); |
1105 m_decoder = 0; | 1113 m_decoder = 0; |
1106 | |
1107 if (hadLoader) | |
1108 dropProtection(); | |
1109 } | 1114 } |
1110 | 1115 |
1111 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
g totalBytesToBeSent) | 1116 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
g totalBytesToBeSent) |
1112 { | 1117 { |
1113 if (!m_upload) | 1118 if (!m_upload) |
1114 return; | 1119 return; |
1115 | 1120 |
1116 if (m_uploadEventsAllowed) | 1121 if (m_uploadEventsAllowed) |
1117 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames()
.progressEvent, true, bytesSent, totalBytesToBeSent)); | 1122 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames()
.progressEvent, true, bytesSent, totalBytesToBeSent)); |
1118 | 1123 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 m_progressEventThrottle.suspend(); | 1239 m_progressEventThrottle.suspend(); |
1235 } | 1240 } |
1236 | 1241 |
1237 void XMLHttpRequest::resume() | 1242 void XMLHttpRequest::resume() |
1238 { | 1243 { |
1239 m_progressEventThrottle.resume(); | 1244 m_progressEventThrottle.resume(); |
1240 } | 1245 } |
1241 | 1246 |
1242 void XMLHttpRequest::stop() | 1247 void XMLHttpRequest::stop() |
1243 { | 1248 { |
1244 internalAbort(); | 1249 internalAbort(DropProtectionAsync); |
1245 } | 1250 } |
1246 | 1251 |
1247 void XMLHttpRequest::contextDestroyed() | 1252 void XMLHttpRequest::contextDestroyed() |
1248 { | 1253 { |
1249 ASSERT(!m_loader); | 1254 ASSERT(!m_loader); |
1250 ActiveDOMObject::contextDestroyed(); | 1255 ActiveDOMObject::contextDestroyed(); |
1251 } | 1256 } |
1252 | 1257 |
1253 const AtomicString& XMLHttpRequest::interfaceName() const | 1258 const AtomicString& XMLHttpRequest::interfaceName() const |
1254 { | 1259 { |
1255 return eventNames().interfaceForXMLHttpRequest; | 1260 return eventNames().interfaceForXMLHttpRequest; |
1256 } | 1261 } |
1257 | 1262 |
1258 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const | 1263 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const |
1259 { | 1264 { |
1260 return ActiveDOMObject::scriptExecutionContext(); | 1265 return ActiveDOMObject::scriptExecutionContext(); |
1261 } | 1266 } |
1262 | 1267 |
1263 } // namespace WebCore | 1268 } // namespace WebCore |
OLD | NEW |