Back to index

lightning-sunbird  0.9+nobinonly
nsScriptNameSpaceManager.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK *****
00038  *
00039  *
00040  * This Original Code has been modified by IBM Corporation.
00041  * Modifications made by IBM described herein are
00042  * Copyright (c) International Business Machines
00043  * Corporation, 2000
00044  *
00045  * Modifications to Mozilla code or documentation
00046  * identified per MPL Section 3.3
00047  *
00048  * Date         Modified by     Description of modification
00049  * 03/27/2000   IBM Corp.       Added PR_CALLBACK for Optlink
00050  *                               use in OS2
00051  */
00052 
00053 #ifndef nsScriptNameSpaceManager_h__
00054 #define nsScriptNameSpaceManager_h__
00055 
00056 #include "nsIScriptNameSpaceManager.h"
00057 #include "nsString.h"
00058 #include "nsID.h"
00059 #include "pldhash.h"
00060 
00061 #include "nsDOMClassInfo.h"
00062 
00063 struct nsGlobalNameStruct
00064 {
00065   struct ConstructorAlias
00066   {
00067     nsCID mCID;
00068     nsString mProtoName;
00069     nsGlobalNameStruct* mProto;    
00070   };
00071 
00072   enum nametype {
00073     eTypeNotInitialized,
00074     eTypeInterface,
00075     eTypeProperty,
00076     eTypeExternalConstructor,
00077     eTypeStaticNameSet,
00078     eTypeDynamicNameSet,
00079     eTypeClassConstructor,
00080     eTypeClassProto,
00081     eTypeExternalClassInfoCreator,
00082     eTypeExternalClassInfo,
00083     eTypeExternalConstructorAlias
00084   } mType;
00085 
00086   union {
00087     PRInt32 mDOMClassInfoID; // eTypeClassConstructor
00088     nsIID mIID; // eTypeInterface, eTypeClassProto
00089     nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo
00090     ConstructorAlias* mAlias; // eTypeExternalConstructorAlias
00091     nsCID mCID; // All other types...
00092   };
00093 
00094 private:
00095 
00096   // copy constructor
00097 };
00098 
00099 
00100 class nsIScriptContext;
00101 class nsICategoryManager;
00102 
00103 
00104 class nsScriptNameSpaceManager
00105 {
00106 public:
00107   nsScriptNameSpaceManager();
00108   virtual ~nsScriptNameSpaceManager();
00109 
00110   nsresult Init();
00111   nsresult InitForContext(nsIScriptContext *aContext);
00112 
00113   // Returns a nsGlobalNameStruct for aName, or null if one is not
00114   // found. The returned nsGlobalNameStruct is only guaranteed to be
00115   // valid until the next call to any of the methods in this class.
00116   // It also returns a pointer to the string buffer of the classname
00117   // in the nsGlobalNameStruct.
00118   nsresult LookupName(const nsAString& aName,
00119                       const nsGlobalNameStruct **aNameStruct,
00120                       const PRUnichar **aClassName = nsnull);
00121 
00122   nsresult RegisterClassName(const char *aClassName,
00123                              PRInt32 aDOMClassInfoID);
00124 
00125   nsresult RegisterClassProto(const char *aClassName,
00126                               const nsIID *aConstructorProtoIID,
00127                               PRBool *aFoundOld);
00128 
00129   nsresult RegisterExternalInterfaces(PRBool aAsProto);
00130 
00131   nsresult RegisterExternalClassName(const char *aClassName,
00132                                      nsCID& aCID);
00133 
00134   // Register the info for an external class. aName must be static
00135   // data, it will not be deleted by the DOM code.
00136   nsresult RegisterDOMCIData(const char *aName,
00137                              nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
00138                              const nsIID *aProtoChainInterface,
00139                              const nsIID **aInterfaces,
00140                              PRUint32 aScriptableFlags,
00141                              PRBool aHasClassInterface,
00142                              const nsCID *aConstructorCID);
00143 
00144   nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct);
00145 
00146 protected:
00147   // Adds a new entry to the hash and returns the nsGlobalNameStruct
00148   // that aKey will be mapped to. If mType in the returned
00149   // nsGlobalNameStruct is != eTypeNotInitialized, an entry for aKey
00150   // already existed.
00151   nsGlobalNameStruct *AddToHash(const char *aKey);
00152 
00153   nsresult FillHash(nsICategoryManager *aCategoryManager,
00154                     const char *aCategory,
00155                     nsGlobalNameStruct::nametype aType);
00156   nsresult FillHashWithDOMInterfaces();
00157   nsresult RegisterInterface(const char* aIfName,
00158                              const nsIID *aIfIID,
00159                              PRBool* aFoundOld);
00160 
00161   // Inline PLDHashTable, init with PL_DHashTableInit() and delete
00162   // with PL_DHashTableFinish().
00163   PLDHashTable mGlobalNames;
00164 
00165   PRPackedBool mIsInitialized;
00166 };
00167 
00168 #endif /* nsScriptNameSpaceManager_h__ */