2002-06-21 23:58:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-02-19 05:44:03 +03:00
|
|
|
/* vim:set ts=4 sw=4 et cindent: */
|
2002-06-21 23:58:54 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-06-21 23:58:54 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2002-06-21 23:58:54 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-06-21 23:58:54 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2002-06-21 23:58:54 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-06-21 23:58:54 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-06-21 23:58:54 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2003-11-17 09:13:49 +03:00
|
|
|
#include "nsXPCOMGlue.h"
|
|
|
|
|
2002-06-21 23:58:54 +04:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "nsMemory.h"
|
2003-11-17 09:13:49 +03:00
|
|
|
#include "nsGREDirServiceProvider.h"
|
2002-06-21 23:58:54 +04:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2003-11-17 09:13:49 +03:00
|
|
|
#include <stdlib.h>
|
2002-06-21 23:58:54 +04:00
|
|
|
|
2003-11-17 09:13:49 +03:00
|
|
|
#if XP_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void GRE_AddGREToEnvironment();
|
|
|
|
|
|
|
|
// functions provided by nsMemory.cpp and nsDebug.cpp
|
|
|
|
nsresult GlueStartupMemory();
|
|
|
|
void GlueShutdownMemory();
|
|
|
|
nsresult GlueStartupDebug();
|
|
|
|
void GlueShutdownDebug();
|
2002-06-21 23:58:54 +04:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
static PRLibrary *xpcomLib;
|
|
|
|
static XPCOMFunctions xpcomFunctions;
|
2002-06-21 23:58:54 +04:00
|
|
|
|
|
|
|
extern "C"
|
2003-11-17 09:13:49 +03:00
|
|
|
nsresult XPCOMGlueStartup(const char* xpcomFile)
|
2002-06-21 23:58:54 +04:00
|
|
|
{
|
2002-07-16 03:32:36 +04:00
|
|
|
#ifdef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
2002-06-21 23:58:54 +04:00
|
|
|
nsresult rv;
|
2004-02-19 05:44:03 +03:00
|
|
|
GetFrozenFunctionsFunc function;
|
|
|
|
|
|
|
|
xpcomFunctions.version = XPCOM_GLUE_VERSION;
|
|
|
|
xpcomFunctions.size = sizeof(XPCOMFunctions);
|
|
|
|
|
|
|
|
//
|
|
|
|
// if xpcomFile == ".", then we assume xpcom is already loaded, and we'll
|
|
|
|
// use NSPR to find NS_GetFrozenFunctions from the list of already loaded
|
|
|
|
// libraries.
|
|
|
|
//
|
|
|
|
// otherwise, we try to load xpcom and then look for NS_GetFrozenFunctions.
|
|
|
|
// if xpcomFile == NULL, then we try to load xpcom by name w/o a fully
|
|
|
|
// qualified path.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (xpcomFile && (xpcomFile[0] == '.' && xpcomFile[1] == '\0')) {
|
|
|
|
function = (GetFrozenFunctionsFunc)PR_FindSymbolAndLibrary("NS_GetFrozenFunctions", &xpcomLib);
|
|
|
|
if (!function)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
char *libPath = PR_GetLibraryFilePathname(XPCOM_DLL, (PRFuncPtr) function);
|
|
|
|
|
|
|
|
if (!libPath)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
else {
|
|
|
|
rv = (*function)(&xpcomFunctions, libPath);
|
|
|
|
PR_Free(libPath);
|
|
|
|
}
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
else {
|
|
|
|
PRLibSpec libSpec;
|
2002-06-21 23:58:54 +04:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
libSpec.type = PR_LibSpec_Pathname;
|
|
|
|
if (!xpcomFile)
|
|
|
|
libSpec.value.pathname = XPCOM_DLL;
|
|
|
|
else
|
|
|
|
libSpec.value.pathname = xpcomFile;
|
2002-06-21 23:58:54 +04:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
xpcomLib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL);
|
|
|
|
if (!xpcomLib)
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-06-21 23:58:54 +04:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
function = (GetFrozenFunctionsFunc) PR_FindSymbol(xpcomLib, "NS_GetFrozenFunctions");
|
|
|
|
|
|
|
|
if (!function)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
else
|
|
|
|
rv = (*function)(&xpcomFunctions, libSpec.value.pathname);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
2002-07-16 03:32:36 +04:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto bail;
|
2003-07-08 02:11:36 +04:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
rv = GlueStartupDebug();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto bail;
|
2003-07-08 02:11:36 +04:00
|
|
|
|
2002-12-10 04:37:56 +03:00
|
|
|
// startup the nsMemory
|
2003-07-08 02:11:36 +04:00
|
|
|
rv = GlueStartupMemory();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
GlueShutdownDebug();
|
2004-02-19 05:44:03 +03:00
|
|
|
goto bail;
|
2003-07-08 02:11:36 +04:00
|
|
|
}
|
|
|
|
|
2003-11-17 09:13:49 +03:00
|
|
|
GRE_AddGREToEnvironment();
|
2004-02-19 05:44:03 +03:00
|
|
|
return NS_OK;
|
2003-11-17 09:13:49 +03:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
bail:
|
|
|
|
PR_UnloadLibrary(xpcomLib);
|
|
|
|
xpcomLib = nsnull;
|
2004-04-12 00:52:32 +04:00
|
|
|
memset(&xpcomFunctions, 0, sizeof(xpcomFunctions));
|
2004-02-19 05:44:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-06-21 23:58:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
2003-11-17 09:13:49 +03:00
|
|
|
nsresult XPCOMGlueShutdown()
|
2002-06-21 23:58:54 +04:00
|
|
|
{
|
2002-07-16 03:32:36 +04:00
|
|
|
#ifdef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
2002-06-21 23:58:54 +04:00
|
|
|
|
2002-12-16 22:26:58 +03:00
|
|
|
GlueShutdownMemory();
|
|
|
|
|
2003-07-08 02:11:36 +04:00
|
|
|
GlueShutdownDebug();
|
|
|
|
|
2002-06-21 23:58:54 +04:00
|
|
|
if (xpcomLib) {
|
|
|
|
PR_UnloadLibrary(xpcomLib);
|
|
|
|
xpcomLib = nsnull;
|
|
|
|
}
|
2002-12-10 04:37:56 +03:00
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
memset(&xpcomFunctions, 0, sizeof(xpcomFunctions));
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_OK;
|
2002-07-16 03:32:36 +04:00
|
|
|
#endif
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
2002-07-16 03:32:36 +04:00
|
|
|
#ifndef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
2002-06-21 23:58:54 +04:00
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_InitXPCOM2(nsIServiceManager* *result,
|
|
|
|
nsIFile* binDirectory,
|
|
|
|
nsIDirectoryServiceProvider* appFileLocationProvider)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.init)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.init(result, binDirectory, appFileLocationProvider);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_ShutdownXPCOM(nsIServiceManager* servMgr)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.shutdown)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.shutdown(servMgr);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_GetServiceManager(nsIServiceManager* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.getServiceManager)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.getServiceManager(result);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_GetComponentManager(nsIComponentManager* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.getComponentManager)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.getComponentManager(result);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.getComponentRegistrar)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.getComponentRegistrar(result);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_GetMemoryManager(nsIMemory* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.getMemoryManager)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.getMemoryManager(result);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.newLocalFile)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.newLocalFile(path, followLinks, result);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.newNativeLocalFile)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.newNativeLocalFile(path, followLinks, result);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.registerExitRoutine)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.registerExitRoutine(exitRoutine, priority);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.unregisterExitRoutine)
|
2002-06-21 23:58:54 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.unregisterExitRoutine(exitRoutine);
|
2002-06-21 23:58:54 +04:00
|
|
|
}
|
2003-07-08 02:11:36 +04:00
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_GetDebug(nsIDebug* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.getDebug)
|
2003-07-08 02:11:36 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.getDebug(result);
|
2003-07-08 02:11:36 +04:00
|
|
|
}
|
|
|
|
|
2003-08-05 09:29:10 +04:00
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_GetTraceRefcnt(nsITraceRefcnt* *result)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.getTraceRefcnt)
|
2003-08-05 09:29:10 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.getTraceRefcnt(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_StringContainerInit(nsStringContainer &aStr)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.stringContainerInit)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.stringContainerInit(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM void
|
|
|
|
NS_StringContainerFinish(nsStringContainer &aStr)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (xpcomFunctions.stringContainerFinish)
|
2004-02-19 05:44:03 +03:00
|
|
|
xpcomFunctions.stringContainerFinish(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM PRUint32
|
|
|
|
NS_StringGetData(const nsAString &aStr, const PRUnichar **aBuf, PRBool *aTerm)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.stringGetData) {
|
|
|
|
*aBuf = nsnull;
|
2004-02-19 05:44:03 +03:00
|
|
|
return 0;
|
2004-04-12 00:52:32 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.stringGetData(aStr, aBuf, aTerm);
|
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_StringSetData(nsAString &aStr, const PRUnichar *aBuf, PRUint32 aCount)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.stringSetData)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
return xpcomFunctions.stringSetData(aStr, aBuf, aCount);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_StringSetDataRange(nsAString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
|
|
|
|
const PRUnichar *aBuf, PRUint32 aCount)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.stringSetDataRange)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.stringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.stringCopy)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.stringCopy(aDest, aSrc);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_CStringContainerInit(nsCStringContainer &aStr)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.cstringContainerInit)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.cstringContainerInit(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM void
|
|
|
|
NS_CStringContainerFinish(nsCStringContainer &aStr)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (xpcomFunctions.cstringContainerFinish)
|
2004-02-19 05:44:03 +03:00
|
|
|
xpcomFunctions.cstringContainerFinish(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM PRUint32
|
|
|
|
NS_CStringGetData(const nsACString &aStr, const char **aBuf, PRBool *aTerm)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.cstringGetData) {
|
|
|
|
*aBuf = nsnull;
|
2004-02-19 05:44:03 +03:00
|
|
|
return 0;
|
2004-04-12 00:52:32 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
return xpcomFunctions.cstringGetData(aStr, aBuf, aTerm);
|
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_CStringSetData(nsACString &aStr, const char *aBuf, PRUint32 aCount)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.cstringSetData)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.cstringSetData(aStr, aBuf, aCount);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_CStringSetDataRange(nsACString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
|
|
|
|
const char *aBuf, PRUint32 aCount)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.cstringSetDataRange)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.cstringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2004-04-12 00:52:32 +04:00
|
|
|
extern "C" NS_COM nsresult
|
2004-02-19 05:44:03 +03:00
|
|
|
NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.cstringCopy)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.cstringCopy(aDest, aSrc);
|
2003-08-05 09:29:10 +04:00
|
|
|
}
|
|
|
|
|
2004-04-02 00:47:48 +04:00
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_CStringToUTF16(const nsACString &aSrc, PRUint32 aSrcEncoding, nsAString &aDest)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.cstringToUTF16)
|
2004-04-02 00:47:48 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.cstringToUTF16(aSrc, aSrcEncoding, aDest);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_COM nsresult
|
|
|
|
NS_UTF16ToCString(const nsAString &aSrc, PRUint32 aDestEncoding, nsACString &aDest)
|
|
|
|
{
|
2004-04-12 00:52:32 +04:00
|
|
|
if (!xpcomFunctions.utf16ToCString)
|
2004-04-02 00:47:48 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return xpcomFunctions.utf16ToCString(aSrc, aDestEncoding, aDest);
|
|
|
|
}
|
|
|
|
|
2002-07-16 03:32:36 +04:00
|
|
|
#endif // #ifndef XPCOM_GLUE_NO_DYNAMIC_LOADING
|
2003-01-03 02:09:30 +03:00
|
|
|
|
|
|
|
|
2003-11-17 09:13:49 +03:00
|
|
|
static char sEnvString[MAXPATHLEN*10];
|
|
|
|
static char* spEnvString = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
GRE_AddGREToEnvironment()
|
|
|
|
{
|
|
|
|
const char* grePath = GRE_GetGREPath();
|
|
|
|
if (!grePath)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char* path = PR_GetEnv(XPCOM_SEARCH_KEY);
|
|
|
|
if (!path) {
|
|
|
|
path = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spEnvString) PR_smprintf_free(spEnvString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* if the PATH string is longer than our static buffer, allocate a
|
|
|
|
* buffer for the environment string. This buffer will be leaked at shutdown!
|
|
|
|
*/
|
|
|
|
if (strlen(grePath) + strlen(path) +
|
|
|
|
sizeof(XPCOM_SEARCH_KEY) + sizeof(XPCOM_ENV_PATH_SEPARATOR) > MAXPATHLEN*10) {
|
|
|
|
if (PR_smprintf(XPCOM_SEARCH_KEY "=%s" XPCOM_ENV_PATH_SEPARATOR "%s",
|
|
|
|
grePath,
|
|
|
|
path)) {
|
|
|
|
PR_SetEnv(spEnvString);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sprintf(sEnvString,
|
|
|
|
XPCOM_SEARCH_KEY "=%s" XPCOM_ENV_PATH_SEPARATOR "%s",
|
|
|
|
grePath,
|
|
|
|
path) > 0) {
|
|
|
|
PR_SetEnv(sEnvString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if XP_WIN32
|
|
|
|
// On windows, the current directory is searched before the
|
|
|
|
// PATH environment variable. This is a very bad thing
|
|
|
|
// since libraries in the cwd will be picked up before
|
|
|
|
// any that are in either the application or GRE directory.
|
|
|
|
|
|
|
|
if (grePath) {
|
|
|
|
SetCurrentDirectory(grePath);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-03 02:09:30 +03:00
|
|
|
// Default GRE startup/shutdown code
|
|
|
|
|
|
|
|
extern "C"
|
2003-11-17 09:13:49 +03:00
|
|
|
nsresult GRE_Startup()
|
2003-01-03 02:09:30 +03:00
|
|
|
{
|
2003-11-17 09:13:49 +03:00
|
|
|
const char* xpcomLocation = GRE_GetXPCOMPath();
|
|
|
|
|
2003-01-03 02:09:30 +03:00
|
|
|
// Startup the XPCOM Glue that links us up with XPCOM.
|
|
|
|
nsresult rv = XPCOMGlueStartup(xpcomLocation);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("gre: XPCOMGlueStartup failed");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGREDirServiceProvider *provider = new nsGREDirServiceProvider();
|
|
|
|
if ( !provider ) {
|
|
|
|
NS_WARNING("GRE_Startup failed");
|
|
|
|
XPCOMGlueShutdown();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
|
|
|
NS_ADDREF( provider );
|
|
|
|
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, provider);
|
|
|
|
NS_RELEASE(provider);
|
|
|
|
|
|
|
|
if ( NS_FAILED(rv) || !servMan) {
|
|
|
|
NS_WARNING("gre: NS_InitXPCOM failed");
|
|
|
|
XPCOMGlueShutdown();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
2003-11-17 09:13:49 +03:00
|
|
|
nsresult GRE_Shutdown()
|
2003-01-03 02:09:30 +03:00
|
|
|
{
|
|
|
|
NS_ShutdownXPCOM(nsnull);
|
|
|
|
XPCOMGlueShutdown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|