michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: set ts=2 sw=2 et tw=78: michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: * michael@0: * michael@0: * This Original Code has been modified by IBM Corporation. michael@0: * Modifications made by IBM described herein are michael@0: * Copyright (c) International Business Machines michael@0: * Corporation, 2000 michael@0: * michael@0: * Modifications to Mozilla code or documentation michael@0: * identified per MPL Section 3.3 michael@0: * michael@0: * Date Modified by Description of modification michael@0: * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink michael@0: * use in OS2 michael@0: */ michael@0: michael@0: #include "nsDOMScriptObjectFactory.h" michael@0: #include "nsScriptNameSpaceManager.h" michael@0: #include "nsIObserverService.h" michael@0: #include "nsJSEnvironment.h" michael@0: #include "nsGlobalWindow.h" michael@0: #include "nsCRT.h" michael@0: #ifdef MOZ_XUL michael@0: #include "nsXULPrototypeCache.h" michael@0: #endif michael@0: #include "nsThreadUtils.h" michael@0: michael@0: using mozilla::dom::GetNameSpaceManager; michael@0: michael@0: nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() michael@0: { michael@0: nsCOMPtr observerService = michael@0: mozilla::services::GetObserverService(); michael@0: if (observerService) { michael@0: observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); michael@0: } michael@0: michael@0: } michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory) michael@0: NS_INTERFACE_MAP_ENTRY(nsIObserver) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: michael@0: NS_IMPL_ADDREF(nsDOMScriptObjectFactory) michael@0: NS_IMPL_RELEASE(nsDOMScriptObjectFactory) michael@0: michael@0: NS_IMETHODIMP_(nsISupports *) michael@0: nsDOMScriptObjectFactory::GetClassInfoInstance(nsDOMClassInfoID aID) michael@0: { michael@0: return NS_GetDOMClassInfoInstance(aID); michael@0: } michael@0: michael@0: NS_IMETHODIMP_(nsISupports *) michael@0: nsDOMScriptObjectFactory::GetExternalClassInfoInstance(const nsAString& aName) michael@0: { michael@0: nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); michael@0: NS_ENSURE_TRUE(nameSpaceManager, nullptr); michael@0: michael@0: const nsGlobalNameStruct *globalStruct = nameSpaceManager->LookupName(aName); michael@0: if (globalStruct) { michael@0: if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) { michael@0: nsresult rv; michael@0: nsCOMPtr creator(do_CreateInstance(globalStruct->mCID, &rv)); michael@0: NS_ENSURE_SUCCESS(rv, nullptr); michael@0: michael@0: rv = creator->RegisterDOMCI(NS_ConvertUTF16toUTF8(aName).get(), this); michael@0: NS_ENSURE_SUCCESS(rv, nullptr); michael@0: michael@0: globalStruct = nameSpaceManager->LookupName(aName); michael@0: NS_ENSURE_TRUE(globalStruct, nullptr); michael@0: michael@0: NS_ASSERTION(globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo, michael@0: "The classinfo data for this class didn't get registered."); michael@0: } michael@0: if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { michael@0: return nsDOMClassInfo::GetClassInfoInstance(globalStruct->mData); michael@0: } michael@0: } michael@0: return nullptr; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDOMScriptObjectFactory::Observe(nsISupports *aSubject, michael@0: const char *aTopic, michael@0: const char16_t *someData) michael@0: { michael@0: if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { michael@0: #ifdef MOZ_XUL michael@0: // Flush the XUL cache since it holds JS roots, and we're about to michael@0: // start the final GC. michael@0: nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); michael@0: michael@0: if (cache) michael@0: cache->Flush(); michael@0: #endif michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName, michael@0: nsDOMClassInfoExternalConstructorFnc aConstructorFptr, michael@0: const nsIID *aProtoChainInterface, michael@0: const nsIID **aInterfaces, michael@0: uint32_t aScriptableFlags, michael@0: bool aHasClassInterface, michael@0: const nsCID *aConstructorCID) michael@0: { michael@0: nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); michael@0: NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED); michael@0: michael@0: return nameSpaceManager->RegisterDOMCIData(aName, michael@0: aConstructorFptr, michael@0: aProtoChainInterface, michael@0: aInterfaces, michael@0: aScriptableFlags, michael@0: aHasClassInterface, michael@0: aConstructorCID); michael@0: }