From 157511a8d798343965850c51eb65f25daed89103 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Wed, 12 Feb 2020 21:29:10 +0000 Subject: [PATCH] Bug 1542784 - Stop speculative image load for lazy load images. r=hsivonen Depends on D61434 Differential Revision: https://phabricator.services.mozilla.com/D61435 --HG-- extra : moz-landing-system : lando --- modules/libpref/init/StaticPrefList.yaml | 2 +- parser/html/nsHtml5TreeBuilderCppSupplement.h | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index c0669dab7a99..20fc10cd5536 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -1629,7 +1629,7 @@ # # See https://github.com/whatwg/html/pull/3752 - name: dom.image-lazy-loading.enabled - type: bool + type: RelaxedAtomicBool value: false mirror: always diff --git a/parser/html/nsHtml5TreeBuilderCppSupplement.h b/parser/html/nsHtml5TreeBuilderCppSupplement.h index b99b969f88fe..6db63a0d8730 100644 --- a/parser/html/nsHtml5TreeBuilderCppSupplement.h +++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h @@ -7,6 +7,7 @@ #include "nsError.h" #include "mozilla/CheckedInt.h" #include "mozilla/Likely.h" +#include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_network.h" #include "mozilla/UniquePtr.h" @@ -170,18 +171,23 @@ nsIContentHandle* nsHtml5TreeBuilder::createElement( switch (aNamespace) { case kNameSpaceID_XHTML: if (nsGkAtoms::img == aName) { - nsHtml5String url = - aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC); - nsHtml5String srcset = - aAttributes->getValue(nsHtml5AttributeName::ATTR_SRCSET); - nsHtml5String crossOrigin = - aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN); - nsHtml5String referrerPolicy = - aAttributes->getValue(nsHtml5AttributeName::ATTR_REFERRERPOLICY); - nsHtml5String sizes = - aAttributes->getValue(nsHtml5AttributeName::ATTR_SIZES); - mSpeculativeLoadQueue.AppendElement()->InitImage( - url, crossOrigin, referrerPolicy, srcset, sizes); + nsHtml5String loading = + aAttributes->getValue(nsHtml5AttributeName::ATTR_LOADING); + if (!StaticPrefs::dom_image_lazy_loading_enabled() || + !loading.LowerCaseEqualsASCII("lazy")) { + nsHtml5String url = + aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC); + nsHtml5String srcset = + aAttributes->getValue(nsHtml5AttributeName::ATTR_SRCSET); + nsHtml5String crossOrigin = + aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN); + nsHtml5String referrerPolicy = aAttributes->getValue( + nsHtml5AttributeName::ATTR_REFERRERPOLICY); + nsHtml5String sizes = + aAttributes->getValue(nsHtml5AttributeName::ATTR_SIZES); + mSpeculativeLoadQueue.AppendElement()->InitImage( + url, crossOrigin, referrerPolicy, srcset, sizes); + } } else if (nsGkAtoms::source == aName) { nsHtml5String srcset = aAttributes->getValue(nsHtml5AttributeName::ATTR_SRCSET);