Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights |
| 5 * reserved. | 5 * reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 156 |
| 157 ImageLoader::ImageLoader(Element* element) | 157 ImageLoader::ImageLoader(Element* element) |
| 158 : element_(element), | 158 : element_(element), |
| 159 deref_element_timer_(this, &ImageLoader::TimerFired), | 159 deref_element_timer_(this, &ImageLoader::TimerFired), |
| 160 has_pending_load_event_(false), | 160 has_pending_load_event_(false), |
| 161 has_pending_error_event_(false), | 161 has_pending_error_event_(false), |
| 162 image_complete_(true), | 162 image_complete_(true), |
| 163 loading_image_document_(false), | 163 loading_image_document_(false), |
| 164 element_is_protected_(false), | 164 element_is_protected_(false), |
| 165 suppress_error_events_(false) { | 165 suppress_error_events_(false) { |
| 166 RESOURCE_LOADING_DVLOG(1) << "new ImageLoader " << this; | 166 RESOURCE_LOADING_DVLOG(1) << "new ImageLoader " << this; |
|
hiroshige
2017/05/05 19:58:31
Previous: has_pending_load_event_ == false.
Now:
| |
| 167 } | 167 } |
| 168 | 168 |
| 169 ImageLoader::~ImageLoader() {} | 169 ImageLoader::~ImageLoader() {} |
| 170 | 170 |
| 171 void ImageLoader::Dispose() { | 171 void ImageLoader::Dispose() { |
| 172 RESOURCE_LOADING_DVLOG(1) | 172 RESOURCE_LOADING_DVLOG(1) |
| 173 << "~ImageLoader " << this | 173 << "~ImageLoader " << this |
| 174 << "; m_hasPendingLoadEvent=" << has_pending_load_event_ | 174 << "; m_hasPendingLoadEvent=" << has_pending_load_event_ |
|
hiroshige
2017/05/05 19:58:31
I left logging of has_pending_load_event_ as is. d
| |
| 175 << ", m_hasPendingErrorEvent=" << has_pending_error_event_; | 175 << ", m_hasPendingErrorEvent=" << has_pending_error_event_; |
| 176 | 176 |
| 177 if (image_) { | 177 if (image_) { |
| 178 image_->RemoveObserver(this); | 178 image_->RemoveObserver(this); |
| 179 image_ = nullptr; | 179 image_ = nullptr; |
| 180 delay_until_image_notify_finished_ = nullptr; | 180 delay_until_image_notify_finished_ = nullptr; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 DEFINE_TRACE(ImageLoader) { | 184 DEFINE_TRACE(ImageLoader) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 196 UpdatedHasPendingEvent(); | 196 UpdatedHasPendingEvent(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( | 199 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( |
| 200 ImageResourceContent* new_image) { | 200 ImageResourceContent* new_image) { |
| 201 DCHECK(failed_load_url_.IsEmpty()); | 201 DCHECK(failed_load_url_.IsEmpty()); |
| 202 ImageResourceContent* old_image = image_.Get(); | 202 ImageResourceContent* old_image = image_.Get(); |
| 203 if (new_image != old_image) { | 203 if (new_image != old_image) { |
| 204 image_ = new_image; | 204 image_ = new_image; |
| 205 delay_until_image_notify_finished_ = nullptr; | 205 delay_until_image_notify_finished_ = nullptr; |
| 206 if (has_pending_load_event_) { | 206 if (has_pending_load_event_) { |
|
hiroshige
2017/05/05 19:58:31
Here we don't check "(image_ && !image_complete_)
| |
| 207 LoadEventSender().CancelEvent(this); | 207 LoadEventSender().CancelEvent(this); |
| 208 has_pending_load_event_ = false; | 208 has_pending_load_event_ = false; |
| 209 } | 209 } |
| 210 if (has_pending_error_event_) { | 210 if (has_pending_error_event_) { |
| 211 ErrorEventSender().CancelEvent(this); | 211 ErrorEventSender().CancelEvent(this); |
| 212 has_pending_error_event_ = false; | 212 has_pending_error_event_ = false; |
| 213 } | 213 } |
| 214 image_complete_ = true; | 214 image_complete_ = true; |
| 215 if (new_image) { | 215 if (new_image) { |
| 216 new_image->AddObserver(this); | 216 new_image->AddObserver(this); |
| 217 } | 217 } |
| 218 if (old_image) { | 218 if (old_image) { |
| 219 old_image->RemoveObserver(this); | 219 old_image->RemoveObserver(this); |
| 220 } | 220 } |
|
hiroshige
2017/05/05 19:58:31
Previous: has_pending_load_event_ == false.
Now:
| |
| 221 } | 221 } |
| 222 | 222 |
| 223 if (LayoutImageResource* image_resource = GetLayoutImageResource()) | 223 if (LayoutImageResource* image_resource = GetLayoutImageResource()) |
| 224 image_resource->ResetAnimation(); | 224 image_resource->ResetAnimation(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 static void ConfigureRequest( | 227 static void ConfigureRequest( |
| 228 FetchParameters& params, | 228 FetchParameters& params, |
| 229 ImageLoader::BypassMainWorldBehavior bypass_behavior, | 229 ImageLoader::BypassMainWorldBehavior bypass_behavior, |
| 230 Element& element, | 230 Element& element, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 DispatchErrorEvent(); | 335 DispatchErrorEvent(); |
| 336 } | 336 } |
| 337 NoImageResourceToLoad(); | 337 NoImageResourceToLoad(); |
| 338 } | 338 } |
| 339 | 339 |
| 340 ImageResourceContent* old_image = image_.Get(); | 340 ImageResourceContent* old_image = image_.Get(); |
| 341 if (update_behavior == kUpdateSizeChanged && element_->GetLayoutObject() && | 341 if (update_behavior == kUpdateSizeChanged && element_->GetLayoutObject() && |
| 342 element_->GetLayoutObject()->IsImage() && new_image == old_image) { | 342 element_->GetLayoutObject()->IsImage() && new_image == old_image) { |
| 343 ToLayoutImage(element_->GetLayoutObject())->IntrinsicSizeChanged(); | 343 ToLayoutImage(element_->GetLayoutObject())->IntrinsicSizeChanged(); |
| 344 } else { | 344 } else { |
| 345 if (has_pending_load_event_) { | 345 if (has_pending_load_event_) { |
|
hiroshige
2017/05/05 19:58:31
Ditto as Line 206.
| |
| 346 LoadEventSender().CancelEvent(this); | 346 LoadEventSender().CancelEvent(this); |
| 347 has_pending_load_event_ = false; | 347 has_pending_load_event_ = false; |
| 348 } | 348 } |
| 349 | 349 |
| 350 // Cancel error events that belong to the previous load, which is now | 350 // Cancel error events that belong to the previous load, which is now |
| 351 // cancelled by changing the src attribute. If newImage is null and | 351 // cancelled by changing the src attribute. If newImage is null and |
| 352 // m_hasPendingErrorEvent is true, we know the error event has been just | 352 // m_hasPendingErrorEvent is true, we know the error event has been just |
| 353 // posted by this load and we should not cancel the event. | 353 // posted by this load and we should not cancel the event. |
| 354 // FIXME: If both previous load and this one got blocked with an error, we | 354 // FIXME: If both previous load and this one got blocked with an error, we |
| 355 // can receive one error event instead of two. | 355 // can receive one error event instead of two. |
| 356 if (has_pending_error_event_ && new_image) { | 356 if (has_pending_error_event_ && new_image) { |
| 357 ErrorEventSender().CancelEvent(this); | 357 ErrorEventSender().CancelEvent(this); |
| 358 has_pending_error_event_ = false; | 358 has_pending_error_event_ = false; |
| 359 } | 359 } |
| 360 | 360 |
| 361 image_ = new_image; | 361 image_ = new_image; |
| 362 has_pending_load_event_ = new_image; | |
| 363 image_complete_ = !new_image; | 362 image_complete_ = !new_image; |
| 364 delay_until_image_notify_finished_ = nullptr; | 363 delay_until_image_notify_finished_ = nullptr; |
| 365 | 364 |
|
hiroshige
2017/05/05 19:58:31
Previous: has_pending_load_event_ == true iff new_
| |
| 366 UpdateLayoutObject(); | 365 UpdateLayoutObject(); |
| 367 // If newImage exists and is cached, addObserver() will result in the load | 366 // If newImage exists and is cached, addObserver() will result in the load |
| 368 // event being queued to fire. Ensure this happens after beforeload is | 367 // event being queued to fire. Ensure this happens after beforeload is |
| 369 // dispatched. | 368 // dispatched. |
| 370 if (new_image) { | 369 if (new_image) { |
| 371 new_image->AddObserver(this); | 370 new_image->AddObserver(this); |
| 372 } | 371 } |
| 373 if (old_image) { | 372 if (old_image) { |
| 374 old_image->RemoveObserver(this); | 373 old_image->RemoveObserver(this); |
| 375 } | 374 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 // Update ImageAnimationPolicy for m_image. | 507 // Update ImageAnimationPolicy for m_image. |
| 509 if (image_) | 508 if (image_) |
| 510 image_->UpdateImageAnimationPolicy(); | 509 image_->UpdateImageAnimationPolicy(); |
| 511 | 510 |
| 512 UpdateLayoutObject(); | 511 UpdateLayoutObject(); |
| 513 | 512 |
| 514 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) | 513 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) |
| 515 ToSVGImage(image_->GetImage()) | 514 ToSVGImage(image_->GetImage()) |
| 516 ->UpdateUseCounters(GetElement()->GetDocument()); | 515 ->UpdateUseCounters(GetElement()->GetDocument()); |
| 517 | 516 |
| 518 if (loading_image_document_) { | 517 if (loading_image_document_) |
| 519 CHECK(!has_pending_load_event_); | |
| 520 return; | 518 return; |
| 521 } | |
| 522 | |
| 523 CHECK(has_pending_load_event_); | |
|
hiroshige
2017/05/05 19:58:31
Previous: We assert has_pending_load_event_ == tru
| |
| 524 | 519 |
| 525 if (resource->ErrorOccurred()) { | 520 if (resource->ErrorOccurred()) { |
| 526 LoadEventSender().CancelEvent(this); | 521 LoadEventSender().CancelEvent(this); |
| 527 has_pending_load_event_ = false; | 522 has_pending_load_event_ = false; |
|
hiroshige
2017/05/05 19:58:31
Because |image_complete_| is true here,
"(image_ &
| |
| 528 | 523 |
| 529 if (resource->GetResourceError().IsAccessCheck()) { | 524 if (resource->GetResourceError().IsAccessCheck()) { |
| 530 CrossSiteOrCSPViolationOccurred( | 525 CrossSiteOrCSPViolationOccurred( |
| 531 AtomicString(resource->GetResourceError().FailingURL())); | 526 AtomicString(resource->GetResourceError().FailingURL())); |
| 532 } | 527 } |
| 533 | 528 |
| 534 // The error event should not fire if the image data update is a result of | 529 // The error event should not fire if the image data update is a result of |
| 535 // environment change. | 530 // environment change. |
| 536 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem ent:the-img-element-55 | 531 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem ent:the-img-element-55 |
| 537 if (!suppress_error_events_) | 532 if (!suppress_error_events_) |
| 538 DispatchErrorEvent(); | 533 DispatchErrorEvent(); |
| 539 | 534 |
| 540 // Only consider updating the protection ref-count of the Element | 535 // Only consider updating the protection ref-count of the Element |
| 541 // immediately before returning from this function as doing so might result | 536 // immediately before returning from this function as doing so might result |
| 542 // in the destruction of this ImageLoader. | 537 // in the destruction of this ImageLoader. |
| 543 UpdatedHasPendingEvent(); | 538 UpdatedHasPendingEvent(); |
| 544 return; | 539 return; |
| 545 } | 540 } |
| 541 has_pending_load_event_ = true; | |
| 546 LoadEventSender().DispatchEventSoon(this); | 542 LoadEventSender().DispatchEventSoon(this); |
| 547 } | 543 } |
| 548 | 544 |
| 549 LayoutImageResource* ImageLoader::GetLayoutImageResource() { | 545 LayoutImageResource* ImageLoader::GetLayoutImageResource() { |
| 550 LayoutObject* layout_object = element_->GetLayoutObject(); | 546 LayoutObject* layout_object = element_->GetLayoutObject(); |
| 551 | 547 |
| 552 if (!layout_object) | 548 if (!layout_object) |
| 553 return 0; | 549 return 0; |
| 554 | 550 |
| 555 // We don't return style generated image because it doesn't belong to the | 551 // We don't return style generated image because it doesn't belong to the |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 582 } | 578 } |
| 583 | 579 |
| 584 void ImageLoader::UpdatedHasPendingEvent() { | 580 void ImageLoader::UpdatedHasPendingEvent() { |
| 585 // If an Element that does image loading is removed from the DOM the | 581 // If an Element that does image loading is removed from the DOM the |
| 586 // load/error event for the image is still observable. As long as the | 582 // load/error event for the image is still observable. As long as the |
| 587 // ImageLoader is actively loading, the Element itself needs to be ref'ed to | 583 // ImageLoader is actively loading, the Element itself needs to be ref'ed to |
| 588 // keep it from being destroyed by DOM manipulation or garbage collection. If | 584 // keep it from being destroyed by DOM manipulation or garbage collection. If |
| 589 // such an Element wishes for the load to stop when removed from the DOM it | 585 // such an Element wishes for the load to stop when removed from the DOM it |
| 590 // needs to stop the ImageLoader explicitly. | 586 // needs to stop the ImageLoader explicitly. |
| 591 bool was_protected = element_is_protected_; | 587 bool was_protected = element_is_protected_; |
| 592 element_is_protected_ = has_pending_load_event_ || has_pending_error_event_; | 588 element_is_protected_ = (image_ && !image_complete_) || |
| 589 has_pending_load_event_ || has_pending_error_event_; | |
| 593 if (was_protected == element_is_protected_) | 590 if (was_protected == element_is_protected_) |
| 594 return; | 591 return; |
| 595 | 592 |
| 596 if (element_is_protected_) { | 593 if (element_is_protected_) { |
| 597 if (deref_element_timer_.IsActive()) | 594 if (deref_element_timer_.IsActive()) |
| 598 deref_element_timer_.Stop(); | 595 deref_element_timer_.Stop(); |
| 599 else | 596 else |
| 600 keep_alive_ = element_; | 597 keep_alive_ = element_; |
| 601 } else { | 598 } else { |
| 602 DCHECK(!deref_element_timer_.IsActive()); | 599 DCHECK(!deref_element_timer_.IsActive()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 618 if (event_type == EventTypeNames::error) | 615 if (event_type == EventTypeNames::error) |
| 619 DispatchPendingErrorEvent(); | 616 DispatchPendingErrorEvent(); |
| 620 } | 617 } |
| 621 | 618 |
| 622 void ImageLoader::DispatchPendingLoadEvent() { | 619 void ImageLoader::DispatchPendingLoadEvent() { |
| 623 CHECK(has_pending_load_event_); | 620 CHECK(has_pending_load_event_); |
| 624 if (!image_) | 621 if (!image_) |
| 625 return; | 622 return; |
| 626 CHECK(image_complete_); | 623 CHECK(image_complete_); |
| 627 has_pending_load_event_ = false; | 624 has_pending_load_event_ = false; |
| 625 CHECK(image_complete_); | |
| 628 if (GetElement()->GetDocument().GetFrame()) | 626 if (GetElement()->GetDocument().GetFrame()) |
| 629 DispatchLoadEvent(); | 627 DispatchLoadEvent(); |
| 630 | 628 |
| 631 // Only consider updating the protection ref-count of the Element immediately | 629 // Only consider updating the protection ref-count of the Element immediately |
| 632 // before returning from this function as doing so might result in the | 630 // before returning from this function as doing so might result in the |
| 633 // destruction of this ImageLoader. | 631 // destruction of this ImageLoader. |
| 634 UpdatedHasPendingEvent(); | 632 UpdatedHasPendingEvent(); |
| 635 } | 633 } |
| 636 | 634 |
| 637 void ImageLoader::DispatchPendingErrorEvent() { | 635 void ImageLoader::DispatchPendingErrorEvent() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 } | 669 } |
| 672 if (delay_until_image_notify_finished_) { | 670 if (delay_until_image_notify_finished_) { |
| 673 delay_until_image_notify_finished_->DocumentChanged( | 671 delay_until_image_notify_finished_->DocumentChanged( |
| 674 element_->GetDocument()); | 672 element_->GetDocument()); |
| 675 } | 673 } |
| 676 ClearFailedLoadURL(); | 674 ClearFailedLoadURL(); |
| 677 SetImage(0); | 675 SetImage(0); |
| 678 } | 676 } |
| 679 | 677 |
| 680 } // namespace blink | 678 } // namespace blink |
| OLD | NEW |