Bug 1245751 - Part 9: Allow href without xlink on SVG <script> elements.
MozReview-Commit-ID: KS41J1RAPIk
--- a/dom/svg/SVGScriptElement.cpp
+++ b/dom/svg/SVGScriptElement.cpp
@@ -16,18 +16,19 @@ namespace mozilla {
namespace dom {
JSObject*
SVGScriptElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
{
return SVGScriptElementBinding::Wrap(aCx, this, aGivenProto);
}
-nsSVGElement::StringInfo SVGScriptElement::sStringInfo[1] =
+nsSVGElement::StringInfo SVGScriptElement::sStringInfo[2] =
{
+ { &nsGkAtoms::href, kNameSpaceID_None, false },
{ &nsGkAtoms::href, kNameSpaceID_XLink, false }
};
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ISUPPORTS_INHERITED(SVGScriptElement, SVGScriptElementBase,
nsIDOMNode, nsIDOMElement,
@@ -104,17 +105,19 @@ SVGScriptElement::SetCrossOrigin(const n
ErrorResult& aError)
{
SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
}
already_AddRefed<SVGAnimatedString>
SVGScriptElement::Href()
{
- return mStringAttributes[HREF].ToDOMAnimatedString(this);
+ return mStringAttributes[HREF].IsExplicitlySet()
+ ? mStringAttributes[HREF].ToDOMAnimatedString(this)
+ : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
}
//----------------------------------------------------------------------
// nsIScriptElement methods
bool
SVGScriptElement::GetScriptType(nsAString& type)
{
@@ -135,38 +138,45 @@ SVGScriptElement::GetScriptCharset(nsASt
void
SVGScriptElement::FreezeUriAsyncDefer()
{
if (mFrozen) {
return;
}
- if (mStringAttributes[HREF].IsExplicitlySet()) {
+ if (mStringAttributes[HREF].IsExplicitlySet() ||
+ mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
// variation of this code in nsHTMLScriptElement - check if changes
// need to be transfered when modifying
nsAutoString src;
- mStringAttributes[HREF].GetAnimValue(src, this);
+ if (mStringAttributes[HREF].IsExplicitlySet()) {
+ mStringAttributes[HREF].GetAnimValue(src, this);
+ } else {
+ mStringAttributes[XLINK_HREF].GetAnimValue(src, this);
+ }
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
NS_NewURI(getter_AddRefs(mUri), src, nullptr, baseURI);
// At this point mUri will be null for invalid URLs.
mExternal = true;
}
-
+
mFrozen = true;
}
//----------------------------------------------------------------------
// nsScriptElement methods
bool
SVGScriptElement::HasScriptContent()
{
- return (mFrozen ? mExternal : mStringAttributes[HREF].IsExplicitlySet()) ||
+ return (mFrozen ? mExternal
+ : mStringAttributes[HREF].IsExplicitlySet() ||
+ mStringAttributes[XLINK_HREF].IsExplicitlySet()) ||
nsContentUtils::HasNonEmptyTextContent(this);
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::StringAttributesInfo
SVGScriptElement::GetStringInfo()
@@ -194,17 +204,19 @@ SVGScriptElement::BindToTree(nsIDocument
return NS_OK;
}
nsresult
SVGScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
- if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) {
+ if ((aNamespaceID == kNameSpaceID_XLink ||
+ aNamespaceID == kNameSpaceID_None) &&
+ aName == nsGkAtoms::href) {
MaybeProcessScript();
}
return SVGScriptElementBase::AfterSetAttr(aNamespaceID, aName,
aValue, aNotify);
}
bool
SVGScriptElement::ParseAttribute(int32_t aNamespaceID,
--- a/dom/svg/SVGScriptElement.h
+++ b/dom/svg/SVGScriptElement.h
@@ -70,17 +70,17 @@ public:
void SetCrossOrigin(const nsAString & aCrossOrigin, ErrorResult& aError);
already_AddRefed<SVGAnimatedString> Href();
protected:
~SVGScriptElement();
virtual StringAttributesInfo GetStringInfo() override;
- enum { HREF };
- nsSVGString mStringAttributes[1];
- static StringInfo sStringInfo[1];
+ enum { HREF, XLINK_HREF };
+ nsSVGString mStringAttributes[2];
+ static StringInfo sStringInfo[2];
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGScriptElement_h