Bug 1245751 - Part 9: Allow href without xlink on SVG <script> elements. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 26 Aug 2016 18:06:04 +0800
changeset 407860 b8a2a9dc7b0b38e8ddcc0c2ecc1d791d2a170103
parent 407859 1e9ce2fb08aac471c63e795adbae09eee8bf3eaa
child 407861 6b2613479084dd04277569a7055f70a747eb4973
push id28064
push userbmo:boris.chiou@gmail.com
push dateWed, 31 Aug 2016 04:26:14 +0000
bugs1245751
milestone51.0a1
Bug 1245751 - Part 9: Allow href without xlink on SVG <script> elements. MozReview-Commit-ID: KS41J1RAPIk
dom/svg/SVGScriptElement.cpp
dom/svg/SVGScriptElement.h
--- 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