Bug 1709577 - Fix invalid src events for images. r=edgar
My previous patch still causes one WPT regression (invalid-src.html), because we stopped firing error event for src="". However that test times out because it doesn't correctly handle the invalid URI case. This patch fixes it and cleans up the code a bit. This fixes bug 1466138 too, and matches Chrome. Differential Revision: https://phabricator.services.mozilla.com/D114495
This commit is contained in:
@@ -888,10 +888,10 @@ 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 =
|
||||
@@ -899,10 +899,8 @@ nsresult HTMLImageElement::LoadSelectedImage(bool aForce, bool aNotify,
|
||||
type = eImageLoadType_Imageset;
|
||||
} else {
|
||||
nsAutoString src;
|
||||
if (!GetAttr(nsGkAtoms::src, src) || src.IsEmpty()) {
|
||||
CancelImageRequests(aNotify);
|
||||
rv = NS_OK;
|
||||
} else {
|
||||
hasSrc = GetAttr(nsGkAtoms::src, src);
|
||||
if (hasSrc && !src.IsEmpty()) {
|
||||
Document* doc = OwnerDoc();
|
||||
StringToURI(src, doc, getter_AddRefs(selectedSource));
|
||||
if (HaveSrcsetOrInPicture()) {
|
||||
@@ -920,18 +918,23 @@ nsresult HTMLImageElement::LoadSelectedImage(bool aForce, bool aNotify,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (selectedSource) {
|
||||
// Before we actually defer the lazy-loading
|
||||
if (mLazyLoading) {
|
||||
if (!nsContentUtils::IsImageAvailable(
|
||||
this, selectedSource, triggeringPrincipal, GetCORSMode())) {
|
||||
return NS_OK;
|
||||
}
|
||||
StopLazyLoading(FromIntersectionObserver::No, StartLoading::No);
|
||||
// Before we actually defer the lazy-loading
|
||||
if (mLazyLoading) {
|
||||
if (!selectedSource ||
|
||||
!nsContentUtils::IsImageAvailable(this, selectedSource,
|
||||
triggeringPrincipal, GetCORSMode())) {
|
||||
return NS_OK;
|
||||
}
|
||||
StopLazyLoading(FromIntersectionObserver::No, StartLoading::No);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user