Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: third_party/WebKit/Source/core/loader/ProgressTracker.cpp

Issue 1860743002: Add a flag to change when android's progress bar completes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add flag to include same origin iframes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/loader/ProgressTracker.h" 26 #include "core/loader/ProgressTracker.h"
27 27
28 #include "core/fetch/Resource.h"
kinuko 2016/06/08 14:26:30 ditto, probably not needed now?
Nate Chapin 2016/06/14 22:51:46 Actually, only about half of these includes are ne
28 #include "core/fetch/ResourceFetcher.h" 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/frame/Settings.h" 32 #include "core/frame/Settings.h"
32 #include "core/inspector/InspectorInstrumentation.h" 33 #include "core/inspector/InspectorInstrumentation.h"
33 #include "core/loader/DocumentLoader.h" 34 #include "core/loader/DocumentLoader.h"
34 #include "core/loader/FrameLoader.h" 35 #include "core/loader/FrameLoader.h"
35 #include "core/loader/FrameLoaderClient.h" 36 #include "core/loader/FrameLoaderClient.h"
36 #include "platform/Logging.h" 37 #include "platform/Logging.h"
37 #include "platform/network/ResourceResponse.h" 38 #include "platform/network/ResourceResponse.h"
38 #include "wtf/CurrentTime.h" 39 #include "wtf/CurrentTime.h"
39 #include "wtf/text/CString.h" 40 #include "wtf/text/CString.h"
40 41
41 using namespace std; 42 using namespace std;
42 43
43 namespace blink { 44 namespace blink {
44 45
45 // Always start progress at initialProgressValue. This helps provide feedback as 46 // Always start progress at initialProgressValue. This helps provide feedback as
46 // soon as a load starts. 47 // soon as a load starts.
47 static const double initialProgressValue = 0.1; 48 static const double initialProgressValue = 0.1;
48 49
49 // Similarly, always leave space at the end. This helps show the user that we're not done
50 // until we're done.
51 static const double finalProgressValue = 0.9; // 1.0 - initialProgressValue
52
53 static const int progressItemDefaultEstimatedLength = 1024 * 1024; 50 static const int progressItemDefaultEstimatedLength = 1024 * 1024;
54 51
55 struct ProgressItem { 52 struct ProgressItem {
56 WTF_MAKE_NONCOPYABLE(ProgressItem); USING_FAST_MALLOC(ProgressItem); 53 WTF_MAKE_NONCOPYABLE(ProgressItem); USING_FAST_MALLOC(ProgressItem);
57 public: 54 public:
58 ProgressItem(long long length) 55 ProgressItem(long long length)
kinuko 2016/06/08 14:26:30 nit: explicit
Nate Chapin 2016/06/14 22:51:46 Done.
59 : bytesReceived(0) 56 : bytesReceived(0)
60 , estimatedLength(length) { } 57 , estimatedLength(length) { }
61 58
62 long long bytesReceived; 59 long long bytesReceived;
63 long long estimatedLength; 60 long long estimatedLength;
64 }; 61 };
65 62
66 ProgressTracker* ProgressTracker::create(LocalFrame* frame) 63 ProgressTracker* ProgressTracker::create(LocalFrame* frame)
67 { 64 {
68 return new ProgressTracker(frame); 65 return new ProgressTracker(frame);
69 } 66 }
70 67
71 ProgressTracker::ProgressTracker(LocalFrame* frame) 68 ProgressTracker::ProgressTracker(LocalFrame* frame)
72 : m_frame(frame) 69 : m_frame(frame)
73 , m_mainResourceIdentifier(0)
74 , m_totalPageAndResourceBytesToLoad(0)
75 , m_totalBytesReceived(0)
76 , m_lastNotifiedProgressValue(0) 70 , m_lastNotifiedProgressValue(0)
77 , m_lastNotifiedProgressTime(0) 71 , m_lastNotifiedProgressTime(0)
78 , m_progressNotificationInterval(0.02) 72 , m_progressNotificationInterval(0.02)
79 , m_progressNotificationTimeInterval(0.1) 73 , m_progressNotificationTimeInterval(0.1)
dcheng 2016/06/08 06:54:17 Not related to your change, but do you know why th
Nate Chapin 2016/06/14 22:51:46 Correct, that's probably a WebKit-era configuratio
74 , m_finishedParsing(false)
80 , m_finalProgressChangedSent(false) 75 , m_finalProgressChangedSent(false)
81 , m_progressValue(0) 76 , m_progressValue(0)
82 { 77 {
83 } 78 }
84 79
85 ProgressTracker::~ProgressTracker() 80 ProgressTracker::~ProgressTracker()
86 { 81 {
87 } 82 }
88 83
89 DEFINE_TRACE(ProgressTracker) 84 DEFINE_TRACE(ProgressTracker)
90 { 85 {
91 visitor->trace(m_frame); 86 visitor->trace(m_frame);
92 } 87 }
93 88
94 void ProgressTracker::dispose() 89 void ProgressTracker::dispose()
95 { 90 {
96 if (m_frame->isLoading()) 91 if (m_frame->isLoading())
97 progressCompleted(); 92 progressCompleted();
98 ASSERT(!m_frame->isLoading()); 93 ASSERT(!m_frame->isLoading());
99 } 94 }
100 95
101 double ProgressTracker::estimatedProgress() const 96 double ProgressTracker::estimatedProgress() const
102 { 97 {
103 return m_progressValue; 98 return m_progressValue;
104 } 99 }
105 100
106 void ProgressTracker::reset() 101 void ProgressTracker::reset()
107 { 102 {
108 m_progressItems.clear(); 103 m_progressItems.clear();
109
110 m_totalPageAndResourceBytesToLoad = 0;
111 m_totalBytesReceived = 0;
112 m_progressValue = 0; 104 m_progressValue = 0;
113 m_lastNotifiedProgressValue = 0; 105 m_lastNotifiedProgressValue = 0;
114 m_lastNotifiedProgressTime = 0; 106 m_lastNotifiedProgressTime = 0;
115 m_finalProgressChangedSent = false; 107 m_finalProgressChangedSent = false;
108 m_finishedParsing = false;
116 } 109 }
117 110
118 void ProgressTracker::progressStarted() 111 void ProgressTracker::progressStarted()
119 { 112 {
120 if (!m_frame->isLoading()) { 113 if (!m_frame->isLoading())
121 reset();
122 m_progressValue = initialProgressValue;
123 m_frame->loader().client()->didStartLoading(NavigationToDifferentDocumen t); 114 m_frame->loader().client()->didStartLoading(NavigationToDifferentDocumen t);
124 } 115 reset();
116 m_progressValue = initialProgressValue;
125 m_frame->setIsLoading(true); 117 m_frame->setIsLoading(true);
126 InspectorInstrumentation::frameStartedLoading(m_frame); 118 InspectorInstrumentation::frameStartedLoading(m_frame);
127 } 119 }
128 120
129 void ProgressTracker::progressCompleted() 121 void ProgressTracker::progressCompleted()
130 { 122 {
131 ASSERT(m_frame->isLoading()); 123 ASSERT(m_frame->isLoading());
132 m_frame->setIsLoading(false); 124 m_frame->setIsLoading(false);
133 sendFinalProgress(); 125 sendFinalProgress();
134 reset(); 126 reset();
135 m_frame->loader().client()->didStopLoading(); 127 m_frame->loader().client()->didStopLoading();
136 InspectorInstrumentation::frameStoppedLoading(m_frame); 128 InspectorInstrumentation::frameStoppedLoading(m_frame);
137 } 129 }
138 130
139 void ProgressTracker::finishedParsing() 131 void ProgressTracker::finishedParsing()
140 { 132 {
141 if (m_frame->settings()->mainResourceOnlyProgress()) 133 m_finishedParsing = true;
142 sendFinalProgress(); 134 maybeSendProgress();
143 } 135 }
144 136
145 void ProgressTracker::sendFinalProgress() 137 void ProgressTracker::sendFinalProgress()
146 { 138 {
147 if (!m_finalProgressChangedSent) { 139 if (!m_finalProgressChangedSent) {
140 m_finalProgressChangedSent = true;
148 m_progressValue = 1; 141 m_progressValue = 1;
149 m_frame->loader().client()->progressEstimateChanged(m_progressValue); 142 m_frame->loader().client()->progressEstimateChanged(m_progressValue);
150 } 143 }
151 } 144 }
152 145
153 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource Response& response) 146 void ProgressTracker::willStartLoading(unsigned long identifier)
154 { 147 {
155 if (!m_frame->isLoading()) 148 if (!m_frame->isLoading())
156 return; 149 return;
150 if (m_frame->settings()->progressBarCompletion() != ProgressBarCompletion::L oadEvent && m_finishedParsing)
dcheng 2016/06/08 06:54:17 Maybe add a comment here? I guess this is when we
Nate Chapin 2016/06/14 22:51:46 Done.
kinuko 2016/06/16 05:59:03 The comment's not reflected on the newest patch ye
Nate Chapin 2016/06/16 20:58:51 Huh, done for real.
151 return;
152 DCHECK(!m_progressItems.get(identifier));
153 m_progressItems.set(identifier, adoptPtr(new ProgressItem(progressItemDefaul tEstimatedLength)));
154 }
157 155
158 if (m_frame->loader().provisionalDocumentLoader() && m_frame->loader().provi sionalDocumentLoader()->mainResourceIdentifier() == identifier) 156 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource Response& response)
159 m_mainResourceIdentifier = identifier; 157 {
158 ProgressItem* item = m_progressItems.get(identifier);
159 if (!item)
160 return;
160 161
161 long long estimatedLength = response.expectedContentLength(); 162 long long estimatedLength = response.expectedContentLength();
162 if (estimatedLength < 0) 163 if (estimatedLength < 0)
163 estimatedLength = progressItemDefaultEstimatedLength; 164 estimatedLength = progressItemDefaultEstimatedLength;
164 165 item->bytesReceived = 0;
165 m_totalPageAndResourceBytesToLoad += estimatedLength; 166 item->estimatedLength = estimatedLength;
166
167 if (ProgressItem* item = m_progressItems.get(identifier)) {
168 item->bytesReceived = 0;
169 item->estimatedLength = estimatedLength;
170 } else {
171 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt h)));
172 }
173 } 167 }
174 168
175 void ProgressTracker::incrementProgressForMainResourceOnly(unsigned long identif ier, int length) 169 void ProgressTracker::incrementProgress(unsigned long identifier, int length)
176 { 170 {
177 if (identifier != m_mainResourceIdentifier)
178 return;
179
180 ProgressItem* item = m_progressItems.get(identifier); 171 ProgressItem* item = m_progressItems.get(identifier);
181 if (!item) 172 if (!item)
182 return; 173 return;
183 174
184 item->bytesReceived += length; 175 item->bytesReceived += length;
185 if (item->bytesReceived > item->estimatedLength) 176 if (item->bytesReceived > item->estimatedLength)
186 item->estimatedLength *= 2; 177 item->estimatedLength = item->bytesReceived * 2;
187 double newProgress = initialProgressValue + 0.1; // +0.1 for committing 178 maybeSendProgress();
188 if (m_frame->view()->didFirstLayout())
189 newProgress += 0.2;
190 // 0.4 possible so far, allow 0.5 from bytes loaded, for a max of 0.9.
191 newProgress += ((double) item->bytesReceived / (double) item->estimatedLengt h) / 2;
192
193 if (newProgress < m_progressValue)
194 return;
195
196 m_progressValue = newProgress;
197 double now = currentTime();
198 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime;
199
200 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV alue;
201 if (notificationProgressDelta < m_progressNotificationInterval && notifiedPr ogressTimeDelta < m_progressNotificationTimeInterval)
202 return;
203 m_frame->loader().client()->progressEstimateChanged(m_progressValue);
204 m_lastNotifiedProgressValue = m_progressValue;
205 m_lastNotifiedProgressTime = now;
206 } 179 }
207 180
208 void ProgressTracker::incrementProgress(unsigned long identifier, int length) 181 void ProgressTracker::maybeSendProgress()
209 { 182 {
210 if (m_frame->settings()->mainResourceOnlyProgress()) { 183 m_progressValue = initialProgressValue + 0.1; // +0.1 for committing
211 incrementProgressForMainResourceOnly(identifier, length); 184 if (m_finishedParsing)
212 return; 185 m_progressValue += 0.2;
186
187 long long bytesReceived = 0;
188 long long estimatedBytesForPendingRequests = 0;
189 for (const auto& progressItem : m_progressItems) {
190 bytesReceived += progressItem.value->bytesReceived;
191 estimatedBytesForPendingRequests += progressItem.value->estimatedLength;
192 }
193 DCHECK_GE(estimatedBytesForPendingRequests, 0);
194 DCHECK_GE(estimatedBytesForPendingRequests, bytesReceived);
195
196 if (m_finishedParsing) {
197 if (m_frame->settings()->progressBarCompletion() == ProgressBarCompletio n::DOMContentLoaded) {
198 sendFinalProgress();
199 return;
200 }
201 if (m_frame->settings()->progressBarCompletion() != ProgressBarCompletio n::LoadEvent && estimatedBytesForPendingRequests == bytesReceived) {
202 sendFinalProgress();
203 return;
204 }
213 } 205 }
214 206
215 ProgressItem* item = m_progressItems.get(identifier); 207 double percentOfBytesReceived = !estimatedBytesForPendingRequests ? 1.0 : (d ouble)bytesReceived / (double)estimatedBytesForPendingRequests;
208 m_progressValue += percentOfBytesReceived / 2;
216 209
217 // FIXME: Can this ever happen? 210 DCHECK_GE(m_progressValue, initialProgressValue);
218 if (!item) 211 // Always leave space at the end. This helps show the user that we're not
212 // done until we're done.
213 DCHECK(m_progressValue <= 0.9);
214 if (m_progressValue < m_lastNotifiedProgressValue)
219 return; 215 return;
220 216
221 unsigned bytesReceived = length;
222 double increment, percentOfRemainingBytes;
223 long long remainingBytes, estimatedBytesForPendingRequests;
224
225 item->bytesReceived += bytesReceived;
226 if (item->bytesReceived > item->estimatedLength) {
227 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item-> estimatedLength);
228 item->estimatedLength = item->bytesReceived * 2;
229 }
230
231 int numPendingOrLoadingRequests = m_frame->document()->fetcher()->requestCou nt();
232 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP endingOrLoadingRequests;
233 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend ingRequests) - m_totalBytesReceived);
234 if (remainingBytes > 0) // Prevent divide by 0.
235 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes ;
236 else
237 percentOfRemainingBytes = 1.0;
238
239 // For documents that use WebCore's layout system, treat first layout as the half-way point.
240 bool useClampedMaxProgress = !m_frame->view()->didFirstLayout();
241 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue;
242 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes;
243 m_progressValue += increment;
244 m_progressValue = min(m_progressValue, maxProgressValue);
245 ASSERT(m_progressValue >= initialProgressValue);
246
247 m_totalBytesReceived += bytesReceived;
248
249 double now = currentTime(); 217 double now = currentTime();
250 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; 218 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime;
251 219
252 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV alue; 220 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV alue;
253 if (notificationProgressDelta >= m_progressNotificationInterval || notifiedP rogressTimeDelta >= m_progressNotificationTimeInterval) { 221 if (notificationProgressDelta >= m_progressNotificationInterval || notifiedP rogressTimeDelta >= m_progressNotificationTimeInterval) {
254 if (!m_finalProgressChangedSent) { 222 DCHECK(!m_finalProgressChangedSent);
255 if (m_progressValue == 1) 223 m_frame->loader().client()->progressEstimateChanged(m_progressValue);
256 m_finalProgressChangedSent = true; 224 m_lastNotifiedProgressValue = m_progressValue;
257 225 m_lastNotifiedProgressTime = now;
258 m_frame->loader().client()->progressEstimateChanged(m_progressValue) ;
259
260 m_lastNotifiedProgressValue = m_progressValue;
261 m_lastNotifiedProgressTime = now;
262 }
263 } 226 }
264 } 227 }
265 228
266 void ProgressTracker::completeProgress(unsigned long identifier) 229 void ProgressTracker::completeProgress(unsigned long identifier)
267 { 230 {
268 ProgressItem* item = m_progressItems.get(identifier); 231 ProgressItem* item = m_progressItems.get(identifier);
269
270 // This can happen if a load fails without receiving any response data.
271 if (!item) 232 if (!item)
272 return; 233 return;
273 234
274 // Adjust the total expected bytes to account for any overage/underage. 235 item->estimatedLength = item->bytesReceived;
275 long long delta = item->bytesReceived - item->estimatedLength; 236 maybeSendProgress();
276 m_totalPageAndResourceBytesToLoad += delta;
277
278 m_progressItems.remove(identifier);
279 } 237 }
280 238
281 } // namespace blink 239 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698