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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 && !name.startsWith(staticData->m_secHeaderPrefix, false); | 438 && !name.startsWith(staticData->m_secHeaderPrefix, false); |
439 } | 439 } |
440 | 440 |
441 void XMLHttpRequest::open(const String& method, const KURL& url, ExceptionState& es) | 441 void XMLHttpRequest::open(const String& method, const KURL& url, ExceptionState& es) |
442 { | 442 { |
443 open(method, url, true, es); | 443 open(method, url, true, es); |
444 } | 444 } |
445 | 445 |
446 void XMLHttpRequest::open(const String& method, const KURL& url, bool async, Exc eptionState& es) | 446 void XMLHttpRequest::open(const String& method, const KURL& url, bool async, Exc eptionState& es) |
447 { | 447 { |
448 internalAbort(); | 448 internalAbort(DropProtectionSync); |
449 State previousState = m_state; | 449 State previousState = m_state; |
450 m_state = UNSENT; | 450 m_state = UNSENT; |
451 m_error = false; | 451 m_error = false; |
452 m_uploadComplete = false; | 452 m_uploadComplete = false; |
453 | 453 |
454 // clear stuff from possible previous load | 454 // clear stuff from possible previous load |
455 clearResponse(); | 455 clearResponse(); |
456 clearRequest(); | 456 clearRequest(); |
457 | 457 |
458 ASSERT(m_state == UNSENT); | 458 ASSERT(m_state == UNSENT); |
(...skipping 285 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) |
769 m_exceptionCode = NetworkError; | 773 m_exceptionCode = NetworkError; |
770 if (m_exceptionCode) | 774 if (m_exceptionCode) |
771 es.throwDOMException(m_exceptionCode); | 775 es.throwDOMException(m_exceptionCode); |
772 } | 776 } |
773 | 777 |
774 void XMLHttpRequest::abort() | 778 void XMLHttpRequest::abort() |
775 { | 779 { |
776 // internalAbort() calls dropProtection(), which may release the last refere nce. | 780 // internalAbort() calls dropProtection(), which may release the last refere nce. |
777 RefPtr<XMLHttpRequest> protect(this); | 781 RefPtr<XMLHttpRequest> protect(this); |
778 | 782 |
779 bool sendFlag = m_loader; | 783 bool sendFlag = m_loader; |
780 | 784 |
781 internalAbort(); | 785 internalAbort(DropProtectionSync); |
782 | 786 |
783 clearResponseBuffers(); | 787 clearResponseBuffers(); |
784 | 788 |
785 // Clear headers as required by the spec | 789 // Clear headers as required by the spec |
786 m_requestHeaders.clear(); | 790 m_requestHeaders.clear(); |
787 | 791 |
788 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) | 792 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) |
789 m_state = UNSENT; | 793 m_state = UNSENT; |
790 else { | 794 else { |
791 ASSERT(!m_loader); | 795 ASSERT(!m_loader); |
792 changeState(DONE); | 796 changeState(DONE); |
793 m_state = UNSENT; | 797 m_state = UNSENT; |
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; | 810 bool hadLoader = m_loader; |
807 | 811 |
808 m_error = true; | 812 m_error = true; |
809 | 813 |
810 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. | 814 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. |
811 m_receivedLength = 0; | 815 m_receivedLength = 0; |
812 | 816 |
813 if (hadLoader) { | 817 if (hadLoader) { |
814 m_loader->cancel(); | 818 m_loader->cancel(); |
815 m_loader = 0; | 819 m_loader = 0; |
816 } | 820 } |
817 | 821 |
818 m_decoder = 0; | 822 m_decoder = 0; |
819 | 823 |
820 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); | 824 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); |
821 | 825 |
822 if (hadLoader) | 826 if (hadLoader) { |
823 dropProtectionSoon(); | 827 if (async == DropProtectionAsync) |
828 dropProtectionSoon(); | |
829 else | |
830 dropProtection(); | |
831 } | |
824 } | 832 } |
825 | 833 |
826 void XMLHttpRequest::clearResponse() | 834 void XMLHttpRequest::clearResponse() |
827 { | 835 { |
828 m_response = ResourceResponse(); | 836 m_response = ResourceResponse(); |
829 clearResponseBuffers(); | 837 clearResponseBuffers(); |
830 } | 838 } |
831 | 839 |
832 void XMLHttpRequest::clearResponseBuffers() | 840 void XMLHttpRequest::clearResponseBuffers() |
833 { | 841 { |
(...skipping 23 matching lines...) Expand all Loading... | |
857 | 865 |
858 void XMLHttpRequest::networkError() | 866 void XMLHttpRequest::networkError() |
859 { | 867 { |
860 genericError(); | 868 genericError(); |
861 if (!m_uploadComplete) { | 869 if (!m_uploadComplete) { |
862 m_uploadComplete = true; | 870 m_uploadComplete = true; |
863 if (m_upload && m_uploadEventsAllowed) | 871 if (m_upload && m_uploadEventsAllowed) |
864 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().errorEvent)); | 872 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().errorEvent)); |
865 } | 873 } |
866 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().errorEvent)); | 874 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().errorEvent)); |
867 internalAbort(); | 875 internalAbort(DropProtectionSync); |
868 } | 876 } |
869 | 877 |
870 void XMLHttpRequest::abortError() | 878 void XMLHttpRequest::abortError() |
871 { | 879 { |
872 genericError(); | 880 genericError(); |
873 if (!m_uploadComplete) { | 881 if (!m_uploadComplete) { |
874 m_uploadComplete = true; | 882 m_uploadComplete = true; |
875 if (m_upload && m_uploadEventsAllowed) | 883 if (m_upload && m_uploadEventsAllowed) |
876 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); | 884 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); |
877 } | 885 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 else | 1182 else |
1175 // Firefox calls readyStateChanged every time it receives data, 4449 442 | 1183 // Firefox calls readyStateChanged every time it receives data, 4449 442 |
1176 callReadyStateChangeListener(); | 1184 callReadyStateChangeListener(); |
1177 } | 1185 } |
1178 } | 1186 } |
1179 | 1187 |
1180 void XMLHttpRequest::didTimeout() | 1188 void XMLHttpRequest::didTimeout() |
1181 { | 1189 { |
1182 // internalAbort() calls dropProtection(), which may release the last refere nce. | 1190 // internalAbort() calls dropProtection(), which may release the last refere nce. |
1183 RefPtr<XMLHttpRequest> protect(this); | 1191 RefPtr<XMLHttpRequest> protect(this); |
1184 internalAbort(); | 1192 internalAbort(DropProtectionSync); |
1185 | 1193 |
1186 clearResponse(); | 1194 clearResponse(); |
1187 clearRequest(); | 1195 clearRequest(); |
1188 | 1196 |
1189 m_error = true; | 1197 m_error = true; |
1190 m_exceptionCode = TimeoutError; | 1198 m_exceptionCode = TimeoutError; |
1191 | 1199 |
1192 if (!m_async) { | 1200 if (!m_async) { |
1193 m_state = DONE; | 1201 m_state = DONE; |
1194 m_exceptionCode = TimeoutError; | 1202 m_exceptionCode = TimeoutError; |
(...skipping 20 matching lines...) Expand all Loading... | |
1215 m_progressEventThrottle.suspend(); | 1223 m_progressEventThrottle.suspend(); |
1216 } | 1224 } |
1217 | 1225 |
1218 void XMLHttpRequest::resume() | 1226 void XMLHttpRequest::resume() |
1219 { | 1227 { |
1220 m_progressEventThrottle.resume(); | 1228 m_progressEventThrottle.resume(); |
1221 } | 1229 } |
1222 | 1230 |
1223 void XMLHttpRequest::stop() | 1231 void XMLHttpRequest::stop() |
1224 { | 1232 { |
1225 internalAbort(); | 1233 internalAbort(DropProtectionAsync); |
abarth-chromium
2013/08/14 04:11:49
What I would do is make DropProtectionSync the def
kouhei (in TOK)
2013/08/14 04:58:20
Done.
| |
1226 } | 1234 } |
1227 | 1235 |
1228 void XMLHttpRequest::contextDestroyed() | 1236 void XMLHttpRequest::contextDestroyed() |
1229 { | 1237 { |
1230 ASSERT(!m_loader); | 1238 ASSERT(!m_loader); |
1231 ActiveDOMObject::contextDestroyed(); | 1239 ActiveDOMObject::contextDestroyed(); |
1232 } | 1240 } |
1233 | 1241 |
1234 const AtomicString& XMLHttpRequest::interfaceName() const | 1242 const AtomicString& XMLHttpRequest::interfaceName() const |
1235 { | 1243 { |
1236 return eventNames().interfaceForXMLHttpRequest; | 1244 return eventNames().interfaceForXMLHttpRequest; |
1237 } | 1245 } |
1238 | 1246 |
1239 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const | 1247 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const |
1240 { | 1248 { |
1241 return ActiveDOMObject::scriptExecutionContext(); | 1249 return ActiveDOMObject::scriptExecutionContext(); |
1242 } | 1250 } |
1243 | 1251 |
1244 EventTargetData* XMLHttpRequest::eventTargetData() | 1252 EventTargetData* XMLHttpRequest::eventTargetData() |
1245 { | 1253 { |
1246 return &m_eventTargetData; | 1254 return &m_eventTargetData; |
1247 } | 1255 } |
1248 | 1256 |
1249 EventTargetData* XMLHttpRequest::ensureEventTargetData() | 1257 EventTargetData* XMLHttpRequest::ensureEventTargetData() |
1250 { | 1258 { |
1251 return &m_eventTargetData; | 1259 return &m_eventTargetData; |
1252 } | 1260 } |
1253 | 1261 |
1254 } // namespace WebCore | 1262 } // namespace WebCore |
OLD | NEW |