Bug 470971 - Add ability to pass the GRE dir to xpcshell, r=ted

This commit is contained in:
Benjamin Smedberg 2009-01-20 14:56:44 -05:00
Родитель 5a3308e838
Коммит 4d262c4424
4 изменённых файлов: 91 добавлений и 3 удалений

Просмотреть файл

@ -184,6 +184,7 @@ MOZ_FIX_LINK_PATHS=@MOZ_FIX_LINK_PATHS@
XPCOM_FROZEN_LDOPTS=@XPCOM_FROZEN_LDOPTS@
XPCOM_LIBS=@XPCOM_LIBS@
LIBXUL_LIBS=@LIBXUL_LIBS@
MOZ_TIMELINE=@MOZ_TIMELINE@
ENABLE_STRIP = @ENABLE_STRIP@

Просмотреть файл

@ -7229,6 +7229,8 @@ if test -n "$MOZ_ENABLE_LIBXUL" -a -z "$MOZ_XUL_APP"; then
AC_MSG_ERROR([--enable-libxul is only compatible with toolkit XUL applications.])
fi
AC_SUBST(LIBXUL_LIBS)
if test -n "$MOZ_ENABLE_LIBXUL"; then
XPCOM_LIBS="$LIBXUL_LIBS"
AC_DEFINE(MOZ_ENABLE_LIBXUL)

Просмотреть файл

@ -50,6 +50,7 @@ REQUIRES = xpconnect \
xpcom \
js \
caps \
xulapp \
$(NULL)
CPPSRCS = xpcshell.cpp
@ -60,8 +61,8 @@ endif
LIBS = \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
$(LIBXUL_LIBS) \
$(MOZ_JS_LIBS) \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \
$(NULL)

Просмотреть файл

@ -45,8 +45,10 @@
/* XPConnect JavaScript interactive shell. */
#include <stdio.h>
#include "nsXULAppAPI.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsStringAPI.h"
#include "nsIXPConnect.h"
#include "nsIXPCScriptable.h"
#include "nsIInterfaceInfo.h"
@ -57,12 +59,16 @@
#include "nsIComponentRegistrar.h"
#include "nsILocalFile.h"
#include "nsStringAPI.h"
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "jsapi.h"
#include "jsdbgapi.h"
#include "jsprf.h"
#include "nscore.h"
#include "nsMemory.h"
#include "nsIGenericFactory.h"
#include "nsISupportsImpl.h"
#include "nsIJSRuntimeService.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
@ -91,6 +97,22 @@
#include "nsIJSContextStack.h"
class XPCShellDirProvider : public nsIDirectoryServiceProvider
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
XPCShellDirProvider() { }
~XPCShellDirProvider() { }
PRBool SetGREDir(const char *dir);
void ClearGREDir() { mGREDir = nsnull; }
private:
nsCOMPtr<nsILocalFile> mGREDir;
};
/***************************************************************************/
#ifdef JS_THREADSAFE
@ -914,7 +936,7 @@ static int
usage(void)
{
fprintf(gErrFile, "%s\n", JS_GetImplementationVersion());
fprintf(gErrFile, "usage: xpcshell [-PswWxCij] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n");
fprintf(gErrFile, "usage: xpcshell [-g gredir] [-PswWxCij] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n");
return 2;
}
@ -1544,9 +1566,32 @@ main(int argc, char **argv, char **envp)
gErrFile = stderr;
gOutFile = stdout;
gInFile = stdin;
NS_LogInit();
nsCOMPtr<nsILocalFile> appDir;
rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appDir));
if (NS_FAILED(rv)) {
printf("Couldn't get application directory.\n");
return 1;
}
XPCShellDirProvider dirprovider;
if (argc > 1 && !strcmp(argv[1], "-g")) {
if (argc < 3)
return usage();
if (!dirprovider.SetGREDir(argv[2])) {
printf("SetGREDir failed.\n");
return 1;
}
argc -= 2;
argv += 2;
}
{
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
rv = NS_InitXPCOM2(getter_AddRefs(servMan), appDir, &dirprovider);
if (NS_FAILED(rv)) {
printf("NS_InitXPCOM failed!\n");
return 1;
@ -1712,9 +1757,48 @@ main(int argc, char **argv, char **envp)
bogus = nsnull;
#endif
appDir = nsnull;
dirprovider.ClearGREDir();
NS_LogTerm();
#ifdef XP_MACOSX
FinishAutoreleasePool();
#endif
return result;
}
PRBool
XPCShellDirProvider::SetGREDir(const char *dir)
{
nsresult rv = XRE_GetFileFromPath(dir, getter_AddRefs(mGREDir));
return NS_SUCCEEDED(rv);
}
NS_IMETHODIMP_(nsrefcnt)
XPCShellDirProvider::AddRef()
{
return 2;
}
NS_IMETHODIMP_(nsrefcnt)
XPCShellDirProvider::Release()
{
return 1;
}
NS_IMPL_QUERY_INTERFACE1(XPCShellDirProvider, nsIDirectoryServiceProvider)
NS_IMETHODIMP
XPCShellDirProvider::GetFile(const char *prop, PRBool *persistent,
nsIFile* *result)
{
if (mGREDir && !strcmp(prop, NS_GRE_DIR)) {
*persistent = PR_TRUE;
NS_ADDREF(*result = mGREDir);
return NS_OK;
}
return NS_ERROR_FAILURE;
}