2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-21 23:12:15 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2013-01-03 07:04:42 -08:00
|
|
|
#include "mozilla/AppData.h"
|
2011-11-21 23:05:59 -08:00
|
|
|
#include "application.ini.h"
|
2011-05-21 23:23:20 -07:00
|
|
|
#include "nsXPCOMGlue.h"
|
2011-05-21 23:24:32 -07:00
|
|
|
#if defined(XP_WIN)
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdlib.h>
|
2011-05-21 23:24:32 -07:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
2013-01-03 07:04:42 -08:00
|
|
|
#include <unistd.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2011-12-19 09:47:09 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "MacQuirks.h"
|
|
|
|
#endif
|
|
|
|
|
2007-07-02 11:20:24 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2012-06-16 10:44:07 -07:00
|
|
|
#include <time.h>
|
2007-07-25 13:24:37 -07:00
|
|
|
|
2007-07-02 11:20:24 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-07-02 11:20:24 -07:00
|
|
|
#include "nsStringGlue.h"
|
|
|
|
|
2013-03-04 10:32:20 -08:00
|
|
|
// Easy access to a five second startup delay used to get
|
|
|
|
// a debugger attached in the metro environment.
|
|
|
|
// #define DEBUG_delay_start_metro
|
|
|
|
|
2007-12-31 07:15:43 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// we want a wmain entry point
|
|
|
|
#include "nsWindowsWMain.cpp"
|
2011-05-21 23:23:20 -07:00
|
|
|
#define snprintf _snprintf
|
|
|
|
#define strcasecmp _stricmp
|
2007-12-31 07:15:43 -08:00
|
|
|
#endif
|
2011-05-21 23:23:20 -07:00
|
|
|
#include "BinaryPath.h"
|
|
|
|
|
|
|
|
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
|
2007-12-31 07:15:43 -08:00
|
|
|
|
2011-05-21 23:24:32 -07:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
2013-01-03 07:04:42 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-02-12 12:51:24 -08:00
|
|
|
#define kDesktopFolder "browser"
|
|
|
|
#define kMetroFolder "metro"
|
|
|
|
#define kMetroAppIniFilename "metroapp.ini"
|
|
|
|
#define kMetroTestFile "tests.ini"
|
|
|
|
|
2007-07-02 11:20:24 -07:00
|
|
|
static void Output(const char *fmt, ... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
2012-07-24 10:04:03 -07:00
|
|
|
#ifndef XP_WIN
|
2007-07-02 11:20:24 -07:00
|
|
|
vfprintf(stderr, fmt, ap);
|
2012-07-24 10:04:03 -07:00
|
|
|
#else
|
|
|
|
char msg[2048];
|
|
|
|
vsnprintf_s(msg, _countof(msg), _TRUNCATE, fmt, ap);
|
|
|
|
|
|
|
|
wchar_t wide_msg[2048];
|
|
|
|
MultiByteToWideChar(CP_UTF8,
|
|
|
|
0,
|
|
|
|
msg,
|
|
|
|
-1,
|
|
|
|
wide_msg,
|
|
|
|
_countof(wide_msg));
|
|
|
|
#if MOZ_WINCONSOLE
|
|
|
|
fwprintf_s(stderr, wide_msg);
|
|
|
|
#else
|
|
|
|
MessageBoxW(NULL, wide_msg, L"Firefox", MB_OK
|
|
|
|
| MB_ICONERROR
|
|
|
|
| MB_SETFOREGROUND);
|
|
|
|
#endif
|
2007-05-25 15:09:29 -07:00
|
|
|
#endif
|
2007-07-02 11:20:24 -07:00
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 13:24:37 -07:00
|
|
|
/**
|
|
|
|
* Return true if |arg| matches the given argument name.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsArg(const char* arg, const char* s)
|
2007-07-25 13:24:37 -07:00
|
|
|
{
|
|
|
|
if (*arg == '-')
|
|
|
|
{
|
|
|
|
if (*++arg == '-')
|
|
|
|
++arg;
|
2011-05-21 23:23:20 -07:00
|
|
|
return !strcasecmp(arg, s);
|
2007-07-25 13:24:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
if (*arg == '/')
|
2011-05-21 23:23:20 -07:00
|
|
|
return !strcasecmp(++arg, s);
|
2007-07-25 13:24:37 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-07-25 13:24:37 -07:00
|
|
|
}
|
|
|
|
|
2011-05-21 23:23:20 -07:00
|
|
|
XRE_GetFileFromPathType XRE_GetFileFromPath;
|
|
|
|
XRE_CreateAppDataType XRE_CreateAppData;
|
|
|
|
XRE_FreeAppDataType XRE_FreeAppData;
|
|
|
|
#ifdef XRE_HAS_DLL_BLOCKLIST
|
|
|
|
XRE_SetupDllBlocklistType XRE_SetupDllBlocklist;
|
|
|
|
#endif
|
2011-05-21 23:24:32 -07:00
|
|
|
XRE_TelemetryAccumulateType XRE_TelemetryAccumulate;
|
2012-06-14 23:23:08 -07:00
|
|
|
XRE_StartupTimelineRecordType XRE_StartupTimelineRecord;
|
2011-05-21 23:23:20 -07:00
|
|
|
XRE_mainType XRE_main;
|
2013-01-04 07:27:41 -08:00
|
|
|
XRE_DisableWritePoisoningType XRE_DisableWritePoisoning;
|
2011-06-15 09:00:28 -07:00
|
|
|
|
2011-05-21 23:23:20 -07:00
|
|
|
static const nsDynamicFunctionLoad kXULFuncs[] = {
|
|
|
|
{ "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
|
|
|
|
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
|
|
|
|
{ "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
|
2011-05-21 23:22:27 -07:00
|
|
|
#ifdef XRE_HAS_DLL_BLOCKLIST
|
2011-05-21 23:23:20 -07:00
|
|
|
{ "XRE_SetupDllBlocklist", (NSFuncPtr*) &XRE_SetupDllBlocklist },
|
2011-05-21 23:22:27 -07:00
|
|
|
#endif
|
2011-05-21 23:24:32 -07:00
|
|
|
{ "XRE_TelemetryAccumulate", (NSFuncPtr*) &XRE_TelemetryAccumulate },
|
2012-06-14 23:23:08 -07:00
|
|
|
{ "XRE_StartupTimelineRecord", (NSFuncPtr*) &XRE_StartupTimelineRecord },
|
2011-05-21 23:23:20 -07:00
|
|
|
{ "XRE_main", (NSFuncPtr*) &XRE_main },
|
2013-01-04 07:27:41 -08:00
|
|
|
{ "XRE_DisableWritePoisoning", (NSFuncPtr*) &XRE_DisableWritePoisoning },
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nullptr, nullptr }
|
2011-05-21 23:23:20 -07:00
|
|
|
};
|
2011-05-21 23:22:27 -07:00
|
|
|
|
2013-01-03 07:04:42 -08:00
|
|
|
static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
2011-05-21 23:23:20 -07:00
|
|
|
{
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> appini;
|
2011-11-21 23:05:59 -08:00
|
|
|
nsresult rv;
|
2013-02-12 12:51:24 -08:00
|
|
|
uint32_t mainFlags = 0;
|
2007-07-02 11:20:24 -07:00
|
|
|
|
2007-07-25 13:24:37 -07:00
|
|
|
// Allow firefox.exe to launch XULRunner apps via -app <application.ini>
|
|
|
|
// Note that -app must be the *first* argument.
|
2011-05-21 23:23:20 -07:00
|
|
|
const char *appDataFile = getenv("XUL_APP_FILE");
|
2007-10-12 22:47:04 -07:00
|
|
|
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")) {
|
2007-07-25 13:24:37 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-21 23:23:20 -07:00
|
|
|
char appEnv[MAXPATHLEN];
|
|
|
|
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
|
|
|
|
if (putenv(appEnv)) {
|
|
|
|
Output("Couldn't set %s.\n", appEnv);
|
|
|
|
return 255;
|
|
|
|
}
|
2007-07-25 13:24:37 -07:00
|
|
|
argv[2] = argv[0];
|
|
|
|
argv += 2;
|
|
|
|
argc -= 2;
|
|
|
|
}
|
|
|
|
|
2011-11-21 23:05:59 -08:00
|
|
|
if (appini) {
|
|
|
|
nsXREAppData *appData;
|
|
|
|
rv = XRE_CreateAppData(appini, &appData);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output("Couldn't read application.ini");
|
|
|
|
return 255;
|
|
|
|
}
|
2013-01-03 07:04:42 -08:00
|
|
|
// xreDirectory already has a refcount from NS_NewLocalFile
|
|
|
|
appData->xreDirectory = xreDirectory;
|
2013-02-12 12:51:24 -08:00
|
|
|
int result = XRE_main(argc, argv, appData, mainFlags);
|
2011-11-21 23:05:59 -08:00
|
|
|
XRE_FreeAppData(appData);
|
2012-02-14 10:03:31 -08:00
|
|
|
return result;
|
2007-07-02 11:20:24 -07:00
|
|
|
}
|
|
|
|
|
2013-02-12 12:51:24 -08:00
|
|
|
bool metroOnDesktop = false;
|
|
|
|
|
|
|
|
#ifdef MOZ_METRO
|
|
|
|
if (argc > 1) {
|
|
|
|
// This command-line flag is passed to our executable when it is to be
|
|
|
|
// launched in metro mode (i.e. our EXE is registered as the default
|
|
|
|
// browser and the user has tapped our EXE's tile)
|
|
|
|
if (IsArg(argv[1], "ServerName:DefaultBrowserServer")) {
|
|
|
|
mainFlags = XRE_MAIN_FLAG_USE_METRO;
|
|
|
|
argv[1] = argv[0];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
} else {
|
|
|
|
// This command-line flag is used to test the metro browser in a desktop
|
|
|
|
// environment.
|
|
|
|
for (int idx = 1; idx < argc; idx++) {
|
|
|
|
if (IsArg(argv[idx], "metrodesktop")) {
|
|
|
|
metroOnDesktop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Desktop browser launch
|
|
|
|
if (mainFlags != XRE_MAIN_FLAG_USE_METRO && !metroOnDesktop) {
|
|
|
|
ScopedAppData appData(&sAppData);
|
|
|
|
nsCOMPtr<nsIFile> exeFile;
|
|
|
|
rv = mozilla::BinaryPath::GetFile(argv[0], getter_AddRefs(exeFile));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output("Couldn't find the application directory.\n");
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> greDir;
|
|
|
|
exeFile->GetParent(getter_AddRefs(greDir));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> appSubdir;
|
|
|
|
greDir->Clone(getter_AddRefs(appSubdir));
|
|
|
|
appSubdir->Append(NS_LITERAL_STRING(kDesktopFolder));
|
|
|
|
|
|
|
|
SetStrongPtr(appData.directory, static_cast<nsIFile*>(appSubdir.get()));
|
|
|
|
// xreDirectory already has a refcount from NS_NewLocalFile
|
|
|
|
appData.xreDirectory = xreDirectory;
|
|
|
|
|
|
|
|
return XRE_main(argc, argv, &appData, mainFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metro browser launch
|
|
|
|
#ifdef MOZ_METRO
|
|
|
|
nsCOMPtr<nsIFile> iniFile, appSubdir;
|
|
|
|
|
|
|
|
xreDirectory->Clone(getter_AddRefs(iniFile));
|
|
|
|
xreDirectory->Clone(getter_AddRefs(appSubdir));
|
|
|
|
|
|
|
|
iniFile->Append(NS_LITERAL_STRING(kMetroFolder));
|
|
|
|
iniFile->Append(NS_LITERAL_STRING(kMetroAppIniFilename));
|
|
|
|
|
|
|
|
appSubdir->Append(NS_LITERAL_STRING(kMetroFolder));
|
|
|
|
|
|
|
|
nsAutoCString path;
|
|
|
|
if (NS_FAILED(iniFile->GetNativePath(path))) {
|
|
|
|
Output("Couldn't get ini file path.\n");
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
char appEnv[MAXPATHLEN];
|
|
|
|
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", path.get());
|
|
|
|
if (putenv(appEnv)) {
|
|
|
|
Output("Couldn't set %s.\n", appEnv);
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXREAppData *appData;
|
|
|
|
rv = XRE_CreateAppData(iniFile, &appData);
|
|
|
|
if (NS_FAILED(rv) || !appData) {
|
|
|
|
Output("Couldn't read application.ini");
|
2013-01-03 07:04:42 -08:00
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2013-02-12 12:51:24 -08:00
|
|
|
SetStrongPtr(appData->directory, static_cast<nsIFile*>(appSubdir.get()));
|
2013-01-03 07:04:42 -08:00
|
|
|
// xreDirectory already has a refcount from NS_NewLocalFile
|
2013-02-12 12:51:24 -08:00
|
|
|
appData->xreDirectory = xreDirectory;
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (!metroOnDesktop) {
|
|
|
|
nsCOMPtr<nsIFile> testFile;
|
|
|
|
|
|
|
|
xreDirectory->Clone(getter_AddRefs(testFile));
|
|
|
|
testFile->Append(NS_LITERAL_STRING(kMetroTestFile));
|
|
|
|
|
|
|
|
nsAutoCString path;
|
|
|
|
if (NS_FAILED(testFile->GetNativePath(path))) {
|
|
|
|
Output("Couldn't get test file path.\n");
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a metro test harness command line args file
|
|
|
|
HANDLE hTestFile = CreateFileA(path.get(),
|
|
|
|
GENERIC_READ,
|
|
|
|
0, NULL, OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if (hTestFile != INVALID_HANDLE_VALUE) {
|
|
|
|
// Typical test harness command line args string is around 100 bytes.
|
|
|
|
char buffer[1024];
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
DWORD bytesRead = 0;
|
|
|
|
if (!ReadFile(hTestFile, (VOID*)buffer, sizeof(buffer)-1,
|
|
|
|
&bytesRead, NULL) || !bytesRead) {
|
|
|
|
CloseHandle(hTestFile);
|
|
|
|
printf("failed to read test file '%s'", testFile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
CloseHandle(hTestFile);
|
|
|
|
|
|
|
|
// Build new args array
|
|
|
|
char* newArgv[20];
|
|
|
|
int newArgc = 1;
|
|
|
|
|
|
|
|
memset(newArgv, 0, sizeof(newArgv));
|
|
|
|
|
|
|
|
char* ptr = buffer;
|
|
|
|
newArgv[0] = ptr;
|
|
|
|
while (*ptr != NULL &&
|
|
|
|
(ptr - buffer) < sizeof(buffer) &&
|
|
|
|
newArgc < ARRAYSIZE(newArgv)) {
|
|
|
|
if (isspace(*ptr)) {
|
|
|
|
*ptr = '\0';
|
|
|
|
ptr++;
|
|
|
|
newArgv[newArgc] = ptr;
|
|
|
|
newArgc++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
}
|
2013-02-20 17:20:04 -08:00
|
|
|
if (ptr == newArgv[newArgc-1])
|
|
|
|
newArgc--;
|
2013-02-12 12:51:24 -08:00
|
|
|
int result = XRE_main(newArgc, newArgv, appData, mainFlags);
|
|
|
|
XRE_FreeAppData(appData);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int result = XRE_main(argc, argv, appData, mainFlags);
|
|
|
|
XRE_FreeAppData(appData);
|
|
|
|
return result;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_NOTREACHED("browser do_main failed to pickup proper initialization");
|
|
|
|
return 255;
|
2011-05-21 23:23:20 -07:00
|
|
|
}
|
|
|
|
|
2012-06-14 23:23:08 -07:00
|
|
|
/* Local implementation of PR_Now, since the executable can't depend on NSPR */
|
|
|
|
static PRTime _PR_Now()
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
MOZ_STATIC_ASSERT(sizeof(PRTime) == sizeof(FILETIME), "PRTime must have the same size as FILETIME");
|
|
|
|
FILETIME ft;
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
PRTime now;
|
|
|
|
CopyMemory(&now, &ft, sizeof(PRTime));
|
|
|
|
#ifdef __GNUC__
|
|
|
|
return (now - 116444736000000000LL) / 10LL;
|
|
|
|
#else
|
|
|
|
return (now - 116444736000000000i64) / 10i64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
struct timeval tm;
|
|
|
|
gettimeofday(&tm, 0);
|
|
|
|
return (((PRTime)tm.tv_sec * 1000000LL) + (PRTime)tm.tv_usec);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-03 07:04:42 -08:00
|
|
|
static bool
|
|
|
|
FileExists(const char *path)
|
2011-05-21 23:23:20 -07:00
|
|
|
{
|
2013-01-03 07:04:42 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
wchar_t wideDir[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, wideDir, MAX_PATH);
|
|
|
|
DWORD fileAttrs = GetFileAttributesW(wideDir);
|
|
|
|
return fileAttrs != INVALID_FILE_ATTRIBUTES;
|
|
|
|
#else
|
|
|
|
return access(path, R_OK) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
2011-05-21 23:23:20 -07:00
|
|
|
|
2013-01-03 07:04:42 -08:00
|
|
|
#ifdef LIBXUL_SDK
|
|
|
|
# define XPCOM_PATH "xulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL
|
|
|
|
#else
|
|
|
|
# define XPCOM_PATH XPCOM_DLL
|
2011-12-19 09:47:09 -08:00
|
|
|
#endif
|
2013-01-03 07:04:42 -08:00
|
|
|
static nsresult
|
|
|
|
InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory)
|
|
|
|
{
|
|
|
|
char exePath[MAXPATHLEN];
|
2011-12-19 09:47:09 -08:00
|
|
|
|
2013-01-03 07:04:42 -08:00
|
|
|
nsresult rv = mozilla::BinaryPath::Get(argv0, exePath);
|
2011-05-21 23:23:20 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-01-03 07:04:42 -08:00
|
|
|
Output("Couldn't find the application directory.\n");
|
|
|
|
return rv;
|
2011-05-21 23:23:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
|
2013-01-03 07:04:42 -08:00
|
|
|
if (!lastSlash || (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_PATH) - 1))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
strcpy(lastSlash + 1, XPCOM_PATH);
|
|
|
|
lastSlash += sizeof(XPCOM_PATH) - sizeof(XPCOM_DLL);
|
|
|
|
|
|
|
|
if (!FileExists(exePath)) {
|
|
|
|
#if defined(LIBXUL_SDK) && defined(XP_MACOSX)
|
|
|
|
// Check for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib
|
|
|
|
bool greFound = false;
|
|
|
|
CFBundleRef appBundle = CFBundleGetMainBundle();
|
|
|
|
if (!appBundle)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle);
|
|
|
|
CFURLRef absfwurl = nullptr;
|
|
|
|
if (fwurl) {
|
|
|
|
absfwurl = CFURLCopyAbsoluteURL(fwurl);
|
|
|
|
CFRelease(fwurl);
|
|
|
|
}
|
|
|
|
if (absfwurl) {
|
|
|
|
CFURLRef xulurl =
|
|
|
|
CFURLCreateCopyAppendingPathComponent(NULL, absfwurl,
|
|
|
|
CFSTR("XUL.framework"),
|
|
|
|
true);
|
|
|
|
|
|
|
|
if (xulurl) {
|
|
|
|
CFURLRef xpcomurl =
|
|
|
|
CFURLCreateCopyAppendingPathComponent(NULL, xulurl,
|
|
|
|
CFSTR("libxpcom.dylib"),
|
|
|
|
false);
|
|
|
|
|
|
|
|
if (xpcomurl) {
|
|
|
|
if (CFURLGetFileSystemRepresentation(xpcomurl, true,
|
|
|
|
(UInt8*) exePath,
|
|
|
|
sizeof(exePath)) &&
|
|
|
|
access(tbuffer, R_OK | X_OK) == 0) {
|
|
|
|
if (realpath(tbuffer, exePath)) {
|
|
|
|
greFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CFRelease(xpcomurl);
|
|
|
|
}
|
|
|
|
CFRelease(xulurl);
|
|
|
|
}
|
|
|
|
CFRelease(absfwurl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!greFound) {
|
2012-07-08 18:54:10 -07:00
|
|
|
#endif
|
2013-01-03 07:04:42 -08:00
|
|
|
Output("Could not find the Mozilla runtime.\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-05-27 19:40:49 -07:00
|
|
|
|
2012-08-02 07:50:29 -07:00
|
|
|
// We do this because of data in bug 771745
|
2012-07-08 18:54:10 -07:00
|
|
|
XPCOMGlueEnablePreload();
|
2011-05-16 01:25:05 -07:00
|
|
|
|
2011-05-21 23:23:20 -07:00
|
|
|
rv = XPCOMGlueStartup(exePath);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output("Couldn't load XPCOM.\n");
|
2013-01-03 07:04:42 -08:00
|
|
|
return rv;
|
2011-05-21 23:23:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output("Couldn't load XRE functions.\n");
|
2013-01-03 07:04:42 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-01-19 00:40:02 -08:00
|
|
|
NS_LogInit();
|
|
|
|
|
2013-01-03 07:04:42 -08:00
|
|
|
// chop XPCOM_DLL off exePath
|
|
|
|
*lastSlash = '\0';
|
|
|
|
#ifdef XP_WIN
|
2013-01-19 00:40:02 -08:00
|
|
|
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), false,
|
|
|
|
xreDirectory);
|
2013-01-03 07:04:42 -08:00
|
|
|
#else
|
2013-01-19 00:40:02 -08:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false,
|
|
|
|
xreDirectory);
|
2013-01-03 07:04:42 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2013-03-04 10:32:20 -08:00
|
|
|
#ifdef DEBUG_delay_start_metro
|
|
|
|
Sleep(5000);
|
|
|
|
#endif
|
2013-01-03 07:04:42 -08:00
|
|
|
PRTime start = _PR_Now();
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
TriggerQuirks();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int gotCounters;
|
|
|
|
#if defined(XP_UNIX)
|
|
|
|
struct rusage initialRUsage;
|
|
|
|
gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage);
|
|
|
|
#elif defined(XP_WIN)
|
|
|
|
IO_COUNTERS ioCounters;
|
|
|
|
gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFile *xreDirectory;
|
|
|
|
|
|
|
|
nsresult rv = InitXPCOMGlue(argv[0], &xreDirectory);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-05-21 23:23:20 -07:00
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2012-06-14 23:23:08 -07:00
|
|
|
XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start);
|
|
|
|
|
2011-05-21 23:23:20 -07:00
|
|
|
#ifdef XRE_HAS_DLL_BLOCKLIST
|
|
|
|
XRE_SetupDllBlocklist();
|
|
|
|
#endif
|
|
|
|
|
2011-05-21 23:24:32 -07:00
|
|
|
if (gotCounters) {
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS,
|
|
|
|
int(ioCounters.ReadOperationCount));
|
|
|
|
XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER,
|
|
|
|
int(ioCounters.ReadTransferCount / 1024));
|
|
|
|
IO_COUNTERS newIoCounters;
|
|
|
|
if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) {
|
|
|
|
XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS,
|
|
|
|
int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount));
|
|
|
|
XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER,
|
|
|
|
int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024));
|
|
|
|
}
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS,
|
|
|
|
int(initialRUsage.ru_majflt));
|
|
|
|
struct rusage newRUsage;
|
|
|
|
if (!getrusage(RUSAGE_SELF, &newRUsage)) {
|
|
|
|
XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS,
|
|
|
|
int(newRUsage.ru_majflt - initialRUsage.ru_majflt));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-19 00:40:02 -08:00
|
|
|
int result = do_main(argc, argv, xreDirectory);
|
|
|
|
|
|
|
|
NS_LogTerm();
|
2011-05-21 23:23:20 -07:00
|
|
|
|
2013-01-04 07:27:41 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Allow writes again. While we would like to catch writes from static
|
|
|
|
// destructors to allow early exits to use _exit, we know that there is
|
|
|
|
// at least one such write that we don't control (see bug 826029). For
|
|
|
|
// now we enable writes again and early exits will have to use exit instead
|
|
|
|
// of _exit.
|
|
|
|
XRE_DisableWritePoisoning();
|
|
|
|
#endif
|
|
|
|
|
2007-07-02 11:20:24 -07:00
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|