OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/fetch/ImageResourceContent.h" | 5 #include "core/fetch/ImageResourceContent.h" |
6 | 6 |
7 #include "core/fetch/ImageResource.h" | 7 #include "core/fetch/ImageResource.h" |
8 #include "core/fetch/ImageResourceInfo.h" | 8 #include "core/fetch/ImageResourceInfo.h" |
9 #include "core/fetch/ImageResourceObserver.h" | 9 #include "core/fetch/ImageResourceObserver.h" |
10 #include "core/svg/graphics/SVGImage.h" | 10 #include "core/svg/graphics/SVGImage.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 public ImageResourceInfo { | 28 public ImageResourceInfo { |
29 USING_GARBAGE_COLLECTED_MIXIN(NullImageResourceInfo); | 29 USING_GARBAGE_COLLECTED_MIXIN(NullImageResourceInfo); |
30 | 30 |
31 public: | 31 public: |
32 NullImageResourceInfo() {} | 32 NullImageResourceInfo() {} |
33 | 33 |
34 DEFINE_INLINE_VIRTUAL_TRACE() { ImageResourceInfo::trace(visitor); } | 34 DEFINE_INLINE_VIRTUAL_TRACE() { ImageResourceInfo::trace(visitor); } |
35 | 35 |
36 private: | 36 private: |
37 const KURL& url() const override { return m_url; } | 37 const KURL& url() const override { return m_url; } |
38 bool isSchedulingReload() const override { return false; } | |
39 bool hasDevicePixelRatioHeaderValue() const override { return false; } | 38 bool hasDevicePixelRatioHeaderValue() const override { return false; } |
40 float devicePixelRatioHeaderValue() const override { return 1.0; } | 39 float devicePixelRatioHeaderValue() const override { return 1.0; } |
41 const ResourceResponse& response() const override { return m_response; } | 40 const ResourceResponse& response() const override { return m_response; } |
42 ResourceStatus getStatus() const override { return ResourceStatus::Cached; } | 41 ResourceStatus getStatus() const override { return ResourceStatus::Cached; } |
43 bool isPlaceholder() const override { return false; } | 42 bool isPlaceholder() const override { return false; } |
44 bool isCacheValidator() const override { return false; } | 43 bool isCacheValidator() const override { return false; } |
45 bool schedulingReloadOrShouldReloadBrokenPlaceholder() const override { | 44 bool shouldReloadBrokenPlaceholder() const override { return false; } |
46 return false; | |
47 } | |
48 bool isAccessAllowed( | 45 bool isAccessAllowed( |
49 SecurityOrigin*, | 46 SecurityOrigin*, |
50 bool doesCurrentFrameHasSingleSecurityOrigin) const override { | 47 bool doesCurrentFrameHasSingleSecurityOrigin) const override { |
51 return true; | 48 return true; |
52 } | 49 } |
53 bool hasCacheControlNoStoreHeader() const override { return false; } | 50 bool hasCacheControlNoStoreHeader() const override { return false; } |
54 const ResourceError& resourceError() const override { return m_error; } | 51 const ResourceError& resourceError() const override { return m_error; } |
| 52 ImageResource* resourceForTest() const override { return nullptr; } |
55 | 53 |
56 const KURL m_url; | 54 const KURL m_url; |
57 const ResourceResponse m_response; | 55 const ResourceResponse m_response; |
58 const ResourceError m_error; | 56 const ResourceError m_error; |
59 }; | 57 }; |
60 | 58 |
61 } // namespace | 59 } // namespace |
62 | 60 |
63 class ResourceFetcher; | 61 class ResourceFetcher; |
64 | 62 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 97 |
100 m_observers.add(observer); | 98 m_observers.add(observer); |
101 | 99 |
102 if (m_info->isCacheValidator()) | 100 if (m_info->isCacheValidator()) |
103 return; | 101 return; |
104 | 102 |
105 if (m_image && !m_image->isNull()) { | 103 if (m_image && !m_image->isNull()) { |
106 observer->imageChanged(this); | 104 observer->imageChanged(this); |
107 } | 105 } |
108 | 106 |
109 if (isLoaded() && m_observers.contains(observer) && | 107 if (isLoaded() && m_observers.contains(observer)) { |
110 !m_info->schedulingReloadOrShouldReloadBrokenPlaceholder()) { | |
111 markObserverFinished(observer); | 108 markObserverFinished(observer); |
112 observer->imageNotifyFinished(this); | 109 observer->imageNotifyFinished(this); |
113 } | 110 } |
114 } | 111 } |
115 | 112 |
116 void ImageResourceContent::removeObserver(ImageResourceObserver* observer) { | 113 void ImageResourceContent::removeObserver(ImageResourceObserver* observer) { |
117 DCHECK(observer); | 114 DCHECK(observer); |
118 | 115 |
119 if (m_observers.contains(observer)) | 116 if (m_observers.contains(observer)) |
120 m_observers.remove(observer); | 117 m_observers.remove(observer); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 NotifyFinishOption notifyingFinishOption, | 238 NotifyFinishOption notifyingFinishOption, |
242 const IntRect* changeRect) { | 239 const IntRect* changeRect) { |
243 for (auto* observer : m_finishedObservers.asVector()) { | 240 for (auto* observer : m_finishedObservers.asVector()) { |
244 if (m_finishedObservers.contains(observer)) | 241 if (m_finishedObservers.contains(observer)) |
245 observer->imageChanged(this, changeRect); | 242 observer->imageChanged(this, changeRect); |
246 } | 243 } |
247 for (auto* observer : m_observers.asVector()) { | 244 for (auto* observer : m_observers.asVector()) { |
248 if (m_observers.contains(observer)) { | 245 if (m_observers.contains(observer)) { |
249 observer->imageChanged(this, changeRect); | 246 observer->imageChanged(this, changeRect); |
250 if (notifyingFinishOption == ShouldNotifyFinish && | 247 if (notifyingFinishOption == ShouldNotifyFinish && |
251 m_observers.contains(observer) && | 248 m_observers.contains(observer)) { |
252 !m_info->schedulingReloadOrShouldReloadBrokenPlaceholder()) { | |
253 markObserverFinished(observer); | 249 markObserverFinished(observer); |
254 observer->imageNotifyFinished(this); | 250 observer->imageNotifyFinished(this); |
255 } | 251 } |
256 } | 252 } |
257 } | 253 } |
258 } | 254 } |
259 | 255 |
260 inline PassRefPtr<Image> ImageResourceContent::createImage() { | 256 inline PassRefPtr<Image> ImageResourceContent::createImage() { |
261 if (m_info->response().mimeType() == "image/svg+xml") | 257 if (m_info->response().mimeType() == "image/svg+xml") |
262 return SVGImage::create(this); | 258 return SVGImage::create(this); |
263 return BitmapImage::create(this); | 259 return BitmapImage::create(this); |
264 } | 260 } |
265 | 261 |
266 inline void ImageResourceContent::clearImage() { | 262 inline void ImageResourceContent::clearImage() { |
267 if (!m_image) | 263 if (!m_image) |
268 return; | 264 return; |
269 int64_t length = m_image->data() ? m_image->data()->size() : 0; | 265 int64_t length = m_image->data() ? m_image->data()->size() : 0; |
270 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); | 266 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); |
271 | 267 |
272 // If our Image has an observer, it's always us so we need to clear the back | 268 // If our Image has an observer, it's always us so we need to clear the back |
273 // pointer before dropping our reference. | 269 // pointer before dropping our reference. |
274 m_image->clearImageObserver(); | 270 m_image->clearImageObserver(); |
275 m_image.clear(); | 271 m_image.clear(); |
276 m_sizeAvailable = Image::SizeUnavailable; | 272 m_sizeAvailable = Image::SizeUnavailable; |
277 } | 273 } |
278 | 274 |
279 void ImageResourceContent::updateImage(PassRefPtr<SharedBuffer> data, | 275 void ImageResourceContent::updateImage(PassRefPtr<SharedBuffer> data, |
280 ClearImageOption clearImageOption, | 276 ClearImageOption clearImageOption, |
281 bool allDataReceived) { | 277 bool allDataReceived, |
| 278 ResourceFetcher* fetcherForReload) { |
282 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); | 279 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); |
283 | 280 |
284 if (clearImageOption == ImageResourceContent::ClearExistingImage) { | 281 if (clearImageOption == ImageResourceContent::ClearExistingImage) { |
285 clearImage(); | 282 clearImage(); |
286 } | 283 } |
287 | 284 |
288 // Have the image update its data from its internal buffer. It will not do | 285 // Have the image update its data from its internal buffer. It will not do |
289 // anything now, but will delay decoding until queried for info (like size or | 286 // anything now, but will delay decoding until queried for info (like size or |
290 // specific image frames). | 287 // specific image frames). |
291 if (data) { | 288 if (data) { |
(...skipping 19 matching lines...) Expand all Loading... |
311 | 308 |
312 clearImage(); | 309 clearImage(); |
313 m_image = PlaceholderImage::create(this, dimensions); | 310 m_image = PlaceholderImage::create(this, dimensions); |
314 } else { | 311 } else { |
315 // Clear the image so that it gets treated like a decoding error, since | 312 // Clear the image so that it gets treated like a decoding error, since |
316 // the attempt to build a placeholder image failed. | 313 // the attempt to build a placeholder image failed. |
317 clearImage(); | 314 clearImage(); |
318 } | 315 } |
319 } | 316 } |
320 | 317 |
| 318 if (m_info->shouldReloadBrokenPlaceholder()) { |
| 319 if (m_info->reloadIfLoFiOrPlaceholder(fetcherForReload)) |
| 320 return; |
| 321 } |
| 322 |
321 if (!m_image || m_image->isNull()) { | 323 if (!m_image || m_image->isNull()) { |
322 clearImage(); | 324 clearImage(); |
323 m_info->decodeError(allDataReceived); | 325 m_info->decodeError(allDataReceived); |
324 } | 326 } |
325 | 327 |
326 // It would be nice to only redraw the decoded band of the image, but with the | 328 // It would be nice to only redraw the decoded band of the image, but with the |
327 // current design (decoding delayed until painting) that seems hard. | 329 // current design (decoding delayed until painting) that seems hard. |
328 notifyObservers(allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish); | 330 notifyObservers(allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish); |
329 } | 331 } |
330 | 332 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 return m_info->hasDevicePixelRatioHeaderValue(); | 441 return m_info->hasDevicePixelRatioHeaderValue(); |
440 } | 442 } |
441 | 443 |
442 const ResourceResponse& ImageResourceContent::response() const { | 444 const ResourceResponse& ImageResourceContent::response() const { |
443 return m_info->response(); | 445 return m_info->response(); |
444 } | 446 } |
445 | 447 |
446 const ResourceError& ImageResourceContent::resourceError() const { | 448 const ResourceError& ImageResourceContent::resourceError() const { |
447 return m_info->resourceError(); | 449 return m_info->resourceError(); |
448 } | 450 } |
| 451 ImageResource* ImageResourceContent::resourceForTest() const { |
| 452 return m_info->resourceForTest(); |
| 453 } |
449 | 454 |
450 } // namespace blink | 455 } // namespace blink |
OLD | NEW |