| Index: third_party/WebKit/Source/core/fetch/ImageResource.cpp
|
| diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.cpp b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
|
| index 0a454391815e5909ea81d4e931931a92341c7884..858260812eb7ee24b4e76ae7f7f5b59960771a1e 100644
|
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
|
| +++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
|
| @@ -36,6 +36,7 @@
|
| #include "platform/geometry/IntSize.h"
|
| #include "platform/graphics/BitmapImage.h"
|
| #include "platform/graphics/PlaceholderImage.h"
|
| +#include "platform/network/HTTPParsers.h"
|
| #include "platform/tracing/TraceEvent.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebCachePolicy.h"
|
| @@ -44,6 +45,7 @@
|
| #include "wtf/StdLibExtras.h"
|
| #include "wtf/Vector.h"
|
| #include <memory>
|
| +#include <stdint.h>
|
| #include <v8.h>
|
|
|
| namespace blink {
|
| @@ -461,6 +463,37 @@ inline void ImageResource::clearImage() {
|
| m_sizeAvailable = Image::SizeUnavailable;
|
| }
|
|
|
| +// Determines if |response| likely contains the entire resource for the purposes
|
| +// of determining whether or not to show a placeholder, e.g. if the server
|
| +// responded with a full 200 response or if the full image is smaller than the
|
| +// requested range.
|
| +static bool isEntireResource(const ResourceResponse& response) {
|
| + if (response.httpStatusCode() != 206)
|
| + return true;
|
| +
|
| + int64_t firstBytePosition = -1, lastBytePosition = -1, instanceLength = -1;
|
| + return parseContentRangeHeader(response.httpHeaderField("Content-Range"),
|
| + &firstBytePosition, &lastBytePosition,
|
| + &instanceLength) &&
|
| + firstBytePosition == 0 && lastBytePosition + 1 == instanceLength;
|
| +}
|
| +
|
| +static bool shouldShowFullImageInsteadOfPlaceholder(
|
| + const ResourceResponse& response,
|
| + const Image* image) {
|
| + if (!isEntireResource(response))
|
| + return false;
|
| + if (image && !image->isNull())
|
| + return true;
|
| +
|
| + // Don't treat a complete and broken image as a placeholder if the response
|
| + // code is something other than a 4xx or 5xx error. This is done to prevent
|
| + // reissuing the request in cases like "204 No Content" responses to tracking
|
| + // requests triggered by <img> tags, and <img> tags used to preload non-image
|
| + // resources.
|
| + return response.httpStatusCode() < 400 || response.httpStatusCode() >= 600;
|
| +}
|
| +
|
| void ImageResource::updateImage(bool allDataReceived) {
|
| TRACE_EVENT0("blink", "ImageResource::updateImage");
|
|
|
| @@ -481,18 +514,13 @@ void ImageResource::updateImage(bool allDataReceived) {
|
| if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived)
|
| return;
|
|
|
| - if (m_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.
|
| + if (m_isPlaceholder && allDataReceived) {
|
| + if (shouldShowFullImageInsteadOfPlaceholder(response(), m_image.get())) {
|
| + m_isPlaceholder = false;
|
| + } else if (m_image && !m_image->isNull()) {
|
| 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();
|
| }
|
| }
|
|
|
|
|