OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/loader/ProgressTracker.h" | 27 #include "core/loader/ProgressTracker.h" |
28 | 28 |
| 29 #include "core/fetch/ResourceFetcher.h" |
29 #include "core/frame/FrameView.h" | 30 #include "core/frame/FrameView.h" |
30 #include "core/frame/LocalFrame.h" | 31 #include "core/frame/LocalFrame.h" |
31 #include "core/inspector/InspectorInstrumentation.h" | 32 #include "core/inspector/InspectorInstrumentation.h" |
32 #include "core/loader/FrameLoader.h" | 33 #include "core/loader/FrameLoader.h" |
33 #include "core/loader/FrameLoaderClient.h" | 34 #include "core/loader/FrameLoaderClient.h" |
34 #include "platform/Logging.h" | 35 #include "platform/Logging.h" |
35 #include "platform/network/ResourceResponse.h" | 36 #include "platform/network/ResourceResponse.h" |
36 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
37 #include "wtf/text/CString.h" | 38 #include "wtf/text/CString.h" |
38 | 39 |
(...skipping 15 matching lines...) Expand all Loading... |
54 WTF_MAKE_NONCOPYABLE(ProgressItem); WTF_MAKE_FAST_ALLOCATED; | 55 WTF_MAKE_NONCOPYABLE(ProgressItem); WTF_MAKE_FAST_ALLOCATED; |
55 public: | 56 public: |
56 ProgressItem(long long length) | 57 ProgressItem(long long length) |
57 : bytesReceived(0) | 58 : bytesReceived(0) |
58 , estimatedLength(length) { } | 59 , estimatedLength(length) { } |
59 | 60 |
60 long long bytesReceived; | 61 long long bytesReceived; |
61 long long estimatedLength; | 62 long long estimatedLength; |
62 }; | 63 }; |
63 | 64 |
64 ProgressTracker::ProgressTracker() | 65 ProgressTracker::ProgressTracker(LocalFrame* frame) |
65 : m_totalPageAndResourceBytesToLoad(0) | 66 : m_frame(frame) |
| 67 , m_inProgress(false) |
| 68 , m_totalPageAndResourceBytesToLoad(0) |
66 , m_totalBytesReceived(0) | 69 , m_totalBytesReceived(0) |
67 , m_lastNotifiedProgressValue(0) | 70 , m_lastNotifiedProgressValue(0) |
68 , m_lastNotifiedProgressTime(0) | 71 , m_lastNotifiedProgressTime(0) |
69 , m_progressNotificationInterval(0.02) | 72 , m_progressNotificationInterval(0.02) |
70 , m_progressNotificationTimeInterval(0.1) | 73 , m_progressNotificationTimeInterval(0.1) |
71 , m_finalProgressChangedSent(false) | 74 , m_finalProgressChangedSent(false) |
72 , m_progressValue(0) | 75 , m_progressValue(0) |
73 , m_numProgressTrackedFrames(0) | |
74 { | 76 { |
75 } | 77 } |
76 | 78 |
77 ProgressTracker::~ProgressTracker() | 79 ProgressTracker::~ProgressTracker() |
78 { | 80 { |
| 81 if (m_inProgress) |
| 82 progressCompleted(); |
79 } | 83 } |
80 | 84 |
81 PassOwnPtr<ProgressTracker> ProgressTracker::create() | 85 PassOwnPtr<ProgressTracker> ProgressTracker::create(LocalFrame* frame) |
82 { | 86 { |
83 return adoptPtr(new ProgressTracker); | 87 return adoptPtr(new ProgressTracker(frame)); |
84 } | 88 } |
85 | 89 |
86 double ProgressTracker::estimatedProgress() const | 90 double ProgressTracker::estimatedProgress() const |
87 { | 91 { |
88 return m_progressValue; | 92 return m_progressValue; |
89 } | 93 } |
90 | 94 |
91 void ProgressTracker::reset() | 95 void ProgressTracker::reset() |
92 { | 96 { |
93 m_progressItems.clear(); | 97 m_progressItems.clear(); |
94 | 98 |
95 m_totalPageAndResourceBytesToLoad = 0; | 99 m_totalPageAndResourceBytesToLoad = 0; |
96 m_totalBytesReceived = 0; | 100 m_totalBytesReceived = 0; |
97 m_progressValue = 0; | 101 m_progressValue = 0; |
98 m_lastNotifiedProgressValue = 0; | 102 m_lastNotifiedProgressValue = 0; |
99 m_lastNotifiedProgressTime = 0; | 103 m_lastNotifiedProgressTime = 0; |
100 m_finalProgressChangedSent = false; | 104 m_finalProgressChangedSent = false; |
101 m_numProgressTrackedFrames = 0; | |
102 m_originatingProgressFrame = nullptr; | |
103 } | 105 } |
104 | 106 |
105 void ProgressTracker::progressStarted(LocalFrame* frame) | 107 void ProgressTracker::progressStarted() |
106 { | 108 { |
107 WTF_LOG(Progress, "Progress started (%p) - frame %p(\"%s\"), value %f, track
ed frames %d, originating frame %p", this, frame, frame->tree().uniqueName().utf
8().data(), m_progressValue, m_numProgressTrackedFrames, m_originatingProgressFr
ame.get()); | 109 if (!m_inProgress) { |
108 | |
109 if (m_numProgressTrackedFrames == 0 || m_originatingProgressFrame == frame)
{ | |
110 reset(); | 110 reset(); |
111 m_progressValue = initialProgressValue; | 111 m_progressValue = initialProgressValue; |
112 m_originatingProgressFrame = frame; | 112 m_frame->loader().client()->didStartLoading(NavigationToDifferentDocumen
t); |
113 | |
114 m_originatingProgressFrame->loader().client()->postProgressStartedNotifi
cation(NavigationToDifferentDocument); | |
115 } | 113 } |
116 m_numProgressTrackedFrames++; | 114 m_inProgress = true; |
117 InspectorInstrumentation::frameStartedLoading(frame); | 115 InspectorInstrumentation::frameStartedLoading(m_frame); |
118 } | 116 } |
119 | 117 |
120 void ProgressTracker::progressCompleted(LocalFrame* frame) | 118 void ProgressTracker::progressCompleted() |
121 { | 119 { |
122 WTF_LOG(Progress, "Progress completed (%p) - frame %p(\"%s\"), value %f, tra
cked frames %d, originating frame %p", this, frame, frame->tree().uniqueName().u
tf8().data(), m_progressValue, m_numProgressTrackedFrames, m_originatingProgress
Frame.get()); | 120 ASSERT(m_inProgress); |
123 | 121 m_inProgress = false; |
124 if (m_numProgressTrackedFrames <= 0) | |
125 return; | |
126 m_numProgressTrackedFrames--; | |
127 if (!m_numProgressTrackedFrames || m_originatingProgressFrame == frame) | |
128 finalProgressComplete(); | |
129 } | |
130 | |
131 void ProgressTracker::finalProgressComplete() | |
132 { | |
133 WTF_LOG(Progress, "Final progress complete (%p)", this); | |
134 | |
135 RefPtr<LocalFrame> frame = m_originatingProgressFrame.release(); | |
136 | |
137 // Before resetting progress value be sure to send client a least one notifi
cation | |
138 // with final progress value. | |
139 if (!m_finalProgressChangedSent) { | 122 if (!m_finalProgressChangedSent) { |
140 m_progressValue = 1; | 123 m_progressValue = 1; |
141 frame->loader().client()->postProgressEstimateChangedNotification(); | 124 m_frame->loader().client()->progressEstimateChanged(m_progressValue); |
142 } | 125 } |
143 | |
144 reset(); | 126 reset(); |
145 frame->loader().client()->postProgressFinishedNotification(); | 127 m_frame->loader().client()->didStopLoading(); |
146 InspectorInstrumentation::frameStoppedLoading(frame.get()); | 128 InspectorInstrumentation::frameStoppedLoading(m_frame); |
147 } | 129 } |
148 | 130 |
149 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource
Response& response) | 131 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource
Response& response) |
150 { | 132 { |
151 WTF_LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d,
originating frame %p", this, m_progressValue, m_numProgressTrackedFrames, m_orig
inatingProgressFrame.get()); | 133 if (!m_inProgress) |
152 | |
153 if (m_numProgressTrackedFrames <= 0) | |
154 return; | 134 return; |
155 | 135 |
156 long long estimatedLength = response.expectedContentLength(); | 136 long long estimatedLength = response.expectedContentLength(); |
157 if (estimatedLength < 0) | 137 if (estimatedLength < 0) |
158 estimatedLength = progressItemDefaultEstimatedLength; | 138 estimatedLength = progressItemDefaultEstimatedLength; |
159 | 139 |
160 m_totalPageAndResourceBytesToLoad += estimatedLength; | 140 m_totalPageAndResourceBytesToLoad += estimatedLength; |
161 | 141 |
162 if (ProgressItem* item = m_progressItems.get(identifier)) { | 142 if (ProgressItem* item = m_progressItems.get(identifier)) { |
163 item->bytesReceived = 0; | 143 item->bytesReceived = 0; |
164 item->estimatedLength = estimatedLength; | 144 item->estimatedLength = estimatedLength; |
165 } else | 145 } else |
166 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt
h))); | 146 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt
h))); |
167 } | 147 } |
168 | 148 |
169 void ProgressTracker::incrementProgress(unsigned long identifier, const char*, i
nt length) | 149 void ProgressTracker::incrementProgress(unsigned long identifier, const char*, i
nt length) |
170 { | 150 { |
171 ProgressItem* item = m_progressItems.get(identifier); | 151 ProgressItem* item = m_progressItems.get(identifier); |
172 | 152 |
173 // FIXME: Can this ever happen? | 153 // FIXME: Can this ever happen? |
174 if (!item) | 154 if (!item) |
175 return; | 155 return; |
176 | 156 |
177 RefPtr<LocalFrame> frame = m_originatingProgressFrame; | |
178 | |
179 unsigned bytesReceived = length; | 157 unsigned bytesReceived = length; |
180 double increment, percentOfRemainingBytes; | 158 double increment, percentOfRemainingBytes; |
181 long long remainingBytes, estimatedBytesForPendingRequests; | 159 long long remainingBytes, estimatedBytesForPendingRequests; |
182 | 160 |
183 item->bytesReceived += bytesReceived; | 161 item->bytesReceived += bytesReceived; |
184 if (item->bytesReceived > item->estimatedLength) { | 162 if (item->bytesReceived > item->estimatedLength) { |
185 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item->
estimatedLength); | 163 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item->
estimatedLength); |
186 item->estimatedLength = item->bytesReceived * 2; | 164 item->estimatedLength = item->bytesReceived * 2; |
187 } | 165 } |
188 | 166 |
189 int numPendingOrLoadingRequests = frame->loader().numPendingOrLoadingRequest
s(true); | 167 int numPendingOrLoadingRequests = m_frame->document()->fetcher()->requestCou
nt(); |
190 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP
endingOrLoadingRequests; | 168 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP
endingOrLoadingRequests; |
191 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend
ingRequests) - m_totalBytesReceived); | 169 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend
ingRequests) - m_totalBytesReceived); |
192 if (remainingBytes > 0) // Prevent divide by 0. | 170 if (remainingBytes > 0) // Prevent divide by 0. |
193 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes
; | 171 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes
; |
194 else | 172 else |
195 percentOfRemainingBytes = 1.0; | 173 percentOfRemainingBytes = 1.0; |
196 | 174 |
197 // For documents that use WebCore's layout system, treat first layout as the
half-way point. | 175 // For documents that use WebCore's layout system, treat first layout as the
half-way point. |
198 bool useClampedMaxProgress = !frame->view()->didFirstLayout(); | 176 bool useClampedMaxProgress = !m_frame->view()->didFirstLayout(); |
199 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; | 177 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; |
200 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; | 178 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; |
201 m_progressValue += increment; | 179 m_progressValue += increment; |
202 m_progressValue = min(m_progressValue, maxProgressValue); | 180 m_progressValue = min(m_progressValue, maxProgressValue); |
203 ASSERT(m_progressValue >= initialProgressValue); | 181 ASSERT(m_progressValue >= initialProgressValue); |
204 | 182 |
205 m_totalBytesReceived += bytesReceived; | 183 m_totalBytesReceived += bytesReceived; |
206 | 184 |
207 double now = currentTime(); | 185 double now = currentTime(); |
208 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; | 186 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; |
209 | 187 |
210 WTF_LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d",
this, m_progressValue, m_numProgressTrackedFrames); | |
211 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV
alue; | 188 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV
alue; |
212 if ((notificationProgressDelta >= m_progressNotificationInterval || | 189 if (notificationProgressDelta >= m_progressNotificationInterval || notifiedP
rogressTimeDelta >= m_progressNotificationTimeInterval) { |
213 notifiedProgressTimeDelta >= m_progressNotificationTimeInterval) && | |
214 m_numProgressTrackedFrames > 0) { | |
215 if (!m_finalProgressChangedSent) { | 190 if (!m_finalProgressChangedSent) { |
216 if (m_progressValue == 1) | 191 if (m_progressValue == 1) |
217 m_finalProgressChangedSent = true; | 192 m_finalProgressChangedSent = true; |
218 | 193 |
219 frame->loader().client()->postProgressEstimateChangedNotification(); | 194 m_frame->loader().client()->progressEstimateChanged(m_progressValue)
; |
220 | 195 |
221 m_lastNotifiedProgressValue = m_progressValue; | 196 m_lastNotifiedProgressValue = m_progressValue; |
222 m_lastNotifiedProgressTime = now; | 197 m_lastNotifiedProgressTime = now; |
223 } | 198 } |
224 } | 199 } |
225 } | 200 } |
226 | 201 |
227 void ProgressTracker::completeProgress(unsigned long identifier) | 202 void ProgressTracker::completeProgress(unsigned long identifier) |
228 { | 203 { |
229 ProgressItem* item = m_progressItems.get(identifier); | 204 ProgressItem* item = m_progressItems.get(identifier); |
230 | 205 |
231 // This can happen if a load fails without receiving any response data. | 206 // This can happen if a load fails without receiving any response data. |
232 if (!item) | 207 if (!item) |
233 return; | 208 return; |
234 | 209 |
235 // Adjust the total expected bytes to account for any overage/underage. | 210 // Adjust the total expected bytes to account for any overage/underage. |
236 long long delta = item->bytesReceived - item->estimatedLength; | 211 long long delta = item->bytesReceived - item->estimatedLength; |
237 m_totalPageAndResourceBytesToLoad += delta; | 212 m_totalPageAndResourceBytesToLoad += delta; |
238 | 213 |
239 m_progressItems.remove(identifier); | 214 m_progressItems.remove(identifier); |
240 } | 215 } |
241 | 216 |
242 } | 217 } |
OLD | NEW |