Bumping manifests a=b2g-bump
[gecko.git] / dom / base / nsScriptNameSpaceManager.h
blobb59f4849b388639f007e17086280c73f50239799
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/.
8 * This Original Code has been modified by IBM Corporation.
9 * Modifications made by IBM described herein are
10 * Copyright (c) International Business Machines
11 * Corporation, 2000
13 * Modifications to Mozilla code or documentation
14 * identified per MPL Section 3.3
16 * Date Modified by Description of modification
17 * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
18 * use in OS2
21 #ifndef nsScriptNameSpaceManager_h__
22 #define nsScriptNameSpaceManager_h__
24 #include "mozilla/MemoryReporting.h"
25 #include "nsIMemoryReporter.h"
26 #include "nsIScriptNameSpaceManager.h"
27 #include "nsString.h"
28 #include "nsID.h"
29 #include "pldhash.h"
30 #include "nsDOMClassInfo.h"
31 #include "nsIObserver.h"
32 #include "nsWeakReference.h"
33 #include "xpcpublic.h"
36 struct nsGlobalNameStruct
38 struct ConstructorAlias
40 nsCID mCID;
41 nsString mProtoName;
42 nsGlobalNameStruct* mProto;
45 enum nametype {
46 eTypeNotInitialized,
47 eTypeNewDOMBinding,
48 eTypeInterface,
49 eTypeProperty,
50 eTypeNavigatorProperty,
51 eTypeExternalConstructor,
52 eTypeClassConstructor,
53 eTypeClassProto,
54 eTypeExternalClassInfoCreator,
55 eTypeExternalClassInfo,
56 eTypeExternalConstructorAlias
57 } mType;
59 // mChromeOnly is only used for structs that define non-WebIDL things
60 // (possibly in addition to WebIDL ones). In particular, it's not even
61 // initialized for eTypeNewDOMBinding structs.
62 bool mChromeOnly : 1;
63 bool mAllowXBL : 1;
65 union {
66 int32_t mDOMClassInfoID; // eTypeClassConstructor
67 nsIID mIID; // eTypeInterface, eTypeClassProto
68 nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo
69 ConstructorAlias* mAlias; // eTypeExternalConstructorAlias
70 nsCID mCID; // All other types except eTypeNewDOMBinding
73 // For new style DOM bindings.
74 union {
75 mozilla::dom::DefineInterface mDefineDOMInterface; // for window
76 mozilla::dom::ConstructNavigatorProperty mConstructNavigatorProperty; // for navigator
78 // May be null if enabled unconditionally
79 mozilla::dom::ConstructorEnabled* mConstructorEnabled;
83 class nsIScriptContext;
84 class nsICategoryManager;
85 class GlobalNameMapEntry;
88 class nsScriptNameSpaceManager : public nsIObserver,
89 public nsSupportsWeakReference,
90 public nsIMemoryReporter
92 public:
93 NS_DECL_ISUPPORTS
94 NS_DECL_NSIOBSERVER
95 NS_DECL_NSIMEMORYREPORTER
97 nsScriptNameSpaceManager();
99 nsresult Init();
101 // Returns a nsGlobalNameStruct for aName, or null if one is not
102 // found. The returned nsGlobalNameStruct is only guaranteed to be
103 // valid until the next call to any of the methods in this class.
104 // It also returns a pointer to the string buffer of the classname
105 // in the nsGlobalNameStruct.
106 const nsGlobalNameStruct* LookupName(const nsAString& aName,
107 const char16_t **aClassName = nullptr)
109 return LookupNameInternal(aName, aClassName);
112 // Returns a nsGlobalNameStruct for the navigator property aName, or
113 // null if one is not found. The returned nsGlobalNameStruct is only
114 // guaranteed to be valid until the next call to any of the methods
115 // in this class.
116 const nsGlobalNameStruct* LookupNavigatorName(const nsAString& aName);
118 nsresult RegisterClassName(const char *aClassName,
119 int32_t aDOMClassInfoID,
120 bool aPrivileged,
121 bool aXBLAllowed,
122 const char16_t **aResult);
124 nsresult RegisterClassProto(const char *aClassName,
125 const nsIID *aConstructorProtoIID,
126 bool *aFoundOld);
128 nsresult RegisterExternalInterfaces(bool aAsProto);
130 nsresult RegisterExternalClassName(const char *aClassName,
131 nsCID& aCID);
133 // Register the info for an external class. aName must be static
134 // data, it will not be deleted by the DOM code.
135 nsresult RegisterDOMCIData(const char *aName,
136 nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
137 const nsIID *aProtoChainInterface,
138 const nsIID **aInterfaces,
139 uint32_t aScriptableFlags,
140 bool aHasClassInterface,
141 const nsCID *aConstructorCID);
143 nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct);
145 void RegisterDefineDOMInterface(const nsAFlatString& aName,
146 mozilla::dom::DefineInterface aDefineDOMInterface,
147 mozilla::dom::ConstructorEnabled* aConstructorEnabled);
148 template<size_t N>
149 void RegisterDefineDOMInterface(const char16_t (&aKey)[N],
150 mozilla::dom::DefineInterface aDefineDOMInterface,
151 mozilla::dom::ConstructorEnabled* aConstructorEnabled)
153 nsLiteralString key(aKey);
154 return RegisterDefineDOMInterface(key, aDefineDOMInterface,
155 aConstructorEnabled);
158 void RegisterNavigatorDOMConstructor(const nsAFlatString& aName,
159 mozilla::dom::ConstructNavigatorProperty aNavConstructor,
160 mozilla::dom::ConstructorEnabled* aConstructorEnabled);
161 template<size_t N>
162 void RegisterNavigatorDOMConstructor(const char16_t (&aKey)[N],
163 mozilla::dom::ConstructNavigatorProperty aNavConstructor,
164 mozilla::dom::ConstructorEnabled* aConstructorEnabled)
166 nsLiteralString key(aKey);
167 return RegisterNavigatorDOMConstructor(key, aNavConstructor,
168 aConstructorEnabled);
171 typedef PLDHashOperator
172 (* NameEnumerator)(const nsAString& aGlobalName,
173 const nsGlobalNameStruct& aGlobalNameStruct,
174 void* aClosure);
176 void EnumerateGlobalNames(NameEnumerator aEnumerator,
177 void* aClosure);
178 void EnumerateNavigatorNames(NameEnumerator aEnumerator,
179 void* aClosure);
181 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
183 private:
184 virtual ~nsScriptNameSpaceManager();
186 // Adds a new entry to the hash and returns the nsGlobalNameStruct
187 // that aKey will be mapped to. If mType in the returned
188 // nsGlobalNameStruct is != eTypeNotInitialized, an entry for aKey
189 // already existed.
190 nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const nsAString *aKey,
191 const char16_t **aClassName = nullptr);
192 nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const char *aKey,
193 const char16_t **aClassName = nullptr)
195 NS_ConvertASCIItoUTF16 key(aKey);
196 return AddToHash(aTable, &key, aClassName);
198 // Removes an existing entry from the hash.
199 void RemoveFromHash(PLDHashTable *aTable, const nsAString *aKey);
201 nsresult FillHash(nsICategoryManager *aCategoryManager,
202 const char *aCategory);
203 nsresult RegisterInterface(const char* aIfName,
204 const nsIID *aIfIID,
205 bool* aFoundOld);
208 * Add a new category entry into the hash table.
209 * Only some categories can be added (see the beginning of the definition).
210 * The other ones will be ignored.
212 * @aCategoryManager Instance of the category manager service.
213 * @aCategory Category where the entry comes from.
214 * @aEntry The entry that should be added.
216 nsresult AddCategoryEntryToHash(nsICategoryManager* aCategoryManager,
217 const char* aCategory,
218 nsISupports* aEntry);
221 * Remove an existing category entry from the hash table.
222 * Only some categories can be removed (see the beginning of the definition).
223 * The other ones will be ignored.
225 * @aCategory Category where the entry will be removed from.
226 * @aEntry The entry that should be removed.
228 nsresult RemoveCategoryEntryFromHash(nsICategoryManager* aCategoryManager,
229 const char* aCategory,
230 nsISupports* aEntry);
232 // common helper for AddCategoryEntryToHash and RemoveCategoryEntryFromHash
233 nsresult OperateCategoryEntryHash(nsICategoryManager* aCategoryManager,
234 const char* aCategory,
235 nsISupports* aEntry,
236 bool aRemove);
238 nsGlobalNameStruct* LookupNameInternal(const nsAString& aName,
239 const char16_t **aClassName = nullptr);
241 PLDHashTable mGlobalNames;
242 PLDHashTable mNavigatorNames;
244 bool mIsInitialized;
247 #endif /* nsScriptNameSpaceManager_h__ */