| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 207 } |
| 208 | 208 |
| 209 void ImageLoader::SetImageForImageDocument(ImageResource* new_image_resource) { | 209 void ImageLoader::SetImageForImageDocument(ImageResource* new_image_resource) { |
| 210 DCHECK(loading_image_document_); | 210 DCHECK(loading_image_document_); |
| 211 DCHECK(new_image_resource); | 211 DCHECK(new_image_resource); |
| 212 DCHECK(new_image_resource->GetContent()); | 212 DCHECK(new_image_resource->GetContent()); |
| 213 | 213 |
| 214 image_resource_for_image_document_ = new_image_resource; | 214 image_resource_for_image_document_ = new_image_resource; |
| 215 SetImageWithoutConsideringPendingLoadEvent(new_image_resource->GetContent()); | 215 SetImageWithoutConsideringPendingLoadEvent(new_image_resource->GetContent()); |
| 216 | 216 |
| 217 // |has_pending_load_event_| is always false and |image_complete_| is | 217 // |image_complete_| is always true for ImageDocument loading, while the |
| 218 // always true for ImageDocument loading, while the loading is just started. | 218 // loading is just started. |
| 219 // TODO(hiroshige): clean up the behavior of flags. https://crbug.com/719759 | 219 // TODO(hiroshige): clean up the behavior of flags. https://crbug.com/719759 |
| 220 has_pending_load_event_ = false; | |
| 221 image_complete_ = true; | 220 image_complete_ = true; |
| 222 | 221 |
| 223 // Only consider updating the protection ref-count of the Element immediately | 222 // Only consider updating the protection ref-count of the Element immediately |
| 224 // before returning from this function as doing so might result in the | 223 // before returning from this function as doing so might result in the |
| 225 // destruction of this ImageLoader. | 224 // destruction of this ImageLoader. |
| 226 UpdatedHasPendingEvent(); | 225 UpdatedHasPendingEvent(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( | 228 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( |
| 230 ImageResourceContent* new_image) { | 229 ImageResourceContent* new_image) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 Task::Create(this, update_behavior, referrer_policy); | 299 Task::Create(this, update_behavior, referrer_policy); |
| 301 pending_task_ = task->CreateWeakPtr(); | 300 pending_task_ = task->CreateWeakPtr(); |
| 302 Microtask::EnqueueMicrotask( | 301 Microtask::EnqueueMicrotask( |
| 303 WTF::Bind(&Task::Run, WTF::Passed(std::move(task)))); | 302 WTF::Bind(&Task::Run, WTF::Passed(std::move(task)))); |
| 304 delay_until_do_update_from_element_ = | 303 delay_until_do_update_from_element_ = |
| 305 IncrementLoadEventDelayCount::Create(element_->GetDocument()); | 304 IncrementLoadEventDelayCount::Create(element_->GetDocument()); |
| 306 } | 305 } |
| 307 | 306 |
| 308 void ImageLoader::UpdateImageState(ImageResourceContent* new_image) { | 307 void ImageLoader::UpdateImageState(ImageResourceContent* new_image) { |
| 309 image_ = new_image; | 308 image_ = new_image; |
| 310 has_pending_load_event_ = new_image; | |
| 311 image_complete_ = !new_image; | 309 image_complete_ = !new_image; |
| 312 delay_until_image_notify_finished_ = nullptr; | 310 delay_until_image_notify_finished_ = nullptr; |
| 313 } | 311 } |
| 314 | 312 |
| 315 void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior, | 313 void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior, |
| 316 UpdateFromElementBehavior update_behavior, | 314 UpdateFromElementBehavior update_behavior, |
| 317 const KURL& url, | 315 const KURL& url, |
| 318 ReferrerPolicy referrer_policy) { | 316 ReferrerPolicy referrer_policy) { |
| 319 // FIXME: According to | 317 // FIXME: According to |
| 320 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-conten
t.html#the-img-element:the-img-element-55 | 318 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-conten
t.html#the-img-element:the-img-element-55 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 534 } |
| 537 | 535 |
| 538 void ImageLoader::ImageNotifyFinished(ImageResourceContent* resource) { | 536 void ImageLoader::ImageNotifyFinished(ImageResourceContent* resource) { |
| 539 RESOURCE_LOADING_DVLOG(1) | 537 RESOURCE_LOADING_DVLOG(1) |
| 540 << "ImageLoader::imageNotifyFinished " << this | 538 << "ImageLoader::imageNotifyFinished " << this |
| 541 << "; has_pending_load_event_=" << has_pending_load_event_; | 539 << "; has_pending_load_event_=" << has_pending_load_event_; |
| 542 | 540 |
| 543 DCHECK(failed_load_url_.IsEmpty()); | 541 DCHECK(failed_load_url_.IsEmpty()); |
| 544 DCHECK_EQ(resource, image_.Get()); | 542 DCHECK_EQ(resource, image_.Get()); |
| 545 | 543 |
| 546 // |has_pending_load_event_| is always false and |image_complete_| is | 544 // |image_complete_| is always true for entire ImageDocument loading for |
| 547 // always true for entire ImageDocument loading for historical reason. | 545 // historical reason. |
| 548 // DoUpdateFromElement() is not called and SetImageForImageDocument() | 546 // DoUpdateFromElement() is not called and SetImageForImageDocument() |
| 549 // is called instead for ImageDocument loading. | 547 // is called instead for ImageDocument loading. |
| 550 // TODO(hiroshige): Turn the CHECK()s to DCHECK()s before going to beta. | 548 // TODO(hiroshige): Turn the CHECK()s to DCHECK()s before going to beta. |
| 551 if (loading_image_document_) | 549 if (loading_image_document_) |
| 552 CHECK(image_complete_); | 550 CHECK(image_complete_); |
| 553 else | 551 else |
| 554 CHECK(!image_complete_); | 552 CHECK(!image_complete_); |
| 555 | 553 |
| 556 image_complete_ = true; | 554 image_complete_ = true; |
| 557 delay_until_image_notify_finished_ = nullptr; | 555 delay_until_image_notify_finished_ = nullptr; |
| 558 | 556 |
| 559 // Update ImageAnimationPolicy for image_. | 557 // Update ImageAnimationPolicy for image_. |
| 560 if (image_) | 558 if (image_) |
| 561 image_->UpdateImageAnimationPolicy(); | 559 image_->UpdateImageAnimationPolicy(); |
| 562 | 560 |
| 563 UpdateLayoutObject(); | 561 UpdateLayoutObject(); |
| 564 | 562 |
| 565 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) | 563 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) |
| 566 ToSVGImage(image_->GetImage()) | 564 ToSVGImage(image_->GetImage()) |
| 567 ->UpdateUseCounters(GetElement()->GetDocument()); | 565 ->UpdateUseCounters(GetElement()->GetDocument()); |
| 568 | 566 |
| 569 if (loading_image_document_) { | 567 if (loading_image_document_) |
| 570 CHECK(!has_pending_load_event_); | |
| 571 return; | 568 return; |
| 572 } | |
| 573 | |
| 574 CHECK(has_pending_load_event_); | |
| 575 | 569 |
| 576 if (resource->ErrorOccurred()) { | 570 if (resource->ErrorOccurred()) { |
| 577 LoadEventSender().CancelEvent(this); | 571 LoadEventSender().CancelEvent(this); |
| 578 has_pending_load_event_ = false; | 572 has_pending_load_event_ = false; |
| 579 | 573 |
| 580 if (resource->GetResourceError().IsAccessCheck()) { | 574 if (resource->GetResourceError().IsAccessCheck()) { |
| 581 CrossSiteOrCSPViolationOccurred( | 575 CrossSiteOrCSPViolationOccurred( |
| 582 AtomicString(resource->GetResourceError().FailingURL())); | 576 AtomicString(resource->GetResourceError().FailingURL())); |
| 583 } | 577 } |
| 584 | 578 |
| 585 // The error event should not fire if the image data update is a result of | 579 // The error event should not fire if the image data update is a result of |
| 586 // environment change. | 580 // environment change. |
| 587 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem
ent:the-img-element-55 | 581 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem
ent:the-img-element-55 |
| 588 if (!suppress_error_events_) | 582 if (!suppress_error_events_) |
| 589 DispatchErrorEvent(); | 583 DispatchErrorEvent(); |
| 590 | 584 |
| 591 // Only consider updating the protection ref-count of the Element | 585 // Only consider updating the protection ref-count of the Element |
| 592 // immediately before returning from this function as doing so might result | 586 // immediately before returning from this function as doing so might result |
| 593 // in the destruction of this ImageLoader. | 587 // in the destruction of this ImageLoader. |
| 594 UpdatedHasPendingEvent(); | 588 UpdatedHasPendingEvent(); |
| 595 return; | 589 return; |
| 596 } | 590 } |
| 591 has_pending_load_event_ = true; |
| 597 LoadEventSender().DispatchEventSoon(this); | 592 LoadEventSender().DispatchEventSoon(this); |
| 598 } | 593 } |
| 599 | 594 |
| 600 LayoutImageResource* ImageLoader::GetLayoutImageResource() { | 595 LayoutImageResource* ImageLoader::GetLayoutImageResource() { |
| 601 LayoutObject* layout_object = element_->GetLayoutObject(); | 596 LayoutObject* layout_object = element_->GetLayoutObject(); |
| 602 | 597 |
| 603 if (!layout_object) | 598 if (!layout_object) |
| 604 return 0; | 599 return 0; |
| 605 | 600 |
| 606 // We don't return style generated image because it doesn't belong to the | 601 // We don't return style generated image because it doesn't belong to the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 625 return; | 620 return; |
| 626 | 621 |
| 627 // Only update the layoutObject if it doesn't have an image or if what we have | 622 // Only update the layoutObject if it doesn't have an image or if what we have |
| 628 // is a complete image. This prevents flickering in the case where a dynamic | 623 // is a complete image. This prevents flickering in the case where a dynamic |
| 629 // change is happening between two images. | 624 // change is happening between two images. |
| 630 ImageResourceContent* cached_image = image_resource->CachedImage(); | 625 ImageResourceContent* cached_image = image_resource->CachedImage(); |
| 631 if (image_ != cached_image && (image_complete_ || !cached_image)) | 626 if (image_ != cached_image && (image_complete_ || !cached_image)) |
| 632 image_resource->SetImageResource(image_.Get()); | 627 image_resource->SetImageResource(image_.Get()); |
| 633 } | 628 } |
| 634 | 629 |
| 630 bool ImageLoader::HasPendingEvent() const { |
| 631 // Regular image loading is in progress. |
| 632 if (image_ && !image_complete_ && !loading_image_document_) |
| 633 return true; |
| 634 |
| 635 if (has_pending_load_event_ || has_pending_error_event_) |
| 636 return true; |
| 637 |
| 638 return false; |
| 639 } |
| 640 |
| 635 void ImageLoader::UpdatedHasPendingEvent() { | 641 void ImageLoader::UpdatedHasPendingEvent() { |
| 636 // If an Element that does image loading is removed from the DOM the | 642 // If an Element that does image loading is removed from the DOM the |
| 637 // load/error event for the image is still observable. As long as the | 643 // load/error event for the image is still observable. As long as the |
| 638 // ImageLoader is actively loading, the Element itself needs to be ref'ed to | 644 // ImageLoader is actively loading, the Element itself needs to be ref'ed to |
| 639 // keep it from being destroyed by DOM manipulation or garbage collection. If | 645 // keep it from being destroyed by DOM manipulation or garbage collection. If |
| 640 // such an Element wishes for the load to stop when removed from the DOM it | 646 // such an Element wishes for the load to stop when removed from the DOM it |
| 641 // needs to stop the ImageLoader explicitly. | 647 // needs to stop the ImageLoader explicitly. |
| 642 bool was_protected = element_is_protected_; | 648 bool was_protected = element_is_protected_; |
| 643 element_is_protected_ = has_pending_load_event_ || has_pending_error_event_; | 649 element_is_protected_ = HasPendingEvent(); |
| 644 if (was_protected == element_is_protected_) | 650 if (was_protected == element_is_protected_) |
| 645 return; | 651 return; |
| 646 | 652 |
| 647 if (element_is_protected_) { | 653 if (element_is_protected_) { |
| 648 if (deref_element_timer_.IsActive()) | 654 if (deref_element_timer_.IsActive()) |
| 649 deref_element_timer_.Stop(); | 655 deref_element_timer_.Stop(); |
| 650 else | 656 else |
| 651 keep_alive_ = element_; | 657 keep_alive_ = element_; |
| 652 } else { | 658 } else { |
| 653 DCHECK(!deref_element_timer_.IsActive()); | 659 DCHECK(!deref_element_timer_.IsActive()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 727 } |
| 722 if (delay_until_image_notify_finished_) { | 728 if (delay_until_image_notify_finished_) { |
| 723 delay_until_image_notify_finished_->DocumentChanged( | 729 delay_until_image_notify_finished_->DocumentChanged( |
| 724 element_->GetDocument()); | 730 element_->GetDocument()); |
| 725 } | 731 } |
| 726 ClearFailedLoadURL(); | 732 ClearFailedLoadURL(); |
| 727 ClearImage(); | 733 ClearImage(); |
| 728 } | 734 } |
| 729 | 735 |
| 730 } // namespace blink | 736 } // namespace blink |
| OLD | NEW |