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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ImageResource.h

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + address review comments Created 4 years, 10 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. 20 Boston, MA 02110-1301, USA.
21 */ 21 */
22 22
23 #ifndef ImageResource_h 23 #ifndef ImageResource_h
24 #define ImageResource_h 24 #define ImageResource_h
25 25
26 #include "core/CoreExport.h" 26 #include "core/CoreExport.h"
27 #include "core/fetch/ResourcePtr.h" 27 #include "core/fetch/Resource.h"
28 #include "platform/geometry/IntRect.h" 28 #include "platform/geometry/IntRect.h"
29 #include "platform/geometry/IntSizeHash.h" 29 #include "platform/geometry/IntSizeHash.h"
30 #include "platform/geometry/LayoutSize.h" 30 #include "platform/geometry/LayoutSize.h"
31 #include "platform/graphics/ImageObserver.h" 31 #include "platform/graphics/ImageObserver.h"
32 #include "platform/graphics/ImageOrientation.h" 32 #include "platform/graphics/ImageOrientation.h"
33 #include "wtf/HashMap.h" 33 #include "wtf/HashMap.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 class ImageResourceClient; 37 class ImageResourceClient;
38 class FetchRequest; 38 class FetchRequest;
39 class ResourceFetcher; 39 class ResourceFetcher;
40 class FloatSize; 40 class FloatSize;
41 class Length; 41 class Length;
42 class MemoryCache; 42 class MemoryCache;
43 class SecurityOrigin; 43 class SecurityOrigin;
44 44
45 class CORE_EXPORT ImageResource final : public Resource, public ImageObserver { 45 class CORE_EXPORT ImageResource final : public Resource, public ImageObserver {
46 friend class MemoryCache; 46 friend class MemoryCache;
47 47
48 public: 48 public:
49 using ClientType = ImageResourceClient; 49 using ClientType = ImageResourceClient;
50 50
51 static ResourcePtr<ImageResource> fetch(FetchRequest&, ResourceFetcher*); 51 static PassRefPtrWillBeRawPtr<ImageResource> fetch(FetchRequest&, ResourceFe tcher*);
52 52
53 ImageResource(blink::Image*); 53 static PassRefPtrWillBeRawPtr<ImageResource> create(blink::Image* image)
54 {
55 return adoptRefWillBeNoop(new ImageResource(image));
56 }
57
54 // Exposed for testing 58 // Exposed for testing
55 ImageResource(const ResourceRequest&, blink::Image*); 59 static PassRefPtrWillBeRawPtr<ImageResource> create(const ResourceRequest& r equest, blink::Image* image)
60 {
61 return adoptRefWillBeNoop(new ImageResource(request, image));
62 }
63
64
56 ~ImageResource() override; 65 ~ImageResource() override;
57 66
58 void load(ResourceFetcher*, const ResourceLoaderOptions&) override; 67 void load(ResourceFetcher*, const ResourceLoaderOptions&) override;
59 68
60 blink::Image* image(); // Returns the nullImage() if the image is not availa ble yet. 69 blink::Image* image(); // Returns the nullImage() if the image is not availa ble yet.
61 bool hasImage() const { return m_image.get(); } 70 bool hasImage() const { return m_image.get(); }
62 71
63 static std::pair<blink::Image*, float> brokenImage(float deviceScaleFactor); // Returns an image and the image's resolution scale factor. 72 static std::pair<blink::Image*, float> brokenImage(float deviceScaleFactor); // Returns an image and the image's resolution scale factor.
64 bool willPaintBrokenImage() const; 73 bool willPaintBrokenImage() const;
65 74
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 bool shouldPauseAnimation(const blink::Image*) override; 120 bool shouldPauseAnimation(const blink::Image*) override;
112 void animationAdvanced(const blink::Image*) override; 121 void animationAdvanced(const blink::Image*) override;
113 void changedInRect(const blink::Image*, const IntRect&) override; 122 void changedInRect(const blink::Image*, const IntRect&) override;
114 123
115 protected: 124 protected:
116 bool isSafeToUnlock() const override; 125 bool isSafeToUnlock() const override;
117 void destroyDecodedDataIfPossible() override; 126 void destroyDecodedDataIfPossible() override;
118 void destroyDecodedDataForFailedRevalidation() override; 127 void destroyDecodedDataForFailedRevalidation() override;
119 128
120 private: 129 private:
130 explicit ImageResource(blink::Image*);
131 ImageResource(const ResourceRequest&, blink::Image*);
132
121 class ImageResourceFactory : public ResourceFactory { 133 class ImageResourceFactory : public ResourceFactory {
122 public: 134 public:
123 ImageResourceFactory() 135 ImageResourceFactory()
124 : ResourceFactory(Resource::Image) { } 136 : ResourceFactory(Resource::Image) { }
125 137
126 Resource* create(const ResourceRequest& request, const String&) const ov erride 138 PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest& request, const String&) const override
127 { 139 {
128 return new ImageResource(request); 140 return adoptRefWillBeNoop(new ImageResource(request));
129 } 141 }
130 }; 142 };
131 ImageResource(const ResourceRequest&); 143 ImageResource(const ResourceRequest&);
132 144
133 void clear(); 145 void clear();
134 146
135 void setCustomAcceptHeader(); 147 void setCustomAcceptHeader();
136 void createImage(); 148 void createImage();
137 void updateImage(bool allDataReceived); 149 void updateImage(bool allDataReceived);
138 void clearImage(); 150 void clearImage();
139 // If not null, changeRect is the changed part of the image. 151 // If not null, changeRect is the changed part of the image.
140 void notifyObservers(const IntRect* changeRect = nullptr); 152 void notifyObservers(const IntRect* changeRect = nullptr);
141 bool loadingMultipartContent() const; 153 bool loadingMultipartContent() const;
142 154
143 float m_devicePixelRatioHeaderValue; 155 float m_devicePixelRatioHeaderValue;
144 156
145 RefPtr<blink::Image> m_image; 157 RefPtr<blink::Image> m_image;
146 bool m_hasDevicePixelRatioHeaderValue; 158 bool m_hasDevicePixelRatioHeaderValue;
147 }; 159 };
148 160
149 DEFINE_RESOURCE_TYPE_CASTS(Image); 161 DEFINE_RESOURCE_TYPE_CASTS(Image);
150 162
151 } // namespace blink 163 } // namespace blink
152 164
153 #endif 165 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/FontResource.cpp ('k') | third_party/WebKit/Source/core/fetch/ImageResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698