Chromium Code Reviews| Index: third_party/WebKit/Source/core/fetch/ImageResource.h |
| diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.h b/third_party/WebKit/Source/core/fetch/ImageResource.h |
| index 2d2b657db0bf936115f91bebc31fa7911502798c..ce17a58c2e9c6601c8d2ae278a7929ab562ee3f5 100644 |
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.h |
| +++ b/third_party/WebKit/Source/core/fetch/ImageResource.h |
| @@ -24,33 +24,31 @@ |
| #define ImageResource_h |
| #include "core/CoreExport.h" |
| +#include "core/fetch/ImageResourceContentInterface.h" |
| #include "core/fetch/MultipartImageResourceParser.h" |
| #include "core/fetch/Resource.h" |
| -#include "platform/geometry/IntRect.h" |
| -#include "platform/geometry/IntSizeHash.h" |
| -#include "platform/geometry/LayoutSize.h" |
| -#include "platform/graphics/Image.h" |
| -#include "platform/graphics/ImageObserver.h" |
| -#include "platform/graphics/ImageOrientation.h" |
| -#include "wtf/HashMap.h" |
| #include <memory> |
| namespace blink { |
| class FetchRequest; |
| -class ImageResourceObserver; |
| class MemoryCache; |
| class ResourceClient; |
| class ResourceFetcher; |
| class SecurityOrigin; |
| +class ImageResourceContent; |
| -// ImageResource class represents an image type resource. |
| +// ImageResource is the resource-related part of image loading. |
| +// Image-related things (blink::Image and ImageResourceObserver) are handled by |
| +// ImageResourceContent. |
| +// Most users should use ImageResourceContent instead of ImageResource. |
| +// https://docs.google.com/document/d/1O-fB83mrE0B_V8gzXNqHgmRLCvstTB4MMi3RnVLr8bE/edit?usp=sharing |
| // |
| -// As for the lifetimes of m_image and m_data, see this document: |
| +// As for the lifetimes of ImageResourceContent::m_image and m_data, see this |
| +// document: |
| // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1VsqpxoL7aciY/edit?usp=sharing |
| class CORE_EXPORT ImageResource final |
| : public Resource, |
| - public ImageObserver, |
| public MultipartImageResourceParser::Client { |
| friend class MemoryCache; |
| USING_GARBAGE_COLLECTED_MIXIN(ImageResource); |
| @@ -58,55 +56,16 @@ class CORE_EXPORT ImageResource final |
| public: |
| using ClientType = ResourceClient; |
| + // Use ImageResourceContent::fetch() unless ImageResource is required. |
| static ImageResource* fetch(FetchRequest&, ResourceFetcher*); |
| - static ImageResource* create(blink::Image* image) { |
| - return new ImageResource(image, ResourceLoaderOptions()); |
| - } |
| - |
| - static ImageResource* create(const ResourceRequest& request) { |
| - return new ImageResource(request, ResourceLoaderOptions(), false); |
| - } |
| + // TODO(hiroshige): Make create() test-only by refactoring ImageDocument. |
| + static ImageResource* create(const ResourceRequest&); |
| ~ImageResource() override; |
| - blink::Image* |
| - getImage(); // Returns the nullImage() if the image is not available yet. |
| - bool hasImage() const { return m_image.get(); } |
| - |
| - static std::pair<blink::Image*, float> brokenImage( |
| - float deviceScaleFactor); // Returns an image and the image's resolution |
| - // scale factor. |
| - bool willPaintBrokenImage() const; |
| - |
| - bool usesImageContainerSize() const; |
| - bool imageHasRelativeSize() const; |
| - // The device pixel ratio we got from the server for this image, or 1.0. |
| - float devicePixelRatioHeaderValue() const { |
| - return m_devicePixelRatioHeaderValue; |
| - } |
| - bool hasDevicePixelRatioHeaderValue() const { |
| - return m_hasDevicePixelRatioHeaderValue; |
| - } |
| - |
| - enum SizeType { |
| - // Report the intrinsic size. |
| - IntrinsicSize, |
| - |
| - // Report the intrinsic size corrected to account for image density. |
| - IntrinsicCorrectedToDPR, |
| - }; |
| - |
| - // This method takes a zoom multiplier that can be used to increase the |
| - // natural size of the image by the zoom. |
| - LayoutSize imageSize( |
| - RespectImageOrientationEnum shouldRespectImageOrientation, |
| - float multiplier, |
| - SizeType = IntrinsicSize); |
| - |
| - bool isAccessAllowed(SecurityOrigin*); |
| - |
| - void updateImageAnimationPolicy(); |
| + ImageResourceContentInterface* getContent() const; |
| + ImageResourceContent* getRealContent() const; |
|
kinuko
2016/12/01 16:40:55
Having both methods here feels a bit confusing...
kinuko
2016/12/01 16:40:55
...ok I just read the comment about why you introd
hiroshige
2016/12/02 08:51:17
Discussed with toyoshim@ offline, and we conclude
|
| enum class ReloadCachePolicy { |
| UseExistingPolicy = 0, // Don't modify the request's cache policy. |
| @@ -122,9 +81,6 @@ class CORE_EXPORT ImageResource final |
| void didAddClient(ResourceClient*) override; |
| - void addObserver(ImageResourceObserver*); |
| - void removeObserver(ImageResourceObserver*); |
| - |
| ResourcePriority priorityFromObservers() override; |
| void allClientsAndObserversRemoved() override; |
| @@ -141,13 +97,6 @@ class CORE_EXPORT ImageResource final |
| bool isImage() const override { return true; } |
| - // ImageObserver |
| - void decodedSizeChangedTo(const blink::Image*, size_t newSize) override; |
| - |
| - bool shouldPauseAnimation(const blink::Image*) override; |
| - void animationAdvanced(const blink::Image*) override; |
| - void changedInRect(const blink::Image*, const IntRect&) override; |
| - |
| // MultipartImageResourceParser::Client |
| void onePartInMultipartReceived(const ResourceResponse&) final; |
| void multipartDataReceived(const char*, size_t) final; |
| @@ -159,14 +108,13 @@ class CORE_EXPORT ImageResource final |
| return m_isPlaceholder && willPaintBrokenImage(); |
| } |
| - void setNotRefetchableDataFromDiskCache() { |
| - m_isRefetchableDataFromDiskCache = false; |
| - } |
| - |
| DECLARE_VIRTUAL_TRACE(); |
| private: |
| - explicit ImageResource(blink::Image*, const ResourceLoaderOptions&); |
| + // Only for ImageResourceInfoImpl. |
| + void decodeError(bool allDataReceived); |
| + bool isAccessAllowed(SecurityOrigin*, |
| + bool doesCurrentFrameHasSingleSecurityOrigin) const; |
| enum class MultipartParsingState : uint8_t { |
| WaitingForFirstPart, |
| @@ -174,48 +122,37 @@ class CORE_EXPORT ImageResource final |
| FinishedParsingFirstPart, |
| }; |
| + class ImageResourceInfoImpl; |
| class ImageResourceFactory; |
| ImageResource(const ResourceRequest&, |
| const ResourceLoaderOptions&, |
| + ImageResourceContent*, |
| bool isPlaceholder); |
| bool hasClientsOrObservers() const override { |
| - return Resource::hasClientsOrObservers() || !m_observers.isEmpty() || |
| - !m_finishedObservers.isEmpty(); |
| + return Resource::hasClientsOrObservers() || getContent()->hasObservers(); |
| } |
| - void clear(); |
| - void createImage(); |
| - void updateImage(bool allDataReceived); |
| void updateImageAndClearBuffer(); |
| - void clearImage(); |
| - enum NotifyFinishOption { ShouldNotifyFinish, DoNotNotifyFinish }; |
| - // If not null, changeRect is the changed part of the image. |
| - void notifyObservers(NotifyFinishOption, const IntRect* changeRect = nullptr); |
| - |
| - void ensureImage(); |
| void checkNotify() override; |
| - void notifyObserversInternal(); |
| - void markObserverFinished(ImageResourceObserver*); |
| - |
| - void doResetAnimation(); |
| void destroyDecodedDataIfPossible() override; |
| void destroyDecodedDataForFailedRevalidation() override; |
| void flushImageIfNeeded(TimerBase*); |
| + bool willPaintBrokenImage() const; |
| + |
| + Member<ImageResourceContent> m_content; |
| + |
| float m_devicePixelRatioHeaderValue; |
| Member<MultipartImageResourceParser> m_multipartParser; |
| - RefPtr<blink::Image> m_image; |
| MultipartParsingState m_multipartParsingState = |
| MultipartParsingState::WaitingForFirstPart; |
| bool m_hasDevicePixelRatioHeaderValue; |
| - HashCountedSet<ImageResourceObserver*> m_observers; |
| - HashCountedSet<ImageResourceObserver*> m_finishedObservers; |
| // Indicates if the ImageResource is currently scheduling a reload, e.g. |
| // because reloadIfLoFi() was called. |
| @@ -227,11 +164,6 @@ class CORE_EXPORT ImageResource final |
| Timer<ImageResource> m_flushTimer; |
| double m_lastFlushTime = 0.; |
| - Image::SizeAvailability m_sizeAvailable = Image::SizeUnavailable; |
| - |
| - // Indicates if this resource's encoded image data can be purged and refetched |
| - // from disk cache to save memory usage. See crbug/664437. |
| - bool m_isRefetchableDataFromDiskCache; |
| }; |
| DEFINE_RESOURCE_TYPE_CASTS(Image); |