| 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 #ifndef ImageResourceContent_h | 5 #ifndef ImageResourceContent_h |
| 6 #define ImageResourceContent_h | 6 #define ImageResourceContent_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/fetch/ResourceStatus.h" | 9 #include "core/fetch/ResourceStatus.h" |
| 10 #include "platform/geometry/IntRect.h" | 10 #include "platform/geometry/IntRect.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 bool hasCacheControlNoStoreHeader() const; | 106 bool hasCacheControlNoStoreHeader() const; |
| 107 | 107 |
| 108 void emulateLoadStartedForInspector(ResourceFetcher*, | 108 void emulateLoadStartedForInspector(ResourceFetcher*, |
| 109 const KURL&, | 109 const KURL&, |
| 110 const AtomicString& initiatorName); | 110 const AtomicString& initiatorName); |
| 111 | 111 |
| 112 void setNotRefetchableDataFromDiskCache() { | 112 void setNotRefetchableDataFromDiskCache() { |
| 113 m_isRefetchableDataFromDiskCache = false; | 113 m_isRefetchableDataFromDiskCache = false; |
| 114 } | 114 } |
| 115 | 115 |
| 116 // For ImageResource only. | 116 // The following public methods should be called from ImageResource only. |
| 117 void setImageResourceInfo(ImageResourceInfo*); | 117 |
| 118 enum ClearImageOption { ClearExistingImage, KeepExistingImage }; | 118 // updateImage() is the single control point of image content modification |
| 119 // from ImageResource that all image updates should call. |
| 120 // We clear and/or update images in this single method |
| 121 // (controlled by UpdateImageOption) rather than providing separate methods, |
| 122 // in order to centralize state changes and |
| 123 // not to expose the state inbetween to ImageResource. |
| 124 enum UpdateImageOption { |
| 125 // Updates the image (including placeholder and decode error handling |
| 126 // and notifying observers) if needed. |
| 127 UpdateImage, |
| 128 |
| 129 // Clears the image and then updates the image if needed. |
| 130 ClearAndUpdateImage, |
| 131 |
| 132 // Clears the image and always notifies observers (without updating). |
| 133 ClearImageAndNotifyObservers, |
| 134 }; |
| 119 void updateImage(PassRefPtr<SharedBuffer>, | 135 void updateImage(PassRefPtr<SharedBuffer>, |
| 120 ClearImageOption, | 136 UpdateImageOption, |
| 121 bool allDataReceived); | 137 bool allDataReceived); |
| 122 enum NotifyFinishOption { ShouldNotifyFinish, DoNotNotifyFinish }; | 138 |
| 123 void clearImage(); | |
| 124 void clearImageAndNotifyObservers(NotifyFinishOption); | |
| 125 ResourcePriority priorityFromObservers() const; | |
| 126 void destroyDecodedData(); | 139 void destroyDecodedData(); |
| 127 void doResetAnimation(); | 140 void doResetAnimation(); |
| 141 |
| 142 void setImageResourceInfo(ImageResourceInfo*); |
| 143 |
| 144 ResourcePriority priorityFromObservers() const; |
| 128 PassRefPtr<const SharedBuffer> resourceBuffer() const; | 145 PassRefPtr<const SharedBuffer> resourceBuffer() const; |
| 129 bool shouldUpdateImageImmediately() const; | 146 bool shouldUpdateImageImmediately() const; |
| 130 bool hasObservers() const { | 147 bool hasObservers() const { |
| 131 return !m_observers.isEmpty() || !m_finishedObservers.isEmpty(); | 148 return !m_observers.isEmpty() || !m_finishedObservers.isEmpty(); |
| 132 } | 149 } |
| 133 bool isRefetchableDataFromDiskCache() const { | 150 bool isRefetchableDataFromDiskCache() const { |
| 134 return m_isRefetchableDataFromDiskCache; | 151 return m_isRefetchableDataFromDiskCache; |
| 135 } | 152 } |
| 136 | 153 |
| 137 private: | 154 private: |
| 138 explicit ImageResourceContent(PassRefPtr<blink::Image> = nullptr); | 155 explicit ImageResourceContent(PassRefPtr<blink::Image> = nullptr); |
| 139 | 156 |
| 140 // ImageObserver | 157 // ImageObserver |
| 141 void decodedSizeChangedTo(const blink::Image*, size_t newSize) override; | 158 void decodedSizeChangedTo(const blink::Image*, size_t newSize) override; |
| 142 bool shouldPauseAnimation(const blink::Image*) override; | 159 bool shouldPauseAnimation(const blink::Image*) override; |
| 143 void animationAdvanced(const blink::Image*) override; | 160 void animationAdvanced(const blink::Image*) override; |
| 144 void changedInRect(const blink::Image*, const IntRect&) override; | 161 void changedInRect(const blink::Image*, const IntRect&) override; |
| 145 | 162 |
| 146 PassRefPtr<Image> createImage(); | 163 PassRefPtr<Image> createImage(); |
| 164 void clearImage(); |
| 165 |
| 166 enum NotifyFinishOption { ShouldNotifyFinish, DoNotNotifyFinish }; |
| 147 | 167 |
| 148 // If not null, changeRect is the changed part of the image. | 168 // If not null, changeRect is the changed part of the image. |
| 149 void notifyObservers(NotifyFinishOption, const IntRect* changeRect = nullptr); | 169 void notifyObservers(NotifyFinishOption, const IntRect* changeRect = nullptr); |
| 150 void markObserverFinished(ImageResourceObserver*); | 170 void markObserverFinished(ImageResourceObserver*); |
| 151 | 171 |
| 152 Member<ImageResourceInfo> m_info; | 172 Member<ImageResourceInfo> m_info; |
| 153 | 173 |
| 154 RefPtr<blink::Image> m_image; | 174 RefPtr<blink::Image> m_image; |
| 155 | 175 |
| 156 HashCountedSet<ImageResourceObserver*> m_observers; | 176 HashCountedSet<ImageResourceObserver*> m_observers; |
| 157 HashCountedSet<ImageResourceObserver*> m_finishedObservers; | 177 HashCountedSet<ImageResourceObserver*> m_finishedObservers; |
| 158 | 178 |
| 159 Image::SizeAvailability m_sizeAvailable = Image::SizeUnavailable; | 179 Image::SizeAvailability m_sizeAvailable = Image::SizeUnavailable; |
| 160 | 180 |
| 161 // Indicates if this resource's encoded image data can be purged and refetched | 181 // Indicates if this resource's encoded image data can be purged and refetched |
| 162 // from disk cache to save memory usage. See crbug/664437. | 182 // from disk cache to save memory usage. See crbug/664437. |
| 163 bool m_isRefetchableDataFromDiskCache; | 183 bool m_isRefetchableDataFromDiskCache; |
| 164 }; | 184 }; |
| 165 | 185 |
| 166 } // namespace blink | 186 } // namespace blink |
| 167 | 187 |
| 168 #endif | 188 #endif |
| OLD | NEW |