1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK *****
38 : *
39 : *
40 : * This Original Code has been modified by IBM Corporation.
41 : * Modifications made by IBM described herein are
42 : * Copyright (c) International Business Machines
43 : * Corporation, 2000
44 : *
45 : * Modifications to Mozilla code or documentation
46 : * identified per MPL Section 3.3
47 : *
48 : * Date Modified by Description of modification
49 : * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
50 : * use in OS2
51 : */
52 :
53 : #ifndef nsScriptNameSpaceManager_h__
54 : #define nsScriptNameSpaceManager_h__
55 :
56 : #include "nsIScriptNameSpaceManager.h"
57 : #include "nsString.h"
58 : #include "nsID.h"
59 : #include "pldhash.h"
60 : #include "nsDOMClassInfo.h"
61 : #include "nsIObserver.h"
62 : #include "nsWeakReference.h"
63 :
64 :
65 : struct nsGlobalNameStruct
66 : {
67 : struct ConstructorAlias
68 1833 : {
69 : nsCID mCID;
70 : nsString mProtoName;
71 : nsGlobalNameStruct* mProto;
72 : };
73 :
74 : enum nametype {
75 : eTypeNotInitialized,
76 : eTypeInterface,
77 : eTypeProperty,
78 : eTypeNavigatorProperty,
79 : eTypeExternalConstructor,
80 : eTypeStaticNameSet,
81 : eTypeDynamicNameSet,
82 : eTypeClassConstructor,
83 : eTypeClassProto,
84 : eTypeExternalClassInfoCreator,
85 : eTypeExternalClassInfo,
86 : eTypeExternalConstructorAlias
87 : } mType;
88 :
89 : bool mChromeOnly;
90 : bool mDisabled;
91 :
92 : union {
93 : PRInt32 mDOMClassInfoID; // eTypeClassConstructor
94 : nsIID mIID; // eTypeInterface, eTypeClassProto
95 : nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo
96 : ConstructorAlias* mAlias; // eTypeExternalConstructorAlias
97 : nsCID mCID; // All other types...
98 : };
99 :
100 : private:
101 :
102 : // copy constructor
103 : };
104 :
105 :
106 : class nsIScriptContext;
107 : class nsICategoryManager;
108 : class GlobalNameMapEntry;
109 :
110 :
111 : class nsScriptNameSpaceManager : public nsIObserver,
112 : public nsSupportsWeakReference
113 : {
114 : public:
115 : NS_DECL_ISUPPORTS
116 : NS_DECL_NSIOBSERVER
117 :
118 : nsScriptNameSpaceManager();
119 : virtual ~nsScriptNameSpaceManager();
120 :
121 : nsresult Init();
122 : nsresult InitForContext(nsIScriptContext *aContext);
123 :
124 : // Returns a nsGlobalNameStruct for aName, or null if one is not
125 : // found. The returned nsGlobalNameStruct is only guaranteed to be
126 : // valid until the next call to any of the methods in this class.
127 : // It also returns a pointer to the string buffer of the classname
128 : // in the nsGlobalNameStruct.
129 : nsresult LookupName(const nsAString& aName,
130 : const nsGlobalNameStruct **aNameStruct,
131 : const PRUnichar **aClassName = nsnull);
132 : // Returns a nsGlobalNameStruct for the navigator property aName, or
133 : // null if one is not found. The returned nsGlobalNameStruct is only
134 : // guaranteed to be valid until the next call to any of the methods
135 : // in this class.
136 : nsresult LookupNavigatorName(const nsAString& aName,
137 : const nsGlobalNameStruct **aNameStruct);
138 :
139 : nsresult RegisterClassName(const char *aClassName,
140 : PRInt32 aDOMClassInfoID,
141 : bool aPrivileged,
142 : bool aDisabled,
143 : const PRUnichar **aResult);
144 :
145 : nsresult RegisterClassProto(const char *aClassName,
146 : const nsIID *aConstructorProtoIID,
147 : bool *aFoundOld);
148 :
149 : nsresult RegisterExternalInterfaces(bool aAsProto);
150 :
151 : nsresult RegisterExternalClassName(const char *aClassName,
152 : nsCID& aCID);
153 :
154 : // Register the info for an external class. aName must be static
155 : // data, it will not be deleted by the DOM code.
156 : nsresult RegisterDOMCIData(const char *aName,
157 : nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
158 : const nsIID *aProtoChainInterface,
159 : const nsIID **aInterfaces,
160 : PRUint32 aScriptableFlags,
161 : bool aHasClassInterface,
162 : const nsCID *aConstructorCID);
163 :
164 : nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct);
165 :
166 : protected:
167 : // Adds a new entry to the hash and returns the nsGlobalNameStruct
168 : // that aKey will be mapped to. If mType in the returned
169 : // nsGlobalNameStruct is != eTypeNotInitialized, an entry for aKey
170 : // already existed.
171 : nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const char *aKey,
172 : const PRUnichar **aClassName = nsnull);
173 :
174 : nsresult FillHash(nsICategoryManager *aCategoryManager,
175 : const char *aCategory);
176 : nsresult FillHashWithDOMInterfaces();
177 : nsresult RegisterInterface(const char* aIfName,
178 : const nsIID *aIfIID,
179 : bool* aFoundOld);
180 :
181 : /**
182 : * Add a new category entry into the hash table.
183 : * Only some categories can be added (see the beginning of the definition).
184 : * The other ones will be ignored.
185 : *
186 : * @aCategoryManager Instance of the category manager service.
187 : * @aCategory Category where the entry comes from.
188 : * @aEntry The entry that should be added.
189 : */
190 : nsresult AddCategoryEntryToHash(nsICategoryManager* aCategoryManager,
191 : const char* aCategory,
192 : nsISupports* aEntry);
193 :
194 : PLDHashTable mGlobalNames;
195 : PLDHashTable mNavigatorNames;
196 :
197 : bool mIsInitialized;
198 : };
199 :
200 : #endif /* nsScriptNameSpaceManager_h__ */
|