Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsNameSpaceManager_h___
7 #define nsNameSpaceManager_h___
9 #include "nsDataHashtable.h"
10 #include "nsTArray.h"
12 #include "mozilla/StaticPtr.h"
14 class nsIAtom;
15 class nsAString;
17 #define kNameSpaceID_Unknown -1
18 // 0 is special at C++, so use a static const int32_t for
19 // kNameSpaceID_None to keep if from being cast to pointers
20 // Note that the XBL cache assumes (and asserts) that it can treat a
21 // single-byte value higher than kNameSpaceID_LastBuiltin specially.
22 static const int32_t kNameSpaceID_None = 0;
23 #define kNameSpaceID_XMLNS 1 // not really a namespace, but it needs to play the game
24 #define kNameSpaceID_XML 2
25 #define kNameSpaceID_XHTML 3
26 #define kNameSpaceID_XLink 4
27 #define kNameSpaceID_XSLT 5
28 #define kNameSpaceID_XBL 6
29 #define kNameSpaceID_MathML 7
30 #define kNameSpaceID_RDF 8
31 #define kNameSpaceID_XUL 9
32 #define kNameSpaceID_SVG 10
33 #define kNameSpaceID_LastBuiltin 10 // last 'built-in' namespace
35 class nsNameSpaceKey : public PLDHashEntryHdr
36 {
37 public:
38 typedef const nsAString* KeyType;
39 typedef const nsAString* KeyTypePointer;
41 nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey)
42 {
43 }
44 nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey)
45 {
46 }
48 KeyType GetKey() const
49 {
50 return mKey;
51 }
52 bool KeyEquals(KeyType aKey) const
53 {
54 return mKey->Equals(*aKey);
55 }
57 static KeyTypePointer KeyToPointer(KeyType aKey)
58 {
59 return aKey;
60 }
61 static PLDHashNumber HashKey(KeyTypePointer aKey) {
62 return mozilla::HashString(*aKey);
63 }
65 enum {
66 ALLOW_MEMMOVE = true
67 };
69 private:
70 const nsAString* mKey;
71 };
73 /**
74 * The Name Space Manager tracks the association between a NameSpace
75 * URI and the int32_t runtime id. Mappings between NameSpaces and
76 * NameSpace prefixes are managed by nsINameSpaces.
77 *
78 * All NameSpace URIs are stored in a global table so that IDs are
79 * consistent accross the app. NameSpace IDs are only consistent at runtime
80 * ie: they are not guaranteed to be consistent accross app sessions.
81 *
82 * The nsNameSpaceManager needs to have a live reference for as long as
83 * the NameSpace IDs are needed.
84 *
85 */
87 class nsNameSpaceManager
88 {
89 public:
90 virtual ~nsNameSpaceManager() {}
92 virtual nsresult RegisterNameSpace(const nsAString& aURI,
93 int32_t& aNameSpaceID);
95 virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
96 virtual int32_t GetNameSpaceID(const nsAString& aURI);
98 virtual bool HasElementCreator(int32_t aNameSpaceID);
100 static nsNameSpaceManager* GetInstance();
101 private:
102 bool Init();
103 nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
105 nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
106 nsTArray< nsAutoPtr<nsString> > mURIArray;
108 static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance;
109 };
111 #endif // nsNameSpaceManager_h___