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

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

Issue 2423683002: Add Blink support for showing image placeholders using range requests. (Closed)
Patch Set: Addressed comments Created 4 years, 2 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 public: 58 public:
59 using ClientType = ResourceClient; 59 using ClientType = ResourceClient;
60 60
61 static ImageResource* fetch(FetchRequest&, ResourceFetcher*); 61 static ImageResource* fetch(FetchRequest&, ResourceFetcher*);
62 62
63 static ImageResource* create(blink::Image* image) { 63 static ImageResource* create(blink::Image* image) {
64 return new ImageResource(image, ResourceLoaderOptions()); 64 return new ImageResource(image, ResourceLoaderOptions());
65 } 65 }
66 66
67 static ImageResource* create(const ResourceRequest& request) { 67 static ImageResource* create(const ResourceRequest& request) {
68 return new ImageResource(request, ResourceLoaderOptions()); 68 return new ImageResource(request, ResourceLoaderOptions(), false);
69 } 69 }
70 70
71 ~ImageResource() override; 71 ~ImageResource() override;
72 72
73 blink::Image* 73 blink::Image*
74 getImage(); // Returns the nullImage() if the image is not available yet. 74 getImage(); // Returns the nullImage() if the image is not available yet.
75 bool hasImage() const { return m_image.get(); } 75 bool hasImage() const { return m_image.get(); }
76 76
77 static std::pair<blink::Image*, float> brokenImage( 77 static std::pair<blink::Image*, float> brokenImage(
78 float deviceScaleFactor); // Returns an image and the image's resolution 78 float deviceScaleFactor); // Returns an image and the image's resolution
(...skipping 22 matching lines...) Expand all
101 // natural size of the image by the zoom. 101 // natural size of the image by the zoom.
102 LayoutSize imageSize( 102 LayoutSize imageSize(
103 RespectImageOrientationEnum shouldRespectImageOrientation, 103 RespectImageOrientationEnum shouldRespectImageOrientation,
104 float multiplier, 104 float multiplier,
105 SizeType = IntrinsicSize); 105 SizeType = IntrinsicSize);
106 106
107 bool isAccessAllowed(SecurityOrigin*); 107 bool isAccessAllowed(SecurityOrigin*);
108 108
109 void updateImageAnimationPolicy(); 109 void updateImageAnimationPolicy();
110 110
111 // If this ImageResource has the Lo-Fi response headers, reload it with the 111 enum class ReloadCachePolicy {
112 // Lo-Fi state set to off and bypassing the cache. 112 UseExistingPolicy = 0, // Don't modify the request's cache policy.
113 void reloadIfLoFi(ResourceFetcher*); 113 BypassCache, // Modify the request so that the reload bypasses the cache.
114 };
115
116 // If this ImageResource has the Lo-Fi response headers or is a placeholder,
117 // reload the full original image with the Lo-Fi state set to off and
118 // optionally bypassing the cache.
119 void reloadIfLoFiOrPlaceholder(
120 ResourceFetcher*,
121 ReloadCachePolicy = ReloadCachePolicy::BypassCache);
114 122
115 void didAddClient(ResourceClient*) override; 123 void didAddClient(ResourceClient*) override;
116 124
117 void addObserver(ImageResourceObserver*); 125 void addObserver(ImageResourceObserver*);
118 void removeObserver(ImageResourceObserver*); 126 void removeObserver(ImageResourceObserver*);
119 127
120 ResourcePriority priorityFromObservers() override; 128 ResourcePriority priorityFromObservers() override;
121 129
122 void allClientsAndObserversRemoved() override; 130 void allClientsAndObserversRemoved() override;
123 131
(...skipping 14 matching lines...) Expand all
138 void didDraw(const blink::Image*) override; 146 void didDraw(const blink::Image*) override;
139 147
140 bool shouldPauseAnimation(const blink::Image*) override; 148 bool shouldPauseAnimation(const blink::Image*) override;
141 void animationAdvanced(const blink::Image*) override; 149 void animationAdvanced(const blink::Image*) override;
142 void changedInRect(const blink::Image*, const IntRect&) override; 150 void changedInRect(const blink::Image*, const IntRect&) override;
143 151
144 // MultipartImageResourceParser::Client 152 // MultipartImageResourceParser::Client
145 void onePartInMultipartReceived(const ResourceResponse&) final; 153 void onePartInMultipartReceived(const ResourceResponse&) final;
146 void multipartDataReceived(const char*, size_t) final; 154 void multipartDataReceived(const char*, size_t) final;
147 155
156 // Used by tests.
157 bool isPlaceholder() const { return m_isPlaceholder; }
158
159 bool shouldReloadBrokenPlaceholder() const {
160 return m_isPlaceholder && willPaintBrokenImage();
161 }
162
148 DECLARE_VIRTUAL_TRACE(); 163 DECLARE_VIRTUAL_TRACE();
149 164
150 private: 165 private:
151 explicit ImageResource(blink::Image*, const ResourceLoaderOptions&); 166 explicit ImageResource(blink::Image*, const ResourceLoaderOptions&);
152 167
153 enum class MultipartParsingState : uint8_t { 168 enum class MultipartParsingState : uint8_t {
154 WaitingForFirstPart, 169 WaitingForFirstPart,
155 ParsingFirstPart, 170 ParsingFirstPart,
156 FinishedParsingFirstPart, 171 FinishedParsingFirstPart,
157 }; 172 };
158 173
159 class ImageResourceFactory : public ResourceFactory { 174 class ImageResourceFactory;
160 public:
161 ImageResourceFactory() : ResourceFactory(Resource::Image) {}
162 175
163 Resource* create(const ResourceRequest& request, 176 ImageResource(const ResourceRequest&,
164 const ResourceLoaderOptions& options, 177 const ResourceLoaderOptions&,
165 const String&) const override { 178 bool isPlaceholder);
166 return new ImageResource(request, options);
167 }
168 };
169 ImageResource(const ResourceRequest&, const ResourceLoaderOptions&);
170 179
171 bool hasClientsOrObservers() const override { 180 bool hasClientsOrObservers() const override {
172 return Resource::hasClientsOrObservers() || !m_observers.isEmpty() || 181 return Resource::hasClientsOrObservers() || !m_observers.isEmpty() ||
173 !m_finishedObservers.isEmpty(); 182 !m_finishedObservers.isEmpty();
174 } 183 }
175 void clear(); 184 void clear();
176 185
177 void createImage(); 186 void createImage();
178 void updateImage(bool allDataReceived); 187 void updateImage(bool allDataReceived);
179 void updateImageAndClearBuffer(); 188 void updateImageAndClearBuffer();
(...skipping 18 matching lines...) Expand all
198 RefPtr<blink::Image> m_image; 207 RefPtr<blink::Image> m_image;
199 MultipartParsingState m_multipartParsingState = 208 MultipartParsingState m_multipartParsingState =
200 MultipartParsingState::WaitingForFirstPart; 209 MultipartParsingState::WaitingForFirstPart;
201 bool m_hasDevicePixelRatioHeaderValue; 210 bool m_hasDevicePixelRatioHeaderValue;
202 HashCountedSet<ImageResourceObserver*> m_observers; 211 HashCountedSet<ImageResourceObserver*> m_observers;
203 HashCountedSet<ImageResourceObserver*> m_finishedObservers; 212 HashCountedSet<ImageResourceObserver*> m_finishedObservers;
204 213
205 // Indicates if the ImageResource is currently scheduling a reload, e.g. 214 // Indicates if the ImageResource is currently scheduling a reload, e.g.
206 // because reloadIfLoFi() was called. 215 // because reloadIfLoFi() was called.
207 bool m_isSchedulingReload; 216 bool m_isSchedulingReload;
217
218 // Indicates if this ImageResource is either attempting to load a placeholder
219 // image, or is a (possibly broken) placeholder image.
220 bool m_isPlaceholder;
208 }; 221 };
209 222
210 DEFINE_RESOURCE_TYPE_CASTS(Image); 223 DEFINE_RESOURCE_TYPE_CASTS(Image);
211 224
212 } // namespace blink 225 } // namespace blink
213 226
214 #endif 227 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698