Files
roytam1 41532ef15e import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1230413 (part 1) - Pass a DrawTarget to several PaintFocus functions(). r=mattwoodrow. (5df91490ae)
- Bug 1230413 (part 2) - Change CallbackData::mContext to a DrawTarget.… r=jfkthame. (07ee11cdd3)
- Bug 1211867 - Use the font's NBSP glyph (if present) rather than rendering NBSP using the standard <space> glyph. r=jdaggett (481384c1a3)
- Bug 1230413 (part 3) - Remove unused gfxContext argument from SetSpaceGlyphIfSimple(). r=jfkthame. (6f9194709d)
- Bug 1230413 (part 4) - Remove unused nsRenderingContext argument from ForceBreak() and OptionallyBreak(). r=mattwoodrow. (8d517a64c3)
- Bug 1230413 (part 5) - Pass a DrawTarget to Draw{Dashed,SolidBorder}Segment(). r=mattwoodrow. (0ec1212b6e)
- Bug 1122788 - patch 1 - nsMultiplexInputStream should not use Tell() in debug builds, r=bz (f92a138bc7)
- iBug 1122788 - patch 2 - nsMultiplexInputStream should not use Tell() in debug builds, r=bz (afadbc68ee)
- Bug 1105044: update XULRunner stub path finding to match the updated Mac app package signing requirements. r=bsmedberg (241e69e234)
- Bug 1151506 - move nsIInterfaceInfo::isMainProcessScriptable to the end of the interface's vtable; r=dbaron (a763bdbeb5)
- Bug 1123323 - Ensure that xptiTypelibGuts cannot have a vtable; r=froydnj (c68a87f37d)
- Bug 1223142 - make XPIDL set default nullptrs for optional out parameters, r=bz (a67cafedba)
- Bug 1219246 - use UniquePtr instead of nsAuto*Ptr in xpcom/; r=erahm (c0a9c817ca)
- Bug 1217047 - try harder in IsContractIDRegistered to return a reasonable answer; r=bsmedberg,f=yury (25f42064c0)
- more of Bug 1101651 - Part 2 (bb82515cb6)
- Bug 1159302 - handle ftell errors in nsINIParser::InitFromFile; r=erahm (252bf762da)
- Bug 1159304 - silence Coverity warning about implicit conversion issues in ReadAheadLib; r=erahm (f6ae3d7af0)
- Bug 1233176 - Scalar Replacement: Initialize properties with the default value of the template object. r=shu (5ae139b872)
- Bug 1223023 - Ensure that we have enough ballast space for allocating MoveGroups in BacktrackingAllocator::resolveControlFlow. r=bhackett (ad486853ad)
- Bug 1231575 - "JitSpew: RegAlloc: dump buffer is too small for a kraken spew". r=bhackett (5042256569)
- Bug 1231581 - "IonMonkey: MOZ_CRASH() in BacktrackingAllocator.cpp:LiveRange::toString() might be unreachable." r=bhackett1024 (8453cfdb5a)
- Bug 1231581 - fix C4018 warning in WinXP. r=bhackett1024 (03ae92e018)
- Bug 1228404 - Add OOM test for module parsing and fix a couple of bugs r=shu (a71b84e9a9)
- Bug 1228579 - BacktrackingAllocator: Pack the LUse::Policy next to the LUse pointer of UsePosition. r=bhackett (91b12c5da8)
- Bug 1225203 - Make backtracking register allocator spew / dump output threadsafe r=bhackett (c44f0a04f1)
- Bug 1202784 - Part 1: Refactor SuperElemOperations for use with emitElemOperands. (r=jandem) (44adc3abf1)
- Bug 1202784 -Part 2: Seperate RequireCoercible check from JSOP_TOID. (r=jandem) (531f3e7543)
- Bug 1225026 - Remove support for atomics on Uint8ClampedArray. r=nbp (29c1dd5bc3)
- Bug 1232022 - Part 1: Mark self-hosted intrinsics for later checking. (r=till) (f49b4de863)
- Bug 1232022 - Part 2: Implement JSOP_DEBUGCHECKSELFHOSTED, and use it to check self-hosted callFunction()s. (r=till, r=h4writer) (c9cbb13f0c)
- Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=shu (1c6d9d4cb5)
- Bug 1135377 - Part 1: Implement RegExp unicode flag. r=till, f=anba (afbcec4095)
- Bug 1220457 - Show deprecation warning for non-standard RegExp.multiline. r=till (175aaa139c)
- Bug 1135377 - Part 2: Parse RegExp unicode character in non-CharacterClass. r=till, f=anba (492f380bbb)
- Bug 1135377 - Part 3: Parse RegExp unicode character in CharacterClass. r=till, f=anba (71bba378d2)
- Bug 1135377 - Part 4: Support everything Atom in RegExp with unicode flag. r=till, f=anba (7a25bc6cd6)
- Bug 1135377 - Part 5: Support CharacterClassEscape in RegExp with unicode flag. r=till, f=anba (f368c54be5)
- Bug 1135377 - Part 6: Support ignoreCase for BMP in RegExp with unicode flag. r=till, f=anba (7c7e89b0bd)
- Bug 1135377 - Part 7: Support ignoreCase for non-BMP in RegExp with unicode flag. r=till, f=anba (6841ae2cd6)
- Bug 1135377 - Part 8: Disallow extended pattern in RegExp with unicode flag. r=till, f=anba (a12155c034)
- Bug 1135377 - Part 9: Use RegExp unicode flag in String.prototype.{match,replace,split}. r=till, f=anba (92f310d912)
- Bug 1135377 - Part 10: Decrement index when it points trail surrogate that has corresponding lead surrogate. r=till, f=anba (61ef65c7b2)
- Bug 1135377 - Part 11: Support back reference with unicode flag. r=till, f=anba (777aa5be56)
- Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=n.nethercote (b7a402773b)
- Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=nbp (b3d16188b4)
- Bug 1231386 - Change debugger to use RuntimeAllocPolicy for all its hash tables r=terrence (800f98186f)
- Bug 1231170: TraceLogger - Use size in debugger instead of the current id to track last logged item, r=bbouvier (a0ea950299)
- Bug 1226217 - Use less verbose cycle collection macros for mozilla::devtools::HeapSnapshot; r=bz (36ca65581d)
- Bug 1231763 - Extract breakdown parsing from JS::ubi::Census. r=jimb (698e7f5c2e)
- reapply bit of 1259403 (d6259f391e)
- Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=jdemooij (edb4735fc5)
- Bug 1230747 - Fix element id generation rule for bytecode documentation. r=jwalden (392a974079)
- Bug 1231900 - "API Document for JS_snprintf() is non-consistent with the Implementation". r=jcoppeard (b669cf0291)
- Bug 1231883 - Implement HeapSnapshot.describeNode; r=mrbkap (515a6c4d1e)
- Bug 1232814 - Part 1: Fix a missing early return in NoteWeakEdge; r=sfink (e56620fb5d)
- Bug 1232814 - Part 2: Move LazyScript finalization to the background finalization thread; r=jonco (bb17b5a10d)
- Bug 1234106 - Avoid symbolic links in various directories used by the build system. r=gps (d150b03192)
2023-06-08 09:57:37 +08:00

446 lines
11 KiB
C++

/* 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/. */
#include "nsXPCOMGlue.h"
#include "nsINIParser.h"
#include "nsXPCOMPrivate.h" // for XP MAXPATHLEN
#include "nsXULAppAPI.h"
#include "nsIFile.h"
#include <stdarg.h>
#ifdef XP_WIN
#include <windows.h>
#include <io.h>
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#endif
#define strcasecmp _stricmp
#define PATH_SEPARATOR_CHAR '\\'
#define R_OK 04
#elif defined(XP_MACOSX)
#include <unistd.h>
#include <sys/stat.h>
#include <CoreFoundation/CoreFoundation.h>
#define PATH_SEPARATOR_CHAR '/'
#else
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#define PATH_SEPARATOR_CHAR '/'
#endif
#ifdef XP_WIN
#define XRE_DONT_PROTECT_DLL_LOAD
#include "nsWindowsWMain.cpp"
#endif
#define VERSION_MAXLEN 128
static void Output(bool isError, const char *fmt, ... )
{
va_list ap;
va_start(ap, fmt);
#if (defined(XP_WIN) && !MOZ_WINCONSOLE)
char msg[2048];
vsnprintf(msg, sizeof(msg), fmt, ap);
UINT flags = MB_OK;
if (isError)
flags |= MB_ICONERROR;
else
flags |= MB_ICONINFORMATION;
wchar_t wide_msg[1024];
MultiByteToWideChar(CP_ACP,
0,
msg,
-1,
wide_msg,
sizeof(wide_msg) / sizeof(wchar_t));
MessageBoxW(nullptr, wide_msg, L"XULRunner", flags);
#else
vfprintf(stderr, fmt, ap);
#endif
va_end(ap);
}
/**
* Return true if |arg| matches the given argument name.
*/
static bool IsArg(const char* arg, const char* s)
{
if (*arg == '-')
{
if (*++arg == '-')
++arg;
return !strcasecmp(arg, s);
}
#if defined(XP_WIN)
if (*arg == '/')
return !strcasecmp(++arg, s);
#endif
return false;
}
/**
* Return true if |aDir| is a valid file/directory.
*/
static bool FolderExists(const char* aDir)
{
#ifdef XP_WIN
wchar_t wideDir[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, aDir, -1, wideDir, MAX_PATH);
DWORD fileAttrs = GetFileAttributesW(wideDir);
return fileAttrs != INVALID_FILE_ATTRIBUTES;
#else
return access(aDir, R_OK) == 0;
#endif
}
static nsresult GetRealPath(const char* appDataFile, char* *aResult)
{
#ifdef XP_WIN
wchar_t wAppDataFile[MAX_PATH];
wchar_t wIniPath[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, appDataFile, -1, wAppDataFile, MAX_PATH);
_wfullpath(wIniPath, wAppDataFile, MAX_PATH);
WideCharToMultiByte(CP_UTF8, 0, wIniPath, -1, *aResult, MAX_PATH, 0, 0);
#else
struct stat fileStat;
if (!realpath(appDataFile, *aResult) || stat(*aResult, &fileStat))
return NS_ERROR_FAILURE;
#endif
if (!*aResult || !**aResult)
return NS_ERROR_FAILURE;
return NS_OK;
}
class AutoAppData
{
public:
AutoAppData(nsIFile* aINIFile) : mAppData(nullptr) {
nsresult rv = XRE_CreateAppData(aINIFile, &mAppData);
if (NS_FAILED(rv))
mAppData = nullptr;
}
~AutoAppData() {
if (mAppData)
XRE_FreeAppData(mAppData);
}
operator nsXREAppData*() const { return mAppData; }
nsXREAppData* operator -> () const { return mAppData; }
private:
nsXREAppData* mAppData;
};
XRE_CreateAppDataType XRE_CreateAppData;
XRE_FreeAppDataType XRE_FreeAppData;
XRE_mainType XRE_main;
int
main(int argc, char **argv)
{
nsresult rv;
char *lastSlash;
char iniPath[MAXPATHLEN];
char tmpPath[MAXPATHLEN];
char greDir[MAXPATHLEN];
bool greFound = false;
#if defined(XP_MACOSX)
CFBundleRef appBundle = CFBundleGetMainBundle();
if (!appBundle)
return 1;
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle);
if (!resourcesURL)
return 1;
CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL);
CFRelease(resourcesURL);
if (!absResourcesURL)
return 1;
CFURLRef iniFileURL =
CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
absResourcesURL,
CFSTR("application.ini"),
false);
CFRelease(absResourcesURL);
if (!iniFileURL)
return 1;
CFStringRef iniPathStr =
CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle);
CFRelease(iniFileURL);
if (!iniPathStr)
return 1;
CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath),
kCFStringEncodingUTF8);
CFRelease(iniPathStr);
#else
#ifdef XP_WIN
wchar_t wide_path[MAX_PATH];
if (!::GetModuleFileNameW(nullptr, wide_path, MAX_PATH))
return 1;
WideCharToMultiByte(CP_UTF8, 0, wide_path,-1,
iniPath, MAX_PATH, nullptr, nullptr);
#else
// on unix, there is no official way to get the path of the current binary.
// instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to
// multiple applications, we will try a series of techniques:
//
// 1) use realpath() on argv[0], which works unless we're loaded from the
// PATH
// 2) manually walk through the PATH and look for ourself
// 3) give up
struct stat fileStat;
strncpy(tmpPath, argv[0], sizeof(tmpPath));
lastSlash = strrchr(tmpPath, '/');
if (lastSlash) {
*lastSlash = 0;
realpath(tmpPath, iniPath);
} else {
const char *path = getenv("PATH");
if (!path)
return 1;
char *pathdup = strdup(path);
if (!pathdup)
return 1;
bool found = false;
char *token = strtok(pathdup, ":");
while (token) {
sprintf(tmpPath, "%s/%s", token, argv[0]);
if (stat(tmpPath, &fileStat) == 0) {
found = true;
lastSlash = strrchr(tmpPath, '/');
*lastSlash = 0;
realpath(tmpPath, iniPath);
break;
}
token = strtok(nullptr, ":");
}
free (pathdup);
if (!found)
return 1;
}
lastSlash = iniPath + strlen(iniPath);
*lastSlash = '/';
#endif
#ifndef XP_UNIX
lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR);
if (!lastSlash)
return 1;
#endif
*(++lastSlash) = '\0';
// On Linux/Win, look for XULRunner in appdir/xulrunner
snprintf(greDir, sizeof(greDir),
"%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL,
iniPath);
greFound = FolderExists(greDir);
#ifdef XP_UNIX
if (greFound) {
char resolved_greDir[MAXPATHLEN] = "";
if (realpath(greDir, resolved_greDir) && *resolved_greDir) {
strncpy(greDir, resolved_greDir, MAXPATHLEN);
}
}
#endif
strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath));
#endif
// If -app parameter was passed in, it is now time to take it under
// consideration.
const char *appDataFile;
appDataFile = getenv("XUL_APP_FILE");
if (!appDataFile || !*appDataFile)
if (argc > 1 && IsArg(argv[1], "app")) {
if (argc == 2) {
Output(false, "specify APP-FILE (optional)\n");
return 1;
}
argv[1] = argv[0];
++argv;
--argc;
appDataFile = argv[1];
argv[1] = argv[0];
++argv;
--argc;
char kAppEnv[MAXPATHLEN];
snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile);
if (putenv(kAppEnv))
Output(false, "Couldn't set %s.\n", kAppEnv);
char *result = (char*) calloc(sizeof(char), MAXPATHLEN);
if (NS_FAILED(GetRealPath(appDataFile, &result))) {
Output(true, "Invalid application.ini path.\n");
return 1;
}
// We have a valid application.ini path passed in to the -app parameter
// but not yet a valid greDir, so lets look for it also on the same folder
// as the stub.
if (!greFound) {
lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR);
if (!lastSlash)
return 1;
*(++lastSlash) = '\0';
snprintf(greDir, sizeof(greDir), "%s" XPCOM_DLL, iniPath);
greFound = FolderExists(greDir);
}
// copy it back.
strcpy(iniPath, result);
}
nsINIParser parser;
rv = parser.Init(iniPath);
if (NS_FAILED(rv)) {
fprintf(stderr, "Could not read application.ini\n");
return 1;
}
if (!greFound) {
#ifdef XP_MACOSX
// The bundle can be found next to the executable, in the MacOS dir.
CFURLRef exurl = CFBundleCopyExecutableURL(appBundle);
CFURLRef absexurl = nullptr;
if (exurl) {
absexurl = CFURLCopyAbsoluteURL(exurl);
CFRelease(exurl);
}
if (absexurl) {
char tbuffer[MAXPATHLEN];
if (CFURLGetFileSystemRepresentation(absexurl, true,
(UInt8*) tbuffer,
sizeof(tbuffer)) &&
access(tbuffer, R_OK | X_OK) == 0) {
if (realpath(tbuffer, greDir)) {
greFound = true;
}
else {
greDir[0] = '\0';
}
}
CFRelease(absexurl);
}
#endif
if (!greFound) {
Output(false, "Could not find the Mozilla runtime.\n");
return 1;
}
}
rv = XPCOMGlueStartup(greDir);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_OUT_OF_MEMORY) {
char applicationName[2000] = "this application";
parser.GetString("App", "Name", applicationName, sizeof(applicationName));
Output(true, "Not enough memory available to start %s.\n",
applicationName);
} else {
Output(true, "Couldn't load XPCOM.\n");
}
return 1;
}
static const nsDynamicFunctionLoad kXULFuncs[] = {
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
{ "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
{ "XRE_main", (NSFuncPtr*) &XRE_main },
{ nullptr, nullptr }
};
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
if (NS_FAILED(rv)) {
Output(true, "Couldn't load XRE functions.\n");
return 1;
}
NS_LogInit();
int retval;
{ // Scope COMPtr and AutoAppData
nsCOMPtr<nsIFile> iniFile;
#ifdef XP_WIN
// On Windows iniPath is UTF-8 encoded so we need to convert it.
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), false,
getter_AddRefs(iniFile));
#else
rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), false,
getter_AddRefs(iniFile));
#endif
if (NS_FAILED(rv)) {
Output(true, "Couldn't find application.ini file.\n");
return 1;
}
AutoAppData appData(iniFile);
if (!appData) {
Output(true, "Error: couldn't parse application.ini.\n");
return 1;
}
NS_ASSERTION(appData->directory, "Failed to get app directory.");
if (!appData->xreDirectory) {
// chop "libxul.so" off the GRE path
lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR);
if (lastSlash) {
*lastSlash = '\0';
}
#ifdef XP_WIN
// same as iniPath.
NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), false,
&appData->xreDirectory);
#else
NS_NewNativeLocalFile(nsDependentCString(greDir), false,
&appData->xreDirectory);
#endif
}
retval = XRE_main(argc, argv, appData, 0);
}
NS_LogTerm();
return retval;
}