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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include "core/loader/ImageLoader.h" | 23 #include "core/loader/ImageLoader.h" |
24 | 24 |
25 #include <memory> | 25 #include <memory> |
26 #include "bindings/core/v8/ScriptController.h" | 26 #include "bindings/core/v8/ScriptController.h" |
27 #include "bindings/core/v8/V8BindingForCore.h" | 27 #include "bindings/core/v8/V8BindingForCore.h" |
28 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
29 #include "core/dom/Element.h" | 29 #include "core/dom/Element.h" |
30 #include "core/dom/IncrementLoadEventDelayCount.h" | 30 #include "core/dom/IncrementLoadEventDelayCount.h" |
31 #include "core/events/Event.h" | 31 #include "core/events/Event.h" |
| 32 #include "core/events/EventSender.h" |
32 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
33 #include "core/frame/Settings.h" | 34 #include "core/frame/Settings.h" |
34 #include "core/frame/UseCounter.h" | 35 #include "core/frame/UseCounter.h" |
35 #include "core/html/CrossOriginAttribute.h" | 36 #include "core/html/CrossOriginAttribute.h" |
36 #include "core/html/HTMLImageElement.h" | 37 #include "core/html/HTMLImageElement.h" |
37 #include "core/html/parser/HTMLParserIdioms.h" | 38 #include "core/html/parser/HTMLParserIdioms.h" |
38 #include "core/layout/LayoutImage.h" | 39 #include "core/layout/LayoutImage.h" |
39 #include "core/layout/LayoutVideo.h" | 40 #include "core/layout/LayoutVideo.h" |
40 #include "core/layout/svg/LayoutSVGImage.h" | 41 #include "core/layout/svg/LayoutSVGImage.h" |
41 #include "core/probe/CoreProbes.h" | 42 #include "core/probe/CoreProbes.h" |
42 #include "core/svg/graphics/SVGImage.h" | 43 #include "core/svg/graphics/SVGImage.h" |
43 #include "platform/bindings/Microtask.h" | 44 #include "platform/bindings/Microtask.h" |
44 #include "platform/bindings/ScriptState.h" | 45 #include "platform/bindings/ScriptState.h" |
45 #include "platform/bindings/V8PerIsolateData.h" | 46 #include "platform/bindings/V8PerIsolateData.h" |
46 #include "platform/loader/fetch/FetchParameters.h" | 47 #include "platform/loader/fetch/FetchParameters.h" |
47 #include "platform/loader/fetch/MemoryCache.h" | 48 #include "platform/loader/fetch/MemoryCache.h" |
48 #include "platform/loader/fetch/ResourceFetcher.h" | 49 #include "platform/loader/fetch/ResourceFetcher.h" |
49 #include "platform/loader/fetch/ResourceLoadingLog.h" | 50 #include "platform/loader/fetch/ResourceLoadingLog.h" |
50 #include "platform/weborigin/SecurityOrigin.h" | 51 #include "platform/weborigin/SecurityOrigin.h" |
51 #include "platform/weborigin/SecurityPolicy.h" | 52 #include "platform/weborigin/SecurityPolicy.h" |
52 #include "platform/wtf/PtrUtil.h" | 53 #include "platform/wtf/PtrUtil.h" |
53 #include "public/platform/WebCachePolicy.h" | 54 #include "public/platform/WebCachePolicy.h" |
54 #include "public/platform/WebURLRequest.h" | 55 #include "public/platform/WebURLRequest.h" |
55 | 56 |
56 namespace blink { | 57 namespace blink { |
57 | 58 |
| 59 static ImageEventSender& LoadEventSender() { |
| 60 DEFINE_STATIC_LOCAL(ImageEventSender, sender, |
| 61 (ImageEventSender::Create(EventTypeNames::load))); |
| 62 return sender; |
| 63 } |
| 64 |
| 65 static ImageEventSender& ErrorEventSender() { |
| 66 DEFINE_STATIC_LOCAL(ImageEventSender, sender, |
| 67 (ImageEventSender::Create(EventTypeNames::error))); |
| 68 return sender; |
| 69 } |
| 70 |
58 static inline bool PageIsBeingDismissed(Document* document) { | 71 static inline bool PageIsBeingDismissed(Document* document) { |
59 return document->PageDismissalEventBeingDispatched() != | 72 return document->PageDismissalEventBeingDispatched() != |
60 Document::kNoDismissal; | 73 Document::kNoDismissal; |
61 } | 74 } |
62 | 75 |
63 static ImageLoader::BypassMainWorldBehavior ShouldBypassMainWorldCSP( | 76 static ImageLoader::BypassMainWorldBehavior ShouldBypassMainWorldCSP( |
64 ImageLoader* loader) { | 77 ImageLoader* loader) { |
65 DCHECK(loader); | 78 DCHECK(loader); |
66 DCHECK(loader->GetElement()); | 79 DCHECK(loader->GetElement()); |
67 if (loader->GetElement()->GetDocument().GetFrame() && | 80 if (loader->GetElement()->GetDocument().GetFrame() && |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 UpdateFromElementBehavior update_behavior_; | 150 UpdateFromElementBehavior update_behavior_; |
138 RefPtr<ScriptState> script_state_; | 151 RefPtr<ScriptState> script_state_; |
139 WeakPtrFactory<Task> weak_factory_; | 152 WeakPtrFactory<Task> weak_factory_; |
140 ReferrerPolicy referrer_policy_; | 153 ReferrerPolicy referrer_policy_; |
141 KURL request_url_; | 154 KURL request_url_; |
142 }; | 155 }; |
143 | 156 |
144 ImageLoader::ImageLoader(Element* element) | 157 ImageLoader::ImageLoader(Element* element) |
145 : element_(element), | 158 : element_(element), |
146 deref_element_timer_(this, &ImageLoader::TimerFired), | 159 deref_element_timer_(this, &ImageLoader::TimerFired), |
| 160 has_pending_load_event_(false), |
| 161 has_pending_error_event_(false), |
147 image_complete_(true), | 162 image_complete_(true), |
148 loading_image_document_(false), | 163 loading_image_document_(false), |
149 element_is_protected_(false), | 164 element_is_protected_(false), |
150 suppress_error_events_(false) { | 165 suppress_error_events_(false) { |
151 RESOURCE_LOADING_DVLOG(1) << "new ImageLoader " << this; | 166 RESOURCE_LOADING_DVLOG(1) << "new ImageLoader " << this; |
152 } | 167 } |
153 | 168 |
154 ImageLoader::~ImageLoader() {} | 169 ImageLoader::~ImageLoader() {} |
155 | 170 |
156 void ImageLoader::Dispose() { | 171 void ImageLoader::Dispose() { |
157 RESOURCE_LOADING_DVLOG(1) | 172 RESOURCE_LOADING_DVLOG(1) |
158 << "~ImageLoader " << this | 173 << "~ImageLoader " << this |
159 << "; has pending load event=" << pending_load_event_.IsActive() | 174 << "; has_pending_load_event_=" << has_pending_load_event_ |
160 << ", has pending error event=" << pending_error_event_.IsActive(); | 175 << ", has_pending_error_event_=" << has_pending_error_event_; |
161 | 176 |
162 if (image_) { | 177 if (image_) { |
163 image_->RemoveObserver(this); | 178 image_->RemoveObserver(this); |
164 image_ = nullptr; | 179 image_ = nullptr; |
165 delay_until_image_notify_finished_ = nullptr; | 180 delay_until_image_notify_finished_ = nullptr; |
166 } | 181 } |
167 } | 182 } |
168 | 183 |
169 DEFINE_TRACE(ImageLoader) { | 184 DEFINE_TRACE(ImageLoader) { |
170 visitor->Trace(image_); | 185 visitor->Trace(image_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // 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 |
209 // destruction of this ImageLoader. | 224 // destruction of this ImageLoader. |
210 UpdatedHasPendingEvent(); | 225 UpdatedHasPendingEvent(); |
211 } | 226 } |
212 | 227 |
213 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( | 228 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( |
214 ImageResourceContent* new_image) { | 229 ImageResourceContent* new_image) { |
215 DCHECK(failed_load_url_.IsEmpty()); | 230 DCHECK(failed_load_url_.IsEmpty()); |
216 ImageResourceContent* old_image = image_.Get(); | 231 ImageResourceContent* old_image = image_.Get(); |
217 if (new_image != old_image) { | 232 if (new_image != old_image) { |
218 if (pending_load_event_.IsActive()) | 233 if (has_pending_load_event_) { |
219 pending_load_event_.Cancel(); | 234 LoadEventSender().CancelEvent(this); |
220 if (pending_error_event_.IsActive()) | 235 has_pending_load_event_ = false; |
221 pending_error_event_.Cancel(); | 236 } |
| 237 if (has_pending_error_event_) { |
| 238 ErrorEventSender().CancelEvent(this); |
| 239 has_pending_error_event_ = false; |
| 240 } |
222 UpdateImageState(new_image); | 241 UpdateImageState(new_image); |
223 if (new_image) { | 242 if (new_image) { |
224 new_image->AddObserver(this); | 243 new_image->AddObserver(this); |
225 } | 244 } |
226 if (old_image) { | 245 if (old_image) { |
227 old_image->RemoveObserver(this); | 246 old_image->RemoveObserver(this); |
228 } | 247 } |
229 } | 248 } |
230 | 249 |
231 if (LayoutImageResource* image_resource = GetLayoutImageResource()) | 250 if (LayoutImageResource* image_resource = GetLayoutImageResource()) |
(...skipping 16 matching lines...) Expand all Loading... |
248 } | 267 } |
249 | 268 |
250 if (client_hints_preferences.ShouldSendResourceWidth() && | 269 if (client_hints_preferences.ShouldSendResourceWidth() && |
251 isHTMLImageElement(element)) | 270 isHTMLImageElement(element)) |
252 params.SetResourceWidth(toHTMLImageElement(element).GetResourceWidth()); | 271 params.SetResourceWidth(toHTMLImageElement(element).GetResourceWidth()); |
253 } | 272 } |
254 | 273 |
255 inline void ImageLoader::DispatchErrorEvent() { | 274 inline void ImageLoader::DispatchErrorEvent() { |
256 // There can be cases where DispatchErrorEvent() is called when there is | 275 // There can be cases where DispatchErrorEvent() is called when there is |
257 // already a scheduled error event for the previous load attempt. | 276 // already a scheduled error event for the previous load attempt. |
258 // In such cases we cancel the previous event (by overwriting | 277 // In such cases we cancel the previous event and then re-schedule a new |
259 // |pending_error_event_|) and then re-schedule a new error event here. | 278 // error event here. crbug.com/722500 |
260 // crbug.com/722500 | 279 if (has_pending_error_event_) |
261 pending_error_event_ = | 280 ErrorEventSender().CancelEvent(this); |
262 TaskRunnerHelper::Get(TaskType::kDOMManipulation, | 281 |
263 &GetElement()->GetDocument()) | 282 has_pending_error_event_ = true; |
264 ->PostCancellableTask( | 283 ErrorEventSender().DispatchEventSoon(this); |
265 BLINK_FROM_HERE, | |
266 WTF::Bind(&ImageLoader::DispatchPendingErrorEvent, | |
267 WrapPersistent(this), | |
268 WTF::Passed(IncrementLoadEventDelayCount::Create( | |
269 GetElement()->GetDocument())))); | |
270 } | 284 } |
271 | 285 |
272 inline void ImageLoader::CrossSiteOrCSPViolationOccurred( | 286 inline void ImageLoader::CrossSiteOrCSPViolationOccurred( |
273 AtomicString image_source_url) { | 287 AtomicString image_source_url) { |
274 failed_load_url_ = image_source_url; | 288 failed_load_url_ = image_source_url; |
275 } | 289 } |
276 | 290 |
277 inline void ImageLoader::ClearFailedLoadURL() { | 291 inline void ImageLoader::ClearFailedLoadURL() { |
278 failed_load_url_ = AtomicString(); | 292 failed_load_url_ = AtomicString(); |
279 } | 293 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 DispatchErrorEvent(); | 375 DispatchErrorEvent(); |
362 } | 376 } |
363 NoImageResourceToLoad(); | 377 NoImageResourceToLoad(); |
364 } | 378 } |
365 | 379 |
366 ImageResourceContent* old_image = image_.Get(); | 380 ImageResourceContent* old_image = image_.Get(); |
367 if (update_behavior == kUpdateSizeChanged && element_->GetLayoutObject() && | 381 if (update_behavior == kUpdateSizeChanged && element_->GetLayoutObject() && |
368 element_->GetLayoutObject()->IsImage() && new_image == old_image) { | 382 element_->GetLayoutObject()->IsImage() && new_image == old_image) { |
369 ToLayoutImage(element_->GetLayoutObject())->IntrinsicSizeChanged(); | 383 ToLayoutImage(element_->GetLayoutObject())->IntrinsicSizeChanged(); |
370 } else { | 384 } else { |
371 if (pending_load_event_.IsActive()) | 385 if (has_pending_load_event_) { |
372 pending_load_event_.Cancel(); | 386 LoadEventSender().CancelEvent(this); |
| 387 has_pending_load_event_ = false; |
| 388 } |
373 | 389 |
374 // Cancel error events that belong to the previous load, which is now | 390 // Cancel error events that belong to the previous load, which is now |
375 // cancelled by changing the src attribute. If newImage is null and | 391 // cancelled by changing the src attribute. If newImage is null and |
376 // has_pending_error_event_ is true, we know the error event has been just | 392 // has_pending_error_event_ is true, we know the error event has been just |
377 // posted by this load and we should not cancel the event. | 393 // posted by this load and we should not cancel the event. |
378 // FIXME: If both previous load and this one got blocked with an error, we | 394 // FIXME: If both previous load and this one got blocked with an error, we |
379 // can receive one error event instead of two. | 395 // can receive one error event instead of two. |
380 if (pending_error_event_.IsActive() && new_image) | 396 if (has_pending_error_event_ && new_image) { |
381 pending_error_event_.Cancel(); | 397 ErrorEventSender().CancelEvent(this); |
| 398 has_pending_error_event_ = false; |
| 399 } |
382 | 400 |
383 UpdateImageState(new_image); | 401 UpdateImageState(new_image); |
384 | 402 |
385 UpdateLayoutObject(); | 403 UpdateLayoutObject(); |
386 // If newImage exists and is cached, addObserver() will result in the load | 404 // If newImage exists and is cached, addObserver() will result in the load |
387 // event being queued to fire. Ensure this happens after beforeload is | 405 // event being queued to fire. Ensure this happens after beforeload is |
388 // dispatched. | 406 // dispatched. |
389 if (new_image) { | 407 if (new_image) { |
390 new_image->AddObserver(this); | 408 new_image->AddObserver(this); |
391 } | 409 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 if (!document.IsActive()) | 529 if (!document.IsActive()) |
512 return; | 530 return; |
513 | 531 |
514 delay_until_image_notify_finished_ = | 532 delay_until_image_notify_finished_ = |
515 IncrementLoadEventDelayCount::Create(document); | 533 IncrementLoadEventDelayCount::Create(document); |
516 } | 534 } |
517 | 535 |
518 void ImageLoader::ImageNotifyFinished(ImageResourceContent* resource) { | 536 void ImageLoader::ImageNotifyFinished(ImageResourceContent* resource) { |
519 RESOURCE_LOADING_DVLOG(1) | 537 RESOURCE_LOADING_DVLOG(1) |
520 << "ImageLoader::imageNotifyFinished " << this | 538 << "ImageLoader::imageNotifyFinished " << this |
521 << "; has pending load event=" << pending_load_event_.IsActive(); | 539 << "; has_pending_load_event_=" << has_pending_load_event_; |
522 | 540 |
523 DCHECK(failed_load_url_.IsEmpty()); | 541 DCHECK(failed_load_url_.IsEmpty()); |
524 DCHECK_EQ(resource, image_.Get()); | 542 DCHECK_EQ(resource, image_.Get()); |
525 | 543 |
526 // |image_complete_| is always true for entire ImageDocument loading for | 544 // |image_complete_| is always true for entire ImageDocument loading for |
527 // historical reason. | 545 // historical reason. |
528 // DoUpdateFromElement() is not called and SetImageForImageDocument() | 546 // DoUpdateFromElement() is not called and SetImageForImageDocument() |
529 // is called instead for ImageDocument loading. | 547 // is called instead for ImageDocument loading. |
530 // 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. |
531 if (loading_image_document_) | 549 if (loading_image_document_) |
(...skipping 15 matching lines...) Expand all Loading... |
547 // checks, which can occur anytime after ImageNotifyFinished() | 565 // checks, which can occur anytime after ImageNotifyFinished() |
548 // (See SVGImage::CurrentFrameHasSingleSecurityOrigin()). | 566 // (See SVGImage::CurrentFrameHasSingleSecurityOrigin()). |
549 // We check the document is loaded here to catch violation of the | 567 // We check the document is loaded here to catch violation of the |
550 // assumption reliably. | 568 // assumption reliably. |
551 ToSVGImage(image_->GetImage())->CheckLoaded(); | 569 ToSVGImage(image_->GetImage())->CheckLoaded(); |
552 | 570 |
553 ToSVGImage(image_->GetImage()) | 571 ToSVGImage(image_->GetImage()) |
554 ->UpdateUseCounters(GetElement()->GetDocument()); | 572 ->UpdateUseCounters(GetElement()->GetDocument()); |
555 } | 573 } |
556 | 574 |
557 if (loading_image_document_) { | 575 if (loading_image_document_) |
558 CHECK(!pending_load_event_.IsActive()); | |
559 return; | 576 return; |
560 } | |
561 | 577 |
562 if (resource->ErrorOccurred()) { | 578 if (resource->ErrorOccurred()) { |
563 pending_load_event_.Cancel(); | 579 LoadEventSender().CancelEvent(this); |
| 580 has_pending_load_event_ = false; |
564 | 581 |
565 if (resource->GetResourceError().IsAccessCheck()) { | 582 if (resource->GetResourceError().IsAccessCheck()) { |
566 CrossSiteOrCSPViolationOccurred( | 583 CrossSiteOrCSPViolationOccurred( |
567 AtomicString(resource->GetResourceError().FailingURL())); | 584 AtomicString(resource->GetResourceError().FailingURL())); |
568 } | 585 } |
569 | 586 |
570 // The error event should not fire if the image data update is a result of | 587 // The error event should not fire if the image data update is a result of |
571 // environment change. | 588 // environment change. |
572 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem
ent:the-img-element-55 | 589 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem
ent:the-img-element-55 |
573 if (!suppress_error_events_) | 590 if (!suppress_error_events_) |
574 DispatchErrorEvent(); | 591 DispatchErrorEvent(); |
575 | 592 |
576 // Only consider updating the protection ref-count of the Element | 593 // Only consider updating the protection ref-count of the Element |
577 // immediately before returning from this function as doing so might result | 594 // immediately before returning from this function as doing so might result |
578 // in the destruction of this ImageLoader. | 595 // in the destruction of this ImageLoader. |
579 UpdatedHasPendingEvent(); | 596 UpdatedHasPendingEvent(); |
580 return; | 597 return; |
581 } | 598 } |
582 | 599 has_pending_load_event_ = true; |
583 CHECK(!pending_load_event_.IsActive()); | 600 LoadEventSender().DispatchEventSoon(this); |
584 pending_load_event_ = | |
585 TaskRunnerHelper::Get(TaskType::kDOMManipulation, | |
586 &GetElement()->GetDocument()) | |
587 ->PostCancellableTask( | |
588 BLINK_FROM_HERE, | |
589 WTF::Bind(&ImageLoader::DispatchPendingLoadEvent, | |
590 WrapPersistent(this), | |
591 WTF::Passed(IncrementLoadEventDelayCount::Create( | |
592 GetElement()->GetDocument())))); | |
593 } | 601 } |
594 | 602 |
595 LayoutImageResource* ImageLoader::GetLayoutImageResource() { | 603 LayoutImageResource* ImageLoader::GetLayoutImageResource() { |
596 LayoutObject* layout_object = element_->GetLayoutObject(); | 604 LayoutObject* layout_object = element_->GetLayoutObject(); |
597 | 605 |
598 if (!layout_object) | 606 if (!layout_object) |
599 return 0; | 607 return 0; |
600 | 608 |
601 // We don't return style generated image because it doesn't belong to the | 609 // We don't return style generated image because it doesn't belong to the |
602 // ImageLoader. See <https://bugs.webkit.org/show_bug.cgi?id=42840> | 610 // ImageLoader. See <https://bugs.webkit.org/show_bug.cgi?id=42840> |
(...skipping 22 matching lines...) Expand all Loading... |
625 ImageResourceContent* cached_image = image_resource->CachedImage(); | 633 ImageResourceContent* cached_image = image_resource->CachedImage(); |
626 if (image_ != cached_image && (image_complete_ || !cached_image)) | 634 if (image_ != cached_image && (image_complete_ || !cached_image)) |
627 image_resource->SetImageResource(image_.Get()); | 635 image_resource->SetImageResource(image_.Get()); |
628 } | 636 } |
629 | 637 |
630 bool ImageLoader::HasPendingEvent() const { | 638 bool ImageLoader::HasPendingEvent() const { |
631 // Regular image loading is in progress. | 639 // Regular image loading is in progress. |
632 if (image_ && !image_complete_ && !loading_image_document_) | 640 if (image_ && !image_complete_ && !loading_image_document_) |
633 return true; | 641 return true; |
634 | 642 |
635 if (pending_load_event_.IsActive() || pending_error_event_.IsActive()) | 643 if (has_pending_load_event_ || has_pending_error_event_) |
636 return true; | 644 return true; |
637 | 645 |
638 return false; | 646 return false; |
639 } | 647 } |
640 | 648 |
641 void ImageLoader::UpdatedHasPendingEvent() { | 649 void ImageLoader::UpdatedHasPendingEvent() { |
642 // If an Element that does image loading is removed from the DOM the | 650 // If an Element that does image loading is removed from the DOM the |
643 // load/error event for the image is still observable. As long as the | 651 // load/error event for the image is still observable. As long as the |
644 // ImageLoader is actively loading, the Element itself needs to be ref'ed to | 652 // ImageLoader is actively loading, the Element itself needs to be ref'ed to |
645 // keep it from being destroyed by DOM manipulation or garbage collection. If | 653 // keep it from being destroyed by DOM manipulation or garbage collection. If |
(...skipping 12 matching lines...) Expand all Loading... |
658 } else { | 666 } else { |
659 DCHECK(!deref_element_timer_.IsActive()); | 667 DCHECK(!deref_element_timer_.IsActive()); |
660 deref_element_timer_.StartOneShot(0, BLINK_FROM_HERE); | 668 deref_element_timer_.StartOneShot(0, BLINK_FROM_HERE); |
661 } | 669 } |
662 } | 670 } |
663 | 671 |
664 void ImageLoader::TimerFired(TimerBase*) { | 672 void ImageLoader::TimerFired(TimerBase*) { |
665 keep_alive_.Clear(); | 673 keep_alive_.Clear(); |
666 } | 674 } |
667 | 675 |
668 void ImageLoader::DispatchPendingLoadEvent( | 676 void ImageLoader::DispatchPendingEvent(ImageEventSender* event_sender) { |
669 std::unique_ptr<IncrementLoadEventDelayCount> count) { | 677 RESOURCE_LOADING_DVLOG(1) << "ImageLoader::dispatchPendingEvent " << this; |
| 678 DCHECK(event_sender == &LoadEventSender() || |
| 679 event_sender == &ErrorEventSender()); |
| 680 const AtomicString& event_type = event_sender->EventType(); |
| 681 if (event_type == EventTypeNames::load) |
| 682 DispatchPendingLoadEvent(); |
| 683 if (event_type == EventTypeNames::error) |
| 684 DispatchPendingErrorEvent(); |
| 685 } |
| 686 |
| 687 void ImageLoader::DispatchPendingLoadEvent() { |
| 688 CHECK(has_pending_load_event_); |
670 if (!image_) | 689 if (!image_) |
671 return; | 690 return; |
672 CHECK(image_complete_); | 691 CHECK(image_complete_); |
| 692 has_pending_load_event_ = false; |
673 if (GetElement()->GetDocument().GetFrame()) | 693 if (GetElement()->GetDocument().GetFrame()) |
674 DispatchLoadEvent(); | 694 DispatchLoadEvent(); |
675 | 695 |
676 // Only consider updating the protection ref-count of the Element immediately | 696 // Only consider updating the protection ref-count of the Element immediately |
677 // before returning from this function as doing so might result in the | 697 // before returning from this function as doing so might result in the |
678 // destruction of this ImageLoader. | 698 // destruction of this ImageLoader. |
679 UpdatedHasPendingEvent(); | 699 UpdatedHasPendingEvent(); |
680 | |
681 // Checks Document's load event synchronously here for performance. | |
682 // This is safe because DispatchPendingLoadEvent() is called asynchronously. | |
683 count->ClearAndCheckLoadEvent(); | |
684 } | 700 } |
685 | 701 |
686 void ImageLoader::DispatchPendingErrorEvent( | 702 void ImageLoader::DispatchPendingErrorEvent() { |
687 std::unique_ptr<IncrementLoadEventDelayCount> count) { | 703 CHECK(has_pending_error_event_); |
| 704 has_pending_error_event_ = false; |
| 705 |
688 if (GetElement()->GetDocument().GetFrame()) | 706 if (GetElement()->GetDocument().GetFrame()) |
689 GetElement()->DispatchEvent(Event::Create(EventTypeNames::error)); | 707 GetElement()->DispatchEvent(Event::Create(EventTypeNames::error)); |
690 | 708 |
691 // Only consider updating the protection ref-count of the Element immediately | 709 // Only consider updating the protection ref-count of the Element immediately |
692 // before returning from this function as doing so might result in the | 710 // before returning from this function as doing so might result in the |
693 // destruction of this ImageLoader. | 711 // destruction of this ImageLoader. |
694 UpdatedHasPendingEvent(); | 712 UpdatedHasPendingEvent(); |
695 | |
696 // Checks Document's load event synchronously here for performance. | |
697 // This is safe because DispatchPendingErrorEvent() is called asynchronously. | |
698 count->ClearAndCheckLoadEvent(); | |
699 } | 713 } |
700 | 714 |
701 bool ImageLoader::GetImageAnimationPolicy(ImageAnimationPolicy& policy) { | 715 bool ImageLoader::GetImageAnimationPolicy(ImageAnimationPolicy& policy) { |
702 if (!GetElement()->GetDocument().GetSettings()) | 716 if (!GetElement()->GetDocument().GetSettings()) |
703 return false; | 717 return false; |
704 | 718 |
705 policy = GetElement()->GetDocument().GetSettings()->GetImageAnimationPolicy(); | 719 policy = GetElement()->GetDocument().GetSettings()->GetImageAnimationPolicy(); |
706 return true; | 720 return true; |
707 } | 721 } |
708 | 722 |
| 723 void ImageLoader::DispatchPendingLoadEvents() { |
| 724 LoadEventSender().DispatchPendingEvents(); |
| 725 } |
| 726 |
| 727 void ImageLoader::DispatchPendingErrorEvents() { |
| 728 ErrorEventSender().DispatchPendingEvents(); |
| 729 } |
| 730 |
709 void ImageLoader::ElementDidMoveToNewDocument() { | 731 void ImageLoader::ElementDidMoveToNewDocument() { |
710 if (delay_until_do_update_from_element_) { | 732 if (delay_until_do_update_from_element_) { |
711 delay_until_do_update_from_element_->DocumentChanged( | 733 delay_until_do_update_from_element_->DocumentChanged( |
712 element_->GetDocument()); | 734 element_->GetDocument()); |
713 } | 735 } |
714 if (delay_until_image_notify_finished_) { | 736 if (delay_until_image_notify_finished_) { |
715 delay_until_image_notify_finished_->DocumentChanged( | 737 delay_until_image_notify_finished_->DocumentChanged( |
716 element_->GetDocument()); | 738 element_->GetDocument()); |
717 } | 739 } |
718 ClearFailedLoadURL(); | 740 ClearFailedLoadURL(); |
719 ClearImage(); | 741 ClearImage(); |
720 } | 742 } |
721 | 743 |
722 } // namespace blink | 744 } // namespace blink |
OLD | NEW |