From 06d962c3ea734e1df894325fe4425d95d402cb9a Mon Sep 17 00:00:00 2001 From: Robert Longson Date: Thu, 7 Aug 2008 15:03:58 +0100 Subject: [PATCH] Bug 448938 - Fix relative URIs in image filters and make href processing more consistent. r+sr=roc --- content/svg/content/src/nsSVGAElement.cpp | 10 +--- content/svg/content/src/nsSVGFilters.cpp | 55 +++++++++++-------- content/svg/content/src/nsSVGImageElement.cpp | 36 +++++------- 3 files changed, 49 insertions(+), 52 deletions(-) diff --git a/content/svg/content/src/nsSVGAElement.cpp b/content/svg/content/src/nsSVGAElement.cpp index 1f7a0e4fc472..bf8e03bab05a 100755 --- a/content/svg/content/src/nsSVGAElement.cpp +++ b/content/svg/content/src/nsSVGAElement.cpp @@ -256,12 +256,8 @@ nsSVGAElement::IsLink(nsIURI** aURI) const nsIContent::ATTR_VALUE_NO_MATCH) { nsCOMPtr baseURI = GetBaseURI(); // Get absolute URI - // XXX: should really be using href->GetStringValue(), but nsSVGElement:: - // ParseAttribute has set the nsAttrValue type to eSVGValue, so we need - // to use the more expensive ToString (generates, rather than fetches). - nsAutoString hrefStr; - href->ToString(hrefStr); - nsContentUtils::NewURIWithDocumentCharset(aURI, hrefStr, + nsContentUtils::NewURIWithDocumentCharset(aURI, + mStringAttributes[HREF].GetAnimValue(), GetOwnerDoc(), baseURI); // must promise out param is non-null if we return true return !!*aURI; @@ -274,7 +270,7 @@ nsSVGAElement::IsLink(nsIURI** aURI) const void nsSVGAElement::GetLinkTarget(nsAString& aTarget) { - GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget); + aTarget = mStringAttributes[TARGET].GetAnimValue(); if (aTarget.IsEmpty()) { static nsIContent::AttrValuesArray sShowVals[] = diff --git a/content/svg/content/src/nsSVGFilters.cpp b/content/svg/content/src/nsSVGFilters.cpp index 61cc125c63c7..ad7ac77787ff 100644 --- a/content/svg/content/src/nsSVGFilters.cpp +++ b/content/svg/content/src/nsSVGFilters.cpp @@ -63,6 +63,7 @@ #include "imgIContainer.h" #include "gfxIImageFrame.h" #include "nsIImage.h" +#include "nsNetUtil.h" #include "nsSVGAnimatedPreserveAspectRatio.h" #include "nsSVGPreserveAspectRatio.h" #include "nsIInterfaceRequestorUtils.h" @@ -5194,10 +5195,11 @@ public: NS_FORWARD_NSIDOMNODE(nsSVGFEImageElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGFEImageElementBase::) - virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + // nsSVGElement + virtual void DidChangeString(PRUint8 aAttrEnum, PRBool aDoSetAttr); - virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, - const nsAString* aValue, PRBool aNotify); + // nsIContent + virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, @@ -5218,6 +5220,8 @@ private: // Invalidate users of the filter containing this element. void Invalidate(); + nsresult LoadSVGImage(PRBool aForce, PRBool aNotify); + protected: virtual PRBool OperatesOnSRGB(nsSVGFilterInstance*, PRUint32, Image*) { return PR_TRUE; } @@ -5293,25 +5297,25 @@ nsSVGFEImageElement::Init() } //---------------------------------------------------------------------- -// nsIContent methods: nsresult -nsSVGFEImageElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, - const nsAString* aValue, PRBool aNotify) +nsSVGFEImageElement::LoadSVGImage(PRBool aForce, PRBool aNotify) { - if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) { - nsAutoString href; - if (GetAttr(kNameSpaceID_XLink, nsGkAtoms::href, href)) { - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadImage(href, PR_FALSE, PR_FALSE); - } - } + // resolve href attribute + nsCOMPtr baseURI = GetBaseURI(); - return nsSVGFEImageElementBase::AfterSetAttr(aNamespaceID, aName, - aValue, aNotify); + nsAutoString href(mStringAttributes[HREF].GetAnimValue()); + href.Trim(" \t\n\r"); + + if (baseURI && !href.IsEmpty()) + NS_MakeAbsoluteURI(href, href, baseURI); + + return LoadImage(href, aForce, aNotify); } +//---------------------------------------------------------------------- +// nsIContent methods: + nsresult nsSVGFEImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, @@ -5324,12 +5328,9 @@ nsSVGFEImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // Our base URI may have changed; claim that our URI changed, and the // nsImageLoadingContent will decide whether a new image load is warranted. - nsAutoString href; - if (GetAttr(kNameSpaceID_XLink, nsGkAtoms::href, href)) { - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadImage(href, PR_FALSE, PR_FALSE); - } + // Note: no need to notify here; since we're just now being bound + // we don't have any frames or anything yet. + LoadSVGImage(PR_FALSE, PR_FALSE); return rv; } @@ -5433,6 +5434,16 @@ nsSVGFEImageElement::GetStringInfo() NS_ARRAY_LENGTH(sStringInfo)); } +void +nsSVGFEImageElement::DidChangeString(PRUint8 aAttrEnum, PRBool aDoSetAttr) +{ + nsSVGFEImageElementBase::DidChangeString(aAttrEnum, aDoSetAttr); + + if (aAttrEnum == HREF) { + LoadSVGImage(PR_TRUE, PR_TRUE); + } +} + //---------------------------------------------------------------------- // imgIDecoderObserver methods diff --git a/content/svg/content/src/nsSVGImageElement.cpp b/content/svg/content/src/nsSVGImageElement.cpp index f1545a8c8bf1..6770828feda0 100644 --- a/content/svg/content/src/nsSVGImageElement.cpp +++ b/content/svg/content/src/nsSVGImageElement.cpp @@ -99,7 +99,7 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; protected: - void GetSrc(nsAString& src); + nsresult LoadSVGImage(PRBool aForce, PRBool aNotify); virtual LengthAttributesInfo GetLengthInfo(); virtual StringAttributesInfo GetStringInfo(); @@ -255,13 +255,6 @@ nsSVGImageElement::DidChangeString(PRUint8 aAttrEnum, PRBool aDoSetAttr) nsSVGImageElementBase::DidChangeString(aAttrEnum, aDoSetAttr); if (aAttrEnum == HREF) { - nsAutoString href; - GetSrc(href); - -#ifdef DEBUG_tor - fprintf(stderr, "nsSVGImageElement - URI <%s>\n", ToNewCString(href)); -#endif - // If caller is not chrome and dom.disable_image_src_set is true, // prevent setting image.src by exiting early if (nsContentUtils::GetBoolPref("dom.disable_image_src_set") && @@ -269,25 +262,25 @@ nsSVGImageElement::DidChangeString(PRUint8 aAttrEnum, PRBool aDoSetAttr) return; } - LoadImage(href, PR_TRUE, PR_TRUE); + LoadSVGImage(PR_TRUE, PR_TRUE); } } //---------------------------------------------------------------------- -void nsSVGImageElement::GetSrc(nsAString& src) +nsresult +nsSVGImageElement::LoadSVGImage(PRBool aForce, PRBool aNotify) { // resolve href attribute - nsCOMPtr baseURI = GetBaseURI(); - nsAutoString relURIStr(mStringAttributes[HREF].GetAnimValue()); - relURIStr.Trim(" \t\n\r"); + nsAutoString href(mStringAttributes[HREF].GetAnimValue()); + href.Trim(" \t\n\r"); - if (baseURI && !relURIStr.IsEmpty()) - NS_MakeAbsoluteURI(src, relURIStr, baseURI); - else - src = relURIStr; + if (baseURI && !href.IsEmpty()) + NS_MakeAbsoluteURI(href, href, baseURI); + + return LoadImage(href, aForce, aNotify); } //---------------------------------------------------------------------- @@ -305,12 +298,9 @@ nsSVGImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // Our base URI may have changed; claim that our URI changed, and the // nsImageLoadingContent will decide whether a new image load is warranted. - nsAutoString href; - if (GetAttr(kNameSpaceID_XLink, nsGkAtoms::href, href)) { - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadImage(href, PR_FALSE, PR_FALSE); - } + // Note: no need to notify here; since we're just now being bound + // we don't have any frames or anything yet. + LoadSVGImage(PR_FALSE, PR_FALSE); return rv; }