1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
26 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #include "nsXPCOM.h"
|
---|
39 | #include "nsXPCOMPrivate.h"
|
---|
40 | #include "nscore.h"
|
---|
41 | #include "prlink.h"
|
---|
42 | #include "nsCOMPtr.h"
|
---|
43 | #include "nsObserverList.h"
|
---|
44 | #include "nsObserverService.h"
|
---|
45 | #include "nsProperties.h"
|
---|
46 | #include "nsIProperties.h"
|
---|
47 | #include "nsPersistentProperties.h"
|
---|
48 | #include "nsScriptableInputStream.h"
|
---|
49 | #include "nsBinaryStream.h"
|
---|
50 | #include "nsStorageStream.h"
|
---|
51 |
|
---|
52 | #include "nsMemoryImpl.h"
|
---|
53 | #include "nsDebugImpl.h"
|
---|
54 | #include "nsTraceRefcntImpl.h"
|
---|
55 | #include "nsErrorService.h"
|
---|
56 | #include "nsByteBuffer.h"
|
---|
57 |
|
---|
58 | #include "nsSupportsArray.h"
|
---|
59 | #include "nsArray.h"
|
---|
60 | #include "nsSupportsPrimitives.h"
|
---|
61 | #include "nsConsoleService.h"
|
---|
62 | #include "nsExceptionService.h"
|
---|
63 |
|
---|
64 | #include "nsComponentManager.h"
|
---|
65 | #include "nsCategoryManagerUtils.h"
|
---|
66 | #include "nsIServiceManager.h"
|
---|
67 | #include "nsGenericFactory.h"
|
---|
68 |
|
---|
69 | #include "nsEventQueueService.h"
|
---|
70 | #include "nsEventQueue.h"
|
---|
71 | #ifdef VBOX
|
---|
72 | # include "nsEventQueueUtils.h"
|
---|
73 | # include "nsProxyRelease.h"
|
---|
74 | #endif /* VBOX */
|
---|
75 |
|
---|
76 | #include "nsIProxyObjectManager.h"
|
---|
77 | #include "nsProxyEventPrivate.h" // access to the impl of nsProxyObjectManager for the generic factory registration.
|
---|
78 |
|
---|
79 | #include "xptinfo.h"
|
---|
80 | #include "nsIInterfaceInfoManager.h"
|
---|
81 |
|
---|
82 | #include "nsTimerImpl.h"
|
---|
83 | #include "TimerThread.h"
|
---|
84 |
|
---|
85 | #include "nsThread.h"
|
---|
86 | #include "nsProcess.h"
|
---|
87 | #include "nsEnvironment.h"
|
---|
88 |
|
---|
89 | #include "nsEmptyEnumerator.h"
|
---|
90 |
|
---|
91 | #include "nsILocalFile.h"
|
---|
92 | #include "nsLocalFile.h"
|
---|
93 | #if defined(XP_UNIX) || defined(XP_OS2)
|
---|
94 | #include "nsNativeCharsetUtils.h"
|
---|
95 | #endif
|
---|
96 | #include "nsDirectoryService.h"
|
---|
97 | #include "nsDirectoryServiceDefs.h"
|
---|
98 | #include "nsCategoryManager.h"
|
---|
99 | #include "nsICategoryManager.h"
|
---|
100 | #include "nsStringStream.h"
|
---|
101 | #include "nsMultiplexInputStream.h"
|
---|
102 |
|
---|
103 | #include "nsFastLoadService.h"
|
---|
104 |
|
---|
105 | #include "nsAtomService.h"
|
---|
106 | #include "nsAtomTable.h"
|
---|
107 | #include "nsTraceRefcnt.h"
|
---|
108 | #include "nsTimelineService.h"
|
---|
109 |
|
---|
110 | #include "nsVariant.h"
|
---|
111 |
|
---|
112 | #include "nsRecyclingAllocator.h"
|
---|
113 |
|
---|
114 | #include "SpecialSystemDirectory.h"
|
---|
115 |
|
---|
116 | #include "ipcdclient.h"
|
---|
117 | #include "ipcService.h"
|
---|
118 | #include "ipcConfig.h"
|
---|
119 | #include "ipcCID.h"
|
---|
120 | #include "ipcLockService.h"
|
---|
121 | #include "ipcLockCID.h"
|
---|
122 | #include "tmTransactionService.h"
|
---|
123 | #include "ipcDConnectService.h"
|
---|
124 |
|
---|
125 | #include <locale.h>
|
---|
126 |
|
---|
127 | // Registry Factory creation function defined in nsRegistry.cpp
|
---|
128 | // We hook into this function locally to create and register the registry
|
---|
129 | // Since noone outside xpcom needs to know about this and nsRegistry.cpp
|
---|
130 | // does not have a local include file, we are putting this definition
|
---|
131 | // here rather than in nsIRegistry.h
|
---|
132 | extern nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
|
---|
133 | extern nsresult NS_CategoryManagerGetFactory( nsIFactory** );
|
---|
134 |
|
---|
135 | #ifdef DEBUG
|
---|
136 | extern void _FreeAutoLockStatics();
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
---|
140 | static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
|
---|
141 | static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
---|
142 |
|
---|
143 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess)
|
---|
144 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsEventQueueServiceImpl, Init)
|
---|
145 |
|
---|
146 | #define NS_ENVIRONMENT_CLASSNAME "Environment Service"
|
---|
147 |
|
---|
148 | #include "nsXPCOM.h"
|
---|
149 | // ds/nsISupportsPrimitives
|
---|
150 | #define NS_SUPPORTS_ID_CLASSNAME "Supports ID"
|
---|
151 | #define NS_SUPPORTS_CSTRING_CLASSNAME "Supports String"
|
---|
152 | #define NS_SUPPORTS_STRING_CLASSNAME "Supports WString"
|
---|
153 | #define NS_SUPPORTS_PRBOOL_CLASSNAME "Supports PRBool"
|
---|
154 | #define NS_SUPPORTS_PRUINT8_CLASSNAME "Supports PRUint8"
|
---|
155 | #define NS_SUPPORTS_PRUINT16_CLASSNAME "Supports PRUint16"
|
---|
156 | #define NS_SUPPORTS_PRUINT32_CLASSNAME "Supports PRUint32"
|
---|
157 | #define NS_SUPPORTS_PRUINT64_CLASSNAME "Supports PRUint64"
|
---|
158 | #define NS_SUPPORTS_PRTIME_CLASSNAME "Supports PRTime"
|
---|
159 | #define NS_SUPPORTS_CHAR_CLASSNAME "Supports Char"
|
---|
160 | #define NS_SUPPORTS_PRINT16_CLASSNAME "Supports PRInt16"
|
---|
161 | #define NS_SUPPORTS_PRINT32_CLASSNAME "Supports PRInt32"
|
---|
162 | #define NS_SUPPORTS_PRINT64_CLASSNAME "Supports PRInt64"
|
---|
163 | #define NS_SUPPORTS_FLOAT_CLASSNAME "Supports float"
|
---|
164 | #define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
|
---|
165 | #define NS_SUPPORTS_VOID_CLASSNAME "Supports void"
|
---|
166 | #define NS_SUPPORTS_INTERFACE_POINTER_CLASSNAME "Supports interface pointer"
|
---|
167 |
|
---|
168 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsIDImpl)
|
---|
169 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsStringImpl)
|
---|
170 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCStringImpl)
|
---|
171 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRBoolImpl)
|
---|
172 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint8Impl)
|
---|
173 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint16Impl)
|
---|
174 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint32Impl)
|
---|
175 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint64Impl)
|
---|
176 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRTimeImpl)
|
---|
177 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCharImpl)
|
---|
178 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt16Impl)
|
---|
179 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
|
---|
180 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
|
---|
181 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
|
---|
182 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
|
---|
183 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
|
---|
184 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
|
---|
185 |
|
---|
186 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsArray)
|
---|
187 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleService)
|
---|
188 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService)
|
---|
189 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService)
|
---|
190 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl)
|
---|
191 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerManager)
|
---|
192 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryOutputStream)
|
---|
193 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryInputStream)
|
---|
194 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageStream)
|
---|
195 |
|
---|
196 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant)
|
---|
197 |
|
---|
198 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsRecyclingAllocatorImpl)
|
---|
199 |
|
---|
200 | #ifdef MOZ_TIMELINE
|
---|
201 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimelineService)
|
---|
202 | #endif
|
---|
203 |
|
---|
204 | static NS_METHOD
|
---|
205 | nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer,
|
---|
206 | const nsIID& aIID,
|
---|
207 | void* *aInstancePtr)
|
---|
208 | {
|
---|
209 | NS_ENSURE_ARG_POINTER(aInstancePtr);
|
---|
210 | NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
|
---|
211 |
|
---|
212 | nsCOMPtr<nsIInterfaceInfoManager> iim(dont_AddRef(XPTI_GetInterfaceInfoManager()));
|
---|
213 | if (!iim) {
|
---|
214 | return NS_ERROR_FAILURE;
|
---|
215 | }
|
---|
216 |
|
---|
217 | return iim->QueryInterface(aIID, aInstancePtr);
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | PR_STATIC_CALLBACK(nsresult)
|
---|
222 | RegisterGenericFactory(nsIComponentRegistrar* registrar,
|
---|
223 | const nsModuleComponentInfo *info)
|
---|
224 | {
|
---|
225 | nsresult rv;
|
---|
226 | nsIGenericFactory* fact;
|
---|
227 | rv = NS_NewGenericFactory(&fact, info);
|
---|
228 | if (NS_FAILED(rv)) return rv;
|
---|
229 |
|
---|
230 | rv = registrar->RegisterFactory(info->mCID,
|
---|
231 | info->mDescription,
|
---|
232 | info->mContractID,
|
---|
233 | fact);
|
---|
234 | NS_RELEASE(fact);
|
---|
235 | return rv;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // In order to support the installer, we need
|
---|
239 | // to be told out of band if we should cause
|
---|
240 | // an autoregister. If the file ".autoreg" exists in the binary
|
---|
241 | // directory, we check its timestamp against the timestamp of the
|
---|
242 | // compreg.dat file. If the .autoreg file is newer, we autoregister.
|
---|
243 | static PRBool CheckUpdateFile()
|
---|
244 | {
|
---|
245 | nsresult rv;
|
---|
246 | nsCOMPtr<nsIProperties> directoryService;
|
---|
247 | nsDirectoryService::Create(nsnull,
|
---|
248 | NS_GET_IID(nsIProperties),
|
---|
249 | getter_AddRefs(directoryService));
|
---|
250 |
|
---|
251 | if (!directoryService)
|
---|
252 | return PR_FALSE;
|
---|
253 |
|
---|
254 | nsCOMPtr<nsIFile> file;
|
---|
255 | rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
---|
256 | NS_GET_IID(nsIFile),
|
---|
257 | getter_AddRefs(file));
|
---|
258 |
|
---|
259 | if (NS_FAILED(rv)) {
|
---|
260 | NS_WARNING("Getting NS_XPCOM_CURRENT_PROCESS_DIR failed");
|
---|
261 | return PR_FALSE;
|
---|
262 | }
|
---|
263 |
|
---|
264 | file->AppendNative(nsDependentCString(".autoreg"));
|
---|
265 |
|
---|
266 | PRBool exists;
|
---|
267 | file->Exists(&exists);
|
---|
268 | if (!exists)
|
---|
269 | return PR_FALSE;
|
---|
270 |
|
---|
271 | nsCOMPtr<nsIFile> compregFile;
|
---|
272 | rv = directoryService->Get(NS_XPCOM_COMPONENT_REGISTRY_FILE,
|
---|
273 | NS_GET_IID(nsIFile),
|
---|
274 | getter_AddRefs(compregFile));
|
---|
275 |
|
---|
276 |
|
---|
277 | if (NS_FAILED(rv)) {
|
---|
278 | NS_WARNING("Getting NS_XPCOM_COMPONENT_REGISTRY_FILE failed");
|
---|
279 | return PR_FALSE;
|
---|
280 | }
|
---|
281 |
|
---|
282 | // Don't need to check whether compreg exists; if it doesn't
|
---|
283 | // we won't even be here.
|
---|
284 |
|
---|
285 | PRInt64 compregModTime, autoregModTime;
|
---|
286 | compregFile->GetLastModifiedTime(&compregModTime);
|
---|
287 | file->GetLastModifiedTime(&autoregModTime);
|
---|
288 |
|
---|
289 | return LL_CMP(autoregModTime, >, compregModTime);
|
---|
290 | }
|
---|
291 |
|
---|
292 | #if 0 /// @todo later
|
---|
293 | NS_GENERIC_FACTORY_CONSTRUCTOR(ipcService)
|
---|
294 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ipcLockService, Init)
|
---|
295 | NS_GENERIC_FACTORY_CONSTRUCTOR(tmTransactionService)
|
---|
296 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ipcDConnectService, Init)
|
---|
297 |
|
---|
298 | // enable this code to make the IPC DCONNECT service auto-start.
|
---|
299 | NS_METHOD
|
---|
300 | ipcDConnectServiceRegisterProc(nsIComponentManager *aCompMgr,
|
---|
301 | nsIFile *aPath,
|
---|
302 | const char *registryLocation,
|
---|
303 | const char *componentType,
|
---|
304 | const nsModuleComponentInfo *info)
|
---|
305 | {
|
---|
306 | //
|
---|
307 | // add ipcService to the XPCOM startup category
|
---|
308 | //
|
---|
309 | nsCOMPtr<nsICategoryManager> catman(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
|
---|
310 | if (catman) {
|
---|
311 | nsXPIDLCString prevEntry;
|
---|
312 | catman->AddCategoryEntry(NS_XPCOM_STARTUP_OBSERVER_ID, "ipcDConnectService",
|
---|
313 | IPC_DCONNECTSERVICE_CONTRACTID, PR_TRUE, PR_TRUE,
|
---|
314 | getter_Copies(prevEntry));
|
---|
315 | }
|
---|
316 | return NS_OK;
|
---|
317 | }
|
---|
318 |
|
---|
319 | NS_METHOD
|
---|
320 | ipcDConnectServiceUnregisterProc(nsIComponentManager *aCompMgr,
|
---|
321 | nsIFile *aPath,
|
---|
322 | const char *registryLocation,
|
---|
323 | const nsModuleComponentInfo *info)
|
---|
324 | {
|
---|
325 | nsCOMPtr<nsICategoryManager> catman(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
|
---|
326 | if (catman)
|
---|
327 | catman->DeleteCategoryEntry(NS_XPCOM_STARTUP_OBSERVER_ID,
|
---|
328 | IPC_DCONNECTSERVICE_CONTRACTID, PR_TRUE);
|
---|
329 | return NS_OK;
|
---|
330 | }
|
---|
331 | #endif
|
---|
332 |
|
---|
333 | nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
|
---|
334 | nsIProperties *gDirectoryService = NULL;
|
---|
335 | PRBool gXPCOMShuttingDown = PR_FALSE;
|
---|
336 |
|
---|
337 | // For each class that wishes to support nsIClassInfo, add a line like this
|
---|
338 | // NS_DECL_CLASSINFO(nsMyClass)
|
---|
339 |
|
---|
340 | #define COMPONENT(NAME, Ctor) \
|
---|
341 | { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor }
|
---|
342 |
|
---|
343 | #define COMPONENT_CI(NAME, Ctor, Class) \
|
---|
344 | { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor, \
|
---|
345 | NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(Class), NULL, \
|
---|
346 | &NS_CLASSINFO_NAME(Class) }
|
---|
347 |
|
---|
348 | static const nsModuleComponentInfo components[] = {
|
---|
349 | COMPONENT(MEMORY, nsMemoryImpl::Create),
|
---|
350 | COMPONENT(DEBUG, nsDebugImpl::Create),
|
---|
351 | #define NS_ERRORSERVICE_CLASSNAME NS_ERRORSERVICE_NAME
|
---|
352 | COMPONENT(ERRORSERVICE, nsErrorService::Create),
|
---|
353 |
|
---|
354 | COMPONENT(BYTEBUFFER, ByteBufferImpl::Create),
|
---|
355 | COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create),
|
---|
356 | COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor),
|
---|
357 | COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor),
|
---|
358 | COMPONENT(STORAGESTREAM, nsStorageStreamConstructor),
|
---|
359 |
|
---|
360 | #define NS_PROPERTIES_CLASSNAME "Properties"
|
---|
361 | COMPONENT(PROPERTIES, nsProperties::Create),
|
---|
362 |
|
---|
363 | #define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
|
---|
364 | COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create),
|
---|
365 |
|
---|
366 | COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create),
|
---|
367 | COMPONENT(ARRAY, nsArrayConstructor),
|
---|
368 | COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor),
|
---|
369 | COMPONENT(EXCEPTIONSERVICE, nsExceptionServiceConstructor),
|
---|
370 | COMPONENT(ATOMSERVICE, nsAtomServiceConstructor),
|
---|
371 | #ifdef MOZ_TIMELINE
|
---|
372 | COMPONENT(TIMELINESERVICE, nsTimelineServiceConstructor),
|
---|
373 | #endif
|
---|
374 | COMPONENT(OBSERVERSERVICE, nsObserverService::Create),
|
---|
375 | COMPONENT(GENERICFACTORY, nsGenericFactory::Create),
|
---|
376 | COMPONENT(EVENTQUEUESERVICE, nsEventQueueServiceImplConstructor),
|
---|
377 | COMPONENT(EVENTQUEUE, nsEventQueueImpl::Create),
|
---|
378 | COMPONENT(THREAD, nsThread::Create),
|
---|
379 |
|
---|
380 | #define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
|
---|
381 | COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create),
|
---|
382 |
|
---|
383 | COMPONENT(TIMER, nsTimerImplConstructor),
|
---|
384 | COMPONENT(TIMERMANAGER, nsTimerManagerConstructor),
|
---|
385 |
|
---|
386 | #define COMPONENT_SUPPORTS(TYPE, Type) \
|
---|
387 | COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)
|
---|
388 |
|
---|
389 | COMPONENT_SUPPORTS(ID, ID),
|
---|
390 | COMPONENT_SUPPORTS(STRING, String),
|
---|
391 | COMPONENT_SUPPORTS(CSTRING, CString),
|
---|
392 | COMPONENT_SUPPORTS(PRBOOL, PRBool),
|
---|
393 | COMPONENT_SUPPORTS(PRUINT8, PRUint8),
|
---|
394 | COMPONENT_SUPPORTS(PRUINT16, PRUint16),
|
---|
395 | COMPONENT_SUPPORTS(PRUINT32, PRUint32),
|
---|
396 | COMPONENT_SUPPORTS(PRUINT64, PRUint64),
|
---|
397 | COMPONENT_SUPPORTS(PRTIME, PRTime),
|
---|
398 | COMPONENT_SUPPORTS(CHAR, Char),
|
---|
399 | COMPONENT_SUPPORTS(PRINT16, PRInt16),
|
---|
400 | COMPONENT_SUPPORTS(PRINT32, PRInt32),
|
---|
401 | COMPONENT_SUPPORTS(PRINT64, PRInt64),
|
---|
402 | COMPONENT_SUPPORTS(FLOAT, Float),
|
---|
403 | COMPONENT_SUPPORTS(DOUBLE, Double),
|
---|
404 | COMPONENT_SUPPORTS(VOID, Void),
|
---|
405 | COMPONENT_SUPPORTS(INTERFACE_POINTER, InterfacePointer),
|
---|
406 |
|
---|
407 | #undef COMPONENT_SUPPORTS
|
---|
408 | #define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
|
---|
409 | COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor),
|
---|
410 | #define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service"
|
---|
411 | COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create),
|
---|
412 | COMPONENT(PROCESS, nsProcessConstructor),
|
---|
413 | COMPONENT(ENVIRONMENT, nsEnvironment::Create),
|
---|
414 |
|
---|
415 | COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor),
|
---|
416 | COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor),
|
---|
417 |
|
---|
418 | COMPONENT(FASTLOADSERVICE, nsFastLoadService::Create),
|
---|
419 | COMPONENT(VARIANT, nsVariantConstructor),
|
---|
420 | COMPONENT(INTERFACEINFOMANAGER_SERVICE, nsXPTIInterfaceInfoManagerGetSingleton),
|
---|
421 |
|
---|
422 | COMPONENT(RECYCLINGALLOCATOR, nsRecyclingAllocatorImplConstructor),
|
---|
423 |
|
---|
424 | #if 0 /// @todo later
|
---|
425 | { IPC_SERVICE_CLASSNAME,
|
---|
426 | IPC_SERVICE_CID,
|
---|
427 | IPC_SERVICE_CONTRACTID,
|
---|
428 | ipcServiceConstructor },
|
---|
429 | /*
|
---|
430 | ipcServiceRegisterProc,
|
---|
431 | ipcServiceUnregisterProc },
|
---|
432 | */
|
---|
433 | //
|
---|
434 | // extensions go here:
|
---|
435 | //
|
---|
436 | { IPC_LOCKSERVICE_CLASSNAME,
|
---|
437 | IPC_LOCKSERVICE_CID,
|
---|
438 | IPC_LOCKSERVICE_CONTRACTID,
|
---|
439 | ipcLockServiceConstructor },
|
---|
440 | { IPC_TRANSACTIONSERVICE_CLASSNAME,
|
---|
441 | IPC_TRANSACTIONSERVICE_CID,
|
---|
442 | IPC_TRANSACTIONSERVICE_CONTRACTID,
|
---|
443 | tmTransactionServiceConstructor },
|
---|
444 |
|
---|
445 | #ifdef BUILD_DCONNECT
|
---|
446 | { IPC_DCONNECTSERVICE_CLASSNAME,
|
---|
447 | IPC_DCONNECTSERVICE_CID,
|
---|
448 | IPC_DCONNECTSERVICE_CONTRACTID,
|
---|
449 | ipcDConnectServiceConstructor,
|
---|
450 | ipcDConnectServiceRegisterProc,
|
---|
451 | ipcDConnectServiceUnregisterProc },
|
---|
452 | #endif
|
---|
453 | #endif
|
---|
454 | };
|
---|
455 |
|
---|
456 | #undef COMPONENT
|
---|
457 |
|
---|
458 | const int components_length = sizeof(components) / sizeof(components[0]);
|
---|
459 |
|
---|
460 | // gMemory will be freed during shutdown.
|
---|
461 | static nsIMemory* gMemory = nsnull;
|
---|
462 | nsresult NS_COM NS_GetMemoryManager(nsIMemory* *result)
|
---|
463 | {
|
---|
464 | nsresult rv = NS_OK;
|
---|
465 | if (!gMemory)
|
---|
466 | {
|
---|
467 | rv = nsMemoryImpl::Create(nsnull,
|
---|
468 | NS_GET_IID(nsIMemory),
|
---|
469 | (void**)&gMemory);
|
---|
470 | }
|
---|
471 | NS_IF_ADDREF(*result = gMemory);
|
---|
472 | return rv;
|
---|
473 | }
|
---|
474 |
|
---|
475 | // gDebug will be freed during shutdown.
|
---|
476 | static nsIDebug* gDebug = nsnull;
|
---|
477 | nsresult NS_COM NS_GetDebug(nsIDebug** result)
|
---|
478 | {
|
---|
479 | nsresult rv = NS_OK;
|
---|
480 | if (!gDebug)
|
---|
481 | {
|
---|
482 | rv = nsDebugImpl::Create(nsnull,
|
---|
483 | NS_GET_IID(nsIDebug),
|
---|
484 | (void**)&gDebug);
|
---|
485 | }
|
---|
486 | NS_IF_ADDREF(*result = gDebug);
|
---|
487 | return rv;
|
---|
488 | }
|
---|
489 |
|
---|
490 | #ifdef NS_BUILD_REFCNT_LOGGING
|
---|
491 | // gTraceRefcnt will be freed during shutdown.
|
---|
492 | static nsITraceRefcnt* gTraceRefcnt = nsnull;
|
---|
493 | #endif
|
---|
494 |
|
---|
495 | nsresult NS_COM NS_GetTraceRefcnt(nsITraceRefcnt** result)
|
---|
496 | {
|
---|
497 | #ifdef NS_BUILD_REFCNT_LOGGING
|
---|
498 | nsresult rv = NS_OK;
|
---|
499 | if (!gTraceRefcnt)
|
---|
500 | {
|
---|
501 | rv = nsTraceRefcntImpl::Create(nsnull,
|
---|
502 | NS_GET_IID(nsITraceRefcnt),
|
---|
503 | (void**)&gTraceRefcnt);
|
---|
504 | }
|
---|
505 | NS_IF_ADDREF(*result = gTraceRefcnt);
|
---|
506 | return rv;
|
---|
507 | #else
|
---|
508 | return NS_ERROR_NOT_INITIALIZED;
|
---|
509 | #endif
|
---|
510 | }
|
---|
511 |
|
---|
512 | nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
|
---|
513 | nsIFile* binDirectory)
|
---|
514 | {
|
---|
515 | return NS_InitXPCOM2(result, binDirectory, nsnull);
|
---|
516 | }
|
---|
517 |
|
---|
518 | nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
|
---|
519 | nsIFile* binDirectory,
|
---|
520 | nsIDirectoryServiceProvider* appFileLocationProvider)
|
---|
521 | {
|
---|
522 | nsresult rv = NS_OK;
|
---|
523 |
|
---|
524 | // We are not shutting down
|
---|
525 | gXPCOMShuttingDown = PR_FALSE;
|
---|
526 |
|
---|
527 | #ifdef NS_BUILD_REFCNT_LOGGING
|
---|
528 | nsTraceRefcntImpl::Startup();
|
---|
529 | #endif
|
---|
530 |
|
---|
531 | // Establish the main thread here.
|
---|
532 | rv = nsIThread::SetMainThread();
|
---|
533 | if (NS_FAILED(rv)) return rv;
|
---|
534 |
|
---|
535 | // Set up the timer globals/timer thread
|
---|
536 | rv = nsTimerImpl::Startup();
|
---|
537 | NS_ENSURE_SUCCESS(rv, rv);
|
---|
538 |
|
---|
539 | // Startup the memory manager
|
---|
540 | rv = nsMemoryImpl::Startup();
|
---|
541 | if (NS_FAILED(rv)) return rv;
|
---|
542 |
|
---|
543 | // If the locale hasn't already been setup by our embedder,
|
---|
544 | // get us out of the "C" locale and into the system
|
---|
545 | if (strcmp(setlocale(LC_ALL, NULL), "C") == 0)
|
---|
546 | setlocale(LC_ALL, "");
|
---|
547 |
|
---|
548 | #if defined(XP_UNIX) || defined(XP_OS2)
|
---|
549 | NS_StartupNativeCharsetUtils();
|
---|
550 | #endif
|
---|
551 | NS_StartupLocalFile();
|
---|
552 |
|
---|
553 | StartupSpecialSystemDirectory();
|
---|
554 |
|
---|
555 | // Start the directory service so that the component manager init can use it.
|
---|
556 | rv = nsDirectoryService::Create(nsnull,
|
---|
557 | NS_GET_IID(nsIProperties),
|
---|
558 | (void**)&gDirectoryService);
|
---|
559 | if (NS_FAILED(rv))
|
---|
560 | return rv;
|
---|
561 |
|
---|
562 | nsCOMPtr<nsIDirectoryService> dirService = do_QueryInterface(gDirectoryService, &rv);
|
---|
563 | if (NS_FAILED(rv))
|
---|
564 | return rv;
|
---|
565 | rv = dirService->Init();
|
---|
566 | if (NS_FAILED(rv))
|
---|
567 | return rv;
|
---|
568 |
|
---|
569 | // Create the Component/Service Manager
|
---|
570 | nsComponentManagerImpl *compMgr = NULL;
|
---|
571 |
|
---|
572 | if (nsComponentManagerImpl::gComponentManager == NULL)
|
---|
573 | {
|
---|
574 | compMgr = new nsComponentManagerImpl();
|
---|
575 | if (compMgr == NULL)
|
---|
576 | return NS_ERROR_OUT_OF_MEMORY;
|
---|
577 | NS_ADDREF(compMgr);
|
---|
578 |
|
---|
579 | nsCOMPtr<nsIFile> xpcomLib;
|
---|
580 |
|
---|
581 | PRBool value;
|
---|
582 | if (binDirectory)
|
---|
583 | {
|
---|
584 | rv = binDirectory->IsDirectory(&value);
|
---|
585 |
|
---|
586 | if (NS_SUCCEEDED(rv) && value) {
|
---|
587 | gDirectoryService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory);
|
---|
588 | binDirectory->Clone(getter_AddRefs(xpcomLib));
|
---|
589 | }
|
---|
590 | }
|
---|
591 | else {
|
---|
592 | gDirectoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
---|
593 | NS_GET_IID(nsIFile),
|
---|
594 | getter_AddRefs(xpcomLib));
|
---|
595 | }
|
---|
596 |
|
---|
597 | if (xpcomLib) {
|
---|
598 | xpcomLib->AppendNative(nsDependentCString(XPCOM_DLL));
|
---|
599 | gDirectoryService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
|
---|
600 | }
|
---|
601 |
|
---|
602 | if (appFileLocationProvider) {
|
---|
603 | rv = dirService->RegisterProvider(appFileLocationProvider);
|
---|
604 | if (NS_FAILED(rv)) return rv;
|
---|
605 | }
|
---|
606 |
|
---|
607 | rv = compMgr->Init();
|
---|
608 | if (NS_FAILED(rv))
|
---|
609 | {
|
---|
610 | NS_RELEASE(compMgr);
|
---|
611 | return rv;
|
---|
612 | }
|
---|
613 |
|
---|
614 | nsComponentManagerImpl::gComponentManager = compMgr;
|
---|
615 |
|
---|
616 | if (result) {
|
---|
617 | nsIServiceManager *serviceManager =
|
---|
618 | NS_STATIC_CAST(nsIServiceManager*, compMgr);
|
---|
619 |
|
---|
620 | NS_ADDREF(*result = serviceManager);
|
---|
621 | }
|
---|
622 | }
|
---|
623 |
|
---|
624 | nsCOMPtr<nsIMemory> memory;
|
---|
625 | NS_GetMemoryManager(getter_AddRefs(memory));
|
---|
626 | // dougt - these calls will be moved into a new interface when nsIComponentManager is frozen.
|
---|
627 | rv = compMgr->RegisterService(kMemoryCID, memory);
|
---|
628 | if (NS_FAILED(rv)) return rv;
|
---|
629 |
|
---|
630 | rv = compMgr->RegisterService(kComponentManagerCID, NS_STATIC_CAST(nsIComponentManager*, compMgr));
|
---|
631 | if (NS_FAILED(rv)) return rv;
|
---|
632 |
|
---|
633 | // 2. Register the global services with the component manager so that
|
---|
634 | // clients can create new objects.
|
---|
635 |
|
---|
636 | // Category Manager
|
---|
637 | {
|
---|
638 | nsCOMPtr<nsIFactory> categoryManagerFactory;
|
---|
639 | if ( NS_FAILED(rv = NS_CategoryManagerGetFactory(getter_AddRefs(categoryManagerFactory))) )
|
---|
640 | return rv;
|
---|
641 |
|
---|
642 | NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
|
---|
643 |
|
---|
644 | rv = compMgr->RegisterFactory(kCategoryManagerCID,
|
---|
645 | NS_CATEGORYMANAGER_CLASSNAME,
|
---|
646 | NS_CATEGORYMANAGER_CONTRACTID,
|
---|
647 | categoryManagerFactory,
|
---|
648 | PR_TRUE);
|
---|
649 | if ( NS_FAILED(rv) ) return rv;
|
---|
650 | }
|
---|
651 |
|
---|
652 | // what I want to do here is QI for a Component Registration Manager. Since this
|
---|
653 | // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home.
|
---|
654 | nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(
|
---|
655 | NS_STATIC_CAST(nsIComponentManager*,compMgr), &rv);
|
---|
656 | if (registrar) {
|
---|
657 | for (int i = 0; i < components_length; i++)
|
---|
658 | RegisterGenericFactory(registrar, &components[i]);
|
---|
659 | }
|
---|
660 | rv = nsComponentManagerImpl::gComponentManager->ReadPersistentRegistry();
|
---|
661 | #ifdef DEBUG
|
---|
662 | if (NS_FAILED(rv)) {
|
---|
663 | printf("No Persistent Registry Found.\n");
|
---|
664 | }
|
---|
665 | #endif
|
---|
666 |
|
---|
667 | #if 0 /// @todo later
|
---|
668 | rv = IPC_Init();
|
---|
669 | if (NS_FAILED(rv))
|
---|
670 | return rv;
|
---|
671 | #endif
|
---|
672 |
|
---|
673 | if ( NS_FAILED(rv) || CheckUpdateFile()) {
|
---|
674 | // if we find no persistent registry, we will try to autoregister
|
---|
675 | // the default components directory.
|
---|
676 | nsComponentManagerImpl::gComponentManager->AutoRegister(nsnull);
|
---|
677 |
|
---|
678 | // If the application is using a GRE, then,
|
---|
679 | // auto register components in the GRE directory as well.
|
---|
680 | //
|
---|
681 | // The application indicates that it's using an GRE by
|
---|
682 | // returning a valid nsIFile when queried (via appFileLocProvider)
|
---|
683 | // for the NS_GRE_DIR atom as shown below
|
---|
684 | //
|
---|
685 |
|
---|
686 | if ( appFileLocationProvider ) {
|
---|
687 | nsCOMPtr<nsIFile> greDir;
|
---|
688 | PRBool persistent = PR_TRUE;
|
---|
689 |
|
---|
690 | appFileLocationProvider->GetFile(NS_GRE_DIR, &persistent, getter_AddRefs(greDir));
|
---|
691 |
|
---|
692 | if (greDir) {
|
---|
693 | #ifdef DEBUG_dougt
|
---|
694 | printf("start - Registering GRE components\n");
|
---|
695 | #endif
|
---|
696 | rv = gDirectoryService->Get(NS_GRE_COMPONENT_DIR,
|
---|
697 | NS_GET_IID(nsIFile),
|
---|
698 | getter_AddRefs(greDir));
|
---|
699 | if (NS_FAILED(rv)) {
|
---|
700 | NS_ERROR("Could not get GRE components directory!");
|
---|
701 | return rv;
|
---|
702 | }
|
---|
703 |
|
---|
704 | // If the GRE contains any loaders, we want to know about it so that we can cause another
|
---|
705 | // autoregistration of the applications component directory.
|
---|
706 | int loaderCount = nsComponentManagerImpl::gComponentManager->GetLoaderCount();
|
---|
707 | rv = nsComponentManagerImpl::gComponentManager->AutoRegister(greDir);
|
---|
708 |
|
---|
709 | if (loaderCount != nsComponentManagerImpl::gComponentManager->GetLoaderCount())
|
---|
710 | nsComponentManagerImpl::gComponentManager->AutoRegisterNonNativeComponents(nsnull);
|
---|
711 |
|
---|
712 | #ifdef DEBUG_dougt
|
---|
713 | printf("end - Registering GRE components\n");
|
---|
714 | #endif
|
---|
715 | if (NS_FAILED(rv)) {
|
---|
716 | NS_ERROR("Could not AutoRegister GRE components");
|
---|
717 | return rv;
|
---|
718 | }
|
---|
719 | }
|
---|
720 | }
|
---|
721 |
|
---|
722 | //
|
---|
723 | // If additional component directories have been specified, then
|
---|
724 | // register them as well.
|
---|
725 | //
|
---|
726 |
|
---|
727 | nsCOMPtr<nsISimpleEnumerator> dirList;
|
---|
728 | gDirectoryService->Get(NS_XPCOM_COMPONENT_DIR_LIST,
|
---|
729 | NS_GET_IID(nsISimpleEnumerator),
|
---|
730 | getter_AddRefs(dirList));
|
---|
731 | if (dirList) {
|
---|
732 | PRBool hasMore;
|
---|
733 | while (NS_SUCCEEDED(dirList->HasMoreElements(&hasMore)) && hasMore) {
|
---|
734 | nsCOMPtr<nsISupports> elem;
|
---|
735 | dirList->GetNext(getter_AddRefs(elem));
|
---|
736 | if (elem) {
|
---|
737 | nsCOMPtr<nsIFile> dir = do_QueryInterface(elem);
|
---|
738 | if (dir)
|
---|
739 | nsComponentManagerImpl::gComponentManager->AutoRegister(dir);
|
---|
740 |
|
---|
741 | // XXX should we worry about new component loaders being
|
---|
742 | // XXX defined by this process?
|
---|
743 | }
|
---|
744 | }
|
---|
745 | }
|
---|
746 |
|
---|
747 |
|
---|
748 | // Make sure the compreg file's mod time is current.
|
---|
749 | nsCOMPtr<nsIFile> compregFile;
|
---|
750 | rv = gDirectoryService->Get(NS_XPCOM_COMPONENT_REGISTRY_FILE,
|
---|
751 | NS_GET_IID(nsIFile),
|
---|
752 | getter_AddRefs(compregFile));
|
---|
753 | compregFile->SetLastModifiedTime(PR_Now() / 1000);
|
---|
754 | }
|
---|
755 |
|
---|
756 | // Pay the cost at startup time of starting this singleton.
|
---|
757 | nsIInterfaceInfoManager* iim = XPTI_GetInterfaceInfoManager();
|
---|
758 | NS_IF_RELEASE(iim);
|
---|
759 | #ifdef VBOX
|
---|
760 | // Must initialize the EventQueueService singleton before anyone is
|
---|
761 | // using it. The notification below creates a thread which races creating
|
---|
762 | // the EventQueueService creation otherwise, no matter what.
|
---|
763 | nsCOMPtr<nsIEventQueue> eventQ;
|
---|
764 | rv = NS_GetMainEventQ(getter_AddRefs(eventQ));
|
---|
765 | if (NS_FAILED(rv)) {
|
---|
766 | NS_ERROR("Could not create event queue for main thread");
|
---|
767 | /* this is just a build-time hack, to reference NS_ProxyRelease */
|
---|
768 | if (rv == 666)
|
---|
769 | NS_ProxyRelease(nsnull, nsnull);
|
---|
770 | return rv;
|
---|
771 | }
|
---|
772 | #endif /* VBOX */
|
---|
773 |
|
---|
774 | // Notify observers of xpcom autoregistration start
|
---|
775 | NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_OBSERVER_ID,
|
---|
776 | nsnull,
|
---|
777 | NS_XPCOM_STARTUP_OBSERVER_ID);
|
---|
778 |
|
---|
779 | return NS_OK;
|
---|
780 | }
|
---|
781 |
|
---|
782 |
|
---|
783 | static nsVoidArray* gExitRoutines;
|
---|
784 |
|
---|
785 | static void CallExitRoutines()
|
---|
786 | {
|
---|
787 | if (!gExitRoutines)
|
---|
788 | return;
|
---|
789 |
|
---|
790 | PRInt32 count = gExitRoutines->Count();
|
---|
791 | for (PRInt32 i = 0; i < count; i++) {
|
---|
792 | XPCOMExitRoutine func = (XPCOMExitRoutine) gExitRoutines->ElementAt(i);
|
---|
793 | func();
|
---|
794 | }
|
---|
795 | gExitRoutines->Clear();
|
---|
796 | delete gExitRoutines;
|
---|
797 | gExitRoutines = nsnull;
|
---|
798 | }
|
---|
799 |
|
---|
800 | nsresult NS_COM
|
---|
801 | NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
|
---|
802 | {
|
---|
803 | // priority are not used right now. It will need to be implemented as more
|
---|
804 | // classes are moved into the glue library --dougt
|
---|
805 | if (!gExitRoutines) {
|
---|
806 | gExitRoutines = new nsVoidArray();
|
---|
807 | if (!gExitRoutines) {
|
---|
808 | NS_WARNING("Failed to allocate gExitRoutines");
|
---|
809 | return NS_ERROR_FAILURE;
|
---|
810 | }
|
---|
811 | }
|
---|
812 |
|
---|
813 | PRBool okay = gExitRoutines->AppendElement((void*)exitRoutine);
|
---|
814 | return okay ? NS_OK : NS_ERROR_FAILURE;
|
---|
815 | }
|
---|
816 |
|
---|
817 | nsresult NS_COM
|
---|
818 | NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
|
---|
819 | {
|
---|
820 | if (!gExitRoutines)
|
---|
821 | return NS_ERROR_FAILURE;
|
---|
822 |
|
---|
823 | PRBool okay = gExitRoutines->RemoveElement((void*)exitRoutine);
|
---|
824 | return okay ? NS_OK : NS_ERROR_FAILURE;
|
---|
825 | }
|
---|
826 |
|
---|
827 |
|
---|
828 | //
|
---|
829 | // NS_ShutdownXPCOM()
|
---|
830 | //
|
---|
831 | // The shutdown sequence for xpcom would be
|
---|
832 | //
|
---|
833 | // - Release the Global Service Manager
|
---|
834 | // - Release all service instances held by the global service manager
|
---|
835 | // - Release the Global Service Manager itself
|
---|
836 | // - Release the Component Manager
|
---|
837 | // - Release all factories cached by the Component Manager
|
---|
838 | // - Unload Libraries
|
---|
839 | // - Release Contractid Cache held by Component Manager
|
---|
840 | // - Release dll abstraction held by Component Manager
|
---|
841 | // - Release the Registry held by Component Manager
|
---|
842 | // - Finally, release the component manager itself
|
---|
843 | //
|
---|
844 | nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
|
---|
845 | {
|
---|
846 |
|
---|
847 | // Notify observers of xpcom shutting down
|
---|
848 | nsresult rv = NS_OK;
|
---|
849 | {
|
---|
850 | // Block it so that the COMPtr will get deleted before we hit
|
---|
851 | // servicemanager shutdown
|
---|
852 | nsCOMPtr<nsIObserverService> observerService =
|
---|
853 | do_GetService("@mozilla.org/observer-service;1", &rv);
|
---|
854 | if (NS_SUCCEEDED(rv))
|
---|
855 | {
|
---|
856 | nsCOMPtr<nsIServiceManager> mgr;
|
---|
857 | rv = NS_GetServiceManager(getter_AddRefs(mgr));
|
---|
858 | if (NS_SUCCEEDED(rv))
|
---|
859 | {
|
---|
860 | (void) observerService->NotifyObservers(mgr,
|
---|
861 | NS_XPCOM_SHUTDOWN_OBSERVER_ID,
|
---|
862 | nsnull);
|
---|
863 | }
|
---|
864 | }
|
---|
865 | }
|
---|
866 |
|
---|
867 | // grab the event queue so that we can process events one last time before exiting
|
---|
868 | nsCOMPtr <nsIEventQueue> currentQ;
|
---|
869 | {
|
---|
870 | nsCOMPtr<nsIEventQueueService> eventQService =
|
---|
871 | do_GetService(kEventQueueServiceCID, &rv);
|
---|
872 |
|
---|
873 | if (eventQService) {
|
---|
874 | eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(currentQ));
|
---|
875 | }
|
---|
876 | }
|
---|
877 | // XPCOM is officially in shutdown mode NOW
|
---|
878 | // Set this only after the observers have been notified as this
|
---|
879 | // will cause servicemanager to become inaccessible.
|
---|
880 | gXPCOMShuttingDown = PR_TRUE;
|
---|
881 |
|
---|
882 | #ifdef DEBUG_dougt
|
---|
883 | fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
|
---|
884 | #endif
|
---|
885 |
|
---|
886 | #if 0 /// @todo later
|
---|
887 | IPC_Shutdown();
|
---|
888 | #endif
|
---|
889 |
|
---|
890 | // We may have AddRef'd for the caller of NS_InitXPCOM, so release it
|
---|
891 | // here again:
|
---|
892 | NS_IF_RELEASE(servMgr);
|
---|
893 |
|
---|
894 | // Shutdown global servicemanager
|
---|
895 | if (nsComponentManagerImpl::gComponentManager) {
|
---|
896 | nsComponentManagerImpl::gComponentManager->FreeServices();
|
---|
897 | }
|
---|
898 | nsServiceManager::ShutdownGlobalServiceManager(nsnull);
|
---|
899 |
|
---|
900 | if (currentQ) {
|
---|
901 | currentQ->ProcessPendingEvents();
|
---|
902 | currentQ = 0;
|
---|
903 | }
|
---|
904 |
|
---|
905 | nsProxyObjectManager::Shutdown();
|
---|
906 |
|
---|
907 | // Release the directory service
|
---|
908 | NS_IF_RELEASE(gDirectoryService);
|
---|
909 |
|
---|
910 | // Shutdown nsLocalFile string conversion
|
---|
911 | NS_ShutdownLocalFile();
|
---|
912 | #ifdef XP_UNIX
|
---|
913 | NS_ShutdownNativeCharsetUtils();
|
---|
914 | #endif
|
---|
915 |
|
---|
916 | // Shutdown the timer thread and all timers that might still be alive before
|
---|
917 | // shutting down the component manager
|
---|
918 | nsTimerImpl::Shutdown();
|
---|
919 |
|
---|
920 | CallExitRoutines();
|
---|
921 |
|
---|
922 | // Shutdown xpcom. This will release all loaders and cause others holding
|
---|
923 | // a refcount to the component manager to release it.
|
---|
924 | if (nsComponentManagerImpl::gComponentManager) {
|
---|
925 | rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
|
---|
926 | NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
|
---|
927 | } else
|
---|
928 | NS_WARNING("Component Manager was never created ...");
|
---|
929 |
|
---|
930 | // Release our own singletons
|
---|
931 | // Do this _after_ shutting down the component manager, because the
|
---|
932 | // JS component loader will use XPConnect to call nsIModule::canUnload,
|
---|
933 | // and that will spin up the InterfaceInfoManager again -- bad mojo
|
---|
934 | XPTI_FreeInterfaceInfoManager();
|
---|
935 |
|
---|
936 | // Finally, release the component manager last because it unloads the
|
---|
937 | // libraries:
|
---|
938 | if (nsComponentManagerImpl::gComponentManager) {
|
---|
939 | nsrefcnt cnt;
|
---|
940 | NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
|
---|
941 | NS_WARN_IF_FALSE(cnt == 0, "Component Manager being held past XPCOM shutdown.");
|
---|
942 | }
|
---|
943 | nsComponentManagerImpl::gComponentManager = nsnull;
|
---|
944 |
|
---|
945 | #ifdef DEBUG
|
---|
946 | _FreeAutoLockStatics();
|
---|
947 | #endif
|
---|
948 |
|
---|
949 | ShutdownSpecialSystemDirectory();
|
---|
950 |
|
---|
951 | EmptyEnumeratorImpl::Shutdown();
|
---|
952 | nsMemoryImpl::Shutdown();
|
---|
953 | NS_IF_RELEASE(gMemory);
|
---|
954 |
|
---|
955 | nsThread::Shutdown();
|
---|
956 | NS_PurgeAtomTable();
|
---|
957 |
|
---|
958 | NS_IF_RELEASE(gDebug);
|
---|
959 |
|
---|
960 | #ifdef NS_BUILD_REFCNT_LOGGING
|
---|
961 | nsTraceRefcntImpl::DumpStatistics();
|
---|
962 | nsTraceRefcntImpl::ResetStatistics();
|
---|
963 | nsTraceRefcntImpl::Shutdown();
|
---|
964 | #endif
|
---|
965 |
|
---|
966 | return NS_OK;
|
---|
967 | }
|
---|
968 |
|
---|
969 | #define GET_FUNC(_tag, _decl, _name) \
|
---|
970 | functions->_tag = (_decl) PR_FindSymbol(xpcomLib, _name); \
|
---|
971 | if (!functions->_tag) goto end
|
---|
972 |
|
---|
973 | nsresult NS_COM PR_CALLBACK
|
---|
974 | NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* libraryPath)
|
---|
975 | {
|
---|
976 | if (!functions)
|
---|
977 | return NS_ERROR_OUT_OF_MEMORY;
|
---|
978 |
|
---|
979 | if (functions->version != XPCOM_GLUE_VERSION)
|
---|
980 | return NS_ERROR_FAILURE;
|
---|
981 |
|
---|
982 | PRLibrary *xpcomLib = PR_LoadLibrary(libraryPath);
|
---|
983 | if (!xpcomLib)
|
---|
984 | return NS_ERROR_FAILURE;
|
---|
985 |
|
---|
986 | nsresult rv = NS_ERROR_FAILURE;
|
---|
987 |
|
---|
988 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
989 | GET_FUNC(init, InitFunc, "VBoxNsxpNS_InitXPCOM2");
|
---|
990 | GET_FUNC(shutdown, ShutdownFunc, "VBoxNsxpNS_ShutdownXPCOM");
|
---|
991 | GET_FUNC(getServiceManager, GetServiceManagerFunc, "VBoxNsxpNS_GetServiceManager");
|
---|
992 | GET_FUNC(getComponentManager, GetComponentManagerFunc, "VBoxNsxpNS_GetComponentManager");
|
---|
993 | GET_FUNC(getComponentRegistrar, GetComponentRegistrarFunc, "VBoxNsxpNS_GetComponentRegistrar");
|
---|
994 | GET_FUNC(getMemoryManager, GetMemoryManagerFunc, "VBoxNsxpNS_GetMemoryManager");
|
---|
995 | GET_FUNC(newLocalFile, NewLocalFileFunc, "VBoxNsxpNS_NewLocalFile");
|
---|
996 | GET_FUNC(newNativeLocalFile, NewNativeLocalFileFunc, "VBoxNsxpNS_NewNativeLocalFile");
|
---|
997 | GET_FUNC(registerExitRoutine, RegisterXPCOMExitRoutineFunc, "VBoxNsxpNS_RegisterXPCOMExitRoutine");
|
---|
998 | GET_FUNC(unregisterExitRoutine, UnregisterXPCOMExitRoutineFunc, "VBoxNsxpNS_UnregisterXPCOMExitRoutine");
|
---|
999 | #else /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
1000 | GET_FUNC(init, InitFunc, "NS_InitXPCOM2");
|
---|
1001 | GET_FUNC(shutdown, ShutdownFunc, "NS_ShutdownXPCOM");
|
---|
1002 | GET_FUNC(getServiceManager, GetServiceManagerFunc, "NS_GetServiceManager");
|
---|
1003 | GET_FUNC(getComponentManager, GetComponentManagerFunc, "NS_GetComponentManager");
|
---|
1004 | GET_FUNC(getComponentRegistrar, GetComponentRegistrarFunc, "NS_GetComponentRegistrar");
|
---|
1005 | GET_FUNC(getMemoryManager, GetMemoryManagerFunc, "NS_GetMemoryManager");
|
---|
1006 | GET_FUNC(newLocalFile, NewLocalFileFunc, "NS_NewLocalFile");
|
---|
1007 | GET_FUNC(newNativeLocalFile, NewNativeLocalFileFunc, "NS_NewNativeLocalFile");
|
---|
1008 | GET_FUNC(registerExitRoutine, RegisterXPCOMExitRoutineFunc, "NS_RegisterXPCOMExitRoutine");
|
---|
1009 | GET_FUNC(unregisterExitRoutine, UnregisterXPCOMExitRoutineFunc, "NS_UnregisterXPCOMExitRoutine");
|
---|
1010 | #endif /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
1011 |
|
---|
1012 | // these functions were added post 1.4 (need to check size of |functions|)
|
---|
1013 | if (functions->size > offsetof(XPCOMFunctions, getTraceRefcnt)) {
|
---|
1014 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
1015 | GET_FUNC(getDebug, GetDebugFunc, "VBoxNsxpNS_GetDebug");
|
---|
1016 | GET_FUNC(getTraceRefcnt, GetTraceRefcntFunc, "VBoxNsxpNS_GetTraceRefcnt");
|
---|
1017 | #else /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
1018 | GET_FUNC(getDebug, GetDebugFunc, "NS_GetDebug");
|
---|
1019 | GET_FUNC(getTraceRefcnt, GetTraceRefcntFunc, "NS_GetTraceRefcnt");
|
---|
1020 | #endif /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | // these functions were added post 1.6 (need to check size of |functions|)
|
---|
1024 | if (functions->size > offsetof(XPCOMFunctions, cstringCloneData)) {
|
---|
1025 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
1026 | GET_FUNC(stringContainerInit, StringContainerInitFunc, "VBoxNsxpNS_StringContainerInit");
|
---|
1027 | GET_FUNC(stringContainerFinish, StringContainerFinishFunc, "VBoxNsxpNS_StringContainerFinish");
|
---|
1028 | GET_FUNC(stringGetData, StringGetDataFunc, "VBoxNsxpNS_StringGetData");
|
---|
1029 | GET_FUNC(stringSetData, StringSetDataFunc, "VBoxNsxpNS_StringSetData");
|
---|
1030 | GET_FUNC(stringSetDataRange, StringSetDataRangeFunc, "VBoxNsxpNS_StringSetDataRange");
|
---|
1031 | GET_FUNC(stringCopy, StringCopyFunc, "VBoxNsxpNS_StringCopy");
|
---|
1032 | GET_FUNC(cstringContainerInit, CStringContainerInitFunc, "VBoxNsxpNS_CStringContainerInit");
|
---|
1033 | GET_FUNC(cstringContainerFinish, CStringContainerFinishFunc, "VBoxNsxpNS_CStringContainerFinish");
|
---|
1034 | GET_FUNC(cstringGetData, CStringGetDataFunc, "VBoxNsxpNS_CStringGetData");
|
---|
1035 | GET_FUNC(cstringSetData, CStringSetDataFunc, "VBoxNsxpNS_CStringSetData");
|
---|
1036 | GET_FUNC(cstringSetDataRange, CStringSetDataRangeFunc, "VBoxNsxpNS_CStringSetDataRange");
|
---|
1037 | GET_FUNC(cstringCopy, CStringCopyFunc, "VBoxNsxpNS_CStringCopy");
|
---|
1038 | GET_FUNC(cstringToUTF16, CStringToUTF16, "VBoxNsxpNS_CStringToUTF16");
|
---|
1039 | GET_FUNC(utf16ToCString, UTF16ToCString, "VBoxNsxpNS_UTF16ToCString");
|
---|
1040 | GET_FUNC(stringCloneData, StringCloneDataFunc, "VBoxNsxpNS_StringCloneData");
|
---|
1041 | GET_FUNC(cstringCloneData, CStringCloneDataFunc, "VBoxNsxpNS_CStringCloneData");
|
---|
1042 | #else /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
1043 | GET_FUNC(stringContainerInit, StringContainerInitFunc, "NS_StringContainerInit");
|
---|
1044 | GET_FUNC(stringContainerFinish, StringContainerFinishFunc, "NS_StringContainerFinish");
|
---|
1045 | GET_FUNC(stringGetData, StringGetDataFunc, "NS_StringGetData");
|
---|
1046 | GET_FUNC(stringSetData, StringSetDataFunc, "NS_StringSetData");
|
---|
1047 | GET_FUNC(stringSetDataRange, StringSetDataRangeFunc, "NS_StringSetDataRange");
|
---|
1048 | GET_FUNC(stringCopy, StringCopyFunc, "NS_StringCopy");
|
---|
1049 | GET_FUNC(cstringContainerInit, CStringContainerInitFunc, "NS_CStringContainerInit");
|
---|
1050 | GET_FUNC(cstringContainerFinish, CStringContainerFinishFunc, "NS_CStringContainerFinish");
|
---|
1051 | GET_FUNC(cstringGetData, CStringGetDataFunc, "NS_CStringGetData");
|
---|
1052 | GET_FUNC(cstringSetData, CStringSetDataFunc, "NS_CStringSetData");
|
---|
1053 | GET_FUNC(cstringSetDataRange, CStringSetDataRangeFunc, "NS_CStringSetDataRange");
|
---|
1054 | GET_FUNC(cstringCopy, CStringCopyFunc, "NS_CStringCopy");
|
---|
1055 | GET_FUNC(cstringToUTF16, CStringToUTF16, "NS_CStringToUTF16");
|
---|
1056 | GET_FUNC(utf16ToCString, UTF16ToCString, "NS_UTF16ToCString");
|
---|
1057 | GET_FUNC(stringCloneData, StringCloneDataFunc, "NS_StringCloneData");
|
---|
1058 | GET_FUNC(cstringCloneData, CStringCloneDataFunc, "NS_CStringCloneData");
|
---|
1059 | #endif /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | rv = NS_OK;
|
---|
1063 | end:
|
---|
1064 | PR_UnloadLibrary(xpcomLib); // the library is refcnt'ed above by the caller.
|
---|
1065 | return rv;
|
---|
1066 | }
|
---|