| 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 31%
|
| copy from third_party/WebKit/Source/core/fetch/ImageResource.h
|
| copy to third_party/WebKit/Source/core/fetch/ImageResourceContent.h
|
| index 2d2b657db0bf936115f91bebc31fa7911502798c..19990226b9ed5326e598906d317abdced4c41c9a 100644
|
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.h
|
| +++ b/third_party/WebKit/Source/core/fetch/ImageResourceContent.h
|
| @@ -1,37 +1,22 @@
|
| -/*
|
| - 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/ImageResourceContentInterface.h"
|
| +#include "core/fetch/ImageResourceInfo.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/HashMap.h"
|
| #include <memory>
|
|
|
| @@ -39,55 +24,41 @@ namespace blink {
|
|
|
| class FetchRequest;
|
| 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 the image-related part of image loading that
|
| +// - Stores decoded data (blink::Image) of ImageResource, and
|
| +// - Handles ImageResourceObserver.
|
| +// https://docs.google.com/document/d/1O-fB83mrE0B_V8gzXNqHgmRLCvstTB4MMi3RnVLr8bE/edit?usp=sharing
|
| +class CORE_EXPORT ImageResourceContent final
|
| + : public GarbageCollectedFinalized<ImageResourceContent>,
|
| + public ImageResourceContentInterface,
|
| + 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.
|
| - bool hasImage() const { return m_image.get(); }
|
| + // Returns the nullImage() if the image is not available yet.
|
| + blink::Image* getImage() const override;
|
| + bool hasImage() const override { 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 +75,77 @@ 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();
|
| +
|
| + // 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;
|
|
|
| - void allClientsAndObserversRemoved() override;
|
| + // For FrameSerializer.
|
| + bool hasCacheControlNoStoreHeader() 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;
|
| + void emulateLoadStartedForInspector(ResourceFetcher*,
|
| + const KURL&,
|
| + const AtomicString& initiatorName);
|
|
|
| - // For compatibility, images keep loading even if there are HTTP errors.
|
| - bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; }
|
| + void setNotRefetchableDataFromDiskCache() {
|
| + m_isRefetchableDataFromDiskCache = false;
|
| + }
|
|
|
| - bool isImage() const override { return true; }
|
| + private:
|
| + ImageResourceContent(PassRefPtr<blink::Image> = nullptr);
|
|
|
| // 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();
|
| + // ImageResourceContentInterface.
|
| + void setImageResourceInfo(ImageResourceInfo*) override;
|
| + void updateImage(PassRefPtr<SharedBuffer>,
|
| + ClearImageOption,
|
| + bool allDataReceived) override;
|
| + ResourcePriority priorityFromObservers() const override;
|
| + void destroyDecodedData() override;
|
| + bool hasObservers() const override {
|
| + return !m_observers.isEmpty() || !m_finishedObservers.isEmpty();
|
| }
|
| -
|
| - void setNotRefetchableDataFromDiskCache() {
|
| - m_isRefetchableDataFromDiskCache = false;
|
| + bool isSizeAvailable() const override {
|
| + return m_sizeAvailable == Image::SizeAvailable;
|
| }
|
| -
|
| - DECLARE_VIRTUAL_TRACE();
|
| -
|
| - private:
|
| - explicit ImageResource(blink::Image*, const ResourceLoaderOptions&);
|
| -
|
| - enum class MultipartParsingState : uint8_t {
|
| - WaitingForFirstPart,
|
| - ParsingFirstPart,
|
| - FinishedParsingFirstPart,
|
| - };
|
| -
|
| - class ImageResourceFactory;
|
| -
|
| - ImageResource(const ResourceRequest&,
|
| - const ResourceLoaderOptions&,
|
| - bool isPlaceholder);
|
| -
|
| - bool hasClientsOrObservers() const override {
|
| - return Resource::hasClientsOrObservers() || !m_observers.isEmpty() ||
|
| - !m_finishedObservers.isEmpty();
|
| + bool isRefetchableDataFromDiskCache() const override {
|
| + return m_isRefetchableDataFromDiskCache;
|
| }
|
| - void clear();
|
| + void doResetAnimation() override;
|
|
|
| - void createImage();
|
| - void updateImage(bool allDataReceived);
|
| - void updateImageAndClearBuffer();
|
| + PassRefPtr<Image> createImage();
|
| 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*);
|
| + Member<ImageResourceInfo> m_info;
|
|
|
| - 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 +153,6 @@ class CORE_EXPORT ImageResource final
|
| bool m_isRefetchableDataFromDiskCache;
|
| };
|
|
|
| -DEFINE_RESOURCE_TYPE_CASTS(Image);
|
| -
|
| } // namespace blink
|
|
|
| #endif
|
|
|