Bug 388833 - Give the Firefox binary the ability to kinda-sorta launch XR apps (mainly meant for webrunner experimentation right now), r=luser
This commit is contained in:
Родитель
e36bbdb9d9
Коммит
bba2a807ee
|
@ -45,6 +45,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
#include "prenv.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsStringGlue.h"
|
||||
|
@ -67,8 +71,40 @@ static void Output(const char *fmt, ... )
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if |arg| matches the given argument name.
|
||||
*/
|
||||
static PRBool IsArg(const char* arg, const char* s)
|
||||
{
|
||||
if (*arg == '-')
|
||||
{
|
||||
if (*++arg == '-')
|
||||
++arg;
|
||||
return !PL_strcasecmp(arg, s);
|
||||
}
|
||||
|
||||
#if defined(XP_WIN) || defined(XP_OS2)
|
||||
if (*arg == '/')
|
||||
return !PL_strcasecmp(++arg, s);
|
||||
#endif
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper class which calls NS_LogTerm/NS_LogTerm in its scope.
|
||||
*/
|
||||
class ScopedLogging
|
||||
{
|
||||
public:
|
||||
ScopedLogging() { NS_LogInit(); }
|
||||
~ScopedLogging() { NS_LogTerm(); }
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
ScopedLogging log;
|
||||
|
||||
nsCOMPtr<nsILocalFile> appini;
|
||||
nsresult rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appini));
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -77,6 +113,36 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));
|
||||
|
||||
// Allow firefox.exe to launch XULRunner apps via -app <application.ini>
|
||||
// Note that -app must be the *first* argument.
|
||||
char *appEnv = nsnull;
|
||||
const char *appDataFile = PR_GetEnv("XUL_APP_FILE");
|
||||
if (appDataFile && *appDataFile) {
|
||||
rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
|
||||
if (NS_FAILED(rv)) {
|
||||
Output("Invalid path found: '%s'", appDataFile);
|
||||
return 255;
|
||||
}
|
||||
}
|
||||
else if (argc > 1 && IsArg(argv[1], "app")) {
|
||||
if (argc == 2) {
|
||||
Output("Incorrect number of arguments passed to -app");
|
||||
return 255;
|
||||
}
|
||||
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
|
||||
if (NS_FAILED(rv)) {
|
||||
Output("application.ini path not recognized: '%s'", argv[2]);
|
||||
return 255;
|
||||
}
|
||||
|
||||
appEnv = PR_smprintf("XUL_APP_FILE=%s", argv[2]);
|
||||
PR_SetEnv(appEnv);
|
||||
argv[2] = argv[0];
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
}
|
||||
|
||||
nsXREAppData *appData;
|
||||
rv = XRE_CreateAppData(appini, &appData);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -86,6 +152,8 @@ int main(int argc, char* argv[])
|
|||
|
||||
int result = XRE_main(argc, argv, appData);
|
||||
XRE_FreeAppData(appData);
|
||||
if (appEnv)
|
||||
PR_smprintf_free(appEnv);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "nsILocalFile.h"
|
||||
#include "nsAppRunner.h"
|
||||
#include "nsCRTGlue.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
void
|
||||
SetAllocatedString(const char *&str, const char *newvalue)
|
||||
|
@ -114,19 +115,27 @@ XRE_CreateAppData(nsILocalFile* aINIFile, nsXREAppData **aAppData)
|
|||
{
|
||||
NS_ENSURE_ARG(aINIFile && aAppData);
|
||||
|
||||
nsXREAppData *data = new ScopedAppData();
|
||||
nsAutoPtr<nsXREAppData> data = new ScopedAppData();
|
||||
if (!data)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = XRE_ParseAppData(aINIFile, data);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete data;
|
||||
}
|
||||
else {
|
||||
*aAppData = data;
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!data->directory) {
|
||||
nsCOMPtr<nsIFile> appDir;
|
||||
rv = aINIFile->GetParent(getter_AddRefs(appDir));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = CallQueryInterface(appDir, &data->directory);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
*aAppData = data.forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
struct ReadString {
|
||||
|
|
|
@ -443,17 +443,6 @@ int main(int argc, char* argv[])
|
|||
return 2;
|
||||
}
|
||||
|
||||
if (!appData->directory) {
|
||||
nsCOMPtr<nsIFile> appDir;
|
||||
rv = appDataLF->GetParent(getter_AddRefs(appDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
Output(PR_TRUE, "Error: could not get application directory.\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
CallQueryInterface(appDir, &appData->directory);
|
||||
}
|
||||
|
||||
return XRE_main(argc, argv, appData);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче