Commit 348e1e89 authored by rajendrant's avatar rajendrant Committed by Commit Bot

Fix preload scanner logic to consider lazyload only for images

Add adds param for lazyload experiment,
enable-lazy-load-images-metadata-fetch is likely to be false when
launching

TBR=holte@chromium.org

Change-Id: Iaaa9977a8834f0e6c9cee02adbba90cd37d01aca
Bug: 950645
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1707176
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679791}
parent bc5f6460
...@@ -63,7 +63,8 @@ class DataSaverSiteBreakdownMetricsObserverBrowserTest ...@@ -63,7 +63,8 @@ class DataSaverSiteBreakdownMetricsObserverBrowserTest
void SetUp() override { void SetUp() override {
scoped_feature_list_.InitWithFeaturesAndParameters( scoped_feature_list_.InitWithFeaturesAndParameters(
{{features::kLazyImageLoading, {{features::kLazyImageLoading,
{{"automatic-lazy-load-images-enabled", "true"}}}}, {{"automatic-lazy-load-images-enabled", "true"},
{"enable-lazy-load-images-metadata-fetch", "true"}}}},
{}); {});
InProcessBrowserTest::SetUp(); InProcessBrowserTest::SetUp();
} }
......
...@@ -405,7 +405,7 @@ void SetIndividualRuntimeFeatures( ...@@ -405,7 +405,7 @@ void SetIndividualRuntimeFeatures(
WebRuntimeFeatures::EnableLazyImageLoadingMetadataFetch( WebRuntimeFeatures::EnableLazyImageLoadingMetadataFetch(
base::GetFieldTrialParamByFeatureAsBool( base::GetFieldTrialParamByFeatureAsBool(
features::kLazyImageLoading, "enable-lazy-load-images-metadata-fetch", features::kLazyImageLoading, "enable-lazy-load-images-metadata-fetch",
true)); false));
WebRuntimeFeatures::EnablePictureInPicture( WebRuntimeFeatures::EnablePictureInPicture(
base::FeatureList::IsEnabled(media::kPictureInPicture)); base::FeatureList::IsEnabled(media::kPictureInPicture));
......
...@@ -2818,6 +2818,7 @@ ...@@ -2818,6 +2818,7 @@
"params": { "params": {
"automatic-lazy-load-frames-enabled": "true", "automatic-lazy-load-frames-enabled": "true",
"automatic-lazy-load-images-enabled": "true", "automatic-lazy-load-images-enabled": "true",
"enable-lazy-load-images-metadata-fetch": "false",
"restrict-lazy-load-frames-to-data-saver-only": "true", "restrict-lazy-load-frames-to-data-saver-only": "true",
"restrict-lazy-load-images-to-data-saver-only": "true" "restrict-lazy-load-images-to-data-saver-only": "true"
}, },
......
...@@ -299,49 +299,51 @@ class TokenPreloadScanner::StartTagScanner { ...@@ -299,49 +299,51 @@ class TokenPreloadScanner::StartTagScanner {
document_parameters.lazyload_policy_enforced) { document_parameters.lazyload_policy_enforced) {
effective_loading_attr_value = LoadingAttrValue::kAuto; effective_loading_attr_value = LoadingAttrValue::kAuto;
} }
bool is_lazy_load_image_enabled = false; if (type == ResourceType::kImage) {
switch (effective_loading_attr_value) { bool is_lazy_load_image_enabled = false;
case LoadingAttrValue::kEager: switch (effective_loading_attr_value) {
is_lazy_load_image_enabled = false; case LoadingAttrValue::kEager:
break;
case LoadingAttrValue::kLazy:
is_lazy_load_image_enabled =
document_parameters.lazy_load_image_setting !=
LocalFrame::LazyLoadImageSetting::kDisabled;
break;
case LoadingAttrValue::kAuto:
if ((width_attr_dimension_type_ ==
HTMLImageElement::LazyLoadDimensionType::kAbsoluteSmall &&
height_attr_dimension_type_ ==
HTMLImageElement::LazyLoadDimensionType::kAbsoluteSmall) ||
inline_style_dimensions_type_ ==
HTMLImageElement::LazyLoadDimensionType::kAbsoluteSmall) {
is_lazy_load_image_enabled = false; is_lazy_load_image_enabled = false;
} else { break;
case LoadingAttrValue::kLazy:
is_lazy_load_image_enabled = is_lazy_load_image_enabled =
document_parameters.lazy_load_image_setting == document_parameters.lazy_load_image_setting !=
LocalFrame::LazyLoadImageSetting::kEnabledAutomatic; LocalFrame::LazyLoadImageSetting::kDisabled;
} break;
break; case LoadingAttrValue::kAuto:
} if ((width_attr_dimension_type_ ==
// Do not preload if lazyload is possible but metadata fetch is disabled. HTMLImageElement::LazyLoadDimensionType::kAbsoluteSmall &&
if (is_lazy_load_image_enabled && height_attr_dimension_type_ ==
!RuntimeEnabledFeatures::LazyImageLoadingMetadataFetchEnabled()) { HTMLImageElement::LazyLoadDimensionType::kAbsoluteSmall) ||
return nullptr; inline_style_dimensions_type_ ==
} HTMLImageElement::LazyLoadDimensionType::kAbsoluteSmall) {
// LazyLoad: Do not preload if absolute dimensions are mentioned in width is_lazy_load_image_enabled = false;
// and height attributes or in the inline style, and the dimensions are not } else {
// small enough. is_lazy_load_image_enabled =
if (is_lazy_load_image_enabled && document_parameters.lazy_load_image_setting ==
((width_attr_dimension_type_ == LocalFrame::LazyLoadImageSetting::kEnabledAutomatic;
HTMLImageElement::LazyLoadDimensionType::kAbsoluteNotSmall && }
height_attr_dimension_type_ == break;
HTMLImageElement::LazyLoadDimensionType::kAbsoluteNotSmall) || }
inline_style_dimensions_type_ == // Do not preload if lazyload is possible but metadata fetch is disabled.
HTMLImageElement::LazyLoadDimensionType::kAbsoluteNotSmall)) { if (is_lazy_load_image_enabled &&
return nullptr; !RuntimeEnabledFeatures::LazyImageLoadingMetadataFetchEnabled()) {
return nullptr;
}
// LazyLoad: Do not preload if absolute dimensions are mentioned in width
// and height attributes or in the inline style, and the dimensions are
// not small enough.
if (is_lazy_load_image_enabled &&
((width_attr_dimension_type_ ==
HTMLImageElement::LazyLoadDimensionType::kAbsoluteNotSmall &&
height_attr_dimension_type_ ==
HTMLImageElement::LazyLoadDimensionType::kAbsoluteNotSmall) ||
inline_style_dimensions_type_ ==
HTMLImageElement::LazyLoadDimensionType::kAbsoluteNotSmall)) {
return nullptr;
}
request->SetIsLazyLoadImageEnabled(is_lazy_load_image_enabled);
} }
request->SetIsLazyLoadImageEnabled(is_lazy_load_image_enabled);
request->SetIntegrityMetadata(integrity_metadata_); request->SetIntegrityMetadata(integrity_metadata_);
......
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