Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: third_party/WebKit/Source/core/loader/ImageLoader.cpp

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

Powered by Google App Engine
This is Rietveld 408576698