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 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 // |has_pending_load_event_| is always false and |image_complete_| is |
|
yhirano
2017/05/12 10:49:50
Is this comment stale?
hiroshige
2017/05/19 20:56:34
Done.
| |
| 218 // always true for ImageDocument loading, while the loading is just started. | 218 // always true for ImageDocument loading, while the 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 Task::Create(this, update_behavior, referrer_policy); | 292 Task::Create(this, update_behavior, referrer_policy); |
| 294 pending_task_ = task->CreateWeakPtr(); | 293 pending_task_ = task->CreateWeakPtr(); |
| 295 Microtask::EnqueueMicrotask( | 294 Microtask::EnqueueMicrotask( |
| 296 WTF::Bind(&Task::Run, WTF::Passed(std::move(task)))); | 295 WTF::Bind(&Task::Run, WTF::Passed(std::move(task)))); |
| 297 delay_until_do_update_from_element_ = | 296 delay_until_do_update_from_element_ = |
| 298 IncrementLoadEventDelayCount::Create(element_->GetDocument()); | 297 IncrementLoadEventDelayCount::Create(element_->GetDocument()); |
| 299 } | 298 } |
| 300 | 299 |
| 301 void ImageLoader::UpdateImageState(ImageResourceContent* new_image) { | 300 void ImageLoader::UpdateImageState(ImageResourceContent* new_image) { |
| 302 image_ = new_image; | 301 image_ = new_image; |
| 303 has_pending_load_event_ = new_image; | |
| 304 image_complete_ = !new_image; | 302 image_complete_ = !new_image; |
| 305 delay_until_image_notify_finished_ = nullptr; | 303 delay_until_image_notify_finished_ = nullptr; |
| 306 } | 304 } |
| 307 | 305 |
| 308 void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior, | 306 void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior, |
| 309 UpdateFromElementBehavior update_behavior, | 307 UpdateFromElementBehavior update_behavior, |
| 310 const KURL& url, | 308 const KURL& url, |
| 311 ReferrerPolicy referrer_policy) { | 309 ReferrerPolicy referrer_policy) { |
| 312 // FIXME: According to | 310 // FIXME: According to |
| 313 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-conten t.html#the-img-element:the-img-element-55 | 311 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-conten t.html#the-img-element:the-img-element-55 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 // Update ImageAnimationPolicy for image_. | 550 // Update ImageAnimationPolicy for image_. |
| 553 if (image_) | 551 if (image_) |
| 554 image_->UpdateImageAnimationPolicy(); | 552 image_->UpdateImageAnimationPolicy(); |
| 555 | 553 |
| 556 UpdateLayoutObject(); | 554 UpdateLayoutObject(); |
| 557 | 555 |
| 558 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) | 556 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) |
| 559 ToSVGImage(image_->GetImage()) | 557 ToSVGImage(image_->GetImage()) |
| 560 ->UpdateUseCounters(GetElement()->GetDocument()); | 558 ->UpdateUseCounters(GetElement()->GetDocument()); |
| 561 | 559 |
| 562 if (loading_image_document_) { | 560 if (loading_image_document_) |
| 563 CHECK(!has_pending_load_event_); | |
| 564 return; | 561 return; |
| 565 } | |
| 566 | |
| 567 CHECK(has_pending_load_event_); | |
| 568 | 562 |
| 569 if (resource->ErrorOccurred()) { | 563 if (resource->ErrorOccurred()) { |
| 570 LoadEventSender().CancelEvent(this); | 564 LoadEventSender().CancelEvent(this); |
| 571 has_pending_load_event_ = false; | 565 has_pending_load_event_ = false; |
| 572 | 566 |
| 573 if (resource->GetResourceError().IsAccessCheck()) { | 567 if (resource->GetResourceError().IsAccessCheck()) { |
| 574 CrossSiteOrCSPViolationOccurred( | 568 CrossSiteOrCSPViolationOccurred( |
| 575 AtomicString(resource->GetResourceError().FailingURL())); | 569 AtomicString(resource->GetResourceError().FailingURL())); |
| 576 } | 570 } |
| 577 | 571 |
| 578 // The error event should not fire if the image data update is a result of | 572 // The error event should not fire if the image data update is a result of |
| 579 // environment change. | 573 // environment change. |
| 580 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem ent:the-img-element-55 | 574 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem ent:the-img-element-55 |
| 581 if (!suppress_error_events_) | 575 if (!suppress_error_events_) |
| 582 DispatchErrorEvent(); | 576 DispatchErrorEvent(); |
| 583 | 577 |
| 584 // Only consider updating the protection ref-count of the Element | 578 // Only consider updating the protection ref-count of the Element |
| 585 // immediately before returning from this function as doing so might result | 579 // immediately before returning from this function as doing so might result |
| 586 // in the destruction of this ImageLoader. | 580 // in the destruction of this ImageLoader. |
| 587 UpdatedHasPendingEvent(); | 581 UpdatedHasPendingEvent(); |
| 588 return; | 582 return; |
| 589 } | 583 } |
| 584 has_pending_load_event_ = true; | |
| 590 LoadEventSender().DispatchEventSoon(this); | 585 LoadEventSender().DispatchEventSoon(this); |
| 591 } | 586 } |
| 592 | 587 |
| 593 LayoutImageResource* ImageLoader::GetLayoutImageResource() { | 588 LayoutImageResource* ImageLoader::GetLayoutImageResource() { |
| 594 LayoutObject* layout_object = element_->GetLayoutObject(); | 589 LayoutObject* layout_object = element_->GetLayoutObject(); |
| 595 | 590 |
| 596 if (!layout_object) | 591 if (!layout_object) |
| 597 return 0; | 592 return 0; |
| 598 | 593 |
| 599 // We don't return style generated image because it doesn't belong to the | 594 // We don't return style generated image because it doesn't belong to the |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 618 return; | 613 return; |
| 619 | 614 |
| 620 // Only update the layoutObject if it doesn't have an image or if what we have | 615 // Only update the layoutObject if it doesn't have an image or if what we have |
| 621 // is a complete image. This prevents flickering in the case where a dynamic | 616 // is a complete image. This prevents flickering in the case where a dynamic |
| 622 // change is happening between two images. | 617 // change is happening between two images. |
| 623 ImageResourceContent* cached_image = image_resource->CachedImage(); | 618 ImageResourceContent* cached_image = image_resource->CachedImage(); |
| 624 if (image_ != cached_image && (image_complete_ || !cached_image)) | 619 if (image_ != cached_image && (image_complete_ || !cached_image)) |
| 625 image_resource->SetImageResource(image_.Get()); | 620 image_resource->SetImageResource(image_.Get()); |
| 626 } | 621 } |
| 627 | 622 |
| 623 bool ImageLoader::HasPendingEvent() const { | |
| 624 return (image_ && !image_complete_ && !loading_image_document_) || | |
| 625 has_pending_load_event_ || has_pending_error_event_; | |
|
kinuko
2017/05/12 08:28:24
This condition is getting slightly complex, maybe
hiroshige
2017/05/19 20:56:35
Done.
| |
| 626 } | |
| 627 | |
| 628 void ImageLoader::UpdatedHasPendingEvent() { | 628 void ImageLoader::UpdatedHasPendingEvent() { |
| 629 // If an Element that does image loading is removed from the DOM the | 629 // If an Element that does image loading is removed from the DOM the |
| 630 // load/error event for the image is still observable. As long as the | 630 // load/error event for the image is still observable. As long as the |
| 631 // ImageLoader is actively loading, the Element itself needs to be ref'ed to | 631 // ImageLoader is actively loading, the Element itself needs to be ref'ed to |
| 632 // keep it from being destroyed by DOM manipulation or garbage collection. If | 632 // keep it from being destroyed by DOM manipulation or garbage collection. If |
| 633 // such an Element wishes for the load to stop when removed from the DOM it | 633 // such an Element wishes for the load to stop when removed from the DOM it |
| 634 // needs to stop the ImageLoader explicitly. | 634 // needs to stop the ImageLoader explicitly. |
| 635 bool was_protected = element_is_protected_; | 635 bool was_protected = element_is_protected_; |
| 636 element_is_protected_ = has_pending_load_event_ || has_pending_error_event_; | 636 element_is_protected_ = HasPendingEvent(); |
| 637 if (was_protected == element_is_protected_) | 637 if (was_protected == element_is_protected_) |
| 638 return; | 638 return; |
| 639 | 639 |
| 640 if (element_is_protected_) { | 640 if (element_is_protected_) { |
| 641 if (deref_element_timer_.IsActive()) | 641 if (deref_element_timer_.IsActive()) |
| 642 deref_element_timer_.Stop(); | 642 deref_element_timer_.Stop(); |
| 643 else | 643 else |
| 644 keep_alive_ = element_; | 644 keep_alive_ = element_; |
| 645 } else { | 645 } else { |
| 646 DCHECK(!deref_element_timer_.IsActive()); | 646 DCHECK(!deref_element_timer_.IsActive()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 } | 714 } |
| 715 if (delay_until_image_notify_finished_) { | 715 if (delay_until_image_notify_finished_) { |
| 716 delay_until_image_notify_finished_->DocumentChanged( | 716 delay_until_image_notify_finished_->DocumentChanged( |
| 717 element_->GetDocument()); | 717 element_->GetDocument()); |
| 718 } | 718 } |
| 719 ClearFailedLoadURL(); | 719 ClearFailedLoadURL(); |
| 720 ClearImage(); | 720 ClearImage(); |
| 721 } | 721 } |
| 722 | 722 |
| 723 } // namespace blink | 723 } // namespace blink |
| OLD | NEW |