Changeset 161541 in webkit for trunk/Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp
- Timestamp:
- Jan 8, 2014, 7:56:47 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp
r161532 r161541 37 37 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(EventTarget* target) 38 38 : m_target(target) 39 , m_hasThrottledProgressEvent(false)40 , m_lengthComputable(false)41 39 , m_loaded(0) 42 40 , m_total(0) … … 51 49 } 52 50 53 void XMLHttpRequestProgressEventThrottle::dispatchThrottledProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total) 54 { 51 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(bool lengthComputable, unsigned long long loaded, unsigned long long total) 52 { 53 if (m_deferEvents) { 54 // Only store the latest progress event while suspended. 55 m_deferredProgressEvent = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total); 56 return; 57 } 58 59 if (!isActive()) { 60 // The timer is not active so the least frequent event for now is every byte. 61 // Just go ahead and dispatch the event. 62 63 // We should not have any pending loaded & total information from a previous run. 64 ASSERT(!m_loaded); 65 ASSERT(!m_total); 66 67 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total)); 68 startRepeating(minimumProgressEventDispatchingIntervalInSeconds); 69 return; 70 } 71 72 // The timer is already active so minimumProgressEventDispatchingIntervalInSeconds is the least frequent event. 55 73 m_lengthComputable = lengthComputable; 56 74 m_loaded = loaded; 57 75 m_total = total; 58 59 if (m_deferEvents) {60 // Only store the latest progress event while suspended.61 m_deferredProgressEvent = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total);62 return;63 }64 65 if (!isActive()) {66 // The timer is not active so the least frequent event for now is every byte.67 // Just go ahead and dispatch the event.68 69 // We should not have any pending loaded & total information from a previous run.70 ASSERT(!m_loaded);71 ASSERT(!m_total);72 73 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, lengthComputable, loaded, total));74 startRepeating(minimumProgressEventDispatchingIntervalInSeconds);75 m_hasThrottledProgressEvent = false;76 return;77 }78 79 // The timer is already active so minimumProgressEventDispatchingIntervalInSeconds is the least frequent event.80 m_hasThrottledProgressEvent = true;81 76 } 82 77 … … 102 97 } 103 98 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)); 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)); 115 105 } 116 106 … … 126 116 if (!hasEventToDispatch()) 127 117 return; 118 128 119 PassRefPtr<Event> event = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total); 129 m_hasThrottledProgressEvent = false; 120 m_loaded = 0; 121 m_total = 0; 130 122 131 123 // We stop the timer as this is called when no more events are supposed to occur. … … 169 161 170 162 dispatchEvent(XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total)); 171 m_hasThrottledProgressEvent = false; 163 m_total = 0; 164 m_loaded = 0; 172 165 } 173 166 174 167 bool XMLHttpRequestProgressEventThrottle::hasEventToDispatch() const 175 168 { 176 return m_hasThrottledProgressEvent&& isActive();169 return (m_total || m_loaded) && isActive(); 177 170 } 178 171 … … 195 188 if (hasEventToDispatch()) { 196 189 m_deferredProgressEvent = XMLHttpRequestProgressEvent::create(eventNames().progressEvent, m_lengthComputable, m_loaded, m_total); 197 m_hasThrottledProgressEvent = false; 190 m_total = 0; 191 m_loaded = 0; 198 192 } 199 193 stop();
Note:
See TracChangeset
for help on using the changeset viewer.