Ignore:
Timestamp:
Jan 8, 2014, 6:11:59 PM (11 years ago)
Author:
[email protected]
Message:

Source/WebCore: Correctly set XHR loadend attributes (loaded and total).
https://bugs.webkit.org/show_bug.cgi?id=120828

Patch by Youenn Fablet <[email protected]> on 2014-01-08
Reviewed by Alexey Proskuryakov.

Added correct initialization of lengthComputable, loaded and total attributes
to XHR ProgressEvent events (load, loadstart, loadend, abort, error and timeout).

XMLHttpRequestProgressEventThrottle and XMLHttpRequestUpload now keep persistent knowledge
of m_loaded and m_total values with this patch.

Code refactoring to handle event dispatching in case of error in a single manner.
XMLHttpRequestProgressEventThrottle::dispatchProgressEvent is renamed as dispatchThrottledProgressEvent
XMLHttpRequestProgressEventThrottle::dispatchEventAndLoadend is replaced by dispatchProgressEvent(const AtomicString&)

Tests: http/tests/xmlhttprequest/loadstart-event-init.html

http/tests/xmlhttprequest/onabort-progressevent-attributes.html
http/tests/xmlhttprequest/onload-progressevent-attributes.html
http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html
http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html

  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::callReadyStateChangeListener): changed readystatechange event from ProgressEvent to Event (not cancellable, not bubblable) to better match the spec
(WebCore::XMLHttpRequest::createRequest):
(WebCore::XMLHttpRequest::abort): code refactoring to handle error event dispatching in a single way
(WebCore::XMLHttpRequest::networkError): code refactoring to handle error event dispatching in a single way
(WebCore::XMLHttpRequest::abortError): code refactoring to handle error event dispatching in a single way
(WebCore::XMLHttpRequest::didSendData):
(WebCore::XMLHttpRequest::didReceiveData):
(WebCore::XMLHttpRequest::dispatchErrorEvents): dispatch progress events in case of error
(WebCore::XMLHttpRequest::didTimeout): code refactoring to handle error event dispatching in a single way

  • xml/XMLHttpRequest.h:
  • 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...)

(WebCore::XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle):
(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.
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent): used to send any ProgressEvent event that is not be throttled
(WebCore::XMLHttpRequestProgressEventThrottle::flushProgressEvent): after the call, no progress event is throttled anymore
(WebCore::XMLHttpRequestProgressEventThrottle::fired): after the call, no progress event is throttled anymore
(WebCore::XMLHttpRequestProgressEventThrottle::hasEventToDispatch):
(WebCore::XMLHttpRequestProgressEventThrottle::suspend):

  • 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
  • xml/XMLHttpRequestUpload.cpp:

(WebCore::XMLHttpRequestUpload::XMLHttpRequestUpload):
(WebCore::XMLHttpRequestUpload::dispatchProgressEvent):

  • xml/XMLHttpRequestUpload.h: introduced m_loaded, m_total and m_lengthComputable, similarly to XMLHttpRequestProgressEventThrottle

LayoutTests: Correctly set XHR loadend event attributes (loaded and total).
https://bugs.webkit.org/show_bug.cgi?id=120828

Patch by Youenn Fablet <[email protected]> on 2014-01-08
Reviewed by Alexey Proskuryakov.

Tests for abort, load, loadstart and loadend ProgressEvent events for XMLHttpRequest and XMLHttpRequestUpload

  • fast/xmlhttprequest/xmlhttprequest-get-expected.txt: Changed to correct event values
  • http/tests/xmlhttprequest/loadstart-event-init-expected.txt: Added.
  • http/tests/xmlhttprequest/loadstart-event-init.html: Added.
  • http/tests/xmlhttprequest/onabort-progressevent-attributes-expected.txt: Added.
  • http/tests/xmlhttprequest/onabort-progressevent-attributes.html: Added.
  • http/tests/xmlhttprequest/onload-progressevent-attributes-expected.txt: Added.
  • http/tests/xmlhttprequest/onload-progressevent-attributes.html: Added.
  • http/tests/xmlhttprequest/upload-onabort-progressevent-attributes-expected.txt: Added.
  • http/tests/xmlhttprequest/upload-onabort-progressevent-attributes.html: Added.
  • http/tests/xmlhttprequest/upload-onload-progressevent-attributes-expected.txt: Added.
  • http/tests/xmlhttprequest/upload-onload-progressevent-attributes.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp

    r157653 r161532  
    3737XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(EventTarget* target)
    3838    : m_target(target)
     39    , m_hasThrottledProgressEvent(false)
     40    , m_lengthComputable(false)
    3941    , m_loaded(0)
    4042    , m_total(0)
     
    4951}
    5052
    51 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total)
    52 {
     53void 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   
    5359    if (m_deferEvents) {
    5460        // Only store the latest progress event while suspended.
     
    6773        dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total));
    6874        startRepeating(minimumProgressEventDispatchingIntervalInSeconds);
     75        m_hasThrottledProgressEvent = false;
    6976        return;
    7077    }
    7178
    7279    // 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;
    7681}
    7782
     
    97102}
    98103
    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));
     104void 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));
    105115}
    106116
     
    116126    if (!hasEventToDispatch())
    117127        return;
    118 
    119128    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;
    122130
    123131    // We stop the timer as this is called when no more events are supposed to occur.
     
    161169
    162170    dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total));
    163     m_total = 0;
    164     m_loaded = 0;
     171    m_hasThrottledProgressEvent = false;
    165172}
    166173
    167174bool XMLHttpRequestProgressEventThrottle::hasEventToDispatch() const
    168175{
    169     return (m_total || m_loaded) && isActive();
     176    return m_hasThrottledProgressEvent && isActive();
    170177}
    171178
     
    188195    if (hasEventToDispatch()) {
    189196        m_deferredProgressEvent = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total);
    190         m_total = 0;
    191         m_loaded = 0;
     197        m_hasThrottledProgressEvent = false;
    192198    }
    193199    stop();
Note: See TracChangeset for help on using the changeset viewer.