content/base/src/nsNodeInfoManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/src/nsNodeInfoManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * A class for handing out nodeinfos and ensuring sharing of them as needed.
    1.11 + */
    1.12 +
    1.13 +#ifndef nsNodeInfoManager_h___
    1.14 +#define nsNodeInfoManager_h___
    1.15 +
    1.16 +#include "mozilla/Attributes.h"           // for MOZ_FINAL
    1.17 +#include "nsCOMPtr.h"                     // for member
    1.18 +#include "nsAutoPtr.h"                    // for nsRefPtr
    1.19 +#include "nsCycleCollectionParticipant.h" // for NS_DECL_CYCLE_*
    1.20 +#include "plhash.h"                       // for typedef PLHashNumber
    1.21 +
    1.22 +class nsAString;
    1.23 +class nsBindingManager;
    1.24 +class nsIAtom;
    1.25 +class nsIDocument;
    1.26 +class nsIDOMDocumentType;
    1.27 +class nsINodeInfo;
    1.28 +class nsIPrincipal;
    1.29 +class nsNodeInfo;
    1.30 +struct PLHashEntry;
    1.31 +struct PLHashTable;
    1.32 +template<class T> struct already_AddRefed;
    1.33 +
    1.34 +class nsNodeInfoManager MOZ_FINAL
    1.35 +{
    1.36 +public:
    1.37 +  nsNodeInfoManager();
    1.38 +  ~nsNodeInfoManager();
    1.39 +
    1.40 +  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager)
    1.41 +
    1.42 +  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsNodeInfoManager)
    1.43 +
    1.44 +  /**
    1.45 +   * Initialize the nodeinfo manager with a document.
    1.46 +   */
    1.47 +  nsresult Init(nsIDocument *aDocument);
    1.48 +
    1.49 +  /**
    1.50 +   * Release the reference to the document, this will be called when
    1.51 +   * the document is going away.
    1.52 +   */
    1.53 +  void DropDocumentReference();
    1.54 +
    1.55 +  /**
    1.56 +   * Methods for creating nodeinfo's from atoms and/or strings.
    1.57 +   */
    1.58 +  already_AddRefed<nsINodeInfo> GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
    1.59 +                                            int32_t aNamespaceID,
    1.60 +                                            uint16_t aNodeType,
    1.61 +                                            nsIAtom* aExtraName = nullptr);
    1.62 +  nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
    1.63 +                       int32_t aNamespaceID, uint16_t aNodeType,
    1.64 +                       nsINodeInfo** aNodeInfo);
    1.65 +  nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
    1.66 +                       const nsAString& aNamespaceURI, uint16_t aNodeType,
    1.67 +                       nsINodeInfo** aNodeInfo);
    1.68 +
    1.69 +  /**
    1.70 +   * Returns the nodeinfo for text nodes. Can return null if OOM.
    1.71 +   */
    1.72 +  already_AddRefed<nsINodeInfo> GetTextNodeInfo();
    1.73 +
    1.74 +  /**
    1.75 +   * Returns the nodeinfo for comment nodes. Can return null if OOM.
    1.76 +   */
    1.77 +  already_AddRefed<nsINodeInfo> GetCommentNodeInfo();
    1.78 +
    1.79 +  /**
    1.80 +   * Returns the nodeinfo for the document node. Can return null if OOM.
    1.81 +   */
    1.82 +  already_AddRefed<nsINodeInfo> GetDocumentNodeInfo();
    1.83 +
    1.84 +  /**
    1.85 +   * Retrieve a pointer to the document that owns this node info
    1.86 +   * manager.
    1.87 +   */
    1.88 +  nsIDocument* GetDocument() const
    1.89 +  {
    1.90 +    return mDocument;
    1.91 +  }
    1.92 +
    1.93 +  /**
    1.94 +   * Gets the principal of the document this nodeinfo manager belongs to.
    1.95 +   */
    1.96 +  nsIPrincipal *DocumentPrincipal() const {
    1.97 +    NS_ASSERTION(mPrincipal, "How'd that happen?");
    1.98 +    return mPrincipal;
    1.99 +  }
   1.100 +
   1.101 +  void RemoveNodeInfo(nsNodeInfo *aNodeInfo);
   1.102 +
   1.103 +  nsBindingManager* GetBindingManager() const
   1.104 +  {
   1.105 +    return mBindingManager;
   1.106 +  }
   1.107 +
   1.108 +protected:
   1.109 +  friend class nsDocument;
   1.110 +  friend class nsXULPrototypeDocument;
   1.111 +  friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
   1.112 +                                        nsNodeInfoManager *,
   1.113 +                                        nsIAtom *,
   1.114 +                                        const nsAString& ,
   1.115 +                                        const nsAString& ,
   1.116 +                                        const nsAString& );
   1.117 +
   1.118 +  /**
   1.119 +   * Sets the principal of the document this nodeinfo manager belongs to.
   1.120 +   */
   1.121 +  void SetDocumentPrincipal(nsIPrincipal *aPrincipal);
   1.122 +
   1.123 +private:
   1.124 +  static int NodeInfoInnerKeyCompare(const void *key1, const void *key2);
   1.125 +  static PLHashNumber GetNodeInfoInnerHashValue(const void *key);
   1.126 +  static int DropNodeInfoDocument(PLHashEntry *he, int hashIndex,
   1.127 +                                     void *arg);
   1.128 +
   1.129 +  PLHashTable *mNodeInfoHash;
   1.130 +  nsIDocument *mDocument; // WEAK
   1.131 +  uint32_t mNonDocumentNodeInfos;
   1.132 +  nsCOMPtr<nsIPrincipal> mPrincipal; // Never null after Init() succeeds.
   1.133 +  nsCOMPtr<nsIPrincipal> mDefaultPrincipal; // Never null after Init() succeeds
   1.134 +  nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership
   1.135 +  nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership
   1.136 +  nsINodeInfo *mDocumentNodeInfo; // WEAK to avoid circular ownership
   1.137 +  nsRefPtr<nsBindingManager> mBindingManager;
   1.138 +};
   1.139 +
   1.140 +#endif /* nsNodeInfoManager_h___ */

mercurial