| 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 fecb6929c0488107cd44f6c145dc19c48b14d56a..f0648c2c38b80f03bd3b500366466a0577c0e925 100644
|
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.h
|
| +++ b/third_party/WebKit/Source/core/fetch/ImageResource.h
|
| @@ -43,6 +43,7 @@ class MemoryCache;
|
| class ResourceClient;
|
| class ResourceFetcher;
|
| class SecurityOrigin;
|
| +class SubstituteData;
|
|
|
| // ImageResource class represents an image type resource.
|
| //
|
| @@ -54,7 +55,11 @@ class CORE_EXPORT ImageResource final : public Resource, public ImageObserver, p
|
| public:
|
| using ClientType = ResourceClient;
|
|
|
| - static ImageResource* fetch(FetchRequest&, ResourceFetcher*);
|
| + enum class PlaceholderRequestType {
|
| + DisallowPlaceholder = 0, // The image being requested must not be a placeholder.
|
| + AllowPlaceholder, // The image being requested is allowed to be a placeholder.
|
| + };
|
| + static ImageResource* fetch(FetchRequest&, ResourceFetcher*, PlaceholderRequestType = PlaceholderRequestType::DisallowPlaceholder);
|
|
|
| static ImageResource* create(blink::Image* image)
|
| {
|
| @@ -63,7 +68,7 @@ public:
|
|
|
| static ImageResource* create(const ResourceRequest& request)
|
| {
|
| - return new ImageResource(request, ResourceLoaderOptions());
|
| + return new ImageResource(request, ResourceLoaderOptions(), request, false /* isPlaceholder */);
|
| }
|
|
|
| ~ImageResource() override;
|
| @@ -129,9 +134,14 @@ public:
|
| void onePartInMultipartReceived(const ResourceResponse&) final;
|
| void multipartDataReceived(const char*, size_t) final;
|
|
|
| + const ResourceRequest& getOriginalResourceRequest() const { return m_originalRequest; }
|
| + bool isPlaceholder() const { return m_isPlaceholder; }
|
| +
|
| DECLARE_VIRTUAL_TRACE();
|
|
|
| private:
|
| + class PlaceholderLoaderJob;
|
| +
|
| explicit ImageResource(blink::Image*, const ResourceLoaderOptions&);
|
|
|
| enum class MultipartParsingState : uint8_t {
|
| @@ -142,15 +152,19 @@ private:
|
|
|
| class ImageResourceFactory : public ResourceFactory {
|
| public:
|
| - ImageResourceFactory()
|
| - : ResourceFactory(Resource::Image) { }
|
| -
|
| - Resource* create(const ResourceRequest& request, const ResourceLoaderOptions& options, const String&) const override
|
| + // Construct a new ImageResourceFactory.
|
| + ImageResourceFactory(bool isPlaceholder)
|
| + : ResourceFactory(Resource::Image)
|
| + , m_isPlaceholder(isPlaceholder)
|
| {
|
| - return new ImageResource(request, options);
|
| }
|
| +
|
| + Resource* create(const ResourceRequest&, const ResourceLoaderOptions&, const String&) const override;
|
| +
|
| + private:
|
| + bool m_isPlaceholder;
|
| };
|
| - ImageResource(const ResourceRequest&, const ResourceLoaderOptions&);
|
| + ImageResource(const ResourceRequest&, const ResourceLoaderOptions&, const ResourceRequest& originalRequest, bool isPlaceholder);
|
|
|
| bool hasClientsOrObservers() const override { return Resource::hasClientsOrObservers() || !m_observers.isEmpty() || !m_finishedObservers.isEmpty(); }
|
| void clear();
|
| @@ -173,6 +187,13 @@ private:
|
| void destroyDecodedDataIfPossible() override;
|
| void destroyDecodedDataForFailedRevalidation() override;
|
|
|
| + void setIsPlaceholder(bool isPlaceholder) { m_isPlaceholder = isPlaceholder; }
|
| +
|
| + // Reload the image using the given ResourceFetcher and ResourceRequest. If
|
| + // valid SubstituteData is provided, then the load will complete
|
| + // synchronously with a 200 response for the given SubstituteData.
|
| + void reload(ResourceFetcher*, const ResourceRequest&, const SubstituteData&);
|
| +
|
| float m_devicePixelRatioHeaderValue;
|
|
|
| Member<MultipartImageResourceParser> m_multipartParser;
|
| @@ -181,6 +202,31 @@ private:
|
| bool m_hasDevicePixelRatioHeaderValue;
|
| HashCountedSet<ImageResourceObserver*> m_observers;
|
| HashCountedSet<ImageResourceObserver*> m_finishedObservers;
|
| +
|
| + // The original ResourceRequest, before making any modifications for
|
| + // fetching placeholders (e.g. adding Range request headers, etc.). This is
|
| + // used by the PlaceholderLoaderJob to reset the ResourceRequest to its
|
| + // original contents while attempting to fetch different states of
|
| + // placeholder images. This needs to outlive the |m_placeholderLoaderJob| so
|
| + // that an ImageResource that has finished loading can still be reloaded and
|
| + // replaced with the full image.
|
| + ResourceRequest m_originalRequest;
|
| +
|
| + // Set to true if the image is a placeholder or if the ImageResource is
|
| + // currently attempting to fetch and construct a placeholder image.
|
| + bool m_isPlaceholder;
|
| +
|
| + // The job responsible for managing loading a placeholder image. This will
|
| + // only be non-null while a placeholder image is being loaded.
|
| + Member<PlaceholderLoaderJob> m_placeholderLoaderJob;
|
| +
|
| + // Flag indicating that the ImageResource is currently scheduling a reload
|
| + // operation. When this flag is set, no observers should be notified of
|
| + // image completion or marked as finished, to avoid notifying observers that
|
| + // the image is finished before the loading process is complete, e.g. if a
|
| + // placeholder or Lo-Fi image is being reloaded before the original load
|
| + // completes.
|
| + bool m_isSchedulingReload;
|
| };
|
|
|
| DEFINE_RESOURCE_TYPE_CASTS(Image);
|
|
|