OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
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 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 return; | 173 return; |
174 if (isFinishing()) { | 174 if (isFinishing()) { |
175 releaseResources(); | 175 releaseResources(); |
176 return; | 176 return; |
177 } | 177 } |
178 | 178 |
179 ResourceError nonNullError = error.isNull() ? ResourceError::cancelledError( m_resource->lastResourceRequest().url()) : error; | 179 ResourceError nonNullError = error.isNull() ? ResourceError::cancelledError( m_resource->lastResourceRequest().url()) : error; |
180 | 180 |
181 WTF_LOG(ResourceLoading, "Cancelled load of '%s'.\n", m_resource->url().getS tring().latin1().data()); | 181 WTF_LOG(ResourceLoading, "Cancelled load of '%s'.\n", m_resource->url().getS tring().latin1().data()); |
182 m_state = ConnectionStateCanceled; | 182 m_state = ConnectionStateCanceled; |
183 m_resource->setResourceError(nonNullError); | |
184 | 183 |
185 // If we don't immediately clear m_loader when cancelling, we might get | 184 // If we don't immediately clear m_loader when cancelling, we might get |
186 // unexpected reentrancy. m_resource->error() can trigger JS events, which | 185 // unexpected reentrancy. m_resource->error() can trigger JS events, which |
187 // could start a modal dialog. Normally, a modal dialog would defer loading | 186 // could start a modal dialog. Normally, a modal dialog would defer loading |
188 // and prevent receiving messages for a cancelled ResourceLoader, but | 187 // and prevent receiving messages for a cancelled ResourceLoader, but |
189 // m_fetcher->didFailLoading() severs the connection by which all of a | 188 // m_fetcher->didFailLoading() severs the connection by which all of a |
190 // page's loads are deferred. A response can then arrive, see m_state | 189 // page's loads are deferred. A response can then arrive, see m_state |
191 // is ConnectionStateCanceled, and ASSERT or break in other ways. | 190 // is ConnectionStateCanceled, and ASSERT or break in other ways. |
192 if (m_loader) { | 191 if (m_loader) { |
193 m_loader->cancel(); | 192 m_loader->cancel(); |
194 m_loader.clear(); | 193 m_loader.clear(); |
195 } | 194 } |
196 | 195 |
197 if (!m_notifiedLoadComplete) { | 196 if (!m_notifiedLoadComplete) { |
198 m_notifiedLoadComplete = true; | 197 m_notifiedLoadComplete = true; |
199 m_fetcher->didFailLoading(m_resource.get(), nonNullError); | 198 m_fetcher->didFailLoading(m_resource.get(), nonNullError); |
200 } | 199 } |
201 | 200 |
202 if (m_state != ConnectionStateReleased) | 201 if (m_state != ConnectionStateReleased) |
203 m_resource->error(Resource::LoadError); | 202 m_resource->error(nonNullError); |
204 if (m_state != ConnectionStateReleased) | 203 if (m_state != ConnectionStateReleased) |
205 releaseResources(); | 204 releaseResources(); |
206 } | 205 } |
207 | 206 |
208 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR equest, const WebURLResponse& passedRedirectResponse) | 207 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR equest, const WebURLResponse& passedRedirectResponse) |
209 { | 208 { |
210 ASSERT(m_state != ConnectionStateReleased); | 209 ASSERT(m_state != ConnectionStateReleased); |
211 ASSERT(!passedNewRequest.isNull()); | 210 ASSERT(!passedNewRequest.isNull()); |
212 ASSERT(!passedRedirectResponse.isNull()); | 211 ASSERT(!passedRedirectResponse.isNull()); |
213 | 212 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 m_resource->responseReceived(resourceResponse, handle.release()); | 279 m_resource->responseReceived(resourceResponse, handle.release()); |
281 if (m_state == ConnectionStateReleased) | 280 if (m_state == ConnectionStateReleased) |
282 return; | 281 return; |
283 | 282 |
284 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); | 283 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); |
285 if (m_state == ConnectionStateReleased) | 284 if (m_state == ConnectionStateReleased) |
286 return; | 285 return; |
287 | 286 |
288 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) | 287 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) |
289 return; | 288 return; |
290 | |
291 if (!m_notifiedLoadComplete) { | |
Nate Chapin
2016/04/28 18:10:27
This block is redundant with cancel()
| |
292 m_notifiedLoadComplete = true; | |
293 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(resourceResponse.url())); | |
294 } | |
295 | |
296 ASSERT(m_state != ConnectionStateReleased); | |
297 m_resource->error(Resource::LoadError); | |
298 cancel(ResourceError::cancelledError(resourceResponse.url())); | 289 cancel(ResourceError::cancelledError(resourceResponse.url())); |
299 } | 290 } |
300 | 291 |
301 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response) | 292 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response) |
302 { | 293 { |
303 didReceiveResponse(loader, response, nullptr); | 294 didReceiveResponse(loader, response, nullptr); |
304 } | 295 } |
305 | 296 |
306 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength) | 297 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength) |
307 { | 298 { |
(...skipping 14 matching lines...) Expand all Loading... | |
322 RELEASE_ASSERT(length >= 0); | 313 RELEASE_ASSERT(length >= 0); |
323 m_resource->appendData(data, length); | 314 m_resource->appendData(data, length); |
324 } | 315 } |
325 | 316 |
326 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t encodedDataLength) | 317 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t encodedDataLength) |
327 { | 318 { |
328 | 319 |
329 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse || m_state == Conn ectionStateReceivingData); | 320 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse || m_state == Conn ectionStateReceivingData); |
330 m_state = ConnectionStateFinishedLoading; | 321 m_state = ConnectionStateFinishedLoading; |
331 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().getString().lat in1().data()); | 322 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().getString().lat in1().data()); |
332 | |
333 m_resource->setLoadFinishTime(finishTime); | |
334 didFinishLoadingOnePart(finishTime, encodedDataLength); | 323 didFinishLoadingOnePart(finishTime, encodedDataLength); |
335 if (m_state == ConnectionStateReleased) | 324 if (m_state == ConnectionStateReleased) |
336 return; | 325 return; |
337 m_resource->finish(); | 326 m_resource->finish(finishTime); |
338 | 327 |
339 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release | 328 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release |
340 // the resources a second time, they have been released by cancel. | 329 // the resources a second time, they have been released by cancel. |
341 if (m_state == ConnectionStateReleased) | 330 if (m_state == ConnectionStateReleased) |
342 return; | 331 return; |
343 releaseResources(); | 332 releaseResources(); |
344 } | 333 } |
345 | 334 |
346 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) | 335 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) |
347 { | 336 { |
348 | 337 |
349 ASSERT(m_state != ConnectionStateReleased); | 338 ASSERT(m_state != ConnectionStateReleased); |
350 m_state = ConnectionStateFailed; | 339 m_state = ConnectionStateFailed; |
351 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().getStri ng().latin1().data()); | 340 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().getStri ng().latin1().data()); |
352 | |
353 m_resource->setResourceError(error); | |
354 | |
355 if (!m_notifiedLoadComplete) { | 341 if (!m_notifiedLoadComplete) { |
356 m_notifiedLoadComplete = true; | 342 m_notifiedLoadComplete = true; |
357 m_fetcher->didFailLoading(m_resource.get(), error); | 343 m_fetcher->didFailLoading(m_resource.get(), error); |
358 } | 344 } |
359 if (m_state == ConnectionStateReleased) | 345 if (m_state == ConnectionStateReleased) |
360 return; | 346 return; |
361 | 347 |
362 m_resource->error(Resource::LoadError); | 348 m_resource->error(error); |
363 | 349 |
364 if (m_state == ConnectionStateReleased) | 350 if (m_state == ConnectionStateReleased) |
365 return; | 351 return; |
366 | 352 |
367 releaseResources(); | 353 releaseResources(); |
368 } | 354 } |
369 | 355 |
370 void ResourceLoader::requestSynchronously(ResourceRequest& request) | 356 void ResourceLoader::requestSynchronously(ResourceRequest& request) |
371 { | 357 { |
372 // downloadToFile is not supported for synchronous requests. | 358 // downloadToFile is not supported for synchronous requests. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 // empty buffer is a noop in most cases, but is destructive in the case of | 394 // empty buffer is a noop in most cases, but is destructive in the case of |
409 // a 304, where it will overwrite the cached data we should be reusing. | 395 // a 304, where it will overwrite the cached data we should be reusing. |
410 if (dataOut.size()) { | 396 if (dataOut.size()) { |
411 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); | 397 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); |
412 m_resource->setResourceBuffer(dataOut); | 398 m_resource->setResourceBuffer(dataOut); |
413 } | 399 } |
414 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 400 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
415 } | 401 } |
416 | 402 |
417 } // namespace blink | 403 } // namespace blink |
OLD | NEW |