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

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: Fix known issues 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void changedInRect(const blink::Image*, const IntRect&) override; 118 void changedInRect(const blink::Image*, const IntRect&) override;
110 119
111 protected: 120 protected:
112 bool isSafeToUnlock() const override; 121 bool isSafeToUnlock() const override;
113 void destroyDecodedDataIfPossible() override; 122 void destroyDecodedDataIfPossible() override;
114 void destroyDecodedDataForFailedRevalidation() override; 123 void destroyDecodedDataForFailedRevalidation() override;
115 124
116 private: 125 private:
117 friend class PaintLayerTest; 126 friend class PaintLayerTest;
118 127
128 explicit ImageResource(blink::Image*);
129 ImageResource(const ResourceRequest&, blink::Image*);
130
119 class ImageResourceFactory : public ResourceFactory { 131 class ImageResourceFactory : public ResourceFactory {
120 public: 132 public:
121 ImageResourceFactory() 133 ImageResourceFactory()
122 : ResourceFactory(Resource::Image) { } 134 : ResourceFactory(Resource::Image) { }
123 135
124 Resource* create(const ResourceRequest& request, const String&) const ov erride 136 PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest& request, const String&) const override
125 { 137 {
126 return new ImageResource(request); 138 return adoptRefWillBeNoop(new ImageResource(request));
127 } 139 }
128 }; 140 };
129 ImageResource(const ResourceRequest&); 141 ImageResource(const ResourceRequest&);
130 142
131 void clear(); 143 void clear();
132 144
133 void setCustomAcceptHeader(); 145 void setCustomAcceptHeader();
134 void createImage(); 146 void createImage();
135 void updateImage(bool allDataReceived); 147 void updateImage(bool allDataReceived);
136 void clearImage(); 148 void clearImage();
137 // If not null, changeRect is the changed part of the image. 149 // If not null, changeRect is the changed part of the image.
138 void notifyObservers(const IntRect* changeRect = nullptr); 150 void notifyObservers(const IntRect* changeRect = nullptr);
139 bool loadingMultipartContent() const; 151 bool loadingMultipartContent() const;
140 152
141 float m_devicePixelRatioHeaderValue; 153 float m_devicePixelRatioHeaderValue;
142 154
143 RefPtr<blink::Image> m_image; 155 RefPtr<blink::Image> m_image;
144 bool m_hasDevicePixelRatioHeaderValue; 156 bool m_hasDevicePixelRatioHeaderValue;
145 }; 157 };
146 158
147 DEFINE_RESOURCE_TYPE_CASTS(Image); 159 DEFINE_RESOURCE_TYPE_CASTS(Image);
148 160
149 } // namespace blink 161 } // namespace blink
150 162
151 #endif 163 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698