DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/* -*- 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 http://mozilla.org/MPL/2.0/. */

#ifndef nsNameSpaceManager_h___
#define nsNameSpaceManager_h___

#include "nsDataHashtable.h"
#include "nsHashKeys.h"
#include "nsAtom.h"
#include "nsIDocument.h"
#include "nsIObserver.h"
#include "nsStringFwd.h"
#include "nsTArray.h"

#include "mozilla/StaticPtr.h"

/**
 * The Name Space Manager tracks the association between a NameSpace
 * URI and the int32_t runtime id. Mappings between NameSpaces and
 * NameSpace prefixes are managed by nsINameSpaces.
 *
 * All NameSpace URIs are stored in a global table so that IDs are
 * consistent accross the app. NameSpace IDs are only consistent at runtime
 * ie: they are not guaranteed to be consistent accross app sessions.
 *
 * The nsNameSpaceManager needs to have a live reference for as long as
 * the NameSpace IDs are needed.
 *
 */

class nsNameSpaceManager final : public nsIObserver {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIOBSERVER
  virtual nsresult RegisterNameSpace(const nsAString& aURI,
                                     int32_t& aNameSpaceID);

  virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);

  // Returns the atom for the namespace URI associated with the given ID. The
  // ID must be within range and not be kNameSpaceID_None (i.e. zero);
  //
  // NB: The requirement of mapping from the first entry to the empty atom is
  // necessary for Servo, though it can be removed if needed adding a branch in
  // GeckoElement::get_namespace().
  nsAtom* NameSpaceURIAtom(int32_t aNameSpaceID) {
    MOZ_ASSERT(aNameSpaceID > 0);
    MOZ_ASSERT((int64_t)aNameSpaceID < (int64_t)mURIArray.Length());
    return mURIArray.ElementAt(aNameSpaceID);
  }

  int32_t GetNameSpaceID(const nsAString& aURI, bool aInChromeDoc);
  int32_t GetNameSpaceID(nsAtom* aURI, bool aInChromeDoc);

  bool HasElementCreator(int32_t aNameSpaceID);

  static nsNameSpaceManager* GetInstance();
  bool mMathMLDisabled;
  bool mSVGDisabled;

 private:
  bool Init();
  nsresult AddNameSpace(already_AddRefed<nsAtom> aURI,
                        const int32_t aNameSpaceID);
  nsresult AddDisabledNameSpace(already_AddRefed<nsAtom> aURI,
                                const int32_t aNameSpaceID);
  ~nsNameSpaceManager(){};

  nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mURIToIDTable;
  nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mDisabledURIToIDTable;
  nsTArray<RefPtr<nsAtom>> mURIArray;

  static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance;
};

#endif  // nsNameSpaceManager_h___