| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| 11 version 2 of the License, or (at your option) any later version. | 11 version 2 of the License, or (at your option) any later version. |
| 12 | 12 |
| 13 This library is distributed in the hope that it will be useful, | 13 This library is distributed in the hope that it will be useful, |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 Library General Public License for more details. | 16 Library General Public License for more details. |
| 17 | 17 |
| 18 You should have received a copy of the GNU Library General Public License | 18 You should have received a copy of the GNU Library General Public License |
| 19 along with this library; see the file COPYING.LIB. If not, write to | 19 along with this library; see the file COPYING.LIB. If not, write to |
| 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "core/fetch/ImageResource.h" | 24 #include "core/fetch/ImageResource.h" |
| 25 | 25 |
| 26 #include "core/fetch/ImageResourceClient.h" | 26 #include "core/fetch/ImageResourceObserver.h" |
| 27 #include "core/fetch/MemoryCache.h" | 27 #include "core/fetch/MemoryCache.h" |
| 28 #include "core/fetch/ResourceClient.h" | 28 #include "core/fetch/ResourceClient.h" |
| 29 #include "core/fetch/ResourceClientWalker.h" | |
| 30 #include "core/fetch/ResourceFetcher.h" | 29 #include "core/fetch/ResourceFetcher.h" |
| 31 #include "core/fetch/ResourceLoader.h" | 30 #include "core/fetch/ResourceLoader.h" |
| 32 #include "core/svg/graphics/SVGImage.h" | 31 #include "core/svg/graphics/SVGImage.h" |
| 33 #include "platform/Logging.h" | 32 #include "platform/Logging.h" |
| 34 #include "platform/RuntimeEnabledFeatures.h" | 33 #include "platform/RuntimeEnabledFeatures.h" |
| 35 #include "platform/SharedBuffer.h" | 34 #include "platform/SharedBuffer.h" |
| 36 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
| 37 #include "platform/graphics/BitmapImage.h" | 36 #include "platform/graphics/BitmapImage.h" |
| 38 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 39 #include "wtf/CurrentTime.h" | 38 #include "wtf/CurrentTime.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 103 } |
| 105 | 104 |
| 106 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions&
options) | 105 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions&
options) |
| 107 { | 106 { |
| 108 if (!fetcher || fetcher->autoLoadImages()) | 107 if (!fetcher || fetcher->autoLoadImages()) |
| 109 Resource::load(fetcher, options); | 108 Resource::load(fetcher, options); |
| 110 else | 109 else |
| 111 setLoading(false); | 110 setLoading(false); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void ImageResource::didAddClient(ResourceClient* c) | 113 void ImageResource::addObserver(ImageResourceObserver* observer) |
| 115 { | 114 { |
| 116 if (m_data && !m_image && !errorOccurred()) { | 115 if (m_data && !m_image && !errorOccurred()) { |
| 117 createImage(); | 116 createImage(); |
| 118 m_image->setData(m_data, true); | 117 m_image->setData(m_data, true); |
| 119 } | 118 } |
| 120 | 119 |
| 121 ASSERT(c->resourceClientType() == ImageResourceClient::expectedType()); | |
| 122 if (m_image && !m_image->isNull()) | 120 if (m_image && !m_image->isNull()) |
| 123 static_cast<ImageResourceClient*>(c)->imageChanged(this); | 121 observer->imageChanged(this); |
| 124 | 122 m_observers.add(observer); |
| 125 Resource::didAddClient(c); | |
| 126 } | 123 } |
| 127 | 124 |
| 128 void ImageResource::didRemoveClient(ResourceClient* c) | 125 void ImageResource::removeObserver(ImageResourceObserver* observer) |
| 129 { | 126 { |
| 130 ASSERT(c); | 127 ASSERT(observer); |
| 131 ASSERT(c->resourceClientType() == ImageResourceClient::expectedType()); | 128 ASSERT(m_observers.contains(observer)); |
| 129 m_observers.remove(observer); |
| 130 } |
| 132 | 131 |
| 133 Resource::didRemoveClient(c); | 132 ResourcePriority ImageResource::priorityFromClients() |
| 133 { |
| 134 ResourcePriority priority; |
| 135 for (const auto& observer : m_observers) { |
| 136 ResourcePriority nextPriority = observer.key->computeResourcePriority(); |
| 137 if (nextPriority.visibility == ResourcePriority::NotVisible) |
| 138 continue; |
| 139 priority.visibility = ResourcePriority::Visible; |
| 140 priority.intraPriorityValue += nextPriority.intraPriorityValue; |
| 141 } |
| 142 return priority; |
| 134 } | 143 } |
| 135 | 144 |
| 136 bool ImageResource::isSafeToUnlock() const | 145 bool ImageResource::isSafeToUnlock() const |
| 137 { | 146 { |
| 138 // Note that |m_image| holds a reference to |m_data| in addition to the one
held by the Resource parent class. | 147 // Note that |m_image| holds a reference to |m_data| in addition to the one
held by the Resource parent class. |
| 139 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); | 148 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); |
| 140 } | 149 } |
| 141 | 150 |
| 142 void ImageResource::destroyDecodedDataForFailedRevalidation() | 151 void ImageResource::destroyDecodedDataForFailedRevalidation() |
| 143 { | 152 { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 249 } |
| 241 | 250 |
| 242 void ImageResource::computeIntrinsicDimensions(Length& intrinsicWidth, Length& i
ntrinsicHeight, FloatSize& intrinsicRatio) | 251 void ImageResource::computeIntrinsicDimensions(Length& intrinsicWidth, Length& i
ntrinsicHeight, FloatSize& intrinsicRatio) |
| 243 { | 252 { |
| 244 if (m_image) | 253 if (m_image) |
| 245 m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int
rinsicRatio); | 254 m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int
rinsicRatio); |
| 246 } | 255 } |
| 247 | 256 |
| 248 void ImageResource::notifyObservers(const IntRect* changeRect) | 257 void ImageResource::notifyObservers(const IntRect* changeRect) |
| 249 { | 258 { |
| 250 ResourceClientWalker<ImageResourceClient> w(m_clients); | 259 WillBeHeapVector<ImageResourceObserver*> observers(m_observers.size()); |
| 251 while (ImageResourceClient* c = w.next()) | 260 size_t index = 0; |
| 252 c->imageChanged(this, changeRect); | 261 for (const auto& observer : m_observers) |
| 253 | 262 observers[index++] = observer.key; |
| 254 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | 263 for (auto observer : observers) |
| 255 while (ImageResourceClient* c = w2.next()) | 264 observer->imageChanged(this, changeRect); |
| 256 c->imageChanged(this, changeRect); | |
| 257 } | 265 } |
| 258 | 266 |
| 259 void ImageResource::clear() | 267 void ImageResource::clear() |
| 260 { | 268 { |
| 261 prune(); | 269 prune(); |
| 262 clearImage(); | 270 clearImage(); |
| 263 setEncodedSize(0); | 271 setEncodedSize(0); |
| 264 } | 272 } |
| 265 | 273 |
| 266 void ImageResource::setCustomAcceptHeader() | 274 void ImageResource::setCustomAcceptHeader() |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // to update MemoryCache. | 392 // to update MemoryCache. |
| 385 if (decodedSize() != 0) | 393 if (decodedSize() != 0) |
| 386 Resource::didAccessDecodedData(); | 394 Resource::didAccessDecodedData(); |
| 387 } | 395 } |
| 388 | 396 |
| 389 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 397 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
| 390 { | 398 { |
| 391 if (!image || image != m_image) | 399 if (!image || image != m_image) |
| 392 return false; | 400 return false; |
| 393 | 401 |
| 394 ResourceClientWalker<ImageResourceClient> w(m_clients); | 402 for (const auto& observer : m_observers) { |
| 395 while (ImageResourceClient* c = w.next()) { | 403 if (observer.key->willRenderImage()) |
| 396 if (c->willRenderImage(this)) | |
| 397 return false; | 404 return false; |
| 398 } | 405 } |
| 399 | |
| 400 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
| 401 while (ImageResourceClient* c = w2.next()) { | |
| 402 if (c->willRenderImage(this)) | |
| 403 return false; | |
| 404 } | |
| 405 | |
| 406 return true; | 406 return true; |
| 407 } | 407 } |
| 408 | 408 |
| 409 void ImageResource::animationAdvanced(const blink::Image* image) | 409 void ImageResource::animationAdvanced(const blink::Image* image) |
| 410 { | 410 { |
| 411 if (!image || image != m_image) | 411 if (!image || image != m_image) |
| 412 return; | 412 return; |
| 413 notifyObservers(); | 413 notifyObservers(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void ImageResource::updateImageAnimationPolicy() | 416 void ImageResource::updateImageAnimationPolicy() |
| 417 { | 417 { |
| 418 if (!m_image) | 418 if (!m_image) |
| 419 return; | 419 return; |
| 420 | 420 |
| 421 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 421 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
| 422 ResourceClientWalker<ImageResourceClient> w(m_clients); | 422 for (const auto& observer : m_observers) { |
| 423 while (ImageResourceClient* c = w.next()) { | 423 if (observer.key->getImageAnimationPolicy(newPolicy)) |
| 424 if (c->getImageAnimationPolicy(this, newPolicy)) | |
| 425 break; | 424 break; |
| 426 } | 425 } |
| 427 | 426 |
| 428 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
| 429 while (ImageResourceClient* c = w2.next()) { | |
| 430 if (c->getImageAnimationPolicy(this, newPolicy)) | |
| 431 break; | |
| 432 } | |
| 433 | |
| 434 if (m_image->animationPolicy() != newPolicy) { | 427 if (m_image->animationPolicy() != newPolicy) { |
| 435 m_image->resetAnimation(); | 428 m_image->resetAnimation(); |
| 436 m_image->setAnimationPolicy(newPolicy); | 429 m_image->setAnimationPolicy(newPolicy); |
| 437 } | 430 } |
| 438 } | 431 } |
| 439 | 432 |
| 440 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 433 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
| 441 { | 434 { |
| 442 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) | 435 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) |
| 443 return; | 436 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 464 return true; | 457 return true; |
| 465 return !securityOrigin->taintsCanvas(response().url()); | 458 return !securityOrigin->taintsCanvas(response().url()); |
| 466 } | 459 } |
| 467 | 460 |
| 468 bool ImageResource::loadingMultipartContent() const | 461 bool ImageResource::loadingMultipartContent() const |
| 469 { | 462 { |
| 470 return m_loader && m_loader->loadingMultipartContent(); | 463 return m_loader && m_loader->loadingMultipartContent(); |
| 471 } | 464 } |
| 472 | 465 |
| 473 } // namespace blink | 466 } // namespace blink |
| OLD | NEW |