diff options
Diffstat (limited to 'Source/WebCore/loader/cache/CachedImage.h')
-rw-r--r-- | Source/WebCore/loader/cache/CachedImage.h | 155 |
1 files changed, 81 insertions, 74 deletions
diff --git a/Source/WebCore/loader/cache/CachedImage.h b/Source/WebCore/loader/cache/CachedImage.h index 12b77cc46..985aa9749 100644 --- a/Source/WebCore/loader/cache/CachedImage.h +++ b/Source/WebCore/loader/cache/CachedImage.h @@ -20,17 +20,16 @@ Boston, MA 02110-1301, USA. */ -#ifndef CachedImage_h -#define CachedImage_h +#pragma once #include "CachedResource.h" +#include "Image.h" #include "ImageObserver.h" #include "IntRect.h" #include "IntSizeHash.h" #include "LayoutSize.h" #include "SVGImageCache.h" #include <wtf/HashMap.h> -#include <wtf/Vector.h> namespace WebCore { @@ -44,124 +43,132 @@ class SecurityOrigin; struct Length; -class CachedImage : public CachedResource, public ImageObserver { +class CachedImage final : public CachedResource { friend class MemoryCache; public: - CachedImage(const ResourceRequest&); - CachedImage(Image*); - CachedImage(const URL&, Image*); + CachedImage(CachedResourceRequest&&, SessionID); + CachedImage(Image*, SessionID); + // Constructor to use for manually cached images. + CachedImage(const URL&, Image*, SessionID); virtual ~CachedImage(); - Image* image(); // Returns the nullImage() if the image is not available yet. - Image* imageForRenderer(const RenderObject*); // Returns the nullImage() if the image is not available yet. + WEBCORE_EXPORT Image* image(); // Returns the nullImage() if the image is not available yet. + WEBCORE_EXPORT Image* imageForRenderer(const RenderObject*); // Returns the nullImage() if the image is not available yet. bool hasImage() const { return m_image.get(); } - bool currentFrameKnownToBeOpaque(const RenderElement*); // Side effect: ensures decoded image is in cache, therefore should only be called when about to draw the image. + bool currentFrameKnownToBeOpaque(const RenderElement*); std::pair<Image*, float> brokenImage(float deviceScaleFactor) const; // Returns an image and the image's resolution scale factor. - bool willPaintBrokenImage() const; + bool willPaintBrokenImage() const; - bool canRender(const RenderObject* renderer, float multiplier) { return !errorOccurred() && !imageSizeForRenderer(renderer, multiplier).isEmpty(); } + bool canRender(const RenderElement* renderer, float multiplier) { return !errorOccurred() && !imageSizeForRenderer(renderer, multiplier).isEmpty(); } - void setContainerSizeForRenderer(const CachedImageClient*, const IntSize&, float); + void setContainerSizeForRenderer(const CachedImageClient*, const LayoutSize&, float); bool usesImageContainerSize() const; bool imageHasRelativeWidth() const; bool imageHasRelativeHeight() const; - virtual void addDataBuffer(ResourceBuffer*) override; - virtual void finishLoading(ResourceBuffer*) override; + void addDataBuffer(SharedBuffer&) override; + void finishLoading(SharedBuffer*) override; enum SizeType { UsedSize, IntrinsicSize }; // This method takes a zoom multiplier that can be used to increase the natural size of the image by the zoom. - LayoutSize imageSizeForRenderer(const RenderObject*, float multiplier, SizeType = UsedSize); // returns the size of the complete image. + LayoutSize imageSizeForRenderer(const RenderElement*, float multiplier, SizeType = UsedSize); // returns the size of the complete image. void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio); -#if USE(CF) - // FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent. - virtual bool isManual() const { return false; } -#endif - - static void resumeAnimatingImagesForLoader(CachedResourceLoader*); - -#if ENABLE(DISK_IMAGE_CACHE) - virtual bool canUseDiskImageCache() const override; - virtual void useDiskImageCache() override; -#endif + bool isManuallyCached() const { return m_isManuallyCached; } + RevalidationDecision makeRevalidationDecision(CachePolicy) const override; + void load(CachedResourceLoader&) override; bool isOriginClean(SecurityOrigin*); private: - virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&) override; - void clear(); + CachedImage(CachedImage&, const ResourceRequest&, SessionID); + + void setBodyDataFrom(const CachedResource&) final; + void createImage(); void clearImage(); - bool canBeDrawn() const; // If not null, changeRect is the changed part of the image. - void notifyObservers(const IntRect* changeRect = 0); - virtual PurgePriority purgePriority() const override { return PurgeFirst; } + void notifyObservers(const IntRect* changeRect = nullptr); void checkShouldPaintBrokenImage(); - virtual void switchClientsToRevalidatedResource() override; - virtual bool mayTryReplaceEncodedData() const override { return true; } + void switchClientsToRevalidatedResource() final; + bool mayTryReplaceEncodedData() const final { return true; } - virtual void didAddClient(CachedResourceClient*) override; - virtual void didRemoveClient(CachedResourceClient*) override; + void didAddClient(CachedResourceClient&) final; + void didRemoveClient(CachedResourceClient&) final; - virtual void allClientsRemoved() override; - virtual void destroyDecodedData() override; + void allClientsRemoved() override; + void destroyDecodedData() override; - virtual void addData(const char* data, unsigned length) override; - virtual void error(CachedResource::Status) override; - virtual void responseReceived(const ResourceResponse&) override; + void addData(const char* data, unsigned length) override; + void error(CachedResource::Status) override; + void responseReceived(const ResourceResponse&) override; // For compatibility, images keep loading even if there are HTTP errors. - virtual bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; } - - virtual bool isImage() const override { return true; } - virtual bool stillNeedsLoad() const override { return !errorOccurred() && status() == Unknown && !isLoading(); } + bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; } + + bool stillNeedsLoad() const override { return !errorOccurred() && status() == Unknown && !isLoading(); } + + class CachedImageObserver final : public RefCounted<CachedImageObserver>, public ImageObserver { + public: + static Ref<CachedImageObserver> create(CachedImage& image) { return adoptRef(*new CachedImageObserver(image)); } + void add(CachedImage& image) { m_cachedImages.append(&image); } + void remove(CachedImage& image) { m_cachedImages.removeFirst(&image); } + + private: + explicit CachedImageObserver(CachedImage&); + + // ImageObserver API + URL sourceUrl() const override { return m_cachedImages[0]->url(); } + bool allowSubsampling() const final { return m_allowSubsampling; } + bool allowLargeImageAsyncDecoding() const override { return m_allowLargeImageAsyncDecoding; } + bool allowAnimatedImageAsyncDecoding() const override { return m_allowAnimatedImageAsyncDecoding; } + bool showDebugBackground() const final { return m_showDebugBackground; } + void decodedSizeChanged(const Image*, long long delta) final; + void didDraw(const Image*) final; + + void animationAdvanced(const Image*) final; + void changedInRect(const Image*, const IntRect*) final; + + Vector<CachedImage*> m_cachedImages; + // The default value of m_allowSubsampling should be the same as defaultImageSubsamplingEnabled in Settings.cpp +#if PLATFORM(IOS) + bool m_allowSubsampling { true }; +#else + bool m_allowSubsampling { false }; +#endif + bool m_allowLargeImageAsyncDecoding { true }; + bool m_allowAnimatedImageAsyncDecoding { true }; + bool m_showDebugBackground { false }; + }; - // ImageObserver - virtual void decodedSizeChanged(const Image*, int delta) override; - virtual void didDraw(const Image*) override; + void decodedSizeChanged(const Image*, long long delta); + void didDraw(const Image*); + void animationAdvanced(const Image*); + void changedInRect(const Image*, const IntRect*); - virtual bool shouldPauseAnimation(const Image*) override; - virtual void animationAdvanced(const Image*) override; - virtual void changedInRect(const Image*, const IntRect&) override; + void addIncrementalDataBuffer(SharedBuffer&); - void addIncrementalDataBuffer(ResourceBuffer*); + void didReplaceSharedBufferContents() override; - typedef std::pair<IntSize, float> SizeAndZoom; + typedef std::pair<LayoutSize, float> SizeAndZoom; typedef HashMap<const CachedImageClient*, SizeAndZoom> ContainerSizeRequests; ContainerSizeRequests m_pendingContainerSizeRequests; + RefPtr<CachedImageObserver> m_imageObserver; RefPtr<Image> m_image; -#if ENABLE(SVG) std::unique_ptr<SVGImageCache> m_svgImageCache; -#endif - bool m_shouldPaintBrokenImage; -}; - -#if USE(CF) -// FIXME: We should look to incorporate the functionality of CachedImageManual -// into CachedImage or find a better place for this class. -// FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent. -class CachedImageManual : public CachedImage { -public: - CachedImageManual(const URL&, Image*); - void addFakeClient() { addClient(m_fakeClient.get()); } - void removeFakeClient() { removeClient(m_fakeClient.get()); } - virtual bool isManual() const override { return true; } - virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const; -private: - std::unique_ptr<CachedResourceClient> m_fakeClient; + bool m_isManuallyCached { false }; + bool m_shouldPaintBrokenImage { true }; }; -#endif -} +} // namespace WebCore -#endif +SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedImage, CachedResource::ImageResource) |