Backed out 2 changesets (bug 1709577) for causing wpt failures. CLOSED TREE

Backed out changeset 0da1dba1749c (bug 1709577)
Backed out changeset bab974107b3b (bug 1709577)
This commit is contained in:
Sandor Molnar
2021-05-07 05:34:43 +03:00
parent 9644eccd27
commit c7dc20560e
11 changed files with 107 additions and 166 deletions

View File

@@ -88,7 +88,15 @@ class ImageLoadTask final : public MicroTaskRunnable {
if (mElement->mPendingImageLoadTask == this) {
mElement->mPendingImageLoadTask = nullptr;
mElement->mUseUrgentStartForChannel = mUseUrgentStartForChannel;
mElement->LoadSelectedImage(true, true, mAlwaysLoad);
// Defer loading this image if loading="lazy" was set after this microtask
// was queued.
// NOTE: Using ShouldLoadImage() will violate the HTML standard spec
// because ShouldLoadImage() checks the document active state which should
// have done just once before this queue is created as per the spec, so
// we just check the lazy loading state here.
if (!mElement->IsLazyLoading()) {
mElement->LoadSelectedImage(true, true, mAlwaysLoad);
}
}
mDocument->UnblockOnload(false);
}
@@ -334,13 +342,17 @@ nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
bool forceReload = false;
if (aName == nsGkAtoms::loading &&
!ImageState().HasState(NS_EVENT_STATE_LOADING)) {
if (aValue && Loading(aValue->GetEnumValue()) == Loading::Lazy) {
if (aName == nsGkAtoms::loading) {
if (aValue &&
static_cast<HTMLImageElement::Loading>(aValue->GetEnumValue()) ==
Loading::Lazy &&
!ImageState().HasState(NS_EVENT_STATE_LOADING)) {
SetLazyLoading();
} else if (aOldValue &&
Loading(aOldValue->GetEnumValue()) == Loading::Lazy) {
StopLazyLoading(FromIntersectionObserver::No, StartLoading::Yes);
static_cast<HTMLImageElement::Loading>(
aOldValue->GetEnumValue()) == Loading::Lazy &&
!ImageState().HasState(NS_EVENT_STATE_LOADING)) {
StopLazyLoadingAndStartLoadIfNeeded(false);
}
} else if (aName == nsGkAtoms::src && !aValue) {
// NOTE: regular src value changes are handled in AfterMaybeChangeAttr, so
@@ -477,8 +489,8 @@ void HTMLImageElement::AfterMaybeChangeAttr(
// when aNotify is true, and 2) When this function is called by
// OnAttrSetButNotChanged, SetAttrAndNotify will not subsequently call
// UpdateState.
LoadSelectedImage(/* aForce = */ true, aNotify,
/* aAlwaysLoad = */ true);
LoadImage(aValue.String(), true, aNotify, eImageLoadType_Normal,
mSrcTriggeringPrincipal);
mNewRequestsWillNeedAnimationReset = false;
}
@@ -544,7 +556,8 @@ nsresult HTMLImageElement::BindToTree(BindContext& aContext, nsINode& aParent) {
// in order to react to changes in the environment. See note of
// https://html.spec.whatwg.org/multipage/embedded-content.html#img-environment-changes
QueueImageLoadTask(false);
} else if (!InResponsiveMode() && HasAttr(nsGkAtoms::src)) {
} else if (!InResponsiveMode() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
// We skip loading when our attributes were set from parser land,
// so trigger a aForce=false load now to check if things changed.
// This isn't necessary for responsive mode, since creating the
@@ -736,7 +749,8 @@ nsresult HTMLImageElement::CopyInnerTo(HTMLImageElement* aDest) {
// doing the image load because we passed in false for aNotify. But we
// really do want it to do the load, so set it up to happen once the cloning
// reaches a stable state.
if (!aDest->InResponsiveMode() && aDest->HasAttr(nsGkAtoms::src) &&
if (!aDest->InResponsiveMode() &&
aDest->HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
aDest->ShouldLoadImage()) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
@@ -821,12 +835,12 @@ void HTMLImageElement::QueueImageLoadTask(bool aAlwaysLoad) {
}
bool HTMLImageElement::HaveSrcsetOrInPicture() {
if (HasAttr(nsGkAtoms::srcset)) {
if (HasAttr(kNameSpaceID_None, nsGkAtoms::srcset)) {
return true;
}
Element* parent = GetParentElement();
return parent && parent->IsHTMLElement(nsGkAtoms::picture);
Element* parent = nsINode::GetParentElement();
return (parent && parent->IsHTMLElement(nsGkAtoms::picture));
}
bool HTMLImageElement::InResponsiveMode() {
@@ -888,53 +902,43 @@ nsresult HTMLImageElement::LoadSelectedImage(bool aForce, bool aNotify,
currentDensity = mResponsiveSelector->GetSelectedImageDensity();
}
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> selectedSource;
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
ImageLoadType type = eImageLoadType_Normal;
bool hasSrc = false;
if (mResponsiveSelector) {
selectedSource = mResponsiveSelector->GetSelectedImageURL();
triggeringPrincipal =
nsCOMPtr<nsIURI> url = mResponsiveSelector->GetSelectedImageURL();
nsCOMPtr<nsIPrincipal> triggeringPrincipal =
mResponsiveSelector->GetSelectedImageTriggeringPrincipal();
type = eImageLoadType_Imageset;
} else {
nsAutoString src;
hasSrc = GetAttr(nsGkAtoms::src, src);
if (hasSrc && !src.IsEmpty()) {
Document* doc = OwnerDoc();
StringToURI(src, doc, getter_AddRefs(selectedSource));
if (HaveSrcsetOrInPicture()) {
// If we have a srcset attribute or are in a <picture> element, we
// always use the Imageset load type, even if we parsed no valid
// responsive sources from either, per spec.
type = eImageLoadType_Imageset;
}
triggeringPrincipal = mSrcTriggeringPrincipal;
}
}
if (!aAlwaysLoad && SelectedSourceMatchesLast(selectedSource)) {
UpdateDensityOnly();
return NS_OK;
}
// Before we actually defer the lazy-loading
if (mLazyLoading) {
if (!selectedSource ||
!nsContentUtils::IsImageAvailable(this, selectedSource,
triggeringPrincipal, GetCORSMode())) {
selectedSource = url;
if (!aAlwaysLoad && SelectedSourceMatchesLast(selectedSource)) {
UpdateDensityOnly();
return NS_OK;
}
StopLazyLoading(FromIntersectionObserver::No, StartLoading::No);
if (url) {
rv = LoadImage(url, aForce, aNotify, eImageLoadType_Imageset,
triggeringPrincipal);
}
} else {
nsAutoString src;
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
CancelImageRequests(aNotify);
rv = NS_OK;
} else {
Document* doc = OwnerDoc();
StringToURI(src, doc, getter_AddRefs(selectedSource));
if (!aAlwaysLoad && SelectedSourceMatchesLast(selectedSource)) {
UpdateDensityOnly();
return NS_OK;
}
// If we have a srcset attribute or are in a <picture> element,
// we always use the Imageset load type, even if we parsed no
// valid responsive sources from either, per spec.
rv = LoadImage(src, aForce, aNotify,
HaveSrcsetOrInPicture() ? eImageLoadType_Imageset
: eImageLoadType_Normal,
mSrcTriggeringPrincipal);
}
}
nsresult rv = NS_ERROR_FAILURE;
// src triggers an error event on invalid URI, unlike other loads.
if (selectedSource || hasSrc) {
rv = LoadImage(selectedSource, aForce, aNotify, type, triggeringPrincipal);
}
mLastSelectedSource = selectedSource;
mCurrentDensity = currentDensity;
@@ -1143,7 +1147,7 @@ bool HTMLImageElement::TryCreateResponsiveSelector(Element* aSourceElement) {
// Skip if has no srcset or an empty srcset
nsString srcset;
if (!aSourceElement->GetAttr(nsGkAtoms::srcset, srcset)) {
if (!aSourceElement->GetAttr(kNameSpaceID_None, nsGkAtoms::srcset, srcset)) {
return false;
}
@@ -1160,14 +1164,14 @@ bool HTMLImageElement::TryCreateResponsiveSelector(Element* aSourceElement) {
}
nsAutoString sizes;
aSourceElement->GetAttr(nsGkAtoms::sizes, sizes);
aSourceElement->GetAttr(kNameSpaceID_None, nsGkAtoms::sizes, sizes);
sel->SetSizesFromDescriptor(sizes);
// If this is the <img> tag, also pull in src as the default source
if (!isSourceTag) {
MOZ_ASSERT(aSourceElement == this);
nsAutoString src;
if (GetAttr(nsGkAtoms::src, src) && !src.IsEmpty()) {
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src) && !src.IsEmpty()) {
sel->SetDefaultSource(src, mSrcTriggeringPrincipal);
}
}
@@ -1242,7 +1246,7 @@ void HTMLImageElement::MediaFeatureValuesChanged() {
}
bool HTMLImageElement::ShouldLoadImage() const {
return OwnerDoc()->ShouldLoadImages();
return OwnerDoc()->ShouldLoadImages() && !mLazyLoading;
}
void HTMLImageElement::SetLazyLoading() {
@@ -1275,7 +1279,7 @@ void HTMLImageElement::StartLoadingIfNeeded() {
// Use script runner for the case the adopt is from appendChild.
// Bug 1076583 - We still behave synchronously in the non-responsive case
nsContentUtils::AddScriptRunner(
InResponsiveMode()
(InResponsiveMode())
? NewRunnableMethod<bool>(
"dom::HTMLImageElement::QueueImageLoadTask", this,
&HTMLImageElement::QueueImageLoadTask, true)
@@ -1285,26 +1289,22 @@ void HTMLImageElement::StartLoadingIfNeeded() {
}
}
void HTMLImageElement::StopLazyLoading(
FromIntersectionObserver aFromIntersectionObserver,
StartLoading aStartLoading) {
void HTMLImageElement::StopLazyLoadingAndStartLoadIfNeeded(
bool aFromIntersectionObserver) {
if (!mLazyLoading) {
return;
}
mLazyLoading = false;
Document* doc = OwnerDoc();
doc->GetLazyLoadImageObserver()->Unobserve(*this);
StartLoadingIfNeeded();
if (bool(aFromIntersectionObserver)) {
if (aFromIntersectionObserver) {
doc->IncLazyLoadImageStarted();
} else {
doc->DecLazyLoadImageCount();
doc->GetLazyLoadImageObserverViewport()->Unobserve(*this);
}
if (bool(aStartLoading)) {
StartLoadingIfNeeded();
}
}
void HTMLImageElement::LazyLoadImageReachedViewport() {