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

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

Issue 2863763003: Remove EventSender from ImageLoader (Closed)
Patch Set: fix tests 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
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 12 matching lines...) Expand all
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 "bindings/core/v8/V8PerIsolateData.h" 28 #include "bindings/core/v8/V8PerIsolateData.h"
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/dom/Element.h" 30 #include "core/dom/Element.h"
31 #include "core/dom/IncrementLoadEventDelayCount.h" 31 #include "core/dom/IncrementLoadEventDelayCount.h"
32 #include "core/events/Event.h" 32 #include "core/events/Event.h"
33 #include "core/events/EventSender.h"
34 #include "core/frame/LocalFrame.h" 33 #include "core/frame/LocalFrame.h"
35 #include "core/frame/Settings.h" 34 #include "core/frame/Settings.h"
36 #include "core/frame/UseCounter.h" 35 #include "core/frame/UseCounter.h"
37 #include "core/html/CrossOriginAttribute.h" 36 #include "core/html/CrossOriginAttribute.h"
38 #include "core/html/HTMLImageElement.h" 37 #include "core/html/HTMLImageElement.h"
39 #include "core/html/parser/HTMLParserIdioms.h" 38 #include "core/html/parser/HTMLParserIdioms.h"
40 #include "core/layout/LayoutImage.h" 39 #include "core/layout/LayoutImage.h"
41 #include "core/layout/LayoutVideo.h" 40 #include "core/layout/LayoutVideo.h"
42 #include "core/layout/svg/LayoutSVGImage.h" 41 #include "core/layout/svg/LayoutSVGImage.h"
43 #include "core/probe/CoreProbes.h" 42 #include "core/probe/CoreProbes.h"
44 #include "core/svg/graphics/SVGImage.h" 43 #include "core/svg/graphics/SVGImage.h"
45 #include "platform/bindings/Microtask.h" 44 #include "platform/bindings/Microtask.h"
46 #include "platform/bindings/ScriptState.h" 45 #include "platform/bindings/ScriptState.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 << "; m_hasPendingLoadEvent=" << has_pending_load_event_ 159 << "; pending load event=" << pending_load_event_.IsActive()
175 << ", m_hasPendingErrorEvent=" << has_pending_error_event_; 160 << ", 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 10 matching lines...) Expand all
196 UpdatedHasPendingEvent(); 181 UpdatedHasPendingEvent();
197 } 182 }
198 183
199 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent( 184 void ImageLoader::SetImageWithoutConsideringPendingLoadEvent(
200 ImageResourceContent* new_image) { 185 ImageResourceContent* new_image) {
201 DCHECK(failed_load_url_.IsEmpty()); 186 DCHECK(failed_load_url_.IsEmpty());
202 ImageResourceContent* old_image = image_.Get(); 187 ImageResourceContent* old_image = image_.Get();
203 if (new_image != old_image) { 188 if (new_image != old_image) {
204 image_ = new_image; 189 image_ = new_image;
205 delay_until_image_notify_finished_ = nullptr; 190 delay_until_image_notify_finished_ = nullptr;
206 if (has_pending_load_event_) { 191 if (pending_load_event_.IsActive())
207 LoadEventSender().CancelEvent(this); 192 pending_load_event_.Cancel();
208 has_pending_load_event_ = false; 193 if (pending_error_event_.IsActive())
209 } 194 pending_error_event_.Cancel();
210 if (has_pending_error_event_) {
211 ErrorEventSender().CancelEvent(this);
212 has_pending_error_event_ = false;
213 }
214 image_complete_ = true; 195 image_complete_ = true;
215 if (new_image) { 196 if (new_image) {
216 new_image->AddObserver(this); 197 new_image->AddObserver(this);
217 } 198 }
218 if (old_image) { 199 if (old_image) {
219 old_image->RemoveObserver(this); 200 old_image->RemoveObserver(this);
220 } 201 }
221 } 202 }
222 203
223 if (LayoutImageResource* image_resource = GetLayoutImageResource()) 204 if (LayoutImageResource* image_resource = GetLayoutImageResource())
(...skipping 14 matching lines...) Expand all
238 params.SetCrossOriginAccessControl( 219 params.SetCrossOriginAccessControl(
239 element.GetDocument().GetSecurityOrigin(), cross_origin); 220 element.GetDocument().GetSecurityOrigin(), cross_origin);
240 } 221 }
241 222
242 if (client_hints_preferences.ShouldSendResourceWidth() && 223 if (client_hints_preferences.ShouldSendResourceWidth() &&
243 isHTMLImageElement(element)) 224 isHTMLImageElement(element))
244 params.SetResourceWidth(toHTMLImageElement(element).GetResourceWidth()); 225 params.SetResourceWidth(toHTMLImageElement(element).GetResourceWidth());
245 } 226 }
246 227
247 inline void ImageLoader::DispatchErrorEvent() { 228 inline void ImageLoader::DispatchErrorEvent() {
248 has_pending_error_event_ = true; 229 pending_error_event_ =
249 ErrorEventSender().DispatchEventSoon(this); 230 TaskRunnerHelper::Get(TaskType::kDOMManipulation,
231 &GetElement()->GetDocument())
232 ->PostCancellableTask(
233 BLINK_FROM_HERE,
234 WTF::Bind(&ImageLoader::DispatchPendingErrorEvent,
235 WrapPersistent(this),
236 WTF::Passed(IncrementLoadEventDelayCount::Create(
237 GetElement()->GetDocument()))));
250 } 238 }
251 239
252 inline void ImageLoader::CrossSiteOrCSPViolationOccurred( 240 inline void ImageLoader::CrossSiteOrCSPViolationOccurred(
253 AtomicString image_source_url) { 241 AtomicString image_source_url) {
254 failed_load_url_ = image_source_url; 242 failed_load_url_ = image_source_url;
255 } 243 }
256 244
257 inline void ImageLoader::ClearFailedLoadURL() { 245 inline void ImageLoader::ClearFailedLoadURL() {
258 failed_load_url_ = AtomicString(); 246 failed_load_url_ = AtomicString();
259 } 247 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 DispatchErrorEvent(); 323 DispatchErrorEvent();
336 } 324 }
337 NoImageResourceToLoad(); 325 NoImageResourceToLoad();
338 } 326 }
339 327
340 ImageResourceContent* old_image = image_.Get(); 328 ImageResourceContent* old_image = image_.Get();
341 if (update_behavior == kUpdateSizeChanged && element_->GetLayoutObject() && 329 if (update_behavior == kUpdateSizeChanged && element_->GetLayoutObject() &&
342 element_->GetLayoutObject()->IsImage() && new_image == old_image) { 330 element_->GetLayoutObject()->IsImage() && new_image == old_image) {
343 ToLayoutImage(element_->GetLayoutObject())->IntrinsicSizeChanged(); 331 ToLayoutImage(element_->GetLayoutObject())->IntrinsicSizeChanged();
344 } else { 332 } else {
345 if (has_pending_load_event_) { 333 if (pending_load_event_.IsActive())
346 LoadEventSender().CancelEvent(this); 334 pending_load_event_.Cancel();
347 has_pending_load_event_ = false;
348 }
349 335
350 // Cancel error events that belong to the previous load, which is now 336 // Cancel error events that belong to the previous load, which is now
351 // cancelled by changing the src attribute. If newImage is null and 337 // cancelled by changing the src attribute. If newImage is null and
352 // m_hasPendingErrorEvent is true, we know the error event has been just 338 // m_hasPendingErrorEvent is true, we know the error event has been just
353 // posted by this load and we should not cancel the event. 339 // 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 340 // FIXME: If both previous load and this one got blocked with an error, we
355 // can receive one error event instead of two. 341 // can receive one error event instead of two.
356 if (has_pending_error_event_ && new_image) { 342 if (pending_error_event_.IsActive() && new_image)
357 ErrorEventSender().CancelEvent(this); 343 pending_error_event_.Cancel();
358 has_pending_error_event_ = false;
359 }
360 344
361 image_ = new_image; 345 image_ = new_image;
362 image_complete_ = !new_image; 346 image_complete_ = !new_image;
363 delay_until_image_notify_finished_ = nullptr; 347 delay_until_image_notify_finished_ = nullptr;
364 348
365 UpdateLayoutObject(); 349 UpdateLayoutObject();
366 // If newImage exists and is cached, addObserver() will result in the load 350 // If newImage exists and is cached, addObserver() will result in the load
367 // event being queued to fire. Ensure this happens after beforeload is 351 // event being queued to fire. Ensure this happens after beforeload is
368 // dispatched. 352 // dispatched.
369 if (new_image) { 353 if (new_image) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (!document.IsActive()) 467 if (!document.IsActive())
484 return; 468 return;
485 469
486 delay_until_image_notify_finished_ = 470 delay_until_image_notify_finished_ =
487 IncrementLoadEventDelayCount::Create(document); 471 IncrementLoadEventDelayCount::Create(document);
488 } 472 }
489 473
490 void ImageLoader::ImageNotifyFinished(ImageResourceContent* resource) { 474 void ImageLoader::ImageNotifyFinished(ImageResourceContent* resource) {
491 RESOURCE_LOADING_DVLOG(1) 475 RESOURCE_LOADING_DVLOG(1)
492 << "ImageLoader::imageNotifyFinished " << this 476 << "ImageLoader::imageNotifyFinished " << this
493 << "; m_hasPendingLoadEvent=" << has_pending_load_event_; 477 << "; m_hasPendingLoadEvent=" << pending_load_event_.IsActive();
494 478
495 DCHECK(failed_load_url_.IsEmpty()); 479 DCHECK(failed_load_url_.IsEmpty());
496 DCHECK_EQ(resource, image_.Get()); 480 DCHECK_EQ(resource, image_.Get());
497 481
498 if (loading_image_document_) { 482 if (loading_image_document_) {
499 CHECK(image_complete_); 483 CHECK(image_complete_);
500 } else { 484 } else {
501 CHECK(!image_complete_); 485 CHECK(!image_complete_);
502 } 486 }
503 487
504 image_complete_ = true; 488 image_complete_ = true;
505 delay_until_image_notify_finished_ = nullptr; 489 delay_until_image_notify_finished_ = nullptr;
506 490
507 // Update ImageAnimationPolicy for m_image. 491 // Update ImageAnimationPolicy for m_image.
508 if (image_) 492 if (image_)
509 image_->UpdateImageAnimationPolicy(); 493 image_->UpdateImageAnimationPolicy();
510 494
511 UpdateLayoutObject(); 495 UpdateLayoutObject();
512 496
513 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage()) 497 if (image_ && image_->GetImage() && image_->GetImage()->IsSVGImage())
514 ToSVGImage(image_->GetImage()) 498 ToSVGImage(image_->GetImage())
515 ->UpdateUseCounters(GetElement()->GetDocument()); 499 ->UpdateUseCounters(GetElement()->GetDocument());
516 500
517 if (loading_image_document_) 501 if (loading_image_document_) {
502 CHECK(!pending_load_event_.IsActive());
518 return; 503 return;
504 }
519 505
520 if (resource->ErrorOccurred()) { 506 if (resource->ErrorOccurred()) {
521 LoadEventSender().CancelEvent(this); 507 pending_load_event_.Cancel();
522 has_pending_load_event_ = false;
523 508
524 if (resource->GetResourceError().IsAccessCheck()) { 509 if (resource->GetResourceError().IsAccessCheck()) {
525 CrossSiteOrCSPViolationOccurred( 510 CrossSiteOrCSPViolationOccurred(
526 AtomicString(resource->GetResourceError().FailingURL())); 511 AtomicString(resource->GetResourceError().FailingURL()));
527 } 512 }
528 513
529 // The error event should not fire if the image data update is a result of 514 // The error event should not fire if the image data update is a result of
530 // environment change. 515 // environment change.
531 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem ent:the-img-element-55 516 // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-elem ent:the-img-element-55
532 if (!suppress_error_events_) 517 if (!suppress_error_events_)
533 DispatchErrorEvent(); 518 DispatchErrorEvent();
534 519
535 // Only consider updating the protection ref-count of the Element 520 // Only consider updating the protection ref-count of the Element
536 // immediately before returning from this function as doing so might result 521 // immediately before returning from this function as doing so might result
537 // in the destruction of this ImageLoader. 522 // in the destruction of this ImageLoader.
538 UpdatedHasPendingEvent(); 523 UpdatedHasPendingEvent();
539 return; 524 return;
540 } 525 }
541 has_pending_load_event_ = true; 526
542 LoadEventSender().DispatchEventSoon(this); 527 CHECK(!pending_load_event_.IsActive());
528 pending_load_event_ =
529 TaskRunnerHelper::Get(TaskType::kDOMManipulation,
530 &GetElement()->GetDocument())
531 ->PostCancellableTask(
532 BLINK_FROM_HERE,
533 WTF::Bind(&ImageLoader::DispatchPendingLoadEvent,
534 WrapPersistent(this),
535 WTF::Passed(IncrementLoadEventDelayCount::Create(
536 GetElement()->GetDocument()))));
543 } 537 }
544 538
545 LayoutImageResource* ImageLoader::GetLayoutImageResource() { 539 LayoutImageResource* ImageLoader::GetLayoutImageResource() {
546 LayoutObject* layout_object = element_->GetLayoutObject(); 540 LayoutObject* layout_object = element_->GetLayoutObject();
547 541
548 if (!layout_object) 542 if (!layout_object)
549 return 0; 543 return 0;
550 544
551 // We don't return style generated image because it doesn't belong to the 545 // We don't return style generated image because it doesn't belong to the
552 // ImageLoader. See <https://bugs.webkit.org/show_bug.cgi?id=42840> 546 // ImageLoader. See <https://bugs.webkit.org/show_bug.cgi?id=42840>
(...skipping 26 matching lines...) Expand all
579 573
580 void ImageLoader::UpdatedHasPendingEvent() { 574 void ImageLoader::UpdatedHasPendingEvent() {
581 // If an Element that does image loading is removed from the DOM the 575 // If an Element that does image loading is removed from the DOM the
582 // load/error event for the image is still observable. As long as the 576 // load/error event for the image is still observable. As long as the
583 // ImageLoader is actively loading, the Element itself needs to be ref'ed to 577 // ImageLoader is actively loading, the Element itself needs to be ref'ed to
584 // keep it from being destroyed by DOM manipulation or garbage collection. If 578 // keep it from being destroyed by DOM manipulation or garbage collection. If
585 // such an Element wishes for the load to stop when removed from the DOM it 579 // such an Element wishes for the load to stop when removed from the DOM it
586 // needs to stop the ImageLoader explicitly. 580 // needs to stop the ImageLoader explicitly.
587 bool was_protected = element_is_protected_; 581 bool was_protected = element_is_protected_;
588 element_is_protected_ = (image_ && !image_complete_) || 582 element_is_protected_ = (image_ && !image_complete_) ||
589 has_pending_load_event_ || has_pending_error_event_; 583 pending_load_event_.IsActive() ||
584 pending_error_event_.IsActive();
590 if (was_protected == element_is_protected_) 585 if (was_protected == element_is_protected_)
591 return; 586 return;
592 587
593 if (element_is_protected_) { 588 if (element_is_protected_) {
594 if (deref_element_timer_.IsActive()) 589 if (deref_element_timer_.IsActive())
595 deref_element_timer_.Stop(); 590 deref_element_timer_.Stop();
596 else 591 else
597 keep_alive_ = element_; 592 keep_alive_ = element_;
598 } else { 593 } else {
599 DCHECK(!deref_element_timer_.IsActive()); 594 DCHECK(!deref_element_timer_.IsActive());
600 deref_element_timer_.StartOneShot(0, BLINK_FROM_HERE); 595 deref_element_timer_.StartOneShot(0, BLINK_FROM_HERE);
601 } 596 }
602 } 597 }
603 598
604 void ImageLoader::TimerFired(TimerBase*) { 599 void ImageLoader::TimerFired(TimerBase*) {
605 keep_alive_.Clear(); 600 keep_alive_.Clear();
606 } 601 }
607 602
608 void ImageLoader::DispatchPendingEvent(ImageEventSender* event_sender) { 603 void ImageLoader::DispatchPendingLoadEvent(
609 RESOURCE_LOADING_DVLOG(1) << "ImageLoader::dispatchPendingEvent " << this; 604 std::unique_ptr<IncrementLoadEventDelayCount> count) {
610 DCHECK(event_sender == &LoadEventSender() ||
611 event_sender == &ErrorEventSender());
612 const AtomicString& event_type = event_sender->EventType();
613 if (event_type == EventTypeNames::load)
614 DispatchPendingLoadEvent();
615 if (event_type == EventTypeNames::error)
616 DispatchPendingErrorEvent();
617 }
618
619 void ImageLoader::DispatchPendingLoadEvent() {
620 CHECK(has_pending_load_event_);
621 if (!image_) 605 if (!image_)
622 return; 606 return;
623 CHECK(image_complete_); 607 CHECK(image_complete_);
624 has_pending_load_event_ = false;
625 CHECK(image_complete_);
626 if (GetElement()->GetDocument().GetFrame()) 608 if (GetElement()->GetDocument().GetFrame())
627 DispatchLoadEvent(); 609 DispatchLoadEvent();
628 610
629 // Only consider updating the protection ref-count of the Element immediately 611 // Only consider updating the protection ref-count of the Element immediately
630 // before returning from this function as doing so might result in the 612 // before returning from this function as doing so might result in the
631 // destruction of this ImageLoader. 613 // destruction of this ImageLoader.
632 UpdatedHasPendingEvent(); 614 UpdatedHasPendingEvent();
615
616 // Checks Document's load event synchronously here for performance.
617 // This is safe because dispatchPendingLoadEvent() is called asynchronously.
618 count->ClearAndCheckLoadEvent();
633 } 619 }
634 620
635 void ImageLoader::DispatchPendingErrorEvent() { 621 void ImageLoader::DispatchPendingErrorEvent(
636 if (!has_pending_error_event_) 622 std::unique_ptr<IncrementLoadEventDelayCount> count) {
637 return;
638 has_pending_error_event_ = false;
639
640 if (GetElement()->GetDocument().GetFrame()) 623 if (GetElement()->GetDocument().GetFrame())
641 GetElement()->DispatchEvent(Event::Create(EventTypeNames::error)); 624 GetElement()->DispatchEvent(Event::Create(EventTypeNames::error));
642 625
643 // Only consider updating the protection ref-count of the Element immediately 626 // Only consider updating the protection ref-count of the Element immediately
644 // before returning from this function as doing so might result in the 627 // before returning from this function as doing so might result in the
645 // destruction of this ImageLoader. 628 // destruction of this ImageLoader.
646 UpdatedHasPendingEvent(); 629 UpdatedHasPendingEvent();
630
631 // Checks Document's load event synchronously here for performance.
632 // This is safe because dispatchPendingErrorEvent() is called asynchronously.
633 count->ClearAndCheckLoadEvent();
647 } 634 }
648 635
649 bool ImageLoader::GetImageAnimationPolicy(ImageAnimationPolicy& policy) { 636 bool ImageLoader::GetImageAnimationPolicy(ImageAnimationPolicy& policy) {
650 if (!GetElement()->GetDocument().GetSettings()) 637 if (!GetElement()->GetDocument().GetSettings())
651 return false; 638 return false;
652 639
653 policy = GetElement()->GetDocument().GetSettings()->GetImageAnimationPolicy(); 640 policy = GetElement()->GetDocument().GetSettings()->GetImageAnimationPolicy();
654 return true; 641 return true;
655 } 642 }
656 643
657 void ImageLoader::DispatchPendingLoadEvents() {
658 LoadEventSender().DispatchPendingEvents();
659 }
660
661 void ImageLoader::DispatchPendingErrorEvents() {
662 ErrorEventSender().DispatchPendingEvents();
663 }
664
665 void ImageLoader::ElementDidMoveToNewDocument() { 644 void ImageLoader::ElementDidMoveToNewDocument() {
666 if (delay_until_do_update_from_element_) { 645 if (delay_until_do_update_from_element_) {
667 delay_until_do_update_from_element_->DocumentChanged( 646 delay_until_do_update_from_element_->DocumentChanged(
668 element_->GetDocument()); 647 element_->GetDocument());
669 } 648 }
670 if (delay_until_image_notify_finished_) { 649 if (delay_until_image_notify_finished_) {
671 delay_until_image_notify_finished_->DocumentChanged( 650 delay_until_image_notify_finished_->DocumentChanged(
672 element_->GetDocument()); 651 element_->GetDocument());
673 } 652 }
674 ClearFailedLoadURL(); 653 ClearFailedLoadURL();
675 SetImage(0); 654 SetImage(0);
676 } 655 }
677 656
678 } // namespace blink 657 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698