| 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 #include <v8.h> | 44 #include <v8.h> |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource
Observer, ImageResourceObserver>; | |
| 48 | |
| 49 ImageResource* ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetc
her) | 48 ImageResource* ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetc
her) |
| 50 { | 49 { |
| 51 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) | 50 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) |
| 52 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); | 51 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); |
| 53 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 52 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
| 54 KURL requestURL = request.resourceRequest().url(); | 53 KURL requestURL = request.resourceRequest().url(); |
| 55 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) | 54 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) |
| 56 fetcher->context().sendImagePing(requestURL); | 55 fetcher->context().sendImagePing(requestURL); |
| 57 return nullptr; | 56 return nullptr; |
| 58 } | 57 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 { | 96 { |
| 98 notifyObserversInternal(MarkFinishedOption::ShouldMarkFinished); | 97 notifyObserversInternal(MarkFinishedOption::ShouldMarkFinished); |
| 99 Resource::checkNotify(); | 98 Resource::checkNotify(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 void ImageResource::notifyObserversInternal(MarkFinishedOption markFinishedOptio
n) | 101 void ImageResource::notifyObserversInternal(MarkFinishedOption markFinishedOptio
n) |
| 103 { | 102 { |
| 104 if (isLoading()) | 103 if (isLoading()) |
| 105 return; | 104 return; |
| 106 | 105 |
| 107 ImageResourceObserverWalker walker(m_observers); | 106 for (auto* observer : m_observers.asVector()) { |
| 108 while (auto* observer = walker.next()) { | 107 if (m_observers.contains(observer)) { |
| 109 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished) | 108 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished) |
| 110 markObserverFinished(observer); | 109 markObserverFinished(observer); |
| 111 observer->imageNotifyFinished(this); | 110 observer->imageNotifyFinished(this); |
| 111 } |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ImageResource::markObserverFinished(ImageResourceObserver* observer) | 115 void ImageResource::markObserverFinished(ImageResourceObserver* observer) |
| 116 { | 116 { |
| 117 if (m_observers.contains(observer)) { | 117 if (m_observers.contains(observer)) { |
| 118 m_finishedObservers.add(observer); | 118 m_finishedObservers.add(observer); |
| 119 m_observers.remove(observer); | 119 m_observers.remove(observer); |
| 120 } | 120 } |
| 121 } | 121 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (nextPriority.visibility == ResourcePriority::NotVisible) | 175 if (nextPriority.visibility == ResourcePriority::NotVisible) |
| 176 return; | 176 return; |
| 177 priority.visibility = ResourcePriority::Visible; | 177 priority.visibility = ResourcePriority::Visible; |
| 178 priority.intraPriorityValue += nextPriority.intraPriorityValue; | 178 priority.intraPriorityValue += nextPriority.intraPriorityValue; |
| 179 } | 179 } |
| 180 | 180 |
| 181 ResourcePriority ImageResource::priorityFromObservers() | 181 ResourcePriority ImageResource::priorityFromObservers() |
| 182 { | 182 { |
| 183 ResourcePriority priority; | 183 ResourcePriority priority; |
| 184 | 184 |
| 185 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 185 for (auto* observer : m_finishedObservers.asVector()) { |
| 186 while (const auto* observer = finishedWalker.next()) { | 186 if (m_finishedObservers.contains(observer)) |
| 187 priorityFromObserver(observer, priority); | 187 priorityFromObserver(observer, priority); |
| 188 } | 188 } |
| 189 | 189 for (auto* observer : m_observers.asVector()) { |
| 190 ImageResourceObserverWalker walker(m_observers); | 190 if (m_observers.contains(observer)) |
| 191 while (const auto* observer = walker.next()) { | 191 priorityFromObserver(observer, priority); |
| 192 priorityFromObserver(observer, priority); | |
| 193 } | 192 } |
| 194 | 193 |
| 195 return priority; | 194 return priority; |
| 196 } | 195 } |
| 197 | 196 |
| 198 void ImageResource::destroyDecodedDataForFailedRevalidation() | 197 void ImageResource::destroyDecodedDataForFailedRevalidation() |
| 199 { | 198 { |
| 200 clearImage(); | 199 clearImage(); |
| 201 setDecodedSize(0); | 200 setDecodedSize(0); |
| 202 } | 201 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed
. | 319 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed
. |
| 321 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU
nit(), | 320 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU
nit(), |
| 322 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()))
; | 321 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()))
; |
| 323 size.scale(multiplier); | 322 size.scale(multiplier); |
| 324 size.clampToMinimumSize(minimumSize); | 323 size.clampToMinimumSize(minimumSize); |
| 325 return size; | 324 return size; |
| 326 } | 325 } |
| 327 | 326 |
| 328 void ImageResource::notifyObservers(const IntRect* changeRect) | 327 void ImageResource::notifyObservers(const IntRect* changeRect) |
| 329 { | 328 { |
| 330 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 329 for (auto* observer : m_finishedObservers.asVector()) { |
| 331 while (auto* observer = finishedWalker.next()) { | 330 if (m_finishedObservers.contains(observer)) |
| 332 observer->imageChanged(this, changeRect); | 331 observer->imageChanged(this, changeRect); |
| 333 } | 332 } |
| 334 | 333 for (auto* observer : m_observers.asVector()) { |
| 335 ImageResourceObserverWalker walker(m_observers); | 334 if (m_observers.contains(observer)) |
| 336 while (auto* observer = walker.next()) { | 335 observer->imageChanged(this, changeRect); |
| 337 observer->imageChanged(this, changeRect); | |
| 338 } | 336 } |
| 339 } | 337 } |
| 340 | 338 |
| 341 void ImageResource::clear() | 339 void ImageResource::clear() |
| 342 { | 340 { |
| 343 clearImage(); | 341 clearImage(); |
| 344 clearData(); | 342 clearData(); |
| 345 setEncodedSize(0); | 343 setEncodedSize(0); |
| 346 } | 344 } |
| 347 | 345 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 // to update MemoryCache. | 475 // to update MemoryCache. |
| 478 if (decodedSize() != 0) | 476 if (decodedSize() != 0) |
| 479 Resource::didAccessDecodedData(); | 477 Resource::didAccessDecodedData(); |
| 480 } | 478 } |
| 481 | 479 |
| 482 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 480 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
| 483 { | 481 { |
| 484 if (!image || image != m_image) | 482 if (!image || image != m_image) |
| 485 return false; | 483 return false; |
| 486 | 484 |
| 487 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 485 for (auto* observer : m_finishedObservers.asVector()) { |
| 488 while (auto* observer = finishedWalker.next()) { | 486 if (m_finishedObservers.contains(observer) && observer->willRenderImage(
)) |
| 489 if (observer->willRenderImage()) | |
| 490 return false; | 487 return false; |
| 491 } | 488 } |
| 492 | 489 |
| 493 ImageResourceObserverWalker walker(m_observers); | 490 for (auto* observer : m_observers.asVector()) { |
| 494 while (auto* observer = walker.next()) { | 491 if (m_observers.contains(observer) && observer->willRenderImage()) |
| 495 if (observer->willRenderImage()) | |
| 496 return false; | 492 return false; |
| 497 } | 493 } |
| 498 | 494 |
| 499 return true; | 495 return true; |
| 500 } | 496 } |
| 501 | 497 |
| 502 void ImageResource::animationAdvanced(const blink::Image* image) | 498 void ImageResource::animationAdvanced(const blink::Image* image) |
| 503 { | 499 { |
| 504 if (!image || image != m_image) | 500 if (!image || image != m_image) |
| 505 return; | 501 return; |
| 506 notifyObservers(); | 502 notifyObservers(); |
| 507 } | 503 } |
| 508 | 504 |
| 509 void ImageResource::updateImageAnimationPolicy() | 505 void ImageResource::updateImageAnimationPolicy() |
| 510 { | 506 { |
| 511 if (!m_image) | 507 if (!m_image) |
| 512 return; | 508 return; |
| 513 | 509 |
| 514 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 510 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
| 515 | 511 for (auto* observer : m_finishedObservers.asVector()) { |
| 516 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 512 if (m_finishedObservers.contains(observer) && observer->getImageAnimatio
nPolicy(newPolicy)) |
| 517 while (auto* observer = finishedWalker.next()) { | 513 break; |
| 518 if (observer->getImageAnimationPolicy(newPolicy)) | 514 } |
| 515 for (auto* observer : m_observers.asVector()) { |
| 516 if (m_observers.contains(observer) && observer->getImageAnimationPolicy(
newPolicy)) |
| 519 break; | 517 break; |
| 520 } | 518 } |
| 521 | 519 |
| 522 ImageResourceObserverWalker walker(m_observers); | |
| 523 while (auto* observer = walker.next()) { | |
| 524 if (observer->getImageAnimationPolicy(newPolicy)) | |
| 525 break; | |
| 526 } | |
| 527 | |
| 528 if (m_image->animationPolicy() != newPolicy) { | 520 if (m_image->animationPolicy() != newPolicy) { |
| 529 m_image->resetAnimation(); | 521 m_image->resetAnimation(); |
| 530 m_image->setAnimationPolicy(newPolicy); | 522 m_image->setAnimationPolicy(newPolicy); |
| 531 } | 523 } |
| 532 } | 524 } |
| 533 | 525 |
| 534 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 526 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
| 535 { | 527 { |
| 536 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) | 528 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) |
| 537 return; | 529 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 if (response().wasFetchedViaServiceWorker()) | 584 if (response().wasFetchedViaServiceWorker()) |
| 593 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; | 585 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; |
| 594 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 586 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 595 return false; | 587 return false; |
| 596 if (passesAccessControlCheck(securityOrigin)) | 588 if (passesAccessControlCheck(securityOrigin)) |
| 597 return true; | 589 return true; |
| 598 return !securityOrigin->taintsCanvas(response().url()); | 590 return !securityOrigin->taintsCanvas(response().url()); |
| 599 } | 591 } |
| 600 | 592 |
| 601 } // namespace blink | 593 } // namespace blink |
| OLD | NEW |