Bug 1245751 - Part 9: Allow href without xlink on SVG <script> elements. draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 06 Jul 2016 18:18:21 +0800
changeset 400493 f908c920645d47961c9ced3b337cfc00547dcae1
parent 400492 f3ad92500106142b39856da14506ece155c0ebc9
child 400494 fedf72ab6cf1babd35de0be0c66d102c2cc3fa3b
push id26164
push userbmo:boris.chiou@gmail.com
push dateSun, 14 Aug 2016 10:23:43 +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