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

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 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.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/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 b319b9a30467bbd8e059d14f3a79c237e49171ad..1fb506486e066dd496d197ee22f410a5f320a29f 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,8 @@ void ImageResource::error(const ResourceError& error) {
// is really needed, or remove it otherwise.
setEncodedSize(0);
Resource::error(error);
- getContent()->updateImage(
- nullptr, ImageResourceContent::ClearImageAndNotifyObservers, true);
+ updateImage(nullptr, ImageResourceContent::ClearImageAndNotifyObservers,
+ true);
}
void ImageResource::responseReceived(
@@ -441,8 +437,8 @@ void ImageResource::reloadIfLoFiOrPlaceholderImage(
} else {
clearData();
setEncodedSize(0);
- getContent()->updateImage(
- nullptr, ImageResourceContent::ClearImageAndNotifyObservers, false);
+ updateImage(nullptr, ImageResourceContent::ClearImageAndNotifyObservers,
+ false);
}
setStatus(NotStarted);
@@ -464,6 +460,8 @@ void ImageResource::onePartInMultipartReceived(
return;
}
updateImageAndClearBuffer();
+ // We should create a new image again when the data for the next part arrive.
+ m_shouldEnforceClearImage = true;
if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) {
m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPart;
@@ -512,4 +510,16 @@ ResourcePriority ImageResource::priorityFromObservers() {
return getContent()->priorityFromObservers();
}
+void ImageResource::updateImage(
+ PassRefPtr<SharedBuffer> sharedBuffer,
+ ImageResourceContent::UpdateImageOption updateImageOption,
+ bool allDataReceived) {
+ if (m_shouldEnforceClearImage &&
+ updateImageOption == ImageResourceContent::UpdateImage)
+ updateImageOption = ImageResourceContent::ClearAndUpdateImage;
+ m_shouldEnforceClearImage = false;
+ getContent()->updateImage(std::move(sharedBuffer), updateImageOption,
+ allDataReceived);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698