Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1490)

Unified Diff: third_party/WebKit/Source/core/fetch/ImageResourceContent.h

Issue 2469873002: [ImageResource 4] Split ImageResource into Resource and Image parts (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..15b2bd9841082de580d7905f86cb5420ec7342d1 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.h
+++ b/third_party/WebKit/Source/core/fetch/ImageResourceContent.h
@@ -1,93 +1,62 @@
-/*
- 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"
yhirano 2016/12/05 09:02:03 +wtf/HashCountedSet.h
hiroshige 2016/12/06 09:32:51 Done.
#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 the image-related part of image loading that
kouhei (in TOK) 2016/12/05 07:13:06 ImageResourceContent is a container that holds fet
hiroshige 2016/12/05 09:11:19 Done.
+// - 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 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;
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 +73,78 @@ 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);
+ 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,
- };
-
- class ImageResourceFactory;
+ ImageResourceContent(PassRefPtr<blink::Image> = nullptr);
- ImageResource(const ResourceRequest&,
- const ResourceLoaderOptions&,
- bool isPlaceholder);
-
- bool hasClientsOrObservers() const override {
- return Resource::hasClientsOrObservers() || !m_observers.isEmpty() ||
- !m_finishedObservers.isEmpty();
- }
- void clear();
+ // 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;
- 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;
+ 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 +152,6 @@ class CORE_EXPORT ImageResource final
bool m_isRefetchableDataFromDiskCache;
};
-DEFINE_RESOURCE_TYPE_CASTS(Image);
-
} // namespace blink
#endif

Powered by Google App Engine
This is Rietveld 408576698