michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: * michael@0: * michael@0: * This Original Code has been modified by IBM Corporation. michael@0: * Modifications made by IBM described herein are michael@0: * Copyright (c) International Business Machines michael@0: * Corporation, 2000 michael@0: * michael@0: * Modifications to Mozilla code or documentation michael@0: * identified per MPL Section 3.3 michael@0: * michael@0: * Date Modified by Description of modification michael@0: * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink michael@0: * use in OS2 michael@0: */ michael@0: michael@0: #ifndef nsScriptNameSpaceManager_h__ michael@0: #define nsScriptNameSpaceManager_h__ michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "nsIMemoryReporter.h" michael@0: #include "nsIScriptNameSpaceManager.h" michael@0: #include "nsString.h" michael@0: #include "nsID.h" michael@0: #include "pldhash.h" michael@0: #include "nsDOMClassInfo.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsWeakReference.h" michael@0: #include "xpcpublic.h" michael@0: michael@0: michael@0: struct nsGlobalNameStruct michael@0: { michael@0: struct ConstructorAlias michael@0: { michael@0: nsCID mCID; michael@0: nsString mProtoName; michael@0: nsGlobalNameStruct* mProto; michael@0: }; michael@0: michael@0: enum nametype { michael@0: eTypeNotInitialized, michael@0: eTypeNewDOMBinding, michael@0: eTypeInterface, michael@0: eTypeProperty, michael@0: eTypeNavigatorProperty, michael@0: eTypeExternalConstructor, michael@0: eTypeStaticNameSet, michael@0: eTypeClassConstructor, michael@0: eTypeClassProto, michael@0: eTypeExternalClassInfoCreator, michael@0: eTypeExternalClassInfo, michael@0: eTypeExternalConstructorAlias michael@0: } mType; michael@0: michael@0: // mChromeOnly is only used for structs that define non-WebIDL things michael@0: // (possibly in addition to WebIDL ones). In particular, it's not even michael@0: // initialized for eTypeNewDOMBinding structs. michael@0: bool mChromeOnly : 1; michael@0: bool mAllowXBL : 1; michael@0: michael@0: union { michael@0: int32_t mDOMClassInfoID; // eTypeClassConstructor michael@0: nsIID mIID; // eTypeInterface, eTypeClassProto michael@0: nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo michael@0: ConstructorAlias* mAlias; // eTypeExternalConstructorAlias michael@0: nsCID mCID; // All other types except eTypeNewDOMBinding michael@0: }; michael@0: michael@0: // For new style DOM bindings. michael@0: union { michael@0: mozilla::dom::DefineInterface mDefineDOMInterface; // for window michael@0: mozilla::dom::ConstructNavigatorProperty mConstructNavigatorProperty; // for navigator michael@0: }; michael@0: // May be null if enabled unconditionally michael@0: mozilla::dom::ConstructorEnabled* mConstructorEnabled; michael@0: }; michael@0: michael@0: michael@0: class nsIScriptContext; michael@0: class nsICategoryManager; michael@0: class GlobalNameMapEntry; michael@0: michael@0: michael@0: class nsScriptNameSpaceManager : public nsIObserver, michael@0: public nsSupportsWeakReference, michael@0: public nsIMemoryReporter michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIOBSERVER michael@0: NS_DECL_NSIMEMORYREPORTER michael@0: michael@0: nsScriptNameSpaceManager(); michael@0: virtual ~nsScriptNameSpaceManager(); michael@0: michael@0: nsresult Init(); michael@0: nsresult InitForContext(nsIScriptContext *aContext); michael@0: michael@0: // Returns a nsGlobalNameStruct for aName, or null if one is not michael@0: // found. The returned nsGlobalNameStruct is only guaranteed to be michael@0: // valid until the next call to any of the methods in this class. michael@0: // It also returns a pointer to the string buffer of the classname michael@0: // in the nsGlobalNameStruct. michael@0: const nsGlobalNameStruct* LookupName(const nsAString& aName, michael@0: const char16_t **aClassName = nullptr) michael@0: { michael@0: return LookupNameInternal(aName, aClassName); michael@0: } michael@0: michael@0: // Returns a nsGlobalNameStruct for the navigator property aName, or michael@0: // null if one is not found. The returned nsGlobalNameStruct is only michael@0: // guaranteed to be valid until the next call to any of the methods michael@0: // in this class. michael@0: const nsGlobalNameStruct* LookupNavigatorName(const nsAString& aName); michael@0: michael@0: nsresult RegisterClassName(const char *aClassName, michael@0: int32_t aDOMClassInfoID, michael@0: bool aPrivileged, michael@0: bool aXBLAllowed, michael@0: const char16_t **aResult); michael@0: michael@0: nsresult RegisterClassProto(const char *aClassName, michael@0: const nsIID *aConstructorProtoIID, michael@0: bool *aFoundOld); michael@0: michael@0: nsresult RegisterExternalInterfaces(bool aAsProto); michael@0: michael@0: nsresult RegisterExternalClassName(const char *aClassName, michael@0: nsCID& aCID); michael@0: michael@0: // Register the info for an external class. aName must be static michael@0: // data, it will not be deleted by the DOM code. michael@0: nsresult RegisterDOMCIData(const char *aName, michael@0: nsDOMClassInfoExternalConstructorFnc aConstructorFptr, michael@0: const nsIID *aProtoChainInterface, michael@0: const nsIID **aInterfaces, michael@0: uint32_t aScriptableFlags, michael@0: bool aHasClassInterface, michael@0: const nsCID *aConstructorCID); michael@0: michael@0: nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct); michael@0: michael@0: void RegisterDefineDOMInterface(const nsAFlatString& aName, michael@0: mozilla::dom::DefineInterface aDefineDOMInterface, michael@0: mozilla::dom::ConstructorEnabled* aConstructorEnabled); michael@0: template michael@0: void RegisterDefineDOMInterface(const char16_t (&aKey)[N], michael@0: mozilla::dom::DefineInterface aDefineDOMInterface, michael@0: mozilla::dom::ConstructorEnabled* aConstructorEnabled) michael@0: { michael@0: nsLiteralString key(aKey); michael@0: return RegisterDefineDOMInterface(key, aDefineDOMInterface, michael@0: aConstructorEnabled); michael@0: } michael@0: michael@0: void RegisterNavigatorDOMConstructor(const nsAFlatString& aName, michael@0: mozilla::dom::ConstructNavigatorProperty aNavConstructor, michael@0: mozilla::dom::ConstructorEnabled* aConstructorEnabled); michael@0: template michael@0: void RegisterNavigatorDOMConstructor(const char16_t (&aKey)[N], michael@0: mozilla::dom::ConstructNavigatorProperty aNavConstructor, michael@0: mozilla::dom::ConstructorEnabled* aConstructorEnabled) michael@0: { michael@0: nsLiteralString key(aKey); michael@0: return RegisterNavigatorDOMConstructor(key, aNavConstructor, michael@0: aConstructorEnabled); michael@0: } michael@0: michael@0: typedef PLDHashOperator michael@0: (* NameEnumerator)(const nsAString& aGlobalName, michael@0: const nsGlobalNameStruct& aGlobalNameStruct, michael@0: void* aClosure); michael@0: michael@0: void EnumerateGlobalNames(NameEnumerator aEnumerator, michael@0: void* aClosure); michael@0: void EnumerateNavigatorNames(NameEnumerator aEnumerator, michael@0: void* aClosure); michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); michael@0: michael@0: private: michael@0: // Adds a new entry to the hash and returns the nsGlobalNameStruct michael@0: // that aKey will be mapped to. If mType in the returned michael@0: // nsGlobalNameStruct is != eTypeNotInitialized, an entry for aKey michael@0: // already existed. michael@0: nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const nsAString *aKey, michael@0: const char16_t **aClassName = nullptr); michael@0: nsGlobalNameStruct *AddToHash(PLDHashTable *aTable, const char *aKey, michael@0: const char16_t **aClassName = nullptr) michael@0: { michael@0: NS_ConvertASCIItoUTF16 key(aKey); michael@0: return AddToHash(aTable, &key, aClassName); michael@0: } michael@0: // Removes an existing entry from the hash. michael@0: void RemoveFromHash(PLDHashTable *aTable, const nsAString *aKey); michael@0: michael@0: nsresult FillHash(nsICategoryManager *aCategoryManager, michael@0: const char *aCategory); michael@0: nsresult RegisterInterface(const char* aIfName, michael@0: const nsIID *aIfIID, michael@0: bool* aFoundOld); michael@0: michael@0: /** michael@0: * Add a new category entry into the hash table. michael@0: * Only some categories can be added (see the beginning of the definition). michael@0: * The other ones will be ignored. michael@0: * michael@0: * @aCategoryManager Instance of the category manager service. michael@0: * @aCategory Category where the entry comes from. michael@0: * @aEntry The entry that should be added. michael@0: */ michael@0: nsresult AddCategoryEntryToHash(nsICategoryManager* aCategoryManager, michael@0: const char* aCategory, michael@0: nsISupports* aEntry); michael@0: michael@0: /** michael@0: * Remove an existing category entry from the hash table. michael@0: * Only some categories can be removed (see the beginning of the definition). michael@0: * The other ones will be ignored. michael@0: * michael@0: * @aCategory Category where the entry will be removed from. michael@0: * @aEntry The entry that should be removed. michael@0: */ michael@0: nsresult RemoveCategoryEntryFromHash(nsICategoryManager* aCategoryManager, michael@0: const char* aCategory, michael@0: nsISupports* aEntry); michael@0: michael@0: // common helper for AddCategoryEntryToHash and RemoveCategoryEntryFromHash michael@0: nsresult OperateCategoryEntryHash(nsICategoryManager* aCategoryManager, michael@0: const char* aCategory, michael@0: nsISupports* aEntry, michael@0: bool aRemove); michael@0: michael@0: nsGlobalNameStruct* LookupNameInternal(const nsAString& aName, michael@0: const char16_t **aClassName = nullptr); michael@0: michael@0: PLDHashTable mGlobalNames; michael@0: PLDHashTable mNavigatorNames; michael@0: michael@0: bool mIsInitialized; michael@0: }; michael@0: michael@0: #endif /* nsScriptNameSpaceManager_h__ */