| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 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 } |
| (...skipping 135 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_); | |
| 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; |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 668 } |
| 672 if (delay_until_image_notify_finished_) { | 669 if (delay_until_image_notify_finished_) { |
| 673 delay_until_image_notify_finished_->DocumentChanged( | 670 delay_until_image_notify_finished_->DocumentChanged( |
| 674 element_->GetDocument()); | 671 element_->GetDocument()); |
| 675 } | 672 } |
| 676 ClearFailedLoadURL(); | 673 ClearFailedLoadURL(); |
| 677 SetImage(0); | 674 SetImage(0); |
| 678 } | 675 } |
| 679 | 676 |
| 680 } // namespace blink | 677 } // namespace blink |
| OLD | NEW |