1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsScriptNameSpaceManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,248 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + * 1.10 + * 1.11 + * This Original Code has been modified by IBM Corporation. 1.12 + * Modifications made by IBM described herein are 1.13 + * Copyright (c) International Business Machines 1.14 + * Corporation, 2000 1.15 + * 1.16 + * Modifications to Mozilla code or documentation 1.17 + * identified per MPL Section 3.3 1.18 + * 1.19 + * Date Modified by Description of modification 1.20 + * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink 1.21 + * use in OS2 1.22 + */ 1.23 + 1.24 +#ifndef nsScriptNameSpaceManager_h__ 1.25 +#define nsScriptNameSpaceManager_h__ 1.26 + 1.27 +#include "mozilla/MemoryReporting.h" 1.28 +#include "nsIMemoryReporter.h" 1.29 +#include "nsIScriptNameSpaceManager.h" 1.30 +#include "nsString.h" 1.31 +#include "nsID.h" 1.32 +#include "pldhash.h" 1.33 +#include "nsDOMClassInfo.h" 1.34 +#include "nsIObserver.h" 1.35 +#include "nsWeakReference.h" 1.36 +#include "xpcpublic.h" 1.37 + 1.38 + 1.39 +struct nsGlobalNameStruct 1.40 +{ 1.41 + struct ConstructorAlias 1.42 + { 1.43 + nsCID mCID; 1.44 + nsString mProtoName; 1.45 + nsGlobalNameStruct* mProto; 1.46 + }; 1.47 + 1.48 + enum nametype { 1.49 + eTypeNotInitialized, 1.50 + eTypeNewDOMBinding, 1.51 + eTypeInterface, 1.52 + eTypeProperty, 1.53 + eTypeNavigatorProperty, 1.54 + eTypeExternalConstructor, 1.55 + eTypeStaticNameSet, 1.56 + eTypeClassConstructor, 1.57 + eTypeClassProto, 1.58 + eTypeExternalClassInfoCreator, 1.59 + eTypeExternalClassInfo, 1.60 + eTypeExternalConstructorAlias 1.61 + } mType; 1.62 + 1.63 + // mChromeOnly is only used for structs that define non-WebIDL things 1.64 + // (possibly in addition to WebIDL ones). In particular, it's not even 1.65 + // initialized for eTypeNewDOMBinding structs. 1.66 + bool mChromeOnly : 1; 1.67 + bool mAllowXBL : 1; 1.68 + 1.69 + union { 1.70 + int32_t mDOMClassInfoID; // eTypeClassConstructor 1.71 + nsIID mIID; // eTypeInterface, eTypeClassProto 1.72 + nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo 1.73 + ConstructorAlias* mAlias; // eTypeExternalConstructorAlias 1.74 + nsCID mCID; // All other types except eTypeNewDOMBinding 1.75 + }; 1.76 + 1.77 + // For new style DOM bindings. 1.78 + union { 1.79 + mozilla::dom::DefineInterface mDefineDOMInterface; // for window 1.80 + mozilla::dom::ConstructNavigatorProperty mConstructNavigatorProperty; // for navigator 1.81 + }; 1.82 + // May be null if enabled unconditionally 1.83 + mozilla::dom::ConstructorEnabled* mConstructorEnabled; 1.84 +}; 1.85 + 1.86 + 1.87 +class nsIScriptContext; 1.88 +class nsICategoryManager; 1.89 +class GlobalNameMapEntry; 1.90 + 1.91 + 1.92 +class nsScriptNameSpaceManager : public nsIObserver, 1.93 + public nsSupportsWeakReference, 1.94 + public nsIMemoryReporter 1.95 +{ 1.96 +public: 1.97 + NS_DECL_ISUPPORTS 1.98 + NS_DECL_NSIOBSERVER 1.99 + NS_DECL_NSIMEMORYREPORTER 1.100 + 1.101 + nsScriptNameSpaceManager(); 1.102 + virtual ~nsScriptNameSpaceManager(); 1.103 + 1.104 + nsresult Init(); 1.105 + nsresult InitForContext(nsIScriptContext *aContext); 1.106 + 1.107 + // Returns a nsGlobalNameStruct for aName, or null if one is not 1.108 + // found. The returned nsGlobalNameStruct is only guaranteed to be 1.109 + // valid until the next call to any of the methods in this class. 1.110 + // It also returns a pointer to the string buffer of the classname 1.111 + // in the nsGlobalNameStruct. 1.112 + const nsGlobalNameStruct* LookupName(const nsAString& aName, 1.113 + const char16_t **aClassName = nullptr) 1.114 + { 1.115 + return LookupNameInternal(aName, aClassName); 1.116 + } 1.117 + 1.118 + // Returns a nsGlobalNameStruct for the navigator property aName, or 1.119 + // null if one is not found. The returned nsGlobalNameStruct is only 1.120 + // guaranteed to be valid until the next call to any of the methods 1.121 + // in this class. 1.122 + const nsGlobalNameStruct* LookupNavigatorName(const nsAString& aName); 1.123 + 1.124 + nsresult RegisterClassName(const char *aClassName, 1.125 + int32_t aDOMClassInfoID, 1.126 + bool aPrivileged, 1.127 + bool aXBLAllowed, 1.128 + const char16_t **aResult); 1.129 + 1.130 + nsresult RegisterClassProto(const char *aClassName, 1.131 + const nsIID *aConstructorProtoIID, 1.132 + bool *aFoundOld); 1.133 + 1.134 + nsresult RegisterExternalInterfaces(bool aAsProto); 1.135 + 1.136 + nsresult RegisterExternalClassName(const char *aClassName, 1.137 + nsCID& aCID); 1.138 + 1.139 + // Register the info for an external class. aName must be static 1.140 + // data, it will not be deleted by the DOM code. 1.141 + nsresult RegisterDOMCIData(const char *aName, 1.142 + nsDOMClassInfoExternalConstructorFnc aConstructorFptr, 1.143 + const nsIID *aProtoChainInterface, 1.144 + const nsIID **aInterfaces, 1.145 + uint32_t aScriptableFlags, 1.146 + bool aHasClassInterface, 1.147 + const nsCID *aConstructorCID); 1.148 + 1.149 + nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct); 1.150 + 1.151 + void RegisterDefineDOMInterface(const nsAFlatString& aName, 1.152 + mozilla::dom::DefineInterface aDefineDOMInterface, 1.153 + mozilla::dom::ConstructorEnabled* aConstructorEnabled); 1.154 + template<size_t N> 1.155 + void RegisterDefineDOMInterface(const char16_t (&aKey)[N], 1.156 + mozilla::dom::DefineInterface aDefineDOMInterface, 1.157 + mozilla::dom::ConstructorEnabled* aConstructorEnabled) 1.158 + { 1.159 + nsLiteralString key(aKey); 1.160 + return RegisterDefineDOMInterface(key, aDefineDOMInterface, 1.161 + aConstructorEnabled); 1.162 + } 1.163 + 1.164 + void RegisterNavigatorDOMConstructor(const nsAFlatString& aName, 1.165 + mozilla::dom::ConstructNavigatorProperty aNavConstructor, 1.166 + mozilla::dom::ConstructorEnabled* aConstructorEnabled); 1.167 + template<size_t N> 1.168 + void RegisterNavigatorDOMConstructor(const char16_t (&aKey)[N], 1.169 + mozilla::dom::ConstructNavigatorProperty aNavConstructor, 1.170 + mozilla::dom::ConstructorEnabled* aConstructorEnabled) 1.171 + { 1.172 + nsLiteralString key(aKey); 1.173 + return RegisterNavigatorDOMConstructor(key, aNavConstructor, 1.174 + aConstructorEnabled); 1.175 + } 1.176 + 1.177 + typedef PLDHashOperator 1.178 + (* NameEnumerator)(const nsAString& aGlobalName, 1.179 + const nsGlobalNameStruct& aGlobalNameStruct, 1.180 + void* aClosure); 1.181 + 1.182 + void EnumerateGlobalNames(NameEnumerator aEnumerator, 1.183 + void* aClosure); 1.184 + void EnumerateNavigatorNames(NameEnumerator aEnumerator, 1.185 + void* aClosure); 1.186 + 1.187 + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); 1.188 + 1.189 +private: 1.190 + // Adds a new entry to the hash and returns the nsGlobalNameStruct 1.191 + // that aKey will be mapped to. If mType in the returned 1.192 + // nsGlobalNameStruct is != eTypeNotInitialized, an entry for aKey 1.193 + // already existed. 1.194 + nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const nsAString *aKey, 1.195 + const char16_t **aClassName = nullptr); 1.196 + nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const char *aKey, 1.197 + const char16_t **aClassName = nullptr) 1.198 + { 1.199 + NS_ConvertASCIItoUTF16 key(aKey); 1.200 + return AddToHash(aTable, &key, aClassName); 1.201 + } 1.202 + // Removes an existing entry from the hash. 1.203 + void RemoveFromHash(PLDHashTable *aTable, const nsAString *aKey); 1.204 + 1.205 + nsresult FillHash(nsICategoryManager *aCategoryManager, 1.206 + const char *aCategory); 1.207 + nsresult RegisterInterface(const char* aIfName, 1.208 + const nsIID *aIfIID, 1.209 + bool* aFoundOld); 1.210 + 1.211 + /** 1.212 + * Add a new category entry into the hash table. 1.213 + * Only some categories can be added (see the beginning of the definition). 1.214 + * The other ones will be ignored. 1.215 + * 1.216 + * @aCategoryManager Instance of the category manager service. 1.217 + * @aCategory Category where the entry comes from. 1.218 + * @aEntry The entry that should be added. 1.219 + */ 1.220 + nsresult AddCategoryEntryToHash(nsICategoryManager* aCategoryManager, 1.221 + const char* aCategory, 1.222 + nsISupports* aEntry); 1.223 + 1.224 + /** 1.225 + * Remove an existing category entry from the hash table. 1.226 + * Only some categories can be removed (see the beginning of the definition). 1.227 + * The other ones will be ignored. 1.228 + * 1.229 + * @aCategory Category where the entry will be removed from. 1.230 + * @aEntry The entry that should be removed. 1.231 + */ 1.232 + nsresult RemoveCategoryEntryFromHash(nsICategoryManager* aCategoryManager, 1.233 + const char* aCategory, 1.234 + nsISupports* aEntry); 1.235 + 1.236 + // common helper for AddCategoryEntryToHash and RemoveCategoryEntryFromHash 1.237 + nsresult OperateCategoryEntryHash(nsICategoryManager* aCategoryManager, 1.238 + const char* aCategory, 1.239 + nsISupports* aEntry, 1.240 + bool aRemove); 1.241 + 1.242 + nsGlobalNameStruct* LookupNameInternal(const nsAString& aName, 1.243 + const char16_t **aClassName = nullptr); 1.244 + 1.245 + PLDHashTable mGlobalNames; 1.246 + PLDHashTable mNavigatorNames; 1.247 + 1.248 + bool mIsInitialized; 1.249 +}; 1.250 + 1.251 +#endif /* nsScriptNameSpaceManager_h__ */