1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsDOMScriptObjectFactory.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: set ts=2 sw=2 et tw=78: 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 + * 1.11 + * 1.12 + * This Original Code has been modified by IBM Corporation. 1.13 + * Modifications made by IBM described herein are 1.14 + * Copyright (c) International Business Machines 1.15 + * Corporation, 2000 1.16 + * 1.17 + * Modifications to Mozilla code or documentation 1.18 + * identified per MPL Section 3.3 1.19 + * 1.20 + * Date Modified by Description of modification 1.21 + * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink 1.22 + * use in OS2 1.23 + */ 1.24 + 1.25 +#include "nsDOMScriptObjectFactory.h" 1.26 +#include "nsScriptNameSpaceManager.h" 1.27 +#include "nsIObserverService.h" 1.28 +#include "nsJSEnvironment.h" 1.29 +#include "nsGlobalWindow.h" 1.30 +#include "nsCRT.h" 1.31 +#ifdef MOZ_XUL 1.32 +#include "nsXULPrototypeCache.h" 1.33 +#endif 1.34 +#include "nsThreadUtils.h" 1.35 + 1.36 +using mozilla::dom::GetNameSpaceManager; 1.37 + 1.38 +nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() 1.39 +{ 1.40 + nsCOMPtr<nsIObserverService> observerService = 1.41 + mozilla::services::GetObserverService(); 1.42 + if (observerService) { 1.43 + observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); 1.44 + } 1.45 + 1.46 +} 1.47 + 1.48 +NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory) 1.49 + NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory) 1.50 + NS_INTERFACE_MAP_ENTRY(nsIObserver) 1.51 + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory) 1.52 +NS_INTERFACE_MAP_END 1.53 + 1.54 + 1.55 +NS_IMPL_ADDREF(nsDOMScriptObjectFactory) 1.56 +NS_IMPL_RELEASE(nsDOMScriptObjectFactory) 1.57 + 1.58 +NS_IMETHODIMP_(nsISupports *) 1.59 +nsDOMScriptObjectFactory::GetClassInfoInstance(nsDOMClassInfoID aID) 1.60 +{ 1.61 + return NS_GetDOMClassInfoInstance(aID); 1.62 +} 1.63 + 1.64 +NS_IMETHODIMP_(nsISupports *) 1.65 +nsDOMScriptObjectFactory::GetExternalClassInfoInstance(const nsAString& aName) 1.66 +{ 1.67 + nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); 1.68 + NS_ENSURE_TRUE(nameSpaceManager, nullptr); 1.69 + 1.70 + const nsGlobalNameStruct *globalStruct = nameSpaceManager->LookupName(aName); 1.71 + if (globalStruct) { 1.72 + if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) { 1.73 + nsresult rv; 1.74 + nsCOMPtr<nsIDOMCIExtension> creator(do_CreateInstance(globalStruct->mCID, &rv)); 1.75 + NS_ENSURE_SUCCESS(rv, nullptr); 1.76 + 1.77 + rv = creator->RegisterDOMCI(NS_ConvertUTF16toUTF8(aName).get(), this); 1.78 + NS_ENSURE_SUCCESS(rv, nullptr); 1.79 + 1.80 + globalStruct = nameSpaceManager->LookupName(aName); 1.81 + NS_ENSURE_TRUE(globalStruct, nullptr); 1.82 + 1.83 + NS_ASSERTION(globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo, 1.84 + "The classinfo data for this class didn't get registered."); 1.85 + } 1.86 + if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { 1.87 + return nsDOMClassInfo::GetClassInfoInstance(globalStruct->mData); 1.88 + } 1.89 + } 1.90 + return nullptr; 1.91 +} 1.92 + 1.93 +NS_IMETHODIMP 1.94 +nsDOMScriptObjectFactory::Observe(nsISupports *aSubject, 1.95 + const char *aTopic, 1.96 + const char16_t *someData) 1.97 +{ 1.98 + if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { 1.99 +#ifdef MOZ_XUL 1.100 + // Flush the XUL cache since it holds JS roots, and we're about to 1.101 + // start the final GC. 1.102 + nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); 1.103 + 1.104 + if (cache) 1.105 + cache->Flush(); 1.106 +#endif 1.107 + } 1.108 + 1.109 + return NS_OK; 1.110 +} 1.111 + 1.112 +NS_IMETHODIMP 1.113 +nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName, 1.114 + nsDOMClassInfoExternalConstructorFnc aConstructorFptr, 1.115 + const nsIID *aProtoChainInterface, 1.116 + const nsIID **aInterfaces, 1.117 + uint32_t aScriptableFlags, 1.118 + bool aHasClassInterface, 1.119 + const nsCID *aConstructorCID) 1.120 +{ 1.121 + nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); 1.122 + NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED); 1.123 + 1.124 + return nameSpaceManager->RegisterDOMCIData(aName, 1.125 + aConstructorFptr, 1.126 + aProtoChainInterface, 1.127 + aInterfaces, 1.128 + aScriptableFlags, 1.129 + aHasClassInterface, 1.130 + aConstructorCID); 1.131 +}