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

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

Issue 19393004: Allow eviction of ImageBitmaps that are created from ImageElements. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix for assertion failure. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/ImageLoader.h ('k') | Source/core/loader/cache/CachedImageTest.cpp » ('j') | 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 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ImageLoader::ImageLoader(Element* element) 68 ImageLoader::ImageLoader(Element* element)
69 : m_element(element) 69 : m_element(element)
70 , m_image(0) 70 , m_image(0)
71 , m_derefElementTimer(this, &ImageLoader::timerFired) 71 , m_derefElementTimer(this, &ImageLoader::timerFired)
72 , m_hasPendingBeforeLoadEvent(false) 72 , m_hasPendingBeforeLoadEvent(false)
73 , m_hasPendingLoadEvent(false) 73 , m_hasPendingLoadEvent(false)
74 , m_hasPendingErrorEvent(false) 74 , m_hasPendingErrorEvent(false)
75 , m_imageComplete(true) 75 , m_imageComplete(true)
76 , m_loadManually(false) 76 , m_loadManually(false)
77 , m_elementIsProtected(false) 77 , m_elementIsProtected(false)
78 , m_highPriorityClientCount(0)
78 { 79 {
79 } 80 }
80 81
81 ImageLoader::~ImageLoader() 82 ImageLoader::~ImageLoader()
82 { 83 {
83 if (m_image) 84 if (m_image)
84 m_image->removeClient(this); 85 m_image->removeClient(this);
85 86
86 ASSERT(m_hasPendingBeforeLoadEvent || !beforeLoadEventSender().hasPendingEve nts(this)); 87 ASSERT(m_hasPendingBeforeLoadEvent || !beforeLoadEventSender().hasPendingEve nts(this));
87 if (m_hasPendingBeforeLoadEvent) 88 if (m_hasPendingBeforeLoadEvent)
(...skipping 20 matching lines...) Expand all
108 // Only consider updating the protection ref-count of the Element immediatel y before returning 109 // Only consider updating the protection ref-count of the Element immediatel y before returning
109 // from this function as doing so might result in the destruction of this Im ageLoader. 110 // from this function as doing so might result in the destruction of this Im ageLoader.
110 updatedHasPendingEvent(); 111 updatedHasPendingEvent();
111 } 112 }
112 113
113 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(CachedImage* newIma ge) 114 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(CachedImage* newIma ge)
114 { 115 {
115 ASSERT(m_failedLoadURL.isEmpty()); 116 ASSERT(m_failedLoadURL.isEmpty());
116 CachedImage* oldImage = m_image.get(); 117 CachedImage* oldImage = m_image.get();
117 if (newImage != oldImage) { 118 if (newImage != oldImage) {
119 sourceImageChanged();
118 m_image = newImage; 120 m_image = newImage;
119 if (m_hasPendingBeforeLoadEvent) { 121 if (m_hasPendingBeforeLoadEvent) {
120 beforeLoadEventSender().cancelEvent(this); 122 beforeLoadEventSender().cancelEvent(this);
121 m_hasPendingBeforeLoadEvent = false; 123 m_hasPendingBeforeLoadEvent = false;
122 } 124 }
123 if (m_hasPendingLoadEvent) { 125 if (m_hasPendingLoadEvent) {
124 loadEventSender().cancelEvent(this); 126 loadEventSender().cancelEvent(this);
125 m_hasPendingLoadEvent = false; 127 m_hasPendingLoadEvent = false;
126 } 128 }
127 if (m_hasPendingErrorEvent) { 129 if (m_hasPendingErrorEvent) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } else 188 } else
187 clearFailedLoadURL(); 189 clearFailedLoadURL();
188 } else if (!attr.isNull()) { 190 } else if (!attr.isNull()) {
189 // Fire an error event if the url is empty. 191 // Fire an error event if the url is empty.
190 m_hasPendingErrorEvent = true; 192 m_hasPendingErrorEvent = true;
191 errorEventSender().dispatchEventSoon(this); 193 errorEventSender().dispatchEventSoon(this);
192 } 194 }
193 195
194 CachedImage* oldImage = m_image.get(); 196 CachedImage* oldImage = m_image.get();
195 if (newImage != oldImage) { 197 if (newImage != oldImage) {
198 sourceImageChanged();
199
196 if (m_hasPendingBeforeLoadEvent) { 200 if (m_hasPendingBeforeLoadEvent) {
197 beforeLoadEventSender().cancelEvent(this); 201 beforeLoadEventSender().cancelEvent(this);
198 m_hasPendingBeforeLoadEvent = false; 202 m_hasPendingBeforeLoadEvent = false;
199 } 203 }
200 if (m_hasPendingLoadEvent) { 204 if (m_hasPendingLoadEvent) {
201 loadEventSender().cancelEvent(this); 205 loadEventSender().cancelEvent(this);
202 m_hasPendingLoadEvent = false; 206 m_hasPendingLoadEvent = false;
203 } 207 }
204 208
205 // Cancel error events that belong to the previous load, which is now ca ncelled by changing the src attribute. 209 // Cancel error events that belong to the previous load, which is now ca ncelled by changing the src attribute.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 return; 423 return;
420 m_hasPendingErrorEvent = false; 424 m_hasPendingErrorEvent = false;
421 if (element()->document()->attached()) 425 if (element()->document()->attached())
422 element()->dispatchEvent(Event::create(eventNames().errorEvent, false, f alse)); 426 element()->dispatchEvent(Event::create(eventNames().errorEvent, false, f alse));
423 427
424 // Only consider updating the protection ref-count of the Element immediatel y before returning 428 // Only consider updating the protection ref-count of the Element immediatel y before returning
425 // from this function as doing so might result in the destruction of this Im ageLoader. 429 // from this function as doing so might result in the destruction of this Im ageLoader.
426 updatedHasPendingEvent(); 430 updatedHasPendingEvent();
427 } 431 }
428 432
433 void ImageLoader::addClient(ImageLoaderClient* client)
434 {
435 if (client->requestsHighLiveResourceCachePriority()) {
436 if (m_image && !m_highPriorityClientCount++)
437 m_image->setCacheLiveResourcePriority(Resource::CacheLiveResourcePri orityHigh);
438 }
439 m_clients.add(client);
440 }
441 void ImageLoader::removeClient(ImageLoaderClient* client)
442 {
443 if (client->requestsHighLiveResourceCachePriority()) {
444 ASSERT(m_highPriorityClientCount);
445 m_highPriorityClientCount--;
446 if (m_image && !m_highPriorityClientCount)
447 m_image->setCacheLiveResourcePriority(Resource::CacheLiveResourcePri orityLow);
448 }
449 m_clients.remove(client);
450 }
451
429 void ImageLoader::dispatchPendingBeforeLoadEvents() 452 void ImageLoader::dispatchPendingBeforeLoadEvents()
430 { 453 {
431 beforeLoadEventSender().dispatchPendingEvents(); 454 beforeLoadEventSender().dispatchPendingEvents();
432 } 455 }
433 456
434 void ImageLoader::dispatchPendingLoadEvents() 457 void ImageLoader::dispatchPendingLoadEvents()
435 { 458 {
436 loadEventSender().dispatchPendingEvents(); 459 loadEventSender().dispatchPendingEvents();
437 } 460 }
438 461
439 void ImageLoader::dispatchPendingErrorEvents() 462 void ImageLoader::dispatchPendingErrorEvents()
440 { 463 {
441 errorEventSender().dispatchPendingEvents(); 464 errorEventSender().dispatchPendingEvents();
442 } 465 }
443 466
444 void ImageLoader::elementDidMoveToNewDocument() 467 void ImageLoader::elementDidMoveToNewDocument()
445 { 468 {
446 clearFailedLoadURL(); 469 clearFailedLoadURL();
447 setImage(0); 470 setImage(0);
448 } 471 }
449 472
473 void ImageLoader::sourceImageChanged()
474 {
475 HashSet<ImageLoaderClient*>::iterator end = m_clients.end();
476 for (HashSet<ImageLoaderClient*>::iterator it = m_clients.begin(); it != end ; ++it) {
477 ImageLoaderClient* handle = *it;
478 handle->notifyImageSourceChanged();
479 }
480 }
481
450 inline void ImageLoader::clearFailedLoadURL() 482 inline void ImageLoader::clearFailedLoadURL()
451 { 483 {
452 m_failedLoadURL = AtomicString(); 484 m_failedLoadURL = AtomicString();
453 } 485 }
454 486
455 } 487 }
OLDNEW
« no previous file with comments | « Source/core/loader/ImageLoader.h ('k') | Source/core/loader/cache/CachedImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698