1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* vim:set ts=4 sw=4 et cindent: */
|
---|
3 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
4 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
5 | *
|
---|
6 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
7 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
8 | * the License. You may obtain a copy of the License at
|
---|
9 | * http://www.mozilla.org/MPL/
|
---|
10 | *
|
---|
11 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
13 | * for the specific language governing rights and limitations under the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * The Original Code is mozilla.org code.
|
---|
17 | *
|
---|
18 | * The Initial Developer of the Original Code is
|
---|
19 | * Netscape Communications Corporation.
|
---|
20 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
21 | * the Initial Developer. All Rights Reserved.
|
---|
22 | *
|
---|
23 | * Contributor(s):
|
---|
24 | *
|
---|
25 | * Alternatively, the contents of this file may be used under the terms of
|
---|
26 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
27 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
28 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
29 | * of those above. If you wish to allow use of your version of this file only
|
---|
30 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
31 | * use your version of this file under the terms of the MPL, indicate your
|
---|
32 | * decision by deleting the provisions above and replace them with the notice
|
---|
33 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
34 | * the provisions above, a recipient may use your version of this file under
|
---|
35 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
36 | *
|
---|
37 | * ***** END LICENSE BLOCK ***** */
|
---|
38 |
|
---|
39 | #include "nsXPCOMGlue.h"
|
---|
40 |
|
---|
41 | #include "nspr.h"
|
---|
42 | #include "nsMemory.h"
|
---|
43 | #include "nsGREDirServiceProvider.h"
|
---|
44 | #include "nsXPCOMPrivate.h"
|
---|
45 | #include <stdlib.h>
|
---|
46 |
|
---|
47 | #if XP_WIN32
|
---|
48 | #include <windows.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | void GRE_AddGREToEnvironment();
|
---|
52 |
|
---|
53 | // functions provided by nsMemory.cpp and nsDebug.cpp
|
---|
54 | nsresult GlueStartupMemory();
|
---|
55 | void GlueShutdownMemory();
|
---|
56 | nsresult GlueStartupDebug();
|
---|
57 | void GlueShutdownDebug();
|
---|
58 |
|
---|
59 | static PRLibrary *xpcomLib;
|
---|
60 | static XPCOMFunctions xpcomFunctions;
|
---|
61 |
|
---|
62 | extern "C"
|
---|
63 | nsresult XPCOMGlueStartup(const char* xpcomFile)
|
---|
64 | {
|
---|
65 | #ifdef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
---|
66 | return NS_OK;
|
---|
67 | #else
|
---|
68 | nsresult rv = NS_OK;
|
---|
69 | GetFrozenFunctionsFunc function = nsnull;
|
---|
70 |
|
---|
71 | xpcomFunctions.version = XPCOM_GLUE_VERSION;
|
---|
72 | xpcomFunctions.size = sizeof(XPCOMFunctions);
|
---|
73 |
|
---|
74 | //
|
---|
75 | // if xpcomFile == ".", then we assume xpcom is already loaded, and we'll
|
---|
76 | // use NSPR to find NS_GetFrozenFunctions from the list of already loaded
|
---|
77 | // libraries.
|
---|
78 | //
|
---|
79 | // otherwise, we try to load xpcom and then look for NS_GetFrozenFunctions.
|
---|
80 | // if xpcomFile == NULL, then we try to load xpcom by name w/o a fully
|
---|
81 | // qualified path.
|
---|
82 | //
|
---|
83 |
|
---|
84 | if (xpcomFile && (xpcomFile[0] == '.' && xpcomFile[1] == '\0')) {
|
---|
85 | function = (GetFrozenFunctionsFunc)
|
---|
86 | PR_FindSymbolAndLibrary("NS_GetFrozenFunctions", &xpcomLib);
|
---|
87 | if (!function) {
|
---|
88 | // The symbol was not found, so failover to loading XPCOM_DLL,
|
---|
89 | // and look for the symbol there. See bug 240986 for details.
|
---|
90 | xpcomFile = nsnull;
|
---|
91 | }
|
---|
92 | else {
|
---|
93 | char *libPath = PR_GetLibraryFilePathname(XPCOM_DLL, (PRFuncPtr) function);
|
---|
94 | if (!libPath)
|
---|
95 | rv = NS_ERROR_FAILURE;
|
---|
96 | else {
|
---|
97 | rv = (*function)(&xpcomFunctions, libPath);
|
---|
98 | PR_Free(libPath);
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (!function) {
|
---|
104 | PRLibSpec libSpec;
|
---|
105 |
|
---|
106 | libSpec.type = PR_LibSpec_Pathname;
|
---|
107 | if (!xpcomFile)
|
---|
108 | libSpec.value.pathname = XPCOM_DLL;
|
---|
109 | else
|
---|
110 | libSpec.value.pathname = xpcomFile;
|
---|
111 |
|
---|
112 | xpcomLib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL);
|
---|
113 | #ifdef __DARWIN__
|
---|
114 | /* works around bundle problem. */
|
---|
115 | if (!xpcomLib) {
|
---|
116 | const char *home = PR_GetEnv("VBOX_XPCOM_HOME");
|
---|
117 | if (home) {
|
---|
118 | char path[PATH_MAX];
|
---|
119 | snprintf(path, sizeof(path), "%s/%s", home, libSpec.value.pathname);
|
---|
120 | libSpec.value.pathname = path;
|
---|
121 | xpcomLib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL);
|
---|
122 | }
|
---|
123 | }
|
---|
124 | #endif
|
---|
125 | if (!xpcomLib)
|
---|
126 | return NS_ERROR_FAILURE;
|
---|
127 |
|
---|
128 | function = (GetFrozenFunctionsFunc) PR_FindSymbol(xpcomLib, "NS_GetFrozenFunctions");
|
---|
129 |
|
---|
130 | if (!function)
|
---|
131 | rv = NS_ERROR_FAILURE;
|
---|
132 | else
|
---|
133 | rv = (*function)(&xpcomFunctions, libSpec.value.pathname);
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (NS_FAILED(rv))
|
---|
137 | goto bail;
|
---|
138 |
|
---|
139 | rv = GlueStartupDebug();
|
---|
140 | if (NS_FAILED(rv))
|
---|
141 | goto bail;
|
---|
142 |
|
---|
143 | // startup the nsMemory
|
---|
144 | rv = GlueStartupMemory();
|
---|
145 | if (NS_FAILED(rv)) {
|
---|
146 | GlueShutdownDebug();
|
---|
147 | goto bail;
|
---|
148 | }
|
---|
149 |
|
---|
150 | GRE_AddGREToEnvironment();
|
---|
151 | return NS_OK;
|
---|
152 |
|
---|
153 | bail:
|
---|
154 | PR_UnloadLibrary(xpcomLib);
|
---|
155 | xpcomLib = nsnull;
|
---|
156 | memset(&xpcomFunctions, 0, sizeof(xpcomFunctions));
|
---|
157 | return NS_ERROR_FAILURE;
|
---|
158 | #endif
|
---|
159 | }
|
---|
160 |
|
---|
161 | extern "C"
|
---|
162 | nsresult XPCOMGlueShutdown()
|
---|
163 | {
|
---|
164 | #ifdef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
---|
165 | return NS_OK;
|
---|
166 | #else
|
---|
167 |
|
---|
168 | GlueShutdownMemory();
|
---|
169 |
|
---|
170 | GlueShutdownDebug();
|
---|
171 |
|
---|
172 | if (xpcomLib) {
|
---|
173 | PR_UnloadLibrary(xpcomLib);
|
---|
174 | xpcomLib = nsnull;
|
---|
175 | }
|
---|
176 |
|
---|
177 | memset(&xpcomFunctions, 0, sizeof(xpcomFunctions));
|
---|
178 | return NS_OK;
|
---|
179 | #endif
|
---|
180 | }
|
---|
181 |
|
---|
182 | #ifndef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
---|
183 | extern "C" NS_COM nsresult
|
---|
184 | NS_InitXPCOM2(nsIServiceManager* *result,
|
---|
185 | nsIFile* binDirectory,
|
---|
186 | nsIDirectoryServiceProvider* appFileLocationProvider)
|
---|
187 | {
|
---|
188 | if (!xpcomFunctions.init)
|
---|
189 | return NS_ERROR_NOT_INITIALIZED;
|
---|
190 | return xpcomFunctions.init(result, binDirectory, appFileLocationProvider);
|
---|
191 | }
|
---|
192 |
|
---|
193 | extern "C" NS_COM nsresult
|
---|
194 | NS_ShutdownXPCOM(nsIServiceManager* servMgr)
|
---|
195 | {
|
---|
196 | if (!xpcomFunctions.shutdown)
|
---|
197 | return NS_ERROR_NOT_INITIALIZED;
|
---|
198 | return xpcomFunctions.shutdown(servMgr);
|
---|
199 | }
|
---|
200 |
|
---|
201 | extern "C" NS_COM nsresult
|
---|
202 | NS_GetServiceManager(nsIServiceManager* *result)
|
---|
203 | {
|
---|
204 | if (!xpcomFunctions.getServiceManager)
|
---|
205 | return NS_ERROR_NOT_INITIALIZED;
|
---|
206 | return xpcomFunctions.getServiceManager(result);
|
---|
207 | }
|
---|
208 |
|
---|
209 | extern "C" NS_COM nsresult
|
---|
210 | NS_GetComponentManager(nsIComponentManager* *result)
|
---|
211 | {
|
---|
212 | if (!xpcomFunctions.getComponentManager)
|
---|
213 | return NS_ERROR_NOT_INITIALIZED;
|
---|
214 | return xpcomFunctions.getComponentManager(result);
|
---|
215 | }
|
---|
216 |
|
---|
217 | extern "C" NS_COM nsresult
|
---|
218 | NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
|
---|
219 | {
|
---|
220 | if (!xpcomFunctions.getComponentRegistrar)
|
---|
221 | return NS_ERROR_NOT_INITIALIZED;
|
---|
222 | return xpcomFunctions.getComponentRegistrar(result);
|
---|
223 | }
|
---|
224 |
|
---|
225 | extern "C" NS_COM nsresult
|
---|
226 | NS_GetMemoryManager(nsIMemory* *result)
|
---|
227 | {
|
---|
228 | if (!xpcomFunctions.getMemoryManager)
|
---|
229 | return NS_ERROR_NOT_INITIALIZED;
|
---|
230 | return xpcomFunctions.getMemoryManager(result);
|
---|
231 | }
|
---|
232 |
|
---|
233 | extern "C" NS_COM nsresult
|
---|
234 | NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result)
|
---|
235 | {
|
---|
236 | if (!xpcomFunctions.newLocalFile)
|
---|
237 | return NS_ERROR_NOT_INITIALIZED;
|
---|
238 | return xpcomFunctions.newLocalFile(path, followLinks, result);
|
---|
239 | }
|
---|
240 |
|
---|
241 | extern "C" NS_COM nsresult
|
---|
242 | NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result)
|
---|
243 | {
|
---|
244 | if (!xpcomFunctions.newNativeLocalFile)
|
---|
245 | return NS_ERROR_NOT_INITIALIZED;
|
---|
246 | return xpcomFunctions.newNativeLocalFile(path, followLinks, result);
|
---|
247 | }
|
---|
248 |
|
---|
249 | extern "C" NS_COM nsresult
|
---|
250 | NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
|
---|
251 | {
|
---|
252 | if (!xpcomFunctions.registerExitRoutine)
|
---|
253 | return NS_ERROR_NOT_INITIALIZED;
|
---|
254 | return xpcomFunctions.registerExitRoutine(exitRoutine, priority);
|
---|
255 | }
|
---|
256 |
|
---|
257 | extern "C" NS_COM nsresult
|
---|
258 | NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
|
---|
259 | {
|
---|
260 | if (!xpcomFunctions.unregisterExitRoutine)
|
---|
261 | return NS_ERROR_NOT_INITIALIZED;
|
---|
262 | return xpcomFunctions.unregisterExitRoutine(exitRoutine);
|
---|
263 | }
|
---|
264 |
|
---|
265 | extern "C" NS_COM nsresult
|
---|
266 | NS_GetDebug(nsIDebug* *result)
|
---|
267 | {
|
---|
268 | if (!xpcomFunctions.getDebug)
|
---|
269 | return NS_ERROR_NOT_INITIALIZED;
|
---|
270 | return xpcomFunctions.getDebug(result);
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 | extern "C" NS_COM nsresult
|
---|
275 | NS_GetTraceRefcnt(nsITraceRefcnt* *result)
|
---|
276 | {
|
---|
277 | if (!xpcomFunctions.getTraceRefcnt)
|
---|
278 | return NS_ERROR_NOT_INITIALIZED;
|
---|
279 | return xpcomFunctions.getTraceRefcnt(result);
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | extern "C" NS_COM nsresult
|
---|
284 | NS_StringContainerInit(nsStringContainer &aStr)
|
---|
285 | {
|
---|
286 | if (!xpcomFunctions.stringContainerInit)
|
---|
287 | return NS_ERROR_NOT_INITIALIZED;
|
---|
288 | return xpcomFunctions.stringContainerInit(aStr);
|
---|
289 | }
|
---|
290 |
|
---|
291 | extern "C" NS_COM void
|
---|
292 | NS_StringContainerFinish(nsStringContainer &aStr)
|
---|
293 | {
|
---|
294 | if (xpcomFunctions.stringContainerFinish)
|
---|
295 | xpcomFunctions.stringContainerFinish(aStr);
|
---|
296 | }
|
---|
297 |
|
---|
298 | extern "C" NS_COM PRUint32
|
---|
299 | NS_StringGetData(const nsAString &aStr, const PRUnichar **aBuf, PRBool *aTerm)
|
---|
300 | {
|
---|
301 | if (!xpcomFunctions.stringGetData) {
|
---|
302 | *aBuf = nsnull;
|
---|
303 | return 0;
|
---|
304 | }
|
---|
305 | return xpcomFunctions.stringGetData(aStr, aBuf, aTerm);
|
---|
306 | }
|
---|
307 |
|
---|
308 | extern "C" NS_COM PRUnichar *
|
---|
309 | NS_StringCloneData(const nsAString &aStr)
|
---|
310 | {
|
---|
311 | if (!xpcomFunctions.stringCloneData)
|
---|
312 | return nsnull;
|
---|
313 | return xpcomFunctions.stringCloneData(aStr);
|
---|
314 | }
|
---|
315 |
|
---|
316 | extern "C" NS_COM nsresult
|
---|
317 | NS_StringSetData(nsAString &aStr, const PRUnichar *aBuf, PRUint32 aCount)
|
---|
318 | {
|
---|
319 | if (!xpcomFunctions.stringSetData)
|
---|
320 | return NS_ERROR_NOT_INITIALIZED;
|
---|
321 |
|
---|
322 | return xpcomFunctions.stringSetData(aStr, aBuf, aCount);
|
---|
323 | }
|
---|
324 |
|
---|
325 | extern "C" NS_COM nsresult
|
---|
326 | NS_StringSetDataRange(nsAString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
|
---|
327 | const PRUnichar *aBuf, PRUint32 aCount)
|
---|
328 | {
|
---|
329 | if (!xpcomFunctions.stringSetDataRange)
|
---|
330 | return NS_ERROR_NOT_INITIALIZED;
|
---|
331 | return xpcomFunctions.stringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount);
|
---|
332 | }
|
---|
333 |
|
---|
334 | extern "C" NS_COM nsresult
|
---|
335 | NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
|
---|
336 | {
|
---|
337 | if (!xpcomFunctions.stringCopy)
|
---|
338 | return NS_ERROR_NOT_INITIALIZED;
|
---|
339 | return xpcomFunctions.stringCopy(aDest, aSrc);
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | extern "C" NS_COM nsresult
|
---|
344 | NS_CStringContainerInit(nsCStringContainer &aStr)
|
---|
345 | {
|
---|
346 | if (!xpcomFunctions.cstringContainerInit)
|
---|
347 | return NS_ERROR_NOT_INITIALIZED;
|
---|
348 | return xpcomFunctions.cstringContainerInit(aStr);
|
---|
349 | }
|
---|
350 |
|
---|
351 | extern "C" NS_COM void
|
---|
352 | NS_CStringContainerFinish(nsCStringContainer &aStr)
|
---|
353 | {
|
---|
354 | if (xpcomFunctions.cstringContainerFinish)
|
---|
355 | xpcomFunctions.cstringContainerFinish(aStr);
|
---|
356 | }
|
---|
357 |
|
---|
358 | extern "C" NS_COM PRUint32
|
---|
359 | NS_CStringGetData(const nsACString &aStr, const char **aBuf, PRBool *aTerm)
|
---|
360 | {
|
---|
361 | if (!xpcomFunctions.cstringGetData) {
|
---|
362 | *aBuf = nsnull;
|
---|
363 | return 0;
|
---|
364 | }
|
---|
365 | return xpcomFunctions.cstringGetData(aStr, aBuf, aTerm);
|
---|
366 | }
|
---|
367 |
|
---|
368 | extern "C" NS_COM char *
|
---|
369 | NS_CStringCloneData(const nsACString &aStr)
|
---|
370 | {
|
---|
371 | if (!xpcomFunctions.cstringCloneData)
|
---|
372 | return nsnull;
|
---|
373 | return xpcomFunctions.cstringCloneData(aStr);
|
---|
374 | }
|
---|
375 |
|
---|
376 | extern "C" NS_COM nsresult
|
---|
377 | NS_CStringSetData(nsACString &aStr, const char *aBuf, PRUint32 aCount)
|
---|
378 | {
|
---|
379 | if (!xpcomFunctions.cstringSetData)
|
---|
380 | return NS_ERROR_NOT_INITIALIZED;
|
---|
381 | return xpcomFunctions.cstringSetData(aStr, aBuf, aCount);
|
---|
382 | }
|
---|
383 |
|
---|
384 | extern "C" NS_COM nsresult
|
---|
385 | NS_CStringSetDataRange(nsACString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
|
---|
386 | const char *aBuf, PRUint32 aCount)
|
---|
387 | {
|
---|
388 | if (!xpcomFunctions.cstringSetDataRange)
|
---|
389 | return NS_ERROR_NOT_INITIALIZED;
|
---|
390 | return xpcomFunctions.cstringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount);
|
---|
391 | }
|
---|
392 |
|
---|
393 | extern "C" NS_COM nsresult
|
---|
394 | NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
|
---|
395 | {
|
---|
396 | if (!xpcomFunctions.cstringCopy)
|
---|
397 | return NS_ERROR_NOT_INITIALIZED;
|
---|
398 | return xpcomFunctions.cstringCopy(aDest, aSrc);
|
---|
399 | }
|
---|
400 |
|
---|
401 | extern "C" NS_COM nsresult
|
---|
402 | NS_CStringToUTF16(const nsACString &aSrc, PRUint32 aSrcEncoding, nsAString &aDest)
|
---|
403 | {
|
---|
404 | if (!xpcomFunctions.cstringToUTF16)
|
---|
405 | return NS_ERROR_NOT_INITIALIZED;
|
---|
406 | return xpcomFunctions.cstringToUTF16(aSrc, aSrcEncoding, aDest);
|
---|
407 | }
|
---|
408 |
|
---|
409 | extern "C" NS_COM nsresult
|
---|
410 | NS_UTF16ToCString(const nsAString &aSrc, PRUint32 aDestEncoding, nsACString &aDest)
|
---|
411 | {
|
---|
412 | if (!xpcomFunctions.utf16ToCString)
|
---|
413 | return NS_ERROR_NOT_INITIALIZED;
|
---|
414 | return xpcomFunctions.utf16ToCString(aSrc, aDestEncoding, aDest);
|
---|
415 | }
|
---|
416 |
|
---|
417 | #endif // #ifndef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
---|
418 |
|
---|
419 |
|
---|
420 | static char sEnvString[MAXPATHLEN*10];
|
---|
421 | static char* spEnvString = 0;
|
---|
422 |
|
---|
423 | void
|
---|
424 | GRE_AddGREToEnvironment()
|
---|
425 | {
|
---|
426 | const char* grePath = GRE_GetGREPath();
|
---|
427 | char szPath[MAXPATHLEN];
|
---|
428 | if (!grePath)
|
---|
429 | return;
|
---|
430 |
|
---|
431 | const char* path = PR_GetEnv(XPCOM_SEARCH_KEY);
|
---|
432 | if (!path)
|
---|
433 | path = "";
|
---|
434 | #ifdef VBOX
|
---|
435 | else
|
---|
436 | {
|
---|
437 | /* sEnvString is part of the environment because of putenv().
|
---|
438 | * path is only temporarily used and not argument of putenv() itself */
|
---|
439 | snprintf(szPath, sizeof(szPath), "%s", path);
|
---|
440 | path = szPath;
|
---|
441 | }
|
---|
442 | #endif
|
---|
443 |
|
---|
444 | if (spEnvString) PR_smprintf_free(spEnvString);
|
---|
445 |
|
---|
446 | /**
|
---|
447 | * if the PATH string is longer than our static buffer, allocate a
|
---|
448 | * buffer for the environment string. This buffer will be leaked at shutdown!
|
---|
449 | */
|
---|
450 | if (strlen(grePath) + strlen(path) +
|
---|
451 | sizeof(XPCOM_SEARCH_KEY) + sizeof(XPCOM_ENV_PATH_SEPARATOR) > MAXPATHLEN*10) {
|
---|
452 | if (PR_smprintf(XPCOM_SEARCH_KEY "=%s" XPCOM_ENV_PATH_SEPARATOR "%s",
|
---|
453 | grePath,
|
---|
454 | path)) {
|
---|
455 | PR_SetEnv(spEnvString);
|
---|
456 | }
|
---|
457 | } else {
|
---|
458 | if (sprintf(sEnvString,
|
---|
459 | XPCOM_SEARCH_KEY "=%s" XPCOM_ENV_PATH_SEPARATOR "%s",
|
---|
460 | grePath,
|
---|
461 | path) > 0) {
|
---|
462 | PR_SetEnv(sEnvString);
|
---|
463 | }
|
---|
464 | }
|
---|
465 |
|
---|
466 | #if XP_WIN32
|
---|
467 | // On windows, the current directory is searched before the
|
---|
468 | // PATH environment variable. This is a very bad thing
|
---|
469 | // since libraries in the cwd will be picked up before
|
---|
470 | // any that are in either the application or GRE directory.
|
---|
471 |
|
---|
472 | if (grePath) {
|
---|
473 | SetCurrentDirectory(grePath);
|
---|
474 | }
|
---|
475 | #endif
|
---|
476 | }
|
---|
477 |
|
---|
478 |
|
---|
479 | // Default GRE startup/shutdown code
|
---|
480 |
|
---|
481 | extern "C"
|
---|
482 | nsresult GRE_Startup()
|
---|
483 | {
|
---|
484 | const char* xpcomLocation = GRE_GetXPCOMPath();
|
---|
485 |
|
---|
486 | // Startup the XPCOM Glue that links us up with XPCOM.
|
---|
487 | nsresult rv = XPCOMGlueStartup(xpcomLocation);
|
---|
488 |
|
---|
489 | if (NS_FAILED(rv)) {
|
---|
490 | NS_WARNING("gre: XPCOMGlueStartup failed");
|
---|
491 | return rv;
|
---|
492 | }
|
---|
493 |
|
---|
494 | nsGREDirServiceProvider *provider = new nsGREDirServiceProvider();
|
---|
495 | if ( !provider ) {
|
---|
496 | NS_WARNING("GRE_Startup failed");
|
---|
497 | XPCOMGlueShutdown();
|
---|
498 | return NS_ERROR_OUT_OF_MEMORY;
|
---|
499 | }
|
---|
500 |
|
---|
501 | nsCOMPtr<nsIServiceManager> servMan;
|
---|
502 | NS_ADDREF( provider );
|
---|
503 | rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, provider);
|
---|
504 | NS_RELEASE(provider);
|
---|
505 |
|
---|
506 | if ( NS_FAILED(rv) || !servMan) {
|
---|
507 | NS_WARNING("gre: NS_InitXPCOM failed");
|
---|
508 | XPCOMGlueShutdown();
|
---|
509 | return rv;
|
---|
510 | }
|
---|
511 |
|
---|
512 | return NS_OK;
|
---|
513 | }
|
---|
514 |
|
---|
515 | extern "C"
|
---|
516 | nsresult GRE_Shutdown()
|
---|
517 | {
|
---|
518 | NS_ShutdownXPCOM(nsnull);
|
---|
519 | XPCOMGlueShutdown();
|
---|
520 | return NS_OK;
|
---|
521 | }
|
---|