Ignore:
Timestamp:
Oct 2, 2014, 3:49:06 PM (11 years ago)
Author:
Chris Dumez
Message:

XMLHttpRequestProgressEventThrottle shouldn't throttle / defer progress events if there are no listeners
https://bugs.webkit.org/show_bug.cgi?id=137346

Reviewed by Alexey Proskuryakov.

Previously XMLHttpRequestProgressEventThrottle would throttle / defer
progress events, which involves queueing events and starting timers,
even if there were no listeners for those events (which is fairly
common case).

This patch updates XMLHttpRequestProgressEventThrottle to make sure
there are actual progress event listeners *before* attempting to
throttle and do extra processing, to avoid doing unnecessary work.

This patch also makes XMLHttpRequestProgressEventThrottle::dispatchEvent()
private as this method is only called from other dispatch methods of
the class and never from the outside.

No new tests, no behavior change.

  • xml/XMLHttpRequestProgressEventThrottle.cpp:

(WebCore::XMLHttpRequestProgressEventThrottle::dispatchThrottledProgressEvent):
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchProgressEvent):

File:
1 edited

Legend:

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

    r170774 r174235  
    5656    m_loaded = loaded;
    5757    m_total = total;
     58
     59    if (!m_target->hasEventListeners(eventNames().progressEvent))
     60        return;
    5861   
    5962    if (m_deferEvents) {
     
    101104}
    102105
    103 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicString &type)
     106void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicString& type)
    104107{
    105108    ASSERT(type == eventNames().loadstartEvent || type == eventNames().progressEvent || type == eventNames().loadEvent || type == eventNames().loadendEvent || type == eventNames().abortEvent || type == eventNames().errorEvent || type == eventNames().timeoutEvent);
     
    111114    }
    112115
    113     dispatchEvent(XMLHttpRequestProgressEvent::create(type, m_lengthComputable, m_loaded, m_total));
     116    if (m_target->hasEventListeners(type))
     117        dispatchEvent(XMLHttpRequestProgressEvent::create(type, m_lengthComputable, m_loaded, m_total));
    114118}
    115119
Note: See TracChangeset for help on using the changeset viewer.