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

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

Issue 2710113002: DO NOT SUBMIT really old prototype of sprite recognition for image replacement
Patch Set: Created 3 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.
(...skipping 25 matching lines...) Expand all
36 36
37 namespace blink { 37 namespace blink {
38 38
39 class FetchRequest; 39 class FetchRequest;
40 class FloatSize; 40 class FloatSize;
41 class ImageResourceObserver; 41 class ImageResourceObserver;
42 class MemoryCache; 42 class MemoryCache;
43 class ResourceClient; 43 class ResourceClient;
44 class ResourceFetcher; 44 class ResourceFetcher;
45 class SecurityOrigin; 45 class SecurityOrigin;
46 class SubstituteData;
46 47
47 // ImageResource class represents an image type resource. 48 // ImageResource class represents an image type resource.
48 // 49 //
49 // As for the lifetimes of m_image and m_data, see this document: 50 // As for the lifetimes of m_image and m_data, see this document:
50 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1VsqpxoL7ac iY/edit?usp=sharing 51 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1VsqpxoL7ac iY/edit?usp=sharing
51 class CORE_EXPORT ImageResource final : public Resource, public ImageObserver, p ublic MultipartImageResourceParser::Client { 52 class CORE_EXPORT ImageResource final : public Resource, public ImageObserver, p ublic MultipartImageResourceParser::Client {
52 friend class MemoryCache; 53 friend class MemoryCache;
53 USING_GARBAGE_COLLECTED_MIXIN(ImageResource); 54 USING_GARBAGE_COLLECTED_MIXIN(ImageResource);
54 public: 55 public:
55 using ClientType = ResourceClient; 56 using ClientType = ResourceClient;
56 57
57 static ImageResource* fetch(FetchRequest&, ResourceFetcher*); 58 enum class PlaceholderRequestType {
59 DisallowPlaceholder = 0, // The image being requested must not be a plac eholder.
60 AllowPlaceholder, // The image being requested is allowed to be a placeh older.
61 };
62 static ImageResource* fetch(FetchRequest&, ResourceFetcher*, PlaceholderRequ estType = PlaceholderRequestType::DisallowPlaceholder);
58 63
59 static ImageResource* create(blink::Image* image) 64 static ImageResource* create(blink::Image* image)
60 { 65 {
61 return new ImageResource(image, ResourceLoaderOptions()); 66 return new ImageResource(image, ResourceLoaderOptions());
62 } 67 }
63 68
64 static ImageResource* create(const ResourceRequest& request) 69 static ImageResource* create(const ResourceRequest& request)
65 { 70 {
66 return new ImageResource(request, ResourceLoaderOptions()); 71 return new ImageResource(request, ResourceLoaderOptions(), request, fals e /* isPlaceholder */);
67 } 72 }
68 73
69 ~ImageResource() override; 74 ~ImageResource() override;
70 75
71 blink::Image* getImage(); // Returns the nullImage() if the image is not ava ilable yet. 76 blink::Image* getImage(); // Returns the nullImage() if the image is not ava ilable yet.
72 bool hasImage() const { return m_image.get(); } 77 bool hasImage() const { return m_image.get(); }
73 78
74 static std::pair<blink::Image*, float> brokenImage(float deviceScaleFactor); // Returns an image and the image's resolution scale factor. 79 static std::pair<blink::Image*, float> brokenImage(float deviceScaleFactor); // Returns an image and the image's resolution scale factor.
75 bool willPaintBrokenImage() const; 80 bool willPaintBrokenImage() const;
76 81
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 void didDraw(const blink::Image*) override; 127 void didDraw(const blink::Image*) override;
123 128
124 bool shouldPauseAnimation(const blink::Image*) override; 129 bool shouldPauseAnimation(const blink::Image*) override;
125 void animationAdvanced(const blink::Image*) override; 130 void animationAdvanced(const blink::Image*) override;
126 void changedInRect(const blink::Image*, const IntRect&) override; 131 void changedInRect(const blink::Image*, const IntRect&) override;
127 132
128 // MultipartImageResourceParser::Client 133 // MultipartImageResourceParser::Client
129 void onePartInMultipartReceived(const ResourceResponse&) final; 134 void onePartInMultipartReceived(const ResourceResponse&) final;
130 void multipartDataReceived(const char*, size_t) final; 135 void multipartDataReceived(const char*, size_t) final;
131 136
137 const ResourceRequest& getOriginalResourceRequest() const { return m_origina lRequest; }
138 bool isPlaceholder() const { return m_isPlaceholder; }
139
132 DECLARE_VIRTUAL_TRACE(); 140 DECLARE_VIRTUAL_TRACE();
133 141
134 private: 142 private:
143 class PlaceholderLoaderJob;
144
135 explicit ImageResource(blink::Image*, const ResourceLoaderOptions&); 145 explicit ImageResource(blink::Image*, const ResourceLoaderOptions&);
136 146
137 enum class MultipartParsingState : uint8_t { 147 enum class MultipartParsingState : uint8_t {
138 WaitingForFirstPart, 148 WaitingForFirstPart,
139 ParsingFirstPart, 149 ParsingFirstPart,
140 FinishedParsingFirstPart, 150 FinishedParsingFirstPart,
141 }; 151 };
142 152
143 class ImageResourceFactory : public ResourceFactory { 153 class ImageResourceFactory : public ResourceFactory {
144 public: 154 public:
145 ImageResourceFactory() 155 // Construct a new ImageResourceFactory.
146 : ResourceFactory(Resource::Image) { } 156 ImageResourceFactory(bool isPlaceholder)
157 : ResourceFactory(Resource::Image)
158 , m_isPlaceholder(isPlaceholder)
159 {
160 }
147 161
148 Resource* create(const ResourceRequest& request, const ResourceLoaderOpt ions& options, const String&) const override 162 Resource* create(const ResourceRequest&, const ResourceLoaderOptions&, c onst String&) const override;
149 { 163
150 return new ImageResource(request, options); 164 private:
151 } 165 bool m_isPlaceholder;
152 }; 166 };
153 ImageResource(const ResourceRequest&, const ResourceLoaderOptions&); 167 ImageResource(const ResourceRequest&, const ResourceLoaderOptions&, const Re sourceRequest& originalRequest, bool isPlaceholder);
154 168
155 bool hasClientsOrObservers() const override { return Resource::hasClientsOrO bservers() || !m_observers.isEmpty() || !m_finishedObservers.isEmpty(); } 169 bool hasClientsOrObservers() const override { return Resource::hasClientsOrO bservers() || !m_observers.isEmpty() || !m_finishedObservers.isEmpty(); }
156 void clear(); 170 void clear();
157 171
158 void createImage(); 172 void createImage();
159 void updateImage(bool allDataReceived); 173 void updateImage(bool allDataReceived);
160 void updateImageAndClearBuffer(); 174 void updateImageAndClearBuffer();
161 void clearImage(); 175 void clearImage();
162 // If not null, changeRect is the changed part of the image. 176 // If not null, changeRect is the changed part of the image.
163 void notifyObservers(const IntRect* changeRect = nullptr); 177 void notifyObservers(const IntRect* changeRect = nullptr);
164 178
165 void ensureImage(); 179 void ensureImage();
166 180
167 void checkNotify() override; 181 void checkNotify() override;
168 void notifyObserversInternal(MarkFinishedOption); 182 void notifyObserversInternal(MarkFinishedOption);
169 void markObserverFinished(ImageResourceObserver*); 183 void markObserverFinished(ImageResourceObserver*);
170 184
171 void doResetAnimation(); 185 void doResetAnimation();
172 186
173 void destroyDecodedDataIfPossible() override; 187 void destroyDecodedDataIfPossible() override;
174 void destroyDecodedDataForFailedRevalidation() override; 188 void destroyDecodedDataForFailedRevalidation() override;
175 189
190 void setIsPlaceholder(bool isPlaceholder) { m_isPlaceholder = isPlaceholder; }
191
192 // Reload the image using the given ResourceFetcher and ResourceRequest. If
193 // valid SubstituteData is provided, then the load will complete
194 // synchronously with a 200 response for the given SubstituteData.
195 void reload(ResourceFetcher*, const ResourceRequest&, const SubstituteData&) ;
196
176 float m_devicePixelRatioHeaderValue; 197 float m_devicePixelRatioHeaderValue;
177 198
178 Member<MultipartImageResourceParser> m_multipartParser; 199 Member<MultipartImageResourceParser> m_multipartParser;
179 RefPtr<blink::Image> m_image; 200 RefPtr<blink::Image> m_image;
180 MultipartParsingState m_multipartParsingState = MultipartParsingState::Waiti ngForFirstPart; 201 MultipartParsingState m_multipartParsingState = MultipartParsingState::Waiti ngForFirstPart;
181 bool m_hasDevicePixelRatioHeaderValue; 202 bool m_hasDevicePixelRatioHeaderValue;
182 HashCountedSet<ImageResourceObserver*> m_observers; 203 HashCountedSet<ImageResourceObserver*> m_observers;
183 HashCountedSet<ImageResourceObserver*> m_finishedObservers; 204 HashCountedSet<ImageResourceObserver*> m_finishedObservers;
205
206 // The original ResourceRequest, before making any modifications for
207 // fetching placeholders (e.g. adding Range request headers, etc.). This is
208 // used by the PlaceholderLoaderJob to reset the ResourceRequest to its
209 // original contents while attempting to fetch different states of
210 // placeholder images. This needs to outlive the |m_placeholderLoaderJob| so
211 // that an ImageResource that has finished loading can still be reloaded and
212 // replaced with the full image.
213 ResourceRequest m_originalRequest;
214
215 // Set to true if the image is a placeholder or if the ImageResource is
216 // currently attempting to fetch and construct a placeholder image.
217 bool m_isPlaceholder;
218
219 // The job responsible for managing loading a placeholder image. This will
220 // only be non-null while a placeholder image is being loaded.
221 Member<PlaceholderLoaderJob> m_placeholderLoaderJob;
222
223 // Flag indicating that the ImageResource is currently scheduling a reload
224 // operation. When this flag is set, no observers should be notified of
225 // image completion or marked as finished, to avoid notifying observers that
226 // the image is finished before the loading process is complete, e.g. if a
227 // placeholder or Lo-Fi image is being reloaded before the original load
228 // completes.
229 bool m_isSchedulingReload;
184 }; 230 };
185 231
186 DEFINE_RESOURCE_TYPE_CASTS(Image); 232 DEFINE_RESOURCE_TYPE_CASTS(Image);
187 233
188 } // namespace blink 234 } // namespace blink
189 235
190 #endif 236 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698