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

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

Issue 1706083002: Split ImageResourceClient into ResourceClient and ImageResourceObserver [1/2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More consistent Client/Observer Created 4 years, 10 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 reserv ed. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv ed.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 m_pendingTask->clearLoader(); 174 m_pendingTask->clearLoader();
175 #endif 175 #endif
176 176
177 #if ENABLE(OILPAN) 177 #if ENABLE(OILPAN)
178 for (const auto& client : m_clients) 178 for (const auto& client : m_clients)
179 willRemoveClient(*client); 179 willRemoveClient(*client);
180 #endif 180 #endif
181 181
182 if (m_image) { 182 if (m_image) {
183 m_image->removeClient(this); 183 m_image->removeClient(this);
184 m_image->removeObserver(this);
184 m_image = nullptr; 185 m_image = nullptr;
185 } 186 }
186 187
187 #if !ENABLE(OILPAN) 188 #if !ENABLE(OILPAN)
188 ASSERT(m_hasPendingLoadEvent || !loadEventSender().hasPendingEvents(this)); 189 ASSERT(m_hasPendingLoadEvent || !loadEventSender().hasPendingEvents(this));
189 if (m_hasPendingLoadEvent) 190 if (m_hasPendingLoadEvent)
190 loadEventSender().cancelEvent(this); 191 loadEventSender().cancelEvent(this);
191 192
192 ASSERT(m_hasPendingErrorEvent || !errorEventSender().hasPendingEvents(this)) ; 193 ASSERT(m_hasPendingErrorEvent || !errorEventSender().hasPendingEvents(this)) ;
193 if (m_hasPendingErrorEvent) 194 if (m_hasPendingErrorEvent)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 m_image = newImage; 238 m_image = newImage;
238 if (m_hasPendingLoadEvent) { 239 if (m_hasPendingLoadEvent) {
239 loadEventSender().cancelEvent(this); 240 loadEventSender().cancelEvent(this);
240 m_hasPendingLoadEvent = false; 241 m_hasPendingLoadEvent = false;
241 } 242 }
242 if (m_hasPendingErrorEvent) { 243 if (m_hasPendingErrorEvent) {
243 errorEventSender().cancelEvent(this); 244 errorEventSender().cancelEvent(this);
244 m_hasPendingErrorEvent = false; 245 m_hasPendingErrorEvent = false;
245 } 246 }
246 m_imageComplete = true; 247 m_imageComplete = true;
247 if (newImage) 248 if (newImage) {
248 newImage->addClient(this); 249 newImage->addClient(this);
249 if (oldImage) 250 newImage->addObserver(this);
251 }
252 if (oldImage) {
250 oldImage->removeClient(this); 253 oldImage->removeClient(this);
254 oldImage->removeObserver(this);
255 }
251 } 256 }
252 257
253 if (LayoutImageResource* imageResource = layoutImageResource()) 258 if (LayoutImageResource* imageResource = layoutImageResource())
254 imageResource->resetAnimation(); 259 imageResource->resetAnimation();
255 } 260 }
256 261
257 static void configureRequest(FetchRequest& request, ImageLoader::BypassMainWorld Behavior bypassBehavior, Element& element, const ClientHintsPreferences& clientH intsPreferences) 262 static void configureRequest(FetchRequest& request, ImageLoader::BypassMainWorld Behavior bypassBehavior, Element& element, const ClientHintsPreferences& clientH intsPreferences)
258 { 263 {
259 if (bypassBehavior == ImageLoader::BypassMainWorldCSP) 264 if (bypassBehavior == ImageLoader::BypassMainWorldCSP)
260 request.setContentSecurityCheck(DoNotCheckContentSecurityPolicy); 265 request.setContentSecurityCheck(DoNotCheckContentSecurityPolicy);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 m_hasPendingErrorEvent = false; 388 m_hasPendingErrorEvent = false;
384 } 389 }
385 390
386 m_image = newImage; 391 m_image = newImage;
387 m_hasPendingLoadEvent = newImage; 392 m_hasPendingLoadEvent = newImage;
388 m_imageComplete = !newImage; 393 m_imageComplete = !newImage;
389 394
390 updateLayoutObject(); 395 updateLayoutObject();
391 // If newImage exists and is cached, addClient() will result in the load event 396 // If newImage exists and is cached, addClient() will result in the load event
392 // being queued to fire. Ensure this happens after beforeload is dispatc hed. 397 // being queued to fire. Ensure this happens after beforeload is dispatc hed.
393 if (newImage) 398 if (newImage) {
394 newImage->addClient(this); 399 newImage->addClient(this);
395 400 newImage->addObserver(this);
396 if (oldImage) 401 }
402 if (oldImage) {
397 oldImage->removeClient(this); 403 oldImage->removeClient(this);
404 oldImage->removeObserver(this);
405 }
398 } 406 }
399 407
400 if (LayoutImageResource* imageResource = layoutImageResource()) 408 if (LayoutImageResource* imageResource = layoutImageResource())
401 imageResource->resetAnimation(); 409 imageResource->resetAnimation();
402 410
403 // Only consider updating the protection ref-count of the Element immediatel y before returning 411 // Only consider updating the protection ref-count of the Element immediatel y before returning
404 // from this function as doing so might result in the destruction of this Im ageLoader. 412 // from this function as doing so might result in the destruction of this Im ageLoader.
405 updatedHasPendingEvent(); 413 updatedHasPendingEvent();
406 } 414 }
407 415
(...skipping 17 matching lines...) Expand all
425 433
426 KURL url = imageSourceToKURL(imageSourceURL); 434 KURL url = imageSourceToKURL(imageSourceURL);
427 if (shouldLoadImmediately(url)) { 435 if (shouldLoadImmediately(url)) {
428 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol icy); 436 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol icy);
429 return; 437 return;
430 } 438 }
431 // Allow the idiom "img.src=''; img.src='.." to clear down the image before 439 // Allow the idiom "img.src=''; img.src='.." to clear down the image before
432 // an asynchronous load completes. 440 // an asynchronous load completes.
433 if (imageSourceURL.isEmpty()) { 441 if (imageSourceURL.isEmpty()) {
434 ImageResource* image = m_image.get(); 442 ImageResource* image = m_image.get();
435 if (image) 443 if (image) {
436 image->removeClient(this); 444 image->removeClient(this);
445 image->removeObserver(this);
446 }
437 m_image = nullptr; 447 m_image = nullptr;
438 } 448 }
439 449
440 // Don't load images for inactive documents. We don't want to slow down the 450 // Don't load images for inactive documents. We don't want to slow down the
441 // raw HTML parsing case by loading images we don't intend to display. 451 // raw HTML parsing case by loading images we don't intend to display.
442 Document& document = m_element->document(); 452 Document& document = m_element->document();
443 if (document.isActive()) 453 if (document.isActive())
444 enqueueImageLoadingMicroTask(updateBehavior, referrerPolicy); 454 enqueueImageLoadingMicroTask(updateBehavior, referrerPolicy);
445 } 455 }
446 456
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 void ImageLoader::willRemoveClient(ImageLoaderClient& client) 641 void ImageLoader::willRemoveClient(ImageLoaderClient& client)
632 { 642 {
633 if (client.requestsHighLiveResourceCachePriority()) { 643 if (client.requestsHighLiveResourceCachePriority()) {
634 ASSERT(m_highPriorityClientCount); 644 ASSERT(m_highPriorityClientCount);
635 m_highPriorityClientCount--; 645 m_highPriorityClientCount--;
636 if (m_image && !m_highPriorityClientCount) 646 if (m_image && !m_highPriorityClientCount)
637 memoryCache()->updateDecodedResource(m_image.get(), UpdateForPropert yChange, MemoryCacheLiveResourcePriorityLow); 647 memoryCache()->updateDecodedResource(m_image.get(), UpdateForPropert yChange, MemoryCacheLiveResourcePriorityLow);
638 } 648 }
639 } 649 }
640 650
641 bool ImageLoader::getImageAnimationPolicy(ImageResource*, ImageAnimationPolicy& policy) 651 bool ImageLoader::getImageAnimationPolicy(ImageAnimationPolicy& policy)
642 { 652 {
643 if (!element()->document().settings()) 653 if (!element()->document().settings())
644 return false; 654 return false;
645 655
646 policy = element()->document().settings()->imageAnimationPolicy(); 656 policy = element()->document().settings()->imageAnimationPolicy();
647 return true; 657 return true;
648 } 658 }
649 659
650 void ImageLoader::dispatchPendingLoadEvents() 660 void ImageLoader::dispatchPendingLoadEvents()
651 { 661 {
(...skipping 15 matching lines...) Expand all
667 677
668 void ImageLoader::sourceImageChanged() 678 void ImageLoader::sourceImageChanged()
669 { 679 {
670 for (auto& client : m_clients) { 680 for (auto& client : m_clients) {
671 ImageLoaderClient* handle = client; 681 ImageLoaderClient* handle = client;
672 handle->notifyImageSourceChanged(); 682 handle->notifyImageSourceChanged();
673 } 683 }
674 } 684 }
675 685
676 } // namespace blink 686 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698