2013-01-15 04:26:47 +04: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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
1998-12-21 19:51:10 +03:00
|
|
|
|
|
|
|
#include "nsScriptNameSpaceManager.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2004-11-01 21:50:36 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIScriptNameSpaceManager.h"
|
2002-01-17 08:09:55 +03:00
|
|
|
#include "nsIScriptContext.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsIInterfaceInfoManager.h"
|
|
|
|
#include "nsIInterfaceInfo.h"
|
|
|
|
#include "xptinfo.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2013-05-02 05:44:44 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2001-03-27 15:17:17 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2005-08-15 22:29:55 +04:00
|
|
|
#include "nsHashKeys.h"
|
2002-03-04 05:25:08 +03:00
|
|
|
#include "nsDOMClassInfo.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2010-11-17 01:09:50 +03:00
|
|
|
#include "nsIObserverService.h"
|
2013-09-23 21:29:27 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2013-05-02 05:44:44 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-05-02 05:44:44 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-12-09 23:35:37 +04:00
|
|
|
#include "mozilla/Services.h"
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
#define NS_INTERFACE_PREFIX "nsI"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#define NS_DOM_INTERFACE_PREFIX "nsIDOM"
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2012-03-13 02:53:18 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2002-01-17 07:08:14 +03:00
|
|
|
GlobalNameHashHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsAString *str = static_cast<const nsAString *>(key);
|
2002-01-17 07:08:14 +03:00
|
|
|
return HashString(*str);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2002-01-17 07:08:14 +03:00
|
|
|
GlobalNameHashMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const GlobalNameMapEntry *e =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const GlobalNameMapEntry *>(entry);
|
|
|
|
const nsAString *str = static_cast<const nsAString *>(key);
|
2002-01-17 07:08:14 +03:00
|
|
|
|
|
|
|
return str->Equals(e->mKey);
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2002-01-17 07:08:14 +03:00
|
|
|
GlobalNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
|
1998-12-21 19:51:10 +03:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
GlobalNameMapEntry *e = static_cast<GlobalNameMapEntry *>(entry);
|
2002-01-17 07:08:14 +03:00
|
|
|
|
|
|
|
// An entry is being cleared, let the key (nsString) do its own
|
|
|
|
// cleanup.
|
|
|
|
e->mKey.~nsString();
|
2002-03-04 05:25:08 +03:00
|
|
|
if (e->mGlobalName.mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
nsIClassInfo* ci = GET_CLEAN_CI_PTR(e->mGlobalName.mData->mCachedClassInfo);
|
|
|
|
|
|
|
|
// If we constructed an internal helper, we'll let the helper delete
|
|
|
|
// the nsDOMClassInfoData structure, if not we do it here.
|
2002-03-04 06:47:08 +03:00
|
|
|
if (!ci || e->mGlobalName.mData->u.mExternalConstructorFptr) {
|
2002-03-04 05:25:08 +03:00
|
|
|
delete e->mGlobalName.mData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release our pointer to the helper.
|
|
|
|
NS_IF_RELEASE(ci);
|
|
|
|
}
|
2002-08-30 12:48:58 +04:00
|
|
|
else if (e->mGlobalName.mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
|
|
|
|
delete e->mGlobalName.mAlias;
|
|
|
|
}
|
2002-01-17 07:08:14 +03:00
|
|
|
|
|
|
|
// This will set e->mGlobalName.mType to
|
|
|
|
// nsGlobalNameStruct::eTypeNotInitialized
|
|
|
|
memset(&e->mGlobalName, 0, sizeof(nsGlobalNameStruct));
|
1998-12-21 19:51:10 +03:00
|
|
|
}
|
|
|
|
|
2015-02-11 20:46:40 +03:00
|
|
|
static void
|
|
|
|
GlobalNameHashInitEntry(PLDHashEntryHdr *entry, const void *key)
|
1998-12-21 19:51:10 +03:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
GlobalNameMapEntry *e = static_cast<GlobalNameMapEntry *>(entry);
|
|
|
|
const nsAString *keyStr = static_cast<const nsAString *>(key);
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
// Initialize the key in the entry with placement new
|
2003-03-19 02:23:32 +03:00
|
|
|
new (&e->mKey) nsString(*keyStr);
|
2002-01-17 07:08:14 +03:00
|
|
|
|
|
|
|
// This will set e->mGlobalName.mType to
|
|
|
|
// nsGlobalNameStruct::eTypeNotInitialized
|
|
|
|
memset(&e->mGlobalName, 0, sizeof(nsGlobalNameStruct));
|
|
|
|
}
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2013-11-07 09:35:30 +04:00
|
|
|
nsScriptNameSpaceManager,
|
|
|
|
nsIObserver,
|
2013-12-08 10:09:10 +04:00
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsIMemoryReporter)
|
2010-11-17 01:09:50 +03:00
|
|
|
|
2015-05-06 02:11:43 +03:00
|
|
|
static const PLDHashTableOps hash_table_ops =
|
|
|
|
{
|
|
|
|
GlobalNameHashHashKey,
|
|
|
|
GlobalNameHashMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
GlobalNameHashClearEntry,
|
|
|
|
GlobalNameHashInitEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GLOBALNAME_HASHTABLE_INITIAL_LENGTH 512
|
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
nsScriptNameSpaceManager::nsScriptNameSpaceManager()
|
2015-05-06 02:11:43 +03:00
|
|
|
: mGlobalNames(&hash_table_ops, sizeof(GlobalNameMapEntry),
|
|
|
|
GLOBALNAME_HASHTABLE_INITIAL_LENGTH)
|
|
|
|
, mNavigatorNames(&hash_table_ops, sizeof(GlobalNameMapEntry),
|
|
|
|
GLOBALNAME_HASHTABLE_INITIAL_LENGTH)
|
2002-01-17 07:08:14 +03:00
|
|
|
{
|
2008-09-11 01:58:13 +04:00
|
|
|
MOZ_COUNT_CTOR(nsScriptNameSpaceManager);
|
1998-12-21 19:51:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsScriptNameSpaceManager::~nsScriptNameSpaceManager()
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
2015-05-06 02:11:43 +03:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2008-09-11 01:58:13 +04:00
|
|
|
MOZ_COUNT_DTOR(nsScriptNameSpaceManager);
|
2002-01-17 07:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGlobalNameStruct *
|
2012-06-14 18:56:38 +04:00
|
|
|
nsScriptNameSpaceManager::AddToHash(PLDHashTable *aTable, const nsAString *aKey,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t **aClassName)
|
2002-01-17 07:08:14 +03:00
|
|
|
{
|
2015-02-03 01:48:58 +03:00
|
|
|
GlobalNameMapEntry *entry = static_cast<GlobalNameMapEntry *>
|
|
|
|
(PL_DHashTableAdd(aTable, aKey, fallible));
|
2002-01-17 07:08:14 +03:00
|
|
|
|
|
|
|
if (!entry) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-01-17 07:08:14 +03:00
|
|
|
}
|
|
|
|
|
2009-06-03 19:30:18 +04:00
|
|
|
if (aClassName) {
|
|
|
|
*aClassName = entry->mKey.get();
|
|
|
|
}
|
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
return &entry->mGlobalName;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2013-08-22 17:44:19 +04:00
|
|
|
void
|
|
|
|
nsScriptNameSpaceManager::RemoveFromHash(PLDHashTable *aTable,
|
|
|
|
const nsAString *aKey)
|
|
|
|
{
|
2015-01-06 05:27:28 +03:00
|
|
|
PL_DHashTableRemove(aTable, aKey);
|
2013-08-22 17:44:19 +04:00
|
|
|
}
|
|
|
|
|
2002-08-30 12:48:58 +04:00
|
|
|
nsGlobalNameStruct*
|
|
|
|
nsScriptNameSpaceManager::GetConstructorProto(const nsGlobalNameStruct* aStruct)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias,
|
|
|
|
"This function only works on constructor aliases!");
|
|
|
|
if (!aStruct->mAlias->mProto) {
|
|
|
|
GlobalNameMapEntry *proto =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<GlobalNameMapEntry *>
|
2015-01-23 08:06:55 +03:00
|
|
|
(PL_DHashTableSearch(&mGlobalNames,
|
2015-01-06 05:27:28 +03:00
|
|
|
&aStruct->mAlias->mProtoName));
|
2015-01-23 08:06:55 +03:00
|
|
|
if (proto) {
|
2002-08-30 12:48:58 +04:00
|
|
|
aStruct->mAlias->mProto = &proto->mGlobalName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aStruct->mAlias->mProto;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::FillHash(nsICategoryManager *aCategoryManager,
|
2010-11-17 01:09:50 +03:00
|
|
|
const char *aCategory)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> e;
|
2010-11-17 01:09:50 +03:00
|
|
|
nsresult rv = aCategoryManager->EnumerateCategory(aCategory,
|
|
|
|
getter_AddRefs(e));
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
while (NS_SUCCEEDED(e->GetNext(getter_AddRefs(entry)))) {
|
2010-11-17 01:09:50 +03:00
|
|
|
rv = AddCategoryEntryToHash(aCategoryManager, aCategory, entry);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2010-11-17 01:09:50 +03:00
|
|
|
return rv;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
1998-12-21 19:51:10 +03:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2002-08-30 12:48:58 +04:00
|
|
|
return NS_OK;
|
1998-12-21 19:51:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsScriptNameSpaceManager::RegisterExternalInterfaces(bool aAsProto)
|
2002-03-04 05:25:08 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsICategoryManager> cm =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-10 19:19:44 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
2002-03-04 05:25:08 +03:00
|
|
|
NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
|
|
|
rv = cm->EnumerateCategory(JAVASCRIPT_DOM_INTERFACE,
|
|
|
|
getter_AddRefs(enumerator));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
nsXPIDLCString IID_string;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString category_entry;
|
2002-03-04 05:25:08 +03:00
|
|
|
const char* if_name;
|
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found_old, dom_prefix;
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) {
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> category(do_QueryInterface(entry));
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
if (!category) {
|
2002-08-06 04:53:19 +04:00
|
|
|
NS_WARNING("Category entry not an nsISupportsCString!");
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
rv = category->GetData(category_entry);
|
2001-05-11 09:24:12 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-08-27 01:20:34 +04:00
|
|
|
rv = cm->GetCategoryEntry(JAVASCRIPT_DOM_INTERFACE, category_entry.get(),
|
2002-03-04 05:25:08 +03:00
|
|
|
getter_Copies(IID_string));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-11 09:24:12 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
nsIID primary_IID;
|
|
|
|
if (!primary_IID.Parse(IID_string) ||
|
|
|
|
primary_IID.Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
NS_ERROR("Invalid IID registered with the script namespace manager!");
|
2001-11-02 07:41:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
2001-05-11 09:24:12 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
iim->GetInfoForIID(&primary_IID, getter_AddRefs(if_info));
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
while (if_info) {
|
|
|
|
const nsIID *iid;
|
|
|
|
if_info->GetIIDShared(&iid);
|
|
|
|
NS_ENSURE_TRUE(iid, NS_ERROR_UNEXPECTED);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
if (iid->Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if_info->GetNameShared(&if_name);
|
|
|
|
dom_prefix = (strncmp(if_name, NS_DOM_INTERFACE_PREFIX,
|
|
|
|
sizeof(NS_DOM_INTERFACE_PREFIX) - 1) == 0);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
const char* name;
|
|
|
|
if (dom_prefix) {
|
|
|
|
name = if_name + sizeof(NS_DOM_INTERFACE_PREFIX) - 1;
|
|
|
|
} else {
|
|
|
|
name = if_name + sizeof(NS_INTERFACE_PREFIX) - 1;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
if (aAsProto) {
|
|
|
|
RegisterClassProto(name, iid, &found_old);
|
|
|
|
} else {
|
2003-01-22 06:22:35 +03:00
|
|
|
RegisterInterface(name, iid, &found_old);
|
2002-03-04 05:25:08 +03:00
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
if (found_old) {
|
|
|
|
break;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> tmp(if_info);
|
|
|
|
tmp->GetParent(getter_AddRefs(if_info));
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
1998-12-21 19:51:10 +03:00
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-01-22 06:22:35 +03:00
|
|
|
nsScriptNameSpaceManager::RegisterInterface(const char* aIfName,
|
|
|
|
const nsIID *aIfIID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aFoundOld)
|
2002-03-04 05:25:08 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aFoundOld = false;
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aIfName);
|
2003-01-17 18:16:33 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
if (s->mType != nsGlobalNameStruct::eTypeNotInitialized &&
|
|
|
|
s->mType != nsGlobalNameStruct::eTypeNewDOMBinding) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aFoundOld = true;
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2003-01-17 18:16:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2003-01-17 18:16:33 +03:00
|
|
|
s->mType = nsGlobalNameStruct::eTypeInterface;
|
2003-01-22 06:22:35 +03:00
|
|
|
s->mIID = *aIfIID;
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::Init()
|
|
|
|
{
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterWeakMemoryReporter(this);
|
2013-01-15 04:26:47 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2013-07-30 17:26:27 +04:00
|
|
|
rv = RegisterExternalInterfaces(false);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> cm =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
rv = FillHash(cm, JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
rv = FillHash(cm, JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY);
|
2007-06-26 18:44:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
rv = FillHash(cm, JAVASCRIPT_GLOBAL_PRIVILEGED_PROPERTY_CATEGORY);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-07 09:53:08 +04:00
|
|
|
rv = FillHash(cm, JAVASCRIPT_NAVIGATOR_PROPERTY_CATEGORY);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
// Initial filling of the has table has been done.
|
|
|
|
// Now, listen for changes.
|
|
|
|
nsCOMPtr<nsIObserverService> serv =
|
2011-12-09 23:35:37 +04:00
|
|
|
mozilla::services::GetObserverService();
|
2010-11-17 01:09:50 +03:00
|
|
|
|
|
|
|
if (serv) {
|
2011-10-17 18:59:28 +04:00
|
|
|
serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID, true);
|
2013-08-22 17:44:19 +04:00
|
|
|
serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID, true);
|
2010-11-17 01:09:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-21 19:51:10 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-29 22:43:13 +04:00
|
|
|
nsGlobalNameStruct*
|
|
|
|
nsScriptNameSpaceManager::LookupNameInternal(const nsAString& aName,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t **aClassName)
|
1998-12-23 01:03:20 +03:00
|
|
|
{
|
2002-01-17 07:08:14 +03:00
|
|
|
GlobalNameMapEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<GlobalNameMapEntry *>
|
2015-01-23 08:06:55 +03:00
|
|
|
(PL_DHashTableSearch(&mGlobalNames, &aName));
|
2002-01-17 07:08:14 +03:00
|
|
|
|
2015-01-23 08:06:55 +03:00
|
|
|
if (entry) {
|
2003-01-31 15:10:13 +03:00
|
|
|
if (aClassName) {
|
|
|
|
*aClassName = entry->mKey.get();
|
|
|
|
}
|
2012-03-29 22:43:13 +04:00
|
|
|
return &entry->mGlobalName;
|
2002-01-17 07:08:14 +03:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2012-03-29 22:43:13 +04:00
|
|
|
if (aClassName) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aClassName = nullptr;
|
2012-03-29 22:43:13 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1998-12-23 01:03:20 +03:00
|
|
|
}
|
|
|
|
|
2012-12-02 12:59:51 +04:00
|
|
|
const nsGlobalNameStruct*
|
|
|
|
nsScriptNameSpaceManager::LookupNavigatorName(const nsAString& aName)
|
2011-09-06 23:01:01 +04:00
|
|
|
{
|
|
|
|
GlobalNameMapEntry *entry =
|
|
|
|
static_cast<GlobalNameMapEntry *>
|
2015-01-23 08:06:55 +03:00
|
|
|
(PL_DHashTableSearch(&mNavigatorNames, &aName));
|
2011-09-06 23:01:01 +04:00
|
|
|
|
2015-01-23 08:06:55 +03:00
|
|
|
return entry ? &entry->mGlobalName : nullptr;
|
2011-09-06 23:01:01 +04:00
|
|
|
}
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::RegisterClassName(const char *aClassName,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDOMClassInfoID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPrivileged,
|
2013-08-09 18:35:53 +04:00
|
|
|
bool aXBLAllowed,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t **aResult)
|
2001-07-11 13:09:30 +04:00
|
|
|
{
|
2002-03-04 05:25:08 +03:00
|
|
|
if (!nsCRT::IsAscii(aClassName)) {
|
|
|
|
NS_ERROR("Trying to register a non-ASCII class name");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aClassName, aResult);
|
2002-01-17 07:08:14 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2002-01-18 01:12:28 +03:00
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeClassConstructor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2002-01-18 01:12:28 +03:00
|
|
|
// If a external constructor is already defined with aClassName we
|
|
|
|
// won't overwrite it.
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2002-01-18 01:12:28 +03:00
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
|
|
|
|
return NS_OK;
|
2001-07-11 13:09:30 +04:00
|
|
|
}
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
|
2012-06-14 18:56:38 +04:00
|
|
|
s->mType == nsGlobalNameStruct::eTypeNewDOMBinding ||
|
2002-03-04 05:25:08 +03:00
|
|
|
s->mType == nsGlobalNameStruct::eTypeInterface,
|
2002-01-17 07:08:14 +03:00
|
|
|
"Whaaa, JS environment name clash!");
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeClassConstructor;
|
|
|
|
s->mDOMClassInfoID = aDOMClassInfoID;
|
2010-04-20 20:44:56 +04:00
|
|
|
s->mChromeOnly = aPrivileged;
|
2013-08-09 18:35:53 +04:00
|
|
|
s->mAllowXBL = aXBLAllowed;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::RegisterClassProto(const char *aClassName,
|
|
|
|
const nsIID *aConstructorProtoIID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aFoundOld)
|
2001-07-11 13:09:30 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aConstructorProtoIID);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aFoundOld = false;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aClassName);
|
2002-01-17 07:08:14 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
if (s->mType != nsGlobalNameStruct::eTypeNotInitialized &&
|
2012-06-14 18:56:38 +04:00
|
|
|
s->mType != nsGlobalNameStruct::eTypeNewDOMBinding &&
|
2002-01-17 07:08:14 +03:00
|
|
|
s->mType != nsGlobalNameStruct::eTypeInterface) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aFoundOld = true;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeClassProto;
|
|
|
|
s->mIID = *aConstructorProtoIID;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-04 05:25:08 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::RegisterExternalClassName(const char *aClassName,
|
|
|
|
nsCID& aCID)
|
|
|
|
{
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aClassName);
|
2002-03-04 05:25:08 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// If an external constructor is already defined with aClassName we
|
|
|
|
// won't overwrite it.
|
|
|
|
|
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
|
2012-06-14 18:56:38 +04:00
|
|
|
s->mType == nsGlobalNameStruct::eTypeNewDOMBinding ||
|
2002-03-04 05:25:08 +03:00
|
|
|
s->mType == nsGlobalNameStruct::eTypeInterface,
|
|
|
|
"Whaaa, JS environment name clash!");
|
|
|
|
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeExternalClassInfoCreator;
|
|
|
|
s->mCID = aCID;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::RegisterDOMCIData(const char *aName,
|
|
|
|
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
|
|
|
|
const nsIID *aProtoChainInterface,
|
|
|
|
const nsIID **aInterfaces,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aScriptableFlags,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHasClassInterface,
|
2002-03-04 05:25:08 +03:00
|
|
|
const nsCID *aConstructorCID)
|
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* className;
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aName, &className);
|
2002-03-04 05:25:08 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// If an external constructor is already defined with aClassName we
|
|
|
|
// won't overwrite it.
|
|
|
|
|
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeClassConstructor ||
|
|
|
|
s->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Should we bail out here?
|
|
|
|
NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
|
2012-06-14 18:56:38 +04:00
|
|
|
s->mType == nsGlobalNameStruct::eTypeNewDOMBinding ||
|
2002-03-04 05:25:08 +03:00
|
|
|
s->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator,
|
|
|
|
"Someone tries to register classinfo data for a class that isn't new or external!");
|
|
|
|
|
|
|
|
s->mData = new nsExternalDOMClassInfoData;
|
|
|
|
NS_ENSURE_TRUE(s->mData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeExternalClassInfo;
|
|
|
|
s->mData->mName = aName;
|
2009-06-03 19:30:18 +04:00
|
|
|
s->mData->mNameUTF16 = className;
|
2002-03-04 05:25:08 +03:00
|
|
|
if (aConstructorFptr)
|
2002-03-04 06:47:08 +03:00
|
|
|
s->mData->u.mExternalConstructorFptr = aConstructorFptr;
|
2002-03-04 05:25:08 +03:00
|
|
|
else
|
|
|
|
// null constructor will cause us to use nsDOMGenericSH::doCreate
|
2012-07-30 18:20:58 +04:00
|
|
|
s->mData->u.mExternalConstructorFptr = nullptr;
|
|
|
|
s->mData->mCachedClassInfo = nullptr;
|
2002-03-04 05:25:08 +03:00
|
|
|
s->mData->mProtoChainInterface = aProtoChainInterface;
|
|
|
|
s->mData->mInterfaces = aInterfaces;
|
|
|
|
s->mData->mScriptableFlags = aScriptableFlags;
|
|
|
|
s->mData->mHasClassInterface = aHasClassInterface;
|
|
|
|
s->mData->mConstructorCID = aConstructorCID;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-17 01:09:50 +03:00
|
|
|
|
|
|
|
nsresult
|
2013-08-22 17:44:19 +04:00
|
|
|
nsScriptNameSpaceManager::OperateCategoryEntryHash(nsICategoryManager* aCategoryManager,
|
|
|
|
const char* aCategory,
|
|
|
|
nsISupports* aEntry,
|
|
|
|
bool aRemove)
|
2010-11-17 01:09:50 +03:00
|
|
|
{
|
2013-08-22 17:44:19 +04:00
|
|
|
MOZ_ASSERT(aCategoryManager);
|
2011-02-03 02:46:12 +03:00
|
|
|
// Get the type from the category name.
|
|
|
|
// NOTE: we could have passed the type in FillHash() and guessed it in
|
|
|
|
// Observe() but this way, we have only one place to update and this is
|
|
|
|
// not performance sensitive.
|
|
|
|
nsGlobalNameStruct::nametype type;
|
|
|
|
if (strcmp(aCategory, JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY) == 0) {
|
|
|
|
type = nsGlobalNameStruct::eTypeExternalConstructor;
|
|
|
|
} else if (strcmp(aCategory, JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY) == 0 ||
|
|
|
|
strcmp(aCategory, JAVASCRIPT_GLOBAL_PRIVILEGED_PROPERTY_CATEGORY) == 0) {
|
|
|
|
type = nsGlobalNameStruct::eTypeProperty;
|
2011-09-06 23:01:01 +04:00
|
|
|
} else if (strcmp(aCategory, JAVASCRIPT_NAVIGATOR_PROPERTY_CATEGORY) == 0) {
|
|
|
|
type = nsGlobalNameStruct::eTypeNavigatorProperty;
|
2011-02-03 02:46:12 +03:00
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
nsCOMPtr<nsISupportsCString> strWrapper = do_QueryInterface(aEntry);
|
|
|
|
|
|
|
|
if (!strWrapper) {
|
|
|
|
NS_WARNING("Category entry not an nsISupportsCString!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString categoryEntry;
|
2010-11-17 01:09:50 +03:00
|
|
|
nsresult rv = strWrapper->GetData(categoryEntry);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-08-22 17:44:19 +04:00
|
|
|
PLDHashTable *table;
|
|
|
|
if (type == nsGlobalNameStruct::eTypeNavigatorProperty) {
|
|
|
|
table = &mNavigatorNames;
|
|
|
|
} else {
|
|
|
|
table = &mGlobalNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to handle removal before calling GetCategoryEntry
|
|
|
|
// because the category entry is already removed before we are
|
|
|
|
// notified.
|
|
|
|
if (aRemove) {
|
|
|
|
NS_ConvertASCIItoUTF16 entry(categoryEntry);
|
|
|
|
const nsGlobalNameStruct *s =
|
|
|
|
type == nsGlobalNameStruct::eTypeNavigatorProperty ?
|
|
|
|
LookupNavigatorName(entry) : LookupNameInternal(entry);
|
|
|
|
// Verify mType so that this API doesn't remove names
|
|
|
|
// registered by others.
|
|
|
|
if (!s || s->mType != type) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveFromHash(table, &entry);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
nsXPIDLCString contractId;
|
|
|
|
rv = aCategoryManager->GetCategoryEntry(aCategory, categoryEntry.get(),
|
|
|
|
getter_Copies(contractId));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-05-02 05:44:44 +04:00
|
|
|
if (type == nsGlobalNameStruct::eTypeNavigatorProperty ||
|
|
|
|
type == nsGlobalNameStruct::eTypeExternalConstructor) {
|
|
|
|
bool isNavProperty = type == nsGlobalNameStruct::eTypeNavigatorProperty;
|
|
|
|
nsPrintfCString prefName("dom.%s.disable.%s",
|
|
|
|
isNavProperty ? "navigator-property" : "global-constructor",
|
|
|
|
categoryEntry.get());
|
|
|
|
if (Preferences::GetType(prefName.get()) == nsIPrefBranch::PREF_BOOL &&
|
|
|
|
Preferences::GetBool(prefName.get(), false)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar;
|
|
|
|
rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCID *cidPtr;
|
|
|
|
rv = registrar->ContractIDToCID(contractId, &cidPtr);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Bad contract id registed with the script namespace manager");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy CID onto the stack, so we can free it right away and avoid having
|
|
|
|
// to add cleanup code at every exit point from this function.
|
|
|
|
nsCID cid = *cidPtr;
|
2015-03-27 03:01:12 +03:00
|
|
|
free(cidPtr);
|
2010-11-17 01:09:50 +03:00
|
|
|
|
|
|
|
if (type == nsGlobalNameStruct::eTypeExternalConstructor) {
|
|
|
|
nsXPIDLCString constructorProto;
|
|
|
|
rv = aCategoryManager->GetCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
|
|
|
|
categoryEntry.get(),
|
|
|
|
getter_Copies(constructorProto));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, categoryEntry.get());
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
|
|
|
|
s->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
|
2010-11-17 01:09:50 +03:00
|
|
|
s->mAlias = new nsGlobalNameStruct::ConstructorAlias;
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeExternalConstructorAlias;
|
2011-10-17 18:59:28 +04:00
|
|
|
s->mChromeOnly = false;
|
2010-11-17 01:09:50 +03:00
|
|
|
s->mAlias->mCID = cid;
|
|
|
|
AppendASCIItoUTF16(constructorProto, s->mAlias->mProtoName);
|
2012-07-30 18:20:58 +04:00
|
|
|
s->mAlias->mProto = nullptr;
|
2010-11-17 01:09:50 +03:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Global script name not overwritten!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-06 23:01:01 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(table, categoryEntry.get());
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-06-14 18:56:38 +04:00
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
|
|
|
|
s->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
|
2010-11-17 01:09:50 +03:00
|
|
|
s->mType = type;
|
|
|
|
s->mCID = cid;
|
|
|
|
s->mChromeOnly =
|
|
|
|
strcmp(aCategory, JAVASCRIPT_GLOBAL_PRIVILEGED_PROPERTY_CATEGORY) == 0;
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Global script name not overwritten!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:44:19 +04:00
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::AddCategoryEntryToHash(nsICategoryManager* aCategoryManager,
|
|
|
|
const char* aCategory,
|
|
|
|
nsISupports* aEntry)
|
|
|
|
{
|
|
|
|
return OperateCategoryEntryHash(aCategoryManager, aCategory, aEntry,
|
|
|
|
/* aRemove = */ false);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::RemoveCategoryEntryFromHash(nsICategoryManager* aCategoryManager,
|
|
|
|
const char* aCategory,
|
|
|
|
nsISupports* aEntry)
|
|
|
|
{
|
|
|
|
return OperateCategoryEntryHash(aCategoryManager, aCategory, aEntry,
|
|
|
|
/* aRemove = */ true);
|
|
|
|
}
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptNameSpaceManager::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2010-11-17 01:09:50 +03:00
|
|
|
{
|
|
|
|
if (!aData) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:44:19 +04:00
|
|
|
if (!strcmp(aTopic, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID)) {
|
2010-11-17 01:09:50 +03:00
|
|
|
nsCOMPtr<nsICategoryManager> cm =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (!cm) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AddCategoryEntryToHash(cm, NS_ConvertUTF16toUTF8(aData).get(),
|
|
|
|
aSubject);
|
2013-08-22 17:44:19 +04:00
|
|
|
} else if (!strcmp(aTopic, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID)) {
|
|
|
|
nsCOMPtr<nsICategoryManager> cm =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (!cm) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RemoveCategoryEntryFromHash(cm, NS_ConvertUTF16toUTF8(aData).get(),
|
|
|
|
aSubject);
|
2010-11-17 01:09:50 +03:00
|
|
|
}
|
|
|
|
|
2013-08-22 17:44:19 +04:00
|
|
|
// TODO: we could observe NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID
|
|
|
|
// but we are safe without it. See bug 600460.
|
2010-11-17 01:09:50 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-06-14 18:56:38 +04:00
|
|
|
nsScriptNameSpaceManager::RegisterDefineDOMInterface(const nsAFlatString& aName,
|
2012-09-05 21:37:28 +04:00
|
|
|
mozilla::dom::DefineInterface aDefineDOMInterface,
|
2013-06-13 09:12:26 +04:00
|
|
|
mozilla::dom::ConstructorEnabled* aConstructorEnabled)
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2012-06-14 18:56:38 +04:00
|
|
|
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, &aName);
|
2012-03-31 08:42:20 +04:00
|
|
|
if (s) {
|
2012-06-14 18:56:38 +04:00
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeNewDOMBinding;
|
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
s->mDefineDOMInterface = aDefineDOMInterface;
|
2013-06-13 09:12:26 +04:00
|
|
|
s->mConstructorEnabled = aConstructorEnabled;
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-05 02:18:44 +04:00
|
|
|
|
2013-05-01 00:30:25 +04:00
|
|
|
void
|
|
|
|
nsScriptNameSpaceManager::RegisterNavigatorDOMConstructor(
|
|
|
|
const nsAFlatString& aName,
|
|
|
|
mozilla::dom::ConstructNavigatorProperty aNavConstructor,
|
2013-06-13 09:12:26 +04:00
|
|
|
mozilla::dom::ConstructorEnabled* aConstructorEnabled)
|
2013-05-01 00:30:25 +04:00
|
|
|
{
|
|
|
|
nsGlobalNameStruct *s = AddToHash(&mNavigatorNames, &aName);
|
|
|
|
if (s) {
|
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
|
|
|
|
s->mType = nsGlobalNameStruct::eTypeNewDOMBinding;
|
|
|
|
}
|
|
|
|
s->mConstructNavigatorProperty = aNavConstructor;
|
2013-06-13 09:12:26 +04:00
|
|
|
s->mConstructorEnabled = aConstructorEnabled;
|
2013-05-01 00:30:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 02:18:44 +04:00
|
|
|
static size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
SizeOfEntryExcludingThis(PLDHashEntryHdr *aHdr, MallocSizeOf aMallocSizeOf,
|
2012-11-05 02:18:44 +04:00
|
|
|
void *aArg)
|
|
|
|
{
|
2013-12-08 10:09:10 +04:00
|
|
|
GlobalNameMapEntry* entry = static_cast<GlobalNameMapEntry*>(aHdr);
|
|
|
|
return entry->SizeOfExcludingThis(aMallocSizeOf);
|
2012-11-05 02:18:44 +04:00
|
|
|
}
|
|
|
|
|
2013-12-08 10:09:10 +04:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ScriptNameSpaceManagerMallocSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptNameSpaceManager::CollectReports(
|
2014-05-21 10:06:54 +04:00
|
|
|
nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize)
|
2013-11-07 09:35:30 +04:00
|
|
|
{
|
2013-12-08 10:09:10 +04:00
|
|
|
return MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/script-namespace-manager", KIND_HEAP, UNITS_BYTES,
|
|
|
|
SizeOfIncludingThis(ScriptNameSpaceManagerMallocSizeOf),
|
|
|
|
"Memory used for the script namespace manager.");
|
2013-11-07 09:35:30 +04:00
|
|
|
}
|
|
|
|
|
2012-11-05 02:18:44 +04:00
|
|
|
size_t
|
2013-11-07 09:35:30 +04:00
|
|
|
nsScriptNameSpaceManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2012-11-05 02:18:44 +04:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mGlobalNames,
|
|
|
|
SizeOfEntryExcludingThis, aMallocSizeOf);
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mNavigatorNames,
|
|
|
|
SizeOfEntryExcludingThis, aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|