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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 m_error = false; | 744 m_error = false; |
745 | 745 |
746 if (m_async) { | 746 if (m_async) { |
747 if (m_upload) | 747 if (m_upload) |
748 request.setReportUploadProgress(true); | 748 request.setReportUploadProgress(true); |
749 | 749 |
750 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page. | 750 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page. |
751 // This is true while running onunload handlers. | 751 // This is true while running onunload handlers. |
752 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload , <http://bugs.webkit.org/show_bug.cgi?id=10904>. | 752 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload , <http://bugs.webkit.org/show_bug.cgi?id=10904>. |
753 // FIXME: Maybe create() can return null for other reasons too? | 753 // FIXME: Maybe create() can return null for other reasons too? |
754 ASSERT(!m_loader); | |
754 m_loader = ThreadableLoader::create(scriptExecutionContext(), this, requ est, options); | 755 m_loader = ThreadableLoader::create(scriptExecutionContext(), this, requ est, options); |
755 if (m_loader) { | 756 if (m_loader) { |
756 // Neither this object nor the JavaScript wrapper should be deleted while | 757 // Neither this object nor the JavaScript wrapper should be deleted while |
757 // a request is in progress because we need to keep the listeners al ive, | 758 // a request is in progress because we need to keep the listeners al ive, |
758 // and they are referenced by the JavaScript wrapper. | 759 // and they are referenced by the JavaScript wrapper. |
760 | |
761 // m_loader was null, so there should be no pending activity at this point. | |
762 ASSERT(!hasPendingActivity()); | |
759 setPendingActivity(this); | 763 setPendingActivity(this); |
760 } | 764 } |
761 } else { | 765 } else { |
762 request.setPriority(ResourceLoadPriorityVeryHigh); | 766 request.setPriority(ResourceLoadPriorityVeryHigh); |
763 InspectorInstrumentation::willLoadXHRSynchronously(scriptExecutionContex t()); | 767 InspectorInstrumentation::willLoadXHRSynchronously(scriptExecutionContex t()); |
764 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re quest, *this, options); | 768 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re quest, *this, options); |
765 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext ()); | 769 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext ()); |
766 } | 770 } |
767 | 771 |
768 if (!m_exceptionCode && m_error) | 772 if (!m_exceptionCode && m_error) |
(...skipping 25 matching lines...) Expand all Loading... | |
794 } | 798 } |
795 | 799 |
796 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().abortEvent)); | 800 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().abortEvent)); |
797 if (!m_uploadComplete) { | 801 if (!m_uploadComplete) { |
798 m_uploadComplete = true; | 802 m_uploadComplete = true; |
799 if (m_upload && m_uploadEventsAllowed) | 803 if (m_upload && m_uploadEventsAllowed) |
800 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); | 804 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); |
801 } | 805 } |
802 } | 806 } |
803 | 807 |
804 void XMLHttpRequest::internalAbort() | 808 void XMLHttpRequest::internalAbort(DropProtection async) |
805 { | 809 { |
806 bool hadLoader = m_loader; | |
807 | |
808 m_error = true; | 810 m_error = true; |
809 | 811 |
810 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. | 812 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. |
811 m_receivedLength = 0; | 813 m_receivedLength = 0; |
812 | |
813 if (hadLoader) { | |
814 m_loader->cancel(); | |
815 m_loader = 0; | |
816 } | |
817 | |
818 m_decoder = 0; | 814 m_decoder = 0; |
819 | 815 |
820 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); | 816 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); |
821 | 817 |
822 if (hadLoader) | 818 if (m_loader) { |
823 dropProtectionSoon(); | 819 m_loader->cancel(); |
820 m_loader = 0; | |
821 | |
822 if (async == DropProtectionAsync) | |
823 dropProtectionSoon(); | |
824 else | |
825 dropProtection(); | |
826 } | |
824 } | 827 } |
825 | 828 |
826 void XMLHttpRequest::clearResponse() | 829 void XMLHttpRequest::clearResponse() |
827 { | 830 { |
828 m_response = ResourceResponse(); | 831 m_response = ResourceResponse(); |
829 clearResponseBuffers(); | 832 clearResponseBuffers(); |
830 } | 833 } |
831 | 834 |
832 void XMLHttpRequest::clearResponseBuffers() | 835 void XMLHttpRequest::clearResponseBuffers() |
833 { | 836 { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 return; | 1076 return; |
1074 | 1077 |
1075 if (m_state < HEADERS_RECEIVED) | 1078 if (m_state < HEADERS_RECEIVED) |
1076 changeState(HEADERS_RECEIVED); | 1079 changeState(HEADERS_RECEIVED); |
1077 | 1080 |
1078 if (m_decoder) | 1081 if (m_decoder) |
1079 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); | 1082 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); |
1080 | 1083 |
1081 InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this , identifier, m_responseText, m_url, m_lastSendURL, m_lastSendLineNumber); | 1084 InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this , identifier, m_responseText, m_url, m_lastSendURL, m_lastSendLineNumber); |
1082 | 1085 |
1083 bool hadLoader = m_loader; | 1086 RefPtr<XMLHttpRequest> protect; |
1084 m_loader = 0; | 1087 if (m_loader) { |
1088 m_loader = 0; | |
1089 | |
1090 // Prevent dropProtection releasing the last reference, and retain |this | until the end of this method. | |
1091 protect = this; | |
abarth-chromium
2013/08/19 17:53:17
I probably would have just done this unconditional
kouhei (in TOK)
2013/08/19 23:44:59
Done.
| |
1092 dropProtection(); | |
1093 } | |
1085 | 1094 |
1086 changeState(DONE); | 1095 changeState(DONE); |
1087 m_responseEncoding = String(); | 1096 m_responseEncoding = String(); |
1088 m_decoder = 0; | 1097 m_decoder = 0; |
1089 | |
1090 if (hadLoader) | |
1091 dropProtection(); | |
1092 } | 1098 } |
1093 | 1099 |
1094 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) | 1100 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) |
1095 { | 1101 { |
1096 if (!m_upload) | 1102 if (!m_upload) |
1097 return; | 1103 return; |
1098 | 1104 |
1099 if (m_uploadEventsAllowed) | 1105 if (m_uploadEventsAllowed) |
1100 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames() .progressEvent, true, bytesSent, totalBytesToBeSent)); | 1106 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames() .progressEvent, true, bytesSent, totalBytesToBeSent)); |
1101 | 1107 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1215 m_progressEventThrottle.suspend(); | 1221 m_progressEventThrottle.suspend(); |
1216 } | 1222 } |
1217 | 1223 |
1218 void XMLHttpRequest::resume() | 1224 void XMLHttpRequest::resume() |
1219 { | 1225 { |
1220 m_progressEventThrottle.resume(); | 1226 m_progressEventThrottle.resume(); |
1221 } | 1227 } |
1222 | 1228 |
1223 void XMLHttpRequest::stop() | 1229 void XMLHttpRequest::stop() |
1224 { | 1230 { |
1225 internalAbort(); | 1231 internalAbort(DropProtectionAsync); |
1226 } | 1232 } |
1227 | 1233 |
1228 void XMLHttpRequest::contextDestroyed() | 1234 void XMLHttpRequest::contextDestroyed() |
1229 { | 1235 { |
1230 ASSERT(!m_loader); | 1236 ASSERT(!m_loader); |
1231 ActiveDOMObject::contextDestroyed(); | 1237 ActiveDOMObject::contextDestroyed(); |
1232 } | 1238 } |
1233 | 1239 |
1234 const AtomicString& XMLHttpRequest::interfaceName() const | 1240 const AtomicString& XMLHttpRequest::interfaceName() const |
1235 { | 1241 { |
1236 return eventNames().interfaceForXMLHttpRequest; | 1242 return eventNames().interfaceForXMLHttpRequest; |
1237 } | 1243 } |
1238 | 1244 |
1239 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const | 1245 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const |
1240 { | 1246 { |
1241 return ActiveDOMObject::scriptExecutionContext(); | 1247 return ActiveDOMObject::scriptExecutionContext(); |
1242 } | 1248 } |
1243 | 1249 |
1244 EventTargetData* XMLHttpRequest::eventTargetData() | 1250 EventTargetData* XMLHttpRequest::eventTargetData() |
1245 { | 1251 { |
1246 return &m_eventTargetData; | 1252 return &m_eventTargetData; |
1247 } | 1253 } |
1248 | 1254 |
1249 EventTargetData* XMLHttpRequest::ensureEventTargetData() | 1255 EventTargetData* XMLHttpRequest::ensureEventTargetData() |
1250 { | 1256 { |
1251 return &m_eventTargetData; | 1257 return &m_eventTargetData; |
1252 } | 1258 } |
1253 | 1259 |
1254 } // namespace WebCore | 1260 } // namespace WebCore |
OLD | NEW |