Bug 1750871 - run mochitest-remote on fission everywhere. r=releng-reviewers,aki
[gecko.git] / dom / base / nsNameSpaceManager.h
blobaa4ec51104a54386f8e2ea86a94715fc21f0a0ea
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsNameSpaceManager_h___
8 #define nsNameSpaceManager_h___
10 #include "nsTHashMap.h"
11 #include "nsHashKeys.h"
12 #include "nsAtom.h"
13 #include "nsStringFwd.h"
14 #include "nsTArray.h"
16 #include "mozilla/StaticPtr.h"
18 /**
19 * The Name Space Manager tracks the association between a NameSpace
20 * URI and the int32_t runtime id. Mappings between NameSpaces and
21 * NameSpace prefixes are managed by nsINameSpaces.
23 * All NameSpace URIs are stored in a global table so that IDs are
24 * consistent accross the app. NameSpace IDs are only consistent at runtime
25 * ie: they are not guaranteed to be consistent accross app sessions.
27 * The nsNameSpaceManager needs to have a live reference for as long as
28 * the NameSpace IDs are needed.
32 class nsNameSpaceManager final {
33 public:
34 NS_INLINE_DECL_REFCOUNTING(nsNameSpaceManager)
36 nsresult RegisterNameSpace(const nsAString& aURI, int32_t& aNameSpaceID);
37 nsresult RegisterNameSpace(already_AddRefed<nsAtom> aURI,
38 int32_t& aNameSpaceID);
40 nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
42 // Returns the atom for the namespace URI associated with the given ID. The
43 // ID must be within range and not be kNameSpaceID_None (i.e. zero);
45 // NB: The requirement of mapping from the first entry to the empty atom is
46 // necessary for Servo, though it can be removed if needed adding a branch in
47 // GeckoElement::get_namespace().
48 nsAtom* NameSpaceURIAtom(int32_t aNameSpaceID) {
49 MOZ_ASSERT(aNameSpaceID > 0);
50 MOZ_ASSERT((int64_t)aNameSpaceID < (int64_t)mURIArray.Length());
51 return mURIArray.ElementAt(aNameSpaceID);
54 int32_t GetNameSpaceID(const nsAString& aURI, bool aInChromeDoc);
55 int32_t GetNameSpaceID(nsAtom* aURI, bool aInChromeDoc);
57 static const char* GetNameSpaceDisplayName(uint32_t aNameSpaceID);
59 bool HasElementCreator(int32_t aNameSpaceID);
61 static nsNameSpaceManager* GetInstance();
62 bool mMathMLDisabled;
63 bool mSVGDisabled;
65 private:
66 static void PrefChanged(const char* aPref, void* aSelf);
67 void PrefChanged(const char* aPref);
69 bool Init();
70 nsresult AddNameSpace(already_AddRefed<nsAtom> aURI,
71 const int32_t aNameSpaceID);
72 nsresult AddDisabledNameSpace(already_AddRefed<nsAtom> aURI,
73 const int32_t aNameSpaceID);
74 ~nsNameSpaceManager() = default;
76 nsTHashMap<nsRefPtrHashKey<nsAtom>, int32_t> mURIToIDTable;
77 nsTHashMap<nsRefPtrHashKey<nsAtom>, int32_t> mDisabledURIToIDTable;
78 nsTArray<RefPtr<nsAtom>> mURIArray;
80 static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance;
83 #endif // nsNameSpaceManager_h___