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

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

Issue 2552653002: Explicitly clear the image in the first updateImage() call (Closed)
Patch Set: Rebase 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
Index: third_party/WebKit/Source/core/loader/resource/ImageResource.cpp
diff --git a/third_party/WebKit/Source/core/loader/resource/ImageResource.cpp b/third_party/WebKit/Source/core/loader/resource/ImageResource.cpp
index 57e7a497df221e5ce82cdc64b2340ed6c12d6d9c..beafff04f6fcd1482b844c2e1f6fbbda4fc7d554 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResource.cpp
@@ -239,8 +239,7 @@ void ImageResource::didAddClient(ResourceClient* client) {
void ImageResource::destroyDecodedDataForFailedRevalidation() {
// Clears the image, as we must create a new image for the failed
// revalidation response.
- getContent()->updateImage(nullptr, ImageResourceContent::ClearAndUpdateImage,
- false);
+ updateImage(nullptr, ImageResourceContent::ClearAndUpdateImage, false);
setDecodedSize(0);
}
@@ -285,8 +284,7 @@ void ImageResource::appendData(const char* data, size_t length) {
// Update the image immediately if needed.
if (getContent()->shouldUpdateImageImmediately()) {
- getContent()->updateImage(this->data(), ImageResourceContent::UpdateImage,
- false);
+ updateImage(this->data(), ImageResourceContent::UpdateImage, false);
return;
}
@@ -314,8 +312,7 @@ void ImageResource::flushImageIfNeeded(TimerBase*) {
// to call |updateImage()|.
if (isLoading()) {
m_lastFlushTime = WTF::monotonicallyIncreasingTime();
- getContent()->updateImage(this->data(), ImageResourceContent::UpdateImage,
- false);
+ updateImage(this->data(), ImageResourceContent::UpdateImage, false);
}
}
@@ -340,8 +337,7 @@ void ImageResource::decodeError(bool allDataReceived) {
}
void ImageResource::updateImageAndClearBuffer() {
- getContent()->updateImage(data(), ImageResourceContent::ClearAndUpdateImage,
- true);
+ updateImage(data(), ImageResourceContent::ClearAndUpdateImage, true);
clearData();
}
@@ -351,7 +347,7 @@ void ImageResource::finish(double loadFinishTime) {
if (data())
updateImageAndClearBuffer();
} else {
- getContent()->updateImage(data(), ImageResourceContent::UpdateImage, true);
+ updateImage(data(), ImageResourceContent::UpdateImage, true);
// As encoded image data can be created from m_image (see
// ImageResource::resourceBuffer(), we don't have to keep m_data. Let's
// clear this. As for the lifetimes of m_image and m_data, see this
@@ -369,8 +365,7 @@ void ImageResource::error(const ResourceError& error) {
// is really needed, or remove it otherwise.
setEncodedSize(0);
Resource::error(error);
- getContent()->updateImage(nullptr, ImageResourceContent::ClearImageOnly,
- true);
+ updateImage(nullptr, ImageResourceContent::ClearImageOnly, true);
}
void ImageResource::responseReceived(
@@ -439,8 +434,7 @@ void ImageResource::reloadIfLoFiOrPlaceholderImage(
} else {
clearData();
setEncodedSize(0);
- getContent()->updateImage(nullptr, ImageResourceContent::ClearImageOnly,
- false);
+ updateImage(nullptr, ImageResourceContent::ClearImageOnly, false);
}
setStatus(NotStarted);
@@ -462,6 +456,9 @@ void ImageResource::onePartInMultipartReceived(
return;
}
updateImageAndClearBuffer();
+ // We should create a new image again when the data for the next part arrive,
+ // so reset |m_isUpdateImageCalled| here.
+ m_isUpdateImageCalled = false;
if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) {
m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPart;
@@ -510,4 +507,16 @@ ResourcePriority ImageResource::priorityFromObservers() {
return getContent()->priorityFromObservers();
}
+void ImageResource::updateImage(
+ PassRefPtr<SharedBuffer> sharedBuffer,
+ ImageResourceContent::UpdateImageOption updateImageOption,
+ bool allDataReceived) {
+ if (!m_isUpdateImageCalled &&
+ updateImageOption == ImageResourceContent::UpdateImage)
+ updateImageOption = ImageResourceContent::ClearAndUpdateImage;
+ m_isUpdateImageCalled = true;
+ getContent()->updateImage(std::move(sharedBuffer), updateImageOption,
+ allDataReceived);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698