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