Changeset 161668 in webkit
- Timestamp:
- Jan 10, 2014 1:22:18 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r161666 r161668 1 2014-01-10 Youenn Fablet <youennf@gmail.com> 2 3 Correctly set XHR loadend event attributes (loaded and total). 4 https://bugs.webkit.org/show_bug.cgi?id=120828 5 6 Reviewed by Alexey Proskuryakov. 7 8 Tests for abort, load, loadstart and loadend ProgressEvent events for XMLHttpRequest and XMLHttpRequestUpload 9 10 * fast/xmlhttprequest/xmlhttprequest-get-expected.txt: Changed to correct event values 11 * http/tests/xmlhttprequest/loadstart-event-init-expected.txt: Added. 12 * http/tests/xmlhttprequest/loadstart-event-init.html: Added. 13 * http/tests/xmlhttprequest/onabort-progressevent-attributes-expected.txt: Added. 14 * http/tests/xmlhttprequest/onabort-progressevent-attributes.html: Added. 15 * http/tests/xmlhttprequest/onload-progressevent-attributes-expected.txt: Added. 16 * http/tests/xmlhttprequest/onload-progressevent-attributes.html: Added. 17 * http/tests/xmlhttprequest/upload-onabort-progressevent-attributes-expected.txt: Added. 18 * http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html: Added. 19 * http/tests/xmlhttprequest/upload-onload-progressevent-attributes-expected.txt: Added. 20 * http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html: Added. 21 1 22 2014-01-10 Mario Sanchez Prada <mario.prada@samsung.com> 2 23 -
trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt
r161541 r161668 54 54 [native code] 55 55 }' 56 lengthComputable : ' false'57 loaded : ' 0'58 position : ' 0'56 lengthComputable : 'true' 57 loaded : '174' 58 position : '174' 59 59 preventDefault : 'function preventDefault() { 60 60 [native code] … … 69 69 }' 70 70 target : '[object XMLHttpRequest]' 71 total : ' 0'72 totalSize : ' 0'71 total : '174' 72 totalSize : '174' 73 73 type : 'load' 74 74 -
trunk/Source/WebCore/ChangeLog
r161667 r161668 1 2014-01-10 Youenn Fablet <youennf@gmail.com> 2 3 4 Correctly set XHR loadend attributes (loaded and total). 5 https://bugs.webkit.org/show_bug.cgi?id=120828 6 7 Reviewed by Alexey Proskuryakov. 8 9 Added correct initialization of lengthComputable, loaded and total attributes 10 to XHR ProgressEvent events (load, loadstart, loadend, abort, error and timeout). 11 12 XMLHttpRequestProgressEventThrottle and XMLHttpRequestUpload now keep persistent knowledge 13 of m_loaded and m_total values with this patch. 14 15 Code refactoring to handle event dispatching in case of error in a single manner. 16 XMLHttpRequestProgressEventThrottle::dispatchProgressEvent is renamed as dispatchThrottledProgressEvent 17 XMLHttpRequestProgressEventThrottle::dispatchEventAndLoadend is replaced by dispatchProgressEvent(const AtomicString&) 18 19 Fixed assertion issues over bug 120828 patch 20 21 Tests: http/tests/xmlhttprequest/loadstart-event-init.html 22 http/tests/xmlhttprequest/onabort-progressevent-attributes.html 23 http/tests/xmlhttprequest/onload-progressevent-attributes.html 24 http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html 25 http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html 26 27 * xml/XMLHttpRequest.cpp: 28 (WebCore::XMLHttpRequest::callReadyStateChangeListener): changed readystatechange event from ProgressEvent to Event (not cancellable, not bubblable) to better match the spec 29 (WebCore::XMLHttpRequest::createRequest): 30 (WebCore::XMLHttpRequest::abort): code refactoring to handle error event dispatching in a single way 31 (WebCore::XMLHttpRequest::networkError): code refactoring to handle error event dispatching in a single way 32 (WebCore::XMLHttpRequest::abortError): code refactoring to handle error event dispatching in a single way 33 (WebCore::XMLHttpRequest::didSendData): 34 (WebCore::XMLHttpRequest::didReceiveData): 35 (WebCore::XMLHttpRequest::dispatchErrorEvents): dispatch progress events in case of error 36 (WebCore::XMLHttpRequest::didTimeout): code refactoring to handle error event dispatching in a single way 37 * xml/XMLHttpRequest.h: 38 * xml/XMLHttpRequestProgressEventThrottle.cpp: before the patch, the fact that a progress event is being throttled is stored indirectly (m_loaded or m_total not equal to zero). With the patch, this information is stored in m_hasThrottledProgressEvent. The m_loaded and m_total values are no longer set back to zero after a progress event is dispatched. This allows using these values to correctly initialize other ProgressEvent events (in particular loadend, abort, timeout...) 39 (WebCore::XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle): 40 (WebCore::XMLHttpRequestProgressEventThrottle::dispatchThrottledProgressEvent): always update the new m_loaded and m_total values. If progress event is not sent as part of the function call, store the fact that a progress event is being throttled through m_hasThrottledProgressEvent. 41 (WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent): used to send any ProgressEvent event that is not be throttled 42 (WebCore::XMLHttpRequestProgressEventThrottle::flushProgressEvent): after the call, no progress event is throttled anymore 43 (WebCore::XMLHttpRequestProgressEventThrottle::fired): after the call, no progress event is throttled anymore 44 (WebCore::XMLHttpRequestProgressEventThrottle::hasEventToDispatch): 45 (WebCore::XMLHttpRequestProgressEventThrottle::suspend): 46 * xml/XMLHttpRequestProgressEventThrottle.h: introduced m_hasThrottledProgressEvent which stores whether a progress event is being throttled and m_computableLength which is used to initialize ProgressEvent computableLength 47 * xml/XMLHttpRequestUpload.cpp: 48 (WebCore::XMLHttpRequestUpload::XMLHttpRequestUpload): 49 (WebCore::XMLHttpRequestUpload::dispatchProgressEvent): 50 * xml/XMLHttpRequestUpload.h: introduced m_loaded, m_total and m_lengthComputable, similarly to XMLHttpRequestProgressEventThrottle 51 1 52 2014-01-10 Bear Travis <betravis@adobe.com> 2 53 -
trunk/Source/WebCore/xml/XMLHttpRequest.cpp
r161662 r161668 431 431 432 432 if (m_async || (m_state <= OPENED || m_state == DONE)) 433 m_progressEventThrottle.dispatchReadyStateChangeEvent( XMLHttpRequestProgressEvent::create(eventNames().readystatechangeEvent), m_state == DONE ? FlushProgressEvent : DoNotFlushProgressEvent);433 m_progressEventThrottle.dispatchReadyStateChangeEvent(Event::create(eventNames().readystatechangeEvent, false, false), m_state == DONE ? FlushProgressEvent : DoNotFlushProgressEvent); 434 434 435 435 InspectorInstrumentation::didDispatchXHRReadyStateChangeEvent(cookie); 436 436 if (m_state == DONE && !m_error) { 437 437 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchXHRLoadEvent(scriptExecutionContext(), this); 438 m_progressEventThrottle.dispatch Event(XMLHttpRequestProgressEvent::create(eventNames().loadEvent));438 m_progressEventThrottle.dispatchProgressEvent(eventNames().loadEvent); 439 439 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie); 440 m_progressEventThrottle.dispatch Event(XMLHttpRequestProgressEvent::create(eventNames().loadendEvent));440 m_progressEventThrottle.dispatchProgressEvent(eventNames().loadendEvent); 441 441 } 442 442 } … … 766 766 bool uploadEvents = false; 767 767 if (m_async) { 768 m_progressEventThrottle.dispatch Event(XMLHttpRequestProgressEvent::create(eventNames().loadstartEvent));768 m_progressEventThrottle.dispatchProgressEvent(eventNames().loadstartEvent); 769 769 if (m_requestEntityBody && m_upload) { 770 770 uploadEvents = m_upload->hasEventListeners(); 771 m_upload->dispatch Event(XMLHttpRequestProgressEvent::create(eventNames().loadstartEvent));771 m_upload->dispatchProgressEvent(eventNames().loadstartEvent); 772 772 } 773 773 } … … 860 860 } 861 861 862 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 863 if (!m_uploadComplete) { 864 m_uploadComplete = true; 865 if (m_upload && m_uploadEventsAllowed) 866 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 867 } 862 dispatchErrorEvents(eventNames().abortEvent); 868 863 } 869 864 … … 926 921 { 927 922 genericError(); 928 if (!m_uploadComplete) { 929 m_uploadComplete = true; 930 if (m_upload && m_uploadEventsAllowed) 931 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().errorEvent)); 932 } 933 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().errorEvent)); 923 dispatchErrorEvents(eventNames().errorEvent); 934 924 internalAbort(); 935 925 } … … 938 928 { 939 929 genericError(); 940 if (!m_uploadComplete) { 941 m_uploadComplete = true; 942 if (m_upload && m_uploadEventsAllowed) 943 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 944 } 945 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 930 dispatchErrorEvents(eventNames().abortEvent); 946 931 } 947 932 … … 1177 1162 1178 1163 if (m_uploadEventsAllowed) 1179 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, true, bytesSent, totalBytesToBeSent)); 1180 1164 m_upload->dispatchThrottledProgressEvent(true, bytesSent, totalBytesToBeSent); 1181 1165 if (bytesSent == totalBytesToBeSent && !m_uploadComplete) { 1182 1166 m_uploadComplete = true; 1183 if (m_uploadEventsAllowed) 1184 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().loadEvent)); 1167 if (m_uploadEventsAllowed) { 1168 m_upload->dispatchProgressEvent(eventNames().loadEvent); 1169 m_upload->dispatchProgressEvent(eventNames().loadendEvent); 1170 } 1185 1171 } 1186 1172 } … … 1240 1226 1241 1227 if (!m_error) { 1242 long long expectedLength = m_response.expectedContentLength();1243 1228 m_receivedLength += len; 1244 1229 1245 1230 if (m_async) { 1231 long long expectedLength = m_response.expectedContentLength(); 1246 1232 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLength; 1247 1233 unsigned long long total = lengthComputable ? expectedLength : 0; 1248 m_progressEventThrottle.dispatch ProgressEvent(lengthComputable, m_receivedLength, total);1234 m_progressEventThrottle.dispatchThrottledProgressEvent(lengthComputable, m_receivedLength, total); 1249 1235 } 1250 1236 … … 1257 1243 } 1258 1244 1245 void XMLHttpRequest::dispatchErrorEvents(const AtomicString& type) 1246 { 1247 if (!m_uploadComplete) { 1248 m_uploadComplete = true; 1249 if (m_upload && m_uploadEventsAllowed) { 1250 m_upload->dispatchProgressEvent(type); 1251 m_upload->dispatchProgressEvent(eventNames().loadendEvent); 1252 } 1253 } 1254 m_progressEventThrottle.dispatchProgressEvent(type); 1255 m_progressEventThrottle.dispatchProgressEvent(eventNames().loadendEvent); 1256 } 1257 1259 1258 #if ENABLE(XHR_TIMEOUT) 1260 1259 void XMLHttpRequest::didTimeout() … … 1278 1277 changeState(DONE); 1279 1278 1280 if (!m_uploadComplete) { 1281 m_uploadComplete = true; 1282 if (m_upload && m_uploadEventsAllowed) 1283 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent)); 1284 } 1285 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent)); 1279 dispatchErrorEvents(eventNames().timeoutEvent); 1286 1280 } 1287 1281 #endif -
trunk/Source/WebCore/xml/XMLHttpRequest.h
r161541 r161668 209 209 bool shouldDecodeResponse() const { return m_responseTypeCode < FirstBinaryResponseType; } 210 210 211 void dispatchErrorEvents(const AtomicString&); 212 211 213 std::unique_ptr<XMLHttpRequestUpload> m_upload; 212 214 -
trunk/Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp
r161541 r161668 37 37 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(EventTarget* target) 38 38 : m_target(target) 39 , m_hasThrottledProgressEvent(false) 40 , m_lengthComputable(false) 39 41 , m_loaded(0) 40 42 , m_total(0) … … 49 51 } 50 52 51 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total) 52 { 53 void XMLHttpRequestProgressEventThrottle::dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total) 54 { 55 m_lengthComputable = lengthComputable; 56 m_loaded = loaded; 57 m_total = total; 58 53 59 if (m_deferEvents) { 54 60 // Only store the latest progress event while suspended. … … 61 67 // Just go ahead and dispatch the event. 62 68 63 // We should not have any pending loaded & total information from a previous run. 64 ASSERT(!m_loaded); 65 ASSERT(!m_total); 69 // We should not have any throttled progress event. 70 ASSERT(!m_hasThrottledProgressEvent); 66 71 67 72 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total)); 68 73 startRepeating(minimumProgressEventDispatchingIntervalInSeconds); 74 m_hasThrottledProgressEvent = false; 69 75 return; 70 76 } 71 77 72 78 // The timer is already active so minimumProgressEventDispatchingIntervalInSeconds is the least frequent event. 73 m_lengthComputable = lengthComputable; 74 m_loaded = loaded; 75 m_total = total; 79 m_hasThrottledProgressEvent = true; 76 80 } 77 81 … … 97 101 } 98 102 99 void XMLHttpRequestProgressEventThrottle::dispatchEventAndLoadEnd(PassRefPtr<Event> event) 100 { 101 ASSERT(event->type() == eventNames().loadEvent || event->type() == eventNames().abortEvent || event->type() == eventNames().errorEvent || event->type() == eventNames().timeoutEvent); 102 103 dispatchEvent(event); 104 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().loadendEvent)); 103 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicString &type) 104 { 105 ASSERT(type == eventNames().loadEvent || type == eventNames().loadendEvent || type == eventNames().loadstartEvent || type == eventNames().abortEvent || type == eventNames().errorEvent || type == eventNames().timeoutEvent); 106 107 if (type == eventNames().loadstartEvent) { 108 m_lengthComputable = false; 109 m_loaded = 0; 110 m_total = 0; 111 } 112 113 dispatchEvent(XMLHttpRequestProgressEvent::create(type, m_lengthComputable, m_loaded, m_total)); 105 114 } 106 115 … … 116 125 if (!hasEventToDispatch()) 117 126 return; 118 119 127 PassRefPtr<Event> event = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total); 120 m_loaded = 0; 121 m_total = 0; 128 m_hasThrottledProgressEvent = false; 122 129 123 130 // We stop the timer as this is called when no more events are supposed to occur. … … 161 168 162 169 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total)); 163 m_total = 0; 164 m_loaded = 0; 170 m_hasThrottledProgressEvent = false; 165 171 } 166 172 167 173 bool XMLHttpRequestProgressEventThrottle::hasEventToDispatch() const 168 174 { 169 return (m_total || m_loaded)&& isActive();175 return m_hasThrottledProgressEvent && isActive(); 170 176 } 171 177 … … 188 194 if (hasEventToDispatch()) { 189 195 m_deferredProgressEvent = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total); 190 m_total = 0; 191 m_loaded = 0; 196 m_hasThrottledProgressEvent = false; 192 197 } 193 198 stop(); … … 196 201 void XMLHttpRequestProgressEventThrottle::resume() 197 202 { 198 ASSERT(!m_loaded); 199 ASSERT(!m_total); 203 ASSERT(!m_hasThrottledProgressEvent); 200 204 201 205 if (m_deferredEvents.isEmpty() && !m_deferredProgressEvent) { -
trunk/Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.h
r161541 r161668 31 31 #include "wtf/PassRefPtr.h" 32 32 #include "wtf/Vector.h" 33 #include <wtf/Forward.h> 33 34 34 35 namespace WebCore { … … 49 50 virtual ~XMLHttpRequestProgressEventThrottle(); 50 51 51 void dispatch ProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total);52 void dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total); 52 53 void dispatchReadyStateChangeEvent(PassRefPtr<Event>, ProgressEventAction = DoNotFlushProgressEvent); 53 54 void dispatchEvent(PassRefPtr<Event>); 54 void dispatch EventAndLoadEnd(PassRefPtr<Event>);55 void dispatchProgressEvent(const AtomicString&); 55 56 56 57 void suspend(); … … 69 70 EventTarget* m_target; 70 71 72 bool m_hasThrottledProgressEvent; 71 73 bool m_lengthComputable; 72 74 unsigned long long m_loaded; -
trunk/Source/WebCore/xml/XMLHttpRequestUpload.cpp
r161541 r161668 37 37 XMLHttpRequestUpload::XMLHttpRequestUpload(XMLHttpRequest* xmlHttpRequest) 38 38 : m_xmlHttpRequest(xmlHttpRequest) 39 , m_lengthComputable(false) 40 , m_loaded(0) 41 , m_total(0) 39 42 { 40 43 } 41 44 42 void XMLHttpRequestUpload::dispatch EventAndLoadEnd(PassRefPtr<Event> event)45 void XMLHttpRequestUpload::dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total) 43 46 { 44 ASSERT(event->type() == eventNames().loadEvent || event->type() == eventNames().abortEvent || event->type() == eventNames().errorEvent || event->type() == eventNames().timeoutEvent); 47 m_lengthComputable = lengthComputable; 48 m_loaded = loaded; 49 m_total = total; 45 50 46 dispatchEvent(event); 47 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().loadendEvent)); 51 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total)); 52 } 53 54 void XMLHttpRequestUpload::dispatchProgressEvent(const AtomicString &type) 55 { 56 ASSERT(type == eventNames().loadEvent || type == eventNames().loadendEvent || type == eventNames().loadstartEvent || type == eventNames().abortEvent || type == eventNames().errorEvent || type == eventNames().timeoutEvent); 57 58 if (type == eventNames().loadstartEvent) { 59 m_lengthComputable = false; 60 m_loaded = 0; 61 m_total = 0; 62 } 63 64 dispatchEvent(XMLHttpRequestProgressEvent::create(type, m_lengthComputable, m_loaded, m_total)); 48 65 } 49 66 50 67 51 52 68 } // namespace WebCore -
trunk/Source/WebCore/xml/XMLHttpRequestUpload.h
r161541 r161668 56 56 DEFINE_ATTRIBUTE_EVENT_LISTENER(progress); 57 57 58 void dispatchEventAndLoadEnd(PassRefPtr<Event>); 58 void dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total); 59 void dispatchProgressEvent(const AtomicString &type); 59 60 60 61 private: … … 63 64 64 65 XMLHttpRequest* m_xmlHttpRequest; 66 bool m_lengthComputable; 67 unsigned long long m_loaded; 68 unsigned long long m_total; 65 69 }; 66 70
Note: See TracChangeset
for help on using the changeset viewer.