Chromium Code Reviews| Index: third_party/WebKit/Source/core/fetch/ImageResourceContent.h |
| diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.h b/third_party/WebKit/Source/core/fetch/ImageResourceContent.h |
| similarity index 32% |
| copy from third_party/WebKit/Source/core/fetch/ImageResource.h |
| copy to third_party/WebKit/Source/core/fetch/ImageResourceContent.h |
| index 2d2b657db0bf936115f91bebc31fa7911502798c..a28f8097270e946248d01a849d24887f398b7609 100644 |
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.h |
| +++ b/third_party/WebKit/Source/core/fetch/ImageResourceContent.h |
| @@ -1,93 +1,69 @@ |
| -/* |
| - Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| - Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
| - Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| - Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| - |
| - This library is free software; you can redistribute it and/or |
| - modify it under the terms of the GNU Library General Public |
| - License as published by the Free Software Foundation; either |
| - version 2 of the License, or (at your option) any later version. |
| - |
| - This library is distributed in the hope that it will be useful, |
| - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| - Library General Public License for more details. |
| - |
| - You should have received a copy of the GNU Library General Public License |
| - along with this library; see the file COPYING.LIB. If not, write to |
| - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| - Boston, MA 02110-1301, USA. |
| -*/ |
| - |
| -#ifndef ImageResource_h |
| -#define ImageResource_h |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef ImageResourceContent_h |
| +#define ImageResourceContent_h |
| #include "core/CoreExport.h" |
| -#include "core/fetch/MultipartImageResourceParser.h" |
| -#include "core/fetch/Resource.h" |
| +#include "core/fetch/ResourceStatus.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 "platform/network/ResourceLoadPriority.h" |
| +#include "platform/weborigin/KURL.h" |
| +#include "wtf/HashCountedSet.h" |
| #include "wtf/HashMap.h" |
| #include <memory> |
| namespace blink { |
| class FetchRequest; |
| +class ImageResourceInfo; |
| class ImageResourceObserver; |
| -class MemoryCache; |
| -class ResourceClient; |
| +class ResourceError; |
| class ResourceFetcher; |
| +class ResourceResponse; |
| class SecurityOrigin; |
| -// ImageResource class represents an image type resource. |
| -// |
| -// As for the lifetimes of 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); |
| +// ImageResourceContent is a container that holds fetch result of |
| +// an ImageResource in a decoded form. |
| +// Classes that use the fetched images |
| +// should hold onto this class and/or inherit ImageResourceObserver, |
| +// instead of holding onto ImageResource or inheriting ResourceClient. |
| +// https://docs.google.com/document/d/1O-fB83mrE0B_V8gzXNqHgmRLCvstTB4MMi3RnVLr8bE/edit?usp=sharing |
| +// TODO(hiroshige): Make ImageResourceContent ResourceClient and remove the |
| +// word 'observer' from ImageResource. |
| +// TODO(hiroshige): Rename local variables of type ImageResourceContent to |
| +// e.g. |imageContent|. Currently they have Resource-like names. |
| +class CORE_EXPORT ImageResourceContent final |
| + : public GarbageCollectedFinalized<ImageResourceContent>, |
| + public ImageObserver { |
| + USING_GARBAGE_COLLECTED_MIXIN(ImageResourceContent); |
| public: |
| - using ClientType = ResourceClient; |
| - |
| - static ImageResource* fetch(FetchRequest&, ResourceFetcher*); |
| - |
| - static ImageResource* create(blink::Image* image) { |
| - return new ImageResource(image, ResourceLoaderOptions()); |
| + static ImageResourceContent* create( |
| + PassRefPtr<blink::Image> image = nullptr) { |
| + return new ImageResourceContent(std::move(image)); |
| } |
| + static ImageResourceContent* fetch(FetchRequest&, ResourceFetcher*); |
| - static ImageResource* create(const ResourceRequest& request) { |
| - return new ImageResource(request, ResourceLoaderOptions(), false); |
| - } |
| - |
| - ~ImageResource() override; |
| - |
| - blink::Image* |
| - getImage(); // Returns the nullImage() if the image is not available yet. |
| + // Returns the nullImage() if the image is not available yet. |
| + blink::Image* getImage() const; |
|
kinuko
2016/12/09 10:42:24
ditto, avoid returning non-const ptr from const me
hiroshige
2016/12/11 19:17:02
I found ImageResource already have potentials for
|
| 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; |
| - } |
| + float devicePixelRatioHeaderValue() const; |
| + bool hasDevicePixelRatioHeaderValue() const; |
| enum SizeType { |
| // Report the intrinsic size. |
| @@ -104,129 +80,79 @@ class CORE_EXPORT ImageResource final |
| float multiplier, |
| SizeType = IntrinsicSize); |
| - bool isAccessAllowed(SecurityOrigin*); |
| - |
| void updateImageAnimationPolicy(); |
| - enum class ReloadCachePolicy { |
| - UseExistingPolicy = 0, // Don't modify the request's cache policy. |
| - BypassCache, // Modify the request so that the reload bypasses the cache. |
| - }; |
| - |
| - // If this ImageResource has the Lo-Fi response headers or is a placeholder, |
| - // reload the full original image with the Lo-Fi state set to off and |
| - // optionally bypassing the cache. |
| - void reloadIfLoFiOrPlaceholder( |
| - ResourceFetcher*, |
| - ReloadCachePolicy = ReloadCachePolicy::BypassCache); |
| - |
| - void didAddClient(ResourceClient*) override; |
| - |
| void addObserver(ImageResourceObserver*); |
| void removeObserver(ImageResourceObserver*); |
| - ResourcePriority priorityFromObservers() override; |
| + DECLARE_TRACE(); |
| - void allClientsAndObserversRemoved() override; |
| + // Redirecting methods to Resource. |
| + const KURL& url() const; |
| + bool isAccessAllowed(SecurityOrigin*) const; |
| + const ResourceResponse& response() const; |
| + bool isLoaded() const; |
| + bool isLoading() const; |
| + bool errorOccurred() const; |
| + bool loadFailedOrCanceled() const; |
| + ResourceStatus getStatus() const; |
| + const ResourceError& resourceError() const; |
| - PassRefPtr<const SharedBuffer> resourceBuffer() const override; |
| - void appendData(const char*, size_t) override; |
| - void error(const ResourceError&) override; |
| - void responseReceived(const ResourceResponse&, |
| - std::unique_ptr<WebDataConsumerHandle>) override; |
| - void finish(double finishTime = 0.0) override; |
| + // For FrameSerializer. |
| + bool hasCacheControlNoStoreHeader() const; |
| - // For compatibility, images keep loading even if there are HTTP errors. |
| - bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; } |
| - |
| - 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; |
| - |
| - // Used by tests. |
| - bool isPlaceholder() const { return m_isPlaceholder; } |
| - |
| - bool shouldReloadBrokenPlaceholder() const { |
| - return m_isPlaceholder && willPaintBrokenImage(); |
| - } |
| + void emulateLoadStartedForInspector(ResourceFetcher*, |
| + const KURL&, |
| + const AtomicString& initiatorName); |
| void setNotRefetchableDataFromDiskCache() { |
| m_isRefetchableDataFromDiskCache = false; |
| } |
| - DECLARE_VIRTUAL_TRACE(); |
| + // For ImageResource only. |
| + void setImageResourceInfo(ImageResourceInfo*); |
| + enum ClearImageOption { ClearExistingImage, KeepExistingImage }; |
| + void updateImage(PassRefPtr<SharedBuffer>, |
| + ClearImageOption, |
| + bool allDataReceived); |
| + enum NotifyFinishOption { ShouldNotifyFinish, DoNotNotifyFinish }; |
| + void clearImage(); |
| + void clearImageAndNotifyObservers(NotifyFinishOption); |
| + ResourcePriority priorityFromObservers() const; |
| + void destroyDecodedData(); |
| + bool hasObservers() const { |
| + return !m_observers.isEmpty() || !m_finishedObservers.isEmpty(); |
| + } |
| + bool isSizeAvailable() const { |
| + return m_sizeAvailable == Image::SizeAvailable; |
| + } |
| + bool isRefetchableDataFromDiskCache() const { |
| + return m_isRefetchableDataFromDiskCache; |
| + } |
| + void doResetAnimation(); |
| private: |
| - explicit ImageResource(blink::Image*, const ResourceLoaderOptions&); |
| - |
| - enum class MultipartParsingState : uint8_t { |
| - WaitingForFirstPart, |
| - ParsingFirstPart, |
| - FinishedParsingFirstPart, |
| - }; |
| + ImageResourceContent(PassRefPtr<blink::Image> = nullptr); |
|
kinuko
2016/12/09 10:42:24
explicit
hiroshige
2016/12/11 19:17:02
Done.
|
| - class ImageResourceFactory; |
| - |
| - ImageResource(const ResourceRequest&, |
| - const ResourceLoaderOptions&, |
| - bool isPlaceholder); |
| + // 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; |
| - bool hasClientsOrObservers() const override { |
| - return Resource::hasClientsOrObservers() || !m_observers.isEmpty() || |
| - !m_finishedObservers.isEmpty(); |
| - } |
| - void clear(); |
| + PassRefPtr<Image> createImage(); |
| - 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; |
| + Member<ImageResourceInfo> m_info; |
| - void flushImageIfNeeded(TimerBase*); |
| - |
| - 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. |
| - bool m_isSchedulingReload; |
| - |
| - // Indicates if this ImageResource is either attempting to load a placeholder |
| - // image, or is a (possibly broken) placeholder image. |
| - bool m_isPlaceholder; |
| - |
| - 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 |
| @@ -234,8 +160,6 @@ class CORE_EXPORT ImageResource final |
| bool m_isRefetchableDataFromDiskCache; |
| }; |
| -DEFINE_RESOURCE_TYPE_CASTS(Image); |
| - |
| } // namespace blink |
| #endif |