| 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/ImageResourceObserver.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/ResourceClientOrObserverWalker.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/fetch/ResourceLoadingLog.h" | 31 #include "core/fetch/ResourceLoadingLog.h" |
| 33 #include "core/svg/graphics/SVGImage.h" | 32 #include "core/svg/graphics/SVGImage.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 "public/platform/WebCachePolicy.h" | 38 #include "public/platform/WebCachePolicy.h" |
| 40 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
| 40 #include "wtf/HashCountedSet.h" |
| 41 #include "wtf/StdLibExtras.h" | 41 #include "wtf/StdLibExtras.h" |
| 42 #include "wtf/Vector.h" |
| 42 #include <memory> | 43 #include <memory> |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource
Observer, ImageResourceObserver>; | |
| 47 | |
| 48 ImageResource* ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetc
her) | 47 ImageResource* ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetc
her) |
| 49 { | 48 { |
| 50 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) | 49 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) |
| 51 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); | 50 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); |
| 52 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 51 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
| 53 KURL requestURL = request.resourceRequest().url(); | 52 KURL requestURL = request.resourceRequest().url(); |
| 54 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) | 53 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) |
| 55 fetcher->context().sendImagePing(requestURL); | 54 fetcher->context().sendImagePing(requestURL); |
| 56 return nullptr; | 55 return nullptr; |
| 57 } | 56 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 Resource::trace(visitor); | 89 Resource::trace(visitor); |
| 91 ImageObserver::trace(visitor); | 90 ImageObserver::trace(visitor); |
| 92 MultipartImageResourceParser::Client::trace(visitor); | 91 MultipartImageResourceParser::Client::trace(visitor); |
| 93 } | 92 } |
| 94 | 93 |
| 95 void ImageResource::checkNotify() | 94 void ImageResource::checkNotify() |
| 96 { | 95 { |
| 97 if (isLoading()) | 96 if (isLoading()) |
| 98 return; | 97 return; |
| 99 | 98 |
| 100 ImageResourceObserverWalker walker(m_observers); | 99 for (auto* observer : m_observers.asVector()) { |
| 101 while (auto* observer = walker.next()) { | 100 if (m_observers.contains(observer)) |
| 102 observer->imageNotifyFinished(this); | 101 observer->imageNotifyFinished(this); |
| 103 } | 102 } |
| 104 | 103 |
| 105 Resource::checkNotify(); | 104 Resource::checkNotify(); |
| 106 } | 105 } |
| 107 | 106 |
| 108 void ImageResource::markClientsAndObserversFinished() | 107 void ImageResource::markClientsAndObserversFinished() |
| 109 { | 108 { |
| 110 HashCountedSet<ImageResourceObserver*> observers; | 109 HashCountedSet<ImageResourceObserver*> observers; |
| 111 m_observers.swap(observers); | 110 m_observers.swap(observers); |
| 112 for (const auto& it : observers) | 111 for (const auto& it : observers) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (nextPriority.visibility == ResourcePriority::NotVisible) | 172 if (nextPriority.visibility == ResourcePriority::NotVisible) |
| 174 return; | 173 return; |
| 175 priority.visibility = ResourcePriority::Visible; | 174 priority.visibility = ResourcePriority::Visible; |
| 176 priority.intraPriorityValue += nextPriority.intraPriorityValue; | 175 priority.intraPriorityValue += nextPriority.intraPriorityValue; |
| 177 } | 176 } |
| 178 | 177 |
| 179 ResourcePriority ImageResource::priorityFromObservers() | 178 ResourcePriority ImageResource::priorityFromObservers() |
| 180 { | 179 { |
| 181 ResourcePriority priority; | 180 ResourcePriority priority; |
| 182 | 181 |
| 183 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 182 for (auto* observer : m_finishedObservers.asVector()) { |
| 184 while (const auto* observer = finishedWalker.next()) { | 183 if (m_finishedObservers.contains(observer)) |
| 185 priorityFromObserver(observer, priority); | 184 priorityFromObserver(observer, priority); |
| 186 } | 185 } |
| 187 | 186 for (auto* observer : m_observers.asVector()) { |
| 188 ImageResourceObserverWalker walker(m_observers); | 187 if (m_observers.contains(observer)) |
| 189 while (const auto* observer = walker.next()) { | 188 priorityFromObserver(observer, priority); |
| 190 priorityFromObserver(observer, priority); | |
| 191 } | 189 } |
| 192 | 190 |
| 193 return priority; | 191 return priority; |
| 194 } | 192 } |
| 195 | 193 |
| 196 bool ImageResource::isSafeToUnlock() const | 194 bool ImageResource::isSafeToUnlock() const |
| 197 { | 195 { |
| 198 // Note that |m_image| holds a reference to |data()| in addition to the one
held by the Resource parent class. | 196 // Note that |m_image| holds a reference to |data()| in addition to the one
held by the Resource parent class. |
| 199 return !m_image || (m_image->hasOneRef() && data()->refCount() == 2); | 197 return !m_image || (m_image->hasOneRef() && data()->refCount() == 2); |
| 200 } | 198 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed
. | 325 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed
. |
| 328 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU
nit(), | 326 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU
nit(), |
| 329 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()))
; | 327 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()))
; |
| 330 size.scale(multiplier); | 328 size.scale(multiplier); |
| 331 size.clampToMinimumSize(minimumSize); | 329 size.clampToMinimumSize(minimumSize); |
| 332 return size; | 330 return size; |
| 333 } | 331 } |
| 334 | 332 |
| 335 void ImageResource::notifyObservers(const IntRect* changeRect) | 333 void ImageResource::notifyObservers(const IntRect* changeRect) |
| 336 { | 334 { |
| 337 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 335 for (auto* observer : m_finishedObservers.asVector()) { |
| 338 while (auto* observer = finishedWalker.next()) { | 336 if (m_finishedObservers.contains(observer)) |
| 339 observer->imageChanged(this, changeRect); | 337 observer->imageChanged(this, changeRect); |
| 340 } | 338 } |
| 341 | 339 for (auto* observer : m_observers.asVector()) { |
| 342 ImageResourceObserverWalker walker(m_observers); | 340 if (m_observers.contains(observer)) |
| 343 while (auto* observer = walker.next()) { | 341 observer->imageChanged(this, changeRect); |
| 344 observer->imageChanged(this, changeRect); | |
| 345 } | 342 } |
| 346 } | 343 } |
| 347 | 344 |
| 348 void ImageResource::clear() | 345 void ImageResource::clear() |
| 349 { | 346 { |
| 350 clearImage(); | 347 clearImage(); |
| 351 clearData(); | 348 clearData(); |
| 352 setEncodedSize(0); | 349 setEncodedSize(0); |
| 353 } | 350 } |
| 354 | 351 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 // to update MemoryCache. | 479 // to update MemoryCache. |
| 483 if (decodedSize() != 0) | 480 if (decodedSize() != 0) |
| 484 Resource::didAccessDecodedData(); | 481 Resource::didAccessDecodedData(); |
| 485 } | 482 } |
| 486 | 483 |
| 487 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 484 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
| 488 { | 485 { |
| 489 if (!image || image != m_image) | 486 if (!image || image != m_image) |
| 490 return false; | 487 return false; |
| 491 | 488 |
| 492 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 489 for (auto* observer : m_finishedObservers.asVector()) { |
| 493 while (auto* observer = finishedWalker.next()) { | 490 if (m_finishedObservers.contains(observer) && observer->willRenderImage(
)) |
| 494 if (observer->willRenderImage()) | |
| 495 return false; | 491 return false; |
| 496 } | 492 } |
| 497 | 493 |
| 498 ImageResourceObserverWalker walker(m_observers); | 494 for (auto* observer : m_observers.asVector()) { |
| 499 while (auto* observer = walker.next()) { | 495 if (m_observers.contains(observer) && observer->willRenderImage()) |
| 500 if (observer->willRenderImage()) | |
| 501 return false; | 496 return false; |
| 502 } | 497 } |
| 503 | 498 |
| 504 return true; | 499 return true; |
| 505 } | 500 } |
| 506 | 501 |
| 507 void ImageResource::animationAdvanced(const blink::Image* image) | 502 void ImageResource::animationAdvanced(const blink::Image* image) |
| 508 { | 503 { |
| 509 if (!image || image != m_image) | 504 if (!image || image != m_image) |
| 510 return; | 505 return; |
| 511 notifyObservers(); | 506 notifyObservers(); |
| 512 } | 507 } |
| 513 | 508 |
| 514 void ImageResource::updateImageAnimationPolicy() | 509 void ImageResource::updateImageAnimationPolicy() |
| 515 { | 510 { |
| 516 if (!m_image) | 511 if (!m_image) |
| 517 return; | 512 return; |
| 518 | 513 |
| 519 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 514 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
| 520 | 515 for (auto* observer : m_finishedObservers.asVector()) { |
| 521 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 516 if (m_finishedObservers.contains(observer) && observer->getImageAnimatio
nPolicy(newPolicy)) |
| 522 while (auto* observer = finishedWalker.next()) { | 517 break; |
| 523 if (observer->getImageAnimationPolicy(newPolicy)) | 518 } |
| 519 for (auto* observer : m_observers.asVector()) { |
| 520 if (m_observers.contains(observer) && observer->getImageAnimationPolicy(
newPolicy)) |
| 524 break; | 521 break; |
| 525 } | 522 } |
| 526 | 523 |
| 527 ImageResourceObserverWalker walker(m_observers); | |
| 528 while (auto* observer = walker.next()) { | |
| 529 if (observer->getImageAnimationPolicy(newPolicy)) | |
| 530 break; | |
| 531 } | |
| 532 | |
| 533 if (m_image->animationPolicy() != newPolicy) { | 524 if (m_image->animationPolicy() != newPolicy) { |
| 534 m_image->resetAnimation(); | 525 m_image->resetAnimation(); |
| 535 m_image->setAnimationPolicy(newPolicy); | 526 m_image->setAnimationPolicy(newPolicy); |
| 536 } | 527 } |
| 537 } | 528 } |
| 538 | 529 |
| 539 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 530 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
| 540 { | 531 { |
| 541 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) | 532 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) |
| 542 return; | 533 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 if (response().wasFetchedViaServiceWorker()) | 585 if (response().wasFetchedViaServiceWorker()) |
| 595 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; | 586 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; |
| 596 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 587 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 597 return false; | 588 return false; |
| 598 if (passesAccessControlCheck(securityOrigin)) | 589 if (passesAccessControlCheck(securityOrigin)) |
| 599 return true; | 590 return true; |
| 600 return !securityOrigin->taintsCanvas(response().url()); | 591 return !securityOrigin->taintsCanvas(response().url()); |
| 601 } | 592 } |
| 602 | 593 |
| 603 } // namespace blink | 594 } // namespace blink |
| OLD | NEW |