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