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 34733c5f3e65f6f948ddd21b80ecb68ad276c05b..b3f3a4f3f184e47f3be1b0653ba5d48861f8223a 100644 |
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp |
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceContent.cpp |
@@ -39,7 +39,6 @@ class NullImageResourceInfo final |
bool HasDevicePixelRatioHeaderValue() const override { return false; } |
float DevicePixelRatioHeaderValue() const override { return 1.0; } |
const ResourceResponse& GetResponse() const override { return response_; } |
- ResourceStatus GetStatus() const override { return ResourceStatus::kCached; } |
bool ShouldShowPlaceholder() const override { return false; } |
bool IsCacheValidator() const override { return false; } |
bool SchedulingReloadOrShouldReloadBrokenPlaceholder() const override { |
@@ -325,8 +324,83 @@ void ImageResourceContent::ClearImage() { |
size_available_ = Image::kSizeUnavailable; |
} |
+// |new_status| is the status of corresponding ImageResource. |
+void ImageResourceContent::UpdateToLoadedContentStatus( |
+ ResourceStatus new_status) { |
+ // When |ShouldNotifyFinish|, we set content_status_ |
+ // to a loaded ResourceStatus. |
+ |
+ // Checks |new_status| (i.e. Resource's current status). |
+ switch (new_status) { |
+ case ResourceStatus::kCached: |
+ case ResourceStatus::kPending: |
+ // In case of successful load, Resource's status can be |
+ // kCached (e.g. for second part of multipart image) or |
+ // still Pending (e.g. for a non-multipart image). |
+ // Therefore we use kCached as the new state here. |
+ new_status = ResourceStatus::kCached; |
+ break; |
+ |
+ case ResourceStatus::kLoadError: |
+ case ResourceStatus::kDecodeError: |
+ // In case of error, Resource's status is set to an error status |
+ // before UpdateImage() and thus we use the error status as-is. |
+ break; |
+ |
+ case ResourceStatus::kNotStarted: |
+ CHECK(false); |
+ break; |
+ } |
+ |
+ // Checks ImageResourceContent's previous status. |
+ switch (GetContentStatus()) { |
+ case ResourceStatus::kPending: |
+ // A non-multipart image or the first part of a multipart image. |
+ break; |
+ |
+ case ResourceStatus::kCached: |
+ // Second (or later) part of a multipart image. |
+ break; |
+ |
+ case ResourceStatus::kNotStarted: |
+ // Should have updated to kPending via NotifyStartLoad(). |
+ CHECK(false); |
+ break; |
+ |
+ case ResourceStatus::kLoadError: |
+ case ResourceStatus::kDecodeError: |
+ CHECK(false); |
+ break; |
+ } |
+ |
+ // Updates the status. |
+ content_status_ = new_status; |
+} |
+ |
+void ImageResourceContent::NotifyStartLoad() { |
+ // Checks ImageResourceContent's previous status. |
+ switch (GetContentStatus()) { |
+ case ResourceStatus::kPending: |
+ CHECK(false); |
+ break; |
+ |
+ case ResourceStatus::kNotStarted: |
+ // Normal load start. |
+ break; |
+ |
+ case ResourceStatus::kCached: |
+ case ResourceStatus::kLoadError: |
+ case ResourceStatus::kDecodeError: |
+ // Load start due to revalidation/reload. |
+ break; |
+ } |
+ |
+ content_status_ = ResourceStatus::kPending; |
+} |
+ |
ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage( |
PassRefPtr<SharedBuffer> data, |
+ ResourceStatus status, |
UpdateImageOption update_image_option, |
bool all_data_received) { |
TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); |
@@ -336,6 +410,8 @@ ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage( |
AutoReset<bool> scope(&is_update_image_being_called_, true); |
#endif |
+ CHECK_NE(GetContentStatus(), ResourceStatus::kNotStarted); |
+ |
// Clears the existing image, if instructed by |updateImageOption|. |
switch (update_image_option) { |
case kClearAndUpdateImage: |
@@ -388,7 +464,14 @@ ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage( |
// 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(all_data_received ? kShouldNotifyFinish : kDoNotNotifyFinish); |
+ |
+ if (all_data_received) { |
+ UpdateToLoadedContentStatus(status); |
+ NotifyObservers(kShouldNotifyFinish); |
+ } else { |
+ NotifyObservers(kDoNotNotifyFinish); |
+ } |
+ |
return UpdateImageResult::kNoDecodeError; |
} |
@@ -470,29 +553,29 @@ void ImageResourceContent::EmulateLoadStartedForInspector( |
info_->EmulateLoadStartedForInspector(fetcher, url, initiator_name); |
} |
-// TODO(hiroshige): Consider removing the following methods, or stoping |
-// redirecting to ImageResource. |
bool ImageResourceContent::IsLoaded() const { |
- return GetStatus() > ResourceStatus::kPending; |
+ return GetContentStatus() > ResourceStatus::kPending; |
} |
bool ImageResourceContent::IsLoading() const { |
- return GetStatus() == ResourceStatus::kPending; |
+ return GetContentStatus() == ResourceStatus::kPending; |
} |
bool ImageResourceContent::ErrorOccurred() const { |
- return GetStatus() == ResourceStatus::kLoadError || |
- GetStatus() == ResourceStatus::kDecodeError; |
+ return GetContentStatus() == ResourceStatus::kLoadError || |
+ GetContentStatus() == ResourceStatus::kDecodeError; |
} |
bool ImageResourceContent::LoadFailedOrCanceled() const { |
- return GetStatus() == ResourceStatus::kLoadError; |
+ return GetContentStatus() == ResourceStatus::kLoadError; |
} |
-ResourceStatus ImageResourceContent::GetStatus() const { |
- return info_->GetStatus(); |
+ResourceStatus ImageResourceContent::GetContentStatus() const { |
+ return content_status_; |
} |
+// TODO(hiroshige): Consider removing the following methods, or stoping |
+// redirecting to ImageResource. |
const KURL& ImageResourceContent::Url() const { |
return info_->Url(); |
} |