| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> All right reserv
ed. | 2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> All right reserv
ed. |
| 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 startRepeating(minimumProgressEventDispatchingIntervalInSeconds, FROM_HE
RE); | 68 startRepeating(minimumProgressEventDispatchingIntervalInSeconds, FROM_HE
RE); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // The timer is already active so minimumProgressEventDispatchingIntervalInS
econds is the least frequent event. | 72 // The timer is already active so minimumProgressEventDispatchingIntervalInS
econds is the least frequent event. |
| 73 m_lengthComputable = lengthComputable; | 73 m_lengthComputable = lengthComputable; |
| 74 m_loaded = loaded; | 74 m_loaded = loaded; |
| 75 m_total = total; | 75 m_total = total; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP
tr<Event> event, ProgressEventAction progressEventAction) | 78 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP
trWillBeRawPtr<Event> event, ProgressEventAction progressEventAction) |
| 79 { | 79 { |
| 80 if (progressEventAction == FlushProgressEvent || progressEventAction == Flus
hDeferredProgressEvent) { | 80 if (progressEventAction == FlushProgressEvent || progressEventAction == Flus
hDeferredProgressEvent) { |
| 81 if (!flushDeferredProgressEvent() && progressEventAction == FlushProgres
sEvent) | 81 if (!flushDeferredProgressEvent() && progressEventAction == FlushProgres
sEvent) |
| 82 deliverProgressEvent(); | 82 deliverProgressEvent(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 dispatchEvent(event); | 85 dispatchEvent(event); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void XMLHttpRequestProgressEventThrottle::dispatchEvent(PassRefPtr<Event> event) | 88 void XMLHttpRequestProgressEventThrottle::dispatchEvent(PassRefPtrWillBeRawPtr<E
vent> event) |
| 89 { | 89 { |
| 90 ASSERT(event); | 90 ASSERT(event); |
| 91 if (m_deferEvents) { | 91 if (m_deferEvents) { |
| 92 if (m_deferredEvents.size() > 1 && event->type() == EventTypeNames::read
ystatechange && event->type() == m_deferredEvents.last()->type()) { | 92 if (m_deferredEvents.size() > 1 && event->type() == EventTypeNames::read
ystatechange && event->type() == m_deferredEvents.last()->type()) { |
| 93 // Readystatechange events are state-less so avoid repeating two ide
ntical events in a row on resume. | 93 // Readystatechange events are state-less so avoid repeating two ide
ntical events in a row on resume. |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 m_deferredEvents.append(event); | 96 m_deferredEvents.append(event); |
| 97 } else | 97 } else |
| 98 m_target->dispatchEvent(event); | 98 m_target->dispatchEvent(event); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void XMLHttpRequestProgressEventThrottle::deliverProgressEvent() | 120 void XMLHttpRequestProgressEventThrottle::deliverProgressEvent() |
| 121 { | 121 { |
| 122 if (!hasEventToDispatch()) | 122 if (!hasEventToDispatch()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 PassRefPtr<Event> event = XMLHttpRequestProgressEvent::create(EventTypeNames
::progress, m_lengthComputable, m_loaded, m_total); | 125 RefPtrWillBeRawPtr<Event> event = XMLHttpRequestProgressEvent::create(EventT
ypeNames::progress, m_lengthComputable, m_loaded, m_total); |
| 126 m_loaded = 0; | 126 m_loaded = 0; |
| 127 m_total = 0; | 127 m_total = 0; |
| 128 | 128 |
| 129 // We stop the timer as this is called when no more events are supposed to o
ccur. | 129 // We stop the timer as this is called when no more events are supposed to o
ccur. |
| 130 stop(); | 130 stop(); |
| 131 | 131 |
| 132 dispatchEvent(event); | 132 dispatchEvent(event); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvents(Timer<XMLHttpRe
questProgressEventThrottle>* timer) | 135 void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvents(Timer<XMLHttpRe
questProgressEventThrottle>* timer) |
| 136 { | 136 { |
| 137 ASSERT_UNUSED(timer, timer == &m_dispatchDeferredEventsTimer); | 137 ASSERT_UNUSED(timer, timer == &m_dispatchDeferredEventsTimer); |
| 138 ASSERT(m_deferEvents); | 138 ASSERT(m_deferEvents); |
| 139 m_deferEvents = false; | 139 m_deferEvents = false; |
| 140 | 140 |
| 141 // Take over the deferred events before dispatching them which can potential
ly add more. | 141 // Take over the deferred events before dispatching them which can potential
ly add more. |
| 142 Vector<RefPtr<Event> > deferredEvents; | 142 WillBeHeapVector<RefPtrWillBeMember<Event> > deferredEvents; |
| 143 m_deferredEvents.swap(deferredEvents); | 143 m_deferredEvents.swap(deferredEvents); |
| 144 | 144 |
| 145 RefPtr<Event> deferredProgressEvent = m_deferredProgressEvent; | 145 RefPtrWillBeRawPtr<Event> deferredProgressEvent = m_deferredProgressEvent; |
| 146 m_deferredProgressEvent = nullptr; | 146 m_deferredProgressEvent = nullptr; |
| 147 | 147 |
| 148 Vector<RefPtr<Event> >::const_iterator it = deferredEvents.begin(); | 148 WillBeHeapVector<RefPtrWillBeMember<Event> >::const_iterator it = deferredEv
ents.begin(); |
| 149 const Vector<RefPtr<Event> >::const_iterator end = deferredEvents.end(); | 149 const WillBeHeapVector<RefPtrWillBeMember<Event> >::const_iterator end = def
erredEvents.end(); |
| 150 for (; it != end; ++it) | 150 for (; it != end; ++it) |
| 151 dispatchEvent(*it); | 151 dispatchEvent(*it); |
| 152 | 152 |
| 153 // The progress event will be in the m_deferredEvents vector if the load was
finished while suspended. | 153 // The progress event will be in the m_deferredEvents vector if the load was
finished while suspended. |
| 154 // If not, just send the most up-to-date progress on resume. | 154 // If not, just send the most up-to-date progress on resume. |
| 155 if (deferredProgressEvent) | 155 if (deferredProgressEvent) |
| 156 dispatchEvent(deferredProgressEvent); | 156 dispatchEvent(deferredProgressEvent); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void XMLHttpRequestProgressEventThrottle::fired() | 159 void XMLHttpRequestProgressEventThrottle::fired() |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Do not dispatch events inline here, since ExecutionContext is iterating o
ver | 212 // Do not dispatch events inline here, since ExecutionContext is iterating o
ver |
| 213 // the list of active DOM objects to resume them, and any activated JS event
-handler | 213 // the list of active DOM objects to resume them, and any activated JS event
-handler |
| 214 // could insert new active DOM objects to the list. | 214 // could insert new active DOM objects to the list. |
| 215 // m_deferEvents is kept true until all deferred events have been dispatched
. | 215 // m_deferEvents is kept true until all deferred events have been dispatched
. |
| 216 m_dispatchDeferredEventsTimer.startOneShot(0, FROM_HERE); | 216 m_dispatchDeferredEventsTimer.startOneShot(0, FROM_HERE); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void XMLHttpRequestProgressEventThrottle::trace(Visitor* visitor) |
| 220 { |
| 221 visitor->trace(m_deferredProgressEvent); |
| 222 visitor->trace(m_deferredEvents); |
| 223 } |
| 224 |
| 219 } // namespace WebCore | 225 } // namespace WebCore |
| OLD | NEW |