OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011, 2012 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceRespo
nse& /*redirectResponse*/) override; | 135 void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceRespo
nse& /*redirectResponse*/) override; |
136 | 136 |
137 // Sets an error to be reported back to the client, asychronously. | 137 // Sets an error to be reported back to the client, asychronously. |
138 void setDelayedError(const ResourceError&); | 138 void setDelayedError(const ResourceError&); |
139 | 139 |
140 // Enables forwarding of error notifications to the WebURLLoaderClient. Thes
e must be | 140 // Enables forwarding of error notifications to the WebURLLoaderClient. Thes
e must be |
141 // deferred until after the call to AssociatedURLLoader::loadAsynchronously(
) completes. | 141 // deferred until after the call to AssociatedURLLoader::loadAsynchronously(
) completes. |
142 void enableErrorNotifications(); | 142 void enableErrorNotifications(); |
143 | 143 |
144 // Stops loading and releases the DocumentThreadableLoader as early as possi
ble. | 144 // Stops loading and releases the DocumentThreadableLoader as early as possi
ble. |
145 void clearClient() { m_client = 0; } | 145 WebURLLoaderClient* releaseClient() |
| 146 { |
| 147 WebURLLoaderClient* client = m_client; |
| 148 m_client = nullptr; |
| 149 return client; |
| 150 } |
146 | 151 |
147 private: | 152 private: |
148 ClientAdapter(AssociatedURLLoader*, WebURLLoaderClient*, const WebURLLoaderO
ptions&); | 153 ClientAdapter(AssociatedURLLoader*, WebURLLoaderClient*, const WebURLLoaderO
ptions&); |
149 | 154 |
150 void notifyError(Timer<ClientAdapter>*); | 155 void notifyError(Timer<ClientAdapter>*); |
151 | 156 |
152 AssociatedURLLoader* m_loader; | 157 AssociatedURLLoader* m_loader; |
153 WebURLLoaderClient* m_client; | 158 WebURLLoaderClient* m_client; |
154 WebURLLoaderOptions m_options; | 159 WebURLLoaderOptions m_options; |
155 WebURLError m_error; | 160 WebURLError m_error; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 m_client->didReceiveCachedMetadata(m_loader, data, dataLength); | 248 m_client->didReceiveCachedMetadata(m_loader, data, dataLength); |
244 } | 249 } |
245 | 250 |
246 void AssociatedURLLoader::ClientAdapter::didFinishLoading(unsigned long identifi
er, double finishTime) | 251 void AssociatedURLLoader::ClientAdapter::didFinishLoading(unsigned long identifi
er, double finishTime) |
247 { | 252 { |
248 if (!m_client) | 253 if (!m_client) |
249 return; | 254 return; |
250 | 255 |
251 m_loader->clientAdapterDone(); | 256 m_loader->clientAdapterDone(); |
252 | 257 |
253 auto client = m_client; | 258 releaseClient()->didFinishLoading(m_loader, finishTime, WebURLLoaderClient::
kUnknownEncodedDataLength); |
254 m_client = nullptr; | |
255 client->didFinishLoading(m_loader, finishTime, WebURLLoaderClient::kUnknownE
ncodedDataLength); | |
256 // |this| may be dead here. | 259 // |this| may be dead here. |
257 } | 260 } |
258 | 261 |
259 void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error) | 262 void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error) |
260 { | 263 { |
261 if (!m_client) | 264 if (!m_client) |
262 return; | 265 return; |
263 | 266 |
264 m_loader->clientAdapterDone(); | 267 m_loader->clientAdapterDone(); |
265 | 268 |
(...skipping 17 matching lines...) Expand all Loading... |
283 m_errorTimer.startOneShot(0, BLINK_FROM_HERE); | 286 m_errorTimer.startOneShot(0, BLINK_FROM_HERE); |
284 } | 287 } |
285 | 288 |
286 void AssociatedURLLoader::ClientAdapter::notifyError(Timer<ClientAdapter>* timer
) | 289 void AssociatedURLLoader::ClientAdapter::notifyError(Timer<ClientAdapter>* timer
) |
287 { | 290 { |
288 ASSERT_UNUSED(timer, timer == &m_errorTimer); | 291 ASSERT_UNUSED(timer, timer == &m_errorTimer); |
289 | 292 |
290 if (!m_client) | 293 if (!m_client) |
291 return; | 294 return; |
292 | 295 |
293 auto client = m_client; | 296 releaseClient()->didFail(m_loader, m_error); |
294 m_client = nullptr; | |
295 client->didFail(m_loader, m_error); | |
296 // |this| may be dead here. | 297 // |this| may be dead here. |
297 } | 298 } |
298 | 299 |
299 class AssociatedURLLoader::Observer final : public GarbageCollected<Observer>, p
ublic ContextLifecycleObserver { | 300 class AssociatedURLLoader::Observer final : public GarbageCollected<Observer>, p
ublic ContextLifecycleObserver { |
300 USING_GARBAGE_COLLECTED_MIXIN(Observer); | 301 USING_GARBAGE_COLLECTED_MIXIN(Observer); |
301 public: | 302 public: |
302 Observer(AssociatedURLLoader* parent, Document* document) | 303 Observer(AssociatedURLLoader* parent, Document* document) |
303 : ContextLifecycleObserver(document) | 304 : ContextLifecycleObserver(document) |
304 , m_parent(parent) | 305 , m_parent(parent) |
305 { | 306 { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // FIXME: return meaningful error codes. | 406 // FIXME: return meaningful error codes. |
406 m_clientAdapter->didFail(ResourceError()); | 407 m_clientAdapter->didFail(ResourceError()); |
407 } | 408 } |
408 m_clientAdapter->enableErrorNotifications(); | 409 m_clientAdapter->enableErrorNotifications(); |
409 } | 410 } |
410 | 411 |
411 void AssociatedURLLoader::cancel() | 412 void AssociatedURLLoader::cancel() |
412 { | 413 { |
413 disposeObserver(); | 414 disposeObserver(); |
414 cancelLoader(); | 415 cancelLoader(); |
415 m_client = nullptr; | 416 releaseClient(); |
416 } | 417 } |
417 | 418 |
418 void AssociatedURLLoader::clientAdapterDone() | 419 void AssociatedURLLoader::clientAdapterDone() |
419 { | 420 { |
420 disposeObserver(); | 421 disposeObserver(); |
421 m_client = nullptr; | 422 releaseClient(); |
422 } | 423 } |
423 | 424 |
424 void AssociatedURLLoader::cancelLoader() | 425 void AssociatedURLLoader::cancelLoader() |
425 { | 426 { |
426 if (!m_clientAdapter) | 427 if (!m_clientAdapter) |
427 return; | 428 return; |
428 | 429 |
429 // Prevent invocation of the WebURLLoaderClient methods. | 430 // Prevent invocation of the WebURLLoaderClient methods. |
430 m_clientAdapter->clearClient(); | 431 m_clientAdapter->releaseClient(); |
431 | 432 |
432 if (m_loader) { | 433 if (m_loader) { |
433 m_loader->cancel(); | 434 m_loader->cancel(); |
434 m_loader.clear(); | 435 m_loader.clear(); |
435 } | 436 } |
436 m_clientAdapter.clear(); | 437 m_clientAdapter.clear(); |
437 } | 438 } |
438 | 439 |
439 void AssociatedURLLoader::setDefersLoading(bool defersLoading) | 440 void AssociatedURLLoader::setDefersLoading(bool defersLoading) |
440 { | 441 { |
441 if (m_loader) | 442 if (m_loader) |
442 m_loader->setDefersLoading(defersLoading); | 443 m_loader->setDefersLoading(defersLoading); |
443 } | 444 } |
444 | 445 |
445 void AssociatedURLLoader::setLoadingTaskRunner(blink::WebTaskRunner*) | 446 void AssociatedURLLoader::setLoadingTaskRunner(blink::WebTaskRunner*) |
446 { | 447 { |
447 // TODO(alexclarke): Maybe support this one day if it proves worthwhile. | 448 // TODO(alexclarke): Maybe support this one day if it proves worthwhile. |
448 } | 449 } |
449 | 450 |
450 void AssociatedURLLoader::documentDestroyed() | 451 void AssociatedURLLoader::documentDestroyed() |
451 { | 452 { |
452 disposeObserver(); | 453 disposeObserver(); |
453 cancelLoader(); | 454 cancelLoader(); |
454 | 455 |
455 if (!m_client) | 456 if (!m_client) |
456 return; | 457 return; |
457 | 458 |
458 WebURLLoaderClient* client = m_client; | 459 releaseClient()->didFail(this, ResourceError()); |
459 m_client = nullptr; | |
460 client->didFail(this, ResourceError()); | |
461 // |this| may be dead here. | 460 // |this| may be dead here. |
462 } | 461 } |
463 | 462 |
464 void AssociatedURLLoader::disposeObserver() | 463 void AssociatedURLLoader::disposeObserver() |
465 { | 464 { |
466 if (!m_observer) | 465 if (!m_observer) |
467 return; | 466 return; |
468 | 467 |
469 // TODO(tyoshino): Remove this assert once Document is fixed so that | 468 // TODO(tyoshino): Remove this assert once Document is fixed so that |
470 // contextDestroyed() is invoked for all kinds of Documents. | 469 // contextDestroyed() is invoked for all kinds of Documents. |
(...skipping 10 matching lines...) Expand all Loading... |
481 // there could be a WebURLLoader instance behind the | 480 // there could be a WebURLLoader instance behind the |
482 // DocumentThreadableLoader instance. So, for safety, we chose to just | 481 // DocumentThreadableLoader instance. So, for safety, we chose to just |
483 // crash here. | 482 // crash here. |
484 RELEASE_ASSERT(ThreadState::current()); | 483 RELEASE_ASSERT(ThreadState::current()); |
485 | 484 |
486 m_observer->dispose(); | 485 m_observer->dispose(); |
487 m_observer = nullptr; | 486 m_observer = nullptr; |
488 } | 487 } |
489 | 488 |
490 } // namespace blink | 489 } // namespace blink |
OLD | NEW |