OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> | 2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> |
3 * All right reserved. | 3 * All right reserved. |
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 20 matching lines...) Expand all Loading... |
31 #include "wtf/PassRefPtr.h" | 31 #include "wtf/PassRefPtr.h" |
32 #include "wtf/Vector.h" | 32 #include "wtf/Vector.h" |
33 | 33 |
34 namespace WebCore { | 34 namespace WebCore { |
35 | 35 |
36 class Event; | 36 class Event; |
37 class EventTarget; | 37 class EventTarget; |
38 | 38 |
39 enum ProgressEventAction { | 39 enum ProgressEventAction { |
40 DoNotFlushProgressEvent, | 40 DoNotFlushProgressEvent, |
| 41 FlushDeferredProgressEvent, |
41 FlushProgressEvent | 42 FlushProgressEvent |
42 }; | 43 }; |
43 | 44 |
44 // This implements the XHR2 progress event dispatching: "dispatch a progress eve
nt called progress | 45 // This implements the XHR2 progress event dispatching: "dispatch a progress eve
nt called progress |
45 // about every 50ms or for every byte received, whichever is least frequent". | 46 // about every 50ms or for every byte received, whichever is least frequent". |
46 class XMLHttpRequestProgressEventThrottle : public TimerBase { | 47 class XMLHttpRequestProgressEventThrottle : public TimerBase { |
47 public: | 48 public: |
48 explicit XMLHttpRequestProgressEventThrottle(EventTarget*); | 49 explicit XMLHttpRequestProgressEventThrottle(EventTarget*); |
49 virtual ~XMLHttpRequestProgressEventThrottle(); | 50 virtual ~XMLHttpRequestProgressEventThrottle(); |
50 | 51 |
51 void dispatchProgressEvent(bool lengthComputable, unsigned long long loaded,
unsigned long long total); | 52 void dispatchProgressEvent(bool lengthComputable, unsigned long long loaded,
unsigned long long total); |
52 void dispatchReadyStateChangeEvent(PassRefPtr<Event>, ProgressEventAction =
DoNotFlushProgressEvent); | 53 void dispatchReadyStateChangeEvent(PassRefPtr<Event>, ProgressEventAction =
DoNotFlushProgressEvent); |
53 void dispatchEvent(PassRefPtr<Event>); | 54 void dispatchEvent(PassRefPtr<Event>); |
54 void dispatchEventAndLoadEnd(PassRefPtr<Event>); | 55 void dispatchEventAndLoadEnd(PassRefPtr<Event>); |
55 | 56 |
56 void suspend(); | 57 void suspend(); |
57 void resume(); | 58 void resume(); |
58 | 59 |
59 private: | 60 private: |
60 static const double minimumProgressEventDispatchingIntervalInSeconds; | 61 static const double minimumProgressEventDispatchingIntervalInSeconds; |
61 | 62 |
62 virtual void fired(); | 63 virtual void fired(); |
63 void dispatchDeferredEvents(Timer<XMLHttpRequestProgressEventThrottle>*); | 64 void dispatchDeferredEvents(Timer<XMLHttpRequestProgressEventThrottle>*); |
64 void flushProgressEvent(); | 65 bool flushDeferredProgressEvent(); |
| 66 void deliverProgressEvent(); |
65 | 67 |
66 bool hasEventToDispatch() const; | 68 bool hasEventToDispatch() const; |
67 | 69 |
68 // Weak pointer to our XMLHttpRequest object as it is the one holding us. | 70 // Weak pointer to our XMLHttpRequest object as it is the one holding us. |
69 EventTarget* m_target; | 71 EventTarget* m_target; |
70 | 72 |
71 bool m_lengthComputable; | 73 bool m_lengthComputable; |
72 unsigned long long m_loaded; | 74 unsigned long long m_loaded; |
73 unsigned long long m_total; | 75 unsigned long long m_total; |
74 | 76 |
75 bool m_deferEvents; | 77 bool m_deferEvents; |
76 RefPtr<Event> m_deferredProgressEvent; | 78 RefPtr<Event> m_deferredProgressEvent; |
77 Vector<RefPtr<Event> > m_deferredEvents; | 79 Vector<RefPtr<Event> > m_deferredEvents; |
78 Timer<XMLHttpRequestProgressEventThrottle> m_dispatchDeferredEventsTimer; | 80 Timer<XMLHttpRequestProgressEventThrottle> m_dispatchDeferredEventsTimer; |
79 }; | 81 }; |
80 | 82 |
81 } // namespace WebCore | 83 } // namespace WebCore |
82 | 84 |
83 #endif // XMLHttpRequestProgressEventThrottle_h | 85 #endif // XMLHttpRequestProgressEventThrottle_h |
OLD | NEW |