2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-21 19:51:10 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-12-21 19:51:10 +03:00
|
|
|
*
|
2001-09-26 02:43:09 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-12-21 19:51:10 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 02:43:09 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-26 02:43:09 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-26 02:43:09 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 02:43:09 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 02:43:09 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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 "nsIScriptExternalNameSet.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"
|
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"
|
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
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
// Our extended PLDHashEntryHdr
|
|
|
|
class GlobalNameMapEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Our hash table ops don't care about the order of these members
|
|
|
|
nsString mKey;
|
|
|
|
nsGlobalNameStruct mGlobalName;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2002-01-17 07:08:14 +03:00
|
|
|
GlobalNameHashInitEntry(PLDHashTable *table, 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));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-17 07:08:14 +03:00
|
|
|
}
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(nsScriptNameSpaceManager,
|
|
|
|
nsIObserver,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
nsScriptNameSpaceManager::nsScriptNameSpaceManager()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mIsInitialized(false)
|
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
|
|
|
{
|
2002-01-17 07:08:14 +03:00
|
|
|
if (mIsInitialized) {
|
|
|
|
// Destroy the hash
|
|
|
|
PL_DHashTableFinish(&mGlobalNames);
|
2011-09-06 23:01:01 +04:00
|
|
|
PL_DHashTableFinish(&mNavigatorNames);
|
2002-01-17 07:08:14 +03:00
|
|
|
}
|
2008-09-11 01:58:13 +04:00
|
|
|
MOZ_COUNT_DTOR(nsScriptNameSpaceManager);
|
2002-01-17 07:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGlobalNameStruct *
|
2011-09-06 23:01:01 +04:00
|
|
|
nsScriptNameSpaceManager::AddToHash(PLDHashTable *aTable, const char *aKey,
|
2009-06-03 19:30:18 +04:00
|
|
|
const PRUnichar **aClassName)
|
2002-01-17 07:08:14 +03:00
|
|
|
{
|
2003-12-23 18:41:10 +03:00
|
|
|
NS_ConvertASCIItoUTF16 key(aKey);
|
2002-01-17 07:08:14 +03:00
|
|
|
GlobalNameMapEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<GlobalNameMapEntry *>
|
2011-09-06 23:01:01 +04:00
|
|
|
(PL_DHashTableOperate(aTable, &key, PL_DHASH_ADD));
|
2002-01-17 07:08:14 +03:00
|
|
|
|
|
|
|
if (!entry) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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 *>
|
|
|
|
(PL_DHashTableOperate(&mGlobalNames,
|
2002-08-30 12:48:58 +04:00
|
|
|
&aStruct->mAlias->mProtoName,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
// This method enumerates over all installed interfaces (in .xpt
|
|
|
|
// files) and finds ones that start with "nsIDOM" and has constants
|
|
|
|
// defined in the interface itself (inherited constants doesn't
|
|
|
|
// count), once such an interface is found the "nsIDOM" prefix is cut
|
|
|
|
// off the name and the rest of the name is added into the hash for
|
|
|
|
// global names. This makes things like 'Node.ELEMENT_NODE' work in
|
2010-08-02 04:39:35 +04:00
|
|
|
// JS. See nsCommonWindowSH::GlobalResolve() for detais on how this is used.
|
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::FillHashWithDOMInterfaces()
|
1998-12-21 19:51:10 +03:00
|
|
|
{
|
2005-11-10 19:19:44 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
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_TRUE(iim, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
// First look for all interfaces whose name starts with nsIDOM
|
|
|
|
nsCOMPtr<nsIEnumerator> domInterfaces;
|
2002-01-17 07:08:14 +03:00
|
|
|
nsresult rv =
|
|
|
|
iim->EnumerateInterfacesWhoseNamesStartWith(NS_DOM_INTERFACE_PREFIX,
|
2002-03-04 05:25:08 +03:00
|
|
|
getter_AddRefs(domInterfaces));
|
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;
|
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
rv = domInterfaces->First();
|
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)) {
|
|
|
|
// Empty interface list?
|
|
|
|
|
2002-01-11 02:52:10 +03:00
|
|
|
NS_WARNING("What, no nsIDOM interfaces installed?");
|
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
|
|
|
|
|
|
|
return NS_OK;
|
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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found_old;
|
2002-03-04 05:25:08 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info;
|
2008-01-12 07:30:42 +03:00
|
|
|
const char *if_name = nsnull;
|
2003-01-22 06:22:35 +03:00
|
|
|
const nsIID *iid;
|
2002-03-04 05:25:08 +03:00
|
|
|
|
2002-11-25 14:21:22 +03:00
|
|
|
for ( ; domInterfaces->IsDone() == NS_ENUMERATOR_FALSE; domInterfaces->Next()) {
|
2002-03-04 05:25:08 +03:00
|
|
|
rv = domInterfaces->CurrentItem(getter_AddRefs(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
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> if_info(do_QueryInterface(entry));
|
2008-01-12 07:30:42 +03:00
|
|
|
if_info->GetNameShared(&if_name);
|
2003-01-22 06:22:35 +03:00
|
|
|
if_info->GetIIDShared(&iid);
|
2008-01-12 07:30:42 +03:00
|
|
|
rv = RegisterInterface(if_name + sizeof(NS_DOM_INTERFACE_PREFIX) - 1,
|
2003-01-22 06:22:35 +03:00
|
|
|
iid, &found_old);
|
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
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(!found_old,
|
|
|
|
"Whaaa, interface name already in hash!");
|
|
|
|
#endif
|
|
|
|
}
|
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
|
|
|
// Next, look for externally registered DOM interfaces
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = RegisterExternalInterfaces(false);
|
2001-05-11 09:24:12 +04:00
|
|
|
|
2002-03-04 05:25:08 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2001-05-11 09:24:12 +04: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;
|
|
|
|
nsCAutoString 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) {
|
|
|
|
if (!aAsProto) {
|
|
|
|
// nsIDOM* interfaces have already been registered.
|
|
|
|
break;
|
2001-11-02 07:41:37 +03:00
|
|
|
}
|
2002-03-04 05:25:08 +03:00
|
|
|
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
|
|
|
|
2003-01-17 18:16:33 +03:00
|
|
|
if (s->mType != nsGlobalNameStruct::eTypeNotInitialized) {
|
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
|
|
|
}
|
|
|
|
|
2008-06-04 02:25:31 +04:00
|
|
|
#define GLOBALNAME_HASHTABLE_INITIAL_SIZE 1024
|
|
|
|
|
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()
|
|
|
|
{
|
2002-01-17 07:08:14 +03:00
|
|
|
static PLDHashTableOps hash_table_ops =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
GlobalNameHashHashKey,
|
|
|
|
GlobalNameHashMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
GlobalNameHashClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
GlobalNameHashInitEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
mIsInitialized = PL_DHashTableInit(&mGlobalNames, &hash_table_ops, nsnull,
|
2008-06-04 02:25:31 +04:00
|
|
|
sizeof(GlobalNameMapEntry),
|
|
|
|
GLOBALNAME_HASHTABLE_INITIAL_SIZE);
|
2002-01-17 07:08:14 +03:00
|
|
|
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2011-09-06 23:01:01 +04:00
|
|
|
mIsInitialized = PL_DHashTableInit(&mNavigatorNames, &hash_table_ops, nsnull,
|
|
|
|
sizeof(GlobalNameMapEntry),
|
|
|
|
GLOBALNAME_HASHTABLE_INITIAL_SIZE);
|
|
|
|
if (!mIsInitialized) {
|
|
|
|
PL_DHashTableFinish(&mGlobalNames);
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
rv = FillHashWithDOMInterfaces();
|
|
|
|
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);
|
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
rv = FillHash(cm, JAVASCRIPT_GLOBAL_STATIC_NAMESET_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_DYNAMIC_NAMESET_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);
|
1998-12-21 19:51:10 +03:00
|
|
|
|
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 =
|
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (serv) {
|
2011-10-17 18:59:28 +04:00
|
|
|
serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID, true);
|
2010-11-17 01:09:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-21 19:51:10 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-17 02:54:59 +04:00
|
|
|
struct NameSetClosure {
|
|
|
|
nsIScriptContext* ctx;
|
|
|
|
nsresult rv;
|
|
|
|
};
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2002-01-17 07:08:14 +03:00
|
|
|
NameSetInitCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
1998-12-21 19:51:10 +03:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
GlobalNameMapEntry *entry = static_cast<GlobalNameMapEntry *>(hdr);
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
if (entry->mGlobalName.mType == nsGlobalNameStruct::eTypeStaticNameSet) {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIScriptExternalNameSet> ns =
|
|
|
|
do_CreateInstance(entry->mGlobalName.mCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PL_DHASH_NEXT);
|
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
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
NameSetClosure *closure = static_cast<NameSetClosure *>(arg);
|
2005-08-17 02:54:59 +04:00
|
|
|
closure->rv = ns->InitializeNameSet(closure->ctx);
|
|
|
|
if (NS_FAILED(closure->rv)) {
|
|
|
|
NS_ERROR("Initing external script classes failed!");
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
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
|
|
|
|
2002-01-17 07:08:14 +03:00
|
|
|
return PL_DHASH_NEXT;
|
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
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::InitForContext(nsIScriptContext *aContext)
|
1998-12-21 19:51:10 +03:00
|
|
|
{
|
2005-08-17 02:54:59 +04:00
|
|
|
NameSetClosure closure;
|
|
|
|
closure.ctx = aContext;
|
|
|
|
closure.rv = NS_OK;
|
|
|
|
PL_DHashTableEnumerate(&mGlobalNames, NameSetInitCallback, &closure);
|
1998-12-21 19:51:10 +03:00
|
|
|
|
2005-08-17 02:54:59 +04:00
|
|
|
return closure.rv;
|
1998-12-21 19:51:10 +03:00
|
|
|
}
|
1998-12-23 01:03:20 +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
|
|
|
nsresult
|
2002-01-17 07:08:14 +03:00
|
|
|
nsScriptNameSpaceManager::LookupName(const nsAString& aName,
|
2003-01-31 15:10:13 +03:00
|
|
|
const nsGlobalNameStruct **aNameStruct,
|
|
|
|
const PRUnichar **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 *>
|
|
|
|
(PL_DHashTableOperate(&mGlobalNames, &aName,
|
2002-01-17 07:08:14 +03:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
2011-04-26 16:30:17 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry) &&
|
|
|
|
!((&entry->mGlobalName)->mDisabled)) {
|
2002-01-17 07:08:14 +03:00
|
|
|
*aNameStruct = &entry->mGlobalName;
|
2003-01-31 15:10:13 +03:00
|
|
|
if (aClassName) {
|
|
|
|
*aClassName = entry->mKey.get();
|
|
|
|
}
|
2002-01-17 07:08:14 +03:00
|
|
|
} else {
|
|
|
|
*aNameStruct = nsnull;
|
2003-01-31 15:10:13 +03:00
|
|
|
if (aClassName) {
|
|
|
|
*aClassName = nsnull;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
return NS_OK;
|
1998-12-23 01:03:20 +03:00
|
|
|
}
|
|
|
|
|
2011-09-06 23:01:01 +04:00
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::LookupNavigatorName(const nsAString& aName,
|
|
|
|
const nsGlobalNameStruct **aNameStruct)
|
|
|
|
{
|
|
|
|
GlobalNameMapEntry *entry =
|
|
|
|
static_cast<GlobalNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mNavigatorNames, &aName,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry) &&
|
|
|
|
!((&entry->mGlobalName)->mDisabled)) {
|
|
|
|
*aNameStruct = &entry->mGlobalName;
|
|
|
|
} else {
|
|
|
|
*aNameStruct = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-11 13:09:30 +04:00
|
|
|
nsresult
|
|
|
|
nsScriptNameSpaceManager::RegisterClassName(const char *aClassName,
|
2009-06-03 19:30:18 +04:00
|
|
|
PRInt32 aDOMClassInfoID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPrivileged,
|
|
|
|
bool aDisabled,
|
2009-06-03 19:30:18 +04:00
|
|
|
const PRUnichar **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 ||
|
|
|
|
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;
|
2011-04-26 16:30:17 +04:00
|
|
|
s->mDisabled = aDisabled;
|
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 &&
|
|
|
|
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 ||
|
|
|
|
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,
|
|
|
|
PRUint32 aScriptableFlags,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHasClassInterface,
|
2002-03-04 05:25:08 +03:00
|
|
|
const nsCID *aConstructorCID)
|
|
|
|
{
|
2009-06-03 19:30:18 +04:00
|
|
|
const PRUnichar* 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 ||
|
|
|
|
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
|
2002-03-04 06:47:08 +03:00
|
|
|
s->mData->u.mExternalConstructorFptr = nsnull;
|
2002-03-04 05:25:08 +03:00
|
|
|
s->mData->mCachedClassInfo = nsnull;
|
|
|
|
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
|
|
|
|
nsScriptNameSpaceManager::AddCategoryEntryToHash(nsICategoryManager* aCategoryManager,
|
|
|
|
const char* aCategory,
|
|
|
|
nsISupports* aEntry)
|
|
|
|
{
|
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 if (strcmp(aCategory, JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY) == 0) {
|
|
|
|
type = nsGlobalNameStruct::eTypeStaticNameSet;
|
|
|
|
} else if (strcmp(aCategory, JAVASCRIPT_GLOBAL_DYNAMIC_NAMESET_CATEGORY) == 0) {
|
|
|
|
type = nsGlobalNameStruct::eTypeDynamicNameSet;
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString categoryEntry;
|
|
|
|
nsresult rv = strWrapper->GetData(categoryEntry);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsXPIDLCString contractId;
|
|
|
|
rv = aCategoryManager->GetCategoryEntry(aCategory, categoryEntry.get(),
|
|
|
|
getter_Copies(contractId));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
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;
|
|
|
|
nsMemory::Free(cidPtr);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
|
|
|
|
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);
|
|
|
|
s->mAlias->mProto = nsnull;
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Global script name not overwritten!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-06 23:01:01 +04:00
|
|
|
PLDHashTable *table;
|
|
|
|
if (type == nsGlobalNameStruct::eTypeNavigatorProperty) {
|
|
|
|
table = &mNavigatorNames;
|
|
|
|
} else {
|
|
|
|
table = &mGlobalNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGlobalNameStruct *s = AddToHash(table, categoryEntry.get());
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptNameSpaceManager::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (!aData) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(aTopic, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID) == 0) {
|
|
|
|
nsCOMPtr<nsICategoryManager> cm =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (!cm) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AddCategoryEntryToHash(cm, NS_ConvertUTF16toUTF8(aData).get(),
|
|
|
|
aSubject);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: we could observe NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID
|
|
|
|
// and NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID but we are safe without it.
|
|
|
|
// See bug 600460.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|