| 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" | |
| 30 #include "core/frame/FrameView.h" | 29 #include "core/frame/FrameView.h" |
| 31 #include "core/frame/LocalFrame.h" | 30 #include "core/frame/LocalFrame.h" |
| 32 #include "core/inspector/InspectorInstrumentation.h" | 31 #include "core/inspector/InspectorInstrumentation.h" |
| 33 #include "core/loader/FrameLoader.h" | 32 #include "core/loader/FrameLoader.h" |
| 34 #include "core/loader/FrameLoaderClient.h" | 33 #include "core/loader/FrameLoaderClient.h" |
| 35 #include "platform/Logging.h" | 34 #include "platform/Logging.h" |
| 36 #include "platform/network/ResourceResponse.h" | 35 #include "platform/network/ResourceResponse.h" |
| 37 #include "wtf/CurrentTime.h" | 36 #include "wtf/CurrentTime.h" |
| 38 #include "wtf/text/CString.h" | 37 #include "wtf/text/CString.h" |
| 39 | 38 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 55 WTF_MAKE_NONCOPYABLE(ProgressItem); WTF_MAKE_FAST_ALLOCATED; | 54 WTF_MAKE_NONCOPYABLE(ProgressItem); WTF_MAKE_FAST_ALLOCATED; |
| 56 public: | 55 public: |
| 57 ProgressItem(long long length) | 56 ProgressItem(long long length) |
| 58 : bytesReceived(0) | 57 : bytesReceived(0) |
| 59 , estimatedLength(length) { } | 58 , estimatedLength(length) { } |
| 60 | 59 |
| 61 long long bytesReceived; | 60 long long bytesReceived; |
| 62 long long estimatedLength; | 61 long long estimatedLength; |
| 63 }; | 62 }; |
| 64 | 63 |
| 65 ProgressTracker::ProgressTracker(LocalFrame* frame) | 64 ProgressTracker::ProgressTracker() |
| 66 : m_frame(frame) | 65 : m_totalPageAndResourceBytesToLoad(0) |
| 67 , m_inProgress(false) | |
| 68 , m_totalPageAndResourceBytesToLoad(0) | |
| 69 , m_totalBytesReceived(0) | 66 , m_totalBytesReceived(0) |
| 70 , m_lastNotifiedProgressValue(0) | 67 , m_lastNotifiedProgressValue(0) |
| 71 , m_lastNotifiedProgressTime(0) | 68 , m_lastNotifiedProgressTime(0) |
| 72 , m_progressNotificationInterval(0.02) | 69 , m_progressNotificationInterval(0.02) |
| 73 , m_progressNotificationTimeInterval(0.1) | 70 , m_progressNotificationTimeInterval(0.1) |
| 74 , m_finalProgressChangedSent(false) | 71 , m_finalProgressChangedSent(false) |
| 75 , m_progressValue(0) | 72 , m_progressValue(0) |
| 73 , m_numProgressTrackedFrames(0) |
| 76 { | 74 { |
| 77 } | 75 } |
| 78 | 76 |
| 79 ProgressTracker::~ProgressTracker() | 77 ProgressTracker::~ProgressTracker() |
| 80 { | 78 { |
| 81 if (m_inProgress) | |
| 82 progressCompleted(); | |
| 83 } | 79 } |
| 84 | 80 |
| 85 PassOwnPtr<ProgressTracker> ProgressTracker::create(LocalFrame* frame) | 81 PassOwnPtr<ProgressTracker> ProgressTracker::create() |
| 86 { | 82 { |
| 87 return adoptPtr(new ProgressTracker(frame)); | 83 return adoptPtr(new ProgressTracker); |
| 88 } | 84 } |
| 89 | 85 |
| 90 double ProgressTracker::estimatedProgress() const | 86 double ProgressTracker::estimatedProgress() const |
| 91 { | 87 { |
| 92 return m_progressValue; | 88 return m_progressValue; |
| 93 } | 89 } |
| 94 | 90 |
| 95 void ProgressTracker::reset() | 91 void ProgressTracker::reset() |
| 96 { | 92 { |
| 97 m_progressItems.clear(); | 93 m_progressItems.clear(); |
| 98 | 94 |
| 99 m_totalPageAndResourceBytesToLoad = 0; | 95 m_totalPageAndResourceBytesToLoad = 0; |
| 100 m_totalBytesReceived = 0; | 96 m_totalBytesReceived = 0; |
| 101 m_progressValue = 0; | 97 m_progressValue = 0; |
| 102 m_lastNotifiedProgressValue = 0; | 98 m_lastNotifiedProgressValue = 0; |
| 103 m_lastNotifiedProgressTime = 0; | 99 m_lastNotifiedProgressTime = 0; |
| 104 m_finalProgressChangedSent = false; | 100 m_finalProgressChangedSent = false; |
| 101 m_numProgressTrackedFrames = 0; |
| 102 m_originatingProgressFrame = nullptr; |
| 105 } | 103 } |
| 106 | 104 |
| 107 void ProgressTracker::progressStarted() | 105 void ProgressTracker::progressStarted(LocalFrame* frame) |
| 108 { | 106 { |
| 109 if (!m_inProgress) { | 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()); |
| 108 |
| 109 if (m_numProgressTrackedFrames == 0 || m_originatingProgressFrame == frame)
{ |
| 110 reset(); | 110 reset(); |
| 111 m_progressValue = initialProgressValue; | 111 m_progressValue = initialProgressValue; |
| 112 m_frame->loader().client()->didStartLoading(NavigationToDifferentDocumen
t); | 112 m_originatingProgressFrame = frame; |
| 113 |
| 114 m_originatingProgressFrame->loader().client()->postProgressStartedNotifi
cation(NavigationToDifferentDocument); |
| 113 } | 115 } |
| 114 m_inProgress = true; | 116 m_numProgressTrackedFrames++; |
| 115 InspectorInstrumentation::frameStartedLoading(m_frame); | 117 InspectorInstrumentation::frameStartedLoading(frame); |
| 116 } | 118 } |
| 117 | 119 |
| 118 void ProgressTracker::progressCompleted() | 120 void ProgressTracker::progressCompleted(LocalFrame* frame) |
| 119 { | 121 { |
| 120 ASSERT(m_inProgress); | 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()); |
| 121 m_inProgress = false; | 123 |
| 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. |
| 122 if (!m_finalProgressChangedSent) { | 139 if (!m_finalProgressChangedSent) { |
| 123 m_progressValue = 1; | 140 m_progressValue = 1; |
| 124 m_frame->loader().client()->progressEstimateChanged(m_progressValue); | 141 frame->loader().client()->postProgressEstimateChangedNotification(); |
| 125 } | 142 } |
| 143 |
| 126 reset(); | 144 reset(); |
| 127 m_frame->loader().client()->didStopLoading(); | 145 frame->loader().client()->postProgressFinishedNotification(); |
| 128 InspectorInstrumentation::frameStoppedLoading(m_frame); | 146 InspectorInstrumentation::frameStoppedLoading(frame.get()); |
| 129 } | 147 } |
| 130 | 148 |
| 131 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource
Response& response) | 149 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource
Response& response) |
| 132 { | 150 { |
| 133 if (!m_inProgress) | 151 WTF_LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d,
originating frame %p", this, m_progressValue, m_numProgressTrackedFrames, m_orig
inatingProgressFrame.get()); |
| 152 |
| 153 if (m_numProgressTrackedFrames <= 0) |
| 134 return; | 154 return; |
| 135 | 155 |
| 136 long long estimatedLength = response.expectedContentLength(); | 156 long long estimatedLength = response.expectedContentLength(); |
| 137 if (estimatedLength < 0) | 157 if (estimatedLength < 0) |
| 138 estimatedLength = progressItemDefaultEstimatedLength; | 158 estimatedLength = progressItemDefaultEstimatedLength; |
| 139 | 159 |
| 140 m_totalPageAndResourceBytesToLoad += estimatedLength; | 160 m_totalPageAndResourceBytesToLoad += estimatedLength; |
| 141 | 161 |
| 142 if (ProgressItem* item = m_progressItems.get(identifier)) { | 162 if (ProgressItem* item = m_progressItems.get(identifier)) { |
| 143 item->bytesReceived = 0; | 163 item->bytesReceived = 0; |
| 144 item->estimatedLength = estimatedLength; | 164 item->estimatedLength = estimatedLength; |
| 145 } else | 165 } else |
| 146 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt
h))); | 166 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt
h))); |
| 147 } | 167 } |
| 148 | 168 |
| 149 void ProgressTracker::incrementProgress(unsigned long identifier, const char*, i
nt length) | 169 void ProgressTracker::incrementProgress(unsigned long identifier, const char*, i
nt length) |
| 150 { | 170 { |
| 151 ProgressItem* item = m_progressItems.get(identifier); | 171 ProgressItem* item = m_progressItems.get(identifier); |
| 152 | 172 |
| 153 // FIXME: Can this ever happen? | 173 // FIXME: Can this ever happen? |
| 154 if (!item) | 174 if (!item) |
| 155 return; | 175 return; |
| 156 | 176 |
| 177 RefPtr<LocalFrame> frame = m_originatingProgressFrame; |
| 178 |
| 157 unsigned bytesReceived = length; | 179 unsigned bytesReceived = length; |
| 158 double increment, percentOfRemainingBytes; | 180 double increment, percentOfRemainingBytes; |
| 159 long long remainingBytes, estimatedBytesForPendingRequests; | 181 long long remainingBytes, estimatedBytesForPendingRequests; |
| 160 | 182 |
| 161 item->bytesReceived += bytesReceived; | 183 item->bytesReceived += bytesReceived; |
| 162 if (item->bytesReceived > item->estimatedLength) { | 184 if (item->bytesReceived > item->estimatedLength) { |
| 163 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item->
estimatedLength); | 185 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item->
estimatedLength); |
| 164 item->estimatedLength = item->bytesReceived * 2; | 186 item->estimatedLength = item->bytesReceived * 2; |
| 165 } | 187 } |
| 166 | 188 |
| 167 int numPendingOrLoadingRequests = m_frame->document()->fetcher()->requestCou
nt(); | 189 int numPendingOrLoadingRequests = frame->loader().numPendingOrLoadingRequest
s(true); |
| 168 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP
endingOrLoadingRequests; | 190 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP
endingOrLoadingRequests; |
| 169 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend
ingRequests) - m_totalBytesReceived); | 191 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend
ingRequests) - m_totalBytesReceived); |
| 170 if (remainingBytes > 0) // Prevent divide by 0. | 192 if (remainingBytes > 0) // Prevent divide by 0. |
| 171 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes
; | 193 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes
; |
| 172 else | 194 else |
| 173 percentOfRemainingBytes = 1.0; | 195 percentOfRemainingBytes = 1.0; |
| 174 | 196 |
| 175 // For documents that use WebCore's layout system, treat first layout as the
half-way point. | 197 // For documents that use WebCore's layout system, treat first layout as the
half-way point. |
| 176 bool useClampedMaxProgress = !m_frame->view()->didFirstLayout(); | 198 bool useClampedMaxProgress = !frame->view()->didFirstLayout(); |
| 177 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; | 199 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; |
| 178 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; | 200 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; |
| 179 m_progressValue += increment; | 201 m_progressValue += increment; |
| 180 m_progressValue = min(m_progressValue, maxProgressValue); | 202 m_progressValue = min(m_progressValue, maxProgressValue); |
| 181 ASSERT(m_progressValue >= initialProgressValue); | 203 ASSERT(m_progressValue >= initialProgressValue); |
| 182 | 204 |
| 183 m_totalBytesReceived += bytesReceived; | 205 m_totalBytesReceived += bytesReceived; |
| 184 | 206 |
| 185 double now = currentTime(); | 207 double now = currentTime(); |
| 186 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; | 208 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; |
| 187 | 209 |
| 210 WTF_LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d",
this, m_progressValue, m_numProgressTrackedFrames); |
| 188 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV
alue; | 211 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV
alue; |
| 189 if (notificationProgressDelta >= m_progressNotificationInterval || notifiedP
rogressTimeDelta >= m_progressNotificationTimeInterval) { | 212 if ((notificationProgressDelta >= m_progressNotificationInterval || |
| 213 notifiedProgressTimeDelta >= m_progressNotificationTimeInterval) && |
| 214 m_numProgressTrackedFrames > 0) { |
| 190 if (!m_finalProgressChangedSent) { | 215 if (!m_finalProgressChangedSent) { |
| 191 if (m_progressValue == 1) | 216 if (m_progressValue == 1) |
| 192 m_finalProgressChangedSent = true; | 217 m_finalProgressChangedSent = true; |
| 193 | 218 |
| 194 m_frame->loader().client()->progressEstimateChanged(m_progressValue)
; | 219 frame->loader().client()->postProgressEstimateChangedNotification(); |
| 195 | 220 |
| 196 m_lastNotifiedProgressValue = m_progressValue; | 221 m_lastNotifiedProgressValue = m_progressValue; |
| 197 m_lastNotifiedProgressTime = now; | 222 m_lastNotifiedProgressTime = now; |
| 198 } | 223 } |
| 199 } | 224 } |
| 200 } | 225 } |
| 201 | 226 |
| 202 void ProgressTracker::completeProgress(unsigned long identifier) | 227 void ProgressTracker::completeProgress(unsigned long identifier) |
| 203 { | 228 { |
| 204 ProgressItem* item = m_progressItems.get(identifier); | 229 ProgressItem* item = m_progressItems.get(identifier); |
| 205 | 230 |
| 206 // This can happen if a load fails without receiving any response data. | 231 // This can happen if a load fails without receiving any response data. |
| 207 if (!item) | 232 if (!item) |
| 208 return; | 233 return; |
| 209 | 234 |
| 210 // Adjust the total expected bytes to account for any overage/underage. | 235 // Adjust the total expected bytes to account for any overage/underage. |
| 211 long long delta = item->bytesReceived - item->estimatedLength; | 236 long long delta = item->bytesReceived - item->estimatedLength; |
| 212 m_totalPageAndResourceBytesToLoad += delta; | 237 m_totalPageAndResourceBytesToLoad += delta; |
| 213 | 238 |
| 214 m_progressItems.remove(identifier); | 239 m_progressItems.remove(identifier); |
| 215 } | 240 } |
| 216 | 241 |
| 217 } | 242 } |
| OLD | NEW |