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 10 matching lines...) Expand all Loading... |
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h" | 28 #include "core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h" |
29 | 29 |
30 #include "core/EventTypeNames.h" | 30 #include "core/EventTypeNames.h" |
31 #include "core/events/EventTarget.h" | 31 #include "core/xmlhttprequest/XMLHttpRequest.h" |
32 #include "core/xmlhttprequest/XMLHttpRequestProgressEvent.h" | 32 #include "core/xmlhttprequest/XMLHttpRequestProgressEvent.h" |
33 #include "wtf/Assertions.h" | 33 #include "wtf/Assertions.h" |
34 #include "wtf/text/AtomicString.h" | 34 #include "wtf/text/AtomicString.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 class XMLHttpRequestProgressEventThrottle::DeferredEvent { | 38 class XMLHttpRequestProgressEventThrottle::DeferredEvent { |
39 public: | 39 public: |
40 DeferredEvent() { clear(); } | 40 DeferredEvent() { clear(); } |
41 void set(bool lengthComputable, unsigned long long loaded, unsigned long lon
g total) | 41 void set(bool lengthComputable, unsigned long long loaded, unsigned long lon
g total) |
(...skipping 17 matching lines...) Expand all Loading... |
59 | 59 |
60 private: | 60 private: |
61 unsigned long long m_loaded; | 61 unsigned long long m_loaded; |
62 unsigned long long m_total; | 62 unsigned long long m_total; |
63 bool m_isDeferred; | 63 bool m_isDeferred; |
64 bool m_lengthComputable; | 64 bool m_lengthComputable; |
65 }; | 65 }; |
66 | 66 |
67 const double XMLHttpRequestProgressEventThrottle::minimumProgressEventDispatchin
gIntervalInSeconds = .05; // 50 ms per specification. | 67 const double XMLHttpRequestProgressEventThrottle::minimumProgressEventDispatchin
gIntervalInSeconds = .05; // 50 ms per specification. |
68 | 68 |
69 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(EventTa
rget* target) | 69 XMLHttpRequestProgressEventThrottle::XMLHttpRequestProgressEventThrottle(XMLHttp
Request* target) |
70 : m_target(target) | 70 : m_target(target) |
71 , m_deferred(adoptPtr(new DeferredEvent)) | 71 , m_deferred(adoptPtr(new DeferredEvent)) |
72 { | 72 { |
73 ASSERT(target); | 73 ASSERT(target); |
74 } | 74 } |
75 | 75 |
76 XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle() | 76 XMLHttpRequestProgressEventThrottle::~XMLHttpRequestProgressEventThrottle() |
77 { | 77 { |
78 } | 78 } |
79 | 79 |
80 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicStri
ng& type, bool lengthComputable, unsigned long long loaded, unsigned long long t
otal) | 80 void XMLHttpRequestProgressEventThrottle::dispatchProgressEvent(const AtomicStri
ng& type, bool lengthComputable, unsigned long long loaded, unsigned long long t
otal) |
81 { | 81 { |
82 // Given that ResourceDispatcher doesn't deliver an event when suspended, | 82 // Given that ResourceDispatcher doesn't deliver an event when suspended, |
83 // we don't have to worry about event dispatching while suspended. | 83 // we don't have to worry about event dispatching while suspended. |
84 if (type != EventTypeNames::progress) { | 84 if (type != EventTypeNames::progress) { |
85 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length
Computable, loaded, total)); | 85 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length
Computable, loaded, total)); |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 if (isActive()) { | 89 if (isActive()) { |
90 m_deferred->set(lengthComputable, loaded, total); | 90 m_deferred->set(lengthComputable, loaded, total); |
91 } else { | 91 } else { |
92 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length
Computable, loaded, total)); | 92 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(type, length
Computable, loaded, total)); |
93 startOneShot(minimumProgressEventDispatchingIntervalInSeconds, FROM_HERE
); | 93 startOneShot(minimumProgressEventDispatchingIntervalInSeconds, FROM_HERE
); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP
trWillBeRawPtr<Event> event, DeferredEventAction action) | 97 void XMLHttpRequestProgressEventThrottle::dispatchReadyStateChangeEvent(PassRefP
trWillBeRawPtr<Event> event, DeferredEventAction action) |
98 { | 98 { |
| 99 XMLHttpRequest::State state = m_target->readyState(); |
99 // Given that ResourceDispatcher doesn't deliver an event when suspended, | 100 // Given that ResourceDispatcher doesn't deliver an event when suspended, |
100 // we don't have to worry about event dispatching while suspended. | 101 // we don't have to worry about event dispatching while suspended. |
101 if (action == Flush) { | 102 if (action == Flush) { |
102 dispatchDeferredEvent(); | 103 dispatchDeferredEvent(); |
| 104 // |m_target| is protected by the caller. |
103 stop(); | 105 stop(); |
104 } else if (action == Clear) { | 106 } else if (action == Clear) { |
105 m_deferred->clear(); | 107 m_deferred->clear(); |
106 stop(); | 108 stop(); |
107 } | 109 } |
108 | 110 |
109 m_target->dispatchEvent(event); | 111 if (state == m_target->readyState()) { |
| 112 // We don't dispatch the event when an event handler associated with |
| 113 // the previously dispatched event changes the readyState (e.g. when |
| 114 // the event handler calls xhr.abort()). In such cases a |
| 115 // readystatechange should have been already dispatched if necessary. |
| 116 m_target->dispatchEvent(event); |
| 117 } |
110 } | 118 } |
111 | 119 |
112 void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvent() | 120 void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvent() |
113 { | 121 { |
114 if (m_deferred->isDeferred()) { | 122 if (m_deferred->isDeferred()) { |
115 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNam
es::progress, m_deferred->lengthComputable(), m_deferred->loaded(), m_deferred->
total())); | 123 m_target->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNam
es::progress, m_deferred->lengthComputable(), m_deferred->loaded(), m_deferred->
total())); |
116 m_deferred->clear(); | 124 m_deferred->clear(); |
117 } | 125 } |
118 } | 126 } |
119 | 127 |
(...skipping 26 matching lines...) Expand all Loading... |
146 // event-handler could insert new active DOM objects to the list. | 154 // event-handler could insert new active DOM objects to the list. |
147 startOneShot(0, FROM_HERE); | 155 startOneShot(0, FROM_HERE); |
148 } | 156 } |
149 | 157 |
150 DEFINE_TRACE(XMLHttpRequestProgressEventThrottle) | 158 DEFINE_TRACE(XMLHttpRequestProgressEventThrottle) |
151 { | 159 { |
152 visitor->trace(m_target); | 160 visitor->trace(m_target); |
153 } | 161 } |
154 | 162 |
155 } // namespace blink | 163 } // namespace blink |
OLD | NEW |