Commit e87ed71f authored by rajendrant's avatar rajendrant Committed by Commit Bot

Disable lazyload when downloading an offline page

This CL creates a bool in WebSettings to enable lazyloading of frames and images.
The bool is populated by WebContentsDelegate which offline pages listens to and
disables lazy loading.

Bug: 701884
Change-Id: I1ad1776adf3f9c7e6a8a3a68507aa9dc419e3955
Reviewed-on: https://chromium-review.googlesource.com/c/1352817
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarPeter Williamson <petewil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612507}
parent 425cd7d0
...@@ -3207,6 +3207,12 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs( ...@@ -3207,6 +3207,12 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs(
} }
} }
web_prefs->lazy_load_enabled =
(base::FeatureList::IsEnabled(features::kLazyFrameLoading) ||
base::FeatureList::IsEnabled(features::kLazyImageLoading)) &&
(!contents->GetDelegate() ||
contents->GetDelegate()->ShouldAllowLazyLoad());
if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) {
const char* param_name = const char* param_name =
web_prefs->data_saver_enabled web_prefs->data_saver_enabled
......
...@@ -148,6 +148,10 @@ void BackgroundLoaderContents::AdjustPreviewsStateForNavigation( ...@@ -148,6 +148,10 @@ void BackgroundLoaderContents::AdjustPreviewsStateForNavigation(
} }
} }
bool BackgroundLoaderContents::ShouldAllowLazyLoad() {
return false;
}
BackgroundLoaderContents::BackgroundLoaderContents() BackgroundLoaderContents::BackgroundLoaderContents()
: browser_context_(nullptr) { : browser_context_(nullptr) {
web_contents_.reset(); web_contents_.reset();
......
...@@ -88,10 +88,10 @@ class BackgroundLoaderContents : public content::WebContentsDelegate { ...@@ -88,10 +88,10 @@ class BackgroundLoaderContents : public content::WebContentsDelegate {
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host, bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
const GURL& security_origin, const GURL& security_origin,
content::MediaStreamType type) override; content::MediaStreamType type) override;
void AdjustPreviewsStateForNavigation( void AdjustPreviewsStateForNavigation(
content::WebContents* web_contents, content::WebContents* web_contents,
content::PreviewsState* previews_state) override; content::PreviewsState* previews_state) override;
bool ShouldAllowLazyLoad() override;
private: private:
friend class BackgroundLoaderContentsTest; friend class BackgroundLoaderContentsTest;
......
...@@ -300,4 +300,8 @@ std::unique_ptr<content::WebContents> WebContentsDelegate::SwapWebContents( ...@@ -300,4 +300,8 @@ std::unique_ptr<content::WebContents> WebContentsDelegate::SwapWebContents(
return new_contents; return new_contents;
} }
bool WebContentsDelegate::ShouldAllowLazyLoad() {
return true;
}
} // namespace content } // namespace content
...@@ -620,6 +620,9 @@ class CONTENT_EXPORT WebContentsDelegate { ...@@ -620,6 +620,9 @@ class CONTENT_EXPORT WebContentsDelegate {
virtual void UpdateUserGestureCarryoverInfo(WebContents* web_contents) {} virtual void UpdateUserGestureCarryoverInfo(WebContents* web_contents) {}
#endif #endif
// Returns true if lazy loading of images and frames should be enabled.
virtual bool ShouldAllowLazyLoad();
// Requests the delegate to replace |old_contents| with |new_contents| in the // Requests the delegate to replace |old_contents| with |new_contents| in the
// container that holds |old_contents|. If the delegate successfully replaces // container that holds |old_contents|. If the delegate successfully replaces
// |old_contents|, the return parameter passes ownership of |old_contents|. // |old_contents|, the return parameter passes ownership of |old_contents|.
......
...@@ -240,7 +240,9 @@ IPC_STRUCT_TRAITS_BEGIN(content::WebPreferences) ...@@ -240,7 +240,9 @@ IPC_STRUCT_TRAITS_BEGIN(content::WebPreferences)
IPC_STRUCT_TRAITS_MEMBER(picture_in_picture_enabled) IPC_STRUCT_TRAITS_MEMBER(picture_in_picture_enabled)
IPC_STRUCT_TRAITS_MEMBER(translate_service_available) IPC_STRUCT_TRAITS_MEMBER(translate_service_available)
IPC_STRUCT_TRAITS_MEMBER(network_quality_estimator_web_holdback) IPC_STRUCT_TRAITS_MEMBER(network_quality_estimator_web_holdback)
IPC_STRUCT_TRAITS_MEMBER(lazy_load_enabled)
IPC_STRUCT_TRAITS_MEMBER(lazy_frame_loading_distance_thresholds_px) IPC_STRUCT_TRAITS_MEMBER(lazy_frame_loading_distance_thresholds_px)
IPC_STRUCT_TRAITS_MEMBER(lazy_image_loading_distance_thresholds_px)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(blink::mojom::WindowFeatures) IPC_STRUCT_TRAITS_BEGIN(blink::mojom::WindowFeatures)
......
...@@ -320,6 +320,9 @@ struct CONTENT_EXPORT WebPreferences { ...@@ -320,6 +320,9 @@ struct CONTENT_EXPORT WebPreferences {
// regardless of the actual quality. // regardless of the actual quality.
net::EffectiveConnectionType network_quality_estimator_web_holdback; net::EffectiveConnectionType network_quality_estimator_web_holdback;
// Whether lazy loading of frames and images is enabled.
bool lazy_load_enabled = true;
// Specifies how close a lazily loaded iframe or image should be from the // Specifies how close a lazily loaded iframe or image should be from the
// viewport before it should start being loaded in, depending on the effective // viewport before it should start being loaded in, depending on the effective
// connection type of the current network. Blink will use the default distance // connection type of the current network. Blink will use the default distance
......
...@@ -932,6 +932,8 @@ void RenderView::ApplyWebPreferences(const WebPreferences& prefs, ...@@ -932,6 +932,8 @@ void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
settings->SetDataSaverHoldbackMediaApi( settings->SetDataSaverHoldbackMediaApi(
prefs.data_saver_holdback_media_api_enabled); prefs.data_saver_holdback_media_api_enabled);
settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
for (const auto& ect_distance_pair : for (const auto& ect_distance_pair :
prefs.lazy_frame_loading_distance_thresholds_px) { prefs.lazy_frame_loading_distance_thresholds_px) {
switch (ect_distance_pair.first) { switch (ect_distance_pair.first) {
......
...@@ -287,6 +287,7 @@ class WebSettings { ...@@ -287,6 +287,7 @@ class WebSettings {
virtual void SetDoNotUpdateSelectionOnMutatingSelectionRange(bool) = 0; virtual void SetDoNotUpdateSelectionOnMutatingSelectionRange(bool) = 0;
virtual void SetMediaDownloadInProductHelpEnabled(bool) = 0; virtual void SetMediaDownloadInProductHelpEnabled(bool) = 0;
virtual void SetLowPriorityIframesThreshold(WebEffectiveConnectionType) = 0; virtual void SetLowPriorityIframesThreshold(WebEffectiveConnectionType) = 0;
virtual void SetLazyLoadEnabled(bool) = 0;
virtual void SetLazyFrameLoadingDistanceThresholdPxUnknown(int) = 0; virtual void SetLazyFrameLoadingDistanceThresholdPxUnknown(int) = 0;
virtual void SetLazyFrameLoadingDistanceThresholdPxOffline(int) = 0; virtual void SetLazyFrameLoadingDistanceThresholdPxOffline(int) = 0;
virtual void SetLazyFrameLoadingDistanceThresholdPxSlow2G(int) = 0; virtual void SetLazyFrameLoadingDistanceThresholdPxSlow2G(int) = 0;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/tree_scope.h" #include "third_party/blink/renderer/core/dom/tree_scope.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/lazy_load_image_observer.h" #include "third_party/blink/renderer/core/html/lazy_load_image_observer.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/content_data.h" #include "third_party/blink/renderer/core/style/content_data.h"
...@@ -203,7 +204,9 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { ...@@ -203,7 +204,9 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
FetchParameters::ImageRequestOptimization FetchParameters::ImageRequestOptimization
image_request_optimization = FetchParameters::kNone; image_request_optimization = FetchParameters::kNone;
if (!BackgroundLayerMayBeSprite(*background_layer)) { if (!BackgroundLayerMayBeSprite(*background_layer)) {
if (element_->GetDocument() if (element_->GetDocument().GetSettings() &&
element_->GetDocument().GetSettings()->GetLazyLoadEnabled() &&
element_->GetDocument()
.GetFrame() .GetFrame()
->IsLazyLoadingImageAllowed()) { ->IsLazyLoadingImageAllowed()) {
image_request_optimization = FetchParameters::kDeferImageLoad; image_request_optimization = FetchParameters::kDeferImageLoad;
......
...@@ -711,6 +711,10 @@ void WebSettingsImpl::SetLowPriorityIframesThreshold( ...@@ -711,6 +711,10 @@ void WebSettingsImpl::SetLowPriorityIframesThreshold(
settings_->SetLowPriorityIframesThreshold(effective_connection_type); settings_->SetLowPriorityIframesThreshold(effective_connection_type);
} }
void WebSettingsImpl::SetLazyLoadEnabled(bool enabled) {
settings_->SetLazyLoadEnabled(enabled);
}
void WebSettingsImpl::SetLazyFrameLoadingDistanceThresholdPxUnknown( void WebSettingsImpl::SetLazyFrameLoadingDistanceThresholdPxUnknown(
int distance_px) { int distance_px) {
settings_->SetLazyFrameLoadingDistanceThresholdPxUnknown(distance_px); settings_->SetLazyFrameLoadingDistanceThresholdPxUnknown(distance_px);
......
...@@ -204,6 +204,8 @@ class CORE_EXPORT WebSettingsImpl final : public WebSettings { ...@@ -204,6 +204,8 @@ class CORE_EXPORT WebSettingsImpl final : public WebSettings {
void SetMediaDownloadInProductHelpEnabled(bool) override; void SetMediaDownloadInProductHelpEnabled(bool) override;
void SetLowPriorityIframesThreshold(WebEffectiveConnectionType) override; void SetLowPriorityIframesThreshold(WebEffectiveConnectionType) override;
void SetLazyLoadEnabled(bool) override;
// TODO(rajendrant): Remove these lazyload distance threshold settings for // TODO(rajendrant): Remove these lazyload distance threshold settings for
// frames and images, once the values are finalized from the experiment. // frames and images, once the values are finalized from the experiment.
void SetLazyFrameLoadingDistanceThresholdPxUnknown(int) override; void SetLazyFrameLoadingDistanceThresholdPxUnknown(int) override;
......
...@@ -951,6 +951,10 @@ ...@@ -951,6 +951,10 @@
initial: true, initial: true,
}, },
{
name: "lazyLoadEnabled",
initial: false,
},
// //
// Lazy frame loading distance-from-viewport thresholds for different effective connection types. // Lazy frame loading distance-from-viewport thresholds for different effective connection types.
// //
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/remote_frame.h" #include "third_party/blink/renderer/core/frame/remote_frame.h"
#include "third_party/blink/renderer/core/frame/remote_frame_view.h" #include "third_party/blink/renderer/core/frame/remote_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/lazy_load_frame_observer.h" #include "third_party/blink/renderer/core/html/lazy_load_frame_observer.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h" #include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
...@@ -407,6 +408,8 @@ bool HTMLFrameOwnerElement::LoadOrRedirectSubframe( ...@@ -407,6 +408,8 @@ bool HTMLFrameOwnerElement::LoadOrRedirectSubframe(
if ((RuntimeEnabledFeatures::LazyFrameLoadingEnabled() || if ((RuntimeEnabledFeatures::LazyFrameLoadingEnabled() ||
RuntimeEnabledFeatures::LazyFrameVisibleLoadTimeMetricsEnabled()) && RuntimeEnabledFeatures::LazyFrameVisibleLoadTimeMetricsEnabled()) &&
GetDocument().GetSettings() &&
GetDocument().GetSettings()->GetLazyLoadEnabled() &&
!lazy_load_frame_observer_ && !lazy_load_frame_observer_ &&
// Only http:// or https:// URLs are eligible for lazy loading, excluding // Only http:// or https:// URLs are eligible for lazy loading, excluding
// URLs like invalid or empty URLs, "about:blank", local file URLs, etc. // URLs like invalid or empty URLs, "about:blank", local file URLs, etc.
......
...@@ -111,6 +111,7 @@ class LazyLoadFramesTest : public SimTest, ...@@ -111,6 +111,7 @@ class LazyLoadFramesTest : public SimTest,
settings.SetLazyFrameLoadingDistanceThresholdPx2G(500); settings.SetLazyFrameLoadingDistanceThresholdPx2G(500);
settings.SetLazyFrameLoadingDistanceThresholdPx3G(600); settings.SetLazyFrameLoadingDistanceThresholdPx3G(600);
settings.SetLazyFrameLoadingDistanceThresholdPx4G(700); settings.SetLazyFrameLoadingDistanceThresholdPx4G(700);
settings.SetLazyLoadEnabled(true);
} }
int GetLoadingDistanceThreshold() const { int GetLoadingDistanceThreshold() const {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/script/document_write_intervention.h" #include "third_party/blink/renderer/core/script/document_write_intervention.h"
#include "third_party/blink/renderer/core/script/script_loader.h" #include "third_party/blink/renderer/core/script/script_loader.h"
......
...@@ -100,7 +100,9 @@ bool IsLazyLoadingImageAllowed(const LocalFrame* frame, ...@@ -100,7 +100,9 @@ bool IsLazyLoadingImageAllowed(const LocalFrame* frame,
width <= kMinDimensionToLazyLoad && height <= kMinDimensionToLazyLoad) { width <= kMinDimensionToLazyLoad && height <= kMinDimensionToLazyLoad) {
return false; return false;
} }
return frame->IsLazyLoadingImageAllowed(); return frame->GetDocument()->GetSettings() &&
frame->GetDocument()->GetSettings()->GetLazyLoadEnabled() &&
frame->IsLazyLoadingImageAllowed();
} }
} // namespace } // namespace
......
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