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