Bug 470971 - Add ability to pass the GRE dir to xpcshell, r=ted - fixed patch: XRE_GetBinaryPath gets the file of the executable: we want to pass the parent directory to XPCOM.
This commit is contained in:
Родитель
88555bd99d
Коммит
834ec83fc3
|
@ -186,6 +186,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@
|
||||
|
|
|
@ -7254,6 +7254,8 @@ if test -n "$MOZ_ENABLE_LIBXUL" -a -n "$BUILD_STATIC_LIBS"; then
|
|||
AC_MSG_ERROR([--enable-libxul is not compatible with --enable-static])
|
||||
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
|
||||
|
@ -919,7 +941,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;
|
||||
}
|
||||
|
||||
|
@ -1548,9 +1570,39 @@ main(int argc, char **argv, char **envp)
|
|||
gErrFile = stderr;
|
||||
gOutFile = stdout;
|
||||
gInFile = stdin;
|
||||
|
||||
NS_LogInit();
|
||||
|
||||
nsCOMPtr<nsILocalFile> appFile;
|
||||
rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("Couldn't figure application file.\n");
|
||||
return 1;
|
||||
}
|
||||
nsCOMPtr<nsIFile> appDir;
|
||||
rv = appFile->GetParent(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;
|
||||
|
@ -1716,9 +1768,49 @@ main(int argc, char **argv, char **envp)
|
|||
bogus = nsnull;
|
||||
#endif
|
||||
|
||||
appDir = nsnull;
|
||||
appFile = 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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче