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

Unified Diff: third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp

Issue 2587503002: Merge clearImage() and clearImageAndNotifyObservers() into updateImage() (Closed)
Patch Set: comment Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResourceContent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp
diff --git a/third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp b/third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp
index 60998017672bdc16522f24c37a891ae6385261d9..2adbbeefea8c30e8fa8de1617991863c7b99fe81 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp
@@ -297,59 +297,69 @@ void ImageResourceContent::clearImage() {
m_sizeAvailable = Image::SizeUnavailable;
}
-void ImageResourceContent::clearImageAndNotifyObservers(
- NotifyFinishOption notifyingFinishOption) {
- clearImage();
- notifyObservers(notifyingFinishOption);
-}
-
void ImageResourceContent::updateImage(PassRefPtr<SharedBuffer> data,
- ClearImageOption clearImageOption,
+ UpdateImageOption updateImageOption,
bool allDataReceived) {
TRACE_EVENT0("blink", "ImageResourceContent::updateImage");
- if (clearImageOption == ImageResourceContent::ClearExistingImage) {
- clearImage();
- }
-
- // Have the image update its data from its internal buffer. It will not do
- // anything now, but will delay decoding until queried for info (like size or
- // specific image frames).
- if (data) {
- if (!m_image)
- m_image = createImage();
- DCHECK(m_image);
- m_sizeAvailable = m_image->setData(std::move(data), allDataReceived);
+ // Clears the existing image, if instructed by |updateImageOption|.
+ switch (updateImageOption) {
+ case ClearAndUpdateImage:
+ case ClearImageAndNotifyObservers:
+ clearImage();
+ break;
+ case UpdateImage:
+ break;
}
- // Go ahead and tell our observers to try to draw if we have either received
- // all the data or the size is known. Each chunk from the network causes
- // observers to repaint, which will force that chunk to decode.
- if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived)
- return;
-
- if (m_info->isPlaceholder() && allDataReceived && m_image &&
- !m_image->isNull()) {
- if (m_sizeAvailable == Image::SizeAvailable) {
- // TODO(sclittle): Show the original image if the response consists of the
- // entire image, such as if the entire image response body is smaller than
- // the requested range.
- IntSize dimensions = m_image->size();
+ // Updates the image, if instructed by |updateImageOption|.
+ switch (updateImageOption) {
+ case ClearImageAndNotifyObservers:
+ DCHECK(!data);
+ break;
- clearImage();
- m_image = PlaceholderImage::create(this, dimensions);
- } else {
- // Clear the image so that it gets treated like a decoding error, since
- // the attempt to build a placeholder image failed.
- clearImage();
- }
- }
+ case UpdateImage:
+ case ClearAndUpdateImage:
+ // Have the image update its data from its internal buffer. It will not do
+ // anything now, but will delay decoding until queried for info (like size
+ // or specific image frames).
+ if (data) {
+ if (!m_image)
+ m_image = createImage();
+ DCHECK(m_image);
+ m_sizeAvailable = m_image->setData(std::move(data), allDataReceived);
+ }
- if (!m_image || m_image->isNull()) {
- clearImage();
- m_info->decodeError(allDataReceived);
+ // Go ahead and tell our observers to try to draw if we have either
+ // received all the data or the size is known. Each chunk from the network
+ // causes observers to repaint, which will force that chunk to decode.
+ if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived)
+ return;
+
+ if (m_info->isPlaceholder() && allDataReceived && m_image &&
+ !m_image->isNull()) {
+ if (m_sizeAvailable == Image::SizeAvailable) {
+ // TODO(sclittle): Show the original image if the response consists of
+ // the entire image, such as if the entire image response body is
+ // smaller than the requested range.
+ IntSize dimensions = m_image->size();
+
+ clearImage();
+ m_image = PlaceholderImage::create(this, dimensions);
+ } else {
+ // Clear the image so that it gets treated like a decoding error,
+ // since the attempt to build a placeholder image failed.
+ clearImage();
+ }
+ }
+ if (!m_image || m_image->isNull()) {
+ clearImage();
+ m_info->decodeError(allDataReceived);
+ }
+ break;
}
+ // Notifies the observers.
// It would be nice to only redraw the decoded band of the image, but with the
// current design (decoding delayed until painting) that seems hard.
notifyObservers(allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish);
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResourceContent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698