Commit a2a6febd authored by Scott Little's avatar Scott Little Committed by Commit Bot

LazyLoad: Hook up support for using loading=lazy on iframes.

Previously, support for the "loading" attribute to control lazy iframe
loading was only used in conjunction with automatic lazy loading. This
CL separates those two concepts, allowing for "loading" attribute
support to be enabled for iframes without automatically lazily loading
iframes that have no "loading" attribute set.

Bug: 937980
Change-Id: I0bf8f0e4d073fee3a3530b654a7834d1eb70cee1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1633790Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Scott Little <sclittle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664608}
parent 3a394526
...@@ -389,7 +389,11 @@ void SetIndividualRuntimeFeatures( ...@@ -389,7 +389,11 @@ void SetIndividualRuntimeFeatures(
if (base::FeatureList::IsEnabled(features::kLazyImageVisibleLoadTimeMetrics)) if (base::FeatureList::IsEnabled(features::kLazyImageVisibleLoadTimeMetrics))
WebRuntimeFeatures::EnableLazyImageVisibleLoadTimeMetrics(true); WebRuntimeFeatures::EnableLazyImageVisibleLoadTimeMetrics(true);
WebRuntimeFeatures::EnableRestrictLazyFrameLoadingToDataSaver( WebRuntimeFeatures::EnableAutomaticLazyFrameLoading(
base::GetFieldTrialParamByFeatureAsBool(
features::kLazyFrameLoading, "automatic-lazy-load-frames-enabled",
false));
WebRuntimeFeatures::EnableRestrictAutomaticLazyFrameLoadingToDataSaver(
base::GetFieldTrialParamByFeatureAsBool( base::GetFieldTrialParamByFeatureAsBool(
features::kLazyFrameLoading, features::kLazyFrameLoading,
"restrict-lazy-load-frames-to-data-saver-only", false)); "restrict-lazy-load-frames-to-data-saver-only", false));
......
...@@ -81,6 +81,7 @@ class WebRuntimeFeatures { ...@@ -81,6 +81,7 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableAdTagging(bool); BLINK_PLATFORM_EXPORT static void EnableAdTagging(bool);
BLINK_PLATFORM_EXPORT static void EnableAllowActivationDelegationAttr(bool); BLINK_PLATFORM_EXPORT static void EnableAllowActivationDelegationAttr(bool);
BLINK_PLATFORM_EXPORT static void EnableAudioOutputDevices(bool); BLINK_PLATFORM_EXPORT static void EnableAudioOutputDevices(bool);
BLINK_PLATFORM_EXPORT static void EnableAutomaticLazyFrameLoading(bool);
BLINK_PLATFORM_EXPORT static void EnableAutomaticLazyImageLoading(bool); BLINK_PLATFORM_EXPORT static void EnableAutomaticLazyImageLoading(bool);
BLINK_PLATFORM_EXPORT static void EnableBackgroundFetch(bool); BLINK_PLATFORM_EXPORT static void EnableBackgroundFetch(bool);
BLINK_PLATFORM_EXPORT static void EnableBlinkHeapIncrementalMarking(bool); BLINK_PLATFORM_EXPORT static void EnableBlinkHeapIncrementalMarking(bool);
...@@ -166,8 +167,8 @@ class WebRuntimeFeatures { ...@@ -166,8 +167,8 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableRemotePlaybackAPI(bool); BLINK_PLATFORM_EXPORT static void EnableRemotePlaybackAPI(bool);
BLINK_PLATFORM_EXPORT static void EnableRenderingPipelineThrottling(bool); BLINK_PLATFORM_EXPORT static void EnableRenderingPipelineThrottling(bool);
BLINK_PLATFORM_EXPORT static void EnableResourceLoadScheduler(bool); BLINK_PLATFORM_EXPORT static void EnableResourceLoadScheduler(bool);
BLINK_PLATFORM_EXPORT static void EnableRestrictLazyFrameLoadingToDataSaver( BLINK_PLATFORM_EXPORT static void
bool); EnableRestrictAutomaticLazyFrameLoadingToDataSaver(bool);
BLINK_PLATFORM_EXPORT static void BLINK_PLATFORM_EXPORT static void
EnableRestrictAutomaticLazyImageLoadingToDataSaver(bool); EnableRestrictAutomaticLazyImageLoadingToDataSaver(bool);
BLINK_PLATFORM_EXPORT static void EnableScriptedSpeechRecognition(bool); BLINK_PLATFORM_EXPORT static void EnableScriptedSpeechRecognition(bool);
......
...@@ -77,9 +77,9 @@ bool DoesParentAllowLazyLoadingChildren(Document& document) { ...@@ -77,9 +77,9 @@ bool DoesParentAllowLazyLoadingChildren(Document& document) {
return containing_frame_owner->ShouldLazyLoadChildren(); return containing_frame_owner->ShouldLazyLoadChildren();
} }
bool IsFrameLazyLoadable(Document& document, bool IsFrameLazyLoadable(const Document& document,
const KURL& url, const KURL& url,
bool is_load_attr_lazy, bool is_loading_attr_lazy,
bool should_lazy_load_children) { bool should_lazy_load_children) {
if (!RuntimeEnabledFeatures::LazyFrameLoadingEnabled() && if (!RuntimeEnabledFeatures::LazyFrameLoadingEnabled() &&
!RuntimeEnabledFeatures::LazyFrameVisibleLoadTimeMetricsEnabled()) { !RuntimeEnabledFeatures::LazyFrameVisibleLoadTimeMetricsEnabled()) {
...@@ -92,7 +92,7 @@ bool IsFrameLazyLoadable(Document& document, ...@@ -92,7 +92,7 @@ bool IsFrameLazyLoadable(Document& document,
if (!url.ProtocolIsInHTTPFamily()) if (!url.ProtocolIsInHTTPFamily())
return false; return false;
if (is_load_attr_lazy) if (is_loading_attr_lazy)
return true; return true;
if (!should_lazy_load_children || if (!should_lazy_load_children ||
...@@ -105,12 +105,28 @@ bool IsFrameLazyLoadable(Document& document, ...@@ -105,12 +105,28 @@ bool IsFrameLazyLoadable(Document& document,
return false; return false;
} }
return true;
}
bool ShouldLazilyLoadFrame(const Document& document,
bool is_loading_attr_lazy) {
DCHECK(document.GetSettings());
if (!RuntimeEnabledFeatures::LazyFrameLoadingEnabled() ||
!document.GetSettings()->GetLazyLoadEnabled()) {
return false;
}
if (is_loading_attr_lazy)
return true;
if (!RuntimeEnabledFeatures::AutomaticLazyFrameLoadingEnabled())
return false;
// If lazy loading is restricted to only Data Saver users, then avoid // If lazy loading is restricted to only Data Saver users, then avoid
// lazy loading unless Data Saver is enabled, taking the Data Saver // lazy loading unless Data Saver is enabled, taking the Data Saver
// holdback into consideration. // holdback into consideration.
if (RuntimeEnabledFeatures::RestrictLazyFrameLoadingToDataSaverEnabled() && if (RuntimeEnabledFeatures::
((document.GetSettings() && RestrictAutomaticLazyFrameLoadingToDataSaverEnabled() &&
document.GetSettings()->GetDataSaverHoldbackWebApi()) || (document.GetSettings()->GetDataSaverHoldbackWebApi() ||
!GetNetworkStateNotifier().SaveDataEnabled())) { !GetNetworkStateNotifier().SaveDataEnabled())) {
return false; return false;
} }
...@@ -452,10 +468,11 @@ bool HTMLFrameOwnerElement::LoadOrRedirectSubframe( ...@@ -452,10 +468,11 @@ bool HTMLFrameOwnerElement::LoadOrRedirectSubframe(
bool loading_lazy_set = EqualIgnoringASCIICase(loading_attr, "lazy") || bool loading_lazy_set = EqualIgnoringASCIICase(loading_attr, "lazy") ||
(IsLoadingFrameDefaultEagerEnforced() && (IsLoadingFrameDefaultEagerEnforced() &&
!EqualIgnoringASCIICase(loading_attr, "eager")); !EqualIgnoringASCIICase(loading_attr, "eager"));
if (!lazy_load_frame_observer_ && if (!lazy_load_frame_observer_ &&
IsFrameLazyLoadable(GetDocument(), url, loading_lazy_set, IsFrameLazyLoadable(GetDocument(), url, loading_lazy_set,
should_lazy_load_children_)) { should_lazy_load_children_)) {
// By default, avoid deferring subresources inside a lazily loaded frame. // Avoid automatically deferring subresources inside a lazily loaded frame.
// This will make it possible for subresources in hidden frames to load that // This will make it possible for subresources in hidden frames to load that
// will never be visible, as well as make it so that deferred frames that // will never be visible, as well as make it so that deferred frames that
// have multiple layers of iframes inside them can load faster once they're // have multiple layers of iframes inside them can load faster once they're
...@@ -468,9 +485,7 @@ bool HTMLFrameOwnerElement::LoadOrRedirectSubframe( ...@@ -468,9 +485,7 @@ bool HTMLFrameOwnerElement::LoadOrRedirectSubframe(
if (RuntimeEnabledFeatures::LazyFrameVisibleLoadTimeMetricsEnabled()) if (RuntimeEnabledFeatures::LazyFrameVisibleLoadTimeMetricsEnabled())
lazy_load_frame_observer_->StartTrackingVisibilityMetrics(); lazy_load_frame_observer_->StartTrackingVisibilityMetrics();
if (RuntimeEnabledFeatures::LazyFrameLoadingEnabled() && if (ShouldLazilyLoadFrame(GetDocument(), loading_lazy_set)) {
GetDocument().GetSettings() &&
GetDocument().GetSettings()->GetLazyLoadEnabled()) {
lazy_load_frame_observer_->DeferLoadUntilNearViewport(request, lazy_load_frame_observer_->DeferLoadUntilNearViewport(request,
child_load_type); child_load_type);
return true; return true;
......
...@@ -116,6 +116,10 @@ void WebRuntimeFeatures::EnableAudioOutputDevices(bool enable) { ...@@ -116,6 +116,10 @@ void WebRuntimeFeatures::EnableAudioOutputDevices(bool enable) {
RuntimeEnabledFeatures::SetAudioOutputDevicesEnabled(enable); RuntimeEnabledFeatures::SetAudioOutputDevicesEnabled(enable);
} }
void WebRuntimeFeatures::EnableAutomaticLazyFrameLoading(bool enable) {
RuntimeEnabledFeatures::SetAutomaticLazyFrameLoadingEnabled(enable);
}
void WebRuntimeFeatures::EnableAutomaticLazyImageLoading(bool enable) { void WebRuntimeFeatures::EnableAutomaticLazyImageLoading(bool enable) {
RuntimeEnabledFeatures::SetAutomaticLazyImageLoadingEnabled(enable); RuntimeEnabledFeatures::SetAutomaticLazyImageLoadingEnabled(enable);
} }
...@@ -516,9 +520,10 @@ void WebRuntimeFeatures::EnableResourceLoadScheduler(bool enable) { ...@@ -516,9 +520,10 @@ void WebRuntimeFeatures::EnableResourceLoadScheduler(bool enable) {
RuntimeEnabledFeatures::SetResourceLoadSchedulerEnabled(enable); RuntimeEnabledFeatures::SetResourceLoadSchedulerEnabled(enable);
} }
void WebRuntimeFeatures::EnableRestrictLazyFrameLoadingToDataSaver( void WebRuntimeFeatures::EnableRestrictAutomaticLazyFrameLoadingToDataSaver(
bool enable) { bool enable) {
RuntimeEnabledFeatures::SetRestrictLazyFrameLoadingToDataSaverEnabled(enable); RuntimeEnabledFeatures::
SetRestrictAutomaticLazyFrameLoadingToDataSaverEnabled(enable);
} }
void WebRuntimeFeatures::EnableRestrictAutomaticLazyImageLoadingToDataSaver( void WebRuntimeFeatures::EnableRestrictAutomaticLazyImageLoadingToDataSaver(
......
...@@ -132,6 +132,10 @@ ...@@ -132,6 +132,10 @@
name: "AudioWorkletRealtimeThread", name: "AudioWorkletRealtimeThread",
status: "experimental", status: "experimental",
}, },
{
name: "AutomaticLazyFrameLoading",
depends_on: ["LazyFrameLoading"],
},
{ {
name: "AutomaticLazyImageLoading", name: "AutomaticLazyImageLoading",
depends_on: ["LazyImageLoading"], depends_on: ["LazyImageLoading"],
...@@ -1241,11 +1245,12 @@ ...@@ -1241,11 +1245,12 @@
status: "stable", status: "stable",
}, },
{ {
name: "RestrictAutomaticLazyImageLoadingToDataSaver", name: "RestrictAutomaticLazyFrameLoadingToDataSaver",
depends_on: ["AutomaticLazyImageLoading"], depends_on: ["AutomaticLazyFrameLoading"],
}, },
{ {
name: "RestrictLazyFrameLoadingToDataSaver", name: "RestrictAutomaticLazyImageLoadingToDataSaver",
depends_on: ["AutomaticLazyImageLoading"],
}, },
{ {
name: "RtcAudioJitterBufferMaxPackets", name: "RtcAudioJitterBufferMaxPackets",
......
...@@ -657,8 +657,8 @@ ...@@ -657,8 +657,8 @@
{ {
"prefix" : "lazyload-policy", "prefix" : "lazyload-policy",
"base": "external/wpt/feature-policy/experimental-features/lazyload", "base": "external/wpt/feature-policy/experimental-features/lazyload",
"args": ["--enable-blink-features=LazyFrameLoading,LazyImageLoading,AutomaticLazyImageLoading", "args": ["--enable-blink-features=LazyFrameLoading,AutomaticLazyFrameLoading,LazyImageLoading,AutomaticLazyImageLoading",
"--disable-blink-features=RestrictAutomaticLazyImageLoadingToDataSaver"] "--disable-blink-features=RestrictAutomaticLazyFrameLoadingToDataSaver,RestrictAutomaticLazyImageLoadingToDataSaver"]
}, },
{ {
"prefix": "display-lock", "prefix": "display-lock",
......
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