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
void SetUp() override {
scoped_feature_list_.InitWithFeaturesAndParameters(
{{features::kLazyImageLoading,
{{"automatic-lazy-load-images-enabled", "true"}}}},
{{"automatic-lazy-load-images-enabled", "true"},
{"enable-lazy-load-images-metadata-fetch", "true"}}}},
{});
InProcessBrowserTest::SetUp();
}
......
......@@ -405,7 +405,7 @@ void SetIndividualRuntimeFeatures(
WebRuntimeFeatures::EnableLazyImageLoadingMetadataFetch(
base::GetFieldTrialParamByFeatureAsBool(
features::kLazyImageLoading, "enable-lazy-load-images-metadata-fetch",
true));
false));
WebRuntimeFeatures::EnablePictureInPicture(
base::FeatureList::IsEnabled(media::kPictureInPicture));
......
......@@ -2818,6 +2818,7 @@
"params": {
"automatic-lazy-load-frames-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-images-to-data-saver-only": "true"
},
......
......@@ -299,49 +299,51 @@ class TokenPreloadScanner::StartTagScanner {
document_parameters.lazyload_policy_enforced) {
effective_loading_attr_value = LoadingAttrValue::kAuto;
}
bool is_lazy_load_image_enabled = false;
switch (effective_loading_attr_value) {
case LoadingAttrValue::kEager:
is_lazy_load_image_enabled = false;
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) {
if (type == ResourceType::kImage) {
bool is_lazy_load_image_enabled = false;
switch (effective_loading_attr_value) {
case LoadingAttrValue::kEager:
is_lazy_load_image_enabled = false;
} else {
break;
case LoadingAttrValue::kLazy:
is_lazy_load_image_enabled =
document_parameters.lazy_load_image_setting ==
LocalFrame::LazyLoadImageSetting::kEnabledAutomatic;
}
break;
}
// Do not preload if lazyload is possible but metadata fetch is disabled.
if (is_lazy_load_image_enabled &&
!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;
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;
} else {
is_lazy_load_image_enabled =
document_parameters.lazy_load_image_setting ==
LocalFrame::LazyLoadImageSetting::kEnabledAutomatic;
}
break;
}
// Do not preload if lazyload is possible but metadata fetch is disabled.
if (is_lazy_load_image_enabled &&
!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_);
......
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