eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 1 | /* |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 2 | Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 | Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 4 | Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
darin | d51eb59 | 2007-05-24 22:56:33 +0000 | [diff] [blame] | 5 | Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 6 | |
| 7 | This library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Library General Public |
| 9 | License as published by the Free Software Foundation; either |
| 10 | version 2 of the License, or (at your option) any later version. |
| 11 | |
| 12 | This library is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | Library General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Library General Public License |
| 18 | along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | Boston, MA 02110-1301, USA. |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
eseidel | 8eddecf | 2007-01-16 00:49:43 +0000 | [diff] [blame] | 23 | #ifndef CachedImage_h |
| 24 | #define CachedImage_h |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 25 | |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 26 | #include "CachedResource.h" |
timothy_horton@apple.com | 3d652c9 | 2014-11-14 04:26:45 +0000 | [diff] [blame] | 27 | #include "Image.h" |
hyatt | c3e1580 | 2007-03-07 07:42:45 +0000 | [diff] [blame] | 28 | #include "ImageObserver.h" |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 29 | #include "IntRect.h" |
pdr@google.com | 0ee8f71 | 2012-12-18 05:01:49 +0000 | [diff] [blame] | 30 | #include "IntSizeHash.h" |
eae@chromium.org | 9717cd8 | 2012-11-07 18:33:44 +0000 | [diff] [blame] | 31 | #include "LayoutSize.h" |
eae@chromium.org | 88c682c | 2012-11-01 15:00:26 +0000 | [diff] [blame] | 32 | #include "SVGImageCache.h" |
pdr@google.com | 0ee8f71 | 2012-12-18 05:01:49 +0000 | [diff] [blame] | 33 | #include <wtf/HashMap.h> |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 34 | #include <wtf/Vector.h> |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 35 | |
darin | 5630e07 | 2006-01-30 07:27:12 +0000 | [diff] [blame] | 36 | namespace WebCore { |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 37 | |
commit-queue@webkit.org | 9ae3fb3 | 2012-08-08 17:54:28 +0000 | [diff] [blame] | 38 | class CachedImageClient; |
abarth@webkit.org | 17d66c6 | 2010-09-08 10:26:02 +0000 | [diff] [blame] | 39 | class CachedResourceLoader; |
zimmermann@webkit.org | cf38c8a | 2011-10-18 08:39:18 +0000 | [diff] [blame] | 40 | class FloatSize; |
abarth@webkit.org | 94d2d9f | 2010-11-08 06:46:03 +0000 | [diff] [blame] | 41 | class MemoryCache; |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 42 | class RenderElement; |
zimmermann@webkit.org | 8cf217f | 2011-10-14 08:08:51 +0000 | [diff] [blame] | 43 | class RenderObject; |
hmuller@adobe.com | b1e2528 | 2013-10-25 20:36:21 +0000 | [diff] [blame] | 44 | class SecurityOrigin; |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 45 | |
zimmermann@webkit.org | 3548f10 | 2011-10-18 09:09:30 +0000 | [diff] [blame] | 46 | struct Length; |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 47 | |
ddkilzer@apple.com | bac2d4d | 2014-02-03 19:34:30 +0000 | [diff] [blame] | 48 | class CachedImage final : public CachedResource, public ImageObserver { |
abarth@webkit.org | 94d2d9f | 2010-11-08 06:46:03 +0000 | [diff] [blame] | 49 | friend class MemoryCache; |
ggaren | fbd237b | 2007-08-10 02:30:30 +0000 | [diff] [blame] | 50 | |
hyatt | 215edaa | 2006-01-28 08:52:23 +0000 | [diff] [blame] | 51 | public: |
ddkilzer@apple.com | bac2d4d | 2014-02-03 19:34:30 +0000 | [diff] [blame] | 52 | enum CacheBehaviorType { AutomaticallyCached, ManuallyCached }; |
| 53 | |
commit-queue@webkit.org | 9ab4d3e | 2014-03-05 20:11:03 +0000 | [diff] [blame] | 54 | CachedImage(const ResourceRequest&, SessionID); |
| 55 | CachedImage(Image*, SessionID); |
| 56 | CachedImage(const URL&, Image*, SessionID); |
| 57 | CachedImage(const URL&, Image*, CacheBehaviorType, SessionID); |
hyatt | 215edaa | 2006-01-28 08:52:23 +0000 | [diff] [blame] | 58 | virtual ~CachedImage(); |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 59 | |
achristensen@apple.com | 0980d45 | 2014-08-20 21:56:55 +0000 | [diff] [blame] | 60 | WEBCORE_EXPORT Image* image(); // Returns the nullImage() if the image is not available yet. |
| 61 | WEBCORE_EXPORT Image* imageForRenderer(const RenderObject*); // Returns the nullImage() if the image is not available yet. |
simon.fraser@apple.com | 1f3fb4c | 2011-01-06 05:44:38 +0000 | [diff] [blame] | 62 | bool hasImage() const { return m_image.get(); } |
simon.fraser@apple.com | a2f15d5 | 2014-08-08 18:55:51 +0000 | [diff] [blame] | 63 | bool currentFrameKnownToBeOpaque(const RenderElement*); |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 64 | |
bdakin@apple.com | e6372a7 | 2011-09-14 18:35:49 +0000 | [diff] [blame] | 65 | std::pair<Image*, float> brokenImage(float deviceScaleFactor) const; // Returns an image and the image's resolution scale factor. |
bdakin@apple.com | 563fc9a | 2011-09-12 21:52:01 +0000 | [diff] [blame] | 66 | bool willPaintBrokenImage() const; |
bdakin@apple.com | b49bc3d | 2011-09-10 06:28:00 +0000 | [diff] [blame] | 67 | |
zimmermann@webkit.org | 8cf217f | 2011-10-14 08:08:51 +0000 | [diff] [blame] | 68 | bool canRender(const RenderObject* renderer, float multiplier) { return !errorOccurred() && !imageSizeForRenderer(renderer, multiplier).isEmpty(); } |
hyatt | 3059a51 | 2006-02-02 08:40:45 +0000 | [diff] [blame] | 69 | |
zalan@apple.com | facdea7 | 2014-04-02 14:18:58 +0000 | [diff] [blame] | 70 | void setContainerSizeForRenderer(const CachedImageClient*, const LayoutSize&, float); |
bdakin@apple.com | 05d7e8e | 2007-12-19 07:53:52 +0000 | [diff] [blame] | 71 | bool usesImageContainerSize() const; |
| 72 | bool imageHasRelativeWidth() const; |
| 73 | bool imageHasRelativeHeight() const; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 74 | |
darin@apple.com | 6644eab | 2014-11-04 16:47:53 +0000 | [diff] [blame] | 75 | virtual void addDataBuffer(SharedBuffer&) override; |
| 76 | virtual void finishLoading(SharedBuffer*) override; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 77 | |
simon.fraser@apple.com | 74523e7 | 2013-08-30 00:23:23 +0000 | [diff] [blame] | 78 | enum SizeType { |
| 79 | UsedSize, |
| 80 | IntrinsicSize |
| 81 | }; |
zimmermann@webkit.org | 8cf217f | 2011-10-14 08:08:51 +0000 | [diff] [blame] | 82 | // This method takes a zoom multiplier that can be used to increase the natural size of the image by the zoom. |
simon.fraser@apple.com | 74523e7 | 2013-08-30 00:23:23 +0000 | [diff] [blame] | 83 | LayoutSize imageSizeForRenderer(const RenderObject*, float multiplier, SizeType = UsedSize); // returns the size of the complete image. |
bdakin@apple.com | fe75cce | 2012-04-30 15:42:28 +0000 | [diff] [blame] | 84 | void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio); |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 85 | |
ddkilzer@apple.com | bac2d4d | 2014-02-03 19:34:30 +0000 | [diff] [blame] | 86 | bool isManuallyCached() const { return m_isManuallyCached; } |
cdumez@apple.com | acd577cf | 2014-12-18 17:21:03 +0000 | [diff] [blame] | 87 | virtual bool mustRevalidateDueToCacheHeaders(const CachedResourceLoader&, CachePolicy) const override; |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 88 | virtual void load(CachedResourceLoader&, const ResourceLoaderOptions&) override; |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 89 | |
hmuller@adobe.com | b1e2528 | 2013-10-25 20:36:21 +0000 | [diff] [blame] | 90 | bool isOriginClean(SecurityOrigin*); |
| 91 | |
hyatt | 215edaa | 2006-01-28 08:52:23 +0000 | [diff] [blame] | 92 | private: |
japhet@chromium.org | 43b65bb | 2012-01-11 23:54:28 +0000 | [diff] [blame] | 93 | void clear(); |
| 94 | |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 95 | void createImage(); |
jamesr@google.com | 05f64f9 | 2012-05-17 01:31:14 +0000 | [diff] [blame] | 96 | void clearImage(); |
simon.fraser@apple.com | f7d140d | 2009-01-02 21:04:27 +0000 | [diff] [blame] | 97 | // If not null, changeRect is the changed part of the image. |
darin@apple.com | 6644eab | 2014-11-04 16:47:53 +0000 | [diff] [blame] | 98 | void notifyObservers(const IntRect* changeRect = nullptr); |
commit-queue@webkit.org | 05565aa | 2011-02-26 09:32:19 +0000 | [diff] [blame] | 99 | void checkShouldPaintBrokenImage(); |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 100 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 101 | virtual void switchClientsToRevalidatedResource() override; |
| 102 | virtual bool mayTryReplaceEncodedData() const override { return true; } |
pdr@google.com | 10f70cf | 2013-01-24 22:27:44 +0000 | [diff] [blame] | 103 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 104 | virtual void didAddClient(CachedResourceClient*) override; |
| 105 | virtual void didRemoveClient(CachedResourceClient*) override; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 106 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 107 | virtual void allClientsRemoved() override; |
| 108 | virtual void destroyDecodedData() override; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 109 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 110 | virtual void addData(const char* data, unsigned length) override; |
| 111 | virtual void error(CachedResource::Status) override; |
| 112 | virtual void responseReceived(const ResourceResponse&) override; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 113 | |
| 114 | // For compatibility, images keep loading even if there are HTTP errors. |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 115 | virtual bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; } |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 116 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 117 | virtual bool stillNeedsLoad() const override { return !errorOccurred() && status() == Unknown && !isLoading(); } |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 118 | |
timothy_horton@apple.com | 3d652c9 | 2014-11-14 04:26:45 +0000 | [diff] [blame] | 119 | virtual bool decodedDataIsPurgeable() const override { return m_image && m_image->decodedDataIsPurgeable(); } |
| 120 | |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 121 | // ImageObserver |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 122 | virtual void decodedSizeChanged(const Image*, int delta) override; |
| 123 | virtual void didDraw(const Image*) override; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 124 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 125 | virtual void animationAdvanced(const Image*) override; |
| 126 | virtual void changedInRect(const Image*, const IntRect&) override; |
carlosgc@webkit.org | 80e15b4 | 2013-06-07 08:57:35 +0000 | [diff] [blame] | 127 | |
darin@apple.com | 6644eab | 2014-11-04 16:47:53 +0000 | [diff] [blame] | 128 | void addIncrementalDataBuffer(SharedBuffer&); |
carlosgc@webkit.org | 3e212df | 2013-06-14 10:59:11 +0000 | [diff] [blame] | 129 | |
zalan@apple.com | facdea7 | 2014-04-02 14:18:58 +0000 | [diff] [blame] | 130 | typedef std::pair<LayoutSize, float> SizeAndZoom; |
pdr@google.com | 0ee8f71 | 2012-12-18 05:01:49 +0000 | [diff] [blame] | 131 | typedef HashMap<const CachedImageClient*, SizeAndZoom> ContainerSizeRequests; |
| 132 | ContainerSizeRequests m_pendingContainerSizeRequests; |
| 133 | |
eric@webkit.org | 5b26560 | 2008-08-14 00:29:26 +0000 | [diff] [blame] | 134 | RefPtr<Image> m_image; |
commit-queue@webkit.org | d6a51e8 | 2013-11-19 17:22:59 +0000 | [diff] [blame] | 135 | std::unique_ptr<SVGImageCache> m_svgImageCache; |
darin@apple.com | 6644eab | 2014-11-04 16:47:53 +0000 | [diff] [blame] | 136 | unsigned m_isManuallyCached : 1; |
| 137 | unsigned m_shouldPaintBrokenImage : 1; |
hyatt | 215edaa | 2006-01-28 08:52:23 +0000 | [diff] [blame] | 138 | }; |
eseidel | 94980f2 | 2006-01-09 09:29:48 +0000 | [diff] [blame] | 139 | |
cdumez@apple.com | c4a3af6 | 2014-10-06 00:31:05 +0000 | [diff] [blame] | 140 | } // namespace WebCore |
ddkilzer@apple.com | f7dd893 | 2014-01-31 02:02:05 +0000 | [diff] [blame] | 141 | |
cdumez@apple.com | c4a3af6 | 2014-10-06 00:31:05 +0000 | [diff] [blame] | 142 | SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedImage, CachedResource::ImageResource) |
darin | 5630e07 | 2006-01-30 07:27:12 +0000 | [diff] [blame] | 143 | |
cdumez@apple.com | c4a3af6 | 2014-10-06 00:31:05 +0000 | [diff] [blame] | 144 | #endif // CachedImage_h |