/src/mozilla-central/dom/base/nsNameSpaceManager.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef nsNameSpaceManager_h___ |
8 | | #define nsNameSpaceManager_h___ |
9 | | |
10 | | #include "nsDataHashtable.h" |
11 | | #include "nsHashKeys.h" |
12 | | #include "nsAtom.h" |
13 | | #include "nsIDocument.h" |
14 | | #include "nsStringFwd.h" |
15 | | #include "nsTArray.h" |
16 | | |
17 | | #include "mozilla/StaticPtr.h" |
18 | | |
19 | | /** |
20 | | * The Name Space Manager tracks the association between a NameSpace |
21 | | * URI and the int32_t runtime id. Mappings between NameSpaces and |
22 | | * NameSpace prefixes are managed by nsINameSpaces. |
23 | | * |
24 | | * All NameSpace URIs are stored in a global table so that IDs are |
25 | | * consistent accross the app. NameSpace IDs are only consistent at runtime |
26 | | * ie: they are not guaranteed to be consistent accross app sessions. |
27 | | * |
28 | | * The nsNameSpaceManager needs to have a live reference for as long as |
29 | | * the NameSpace IDs are needed. |
30 | | * |
31 | | */ |
32 | | |
33 | | class nsNameSpaceManager final |
34 | | { |
35 | | public: |
36 | | NS_INLINE_DECL_REFCOUNTING(nsNameSpaceManager) |
37 | | |
38 | | virtual nsresult RegisterNameSpace(const nsAString& aURI, |
39 | | int32_t& aNameSpaceID); |
40 | | nsresult RegisterNameSpace(already_AddRefed<nsAtom> aURI, |
41 | | int32_t& aNameSpaceID); |
42 | | |
43 | | virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI); |
44 | | |
45 | | // Returns the atom for the namespace URI associated with the given ID. The |
46 | | // ID must be within range and not be kNameSpaceID_None (i.e. zero); |
47 | | // |
48 | | // NB: The requirement of mapping from the first entry to the empty atom is |
49 | | // necessary for Servo, though it can be removed if needed adding a branch in |
50 | | // GeckoElement::get_namespace(). |
51 | | nsAtom* NameSpaceURIAtom(int32_t aNameSpaceID) { |
52 | | MOZ_ASSERT(aNameSpaceID > 0); |
53 | | MOZ_ASSERT((int64_t) aNameSpaceID < (int64_t) mURIArray.Length()); |
54 | | return mURIArray.ElementAt(aNameSpaceID); |
55 | | } |
56 | | |
57 | | int32_t GetNameSpaceID(const nsAString& aURI, |
58 | | bool aInChromeDoc); |
59 | | int32_t GetNameSpaceID(nsAtom* aURI, |
60 | | bool aInChromeDoc); |
61 | | |
62 | | bool HasElementCreator(int32_t aNameSpaceID); |
63 | | |
64 | | static nsNameSpaceManager* GetInstance(); |
65 | | bool mMathMLDisabled; |
66 | | bool mSVGDisabled; |
67 | | |
68 | | private: |
69 | | void PrefChanged(const char* aPref); |
70 | | |
71 | | bool Init(); |
72 | | nsresult AddNameSpace(already_AddRefed<nsAtom> aURI, const int32_t aNameSpaceID); |
73 | | nsresult AddDisabledNameSpace(already_AddRefed<nsAtom> aURI, const int32_t aNameSpaceID); |
74 | 0 | ~nsNameSpaceManager() {}; |
75 | | |
76 | | nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mURIToIDTable; |
77 | | nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mDisabledURIToIDTable; |
78 | | nsTArray<RefPtr<nsAtom>> mURIArray; |
79 | | |
80 | | static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance; |
81 | | }; |
82 | | |
83 | | #endif // nsNameSpaceManager_h___ |