Changeset 56394 in webkit


Ignore:
Timestamp:
Mar 23, 2010 8:33:16 AM (14 years ago)
Author:
jchaffraix@webkit.org
Message:

[XHR] onProgress event needs to be dispatched according to what the specification states
https://bugs.webkit.org/show_bug.cgi?id=18654

Reviewed by Alexey Proskuryakov.

WebCore:

Test: http/tests/xmlhttprequest/xmlhttprequest-50ms-download-dispatch.html

  • Android.mk:
  • GNUmakefile.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:

Added XMLHttpRequestProgressEventThrottle to the build systems.

  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::XMLHttpRequest): Created the throttle.
(WebCore::XMLHttpRequest::callReadyStateChangeListener): The 'readyState' event are
dispatched using the XMLHttpRequestProgressEventThrottle now. For the DONE state, we
need to flush any pending progress event as we do not want it to be dispatched after
the DONE readyState event.
(WebCore::XMLHttpRequest::createRequest): Made this event use the
XMLHttpRequestProgressEventThrottle for event dispatching.
(WebCore::XMLHttpRequest::abort): Ditto.
(WebCore::XMLHttpRequest::networkError): Ditto.
(WebCore::XMLHttpRequest::abortError): Ditto.
(WebCore::XMLHttpRequest::didReceiveData): Ditto. Also fixed a potential warning.
(WebCore::XMLHttpRequest::suspend):
(WebCore::XMLHttpRequest::resume): Implemented the logic for suspend / resume.

  • xml/XMLHttpRequest.h:
  • xml/XMLHttpRequestProgressEventThrottle.cpp: Added.

(WebCore::XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle):
(WebCore::XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle):
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent): Implemented the bulk
of the event throttling here: we use a timer to do so, as long as the timer is active it means
that events are coming faster than the throttling time and we coalesce them.
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchEvent): Generic method to dispatch an event.
(WebCore::XMLHttpRequestProgressEventThrottle::flushProgressEvent): Called when we want to dispatch
any pending events and stopping any further dispatching.
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchPausedEvent): Used to dispatch the event
that was queued due to the object being suspended.
(WebCore::XMLHttpRequestProgressEventThrottle::fired): Used to dispatch any coalesced event.
(WebCore::XMLHttpRequestProgressEventThrottle::hasEventToDispatch): Used to check if we have
an event to dispatch.
(WebCore::XMLHttpRequestProgressEventThrottle::suspend): Marked the object as suspended.
(WebCore::XMLHttpRequestProgressEventThrottle::resume): Dispatched the event that was queued.

  • xml/XMLHttpRequestProgressEventThrottle.h: Added.

(WebCore::):
(WebCore::XMLHttpRequestProgressEventThrottle::suspended):

LayoutTests:

Add a test to check that progress events are really throttled.

  • http/tests/xmlhttprequest/resources/download-with-delay.php: Added.
  • http/tests/xmlhttprequest/xmlhttprequest-50ms-download-dispatch-expected.txt: Added.
  • http/tests/xmlhttprequest/xmlhttprequest-50ms-download-dispatch.html: Added.
Location:
trunk
Files:
5 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r56393 r56394  
     12010-03-23  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        [XHR] onProgress event needs to be dispatched according to what the specification states
     6        https://bugs.webkit.org/show_bug.cgi?id=18654
     7
     8        Add a test to check that progress events are really throttled.
     9
     10        * http/tests/xmlhttprequest/resources/download-with-delay.php: Added.
     11        * http/tests/xmlhttprequest/xmlhttprequest-50ms-download-dispatch-expected.txt: Added.
     12        * http/tests/xmlhttprequest/xmlhttprequest-50ms-download-dispatch.html: Added.
     13
    1142010-03-23  Pavel Feldman  <pfeldman@chromium.org>
    215
  • trunk/WebCore/Android.mk

    r55821 r56394  
    897897        xml/DOMParser.cpp \
    898898        xml/XMLHttpRequest.cpp \
     899        xml/XMLHttpRequestProgressEventThrottle.cpp \
    899900        xml/XMLHttpRequestUpload.cpp \
    900901        xml/XMLSerializer.cpp
  • trunk/WebCore/ChangeLog

    r56393 r56394  
     12010-03-23  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        [XHR] onProgress event needs to be dispatched according to what the specification states
     6        https://bugs.webkit.org/show_bug.cgi?id=18654
     7
     8        Test: http/tests/xmlhttprequest/xmlhttprequest-50ms-download-dispatch.html
     9
     10        * Android.mk:
     11        * GNUmakefile.am:
     12        * WebCore.gypi:
     13        * WebCore.pro:
     14        * WebCore.vcproj/WebCore.vcproj:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        Added XMLHttpRequestProgressEventThrottle to the build systems.
     17
     18        * xml/XMLHttpRequest.cpp:
     19        (WebCore::XMLHttpRequest::XMLHttpRequest): Created the throttle.
     20        (WebCore::XMLHttpRequest::callReadyStateChangeListener): The 'readyState' event are
     21        dispatched using the XMLHttpRequestProgressEventThrottle now. For the DONE state, we
     22        need to flush any pending progress event as we do not want it to be dispatched after
     23        the DONE readyState event.
     24        (WebCore::XMLHttpRequest::createRequest): Made this event use the
     25        XMLHttpRequestProgressEventThrottle for event dispatching.
     26        (WebCore::XMLHttpRequest::abort): Ditto.
     27        (WebCore::XMLHttpRequest::networkError): Ditto.
     28        (WebCore::XMLHttpRequest::abortError): Ditto.
     29        (WebCore::XMLHttpRequest::didReceiveData): Ditto. Also fixed a potential warning.
     30        (WebCore::XMLHttpRequest::suspend):
     31        (WebCore::XMLHttpRequest::resume): Implemented the logic for suspend / resume.
     32        * xml/XMLHttpRequest.h:
     33        * xml/XMLHttpRequestProgressEventThrottle.cpp: Added.
     34        (WebCore::XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle):
     35        (WebCore::XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle):
     36        (WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent): Implemented the bulk
     37        of the event throttling here: we use a timer to do so, as long as the timer is active it means
     38        that events are coming faster than the throttling time and we coalesce them.
     39        (WebCore::XMLHttpRequestProgressEventThrottle::dispatchEvent): Generic method to dispatch an event.
     40        (WebCore::XMLHttpRequestProgressEventThrottle::flushProgressEvent): Called when we want to dispatch
     41        any pending events and stopping any further dispatching.
     42        (WebCore::XMLHttpRequestProgressEventThrottle::dispatchPausedEvent): Used to dispatch the event
     43        that was queued due to the object being suspended.
     44        (WebCore::XMLHttpRequestProgressEventThrottle::fired): Used to dispatch any coalesced event.
     45        (WebCore::XMLHttpRequestProgressEventThrottle::hasEventToDispatch): Used to check if we have
     46        an event to dispatch.
     47        (WebCore::XMLHttpRequestProgressEventThrottle::suspend): Marked the object as suspended.
     48        (WebCore::XMLHttpRequestProgressEventThrottle::resume): Dispatched the event that was queued.
     49        * xml/XMLHttpRequestProgressEventThrottle.h: Added.
     50        (WebCore::):
     51        (WebCore::XMLHttpRequestProgressEventThrottle::suspended):
     52
    1532010-03-23  Pavel Feldman  <pfeldman@chromium.org>
    254
  • trunk/WebCore/GNUmakefile.am

    r56387 r56394  
    19841984        WebCore/xml/XMLHttpRequestException.h \
    19851985        WebCore/xml/XMLHttpRequestProgressEvent.h \
     1986        WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp \
     1987        WebCore/xml/XMLHttpRequestProgressEventThrottle.h \
    19861988        WebCore/xml/XMLHttpRequestUpload.cpp \
    19871989        WebCore/xml/XMLHttpRequestUpload.h \
  • trunk/WebCore/WebCore.gypi

    r56241 r56394  
    37153715            'xml/XMLHttpRequestException.h',
    37163716            'xml/XMLHttpRequestProgressEvent.h',
     3717            'xml/XMLHttpRequestProgressEventThrottle.cpp',
     3718            'xml/XMLHttpRequestProgressEventThrottle.h',
    37173719            'xml/XMLHttpRequestUpload.cpp',
    37183720            'xml/XMLHttpRequestUpload.h',
  • trunk/WebCore/WebCore.pro

    r56386 r56394  
    989989    xml/DOMParser.cpp \
    990990    xml/XMLHttpRequest.cpp \
     991    xml/XMLHttpRequestProgressEventThrottle.cpp \
    991992    xml/XMLHttpRequestUpload.cpp \
    992993    xml/XMLSerializer.cpp
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r56256 r56394  
    2846028460                        </File>
    2846128461                        <File
     28462                                RelativePath="..\xml\XMLHttpRequestProgressEventThrottle.cpp"
     28463                                >
     28464                        </File>
     28465                        <File
     28466                                RelativePath="..\xml\XMLHttpRequestProgressEventThrottle.h"
     28467                                >
     28468                        </File>
     28469                        <File
    2846228470                                RelativePath="..\xml\XMLHttpRequestUpload.cpp"
    2846328471                                >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r56361 r56394  
    43964396                BC772C460C4EB2C60083285F /* XMLHttpRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC772C440C4EB2C60083285F /* XMLHttpRequest.cpp */; };
    43974397                BC772C470C4EB2C60083285F /* XMLHttpRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = BC772C450C4EB2C60083285F /* XMLHttpRequest.h */; };
     4398                A136A00C1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A136A00A1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp */; };
     4399                A136A00D1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h in Headers */ = {isa = PBXBuildFile; fileRef = A136A00B1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h */; };
    43984400                BC772C4E0C4EB3040083285F /* MIMETypeRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */; };
    43994401                BC772C4F0C4EB3040083285F /* MIMETypeRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    78987900                9F72304D11184B4100AD0126 /* ScriptProfiler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptProfiler.cpp; sourceTree = "<group>"; };
    78997901                9F72304E11184B4100AD0126 /* ScriptProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptProfiler.h; sourceTree = "<group>"; };
     7902                A136A00A1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLHttpRequestProgressEventThrottle.cpp; sourceTree = "<group>"; };
     7903                A136A00B1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLHttpRequestProgressEventThrottle.h; sourceTree = "<group>"; };
    79007904                A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLElementFactory.cpp; sourceTree = "<group>"; };
    79017905                A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLElementFactory.h; sourceTree = "<group>"; };
     
    1545515459                                F9F0ED770DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.h */,
    1545615460                                F9F0ED780DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.idl */,
     15461                                A136A00A1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp */,
     15462                                A136A00B1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h */,
    1545715463                                BCDFD48D0E305290009D10AD /* XMLHttpRequestUpload.cpp */,
    1545815464                                BCDFD48C0E305290009D10AD /* XMLHttpRequestUpload.h */,
     
    1870518711                                BC60D9C90D2A29E500B9918F /* XMLHttpRequestException.h in Headers */,
    1870618712                                F9F0ED7A0DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.h in Headers */,
     18713                                A136A00D1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h in Headers */,
    1870718714                                BCDFD48E0E305290009D10AD /* XMLHttpRequestUpload.h in Headers */,
    1870818715                                A833C80D0A2CF25600D57664 /* XMLNames.h in Headers */,
     
    2091820925                                BC772C460C4EB2C60083285F /* XMLHttpRequest.cpp in Sources */,
    2091920926                                BCDFD48F0E305290009D10AD /* XMLHttpRequestUpload.cpp in Sources */,
     20927                                A136A00C1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp in Sources */,
    2092020928                                A833C80C0A2CF25600D57664 /* XMLNames.cpp in Sources */,
    2092120929                                E15A36D91104572700B7B639 /* XMLNSNames.cpp in Sources */,
  • trunk/WebCore/xml/XMLHttpRequest.cpp

    r55821 r56394  
    159159    , m_lastSendLineNumber(0)
    160160    , m_exceptionCode(0)
     161    , m_progressEventThrottle(this)
    161162{
    162163    initializeXMLHttpRequestStaticData();
     
    260261#endif
    261262
    262     dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().readystatechangeEvent));
     263    m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().readystatechangeEvent), m_state == DONE ? FlushProgressEvent : DoNotFlushProgressEvent);
    263264
    264265#if ENABLE(INSPECTOR)
     
    275276#endif
    276277
    277         dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().loadEvent));
     278        m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().loadEvent));
    278279
    279280#if ENABLE(INSPECTOR)
     
    487488    bool forcePreflight = false;
    488489    if (m_async) {
    489         dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().loadstartEvent));
     490        m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().loadstartEvent));
    490491        if (m_requestEntityBody && m_upload) {
    491492            forcePreflight = m_upload->hasEventListeners();
     
    579580    }
    580581
    581     dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().abortEvent));
     582    m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().abortEvent));
    582583    if (!m_uploadComplete) {
    583584        m_uploadComplete = true;
     
    633634{
    634635    genericError();
    635     dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().errorEvent));
     636    m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().errorEvent));
    636637    if (!m_uploadComplete) {
    637638        m_uploadComplete = true;
     
    645646{
    646647    genericError();
    647     dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().abortEvent));
     648    m_progressEventThrottle.dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().abortEvent));
    648649    if (!m_uploadComplete) {
    649650        m_uploadComplete = true;
     
    948949        m_receivedLength += len;
    949950
    950         // FIXME: the spec requires that we dispatch the event according to the least
    951         // frequent method between every 350ms (+/-200ms) and for every byte received.
    952         dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, expectedLength && m_receivedLength <= expectedLength, static_cast<unsigned>(m_receivedLength), static_cast<unsigned>(expectedLength)));
     951        bool lengthComputable = expectedLength && m_receivedLength <= expectedLength;
     952        m_progressEventThrottle.dispatchProgressEvent(lengthComputable, static_cast<unsigned>(m_receivedLength), static_cast<unsigned>(expectedLength));
    953953
    954954        if (m_state != LOADING)
     
    965965}
    966966
     967void XMLHttpRequest::suspend()
     968{
     969    m_progressEventThrottle.suspend();
     970}
     971
     972void XMLHttpRequest::resume()
     973{
     974    m_progressEventThrottle.resume();
     975}
     976
    967977void XMLHttpRequest::stop()
    968978{
  • trunk/WebCore/xml/XMLHttpRequest.h

    r55821 r56394  
    3030#include "ScriptString.h"
    3131#include "ThreadableLoaderClient.h"
     32#include "XMLHttpRequestProgressEventThrottle.h"
    3233#include <wtf/OwnPtr.h>
    3334
     
    5960    virtual void contextDestroyed();
    6061    virtual bool canSuspend() const;
     62    virtual void suspend();
     63    virtual void resume();
    6164    virtual void stop();
    6265
     
    188191
    189192    EventTargetData m_eventTargetData;
     193
     194    XMLHttpRequestProgressEventThrottle m_progressEventThrottle;
    190195};
    191196
Note: See TracChangeset for help on using the changeset viewer.