Changeset 161532 in webkit
- Timestamp:
- Jan 8, 2014 6:11:59 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r161521 r161532 1 2014-01-08 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-07 Myles C. Maxfield <mmaxfield@apple.com> 2 23 -
trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt
r150949 r161532 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
r161530 r161532 1 2014-01-08 Youenn Fablet <youennf@gmail.com> 2 3 Correctly set XHR loadend attributes (loaded and total). 4 https://bugs.webkit.org/show_bug.cgi?id=120828 5 6 Reviewed by Alexey Proskuryakov. 7 8 Added correct initialization of lengthComputable, loaded and total attributes 9 to XHR ProgressEvent events (load, loadstart, loadend, abort, error and timeout). 10 11 XMLHttpRequestProgressEventThrottle and XMLHttpRequestUpload now keep persistent knowledge 12 of m_loaded and m_total values with this patch. 13 14 Code refactoring to handle event dispatching in case of error in a single manner. 15 XMLHttpRequestProgressEventThrottle::dispatchProgressEvent is renamed as dispatchThrottledProgressEvent 16 XMLHttpRequestProgressEventThrottle::dispatchEventAndLoadend is replaced by dispatchProgressEvent(const AtomicString&) 17 18 Tests: http/tests/xmlhttprequest/loadstart-event-init.html 19 http/tests/xmlhttprequest/onabort-progressevent-attributes.html 20 http/tests/xmlhttprequest/onload-progressevent-attributes.html 21 http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html 22 http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html 23 24 * xml/XMLHttpRequest.cpp: 25 (WebCore::XMLHttpRequest::callReadyStateChangeListener): changed readystatechange event from ProgressEvent to Event (not cancellable, not bubblable) to better match the spec 26 (WebCore::XMLHttpRequest::createRequest): 27 (WebCore::XMLHttpRequest::abort): code refactoring to handle error event dispatching in a single way 28 (WebCore::XMLHttpRequest::networkError): code refactoring to handle error event dispatching in a single way 29 (WebCore::XMLHttpRequest::abortError): code refactoring to handle error event dispatching in a single way 30 (WebCore::XMLHttpRequest::didSendData): 31 (WebCore::XMLHttpRequest::didReceiveData): 32 (WebCore::XMLHttpRequest::dispatchErrorEvents): dispatch progress events in case of error 33 (WebCore::XMLHttpRequest::didTimeout): code refactoring to handle error event dispatching in a single way 34 * xml/XMLHttpRequest.h: 35 * 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...) 36 (WebCore::XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle): 37 (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. 38 (WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent): used to send any ProgressEvent event that is not be throttled 39 (WebCore::XMLHttpRequestProgressEventThrottle::flushProgressEvent): after the call, no progress event is throttled anymore 40 (WebCore::XMLHttpRequestProgressEventThrottle::fired): after the call, no progress event is throttled anymore 41 (WebCore::XMLHttpRequestProgressEventThrottle::hasEventToDispatch): 42 (WebCore::XMLHttpRequestProgressEventThrottle::suspend): 43 * 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 44 * xml/XMLHttpRequestUpload.cpp: 45 (WebCore::XMLHttpRequestUpload::XMLHttpRequestUpload): 46 (WebCore::XMLHttpRequestUpload::dispatchProgressEvent): 47 * xml/XMLHttpRequestUpload.h: introduced m_loaded, m_total and m_lengthComputable, similarly to XMLHttpRequestProgressEventThrottle 48 1 49 2014-01-08 Tim Horton <timothy_horton@apple.com> 2 50 -
trunk/Source/WebCore/xml/XMLHttpRequest.cpp
r161425 r161532 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 } … … 863 863 } 864 864 865 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 866 if (!m_uploadComplete) { 867 m_uploadComplete = true; 868 if (m_upload && m_uploadEventsAllowed) 869 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 870 } 865 dispatchErrorEvents(eventNames().abortEvent); 871 866 } 872 867 … … 929 924 { 930 925 genericError(); 931 if (!m_uploadComplete) { 932 m_uploadComplete = true; 933 if (m_upload && m_uploadEventsAllowed) 934 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().errorEvent)); 935 } 936 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().errorEvent)); 926 dispatchErrorEvents(eventNames().errorEvent); 937 927 internalAbort(); 938 928 } … … 941 931 { 942 932 genericError(); 943 if (!m_uploadComplete) { 944 m_uploadComplete = true; 945 if (m_upload && m_uploadEventsAllowed) 946 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 947 } 948 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent)); 933 dispatchErrorEvents(eventNames().abortEvent); 949 934 } 950 935 … … 1180 1165 1181 1166 if (m_uploadEventsAllowed) 1182 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, true, bytesSent, totalBytesToBeSent)); 1183 1167 m_upload->dispatchThrottledProgressEvent(true, bytesSent, totalBytesToBeSent); 1184 1168 if (bytesSent == totalBytesToBeSent && !m_uploadComplete) { 1185 1169 m_uploadComplete = true; 1186 if (m_uploadEventsAllowed) 1187 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().loadEvent)); 1170 if (m_uploadEventsAllowed) { 1171 m_upload->dispatchProgressEvent(eventNames().loadEvent); 1172 m_upload->dispatchProgressEvent(eventNames().loadendEvent); 1173 } 1188 1174 } 1189 1175 } … … 1243 1229 1244 1230 if (!m_error) { 1245 long long expectedLength = m_response.expectedContentLength();1246 1231 m_receivedLength += len; 1247 1232 1248 1233 if (m_async) { 1234 long long expectedLength = m_response.expectedContentLength(); 1249 1235 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLength; 1250 1236 unsigned long long total = lengthComputable ? expectedLength : 0; 1251 m_progressEventThrottle.dispatch ProgressEvent(lengthComputable, m_receivedLength, total);1237 m_progressEventThrottle.dispatchThrottledProgressEvent(lengthComputable, m_receivedLength, total); 1252 1238 } 1253 1239 … … 1260 1246 } 1261 1247 1248 void XMLHttpRequest::dispatchErrorEvents(const AtomicString& type) 1249 { 1250 if (!m_uploadComplete) { 1251 m_uploadComplete = true; 1252 if (m_upload && m_uploadEventsAllowed) { 1253 m_upload->dispatchProgressEvent(type); 1254 m_upload->dispatchProgressEvent(eventNames().loadendEvent); 1255 } 1256 } 1257 m_progressEventThrottle.dispatchProgressEvent(type); 1258 m_progressEventThrottle.dispatchProgressEvent(eventNames().loadendEvent); 1259 } 1260 1262 1261 #if ENABLE(XHR_TIMEOUT) 1263 1262 void XMLHttpRequest::didTimeout() … … 1281 1280 changeState(DONE); 1282 1281 1283 if (!m_uploadComplete) { 1284 m_uploadComplete = true; 1285 if (m_upload && m_uploadEventsAllowed) 1286 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent)); 1287 } 1288 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent)); 1282 dispatchErrorEvents(eventNames().timeoutEvent); 1289 1283 } 1290 1284 #endif -
trunk/Source/WebCore/xml/XMLHttpRequest.h
r161058 r161532 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
r157653 r161532 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. … … 67 73 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total)); 68 74 startRepeating(minimumProgressEventDispatchingIntervalInSeconds); 75 m_hasThrottledProgressEvent = false; 69 76 return; 70 77 } 71 78 72 79 // The timer is already active so minimumProgressEventDispatchingIntervalInSeconds is the least frequent event. 73 m_lengthComputable = lengthComputable; 74 m_loaded = loaded; 75 m_total = total; 80 m_hasThrottledProgressEvent = true; 76 81 } 77 82 … … 97 102 } 98 103 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)); 104 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicString &type) 105 { 106 ASSERT(type == eventNames().loadEvent || type == eventNames().loadstartEvent || type == eventNames().abortEvent || type == eventNames().errorEvent || type == eventNames().timeoutEvent); 107 108 if (type == eventNames().loadstartEvent) { 109 m_lengthComputable = false; 110 m_loaded = 0; 111 m_total = 0; 112 } 113 114 dispatchEvent(XMLHttpRequestProgressEvent::create(type, m_lengthComputable, m_loaded, m_total)); 105 115 } 106 116 … … 116 126 if (!hasEventToDispatch()) 117 127 return; 118 119 128 PassRefPtr<Event> event = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total); 120 m_loaded = 0; 121 m_total = 0; 129 m_hasThrottledProgressEvent = false; 122 130 123 131 // We stop the timer as this is called when no more events are supposed to occur. … … 161 169 162 170 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total)); 163 m_total = 0; 164 m_loaded = 0; 171 m_hasThrottledProgressEvent = false; 165 172 } 166 173 167 174 bool XMLHttpRequestProgressEventThrottle::hasEventToDispatch() const 168 175 { 169 return (m_total || m_loaded)&& isActive();176 return m_hasThrottledProgressEvent && isActive(); 170 177 } 171 178 … … 188 195 if (hasEventToDispatch()) { 189 196 m_deferredProgressEvent = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total); 190 m_total = 0; 191 m_loaded = 0; 197 m_hasThrottledProgressEvent = false; 192 198 } 193 199 stop(); -
trunk/Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.h
r157653 r161532 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
r161425 r161532 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().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
r161425 r161532 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.