Commit 96250c40 authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

[Lazyload]: Remove Lazy Loaded Image Placeholder Logic

This CL removes lazy load image placeholder logic and tests. It somewhat
accompanies https://crrev.com/c/2125570, and the specific changes are
summarized below:

 - Removes FetchParameters::SetAllowImagePlaceholder, which turns
   eligible image requests into range requests for the first 2k of the
   real image, such as to fetch the placeholder. This was originally
   added in codereview.chromium.org/2423683002.
 - Removes the LAZY_IMAGE_LOAD_DEFERRED previews state, and its
   associated Blink enum value. This was originally added in
   crrev.com/c/1260926, which also stored some lazy loaded image state
   in PlaceHolderImage, and added some placeholder creation logic. This
   CL removes those changes as well.
 - Removes the LAZY_IMAGE_AUTO_RELOAD previews state, and its associated
   Blink enum value. This was originally added in crrev.com/c/1529865,
   which also recorded estimated data savings of Lo-Fi and lazy loaded
   images whose placeholders were first fetched. The Lo-Fi recording
   was removed in crrev.com/c/1652012, and this CL removes the recording
   for lazy loaded images.
 - Removes FetchParameters::ImageRequestOptimization::kAllowPlaceholder,
   and replaces all invocations of CSSImageValue::CacheImage that pass
   in  kAllowPlaceholder, with invocations that pass kNone.
 - [TEST]: Removes TestThatReloadIsStartedThenServeReload, and
   TestThatIsPlaceholderRequestAndServeResponse in the image resource
   tests, and the tests that use them, as they test placeholder/partial
   image fetching, and use FetchParameters::SetAllowImagePlaceholder
   which is going away in this CL.
 - [TEST]: Remove other tests that use
   FetchParameters::SetAllowImagePlaceholder.

Bug: N/A
Change-Id: Ic39036a5a240df483970375a89f35678e0f10866
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137860Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758199}
parent 5907fe6e
...@@ -74,10 +74,6 @@ TEST(SubresourceRedirectURLLoaderThrottleTest, TestMaybeCreateThrottle) { ...@@ -74,10 +74,6 @@ TEST(SubresourceRedirectURLLoaderThrottleTest, TestMaybeCreateThrottle) {
{true, true, network::mojom::RequestDestination::kImage, {true, true, network::mojom::RequestDestination::kImage,
content::PreviewsTypes::SUBRESOURCE_REDIRECT_ON, content::PreviewsTypes::SUBRESOURCE_REDIRECT_ON,
"https://www.test.com/test.jpg", true}, "https://www.test.com/test.jpg", true},
{true, true, network::mojom::RequestDestination::kImage,
content::PreviewsTypes::SUBRESOURCE_REDIRECT_ON |
content::PreviewsTypes::LAZY_IMAGE_AUTO_RELOAD,
"https://www.test.com/test.jpg", true},
// Failure cases // Failure cases
{false, true, network::mojom::RequestDestination::kImage, {false, true, network::mojom::RequestDestination::kImage,
...@@ -157,11 +153,6 @@ TEST(SubresourceRedirectURLLoaderThrottleTest, TestGetSubresourceURL) { ...@@ -157,11 +153,6 @@ TEST(SubresourceRedirectURLLoaderThrottleTest, TestGetSubresourceURL) {
GURL("https://www.test.com/public_img.jpg&private_arg1=foo"), GURL("https://www.test.com/public_img.jpg&private_arg1=foo"),
GURL(), GURL(),
}, },
{
content::PreviewsTypes::LAZY_IMAGE_AUTO_RELOAD,
GURL("https://www.test.com/public_img.jpg"),
GURL(),
},
}; };
blink::WebNetworkStateNotifier::SetSaveDataEnabled(true); blink::WebNetworkStateNotifier::SetSaveDataEnabled(true);
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
......
...@@ -146,12 +146,10 @@ void MetricsRenderFrameObserver::DidStartResponse( ...@@ -146,12 +146,10 @@ void MetricsRenderFrameObserver::DidStartResponse(
// case. There should be a guarantee that DidStartProvisionalLoad be called // case. There should be a guarantee that DidStartProvisionalLoad be called
// before DidStartResponse for the frame request. // before DidStartResponse for the frame request.
provisional_frame_resource_data_use_->DidStartResponse( provisional_frame_resource_data_use_->DidStartResponse(
response_url, request_id, response_head, request_destination, response_url, request_id, response_head, request_destination);
previews_state);
} else if (page_timing_metrics_sender_) { } else if (page_timing_metrics_sender_) {
page_timing_metrics_sender_->DidStartResponse( page_timing_metrics_sender_->DidStartResponse(
response_url, request_id, response_head, request_destination, response_url, request_id, response_head, request_destination);
previews_state);
UpdateResourceMetadata(request_id); UpdateResourceMetadata(request_id);
} }
} }
......
...@@ -13,61 +13,6 @@ ...@@ -13,61 +13,6 @@
namespace page_load_metrics { namespace page_load_metrics {
namespace {
// Returns true when the image is a placeholder for lazy load.
bool IsPartialImageRequest(
network::mojom::RequestDestination request_destination,
content::PreviewsState previews_state) {
if (request_destination != network::mojom::RequestDestination::kImage)
return false;
return previews_state & content::PreviewsTypes::LAZY_IMAGE_LOAD_DEFERRED;
}
// Returns true if this resource was previously fetched as a placeholder.
bool IsImageAutoReload(network::mojom::RequestDestination request_destination,
content::PreviewsState previews_state) {
if (request_destination != network::mojom::RequestDestination::kImage)
return false;
return previews_state & content::PreviewsTypes::LAZY_IMAGE_AUTO_RELOAD;
}
// Returns the ratio of original data size (without applying interventions) to
// actual data use for a placeholder.
double EstimatePartialImageRequestSavings(
const network::mojom::URLResponseHead& response_head) {
if (!response_head.headers)
return 1.0;
if (response_head.headers->GetContentLength() <= 0)
return 1.0;
int64_t first, last, original_length;
if (!response_head.headers->GetContentRangeFor206(&first, &last,
&original_length)) {
return 1.0;
}
if (original_length < response_head.headers->GetContentLength())
return 1.0;
return original_length / response_head.headers->GetContentLength();
}
// Returns a ratio of original data use to actual data use while factoring in
// that this request was previously fetched as a placeholder, and therefore
// recorded savings earlier.
double EstimateAutoReloadImageRequestSavings(
const network::mojom::URLResponseHead& response_head) {
static const double kPlageholderContentInCache = 2048;
// Count the new network usage. For a reloaded placeholder image, 2KB will be
// in cache.
return kPlageholderContentInCache / response_head.headers->GetContentLength();
}
} // namespace
PageResourceDataUse::PageResourceDataUse() PageResourceDataUse::PageResourceDataUse()
: resource_id_(-1), : resource_id_(-1),
data_reduction_proxy_compression_ratio_estimate_(1.0), data_reduction_proxy_compression_ratio_estimate_(1.0),
...@@ -91,21 +36,10 @@ void PageResourceDataUse::DidStartResponse( ...@@ -91,21 +36,10 @@ void PageResourceDataUse::DidStartResponse(
const GURL& response_url, const GURL& response_url,
int resource_id, int resource_id,
const network::mojom::URLResponseHead& response_head, const network::mojom::URLResponseHead& response_head,
network::mojom::RequestDestination request_destination, network::mojom::RequestDestination request_destination) {
content::PreviewsState previews_state) {
resource_id_ = resource_id; resource_id_ = resource_id;
if (IsPartialImageRequest(request_destination, previews_state)) {
data_reduction_proxy_compression_ratio_estimate_ =
EstimatePartialImageRequestSavings(response_head);
} else if (IsImageAutoReload(request_destination, previews_state)) {
data_reduction_proxy_compression_ratio_estimate_ = data_reduction_proxy_compression_ratio_estimate_ =
EstimateAutoReloadImageRequestSavings(response_head); data_reduction_proxy::EstimateCompressionRatioFromHeaders(&response_head);
} else {
data_reduction_proxy_compression_ratio_estimate_ =
data_reduction_proxy::EstimateCompressionRatioFromHeaders(
&response_head);
}
proxy_used_ = !response_head.proxy_server.is_direct(); proxy_used_ = !response_head.proxy_server.is_direct();
mime_type_ = response_head.mime_type; mime_type_ = response_head.mime_type;
......
...@@ -31,8 +31,7 @@ class PageResourceDataUse { ...@@ -31,8 +31,7 @@ class PageResourceDataUse {
void DidStartResponse(const GURL& response_url, void DidStartResponse(const GURL& response_url,
int resource_id, int resource_id,
const network::mojom::URLResponseHead& response_head, const network::mojom::URLResponseHead& response_head,
network::mojom::RequestDestination request_destination, network::mojom::RequestDestination request_destination);
content::PreviewsState previews_state);
// Updates received bytes. // Updates received bytes.
void DidReceiveTransferSizeUpdate(int received_data_length); void DidReceiveTransferSizeUpdate(int received_data_length);
......
...@@ -130,16 +130,14 @@ void PageTimingMetricsSender::DidStartResponse( ...@@ -130,16 +130,14 @@ void PageTimingMetricsSender::DidStartResponse(
const GURL& response_url, const GURL& response_url,
int resource_id, int resource_id,
const network::mojom::URLResponseHead& response_head, const network::mojom::URLResponseHead& response_head,
network::mojom::RequestDestination request_destination, network::mojom::RequestDestination request_destination) {
content::PreviewsState previews_state) {
DCHECK(!base::Contains(page_resource_data_use_, resource_id)); DCHECK(!base::Contains(page_resource_data_use_, resource_id));
auto resource_it = page_resource_data_use_.emplace( auto resource_it = page_resource_data_use_.emplace(
std::piecewise_construct, std::forward_as_tuple(resource_id), std::piecewise_construct, std::forward_as_tuple(resource_id),
std::forward_as_tuple(std::make_unique<PageResourceDataUse>())); std::forward_as_tuple(std::make_unique<PageResourceDataUse>()));
resource_it.first->second->DidStartResponse( resource_it.first->second->DidStartResponse(
response_url, resource_id, response_head, request_destination, response_url, resource_id, response_head, request_destination);
previews_state);
} }
void PageTimingMetricsSender::DidReceiveTransferSizeUpdate( void PageTimingMetricsSender::DidReceiveTransferSizeUpdate(
......
...@@ -59,8 +59,7 @@ class PageTimingMetricsSender { ...@@ -59,8 +59,7 @@ class PageTimingMetricsSender {
void DidStartResponse(const GURL& response_url, void DidStartResponse(const GURL& response_url,
int resource_id, int resource_id,
const network::mojom::URLResponseHead& response_head, const network::mojom::URLResponseHead& response_head,
network::mojom::RequestDestination request_destination, network::mojom::RequestDestination request_destination);
content::PreviewsState previews_state);
void DidReceiveTransferSizeUpdate(int resource_id, int received_data_length); void DidReceiveTransferSizeUpdate(int resource_id, int received_data_length);
void DidCompleteResponse(int resource_id, void DidCompleteResponse(int resource_id,
const network::URLLoaderCompletionStatus& status); const network::URLLoaderCompletionStatus& status);
......
...@@ -30,10 +30,6 @@ STATIC_ASSERT_PREVIEWS_ENUM(OFFLINE_PAGE_ON, ...@@ -30,10 +30,6 @@ STATIC_ASSERT_PREVIEWS_ENUM(OFFLINE_PAGE_ON,
blink::WebURLRequest::kOfflinePageOn); blink::WebURLRequest::kOfflinePageOn);
STATIC_ASSERT_PREVIEWS_ENUM(LITE_PAGE_REDIRECT_ON, STATIC_ASSERT_PREVIEWS_ENUM(LITE_PAGE_REDIRECT_ON,
blink::WebURLRequest::kLitePageRedirectOn); blink::WebURLRequest::kLitePageRedirectOn);
STATIC_ASSERT_PREVIEWS_ENUM(LAZY_IMAGE_LOAD_DEFERRED,
blink::WebURLRequest::kLazyImageLoadDeferred);
STATIC_ASSERT_PREVIEWS_ENUM(LAZY_IMAGE_AUTO_RELOAD,
blink::WebURLRequest::kLazyImageAutoReload);
STATIC_ASSERT_PREVIEWS_ENUM(SUBRESOURCE_REDIRECT_ON, STATIC_ASSERT_PREVIEWS_ENUM(SUBRESOURCE_REDIRECT_ON,
blink::WebURLRequest::kSubresourceRedirectOn); blink::WebURLRequest::kSubresourceRedirectOn);
STATIC_ASSERT_PREVIEWS_ENUM(PREVIEWS_STATE_LAST, STATIC_ASSERT_PREVIEWS_ENUM(PREVIEWS_STATE_LAST,
......
...@@ -39,14 +39,10 @@ enum PreviewsTypes { ...@@ -39,14 +39,10 @@ enum PreviewsTypes {
1 << 8, // Request that an offline page be used if one is stored. 1 << 8, // Request that an offline page be used if one is stored.
LITE_PAGE_REDIRECT_ON = 1 << 9, // Allow the browser to redirect the resource LITE_PAGE_REDIRECT_ON = 1 << 9, // Allow the browser to redirect the resource
// to a Lite Page server. // to a Lite Page server.
LAZY_IMAGE_LOAD_DEFERRED = 1 << 10, // Request the placeholder version of an DEFER_ALL_SCRIPT_ON = 1 << 10, // Request that script execution be deferred
// image that was deferred by lazyload.
LAZY_IMAGE_AUTO_RELOAD = 1 << 11, // Request the full image after previously
// getting a lazy load placeholder.
DEFER_ALL_SCRIPT_ON = 1 << 12, // Request that script execution be deferred
// until parsing completes. // until parsing completes.
SUBRESOURCE_REDIRECT_ON = SUBRESOURCE_REDIRECT_ON =
1 << 13, // Allow the subresources in the page to be redirected to 1 << 11, // Allow the subresources in the page to be redirected to
// serve better optimized resources. Set on subresources. // serve better optimized resources. Set on subresources.
PREVIEWS_STATE_LAST = SUBRESOURCE_REDIRECT_ON PREVIEWS_STATE_LAST = SUBRESOURCE_REDIRECT_ON
}; };
......
...@@ -115,15 +115,10 @@ class WebURLRequest { ...@@ -115,15 +115,10 @@ class WebURLRequest {
kOfflinePageOn = 1 << 8, kOfflinePageOn = 1 << 8,
kLitePageRedirectOn = 1 << 9, // Allow the browser to redirect the resource kLitePageRedirectOn = 1 << 9, // Allow the browser to redirect the resource
// to a Lite Page server. // to a Lite Page server.
kLazyImageLoadDeferred = 1 << 10, // Request the placeholder version of an kDeferAllScriptOn = 1 << 10, // Request that script execution be deferred
// image that was deferred by lazyload.
kLazyImageAutoReload = 1 << 11, // Request the full version of an image
// that was previously fetched as a
// placeholder by lazyload.
kDeferAllScriptOn = 1 << 12, // Request that script execution be deferred
// until parsing completes. // until parsing completes.
kSubresourceRedirectOn = kSubresourceRedirectOn =
1 << 13, // Allow the subresources in the page to be redirected 1 << 11, // Allow the subresources in the page to be redirected
// to serve better optimized resources. // to serve better optimized resources.
kPreviewsStateLast = kSubresourceRedirectOn kPreviewsStateLast = kSubresourceRedirectOn
}; };
......
...@@ -68,7 +68,7 @@ static ImageResourceContent* CachedImageForCSSValue(CSSValue* value, ...@@ -68,7 +68,7 @@ static ImageResourceContent* CachedImageForCSSValue(CSSValue* value,
if (auto* image_value = DynamicTo<CSSImageValue>(value)) { if (auto* image_value = DynamicTo<CSSImageValue>(value)) {
StyleImage* style_image_resource = StyleImage* style_image_resource =
image_value->CacheImage(document, FetchParameters::kAllowPlaceholder); image_value->CacheImage(document, FetchParameters::kNone);
if (!style_image_resource) if (!style_image_resource)
return nullptr; return nullptr;
......
...@@ -212,8 +212,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -212,8 +212,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
->GetLazyLoadImageSetting() == ->GetLazyLoadImageSetting() ==
LocalFrame::LazyLoadImageSetting::kEnabledAutomatic) { LocalFrame::LazyLoadImageSetting::kEnabledAutomatic) {
image_request_behavior = FetchParameters::kDeferImageLoad; image_request_behavior = FetchParameters::kDeferImageLoad;
} else {
image_request_behavior = FetchParameters::kAllowPlaceholder;
} }
} }
StyleImage* new_image = StyleImage* new_image =
...@@ -236,9 +234,9 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -236,9 +234,9 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
StyleImage* image = To<ImageContentData>(content_data)->GetImage(); StyleImage* image = To<ImageContentData>(content_data)->GetImage();
if (image->IsPendingImage()) { if (image->IsPendingImage()) {
To<ImageContentData>(content_data) To<ImageContentData>(content_data)
->SetImage( ->SetImage(LoadPendingImage(style,
LoadPendingImage(style, To<StylePendingImage>(image), To<StylePendingImage>(image),
FetchParameters::kAllowPlaceholder)); FetchParameters::kNone));
} }
} }
} }
...@@ -250,7 +248,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -250,7 +248,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
CursorData& current_cursor = cursor_list->at(i); CursorData& current_cursor = cursor_list->at(i);
if (StyleImage* image = current_cursor.GetImage()) { if (StyleImage* image = current_cursor.GetImage()) {
if (image->IsPendingImage()) { if (image->IsPendingImage()) {
// cursor images shouldn't be replaced with placeholders
current_cursor.SetImage( current_cursor.SetImage(
LoadPendingImage(style, To<StylePendingImage>(image), LoadPendingImage(style, To<StylePendingImage>(image),
FetchParameters::kNone)); FetchParameters::kNone));
...@@ -263,7 +260,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -263,7 +260,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
case CSSPropertyID::kListStyleImage: { case CSSPropertyID::kListStyleImage: {
if (style->ListStyleImage() && if (style->ListStyleImage() &&
style->ListStyleImage()->IsPendingImage()) { style->ListStyleImage()->IsPendingImage()) {
// List style images shouldn't be replaced with placeholders
style->SetListStyleImage(LoadPendingImage( style->SetListStyleImage(LoadPendingImage(
style, To<StylePendingImage>(style->ListStyleImage()), style, To<StylePendingImage>(style->ListStyleImage()),
FetchParameters::kNone)); FetchParameters::kNone));
...@@ -273,7 +269,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -273,7 +269,6 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
case CSSPropertyID::kBorderImageSource: { case CSSPropertyID::kBorderImageSource: {
if (style->BorderImageSource() && if (style->BorderImageSource() &&
style->BorderImageSource()->IsPendingImage()) { style->BorderImageSource()->IsPendingImage()) {
// Border images shouldn't be replaced with placeholders
style->SetBorderImageSource(LoadPendingImage( style->SetBorderImageSource(LoadPendingImage(
style, To<StylePendingImage>(style->BorderImageSource()), style, To<StylePendingImage>(style->BorderImageSource()),
FetchParameters::kNone)); FetchParameters::kNone));
...@@ -287,7 +282,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -287,7 +282,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
mask_image.GetImage()->IsPendingImage()) { mask_image.GetImage()->IsPendingImage()) {
StyleImage* loaded_image = LoadPendingImage( StyleImage* loaded_image = LoadPendingImage(
style, To<StylePendingImage>(mask_image.GetImage()), style, To<StylePendingImage>(mask_image.GetImage()),
FetchParameters::kAllowPlaceholder); FetchParameters::kNone);
reflection->SetMask(NinePieceImage( reflection->SetMask(NinePieceImage(
loaded_image, mask_image.ImageSlices(), mask_image.Fill(), loaded_image, mask_image.ImageSlices(), mask_image.Fill(),
mask_image.BorderSlices(), mask_image.Outset(), mask_image.BorderSlices(), mask_image.Outset(),
...@@ -301,7 +296,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -301,7 +296,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
style->MaskBoxImageSource()->IsPendingImage()) { style->MaskBoxImageSource()->IsPendingImage()) {
style->SetMaskBoxImageSource(LoadPendingImage( style->SetMaskBoxImageSource(LoadPendingImage(
style, To<StylePendingImage>(style->MaskBoxImageSource()), style, To<StylePendingImage>(style->MaskBoxImageSource()),
FetchParameters::kAllowPlaceholder)); FetchParameters::kNone));
} }
break; break;
} }
...@@ -312,8 +307,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -312,8 +307,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
mask_layer->GetImage()->IsPendingImage()) { mask_layer->GetImage()->IsPendingImage()) {
mask_layer->SetImage(LoadPendingImage( mask_layer->SetImage(LoadPendingImage(
style, To<StylePendingImage>(mask_layer->GetImage()), style, To<StylePendingImage>(mask_layer->GetImage()),
FetchParameters::kAllowPlaceholder, FetchParameters::kNone, kCrossOriginAttributeAnonymous));
kCrossOriginAttributeAnonymous));
} }
} }
break; break;
...@@ -323,8 +317,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -323,8 +317,7 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
style->ShapeOutside()->GetImage()->IsPendingImage()) { style->ShapeOutside()->GetImage()->IsPendingImage()) {
style->ShapeOutside()->SetImage(LoadPendingImage( style->ShapeOutside()->SetImage(LoadPendingImage(
style, To<StylePendingImage>(style->ShapeOutside()->GetImage()), style, To<StylePendingImage>(style->ShapeOutside()->GetImage()),
FetchParameters::kAllowPlaceholder, FetchParameters::kNone, kCrossOriginAttributeAnonymous));
kCrossOriginAttributeAnonymous));
} }
break; break;
default: default:
......
...@@ -322,15 +322,6 @@ INSTANTIATE_TEST_SUITE_P(All, ...@@ -322,15 +322,6 @@ INSTANTIATE_TEST_SUITE_P(All,
LazyLoadImagesSimTest, LazyLoadImagesSimTest,
::testing::Bool() /*is_lazyload_image_enabled*/); ::testing::Bool() /*is_lazyload_image_enabled*/);
void ExpectResourceIsFullImage(Resource* resource) {
EXPECT_TRUE(resource);
EXPECT_TRUE(resource->IsLoaded());
EXPECT_FALSE(
resource->GetResourceRequest().HttpHeaderFields().Contains("range"));
EXPECT_EQ(ResourceType::kImage, resource->GetType());
EXPECT_FALSE(ToImageResource(resource)->ShouldShowLazyImagePlaceholder());
}
class ScopedDataSaverSetting { class ScopedDataSaverSetting {
public: public:
explicit ScopedDataSaverSetting(bool is_data_saver_enabled) explicit ScopedDataSaverSetting(bool is_data_saver_enabled)
...@@ -503,8 +494,6 @@ TEST_P(LazyLoadImagesParamsTest, NearViewport) { ...@@ -503,8 +494,6 @@ TEST_P(LazyLoadImagesParamsTest, NearViewport) {
EXPECT_FALSE(ConsoleMessages().Contains("unset onload")); EXPECT_FALSE(ConsoleMessages().Contains("unset onload"));
eager_resource.Complete(full_image); eager_resource.Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/eager.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -523,12 +512,7 @@ TEST_P(LazyLoadImagesParamsTest, NearViewport) { ...@@ -523,12 +512,7 @@ TEST_P(LazyLoadImagesParamsTest, NearViewport) {
EXPECT_FALSE(ConsoleMessages().Contains("unset onload")); EXPECT_FALSE(ConsoleMessages().Contains("unset onload"));
auto_resource->Complete(full_image); auto_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/auto.png")));
unset_resource->Complete(full_image); unset_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/unset.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -544,8 +528,6 @@ TEST_P(LazyLoadImagesParamsTest, NearViewport) { ...@@ -544,8 +528,6 @@ TEST_P(LazyLoadImagesParamsTest, NearViewport) {
EXPECT_TRUE(ConsoleMessages().Contains("unset onload")); EXPECT_TRUE(ConsoleMessages().Contains("unset onload"));
lazy_resource->Complete(full_image); lazy_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/lazy.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -621,8 +603,6 @@ TEST_P(LazyLoadImagesParamsTest, FarFromViewport) { ...@@ -621,8 +603,6 @@ TEST_P(LazyLoadImagesParamsTest, FarFromViewport) {
partial_image.Append(full_image.data(), 2048U); partial_image.Append(full_image.data(), 2048U);
eager_resource.Complete(full_image); eager_resource.Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/eager.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -643,18 +623,11 @@ TEST_P(LazyLoadImagesParamsTest, FarFromViewport) { ...@@ -643,18 +623,11 @@ TEST_P(LazyLoadImagesParamsTest, FarFromViewport) {
if (!RuntimeEnabledFeatures::LazyImageLoadingEnabled()) { if (!RuntimeEnabledFeatures::LazyImageLoadingEnabled()) {
lazy_resource->Complete(full_image); lazy_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/lazy.png")));
} }
if (!IsAutomaticLazyImageLoadingExpected()) { if (!IsAutomaticLazyImageLoadingExpected()) {
auto_resource->Complete(full_image); auto_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/auto.png")));
unset_resource->Complete(full_image); unset_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/unset.png")));
} }
if (lazy_image_loading_feature_status != if (lazy_image_loading_feature_status !=
...@@ -679,20 +652,13 @@ TEST_P(LazyLoadImagesParamsTest, FarFromViewport) { ...@@ -679,20 +652,13 @@ TEST_P(LazyLoadImagesParamsTest, FarFromViewport) {
EXPECT_FALSE(ConsoleMessages().Contains("lazy onload")); EXPECT_FALSE(ConsoleMessages().Contains("lazy onload"));
lazy_resource->Complete(full_image); lazy_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/lazy.png")));
if (IsAutomaticLazyImageLoadingExpected()) { if (IsAutomaticLazyImageLoadingExpected()) {
EXPECT_FALSE(ConsoleMessages().Contains("auto onload")); EXPECT_FALSE(ConsoleMessages().Contains("auto onload"));
EXPECT_FALSE(ConsoleMessages().Contains("unset onload")); EXPECT_FALSE(ConsoleMessages().Contains("unset onload"));
auto_resource->Complete(full_image); auto_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/auto.png")));
unset_resource->Complete(full_image); unset_resource->Complete(full_image);
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/unset.png")));
} }
Compositor().BeginFrame(); Compositor().BeginFrame();
...@@ -813,8 +779,6 @@ class LazyLoadAutomaticImagesTest : public SimTest { ...@@ -813,8 +779,6 @@ class LazyLoadAutomaticImagesTest : public SimTest {
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
full_resource.Complete(ReadTestImage()); full_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
test::RunPendingTasks(); test::RunPendingTasks();
EXPECT_TRUE(ConsoleMessages().Contains("main body onload")); EXPECT_TRUE(ConsoleMessages().Contains("main body onload"));
...@@ -839,8 +803,6 @@ class LazyLoadAutomaticImagesTest : public SimTest { ...@@ -839,8 +803,6 @@ class LazyLoadAutomaticImagesTest : public SimTest {
EXPECT_FALSE(ConsoleMessages().Contains("image onload")); EXPECT_FALSE(ConsoleMessages().Contains("image onload"));
full_resource.Complete(ReadTestImage()); full_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -880,8 +842,6 @@ TEST_F(LazyLoadAutomaticImagesTest, AttributeChangedFromLazyToEager) { ...@@ -880,8 +842,6 @@ TEST_F(LazyLoadAutomaticImagesTest, AttributeChangedFromLazyToEager) {
test::RunPendingTasks(); test::RunPendingTasks();
full_resource.Complete(ReadTestImage()); full_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -911,8 +871,6 @@ TEST_F(LazyLoadAutomaticImagesTest, AttributeChangedFromAutoToEager) { ...@@ -911,8 +871,6 @@ TEST_F(LazyLoadAutomaticImagesTest, AttributeChangedFromAutoToEager) {
test::RunPendingTasks(); test::RunPendingTasks();
full_resource.Complete(ReadTestImage()); full_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -942,8 +900,6 @@ TEST_F(LazyLoadAutomaticImagesTest, AttributeChangedFromUnsetToEager) { ...@@ -942,8 +900,6 @@ TEST_F(LazyLoadAutomaticImagesTest, AttributeChangedFromUnsetToEager) {
test::RunPendingTasks(); test::RunPendingTasks();
full_resource.Complete(ReadTestImage()); full_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -1025,8 +981,6 @@ TEST_F(LazyLoadAutomaticImagesTest, FirstKImagesLoaded) { ...@@ -1025,8 +981,6 @@ TEST_F(LazyLoadAutomaticImagesTest, FirstKImagesLoaded) {
// One image should be loaded fully, even though it is below viewport. // One image should be loaded fully, even though it is below viewport.
img1.Complete(ReadTestImage()); img1.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png?id=1")));
test::RunPendingTasks(); test::RunPendingTasks();
EXPECT_TRUE(ConsoleMessages().Contains("main body onload")); EXPECT_TRUE(ConsoleMessages().Contains("main body onload"));
...@@ -1043,8 +997,6 @@ TEST_F(LazyLoadAutomaticImagesTest, FirstKImagesLoaded) { ...@@ -1043,8 +997,6 @@ TEST_F(LazyLoadAutomaticImagesTest, FirstKImagesLoaded) {
test::RunPendingTasks(); test::RunPendingTasks();
img2.Complete(ReadTestImage()); img2.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png?id=2")));
test::RunPendingTasks(); test::RunPendingTasks();
EXPECT_TRUE(ConsoleMessages().Contains("main body onload")); EXPECT_TRUE(ConsoleMessages().Contains("main body onload"));
...@@ -1080,8 +1032,6 @@ TEST_F(LazyLoadAutomaticImagesTest, JavascriptCreatedImageFarFromViewport) { ...@@ -1080,8 +1032,6 @@ TEST_F(LazyLoadAutomaticImagesTest, JavascriptCreatedImageFarFromViewport) {
EXPECT_FALSE(ConsoleMessages().Contains("my_image onload")); EXPECT_FALSE(ConsoleMessages().Contains("my_image onload"));
image_resource.Complete(ReadTestImage()); image_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -1119,8 +1069,6 @@ TEST_F(LazyLoadAutomaticImagesTest, JavascriptCreatedImageAddedAfterLoad) { ...@@ -1119,8 +1069,6 @@ TEST_F(LazyLoadAutomaticImagesTest, JavascriptCreatedImageAddedAfterLoad) {
EXPECT_FALSE(ConsoleMessages().Contains("my_image onload")); EXPECT_FALSE(ConsoleMessages().Contains("my_image onload"));
image_resource.Complete(ReadTestImage()); image_resource.Complete(ReadTestImage());
ExpectResourceIsFullImage(GetDocument().Fetcher()->CachedResource(
KURL("https://example.com/image.png")));
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -1203,21 +1151,9 @@ TEST_F(LazyLoadAutomaticImagesTest, ImageInsideLazyLoadedFrame) { ...@@ -1203,21 +1151,9 @@ TEST_F(LazyLoadAutomaticImagesTest, ImageInsideLazyLoadedFrame) {
Vector<char> partial_image; Vector<char> partial_image;
partial_image.Append(full_image.data(), 2048U); partial_image.Append(full_image.data(), 2048U);
Document* child_frame_document =
To<HTMLIFrameElement>(GetDocument().getElementById("child_frame"))
->contentDocument();
eager_resource.Complete(full_image); eager_resource.Complete(full_image);
ExpectResourceIsFullImage(child_frame_document->Fetcher()->CachedResource(
KURL("https://example.com/eager.png")));
auto_resource.Complete(full_image); auto_resource.Complete(full_image);
ExpectResourceIsFullImage(child_frame_document->Fetcher()->CachedResource(
KURL("https://example.com/auto.png")));
unset_resource.Complete(full_image); unset_resource.Complete(full_image);
ExpectResourceIsFullImage(child_frame_document->Fetcher()->CachedResource(
KURL("https://example.com/unset.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
...@@ -1241,8 +1177,6 @@ TEST_F(LazyLoadAutomaticImagesTest, ImageInsideLazyLoadedFrame) { ...@@ -1241,8 +1177,6 @@ TEST_F(LazyLoadAutomaticImagesTest, ImageInsideLazyLoadedFrame) {
test::RunPendingTasks(); test::RunPendingTasks();
lazy_resource.Complete(full_image); lazy_resource.Complete(full_image);
ExpectResourceIsFullImage(child_frame_document->Fetcher()->CachedResource(
KURL("https://example.com/lazy.png")));
Compositor().BeginFrame(); Compositor().BeginFrame();
test::RunPendingTasks(); test::RunPendingTasks();
......
...@@ -1810,7 +1810,6 @@ void DocumentLoader::ReportPreviewsIntervention() const { ...@@ -1810,7 +1810,6 @@ void DocumentLoader::ReportPreviewsIntervention() const {
// Verify that certain types are not on main frame requests. // Verify that certain types are not on main frame requests.
DCHECK_NE(WebURLRequest::kClientLoFiAutoReload, previews_state_); DCHECK_NE(WebURLRequest::kClientLoFiAutoReload, previews_state_);
DCHECK_NE(WebURLRequest::kLazyImageLoadDeferred, previews_state_);
DCHECK_NE(WebURLRequest::kSubresourceRedirectOn, previews_state_); DCHECK_NE(WebURLRequest::kSubresourceRedirectOn, previews_state_);
static_assert(WebURLRequest::kPreviewsStateLast == static_assert(WebURLRequest::kPreviewsStateLast ==
......
...@@ -448,10 +448,6 @@ void FrameFetchContext::PrepareRequest( ...@@ -448,10 +448,6 @@ void FrameFetchContext::PrepareRequest(
if (request.GetPreviewsState() == WebURLRequest::kPreviewsUnspecified) { if (request.GetPreviewsState() == WebURLRequest::kPreviewsUnspecified) {
WebURLRequest::PreviewsState request_previews_state = WebURLRequest::PreviewsState request_previews_state =
document_loader->GetPreviewsState(); document_loader->GetPreviewsState();
// The decision of whether or not to enable Client Lo-Fi is made earlier
// in the request lifetime, in LocalFrame::MaybeAllowImagePlaceholder(),
// so don't add the Client Lo-Fi bit to the request here.
request_previews_state &= ~(WebURLRequest::kLazyImageLoadDeferred);
if (request_previews_state == WebURLRequest::kPreviewsUnspecified) if (request_previews_state == WebURLRequest::kPreviewsUnspecified)
request_previews_state = WebURLRequest::kPreviewsOff; request_previews_state = WebURLRequest::kPreviewsOff;
request.SetPreviewsState(request_previews_state); request.SetPreviewsState(request_previews_state);
......
...@@ -97,9 +97,6 @@ class ImageResource::ImageResourceInfoImpl final ...@@ -97,9 +97,6 @@ class ImageResource::ImageResourceInfoImpl final
bool ShouldShowPlaceholder() const override { bool ShouldShowPlaceholder() const override {
return resource_->ShouldShowPlaceholder(); return resource_->ShouldShowPlaceholder();
} }
bool ShouldShowLazyImagePlaceholder() const override {
return resource_->ShouldShowLazyImagePlaceholder();
}
bool IsCacheValidator() const override { bool IsCacheValidator() const override {
return resource_->IsCacheValidator(); return resource_->IsCacheValidator();
} }
...@@ -157,21 +154,14 @@ class ImageResource::ImageResourceFactory : public NonTextResourceFactory { ...@@ -157,21 +154,14 @@ class ImageResource::ImageResourceFactory : public NonTextResourceFactory {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
explicit ImageResourceFactory(const FetchParameters& fetch_params) explicit ImageResourceFactory()
: NonTextResourceFactory(ResourceType::kImage), : NonTextResourceFactory(ResourceType::kImage) {}
fetch_params_(&fetch_params) {}
Resource* Create(const ResourceRequest& request, Resource* Create(const ResourceRequest& request,
const ResourceLoaderOptions& options) const override { const ResourceLoaderOptions& options) const override {
return MakeGarbageCollected<ImageResource>( return MakeGarbageCollected<ImageResource>(
request, options, ImageResourceContent::CreateNotStarted(), request, options, ImageResourceContent::CreateNotStarted());
fetch_params_->GetImageRequestBehavior() ==
FetchParameters::kAllowPlaceholder);
} }
private:
// Weak, unowned pointer. Must outlive |this|.
const FetchParameters* fetch_params_;
}; };
ImageResource* ImageResource::Fetch(FetchParameters& params, ImageResource* ImageResource::Fetch(FetchParameters& params,
...@@ -183,7 +173,7 @@ ImageResource* ImageResource::Fetch(FetchParameters& params, ...@@ -183,7 +173,7 @@ ImageResource* ImageResource::Fetch(FetchParameters& params,
} }
ImageResource* resource = ToImageResource( ImageResource* resource = ToImageResource(
fetcher->RequestResource(params, ImageResourceFactory(params), nullptr)); fetcher->RequestResource(params, ImageResourceFactory(), nullptr));
// If the fetch originated from user agent CSS we should mark it as a user // If the fetch originated from user agent CSS we should mark it as a user
// agent resource. // agent resource.
...@@ -197,8 +187,7 @@ Resource::MatchStatus ImageResource::CanReuse( ...@@ -197,8 +187,7 @@ Resource::MatchStatus ImageResource::CanReuse(
const FetchParameters& params) const { const FetchParameters& params) const {
// If the image is a placeholder, but this fetch doesn't allow a // If the image is a placeholder, but this fetch doesn't allow a
// placeholder, then do not reuse this resource. // placeholder, then do not reuse this resource.
if (params.GetImageRequestBehavior() != FetchParameters::kAllowPlaceholder && if (placeholder_option_ != PlaceholderOption::kDoNotReloadPlaceholder) {
placeholder_option_ != PlaceholderOption::kDoNotReloadPlaceholder) {
return MatchStatus::kImagePlaceholder; return MatchStatus::kImagePlaceholder;
} }
...@@ -218,7 +207,7 @@ bool ImageResource::CanUseCacheValidator() const { ...@@ -218,7 +207,7 @@ bool ImageResource::CanUseCacheValidator() const {
ImageResource* ImageResource::Create(const ResourceRequest& request) { ImageResource* ImageResource::Create(const ResourceRequest& request) {
ResourceLoaderOptions options; ResourceLoaderOptions options;
return MakeGarbageCollected<ImageResource>( return MakeGarbageCollected<ImageResource>(
request, options, ImageResourceContent::CreateNotStarted(), false); request, options, ImageResourceContent::CreateNotStarted());
} }
ImageResource* ImageResource::CreateForTest(const KURL& url) { ImageResource* ImageResource::CreateForTest(const KURL& url) {
...@@ -236,14 +225,11 @@ ImageResource* ImageResource::CreateForTest(const KURL& url) { ...@@ -236,14 +225,11 @@ ImageResource* ImageResource::CreateForTest(const KURL& url) {
ImageResource::ImageResource(const ResourceRequest& resource_request, ImageResource::ImageResource(const ResourceRequest& resource_request,
const ResourceLoaderOptions& options, const ResourceLoaderOptions& options,
ImageResourceContent* content, ImageResourceContent* content)
bool is_placeholder)
: Resource(resource_request, ResourceType::kImage, options), : Resource(resource_request, ResourceType::kImage, options),
content_(content), content_(content),
is_scheduling_reload_(false), is_scheduling_reload_(false),
placeholder_option_( placeholder_option_(PlaceholderOption::kDoNotReloadPlaceholder) {
is_placeholder ? PlaceholderOption::kShowAndReloadPlaceholderAlways
: PlaceholderOption::kDoNotReloadPlaceholder) {
DCHECK(GetContent()); DCHECK(GetContent());
RESOURCE_LOADING_DVLOG(1) RESOURCE_LOADING_DVLOG(1)
<< "MakeGarbageCollected<ImageResource>(ResourceRequest) " << this; << "MakeGarbageCollected<ImageResource>(ResourceRequest) " << this;
...@@ -529,21 +515,6 @@ bool ImageResource::ShouldShowPlaceholder() const { ...@@ -529,21 +515,6 @@ bool ImageResource::ShouldShowPlaceholder() const {
return false; return false;
} }
bool ImageResource::ShouldShowLazyImagePlaceholder() const {
switch (placeholder_option_) {
case PlaceholderOption::kShowAndReloadPlaceholderAlways:
case PlaceholderOption::kShowAndDoNotReloadPlaceholder:
return RuntimeEnabledFeatures::LazyImageLoadingEnabled() &&
(GetResourceRequest().GetPreviewsState() &
WebURLRequest::kLazyImageLoadDeferred);
case PlaceholderOption::kReloadPlaceholderOnDecodeError:
case PlaceholderOption::kDoNotReloadPlaceholder:
return false;
}
NOTREACHED();
return false;
}
bool ImageResource::ShouldReloadBrokenPlaceholder() const { bool ImageResource::ShouldReloadBrokenPlaceholder() const {
switch (placeholder_option_) { switch (placeholder_option_) {
case PlaceholderOption::kShowAndReloadPlaceholderAlways: case PlaceholderOption::kShowAndReloadPlaceholderAlways:
......
...@@ -65,8 +65,7 @@ class CORE_EXPORT ImageResource final ...@@ -65,8 +65,7 @@ class CORE_EXPORT ImageResource final
ImageResource(const ResourceRequest&, ImageResource(const ResourceRequest&,
const ResourceLoaderOptions&, const ResourceLoaderOptions&,
ImageResourceContent*, ImageResourceContent*);
bool is_placeholder);
~ImageResource() override; ~ImageResource() override;
ImageResourceContent* GetContent(); ImageResourceContent* GetContent();
...@@ -101,7 +100,6 @@ class CORE_EXPORT ImageResource final ...@@ -101,7 +100,6 @@ class CORE_EXPORT ImageResource final
void MultipartDataReceived(const char*, size_t) final; void MultipartDataReceived(const char*, size_t) final;
bool ShouldShowPlaceholder() const; bool ShouldShowPlaceholder() const;
bool ShouldShowLazyImagePlaceholder() const;
// If the ImageResource came from a user agent CSS stylesheet then we should // If the ImageResource came from a user agent CSS stylesheet then we should
// flag it so that it can persist beyond navigation. // flag it so that it can persist beyond navigation.
......
...@@ -45,7 +45,6 @@ class NullImageResourceInfo final ...@@ -45,7 +45,6 @@ class NullImageResourceInfo final
bool IsSchedulingReload() const override { return false; } bool IsSchedulingReload() const override { return false; }
const ResourceResponse& GetResponse() const override { return response_; } const ResourceResponse& GetResponse() const override { return response_; }
bool ShouldShowPlaceholder() const override { return false; } bool ShouldShowPlaceholder() const override { return false; }
bool ShouldShowLazyImagePlaceholder() const override { return false; }
bool IsCacheValidator() const override { return false; } bool IsCacheValidator() const override { return false; }
bool SchedulingReloadOrShouldReloadBrokenPlaceholder() const override { bool SchedulingReloadOrShouldReloadBrokenPlaceholder() const override {
return false; return false;
...@@ -121,14 +120,6 @@ ImageResourceContent* ImageResourceContent::CreateLoaded( ...@@ -121,14 +120,6 @@ ImageResourceContent* ImageResourceContent::CreateLoaded(
return content; return content;
} }
ImageResourceContent* ImageResourceContent::CreateLazyImagePlaceholder() {
ImageResourceContent* content = MakeGarbageCollected<ImageResourceContent>();
content->content_status_ = ResourceStatus::kCached;
content->image_ =
PlaceholderImage::CreateForLazyImages(content, IntSize(1, 1));
return content;
}
ImageResourceContent* ImageResourceContent::Fetch(FetchParameters& params, ImageResourceContent* ImageResourceContent::Fetch(FetchParameters& params,
ResourceFetcher* fetcher) { ResourceFetcher* fetcher) {
// TODO(hiroshige): Remove direct references to ImageResource by making // TODO(hiroshige): Remove direct references to ImageResource by making
...@@ -449,21 +440,15 @@ ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage( ...@@ -449,21 +440,15 @@ ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage(
if (size_available_ == Image::kSizeUnavailable && !all_data_received) if (size_available_ == Image::kSizeUnavailable && !all_data_received)
return UpdateImageResult::kNoDecodeError; return UpdateImageResult::kNoDecodeError;
if ((info_->ShouldShowPlaceholder() || if (info_->ShouldShowPlaceholder() && all_data_received) {
info_->ShouldShowLazyImagePlaceholder()) &&
all_data_received) {
if (image_ && !image_->IsNull()) { if (image_ && !image_->IsNull()) {
IntSize dimensions = image_->Size(); IntSize dimensions = image_->Size();
ClearImage(); ClearImage();
if (info_->ShouldShowLazyImagePlaceholder()) {
image_ = PlaceholderImage::CreateForLazyImages(this, dimensions);
} else {
image_ = PlaceholderImage::Create( image_ = PlaceholderImage::Create(
this, dimensions, this, dimensions,
EstimateOriginalImageSizeForPlaceholder(info_->GetResponse())); EstimateOriginalImageSizeForPlaceholder(info_->GetResponse()));
} }
} }
}
// As per spec, zero intrinsic size SVG is a valid image so do not // As per spec, zero intrinsic size SVG is a valid image so do not
// consider such an image as DecodeError. // consider such an image as DecodeError.
......
...@@ -56,8 +56,6 @@ class CORE_EXPORT ImageResourceContent final ...@@ -56,8 +56,6 @@ class CORE_EXPORT ImageResourceContent final
// Creates ImageResourceContent from an already loaded image. // Creates ImageResourceContent from an already loaded image.
static ImageResourceContent* CreateLoaded(scoped_refptr<blink::Image>); static ImageResourceContent* CreateLoaded(scoped_refptr<blink::Image>);
static ImageResourceContent* CreateLazyImagePlaceholder();
static ImageResourceContent* Fetch(FetchParameters&, ResourceFetcher*); static ImageResourceContent* Fetch(FetchParameters&, ResourceFetcher*);
explicit ImageResourceContent(scoped_refptr<blink::Image> = nullptr); explicit ImageResourceContent(scoped_refptr<blink::Image> = nullptr);
......
...@@ -33,7 +33,6 @@ class CORE_EXPORT ImageResourceInfo : public GarbageCollectedMixin { ...@@ -33,7 +33,6 @@ class CORE_EXPORT ImageResourceInfo : public GarbageCollectedMixin {
virtual bool IsSchedulingReload() const = 0; virtual bool IsSchedulingReload() const = 0;
virtual const ResourceResponse& GetResponse() const = 0; virtual const ResourceResponse& GetResponse() const = 0;
virtual bool ShouldShowPlaceholder() const = 0; virtual bool ShouldShowPlaceholder() const = 0;
virtual bool ShouldShowLazyImagePlaceholder() const = 0;
virtual bool IsCacheValidator() const = 0; virtual bool IsCacheValidator() const = 0;
virtual bool SchedulingReloadOrShouldReloadBrokenPlaceholder() const = 0; virtual bool SchedulingReloadOrShouldReloadBrokenPlaceholder() const = 0;
enum DoesCurrentFrameHaveSingleSecurityOrigin { enum DoesCurrentFrameHaveSingleSecurityOrigin {
......
...@@ -207,14 +207,12 @@ PlaceholderImage::SharedFont* PlaceholderImage::SharedFont::g_instance_ = ...@@ -207,14 +207,12 @@ PlaceholderImage::SharedFont* PlaceholderImage::SharedFont::g_instance_ =
PlaceholderImage::PlaceholderImage(ImageObserver* observer, PlaceholderImage::PlaceholderImage(ImageObserver* observer,
const IntSize& size, const IntSize& size,
int64_t original_resource_size, int64_t original_resource_size)
bool is_lazy_image)
: Image(observer), : Image(observer),
size_(size), size_(size),
text_(original_resource_size <= 0 text_(original_resource_size <= 0
? String() ? String()
: FormatOriginalResourceSizeBytes(original_resource_size)), : FormatOriginalResourceSizeBytes(original_resource_size)),
is_lazy_image_(is_lazy_image),
paint_record_content_id_(-1) {} paint_record_content_id_(-1) {}
PlaceholderImage::~PlaceholderImage() = default; PlaceholderImage::~PlaceholderImage() = default;
...@@ -282,10 +280,6 @@ void PlaceholderImage::Draw(cc::PaintCanvas* canvas, ...@@ -282,10 +280,6 @@ void PlaceholderImage::Draw(cc::PaintCanvas* canvas,
static_cast<float>(size_.Height())))) { static_cast<float>(size_.Height())))) {
return; return;
} }
if (is_lazy_image_) {
// Keep the image without any color and text decorations.
return;
}
PaintFlags flags(base_flags); PaintFlags flags(base_flags);
flags.setStyle(PaintFlags::kFill_Style); flags.setStyle(PaintFlags::kFill_Style);
......
...@@ -26,8 +26,7 @@ class GraphicsContext; ...@@ -26,8 +26,7 @@ class GraphicsContext;
class ImageObserver; class ImageObserver;
// A generated placeholder image that shows a translucent gray rectangle with // A generated placeholder image that shows a translucent gray rectangle with
// the full resource size (for example, 100KB) shown in the center. For // the full resource size (for example, 100KB) shown in the center.
// LazyImages the placeholder image will be a plain translucent rectangle.
class PLATFORM_EXPORT PlaceholderImage final : public Image { class PLATFORM_EXPORT PlaceholderImage final : public Image {
public: public:
static scoped_refptr<PlaceholderImage> Create( static scoped_refptr<PlaceholderImage> Create(
...@@ -35,13 +34,7 @@ class PLATFORM_EXPORT PlaceholderImage final : public Image { ...@@ -35,13 +34,7 @@ class PLATFORM_EXPORT PlaceholderImage final : public Image {
const IntSize& size, const IntSize& size,
int64_t original_resource_size) { int64_t original_resource_size) {
return base::AdoptRef( return base::AdoptRef(
new PlaceholderImage(observer, size, original_resource_size, false)); new PlaceholderImage(observer, size, original_resource_size));
}
static scoped_refptr<PlaceholderImage> CreateForLazyImages(
ImageObserver* observer,
const IntSize& size) {
return base::AdoptRef(new PlaceholderImage(observer, size, 0, true));
} }
~PlaceholderImage() override; ~PlaceholderImage() override;
...@@ -70,8 +63,7 @@ class PLATFORM_EXPORT PlaceholderImage final : public Image { ...@@ -70,8 +63,7 @@ class PLATFORM_EXPORT PlaceholderImage final : public Image {
private: private:
PlaceholderImage(ImageObserver*, PlaceholderImage(ImageObserver*,
const IntSize&, const IntSize&,
int64_t original_resource_size, int64_t original_resource_size);
bool is_lazy_image);
bool CurrentFrameHasSingleSecurityOrigin() const override; bool CurrentFrameHasSingleSecurityOrigin() const override;
...@@ -92,9 +84,6 @@ class PLATFORM_EXPORT PlaceholderImage final : public Image { ...@@ -92,9 +84,6 @@ class PLATFORM_EXPORT PlaceholderImage final : public Image {
const IntSize size_; const IntSize size_;
const String text_; const String text_;
// This placeholder image is used for lazyloading of images.
bool is_lazy_image_;
float icon_and_text_scale_factor_ = 1.0f; float icon_and_text_scale_factor_ = 1.0f;
class SharedFont; class SharedFont;
......
...@@ -281,19 +281,6 @@ TEST_F(PlaceholderImageTest, FormatPlaceholderText) { ...@@ -281,19 +281,6 @@ TEST_F(PlaceholderImageTest, FormatPlaceholderText) {
} }
} }
TEST_F(PlaceholderImageTest, DrawLazyImage) {
MockPaintCanvas canvas;
EXPECT_CALL(canvas, drawRect(_, _)).Times(0);
EXPECT_CALL(canvas, drawImageRect(_, _, _, _, _)).Times(0);
EXPECT_CALL(canvas, drawTextBlob(_, _, _, _)).Times(0);
PlaceholderImage::CreateForLazyImages(nullptr, IntSize(800, 600))
->Draw(&canvas, PaintFlags(), FloatRect(0.0f, 0.0f, 800.0f, 600.0f),
FloatRect(0.0f, 0.0f, 800.0f, 600.0f),
kDoNotRespectImageOrientation, Image::kClampImageToSourceRect,
Image::kUnspecifiedDecode);
}
TEST_F(PlaceholderImageTest, DrawNonIntersectingSrcRect) { TEST_F(PlaceholderImageTest, DrawNonIntersectingSrcRect) {
MockPaintCanvas canvas; MockPaintCanvas canvas;
EXPECT_CALL(canvas, drawRect(_, _)).Times(0); EXPECT_CALL(canvas, drawRect(_, _)).Times(0);
......
...@@ -112,40 +112,13 @@ void FetchParameters::MakeSynchronous() { ...@@ -112,40 +112,13 @@ void FetchParameters::MakeSynchronous() {
} }
void FetchParameters::SetLazyImageDeferred() { void FetchParameters::SetLazyImageDeferred() {
resource_request_.SetPreviewsState(resource_request_.GetPreviewsState() |
WebURLRequest::kLazyImageLoadDeferred);
DCHECK_EQ(kNone, image_request_behavior_); DCHECK_EQ(kNone, image_request_behavior_);
image_request_behavior_ = kDeferImageLoad; image_request_behavior_ = kDeferImageLoad;
} }
void FetchParameters::SetLazyImageNonBlocking() { void FetchParameters::SetLazyImageNonBlocking() {
// TODO(domfarolino): [Before merging]: can we DCHECK here.
image_request_behavior_ = kNonBlockingImage; image_request_behavior_ = kNonBlockingImage;
} }
void FetchParameters::SetAllowImagePlaceholder() {
DCHECK_EQ(kNone, image_request_behavior_);
if (!resource_request_.Url().ProtocolIsInHTTPFamily() ||
resource_request_.HttpMethod() != "GET" ||
!resource_request_.HttpHeaderField("range").IsNull()) {
// Make sure that the request isn't marked as using an image preview type,
// since without loading an image placeholder, Client Lo-Fi isn't really
// in use.
resource_request_.SetPreviewsState(resource_request_.GetPreviewsState() &
~WebURLRequest::kLazyImageLoadDeferred);
return;
}
image_request_behavior_ = kAllowPlaceholder;
// Fetch the first few bytes of the image. This number is tuned to both (a)
// likely capture the entire image for small images and (b) likely contain
// the dimensions for larger images.
// TODO(sclittle): Calculate the optimal value for this number.
resource_request_.SetHttpHeaderField("range", "bytes=0-2047");
// TODO(sclittle): Indicate somehow (e.g. through a new request bit) to the
// embedder that it should return the full resource if the entire resource is
// fresh in the cache.
}
} // namespace blink } // namespace blink
...@@ -58,7 +58,6 @@ class PLATFORM_EXPORT FetchParameters { ...@@ -58,7 +58,6 @@ class PLATFORM_EXPORT FetchParameters {
}; };
enum ImageRequestBehavior { enum ImageRequestBehavior {
kNone = 0, // No optimization. kNone = 0, // No optimization.
kAllowPlaceholder, // The image is allowed to be a placeholder.
kDeferImageLoad, // Defer loading the image from network. Full image kDeferImageLoad, // Defer loading the image from network. Full image
// might still load if the request is already-loaded or // might still load if the request is already-loaded or
// in memory cache. // in memory cache.
...@@ -189,12 +188,6 @@ class PLATFORM_EXPORT FetchParameters { ...@@ -189,12 +188,6 @@ class PLATFORM_EXPORT FetchParameters {
void SetLazyImageDeferred(); void SetLazyImageDeferred();
void SetLazyImageNonBlocking(); void SetLazyImageNonBlocking();
// Configures the request to load an image placeholder if the request is
// eligible (e.g. the url's protocol is HTTP, etc.). If this request is
// non-eligible, this method doesn't modify the ResourceRequest. Calling this
// method sets image_request_behavior_ to the appropriate value.
void SetAllowImagePlaceholder();
// See documentation in blink::ResourceRequest. // See documentation in blink::ResourceRequest.
bool IsFromOriginDirtyStyleSheet() const { bool IsFromOriginDirtyStyleSheet() const {
return is_from_origin_dirty_style_sheet_; return is_from_origin_dirty_style_sheet_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment