Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: set ts=2 sw=2 et tw=78: |
michael@0 | 3 | * |
michael@0 | 4 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 7 | * |
michael@0 | 8 | * |
michael@0 | 9 | * This Original Code has been modified by IBM Corporation. |
michael@0 | 10 | * Modifications made by IBM described herein are |
michael@0 | 11 | * Copyright (c) International Business Machines |
michael@0 | 12 | * Corporation, 2000 |
michael@0 | 13 | * |
michael@0 | 14 | * Modifications to Mozilla code or documentation |
michael@0 | 15 | * identified per MPL Section 3.3 |
michael@0 | 16 | * |
michael@0 | 17 | * Date Modified by Description of modification |
michael@0 | 18 | * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink |
michael@0 | 19 | * use in OS2 |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | #include "nsDOMScriptObjectFactory.h" |
michael@0 | 23 | #include "nsScriptNameSpaceManager.h" |
michael@0 | 24 | #include "nsIObserverService.h" |
michael@0 | 25 | #include "nsJSEnvironment.h" |
michael@0 | 26 | #include "nsGlobalWindow.h" |
michael@0 | 27 | #include "nsCRT.h" |
michael@0 | 28 | #ifdef MOZ_XUL |
michael@0 | 29 | #include "nsXULPrototypeCache.h" |
michael@0 | 30 | #endif |
michael@0 | 31 | #include "nsThreadUtils.h" |
michael@0 | 32 | |
michael@0 | 33 | using mozilla::dom::GetNameSpaceManager; |
michael@0 | 34 | |
michael@0 | 35 | nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() |
michael@0 | 36 | { |
michael@0 | 37 | nsCOMPtr<nsIObserverService> observerService = |
michael@0 | 38 | mozilla::services::GetObserverService(); |
michael@0 | 39 | if (observerService) { |
michael@0 | 40 | observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory) |
michael@0 | 46 | NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory) |
michael@0 | 47 | NS_INTERFACE_MAP_ENTRY(nsIObserver) |
michael@0 | 48 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory) |
michael@0 | 49 | NS_INTERFACE_MAP_END |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | NS_IMPL_ADDREF(nsDOMScriptObjectFactory) |
michael@0 | 53 | NS_IMPL_RELEASE(nsDOMScriptObjectFactory) |
michael@0 | 54 | |
michael@0 | 55 | NS_IMETHODIMP_(nsISupports *) |
michael@0 | 56 | nsDOMScriptObjectFactory::GetClassInfoInstance(nsDOMClassInfoID aID) |
michael@0 | 57 | { |
michael@0 | 58 | return NS_GetDOMClassInfoInstance(aID); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | NS_IMETHODIMP_(nsISupports *) |
michael@0 | 62 | nsDOMScriptObjectFactory::GetExternalClassInfoInstance(const nsAString& aName) |
michael@0 | 63 | { |
michael@0 | 64 | nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); |
michael@0 | 65 | NS_ENSURE_TRUE(nameSpaceManager, nullptr); |
michael@0 | 66 | |
michael@0 | 67 | const nsGlobalNameStruct *globalStruct = nameSpaceManager->LookupName(aName); |
michael@0 | 68 | if (globalStruct) { |
michael@0 | 69 | if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) { |
michael@0 | 70 | nsresult rv; |
michael@0 | 71 | nsCOMPtr<nsIDOMCIExtension> creator(do_CreateInstance(globalStruct->mCID, &rv)); |
michael@0 | 72 | NS_ENSURE_SUCCESS(rv, nullptr); |
michael@0 | 73 | |
michael@0 | 74 | rv = creator->RegisterDOMCI(NS_ConvertUTF16toUTF8(aName).get(), this); |
michael@0 | 75 | NS_ENSURE_SUCCESS(rv, nullptr); |
michael@0 | 76 | |
michael@0 | 77 | globalStruct = nameSpaceManager->LookupName(aName); |
michael@0 | 78 | NS_ENSURE_TRUE(globalStruct, nullptr); |
michael@0 | 79 | |
michael@0 | 80 | NS_ASSERTION(globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo, |
michael@0 | 81 | "The classinfo data for this class didn't get registered."); |
michael@0 | 82 | } |
michael@0 | 83 | if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { |
michael@0 | 84 | return nsDOMClassInfo::GetClassInfoInstance(globalStruct->mData); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | return nullptr; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | NS_IMETHODIMP |
michael@0 | 91 | nsDOMScriptObjectFactory::Observe(nsISupports *aSubject, |
michael@0 | 92 | const char *aTopic, |
michael@0 | 93 | const char16_t *someData) |
michael@0 | 94 | { |
michael@0 | 95 | if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { |
michael@0 | 96 | #ifdef MOZ_XUL |
michael@0 | 97 | // Flush the XUL cache since it holds JS roots, and we're about to |
michael@0 | 98 | // start the final GC. |
michael@0 | 99 | nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); |
michael@0 | 100 | |
michael@0 | 101 | if (cache) |
michael@0 | 102 | cache->Flush(); |
michael@0 | 103 | #endif |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | return NS_OK; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | NS_IMETHODIMP |
michael@0 | 110 | nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName, |
michael@0 | 111 | nsDOMClassInfoExternalConstructorFnc aConstructorFptr, |
michael@0 | 112 | const nsIID *aProtoChainInterface, |
michael@0 | 113 | const nsIID **aInterfaces, |
michael@0 | 114 | uint32_t aScriptableFlags, |
michael@0 | 115 | bool aHasClassInterface, |
michael@0 | 116 | const nsCID *aConstructorCID) |
michael@0 | 117 | { |
michael@0 | 118 | nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); |
michael@0 | 119 | NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 120 | |
michael@0 | 121 | return nameSpaceManager->RegisterDOMCIData(aName, |
michael@0 | 122 | aConstructorFptr, |
michael@0 | 123 | aProtoChainInterface, |
michael@0 | 124 | aInterfaces, |
michael@0 | 125 | aScriptableFlags, |
michael@0 | 126 | aHasClassInterface, |
michael@0 | 127 | aConstructorCID); |
michael@0 | 128 | } |