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(false); |
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 m_loader = ThreadableLoader::create(scriptExecutionContext(), this, requ est, options); | 754 m_loader = ThreadableLoader::create(scriptExecutionContext(), this, requ est, options); |
755 if (m_loader) { | 755 if (m_loader) { |
756 // Neither this object nor the JavaScript wrapper should be deleted while | 756 // 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, | 757 // a request is in progress because we need to keep the listeners al ive, |
758 // and they are referenced by the JavaScript wrapper. | 758 // and they are referenced by the JavaScript wrapper. |
759 ASSERT(!hasPendingActivity()); | |
haraken
2013/08/14 02:35:07
Would you add a comment on this line?
kouhei (in TOK)
2013/08/14 03:19:30
Done.
| |
759 setPendingActivity(this); | 760 setPendingActivity(this); |
760 } | 761 } |
761 } else { | 762 } else { |
762 request.setPriority(ResourceLoadPriorityVeryHigh); | 763 request.setPriority(ResourceLoadPriorityVeryHigh); |
763 InspectorInstrumentation::willLoadXHRSynchronously(scriptExecutionContex t()); | 764 InspectorInstrumentation::willLoadXHRSynchronously(scriptExecutionContex t()); |
764 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re quest, *this, options); | 765 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re quest, *this, options); |
765 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext ()); | 766 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext ()); |
766 } | 767 } |
767 | 768 |
768 if (!m_exceptionCode && m_error) | 769 if (!m_exceptionCode && m_error) |
769 m_exceptionCode = NetworkError; | 770 m_exceptionCode = NetworkError; |
770 if (m_exceptionCode) | 771 if (m_exceptionCode) |
771 es.throwDOMException(m_exceptionCode); | 772 es.throwDOMException(m_exceptionCode); |
772 } | 773 } |
773 | 774 |
774 void XMLHttpRequest::abort() | 775 void XMLHttpRequest::abort() |
775 { | 776 { |
776 // internalAbort() calls dropProtection(), which may release the last refere nce. | 777 // internalAbort() calls dropProtection(), which may release the last refere nce. |
777 RefPtr<XMLHttpRequest> protect(this); | 778 RefPtr<XMLHttpRequest> protect(this); |
778 | 779 |
779 bool sendFlag = m_loader; | 780 bool sendFlag = m_loader; |
780 | 781 |
781 internalAbort(); | 782 internalAbort(false); |
782 | 783 |
783 clearResponseBuffers(); | 784 clearResponseBuffers(); |
784 | 785 |
785 // Clear headers as required by the spec | 786 // Clear headers as required by the spec |
786 m_requestHeaders.clear(); | 787 m_requestHeaders.clear(); |
787 | 788 |
788 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) | 789 if ((m_state <= OPENED && !sendFlag) || m_state == DONE) |
789 m_state = UNSENT; | 790 m_state = UNSENT; |
790 else { | 791 else { |
791 ASSERT(!m_loader); | 792 ASSERT(!m_loader); |
792 changeState(DONE); | 793 changeState(DONE); |
793 m_state = UNSENT; | 794 m_state = UNSENT; |
794 } | 795 } |
795 | 796 |
796 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().abortEvent)); | 797 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().abortEvent)); |
797 if (!m_uploadComplete) { | 798 if (!m_uploadComplete) { |
798 m_uploadComplete = true; | 799 m_uploadComplete = true; |
799 if (m_upload && m_uploadEventsAllowed) | 800 if (m_upload && m_uploadEventsAllowed) |
800 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); | 801 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); |
801 } | 802 } |
802 } | 803 } |
803 | 804 |
804 void XMLHttpRequest::internalAbort() | 805 void XMLHttpRequest::internalAbort(bool dropProtectionAsync) |
haraken
2013/08/14 02:35:07
Instead of bool, could you use a more descriptive
kouhei (in TOK)
2013/08/14 03:19:30
Done.
| |
805 { | 806 { |
806 bool hadLoader = m_loader; | 807 bool hadLoader = m_loader; |
807 | 808 |
808 m_error = true; | 809 m_error = true; |
809 | 810 |
810 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. | 811 // FIXME: when we add the support for multi-part XHR, we will have to think be careful with this initialization. |
811 m_receivedLength = 0; | 812 m_receivedLength = 0; |
812 | 813 |
813 if (hadLoader) { | 814 if (hadLoader) { |
814 m_loader->cancel(); | 815 m_loader->cancel(); |
815 m_loader = 0; | 816 m_loader = 0; |
816 } | 817 } |
817 | 818 |
818 m_decoder = 0; | 819 m_decoder = 0; |
819 | 820 |
820 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); | 821 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); |
821 | 822 |
822 if (hadLoader) | 823 if (hadLoader) { |
823 dropProtectionSoon(); | 824 if (dropProtectionAsync) |
825 dropProtectionSoon(); | |
826 else | |
827 dropProtection(); | |
828 } | |
824 } | 829 } |
825 | 830 |
826 void XMLHttpRequest::clearResponse() | 831 void XMLHttpRequest::clearResponse() |
827 { | 832 { |
828 m_response = ResourceResponse(); | 833 m_response = ResourceResponse(); |
829 clearResponseBuffers(); | 834 clearResponseBuffers(); |
830 } | 835 } |
831 | 836 |
832 void XMLHttpRequest::clearResponseBuffers() | 837 void XMLHttpRequest::clearResponseBuffers() |
833 { | 838 { |
(...skipping 23 matching lines...) Expand all Loading... | |
857 | 862 |
858 void XMLHttpRequest::networkError() | 863 void XMLHttpRequest::networkError() |
859 { | 864 { |
860 genericError(); | 865 genericError(); |
861 if (!m_uploadComplete) { | 866 if (!m_uploadComplete) { |
862 m_uploadComplete = true; | 867 m_uploadComplete = true; |
863 if (m_upload && m_uploadEventsAllowed) | 868 if (m_upload && m_uploadEventsAllowed) |
864 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().errorEvent)); | 869 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().errorEvent)); |
865 } | 870 } |
866 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().errorEvent)); | 871 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().errorEvent)); |
867 internalAbort(); | 872 internalAbort(false); |
868 } | 873 } |
869 | 874 |
870 void XMLHttpRequest::abortError() | 875 void XMLHttpRequest::abortError() |
871 { | 876 { |
872 genericError(); | 877 genericError(); |
873 if (!m_uploadComplete) { | 878 if (!m_uploadComplete) { |
874 m_uploadComplete = true; | 879 m_uploadComplete = true; |
875 if (m_upload && m_uploadEventsAllowed) | 880 if (m_upload && m_uploadEventsAllowed) |
876 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); | 881 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().abortEvent)); |
877 } | 882 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 else | 1179 else |
1175 // Firefox calls readyStateChanged every time it receives data, 4449 442 | 1180 // Firefox calls readyStateChanged every time it receives data, 4449 442 |
1176 callReadyStateChangeListener(); | 1181 callReadyStateChangeListener(); |
1177 } | 1182 } |
1178 } | 1183 } |
1179 | 1184 |
1180 void XMLHttpRequest::didTimeout() | 1185 void XMLHttpRequest::didTimeout() |
1181 { | 1186 { |
1182 // internalAbort() calls dropProtection(), which may release the last refere nce. | 1187 // internalAbort() calls dropProtection(), which may release the last refere nce. |
1183 RefPtr<XMLHttpRequest> protect(this); | 1188 RefPtr<XMLHttpRequest> protect(this); |
1184 internalAbort(); | 1189 internalAbort(false); |
1185 | 1190 |
1186 clearResponse(); | 1191 clearResponse(); |
1187 clearRequest(); | 1192 clearRequest(); |
1188 | 1193 |
1189 m_error = true; | 1194 m_error = true; |
1190 m_exceptionCode = TimeoutError; | 1195 m_exceptionCode = TimeoutError; |
1191 | 1196 |
1192 if (!m_async) { | 1197 if (!m_async) { |
1193 m_state = DONE; | 1198 m_state = DONE; |
1194 m_exceptionCode = TimeoutError; | 1199 m_exceptionCode = TimeoutError; |
(...skipping 20 matching lines...) Expand all Loading... | |
1215 m_progressEventThrottle.suspend(); | 1220 m_progressEventThrottle.suspend(); |
1216 } | 1221 } |
1217 | 1222 |
1218 void XMLHttpRequest::resume() | 1223 void XMLHttpRequest::resume() |
1219 { | 1224 { |
1220 m_progressEventThrottle.resume(); | 1225 m_progressEventThrottle.resume(); |
1221 } | 1226 } |
1222 | 1227 |
1223 void XMLHttpRequest::stop() | 1228 void XMLHttpRequest::stop() |
1224 { | 1229 { |
1225 internalAbort(); | 1230 internalAbort(true); |
1226 } | 1231 } |
1227 | 1232 |
1228 void XMLHttpRequest::contextDestroyed() | 1233 void XMLHttpRequest::contextDestroyed() |
1229 { | 1234 { |
1230 ASSERT(!m_loader); | 1235 ASSERT(!m_loader); |
1231 ActiveDOMObject::contextDestroyed(); | 1236 ActiveDOMObject::contextDestroyed(); |
1232 } | 1237 } |
1233 | 1238 |
1234 const AtomicString& XMLHttpRequest::interfaceName() const | 1239 const AtomicString& XMLHttpRequest::interfaceName() const |
1235 { | 1240 { |
1236 return eventNames().interfaceForXMLHttpRequest; | 1241 return eventNames().interfaceForXMLHttpRequest; |
1237 } | 1242 } |
1238 | 1243 |
1239 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const | 1244 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const |
1240 { | 1245 { |
1241 return ActiveDOMObject::scriptExecutionContext(); | 1246 return ActiveDOMObject::scriptExecutionContext(); |
1242 } | 1247 } |
1243 | 1248 |
1244 EventTargetData* XMLHttpRequest::eventTargetData() | 1249 EventTargetData* XMLHttpRequest::eventTargetData() |
1245 { | 1250 { |
1246 return &m_eventTargetData; | 1251 return &m_eventTargetData; |
1247 } | 1252 } |
1248 | 1253 |
1249 EventTargetData* XMLHttpRequest::ensureEventTargetData() | 1254 EventTargetData* XMLHttpRequest::ensureEventTargetData() |
1250 { | 1255 { |
1251 return &m_eventTargetData; | 1256 return &m_eventTargetData; |
1252 } | 1257 } |
1253 | 1258 |
1254 } // namespace WebCore | 1259 } // namespace WebCore |
OLD | NEW |