author Kris Maglione <>
Wed, 01 Nov 2017 20:35:52 -0700
changeset 445040 4f63760c1dbb3d413a850c8b12ad29646399e7d7
parent 435808 67a8e12324569dd730347187e2ffccae486c758b
child 449662 a24287fb46abc6959e2d8e17d632b8016cd613c1
permissions -rw-r--r--
Bug 1415352: Part 1a - Pass subject principal through to ParseAttribute. r=bz This is necessary in order to parse style attributes using the subject principal of the caller, rather than defaulting to the page principal. MozReview-Commit-ID: GIshajQ28la

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef mozilla_dom_SVGMPathElement_h
#define mozilla_dom_SVGMPathElement_h

#include "mozilla/dom/IDTracker.h"
#include "nsSVGElement.h"
#include "nsStubMutationObserver.h"
#include "nsSVGString.h"

nsresult NS_NewSVGMPathElement(nsIContent **aResult,
                               already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);

typedef nsSVGElement SVGMPathElementBase;

namespace mozilla {
namespace dom {
class SVGPathElement;

class SVGMPathElement final : public SVGMPathElementBase,
                              public nsStubMutationObserver
  friend nsresult (::NS_NewSVGMPathElement(nsIContent **aResult,
                                           already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
  explicit SVGMPathElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);

  virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;

  // interfaces:



  // nsIContent interface
  virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                         bool aPreallocateChildren) const override;
  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                              nsIContent* aBindingParent,
                              bool aCompileEventHandlers) override;
  virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;

  virtual nsresult UnsetAttr(int32_t aNamespaceID, nsAtom* aAttribute,
                             bool aNotify) override;
  // Element specializations
  virtual bool ParseAttribute(int32_t aNamespaceID,
                                nsAtom* aAttribute,
                                const nsAString& aValue,
                                nsIPrincipal* aMaybeScriptedPrincipal,
                                nsAttrValue& aResult) override;

  // Public helper method: If our xlink:href attribute links to a <path>
  // element, this method returns a pointer to that element. Otherwise,
  // this returns nullptr.
  SVGPathElement* GetReferencedPath();

  // WebIDL
  already_AddRefed<SVGAnimatedString> Href();

   * Helper that provides a reference to the 'path' element with the ID that is
   * referenced by the 'mpath' element's 'href' attribute, and that will
   * invalidate the parent of the 'mpath' and update mutation observers to the
   * new path element if the element that that ID identifies changes to a
   * different element (or none).
  class PathElementTracker final : public IDTracker {
    explicit PathElementTracker(SVGMPathElement* aMpathElement)
      : mMpathElement(aMpathElement)
    // We need to be notified when target changes, in order to request a sample
    // (which will clear animation effects that used the old target-path
    // and recompute the animation effects using the new target-path).
    virtual void ElementChanged(Element* aFrom, Element* aTo) override {
      IDTracker::ElementChanged(aFrom, aTo);
      if (aFrom) {
      if (aTo) {

    // We need to override IsPersistent to get persistent tracking (beyond the
    // first time the target changes)
    virtual bool IsPersistent() override { return true; }
    SVGMPathElement* const mMpathElement;

  virtual StringAttributesInfo GetStringInfo() override;

  void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
  void UnlinkHrefTarget(bool aNotifyParent);
  void NotifyParentOfMpathChange(nsIContent* aParent);

  enum { HREF, XLINK_HREF };
  nsSVGString        mStringAttributes[2];
  static StringInfo  sStringInfo[2];
  PathElementTracker mPathTracker;

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_SVGMPathElement_h