2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef XMLHttpRequestProgressEventThrottle_h
28 #define XMLHttpRequestProgressEventThrottle_h
30 #include "platform/Timer.h"
31 #include "platform/heap/Handle.h"
32 #include "wtf/Forward.h"
33 #include "wtf/OwnPtr.h"
34 #include "wtf/PassRefPtr.h"
41 // This class implements the XHR2 ProgressEvent dispatching:
42 // "dispatch a progress event named progress about every 50ms or for every
43 // byte received, whichever is least frequent".
45 // readystatechange events also go through this class since ProgressEvents and
46 // readystatechange events affect each other.
48 // In the comments for this class:
49 // - "progress" event means an event named "progress"
50 // - ProgressEvent means an event using the ProgressEvent interface defined in
52 class XMLHttpRequestProgressEventThrottle final
: public GarbageCollectedFinalized
<XMLHttpRequestProgressEventThrottle
>, public TimerBase
{
54 static XMLHttpRequestProgressEventThrottle
* create(XMLHttpRequest
* eventTarget
)
56 return new XMLHttpRequestProgressEventThrottle(eventTarget
);
58 ~XMLHttpRequestProgressEventThrottle() override
;
60 enum DeferredEventAction
{
66 // Dispatches a ProgressEvent.
68 // Special treatment for events named "progress" is implemented to dispatch
69 // them at the required frequency. If this object is suspended, the given
70 // ProgressEvent overwrites the existing. I.e. only the latest one gets
71 // queued. If the timer is running, this method just updates
72 // m_lengthComputable, m_loaded and m_total. They'll be used on next
74 void dispatchProgressEvent(const AtomicString
&, bool lengthComputable
, unsigned long long loaded
, unsigned long long total
);
75 // Dispatches the given event after operation about the "progress" event
76 // depending on the value of the ProgressEventAction argument.
77 void dispatchReadyStateChangeEvent(PassRefPtrWillBeRawPtr
<Event
>, DeferredEventAction
);
82 // Need to promptly stop this timer when it is deemed finalizable.
87 explicit XMLHttpRequestProgressEventThrottle(XMLHttpRequest
*);
89 // The main purpose of this class is to throttle the "progress"
90 // ProgressEvent dispatching. This class represents such a deferred
91 // "progress" ProgressEvent.
93 static const double minimumProgressEventDispatchingIntervalInSeconds
;
95 void fired() override
;
96 void dispatchDeferredEvent();
98 // Non-Oilpan, keep a weak pointer to our XMLHttpRequest object as it is
99 // the one holding us. With Oilpan, a simple strong Member can be used -
100 // this XMLHttpRequestProgressEventThrottle (part) object dies together
101 // with the XMLHttpRequest object.
102 Member
<XMLHttpRequest
> m_target
;
104 // A slot for the deferred "progress" ProgressEvent. When multiple events
105 // arrive, only the last one is stored and others are discarded.
106 const OwnPtr
<DeferredEvent
> m_deferred
;
111 #endif // XMLHttpRequestProgressEventThrottle_h