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

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

Issue 2613853002: Phase III Step 2: Call imageNotifyFinished() and image load event after SVG loading completes (Closed)
Patch Set: Rebase Created 3 years, 9 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 void ImageLoader::dispose() { 170 void ImageLoader::dispose() {
171 RESOURCE_LOADING_DVLOG(1) 171 RESOURCE_LOADING_DVLOG(1)
172 << "~ImageLoader " << this 172 << "~ImageLoader " << this
173 << "; m_hasPendingLoadEvent=" << m_hasPendingLoadEvent 173 << "; m_hasPendingLoadEvent=" << m_hasPendingLoadEvent
174 << ", m_hasPendingErrorEvent=" << m_hasPendingErrorEvent; 174 << ", m_hasPendingErrorEvent=" << m_hasPendingErrorEvent;
175 175
176 if (m_image) { 176 if (m_image) {
177 m_image->removeObserver(this); 177 m_image->removeObserver(this);
178 m_image = nullptr; 178 m_image = nullptr;
179 m_loadDelayCounter2 = nullptr;
179 } 180 }
180 } 181 }
181 182
182 DEFINE_TRACE(ImageLoader) { 183 DEFINE_TRACE(ImageLoader) {
183 visitor->trace(m_image); 184 visitor->trace(m_image);
184 visitor->trace(m_imageResourceForImageDocument); 185 visitor->trace(m_imageResourceForImageDocument);
185 visitor->trace(m_element); 186 visitor->trace(m_element);
186 } 187 }
187 188
188 void ImageLoader::setImage(ImageResourceContent* newImage) { 189 void ImageLoader::setImage(ImageResourceContent* newImage) {
189 setImageWithoutConsideringPendingLoadEvent(newImage); 190 setImageWithoutConsideringPendingLoadEvent(newImage);
190 191
191 // Only consider updating the protection ref-count of the Element immediately 192 // Only consider updating the protection ref-count of the Element immediately
192 // before returning from this function as doing so might result in the 193 // before returning from this function as doing so might result in the
193 // destruction of this ImageLoader. 194 // destruction of this ImageLoader.
194 updatedHasPendingEvent(); 195 updatedHasPendingEvent();
195 } 196 }
196 197
197 void ImageLoader::setImageWithoutConsideringPendingLoadEvent( 198 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(
198 ImageResourceContent* newImage) { 199 ImageResourceContent* newImage) {
199 DCHECK(m_failedLoadURL.isEmpty()); 200 DCHECK(m_failedLoadURL.isEmpty());
200 ImageResourceContent* oldImage = m_image.get(); 201 ImageResourceContent* oldImage = m_image.get();
201 if (newImage != oldImage) { 202 if (newImage != oldImage) {
202 m_image = newImage; 203 m_image = newImage;
204 m_loadDelayCounter2 = nullptr;
203 if (m_hasPendingLoadEvent) { 205 if (m_hasPendingLoadEvent) {
204 loadEventSender().cancelEvent(this); 206 loadEventSender().cancelEvent(this);
205 m_hasPendingLoadEvent = false; 207 m_hasPendingLoadEvent = false;
206 } 208 }
207 if (m_hasPendingErrorEvent) { 209 if (m_hasPendingErrorEvent) {
208 errorEventSender().cancelEvent(this); 210 errorEventSender().cancelEvent(this);
209 m_hasPendingErrorEvent = false; 211 m_hasPendingErrorEvent = false;
210 } 212 }
211 m_imageComplete = true; 213 m_imageComplete = true;
212 if (newImage) { 214 if (newImage) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // FIXME: If both previous load and this one got blocked with an error, we 354 // FIXME: If both previous load and this one got blocked with an error, we
353 // can receive one error event instead of two. 355 // can receive one error event instead of two.
354 if (m_hasPendingErrorEvent && newImage) { 356 if (m_hasPendingErrorEvent && newImage) {
355 errorEventSender().cancelEvent(this); 357 errorEventSender().cancelEvent(this);
356 m_hasPendingErrorEvent = false; 358 m_hasPendingErrorEvent = false;
357 } 359 }
358 360
359 m_image = newImage; 361 m_image = newImage;
360 m_hasPendingLoadEvent = newImage; 362 m_hasPendingLoadEvent = newImage;
361 m_imageComplete = !newImage; 363 m_imageComplete = !newImage;
364 m_loadDelayCounter2 = nullptr;
362 365
363 updateLayoutObject(); 366 updateLayoutObject();
364 // If newImage exists and is cached, addObserver() will result in the load 367 // If newImage exists and is cached, addObserver() will result in the load
365 // event being queued to fire. Ensure this happens after beforeload is 368 // event being queued to fire. Ensure this happens after beforeload is
366 // dispatched. 369 // dispatched.
370 if (oldImage) {
371 oldImage->removeObserver(this);
372 }
367 if (newImage) { 373 if (newImage) {
fs 2017/03/15 14:22:17 This shuffle is non-obvious, what are the side-eff
hiroshige 2017/05/04 22:50:50 Oh, this was my mistake (unintentionally changed t
368 newImage->addObserver(this); 374 newImage->addObserver(this);
369 } 375 }
370 if (oldImage) {
371 oldImage->removeObserver(this);
372 }
373 } 376 }
374 377
375 if (LayoutImageResource* imageResource = layoutImageResource()) 378 if (LayoutImageResource* imageResource = layoutImageResource())
376 imageResource->resetAnimation(); 379 imageResource->resetAnimation();
377 380
378 // Only consider updating the protection ref-count of the Element immediately 381 // Only consider updating the protection ref-count of the Element immediately
379 // before returning from this function as doing so might result in the 382 // before returning from this function as doing so might result in the
380 // destruction of this ImageLoader. 383 // destruction of this ImageLoader.
381 updatedHasPendingEvent(); 384 updatedHasPendingEvent();
382 } 385 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 KURL url = imageSourceToKURL(imageSourceURL); 419 KURL url = imageSourceToKURL(imageSourceURL);
417 if (shouldLoadImmediately(url)) { 420 if (shouldLoadImmediately(url)) {
418 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, url, 421 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, url,
419 referrerPolicy); 422 referrerPolicy);
420 return; 423 return;
421 } 424 }
422 // Allow the idiom "img.src=''; img.src='.." to clear down the image before an 425 // Allow the idiom "img.src=''; img.src='.." to clear down the image before an
423 // asynchronous load completes. 426 // asynchronous load completes.
424 if (imageSourceURL.isEmpty()) { 427 if (imageSourceURL.isEmpty()) {
425 ImageResourceContent* image = m_image.get(); 428 ImageResourceContent* image = m_image.get();
426 if (image) { 429 if (image)
427 image->removeObserver(this); 430 image->removeObserver(this);
428 }
429 m_image = nullptr; 431 m_image = nullptr;
432 m_loadDelayCounter2 = nullptr;
430 } 433 }
431 434
432 // Don't load images for inactive documents. We don't want to slow down the 435 // Don't load images for inactive documents. We don't want to slow down the
433 // raw HTML parsing case by loading images we don't intend to display. 436 // raw HTML parsing case by loading images we don't intend to display.
434 Document& document = m_element->document(); 437 Document& document = m_element->document();
435 if (document.isActive()) 438 if (document.isActive())
436 enqueueImageLoadingMicroTask(updateBehavior, referrerPolicy); 439 enqueueImageLoadingMicroTask(updateBehavior, referrerPolicy);
437 } 440 }
438 441
439 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const { 442 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const {
(...skipping 22 matching lines...) Expand all
462 // content when style recalc is over and DOM mutation is allowed again. 465 // content when style recalc is over and DOM mutation is allowed again.
463 if (!url.isNull()) { 466 if (!url.isNull()) {
464 Resource* resource = memoryCache()->resourceForURL( 467 Resource* resource = memoryCache()->resourceForURL(
465 url, m_element->document().fetcher()->getCacheIdentifier()); 468 url, m_element->document().fetcher()->getCacheIdentifier());
466 if (resource && !resource->errorOccurred()) 469 if (resource && !resource->errorOccurred())
467 return true; 470 return true;
468 } 471 }
469 return (isHTMLObjectElement(m_element) || isHTMLEmbedElement(m_element)); 472 return (isHTMLObjectElement(m_element) || isHTMLEmbedElement(m_element));
470 } 473 }
471 474
475 void ImageLoader::imageChanged(ImageResourceContent* content, const IntRect*) {
476 DCHECK_EQ(content, m_image.get());
477 if (m_imageComplete || !content->isLoading() || m_loadDelayCounter2)
478 return;
479
480 Document& document = m_element->document();
481 if (!document.isActive())
482 return;
483
484 m_loadDelayCounter2 = IncrementLoadEventDelayCount::create(document);
485 }
486
472 void ImageLoader::imageNotifyFinished(ImageResourceContent* resource) { 487 void ImageLoader::imageNotifyFinished(ImageResourceContent* resource) {
473 RESOURCE_LOADING_DVLOG(1) 488 RESOURCE_LOADING_DVLOG(1)
474 << "ImageLoader::imageNotifyFinished " << this 489 << "ImageLoader::imageNotifyFinished " << this
475 << "; m_hasPendingLoadEvent=" << m_hasPendingLoadEvent; 490 << "; m_hasPendingLoadEvent=" << m_hasPendingLoadEvent;
476 491
477 DCHECK(m_failedLoadURL.isEmpty()); 492 DCHECK(m_failedLoadURL.isEmpty());
478 DCHECK_EQ(resource, m_image.get()); 493 DCHECK_EQ(resource, m_image.get());
479 494
480 m_imageComplete = true; 495 m_imageComplete = true;
496 m_loadDelayCounter2 = nullptr;
481 497
482 // Update ImageAnimationPolicy for m_image. 498 // Update ImageAnimationPolicy for m_image.
483 if (m_image) 499 if (m_image)
484 m_image->updateImageAnimationPolicy(); 500 m_image->updateImageAnimationPolicy();
485 501
486 updateLayoutObject(); 502 updateLayoutObject();
487 503
488 if (m_image && m_image->getImage() && m_image->getImage()->isSVGImage()) 504 if (m_image && m_image->getImage() && m_image->getImage()->isSVGImage())
489 toSVGImage(m_image->getImage())->updateUseCounters(element()->document()); 505 toSVGImage(m_image->getImage())->updateUseCounters(element()->document());
490 506
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 loadEventSender().dispatchPendingEvents(); 645 loadEventSender().dispatchPendingEvents();
630 } 646 }
631 647
632 void ImageLoader::dispatchPendingErrorEvents() { 648 void ImageLoader::dispatchPendingErrorEvents() {
633 errorEventSender().dispatchPendingEvents(); 649 errorEventSender().dispatchPendingEvents();
634 } 650 }
635 651
636 void ImageLoader::elementDidMoveToNewDocument() { 652 void ImageLoader::elementDidMoveToNewDocument() {
637 if (m_loadDelayCounter) 653 if (m_loadDelayCounter)
638 m_loadDelayCounter->documentChanged(m_element->document()); 654 m_loadDelayCounter->documentChanged(m_element->document());
655 if (m_loadDelayCounter2)
656 m_loadDelayCounter2->documentChanged(m_element->document());
639 clearFailedLoadURL(); 657 clearFailedLoadURL();
640 setImage(0); 658 setImage(0);
641 } 659 }
642 660
643 } // namespace blink 661 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698