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
|
|
|
|
2007-07-20 11:57:22 -07:00
|
|
|
#if defined(XP_OS2) && defined(MOZ_OS2_HIGH_MEMORY)
|
|
|
|
// os2safe.h has to be included before os2.h, needed for high mem
|
|
|
|
#include <os2safe.h>
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
|
|
|
|
|
2008-04-19 06:21:59 -07:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
2012-03-22 16:24:40 -07:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QStringList>
|
2011-10-17 17:53:37 -07:00
|
|
|
#include "nsQAppInstance.h"
|
2012-03-22 16:24:40 -07:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
|
|
|
#include <QInputContextFactory>
|
|
|
|
#include <QInputContext>
|
|
|
|
#endif
|
2010-08-03 10:44:46 -07:00
|
|
|
#endif // MOZ_WIDGET_QT
|
2008-04-19 06:21:59 -07:00
|
|
|
|
2010-08-11 18:18:41 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2011-10-04 13:31:00 -07:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2010-08-11 18:18:41 -07:00
|
|
|
|
2012-06-19 20:49:05 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2013-05-07 11:48:59 -07:00
|
|
|
#include "mozilla/Poison.h"
|
2013-01-31 13:11:38 -08:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-05-07 11:48:59 -07:00
|
|
|
#include "mozilla/Util.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2010-03-04 13:51:42 -08:00
|
|
|
#include "nsAppRunner.h"
|
2012-06-08 05:41:30 -07:00
|
|
|
#include "mozilla/AppData.h"
|
2010-03-04 13:51:42 -08:00
|
|
|
#include "nsUpdateDriver.h"
|
2012-03-19 17:01:49 -07:00
|
|
|
#include "ProfileReset.h"
|
2010-03-04 13:51:42 -08:00
|
|
|
|
2011-03-03 08:20:02 -08:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
|
|
|
#include "EventTracer.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2011-10-26 19:57:26 -07:00
|
|
|
#include "nsVersionComparator.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "MacLaunchHelper.h"
|
|
|
|
#include "MacApplicationDelegate.h"
|
2010-04-21 01:29:38 -07:00
|
|
|
#include "MacAutoreleasePool.h"
|
2011-10-14 12:22:11 -07:00
|
|
|
// these are needed for sysctl
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_OS2
|
|
|
|
#include "private/pprthred.h"
|
|
|
|
#endif
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "prnetdb.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prproces.h"
|
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsIAppStartup.h"
|
|
|
|
#include "nsIAppStartupNotifier.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIChromeRegistry.h"
|
|
|
|
#include "nsICommandLineRunner.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIContentHandler.h"
|
|
|
|
#include "nsIDialogParamBlock.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2007-08-16 16:10:46 -07:00
|
|
|
#include "nsIIOService2.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsINativeAppSupport.h"
|
|
|
|
#include "nsIProcess.h"
|
|
|
|
#include "nsIProfileUnlocker.h"
|
|
|
|
#include "nsIPromptService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
|
|
|
#include "nsIToolkitProfile.h"
|
|
|
|
#include "nsIToolkitProfileService.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIWindowCreator.h"
|
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsIXULRuntime.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsAppShellCID.h"
|
2012-10-23 09:46:51 -07:00
|
|
|
#include "mozilla/scache/StartupCache.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-02 12:35:42 -07:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
2011-08-02 12:35:42 -07:00
|
|
|
using mozilla::unused;
|
2012-10-23 09:46:51 -07:00
|
|
|
using mozilla::scache::StartupCache;
|
2010-04-26 11:13:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsIWinAppHelper.h"
|
2009-07-17 07:17:45 -07:00
|
|
|
#include <windows.h>
|
2011-01-23 02:45:00 -08:00
|
|
|
#include "cairo/cairo-features.h"
|
2012-11-05 03:26:12 -08:00
|
|
|
#ifdef MOZ_METRO
|
|
|
|
#include <roapi.h>
|
|
|
|
#endif
|
2009-07-17 07:17:45 -07:00
|
|
|
|
|
|
|
#ifndef PROCESS_DEP_ENABLE
|
|
|
|
#define PROCESS_DEP_ENABLE 0x1
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsEmbedCID.h"
|
|
|
|
#include "nsNetUtil.h"
|
2007-06-29 22:02:49 -07:00
|
|
|
#include "nsReadableUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsStaticComponents.h"
|
|
|
|
#include "nsXPCOM.h"
|
2009-01-12 08:05:10 -08:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXPIDLString.h"
|
2012-02-23 19:34:18 -08:00
|
|
|
#include "nsPrintfCString.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsVersionComparator.h"
|
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsXREDirProvider.h"
|
|
|
|
#include "nsToolkitCompsCID.h"
|
|
|
|
|
|
|
|
#include "nsINIParser.h"
|
2010-05-21 10:58:32 -07:00
|
|
|
#include "mozilla/Omnijar.h"
|
2011-11-17 23:54:27 -08:00
|
|
|
#include "mozilla/StartupTimeline.h"
|
2012-10-31 11:18:03 -07:00
|
|
|
#include "mozilla/mozPoisonWrite.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-10-17 07:36:43 -07:00
|
|
|
// for old system jemalloc version check
|
|
|
|
#if !defined(MOZ_MEMORY) && defined(__NetBSD__)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2010-04-29 00:19:50 -07:00
|
|
|
#include <pwd.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsILocalFileMac.h"
|
|
|
|
#include "nsCommandLineServiceMac.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for X remote support
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
#include "XRemoteClient.h"
|
|
|
|
#include "nsIRemoteService.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS_TRACE_MALLOC
|
|
|
|
#include "nsTraceMalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(XP_WIN32)
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (XP_MACOSX)
|
2009-03-19 10:41:13 -07:00
|
|
|
#include <Carbon/Carbon.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
#include "jprof.h"
|
|
|
|
#endif
|
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
2007-04-10 12:15:16 -07:00
|
|
|
#include "nsICrashReporter.h"
|
|
|
|
#define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
|
2009-11-13 15:05:14 -08:00
|
|
|
#include "nsIPrefService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
#include "base/command_line.h"
|
2013-03-11 11:47:40 -07:00
|
|
|
#ifdef MOZ_ENABLE_TESTS
|
2012-05-22 13:45:24 -07:00
|
|
|
#include "GTestRunner.h"
|
|
|
|
#endif
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2010-06-03 18:16:20 -07:00
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
extern uint32_t gRestartMode;
|
2009-12-17 13:56:12 -08:00
|
|
|
extern void InstallSignalHandlers(const char *ProgramName);
|
2010-02-24 14:25:16 -08:00
|
|
|
#include "nsX11ErrorHandler.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-15 23:32:29 -07:00
|
|
|
#define FILE_COMPATIBILITY_INFO NS_LITERAL_CSTRING("compatibility.ini")
|
2010-07-02 16:59:17 -07:00
|
|
|
#define FILE_INVALIDATE_CACHES NS_LITERAL_CSTRING(".purgecaches")
|
2009-10-15 23:32:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
int gArgc;
|
|
|
|
char **gArgv;
|
|
|
|
|
2010-04-07 12:44:38 -07:00
|
|
|
static const char gToolkitVersion[] = NS_STRINGIFY(GRE_MILESTONE);
|
|
|
|
static const char gToolkitBuildID[] = NS_STRINGIFY(GRE_BUILDID);
|
2007-07-02 11:20:24 -07:00
|
|
|
|
2011-11-07 21:20:42 -08:00
|
|
|
static nsIProfileLock* gProfileLock;
|
|
|
|
|
2012-05-22 07:50:04 -07:00
|
|
|
int gRestartArgc;
|
|
|
|
char **gRestartArgv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-16 23:52:23 -07:00
|
|
|
#ifdef MOZ_WIDGET_QT
|
|
|
|
static int gQtOnlyArgc;
|
|
|
|
static char **gQtOnlyArgv;
|
|
|
|
#endif
|
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2008-09-25 15:38:25 -07:00
|
|
|
#if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) \
|
|
|
|
|| defined(NS_TRACE_MALLOC)
|
|
|
|
#define CLEANUP_MEMORY 1
|
|
|
|
#define PANGO_ENABLE_BACKEND
|
|
|
|
#include <pango/pangofc-fontmap.h>
|
|
|
|
#endif
|
2007-04-30 16:52:44 -07:00
|
|
|
#include <gtk/gtk.h>
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2007-10-03 14:44:05 -07:00
|
|
|
#include <gdk/gdkx.h>
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGTKToolkit.h"
|
|
|
|
#endif
|
2011-05-21 23:23:20 -07:00
|
|
|
#include "BinaryPath.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-11 11:47:40 -07:00
|
|
|
namespace mozilla {
|
|
|
|
int (*RunGTest)() = 0;
|
|
|
|
}
|
|
|
|
|
2011-07-15 03:31:34 -07:00
|
|
|
using mozilla::dom::ContentParent;
|
2011-10-04 13:31:00 -07:00
|
|
|
using mozilla::dom::ContentChild;
|
2011-07-15 03:31:34 -07:00
|
|
|
|
2010-04-19 01:29:18 -07:00
|
|
|
// Save literal putenv string to environment variable.
|
|
|
|
static void
|
|
|
|
SaveToEnv(const char *putenv)
|
|
|
|
{
|
|
|
|
char *expr = strdup(putenv);
|
|
|
|
if (expr)
|
|
|
|
PR_SetEnv(expr);
|
|
|
|
// We intentionally leak |expr| here since it is required by PR_SetEnv.
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:28:18 -07:00
|
|
|
// Tests that an environment variable exists and has a value
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-03-23 10:28:18 -07:00
|
|
|
EnvHasValue(const char *name)
|
|
|
|
{
|
|
|
|
const char *val = PR_GetEnv(name);
|
|
|
|
return (val && *val);
|
|
|
|
}
|
|
|
|
|
2007-06-29 22:02:49 -07:00
|
|
|
// Save the given word to the specified environment variable.
|
|
|
|
static void
|
|
|
|
SaveWordToEnv(const char *name, const nsACString & word)
|
|
|
|
{
|
|
|
|
char *expr = PR_smprintf("%s=%s", name, PromiseFlatCString(word).get());
|
|
|
|
if (expr)
|
|
|
|
PR_SetEnv(expr);
|
|
|
|
// We intentionally leak |expr| here since it is required by PR_SetEnv.
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Save the path of the given file to the specified environment variable.
|
|
|
|
static void
|
|
|
|
SaveFileToEnv(const char *name, nsIFile *file)
|
|
|
|
{
|
2007-12-31 07:15:43 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsAutoString path;
|
|
|
|
file->GetPath(path);
|
|
|
|
SetEnvironmentVariableW(NS_ConvertASCIItoUTF16(name).get(), path.get());
|
|
|
|
#else
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString path;
|
2007-03-22 10:30:00 -07:00
|
|
|
file->GetNativePath(path);
|
2007-06-29 22:02:49 -07:00
|
|
|
SaveWordToEnv(name, path);
|
2007-12-31 07:15:43 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the path of a file saved with SaveFileToEnv
|
2012-06-05 19:08:30 -07:00
|
|
|
static already_AddRefed<nsIFile>
|
2007-12-31 07:15:43 -08:00
|
|
|
GetFileFromEnv(const char *name)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2013-04-22 04:15:59 -07:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2007-12-31 07:15:43 -08:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
WCHAR path[_MAX_PATH];
|
|
|
|
if (!GetEnvironmentVariableW(NS_ConvertASCIItoUTF16(name).get(),
|
|
|
|
path, _MAX_PATH))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-12-31 07:15:43 -08:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
rv = NS_NewLocalFile(nsDependentString(path), true, getter_AddRefs(file));
|
2007-12-31 07:15:43 -08:00
|
|
|
if (NS_FAILED(rv))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-12-31 07:15:43 -08:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
return file.forget();
|
2007-12-31 07:15:43 -08:00
|
|
|
#else
|
|
|
|
const char *arg = PR_GetEnv(name);
|
|
|
|
if (!arg || !*arg)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-12-31 07:15:43 -08:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(arg), true,
|
|
|
|
getter_AddRefs(file));
|
2007-12-31 07:15:43 -08:00
|
|
|
if (NS_FAILED(rv))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-12-31 07:15:43 -08:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
return file.forget();
|
2007-12-31 07:15:43 -08:00
|
|
|
#endif
|
2007-06-29 22:02:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-29 22:02:49 -07:00
|
|
|
// Save the path of the given word to the specified environment variable
|
|
|
|
// provided the environment variable does not have a value.
|
|
|
|
static void
|
|
|
|
SaveWordToEnvIfUnset(const char *name, const nsACString & word)
|
|
|
|
{
|
2011-03-23 10:28:18 -07:00
|
|
|
if (!EnvHasValue(name))
|
2007-06-29 22:02:49 -07:00
|
|
|
SaveWordToEnv(name, word);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the path of the given file to the specified environment variable
|
|
|
|
// provided the environment variable does not have a value.
|
|
|
|
static void
|
|
|
|
SaveFileToEnvIfUnset(const char *name, nsIFile *file)
|
|
|
|
{
|
2011-03-23 10:28:18 -07:00
|
|
|
if (!EnvHasValue(name))
|
2007-03-22 10:30:00 -07:00
|
|
|
SaveFileToEnv(name, file);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
strimatch(const char* lowerstr, const char* mixedstr)
|
|
|
|
{
|
|
|
|
while(*lowerstr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!*mixedstr) return false; // mixedstr is shorter
|
|
|
|
if (tolower(*mixedstr) != *lowerstr) return false; // no match
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
++lowerstr;
|
|
|
|
++mixedstr;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
if (*mixedstr) return false; // lowerstr is shorter
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a string to the user. This method is really only meant to be used to
|
|
|
|
* output last-ditch error messages designed for developers NOT END USERS.
|
|
|
|
*
|
|
|
|
* @param isError
|
|
|
|
* Pass true to indicate severe errors.
|
|
|
|
* @param fmt
|
|
|
|
* printf-style format string followed by arguments.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static void Output(bool isError, const char *fmt, ... )
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
#if defined(XP_WIN) && !MOZ_WINCONSOLE
|
|
|
|
char *msg = PR_vsmprintf(fmt, ap);
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
UINT flags = MB_OK;
|
|
|
|
if (isError)
|
|
|
|
flags |= MB_ICONERROR;
|
|
|
|
else
|
|
|
|
flags |= MB_ICONINFORMATION;
|
2008-09-25 14:34:53 -07:00
|
|
|
|
|
|
|
wchar_t wide_msg[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP,
|
|
|
|
0,
|
|
|
|
msg,
|
|
|
|
-1,
|
|
|
|
wide_msg,
|
|
|
|
sizeof(wide_msg) / sizeof(wchar_t));
|
|
|
|
|
|
|
|
MessageBoxW(NULL, wide_msg, L"XULRunner", flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_smprintf_free(msg);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2007-08-19 22:09:07 -07:00
|
|
|
enum RemoteResult {
|
|
|
|
REMOTE_NOT_FOUND = 0,
|
|
|
|
REMOTE_FOUND = 1,
|
|
|
|
REMOTE_ARG_BAD = 2
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
enum ArgResult {
|
|
|
|
ARG_NONE = 0,
|
|
|
|
ARG_FOUND = 1,
|
|
|
|
ARG_BAD = 2 // you wanted a param, but there isn't one
|
|
|
|
};
|
|
|
|
|
|
|
|
static void RemoveArg(char **argv)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
*argv = *(argv + 1);
|
|
|
|
++argv;
|
|
|
|
} while (*argv);
|
|
|
|
|
|
|
|
--gArgc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for a commandline flag. If the flag takes a parameter, the
|
|
|
|
* parameter is returned in aParam. Flags may be in the form -arg or
|
|
|
|
* --arg (or /arg on win32/OS2).
|
|
|
|
*
|
|
|
|
* @param aArg the parameter to check. Must be lowercase.
|
2007-07-10 22:59:56 -07:00
|
|
|
* @param aCheckOSInt if true returns ARG_BAD if the osint argument is present
|
|
|
|
* when aArg is also present.
|
2013-04-22 16:00:17 -07:00
|
|
|
* @param aParam if non-null, the -arg <data> will be stored in this pointer.
|
|
|
|
* This is *not* allocated, but rather a pointer to the argv data.
|
|
|
|
* @param aRemArg if true, the argument is removed from the gArgv array.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
static ArgResult
|
2012-07-30 07:20:58 -07:00
|
|
|
CheckArg(const char* aArg, bool aCheckOSInt = false, const char **aParam = nullptr, bool aRemArg = true)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:50:17 -07:00
|
|
|
NS_ABORT_IF_FALSE(gArgv, "gArgv must be initialized before CheckArg()");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
char **curarg = gArgv + 1; // skip argv[0]
|
2007-07-10 22:59:56 -07:00
|
|
|
ArgResult ar = ARG_NONE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (*curarg) {
|
|
|
|
char *arg = curarg[0];
|
|
|
|
|
|
|
|
if (arg[0] == '-'
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
|| *arg == '/'
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
++arg;
|
|
|
|
if (*arg == '-')
|
|
|
|
++arg;
|
|
|
|
|
|
|
|
if (strimatch(aArg, arg)) {
|
2009-08-26 16:10:48 -07:00
|
|
|
if (aRemArg)
|
|
|
|
RemoveArg(curarg);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aParam) {
|
2007-07-10 22:59:56 -07:00
|
|
|
ar = ARG_FOUND;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*curarg) {
|
|
|
|
if (**curarg == '-'
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
|| **curarg == '/'
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
return ARG_BAD;
|
|
|
|
|
|
|
|
*aParam = *curarg;
|
2009-08-26 16:10:48 -07:00
|
|
|
if (aRemArg)
|
|
|
|
RemoveArg(curarg);
|
2007-07-10 22:59:56 -07:00
|
|
|
ar = ARG_FOUND;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return ARG_BAD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++curarg;
|
|
|
|
}
|
|
|
|
|
2007-07-10 22:59:56 -07:00
|
|
|
if (aCheckOSInt && ar == ARG_FOUND) {
|
|
|
|
ArgResult arOSInt = CheckArg("osint");
|
|
|
|
if (arOSInt == ARG_FOUND) {
|
|
|
|
ar = ARG_BAD;
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -osint is invalid\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ar;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
/**
|
|
|
|
* Check for a commandline flag from the windows shell and remove it from the
|
|
|
|
* argv used when restarting. Flags MUST be in the form -arg.
|
|
|
|
*
|
|
|
|
* @param aArg the parameter to check. Must be lowercase.
|
|
|
|
*/
|
|
|
|
static ArgResult
|
|
|
|
CheckArgShell(const char* aArg)
|
|
|
|
{
|
|
|
|
char **curarg = gRestartArgv + 1; // skip argv[0]
|
|
|
|
|
|
|
|
while (*curarg) {
|
|
|
|
char *arg = curarg[0];
|
|
|
|
|
|
|
|
if (arg[0] == '-') {
|
|
|
|
++arg;
|
|
|
|
|
|
|
|
if (strimatch(aArg, arg)) {
|
|
|
|
do {
|
|
|
|
*curarg = *(curarg + 1);
|
|
|
|
++curarg;
|
|
|
|
} while (*curarg);
|
|
|
|
|
|
|
|
--gRestartArgc;
|
|
|
|
|
|
|
|
return ARG_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++curarg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ARG_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-20 17:21:21 -07:00
|
|
|
* Enabled Native App Support to process DDE messages when the app needs to
|
|
|
|
* restart and the app has been launched by the Windows shell to open an url.
|
|
|
|
* When aWait is false this will process the DDE events manually. This prevents
|
|
|
|
* Windows from displaying an error message due to the DDE message not being
|
|
|
|
* acknowledged.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
static void
|
2011-09-28 23:19:26 -07:00
|
|
|
ProcessDDE(nsINativeAppSupport* aNative, bool aWait)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// When the app is launched by the windows shell the windows shell
|
|
|
|
// expects the app to be available for DDE messages and if it isn't
|
|
|
|
// windows displays an error dialog. To prevent the error the DDE server
|
|
|
|
// is enabled and pending events are processed when the app needs to
|
|
|
|
// restart after it was launched by the shell with the requestpending
|
|
|
|
// argument. The requestpending pending argument is removed to
|
|
|
|
// differentiate it from being launched when an app restart is not
|
|
|
|
// required.
|
|
|
|
ArgResult ar;
|
|
|
|
ar = CheckArgShell("requestpending");
|
|
|
|
if (ar == ARG_FOUND) {
|
|
|
|
aNative->Enable(); // enable win32 DDE responses
|
2008-06-20 17:21:21 -07:00
|
|
|
if (aWait) {
|
|
|
|
nsIThread *thread = NS_GetCurrentThread();
|
|
|
|
// This is just a guesstimate based on testing different values.
|
|
|
|
// If count is 8 or less windows will display an error dialog.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = 20;
|
2008-06-20 17:21:21 -07:00
|
|
|
while(--count >= 0) {
|
|
|
|
NS_ProcessNextEvent(thread);
|
|
|
|
PR_Sleep(PR_MillisecondsToInterval(1));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool gSafeMode = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsXULAppInfo object implements nsIFactory so that it can be its own
|
|
|
|
* singleton.
|
|
|
|
*/
|
|
|
|
class nsXULAppInfo : public nsIXULAppInfo,
|
|
|
|
#ifdef XP_WIN
|
|
|
|
public nsIWinAppHelper,
|
2007-04-10 12:15:16 -07:00
|
|
|
#endif
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-04-10 12:15:16 -07:00
|
|
|
public nsICrashReporter,
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
public nsIXULRuntime
|
2009-07-29 20:23:56 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-03-24 16:29:29 -07:00
|
|
|
nsXULAppInfo() {}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIXULAPPINFO
|
|
|
|
NS_DECL_NSIXULRUNTIME
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-04-10 12:15:16 -07:00
|
|
|
NS_DECL_NSICRASHREPORTER
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
NS_DECL_NSIWINAPPHELPER
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXULAppInfo)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULRuntime)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULRuntime)
|
|
|
|
#ifdef XP_WIN
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWinAppHelper)
|
2007-04-10 12:15:16 -07:00
|
|
|
#endif
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-04-10 12:15:16 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICrashReporter)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2011-10-04 13:31:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData ||
|
|
|
|
XRE_GetProcessType() == GeckoProcessType_Content)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXULAppInfo::AddRef()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXULAppInfo::Release()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetVendor(nsACString& aResult)
|
|
|
|
{
|
2011-10-04 13:31:00 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.Assign(gAppData->vendor);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetName(nsACString& aResult)
|
|
|
|
{
|
2011-10-04 13:31:00 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.Assign(gAppData->name);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetID(nsACString& aResult)
|
|
|
|
{
|
2011-10-04 13:31:00 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.Assign(gAppData->ID);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetVersion(nsACString& aResult)
|
|
|
|
{
|
2011-10-04 13:31:00 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
ContentChild* cc = ContentChild::GetSingleton();
|
|
|
|
aResult = cc->GetAppInfo().version;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.Assign(gAppData->version);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetPlatformVersion(nsACString& aResult)
|
|
|
|
{
|
2007-07-19 06:51:44 -07:00
|
|
|
aResult.Assign(gToolkitVersion);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetAppBuildID(nsACString& aResult)
|
|
|
|
{
|
2011-10-04 13:31:00 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
ContentChild* cc = ContentChild::GetSingleton();
|
|
|
|
aResult = cc->GetAppInfo().buildID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.Assign(gAppData->buildID);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetPlatformBuildID(nsACString& aResult)
|
|
|
|
{
|
2007-07-02 11:20:24 -07:00
|
|
|
aResult.Assign(gToolkitBuildID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-23 13:09:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetUAName(nsACString& aResult)
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
aResult.Assign(gAppData->UAName);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::GetLogConsoleErrors(bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aResult = gLogConsoleErrors;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::SetLogConsoleErrors(bool aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
gLogConsoleErrors = aValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::GetInSafeMode(bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aResult = gSafeMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetOS(nsACString& aResult)
|
|
|
|
{
|
|
|
|
aResult.AssignLiteral(OS_TARGET);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetXPCOMABI(nsACString& aResult)
|
|
|
|
{
|
|
|
|
#ifdef TARGET_XPCOM_ABI
|
|
|
|
aResult.AssignLiteral(TARGET_XPCOM_ABI);
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-02 05:53:24 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetWidgetToolkit(nsACString& aResult)
|
|
|
|
{
|
|
|
|
aResult.AssignLiteral(MOZ_WIDGET_TOOLKIT);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 10:09:51 -07:00
|
|
|
// Ensure that the GeckoProcessType enum, defined in xpcom/build/nsXULAppAPI.h,
|
|
|
|
// is synchronized with the const unsigned longs defined in
|
|
|
|
// xpcom/system/nsIXULRuntime.idl.
|
|
|
|
#define SYNC_ENUMS(a,b) \
|
2012-04-02 17:21:24 -07:00
|
|
|
MOZ_STATIC_ASSERT(nsIXULRuntime::PROCESS_TYPE_ ## a == \
|
|
|
|
static_cast<int>(GeckoProcessType_ ## b), \
|
|
|
|
"GeckoProcessType in nsXULAppAPI.h not synchronized with nsIXULRuntime.idl");
|
2009-08-19 10:09:51 -07:00
|
|
|
|
|
|
|
SYNC_ENUMS(DEFAULT, Default)
|
|
|
|
SYNC_ENUMS(PLUGIN, Plugin)
|
|
|
|
SYNC_ENUMS(CONTENT, Content)
|
2009-10-06 11:02:26 -07:00
|
|
|
SYNC_ENUMS(IPDLUNITTEST, IPDLUnitTest)
|
2009-08-19 10:09:51 -07:00
|
|
|
|
|
|
|
// .. and ensure that that is all of them:
|
2012-04-02 17:21:24 -07:00
|
|
|
MOZ_STATIC_ASSERT(GeckoProcessType_IPDLUnitTest + 1 == GeckoProcessType_End,
|
|
|
|
"Did not find the final GeckoProcessType");
|
2009-08-19 10:09:51 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULAppInfo::GetProcessType(uint32_t* aResult)
|
2009-08-19 10:09:51 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = XRE_GetProcessType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-30 11:43:56 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::EnsureContentProcess()
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2013-04-02 16:52:51 -07:00
|
|
|
nsRefPtr<ContentParent> unused = ContentParent::GetNewOrUsed();
|
2010-07-30 11:43:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-15 23:32:29 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::InvalidateCachesOnRestart()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DIR_STARTUP,
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
file->AppendNative(FILE_COMPATIBILITY_INFO);
|
|
|
|
|
|
|
|
nsINIParser parser;
|
2012-06-05 19:08:30 -07:00
|
|
|
rv = parser.Init(file);
|
2009-10-15 23:32:29 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// This fails if compatibility.ini is not there, so we'll
|
|
|
|
// flush the caches on the next restart anyways.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buf;
|
2009-10-15 23:32:29 -07:00
|
|
|
rv = parser.GetString("Compatibility", "InvalidateCaches", buf);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
PRFileDesc *fd = nullptr;
|
2012-06-05 19:08:30 -07:00
|
|
|
file->OpenNSPRFileDesc(PR_RDWR | PR_APPEND, 0600, &fd);
|
2009-10-15 23:32:29 -07:00
|
|
|
if (!fd) {
|
|
|
|
NS_ERROR("could not create output stream");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
static const char kInvalidationHeader[] = NS_LINEBREAK "InvalidateCaches=1" NS_LINEBREAK;
|
2012-07-27 06:54:09 -07:00
|
|
|
PR_Write(fd, kInvalidationHeader, sizeof(kInvalidationHeader) - 1);
|
2009-10-15 23:32:29 -07:00
|
|
|
PR_Close(fd);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-07 21:20:42 -08:00
|
|
|
NS_IMETHODIMP
|
2012-08-30 00:10:35 -07:00
|
|
|
nsXULAppInfo::GetReplacedLockTime(PRTime *aReplacedLockTime)
|
2011-11-07 21:20:42 -08:00
|
|
|
{
|
|
|
|
if (!gProfileLock)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
gProfileLock->GetReplacedLockTime(aReplacedLockTime);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetLastRunCrashID(nsAString &aLastRunCrashID)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
CrashReporter::GetLastRunCrashID(aLastRunCrashID);
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_WIN
|
2007-09-20 09:54:00 -07:00
|
|
|
// Matches the enum in WinNT.h for the Vista SDK but renamed so that we can
|
|
|
|
// safely build with the Vista SDK and without it.
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
VistaTokenElevationTypeDefault = 1,
|
|
|
|
VistaTokenElevationTypeFull,
|
|
|
|
VistaTokenElevationTypeLimited
|
|
|
|
} VISTA_TOKEN_ELEVATION_TYPE;
|
|
|
|
|
|
|
|
// avoid collision with TokeElevationType enum in WinNT.h
|
|
|
|
// of the Vista SDK
|
|
|
|
#define VistaTokenElevationType static_cast< TOKEN_INFORMATION_CLASS >( 18 )
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::GetUserCanElevate(bool *aUserCanElevate)
|
2007-09-20 09:54:00 -07:00
|
|
|
{
|
|
|
|
HANDLE hToken;
|
|
|
|
|
|
|
|
VISTA_TOKEN_ELEVATION_TYPE elevationType;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
|
|
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken) ||
|
|
|
|
!GetTokenInformation(hToken, VistaTokenElevationType, &elevationType,
|
|
|
|
sizeof(elevationType), &dwSize)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aUserCanElevate = false;
|
2007-09-20 09:54:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The possible values returned for elevationType and their meanings are:
|
|
|
|
// TokenElevationTypeDefault: The token does not have a linked token
|
|
|
|
// (e.g. UAC disabled or a standard user, so they can't be elevated)
|
|
|
|
// TokenElevationTypeFull: The token is linked to an elevated token
|
|
|
|
// (e.g. UAC is enabled and the user is already elevated so they can't
|
|
|
|
// be elevated again)
|
|
|
|
// TokenElevationTypeLimited: The token is linked to a limited token
|
|
|
|
// (e.g. UAC is enabled and the user is not elevated, so they can be
|
2011-02-22 23:18:17 -08:00
|
|
|
// elevated)
|
2007-09-20 09:54:00 -07:00
|
|
|
*aUserCanElevate = (elevationType == VistaTokenElevationTypeLimited);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hToken)
|
|
|
|
CloseHandle(hToken);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2009-04-02 08:41:12 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::GetEnabled(bool *aEnabled)
|
2009-04-02 08:41:12 -07:00
|
|
|
{
|
|
|
|
*aEnabled = CrashReporter::GetEnabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::SetEnabled(bool aEnabled)
|
2009-04-02 08:41:12 -07:00
|
|
|
{
|
|
|
|
if (aEnabled) {
|
|
|
|
if (CrashReporter::GetEnabled())
|
|
|
|
// no point in erroring for double-enabling
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> xreDirectory;
|
2009-04-02 08:41:12 -07:00
|
|
|
if (gAppData) {
|
|
|
|
xreDirectory = gAppData->xreDirectory;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We didn't get started through XRE_Main, probably
|
|
|
|
nsCOMPtr<nsIFile> greDir;
|
|
|
|
NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(greDir));
|
|
|
|
if (!greDir)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
xreDirectory = do_QueryInterface(greDir);
|
|
|
|
if (!xreDirectory)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-05-07 11:48:59 -07:00
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("FramePoisonBase"),
|
|
|
|
nsPrintfCString("%.16llx", uint64_t(gMozillaPoisonBase)));
|
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("FramePoisonSize"),
|
|
|
|
nsPrintfCString("%lu", uint32_t(gMozillaPoisonSize)));
|
2009-04-02 08:41:12 -07:00
|
|
|
return CrashReporter::SetExceptionHandler(xreDirectory, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!CrashReporter::GetEnabled())
|
|
|
|
// no point in erroring for double-disabling
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return CrashReporter::UnsetExceptionHandler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetServerURL(nsIURL** aServerURL)
|
|
|
|
{
|
|
|
|
if (!CrashReporter::GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString data;
|
2009-04-02 08:41:12 -07:00
|
|
|
if (!CrashReporter::GetServerURL(data)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), data);
|
|
|
|
if (!uri)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url;
|
|
|
|
url = do_QueryInterface(uri);
|
|
|
|
NS_ADDREF(*aServerURL = url);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::SetServerURL(nsIURL* aServerURL)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool schemeOk;
|
2009-04-02 08:41:12 -07:00
|
|
|
// only allow https or http URLs
|
|
|
|
nsresult rv = aServerURL->SchemeIs("https", &schemeOk);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!schemeOk) {
|
|
|
|
rv = aServerURL->SchemeIs("http", &schemeOk);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!schemeOk)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec;
|
2009-04-02 08:41:12 -07:00
|
|
|
rv = aServerURL->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CrashReporter::SetServerURL(spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-05 19:08:30 -07:00
|
|
|
nsXULAppInfo::GetMinidumpPath(nsIFile** aMinidumpPath)
|
2009-04-02 08:41:12 -07:00
|
|
|
{
|
|
|
|
if (!CrashReporter::GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsAutoString path;
|
|
|
|
if (!CrashReporter::GetMinidumpPath(path))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = NS_NewLocalFile(path, false, aMinidumpPath);
|
2009-04-02 08:41:12 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-05 19:08:30 -07:00
|
|
|
nsXULAppInfo::SetMinidumpPath(nsIFile* aMinidumpPath)
|
2009-04-02 08:41:12 -07:00
|
|
|
{
|
|
|
|
nsAutoString path;
|
|
|
|
nsresult rv = aMinidumpPath->GetPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return CrashReporter::SetMinidumpPath(path);
|
|
|
|
}
|
|
|
|
|
2007-04-10 12:15:16 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::AnnotateCrashReport(const nsACString& key,
|
|
|
|
const nsACString& data)
|
|
|
|
{
|
|
|
|
return CrashReporter::AnnotateCrashReport(key, data);
|
|
|
|
}
|
2008-02-08 18:40:47 -08:00
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::AppendAppNotesToCrashReport(const nsACString& data)
|
|
|
|
{
|
|
|
|
return CrashReporter::AppendAppNotesToCrashReport(data);
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:31:11 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULAppInfo::RegisterAppMemory(uint64_t pointer,
|
|
|
|
uint64_t len)
|
2011-07-07 17:31:11 -07:00
|
|
|
{
|
|
|
|
return CrashReporter::RegisterAppMemory((void *)pointer, len);
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:40:47 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::WriteMinidumpForException(void* aExceptionInfo)
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
return CrashReporter::WriteMinidumpForException(static_cast<EXCEPTION_POINTERS*>(aExceptionInfo));
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
2007-04-10 12:15:16 -07:00
|
|
|
|
2008-08-27 21:41:38 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::AppendObjCExceptionInfoToAppNotes(void* aException)
|
|
|
|
{
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
return CrashReporter::AppendObjCExceptionInfoToAppNotes(aException);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
2010-02-09 17:05:31 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::GetSubmitReports(bool* aEnabled)
|
2010-02-09 17:05:31 -08:00
|
|
|
{
|
|
|
|
return CrashReporter::GetSubmitReports(aEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULAppInfo::SetSubmitReports(bool aEnabled)
|
2010-02-09 17:05:31 -08:00
|
|
|
{
|
|
|
|
return CrashReporter::SetSubmitReports(aEnabled);
|
|
|
|
}
|
|
|
|
|
2008-08-27 22:23:43 -07:00
|
|
|
#endif
|
2008-08-27 21:41:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const nsXULAppInfo kAppInfo;
|
2010-06-10 11:11:11 -07:00
|
|
|
static nsresult AppInfoConstructor(nsISupports* aOuter,
|
|
|
|
REFNSIID aIID, void **aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
return const_cast<nsXULAppInfo*>(&kAppInfo)->
|
2007-03-22 10:30:00 -07:00
|
|
|
QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
2013-03-04 03:50:06 -08:00
|
|
|
bool gLogConsoleErrors = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_ENSURE_TRUE_LOG(x, ret) \
|
|
|
|
PR_BEGIN_MACRO \
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!(x))) { \
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \
|
2012-10-26 06:32:10 -07:00
|
|
|
gLogConsoleErrors = true; \
|
2007-03-22 10:30:00 -07:00
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define NS_ENSURE_SUCCESS_LOG(res, ret) \
|
|
|
|
NS_ENSURE_TRUE_LOG(NS_SUCCEEDED(res), ret)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Because we're starting/stopping XPCOM several times in different scenarios,
|
|
|
|
* this class is a stack-based critter that makes sure that XPCOM is shut down
|
|
|
|
* during early returns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ScopedXPCOMStartup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScopedXPCOMStartup() :
|
2012-07-30 07:20:58 -07:00
|
|
|
mServiceManager(nullptr) { }
|
2007-03-22 10:30:00 -07:00
|
|
|
~ScopedXPCOMStartup();
|
|
|
|
|
|
|
|
nsresult Initialize();
|
|
|
|
nsresult SetWindowCreator(nsINativeAppSupport* native);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
static nsresult CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsIServiceManager* mServiceManager;
|
2010-06-10 11:11:11 -07:00
|
|
|
static nsINativeAppSupport* gNativeAppSupport;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ScopedXPCOMStartup::~ScopedXPCOMStartup()
|
|
|
|
{
|
2010-06-22 17:11:32 -07:00
|
|
|
NS_IF_RELEASE(gNativeAppSupport);
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mServiceManager) {
|
2010-04-21 01:29:38 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// On OS X, we need a pool to catch cocoa objects that are autoreleased
|
|
|
|
// during teardown.
|
|
|
|
mozilla::MacAutoreleasePool pool;
|
|
|
|
#endif
|
|
|
|
|
2007-12-11 02:35:02 -08:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
if (appStartup)
|
|
|
|
appStartup->DestroyHiddenWindow();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gDirServiceProvider->DoShutdown();
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_MARKER("Shutdown early");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
WriteConsoleLog();
|
|
|
|
|
|
|
|
NS_ShutdownXPCOM(mServiceManager);
|
2012-07-30 07:20:58 -07:00
|
|
|
mServiceManager = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// {95d89e3e-a169-41a3-8e56-719978e15b12}
|
|
|
|
#define APPINFO_CID \
|
|
|
|
{ 0x95d89e3e, 0xa169, 0x41a3, { 0x8e, 0x56, 0x71, 0x99, 0x78, 0xe1, 0x5b, 0x12 } }
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// {0C4A446C-EE82-41f2-8D04-D366D2C7A7D4}
|
|
|
|
static const nsCID kNativeAppSupportCID =
|
|
|
|
{ 0xc4a446c, 0xee82, 0x41f2, { 0x8d, 0x4, 0xd3, 0x66, 0xd2, 0xc7, 0xa7, 0xd4 } };
|
|
|
|
|
|
|
|
// {5F5E59CE-27BC-47eb-9D1F-B09CA9049836}
|
|
|
|
static const nsCID kProfileServiceCID =
|
|
|
|
{ 0x5f5e59ce, 0x27bc, 0x47eb, { 0x9d, 0x1f, 0xb0, 0x9c, 0xa9, 0x4, 0x98, 0x36 } };
|
|
|
|
|
|
|
|
static already_AddRefed<nsIFactory>
|
|
|
|
ProfileServiceFactoryConstructor(const mozilla::Module& module, const mozilla::Module::CIDEntry& entry)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
NS_NewToolkitProfileFactory(getter_AddRefs(factory));
|
|
|
|
return factory.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DEFINE_NAMED_CID(APPINFO_CID);
|
|
|
|
|
|
|
|
static const mozilla::Module::CIDEntry kXRECIDs[] = {
|
|
|
|
{ &kAPPINFO_CID, false, NULL, AppInfoConstructor },
|
|
|
|
{ &kProfileServiceCID, false, ProfileServiceFactoryConstructor, NULL },
|
|
|
|
{ &kNativeAppSupportCID, false, NULL, ScopedXPCOMStartup::CreateAppSupport },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::ContractIDEntry kXREContracts[] = {
|
|
|
|
{ XULAPPINFO_SERVICE_CONTRACTID, &kAPPINFO_CID },
|
|
|
|
{ XULRUNTIME_SERVICE_CONTRACTID, &kAPPINFO_CID },
|
2010-06-22 17:18:45 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-06-10 11:11:11 -07:00
|
|
|
{ NS_CRASHREPORTER_CONTRACTID, &kAPPINFO_CID },
|
2010-06-22 17:18:45 -07:00
|
|
|
#endif
|
2010-06-10 11:11:11 -07:00
|
|
|
{ NS_PROFILESERVICE_CONTRACTID, &kProfileServiceCID },
|
|
|
|
{ NS_NATIVEAPPSUPPORT_CONTRACTID, &kNativeAppSupportCID },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module kXREModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kXRECIDs,
|
|
|
|
kXREContracts
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NSMODULE_DEFN(Apprunner) = &kXREModule;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::Initialize()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(gDirServiceProvider, "Should not get here!");
|
|
|
|
|
|
|
|
nsresult rv;
|
2010-05-21 10:58:32 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
rv = NS_InitXPCOM2(&mServiceManager, gDirServiceProvider->GetAppDir(),
|
|
|
|
gDirServiceProvider);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Couldn't start xpcom!");
|
2012-07-30 07:20:58 -07:00
|
|
|
mServiceManager = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIComponentRegistrar> reg =
|
|
|
|
do_QueryInterface(mServiceManager);
|
|
|
|
NS_ASSERTION(reg, "Service Manager doesn't QI to Registrar.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a little factory class that serves as a singleton-service-factory
|
|
|
|
* for the nativeappsupport object.
|
|
|
|
*/
|
2012-06-19 20:49:05 -07:00
|
|
|
class nsSingletonFactory MOZ_FINAL : public nsIFactory
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFACTORY
|
|
|
|
|
|
|
|
nsSingletonFactory(nsISupports* aSingleton);
|
|
|
|
~nsSingletonFactory() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mSingleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsSingletonFactory::nsSingletonFactory(nsISupports* aSingleton)
|
|
|
|
: mSingleton(aSingleton)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mSingleton, "Singleton was null!");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsSingletonFactory, nsIFactory)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSingletonFactory::CreateInstance(nsISupports* aOuter,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
|
|
|
|
|
|
|
return mSingleton->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSingletonFactory::LockFactory(bool)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set our windowcreator on the WindowWatcher service.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_IF_ADDREF(gNativeAppSupport = native);
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Inform the chrome registry about OS accessibility
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIToolkitChromeRegistry> cr =
|
|
|
|
mozilla::services::GetToolkitChromeRegistryService();
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cr)
|
|
|
|
cr->CheckForOSAccessibility();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowCreator> creator (do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
if (!creator) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowWatcher> wwatch
|
|
|
|
(do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return wwatch->SetWindowCreator(creator);
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
/* static */ nsresult
|
|
|
|
ScopedXPCOMStartup::CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
|
|
|
{
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
if (!gNativeAppSupport)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
return gNativeAppSupport->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINativeAppSupport* ScopedXPCOMStartup::gNativeAppSupport;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-05 19:00:53 -07:00
|
|
|
* A helper class which calls NS_LogInit/NS_LogTerm in its scope.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
class ScopedLogging
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScopedLogging() { NS_LogInit(); }
|
|
|
|
~ScopedLogging() { NS_LogTerm(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void DumpArbitraryHelp()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
ScopedLogging log;
|
|
|
|
|
|
|
|
{
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
xpcom.Initialize();
|
|
|
|
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdline
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
if (!cmdline)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCString text;
|
|
|
|
rv = cmdline->GetHelpText(text);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
printf("%s", text.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// English text needs to go into a dtd file.
|
|
|
|
// But when this is called we have no components etc. These strings must either be
|
|
|
|
// here, or in a native resource file.
|
|
|
|
static void
|
|
|
|
DumpHelp()
|
|
|
|
{
|
|
|
|
printf("Usage: %s [ options ... ] [URL]\n"
|
|
|
|
" where options include:\n\n", gArgv[0]);
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
printf("X11 options\n"
|
2009-10-09 03:50:42 -07:00
|
|
|
" --display=DISPLAY X display to use\n"
|
2011-03-31 01:40:25 -07:00
|
|
|
" --sync Make X calls synchronous\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_UNIX
|
2009-10-09 03:50:42 -07:00
|
|
|
printf(" --g-fatal-warnings Make all warnings fatal\n"
|
2008-08-29 14:12:52 -07:00
|
|
|
"\n%s options\n", gAppData->name);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2009-10-09 03:50:42 -07:00
|
|
|
printf(" -h or -help Print this message.\n"
|
|
|
|
" -v or -version Print %s version.\n"
|
|
|
|
" -P <profile> Start with <profile>.\n"
|
|
|
|
" -migration Start with migration wizard.\n"
|
|
|
|
" -ProfileManager Start with ProfileManager.\n"
|
2012-01-19 22:12:00 -08:00
|
|
|
" -no-remote Do not accept or send remote commands; implies -new-instance.\n"
|
|
|
|
" -new-instance Open new instance, not a new window in running instance.\n"
|
2009-10-09 03:50:42 -07:00
|
|
|
" -UILocale <locale> Start with <locale> resources as UI Locale.\n"
|
|
|
|
" -safe-mode Disables extensions and themes for this session.\n", gAppData->name);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2009-10-09 03:50:42 -07:00
|
|
|
printf(" -console Start %s with a debugging console.\n", gAppData->name);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// this works, but only after the components have registered. so if you drop in a new command line handler, -help
|
|
|
|
// won't not until the second run.
|
|
|
|
// out of the bug, because we ship a component.reg file, it works correctly.
|
|
|
|
DumpArbitraryHelp();
|
|
|
|
}
|
|
|
|
|
2012-08-27 12:12:32 -07:00
|
|
|
#if defined(DEBUG) && defined(XP_WIN)
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG_warren
|
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
#endif
|
2012-08-27 12:12:32 -07:00
|
|
|
// Set a CRT ReportHook function to capture and format MSCRT
|
|
|
|
// warnings, errors and assertions.
|
|
|
|
// See http://msdn.microsoft.com/en-US/library/74kabxyx(v=VS.80).aspx
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#include "mozilla/mozalloc_abort.h"
|
|
|
|
static int MSCRTReportHook( int aReportType, char *aMessage, int *oReturnValue)
|
|
|
|
{
|
|
|
|
*oReturnValue = 0; // continue execution
|
|
|
|
|
|
|
|
// Do not use fprintf or other functions which may allocate
|
|
|
|
// memory from the heap which may be corrupted. Instead,
|
|
|
|
// use fputs to output the leading portion of the message
|
|
|
|
// and use mozalloc_abort to emit the remainder of the
|
|
|
|
// message.
|
|
|
|
|
|
|
|
switch(aReportType) {
|
|
|
|
case 0:
|
|
|
|
fputs("\nWARNING: CRT WARNING", stderr);
|
|
|
|
fputs(aMessage, stderr);
|
|
|
|
fputs("\n", stderr);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fputs("\n###!!! ABORT: CRT ERROR ", stderr);
|
|
|
|
mozalloc_abort(aMessage);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fputs("\n###!!! ABORT: CRT ASSERT ", stderr);
|
|
|
|
mozalloc_abort(aMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do not invoke the debugger
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
DumpVersion()
|
|
|
|
{
|
2007-11-30 12:08:55 -08:00
|
|
|
printf("%s %s %s",
|
|
|
|
gAppData->vendor ? gAppData->vendor : "", gAppData->name, gAppData->version);
|
|
|
|
if (gAppData->copyright)
|
|
|
|
printf(", %s", gAppData->copyright);
|
|
|
|
printf("\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
// use int here instead of a PR type since it will be returned
|
|
|
|
// from main - just to keep types consistent
|
|
|
|
static int
|
|
|
|
HandleRemoteArgument(const char* remote, const char* aDesktopStartupID)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
|
|
|
|
const char *profile = 0;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString program(gAppData->name);
|
2007-03-22 10:30:00 -07:00
|
|
|
ToLowerCase(program);
|
|
|
|
const char *username = getenv("LOGNAME");
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("p", false, &profile);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -p requires a profile name\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *temp = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("a", false, &temp);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
|
|
|
return 1;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
program.Assign(temp);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("u", false, &username);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -u requires a username\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XRemoteClient client;
|
|
|
|
rv = client.Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: Failed to connect to X server.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLCString response;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = client.SendCommand(program.get(), username, profile, remote,
|
|
|
|
aDesktopStartupID, getter_Copies(response), &success);
|
|
|
|
// did the command fail?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: Failed to send command: %s\n",
|
|
|
|
response ? response.get() : "No response included");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: No running window found\n");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-19 22:09:07 -07:00
|
|
|
static RemoteResult
|
2007-03-22 10:30:00 -07:00
|
|
|
RemoteCommandLine(const char* aDesktopStartupID)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString program(gAppData->name);
|
2007-03-22 10:30:00 -07:00
|
|
|
ToLowerCase(program);
|
|
|
|
const char *username = getenv("LOGNAME");
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *temp = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("a", true, &temp);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
2007-08-19 22:09:07 -07:00
|
|
|
return REMOTE_ARG_BAD;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
program.Assign(temp);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("u", true, &username);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -u requires a username\n");
|
2007-08-19 22:09:07 -07:00
|
|
|
return REMOTE_ARG_BAD;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
XRemoteClient client;
|
|
|
|
rv = client.Init();
|
|
|
|
if (NS_FAILED(rv))
|
2007-08-19 22:09:07 -07:00
|
|
|
return REMOTE_NOT_FOUND;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXPIDLCString response;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool success = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = client.SendCommandLine(program.get(), username, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
gArgc, gArgv, aDesktopStartupID,
|
|
|
|
getter_Copies(response), &success);
|
|
|
|
// did the command fail?
|
|
|
|
if (NS_FAILED(rv) || !success)
|
2007-08-19 22:09:07 -07:00
|
|
|
return REMOTE_NOT_FOUND;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-19 22:09:07 -07:00
|
|
|
return REMOTE_FOUND;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif // MOZ_ENABLE_XREMOTE
|
|
|
|
|
2011-06-26 19:05:51 -07:00
|
|
|
void
|
2012-06-05 19:08:30 -07:00
|
|
|
XRE_InitOmnijar(nsIFile* greOmni, nsIFile* appOmni)
|
2011-06-26 19:05:51 -07:00
|
|
|
{
|
|
|
|
mozilla::Omnijar::Init(greOmni, appOmni);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2012-06-05 19:08:30 -07:00
|
|
|
XRE_GetBinaryPath(const char* argv0, nsIFile* *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-21 23:23:20 -07:00
|
|
|
return mozilla::BinaryPath::GetFile(argv0, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsWindowsRestart.cpp"
|
2009-01-01 16:18:33 -08:00
|
|
|
#include <shellapi.h>
|
2011-01-23 02:45:00 -08:00
|
|
|
|
|
|
|
typedef BOOL (WINAPI* SetProcessDEPPolicyFunc)(DWORD dwFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-10-11 04:49:03 -07:00
|
|
|
#if defined(XP_OS2) && (__KLIBC__ == 0 && __KLIBC_MINOR__ >= 6) // broken kLibc
|
2007-07-20 11:57:22 -07:00
|
|
|
// Copy the environment maintained by the C library into an ASCIIZ array
|
|
|
|
// that can be used to pass it on to the OS/2 Dos* APIs (which otherwise
|
|
|
|
// don't know anything about the stuff set by PR_SetEnv() or setenv()).
|
|
|
|
char *createEnv()
|
|
|
|
{
|
|
|
|
// just allocate the maximum amount (24 kB = 0x60000 bytes), to be able to
|
|
|
|
// copy the existing environment
|
|
|
|
char *env = (char *)calloc(0x6000, sizeof(char));
|
|
|
|
if (!env) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk along the environ string array of the C library and copy
|
|
|
|
// everything (that fits) into the output environment array, leaving
|
|
|
|
// null bytes between the entries
|
|
|
|
char *penv = env; // movable pointer to result environment ASCIIZ array
|
|
|
|
int i = 0, space = 0x6000;
|
|
|
|
while (environ[i] && environ[i][0]) {
|
|
|
|
int len = strlen(environ[i]);
|
|
|
|
if (space - len <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strcpy(penv, environ[i]);
|
|
|
|
i++; // next environment variable
|
|
|
|
penv += len + 1; // jump to after next null byte
|
|
|
|
space -= len - 1; // subtract consumed length from usable space
|
|
|
|
}
|
|
|
|
|
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OS2LaunchChild() is there to replace _execv() which is broken in the C
|
|
|
|
// runtime library that comes with GCC 3.3.5 on OS/2. It uses createEnv()
|
|
|
|
// to copy the process environment and add necessary variables
|
|
|
|
//
|
|
|
|
// returns -1 on failure and 0 on success
|
|
|
|
int OS2LaunchChild(const char *aExePath, int aArgc, char **aArgv)
|
|
|
|
{
|
|
|
|
// find total length of aArgv
|
|
|
|
int len = 0;
|
|
|
|
for (int i = 0; i < aArgc; i++) {
|
|
|
|
len += strlen(aArgv[i]) + 1; // plus space in between
|
|
|
|
}
|
|
|
|
len++; // leave space for null byte at end
|
|
|
|
// allocate enough space for all strings and nulls,
|
|
|
|
// calloc helpfully initializes to null
|
|
|
|
char *args = (char *)calloc(len, sizeof(char));
|
|
|
|
if (!args) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
char *pargs = args; // extra pointer to after the last argument
|
|
|
|
// build argument list in the format the DosStartSession() wants,
|
|
|
|
// adding spaces between the arguments
|
|
|
|
for (int i = 0; i < aArgc; i++, *pargs++ = ' ') {
|
|
|
|
strcpy(pargs, aArgv[i]);
|
|
|
|
pargs += strlen(aArgv[i]);
|
|
|
|
}
|
|
|
|
if (aArgc > 1) {
|
|
|
|
*(pargs-1) = '\0'; // replace last space
|
|
|
|
}
|
|
|
|
*pargs = '\0';
|
|
|
|
// make sure that the program is separated by null byte
|
|
|
|
pargs = strchr(args, ' ');
|
|
|
|
if (pargs) {
|
|
|
|
*pargs = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
char *env = createEnv();
|
|
|
|
|
|
|
|
char error[CCHMAXPATH] = { 0 };
|
|
|
|
RESULTCODES crc = { 0 };
|
|
|
|
ULONG rc = DosExecPgm(error, sizeof(error), EXEC_ASYNC, args, env,
|
|
|
|
&crc, (PSZ)aExePath);
|
|
|
|
free(args); // done with the arguments
|
|
|
|
if (env) {
|
|
|
|
free(env);
|
|
|
|
}
|
|
|
|
if (rc != NO_ERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If aBlankCommandLine is true, then the application will be launched with a
|
|
|
|
// blank command line instead of being launched with the same command line that
|
|
|
|
// it was initially started with.
|
|
|
|
static nsresult LaunchChild(nsINativeAppSupport* aNative,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aBlankCommandLine = false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aNative->Quit(); // release DDE mutex, if we're holding it
|
|
|
|
|
|
|
|
// Restart this process by exec'ing it into the current process
|
|
|
|
// if supported by the platform. Otherwise, use NSPR.
|
2011-08-12 08:59:20 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
// make sure JPROF doesn't think we're E10s
|
|
|
|
unsetenv("JPROF_SLAVE");
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aBlankCommandLine) {
|
2010-07-16 23:52:23 -07:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
// Remove only arguments not given to Qt
|
|
|
|
gRestartArgc = gQtOnlyArgc;
|
|
|
|
gRestartArgv = gQtOnlyArgv;
|
|
|
|
#else
|
2007-10-12 22:47:04 -07:00
|
|
|
gRestartArgc = 1;
|
2012-07-30 07:20:58 -07:00
|
|
|
gRestartArgv[gRestartArgc] = nullptr;
|
2010-07-16 23:52:23 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-19 01:29:18 -07:00
|
|
|
SaveToEnv("MOZ_LAUNCHED_CHILD=1");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-06-03 18:16:20 -07:00
|
|
|
mozilla::AndroidBridge::Bridge()->ScheduleRestart();
|
|
|
|
#else
|
2007-03-22 10:30:00 -07:00
|
|
|
#if defined(XP_MACOSX)
|
2011-10-17 07:59:28 -07:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, true);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t restartMode = 0;
|
2011-02-07 10:32:52 -08:00
|
|
|
restartMode = gRestartMode;
|
|
|
|
LaunchChildMac(gRestartArgc, gRestartArgv, restartMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-12-31 07:15:43 -08:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
nsAutoString exePath;
|
|
|
|
rv = lf->GetPath(exePath);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-01-01 16:18:33 -08:00
|
|
|
if (!WinLaunchChild(exePath.get(), gRestartArgc, gRestartArgv))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-31 07:15:43 -08:00
|
|
|
|
|
|
|
#else
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString exePath;
|
2007-12-31 07:15:43 -08:00
|
|
|
rv = lf->GetNativePath(exePath);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2008-10-11 04:49:03 -07:00
|
|
|
#if defined(XP_OS2) && (__KLIBC__ == 0 && __KLIBC_MINOR__ >= 6)
|
|
|
|
// implementation of _execv() is broken with kLibc 0.6.x and later
|
2007-07-20 11:57:22 -07:00
|
|
|
if (OS2LaunchChild(exePath.get(), gRestartArgc, gRestartArgv) == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_OS2)
|
|
|
|
if (_execv(exePath.get(), gRestartArgv) == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
if (execv(exePath.get(), gRestartArgv) == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#else
|
|
|
|
PRProcess* process = PR_CreateProcess(exePath.get(), gRestartArgv,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!process) return NS_ERROR_FAILURE;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t exitCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRStatus failed = PR_WaitProcess(process, &exitCode);
|
|
|
|
if (failed || exitCode)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-31 07:15:43 -08:00
|
|
|
#endif // XP_OS2 series
|
|
|
|
#endif // WP_WIN
|
|
|
|
#endif // WP_MACOSX
|
2011-11-10 16:17:46 -08:00
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_LAUNCHED_CHILD_PROCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char kProfileProperties[] =
|
|
|
|
"chrome://mozapps/locale/profile/profileSelection.properties";
|
|
|
|
|
|
|
|
static nsresult
|
2012-06-05 19:08:30 -07:00
|
|
|
ProfileLockedDialog(nsIFile* aProfileDir, nsIFile* aProfileLocalDir,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIProfileUnlocker* aUnlocker,
|
|
|
|
nsINativeAppSupport* aNative, nsIProfileLock* *aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-01-31 13:11:38 -08:00
|
|
|
mozilla::Telemetry::WriteFailedProfileLock(aProfileDir);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
rv = xpcom.SetWindowCreator(aNative);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
{ //extra scoping is needed so we release these components before xpcom shutdown
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(sbs, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> sb;
|
|
|
|
sbs->CreateBundle(kProfileProperties, getter_AddRefs(sb));
|
|
|
|
NS_ENSURE_TRUE_LOG(sbs, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 appName(gAppData->name);
|
|
|
|
const PRUnichar* params[] = {appName.get(), appName.get()};
|
|
|
|
|
|
|
|
nsXPIDLString killMessage;
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
static const PRUnichar kRestartNoUnlocker[] = {'r','e','s','t','a','r','t','M','e','s','s','a','g','e','N','o','U','n','l','o','c','k','e','r','\0'}; // "restartMessageNoUnlocker"
|
|
|
|
static const PRUnichar kRestartUnlocker[] = {'r','e','s','t','a','r','t','M','e','s','s','a','g','e','U','n','l','o','c','k','e','r','\0'}; // "restartMessageUnlocker"
|
|
|
|
#else
|
|
|
|
static const PRUnichar kRestartNoUnlocker[] = {'r','e','s','t','a','r','t','M','e','s','s','a','g','e','N','o','U','n','l','o','c','k','e','r','M','a','c','\0'}; // "restartMessageNoUnlockerMac"
|
|
|
|
static const PRUnichar kRestartUnlocker[] = {'r','e','s','t','a','r','t','M','e','s','s','a','g','e','U','n','l','o','c','k','e','r','M','a','c','\0'}; // "restartMessageUnlockerMac"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sb->FormatStringFromName(aUnlocker ? kRestartUnlocker : kRestartNoUnlocker,
|
|
|
|
params, 2, getter_Copies(killMessage));
|
|
|
|
|
|
|
|
nsXPIDLString killTitle;
|
|
|
|
sb->FormatStringFromName(NS_LITERAL_STRING("restartTitle").get(),
|
|
|
|
params, 1, getter_Copies(killTitle));
|
|
|
|
|
|
|
|
if (!killMessage || !killTitle)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPromptService> ps
|
|
|
|
(do_GetService(NS_PROMPTSERVICE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(ps, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (aUnlocker) {
|
2012-11-14 09:36:41 -08:00
|
|
|
int32_t button;
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
mozilla::AndroidBridge::Bridge()->KillAnyZombies();
|
|
|
|
button = 1;
|
|
|
|
#else
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t flags =
|
2011-08-26 06:03:26 -07:00
|
|
|
(nsIPromptService::BUTTON_TITLE_CANCEL *
|
|
|
|
nsIPromptService::BUTTON_POS_0) +
|
|
|
|
(nsIPromptService::BUTTON_TITLE_IS_STRING *
|
|
|
|
nsIPromptService::BUTTON_POS_1) +
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPromptService::BUTTON_POS_1_DEFAULT;
|
|
|
|
|
2011-08-26 06:03:26 -07:00
|
|
|
// The actual value is irrelevant but we shouldn't be handing out
|
|
|
|
// malformed JSBools to XPConnect.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool checkState = false;
|
2012-11-14 09:36:41 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = ps->ConfirmEx(nullptr, killTitle, killMessage, flags,
|
|
|
|
killTitle, nullptr, nullptr, nullptr,
|
2011-08-26 06:03:26 -07:00
|
|
|
&checkState, &button);
|
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2012-10-05 12:35:26 -07:00
|
|
|
#endif
|
2011-08-26 06:03:26 -07:00
|
|
|
|
|
|
|
if (button == 1) {
|
|
|
|
rv = aUnlocker->Unlock(nsIProfileUnlocker::FORCE_QUIT);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return NS_LockProfilePath(aProfileDir, aProfileLocalDir,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, aResult);
|
2011-08-26 06:03:26 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-10-05 12:35:26 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2012-10-18 10:54:42 -07:00
|
|
|
if (mozilla::AndroidBridge::Bridge()->UnlockProfile()) {
|
|
|
|
return NS_LockProfilePath(aProfileDir, aProfileLocalDir,
|
|
|
|
nullptr, aResult);
|
|
|
|
}
|
2012-10-05 12:35:26 -07:00
|
|
|
#else
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = ps->Alert(nullptr, killTitle, killMessage);
|
2011-08-26 06:03:26 -07:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2012-10-05 12:35:26 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
|
2010-03-06 07:40:33 -08:00
|
|
|
static nsresult
|
|
|
|
ProfileMissingDialog(nsINativeAppSupport* aNative)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
rv = xpcom.SetWindowCreator(aNative);
|
2010-03-06 07:40:33 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
{ //extra scoping is needed so we release these components before xpcom shutdown
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2010-03-06 07:40:33 -08:00
|
|
|
NS_ENSURE_TRUE(sbs, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> sb;
|
|
|
|
sbs->CreateBundle(kProfileProperties, getter_AddRefs(sb));
|
|
|
|
NS_ENSURE_TRUE_LOG(sbs, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 appName(gAppData->name);
|
|
|
|
const PRUnichar* params[] = {appName.get(), appName.get()};
|
|
|
|
|
|
|
|
nsXPIDLString missingMessage;
|
|
|
|
|
|
|
|
// profileMissing
|
|
|
|
static const PRUnichar kMissing[] = {'p','r','o','f','i','l','e','M','i','s','s','i','n','g','\0'};
|
|
|
|
sb->FormatStringFromName(kMissing, params, 2, getter_Copies(missingMessage));
|
|
|
|
|
|
|
|
nsXPIDLString missingTitle;
|
|
|
|
sb->FormatStringFromName(NS_LITERAL_STRING("profileMissingTitle").get(),
|
|
|
|
params, 1, getter_Copies(missingTitle));
|
|
|
|
|
|
|
|
if (missingMessage && missingTitle) {
|
|
|
|
nsCOMPtr<nsIPromptService> ps
|
|
|
|
(do_GetService(NS_PROMPTSERVICE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(ps, NS_ERROR_FAILURE);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
ps->Alert(nullptr, missingTitle, missingMessage);
|
2010-03-06 07:40:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
static nsresult
|
|
|
|
ProfileLockedDialog(nsIToolkitProfile* aProfile, nsIProfileUnlocker* aUnlocker,
|
|
|
|
nsINativeAppSupport* aNative, nsIProfileLock* *aResult)
|
|
|
|
{
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> profileDir;
|
2012-03-19 17:01:49 -07:00
|
|
|
nsresult rv = aProfile->GetRootDir(getter_AddRefs(profileDir));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
bool exists;
|
2012-07-10 11:53:19 -07:00
|
|
|
profileDir->Exists(&exists);
|
2012-03-19 17:01:49 -07:00
|
|
|
if (!exists) {
|
|
|
|
return ProfileMissingDialog(aNative);
|
|
|
|
}
|
|
|
|
|
2012-07-10 11:53:19 -07:00
|
|
|
nsCOMPtr<nsIFile> profileLocalDir;
|
|
|
|
rv = aProfile->GetLocalDir(getter_AddRefs(profileLocalDir));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
return ProfileLockedDialog(profileDir, profileLocalDir, aUnlocker, aNative,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const char kProfileManagerURL[] =
|
|
|
|
"chrome://mozapps/content/profile/profileSelection.xul";
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
ShowProfileManager(nsIToolkitProfileService* aProfileSvc,
|
|
|
|
nsINativeAppSupport* aNative)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> profD, profLD;
|
2007-06-29 22:02:49 -07:00
|
|
|
PRUnichar* profileNamePtr;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString profileName;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
rv = xpcom.SetWindowCreator(aNative);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2011-10-17 07:59:28 -07:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2008-06-20 17:21:21 -07:00
|
|
|
// we don't have to wait here because profile manager window will pump
|
|
|
|
// and DDE message will be handled
|
2011-10-17 07:59:28 -07:00
|
|
|
ProcessDDE(aNative, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
{ //extra scoping is needed so we release these components before xpcom shutdown
|
|
|
|
nsCOMPtr<nsIWindowWatcher> windowWatcher
|
|
|
|
(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
|
|
|
nsCOMPtr<nsIDialogParamBlock> ioParamBlock
|
|
|
|
(do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
|
|
|
|
nsCOMPtr<nsIMutableArray> dlgArray (do_CreateInstance(NS_ARRAY_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(windowWatcher && ioParamBlock && dlgArray, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
ioParamBlock->SetObjects(dlgArray);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAppStartup> appStartup
|
|
|
|
(do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> newWindow;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = windowWatcher->OpenWindow(nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
kProfileManagerURL,
|
|
|
|
"_blank",
|
|
|
|
"centerscreen,chrome,modal,titlebar",
|
|
|
|
ioParamBlock,
|
|
|
|
getter_AddRefs(newWindow));
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
|
|
|
|
|
|
|
aProfileSvc->Flush();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t dialogConfirmed;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = ioParamBlock->GetInt(0, &dialogConfirmed);
|
|
|
|
if (NS_FAILED(rv) || dialogConfirmed == 0) return NS_ERROR_ABORT;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProfileLock> lock;
|
|
|
|
rv = dlgArray->QueryElementAt(0, NS_GET_IID(nsIProfileLock),
|
|
|
|
getter_AddRefs(lock));
|
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
|
|
|
|
|
|
|
rv = lock->GetDirectory(getter_AddRefs(profD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = lock->GetLocalDirectory(getter_AddRefs(profLD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-06-29 22:02:49 -07:00
|
|
|
rv = ioParamBlock->GetString(0, &profileNamePtr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
CopyUTF16toUTF8(profileNamePtr, profileName);
|
|
|
|
NS_Free(profileNamePtr);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
lock->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveFileToEnv("XRE_PROFILE_PATH", profD);
|
|
|
|
SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", profLD);
|
2007-06-29 22:02:49 -07:00
|
|
|
SaveWordToEnv("XRE_PROFILE_NAME", profileName);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool offline = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
aProfileSvc->GetStartOffline(&offline);
|
|
|
|
if (offline) {
|
2010-04-19 01:29:18 -07:00
|
|
|
SaveToEnv("XRE_START_OFFLINE=1");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return LaunchChild(aNative);
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
static nsresult
|
2012-03-19 17:01:49 -07:00
|
|
|
GetCurrentProfileIsDefault(nsIToolkitProfileService* aProfileSvc,
|
2012-06-05 19:08:30 -07:00
|
|
|
nsIFile* aCurrentProfileRoot, bool *aResult)
|
2012-02-23 19:34:18 -08:00
|
|
|
{
|
2012-03-19 17:01:49 -07:00
|
|
|
nsresult rv;
|
|
|
|
// Check that the profile to reset is the default since reset and the associated migration are
|
|
|
|
// only supported in that case.
|
|
|
|
nsCOMPtr<nsIToolkitProfile> selectedProfile;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> selectedProfileRoot;
|
2012-03-19 17:01:49 -07:00
|
|
|
rv = aProfileSvc->GetSelectedProfile(getter_AddRefs(selectedProfile));
|
2012-02-23 19:34:18 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
rv = selectedProfile->GetRootDir(getter_AddRefs(selectedProfileRoot));
|
2012-02-23 19:34:18 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
bool currentIsSelected;
|
|
|
|
rv = aCurrentProfileRoot->Equals(selectedProfileRoot, ¤tIsSelected);
|
2012-02-23 19:34:18 -08:00
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
*aResult = currentIsSelected;
|
|
|
|
return rv;
|
2012-02-23 19:34:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the currently running profile as the default/selected one.
|
|
|
|
*
|
|
|
|
* @param aCurrentProfileRoot The root directory of the current profile.
|
|
|
|
* @return an error if aCurrentProfileRoot is not found or the profile could not
|
|
|
|
* be set as the default.
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
SetCurrentProfileAsDefault(nsIToolkitProfileService* aProfileSvc,
|
2012-06-05 19:08:30 -07:00
|
|
|
nsIFile* aCurrentProfileRoot)
|
2012-02-23 19:34:18 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aProfileSvc);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> profiles;
|
|
|
|
nsresult rv = aProfileSvc->GetProfiles(getter_AddRefs(profiles));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
bool foundMatchingProfile = false;
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
rv = profiles->GetNext(getter_AddRefs(profile));
|
|
|
|
while (NS_SUCCEEDED(rv)) {
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> profileRoot;
|
2012-02-23 19:34:18 -08:00
|
|
|
profile->GetRootDir(getter_AddRefs(profileRoot));
|
|
|
|
profileRoot->Equals(aCurrentProfileRoot, &foundMatchingProfile);
|
|
|
|
if (foundMatchingProfile && profile) {
|
|
|
|
rv = aProfileSvc->SetSelectedProfile(profile);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = aProfileSvc->Flush();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = profiles->GetNext(getter_AddRefs(profile));
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
static bool gDoMigration = false;
|
|
|
|
static bool gDoProfileReset = false;
|
|
|
|
|
|
|
|
// Pick a profile. We need to end up with a profile lock.
|
|
|
|
//
|
|
|
|
// 1) check for -profile <path>
|
|
|
|
// 2) check for -P <name>
|
|
|
|
// 3) check for -ProfileManager
|
|
|
|
// 4) use the default profile, if there is one
|
|
|
|
// 5) if there are *no* profiles, set up profile-migration
|
|
|
|
// 6) display the profile-manager UI
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult
|
2012-02-23 19:34:18 -08:00
|
|
|
SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, nsINativeAppSupport* aNative,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aStartOffline, nsACString* aProfileName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
const char* arg;
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
*aStartOffline = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("offline", true);
|
2007-07-10 22:59:56 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -offline is invalid when argument -osint is specified\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-03-23 10:28:18 -07:00
|
|
|
if (ar || EnvHasValue("XRE_START_OFFLINE"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*aStartOffline = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
if (EnvHasValue("MOZ_RESET_PROFILE_RESTART")) {
|
|
|
|
gDoProfileReset = true;
|
|
|
|
gDoMigration = true;
|
|
|
|
SaveToEnv("MOZ_RESET_PROFILE_RESTART=");
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset-profile and migration args need to be checked before any profiles are chosen below.
|
|
|
|
ar = CheckArg("reset-profile", true);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -reset-profile is invalid when argument -osint is specified\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
gDoProfileReset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ar = CheckArg("migration", true);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -migration is invalid when argument -osint is specified\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
gDoMigration = true;
|
|
|
|
}
|
2007-07-10 22:59:56 -07:00
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> lf = GetFileFromEnv("XRE_PROFILE_PATH");
|
2007-12-31 07:15:43 -08:00
|
|
|
if (lf) {
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> localDir =
|
2007-12-31 07:15:43 -08:00
|
|
|
GetFileFromEnv("XRE_PROFILE_LOCAL_PATH");
|
|
|
|
if (!localDir) {
|
2007-03-22 10:30:00 -07:00
|
|
|
localDir = lf;
|
|
|
|
}
|
|
|
|
|
2007-06-29 22:02:49 -07:00
|
|
|
arg = PR_GetEnv("XRE_PROFILE_NAME");
|
|
|
|
if (arg && *arg && aProfileName)
|
|
|
|
aProfileName->Assign(nsDependentCString(arg));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Clear out flags that we handled (or should have handled!) last startup.
|
|
|
|
const char *dummy;
|
2011-10-17 07:59:28 -07:00
|
|
|
CheckArg("p", false, &dummy);
|
|
|
|
CheckArg("profile", false, &dummy);
|
2007-03-22 10:30:00 -07:00
|
|
|
CheckArg("profilemanager");
|
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
if (gDoProfileReset) {
|
2012-03-19 17:01:49 -07:00
|
|
|
// Check that the profile to reset is the default since reset and migration are only
|
|
|
|
// supported in that case.
|
|
|
|
bool currentIsSelected;
|
|
|
|
GetCurrentProfileIsDefault(aProfileSvc, lf, ¤tIsSelected);
|
|
|
|
if (!currentIsSelected) {
|
|
|
|
NS_WARNING("Profile reset is only supported for the default profile.");
|
|
|
|
gDoProfileReset = gDoMigration = false;
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
// If we're resetting a profile, create a new one and use it to startup.
|
|
|
|
nsCOMPtr<nsIToolkitProfile> newProfile;
|
2012-03-19 17:01:49 -07:00
|
|
|
rv = CreateResetProfile(aProfileSvc, getter_AddRefs(newProfile));
|
2012-02-23 19:34:18 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = newProfile->GetRootDir(getter_AddRefs(lf));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
SaveFileToEnv("XRE_PROFILE_PATH", lf);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
rv = newProfile->GetLocalDir(getter_AddRefs(localDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", localDir);
|
|
|
|
|
|
|
|
rv = newProfile->GetName(*aProfileName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aProfileName->Truncate(0);
|
|
|
|
SaveWordToEnv("XRE_PROFILE_NAME", *aProfileName);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Profile reset failed.");
|
|
|
|
gDoProfileReset = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return NS_LockProfilePath(lf, localDir, nullptr, aResult);
|
2007-07-10 22:59:56 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("profile", true, &arg);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -profile requires a path\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (ar) {
|
2012-02-23 19:34:18 -08:00
|
|
|
if (gDoProfileReset) {
|
|
|
|
NS_WARNING("Profile reset is only supported for the default profile.");
|
|
|
|
gDoProfileReset = false;
|
|
|
|
}
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = XRE_GetFileFromPath(arg, getter_AddRefs(lf));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
|
2009-12-02 11:00:56 -08:00
|
|
|
// Check if the profile path exists and it's a directory.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool exists;
|
2009-12-02 11:00:56 -08:00
|
|
|
lf->Exists(&exists);
|
|
|
|
if (!exists) {
|
2010-09-09 19:08:25 -07:00
|
|
|
rv = lf->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2009-12-02 11:00:56 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If a profile path is specified directory on the command line, then
|
|
|
|
// assume that the temp directory is the same as the given directory.
|
|
|
|
rv = NS_LockProfilePath(lf, lf, getter_AddRefs(unlocker), aResult);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return ProfileLockedDialog(lf, lf, unlocker, aNative, aResult);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("createprofile", true, &arg);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -createprofile requires a profile name\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (ar) {
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
|
|
|
|
const char* delim = strchr(arg, ' ');
|
|
|
|
if (delim) {
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(delim + 1),
|
2011-10-17 07:59:28 -07:00
|
|
|
true, getter_AddRefs(lf));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: profile path not valid.\n");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// As with -profile, assume that the given path will be used for both the
|
|
|
|
// main profile directory and the temp profile directory.
|
2012-02-23 19:34:18 -08:00
|
|
|
rv = aProfileSvc->CreateProfile(lf, lf, nsDependentCSubstring(arg, delim),
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = aProfileSvc->CreateProfile(nullptr, nullptr, nsDependentCString(arg),
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
}
|
|
|
|
// Some pathological arguments can make it this far
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error creating profile.\n");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = NS_ERROR_ABORT;
|
2012-02-23 19:34:18 -08:00
|
|
|
aProfileSvc->Flush();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXXben need to ensure prefs.js exists here so the tinderboxes will
|
|
|
|
// not go orange.
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> prefsJSFile;
|
2007-03-22 10:30:00 -07:00
|
|
|
profile->GetRootDir(getter_AddRefs(prefsJSFile));
|
|
|
|
prefsJSFile->AppendNative(NS_LITERAL_CSTRING("prefs.js"));
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString pathStr;
|
2007-04-25 19:56:25 -07:00
|
|
|
prefsJSFile->GetNativePath(pathStr);
|
|
|
|
PR_fprintf(PR_STDERR, "Success: created profile '%s' at '%s'\n", arg, pathStr.get());
|
2011-09-28 23:19:26 -07:00
|
|
|
bool exists;
|
2007-03-22 10:30:00 -07:00
|
|
|
prefsJSFile->Exists(&exists);
|
|
|
|
if (!exists)
|
|
|
|
prefsJSFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
|
|
|
// XXXdarin perhaps 0600 would be better?
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
2012-02-23 19:34:18 -08:00
|
|
|
rv = aProfileSvc->GetProfileCount(&count);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("p", false, &arg);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ar == ARG_BAD) {
|
2007-07-10 22:59:56 -07:00
|
|
|
ar = CheckArg("osint");
|
|
|
|
if (ar == ARG_FOUND) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -p is invalid when argument -osint is specified\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-02-23 19:34:18 -08:00
|
|
|
return ShowProfileManager(aProfileSvc, aNative);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (ar) {
|
2007-07-10 22:59:56 -07:00
|
|
|
ar = CheckArg("osint");
|
|
|
|
if (ar == ARG_FOUND) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -p is invalid when argument -osint is specified\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
2012-02-23 19:34:18 -08:00
|
|
|
rv = aProfileSvc->GetProfileByName(nsDependentCString(arg),
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-02-23 19:34:18 -08:00
|
|
|
if (gDoProfileReset) {
|
|
|
|
NS_WARNING("Profile reset is only supported for the default profile.");
|
|
|
|
gDoProfileReset = false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
2012-10-05 17:58:29 -07:00
|
|
|
rv = profile->Lock(getter_AddRefs(unlocker), aResult);
|
2007-06-29 22:02:49 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aProfileName)
|
|
|
|
aProfileName->Assign(nsDependentCString(arg));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2007-06-29 22:02:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
return ProfileLockedDialog(profile, unlocker, aNative, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
return ShowProfileManager(aProfileSvc, aNative);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("profilemanager", true);
|
2007-07-10 22:59:56 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -profilemanager is invalid when argument -osint is specified\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
2012-02-23 19:34:18 -08:00
|
|
|
return ShowProfileManager(aProfileSvc, aNative);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!count) {
|
2011-10-17 07:59:28 -07:00
|
|
|
gDoMigration = true;
|
2012-02-23 19:34:18 -08:00
|
|
|
gDoProfileReset = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// create a default profile
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = aProfileSvc->CreateProfile(nullptr, // choose a default dir for us
|
|
|
|
nullptr, // choose a default dir for us
|
2012-02-23 19:34:18 -08:00
|
|
|
NS_LITERAL_CSTRING("default"),
|
|
|
|
getter_AddRefs(profile));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-02-23 19:34:18 -08:00
|
|
|
aProfileSvc->Flush();
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = profile->Lock(nullptr, aResult);
|
2007-06-29 22:02:49 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aProfileName)
|
|
|
|
aProfileName->Assign(NS_LITERAL_CSTRING("default"));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2007-06-29 22:02:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool useDefault = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (count > 1)
|
2012-02-23 19:34:18 -08:00
|
|
|
aProfileSvc->GetStartWithLastProfile(&useDefault);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (useDefault) {
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
// GetSelectedProfile will auto-select the only profile if there's just one
|
2012-02-23 19:34:18 -08:00
|
|
|
aProfileSvc->GetSelectedProfile(getter_AddRefs(profile));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (profile) {
|
2012-02-23 19:34:18 -08:00
|
|
|
// If we're resetting a profile, create a new one and use it to startup.
|
|
|
|
if (gDoProfileReset) {
|
2012-03-19 17:01:49 -07:00
|
|
|
{
|
|
|
|
// Check that the source profile is not in use by temporarily acquiring its lock.
|
|
|
|
nsIProfileLock* tempProfileLock;
|
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
rv = profile->Lock(getter_AddRefs(unlocker), &tempProfileLock);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return ProfileLockedDialog(profile, unlocker, aNative, &tempProfileLock);
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
nsCOMPtr<nsIToolkitProfile> newProfile;
|
2012-03-19 17:01:49 -07:00
|
|
|
rv = CreateResetProfile(aProfileSvc, getter_AddRefs(newProfile));
|
2012-02-23 19:34:18 -08:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
profile = newProfile;
|
|
|
|
else
|
|
|
|
gDoProfileReset = false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
rv = profile->Lock(getter_AddRefs(unlocker), aResult);
|
2007-06-29 22:02:49 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Try to grab the profile name.
|
|
|
|
if (aProfileName) {
|
|
|
|
rv = profile->GetName(*aProfileName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aProfileName->Truncate(0);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2007-06-29 22:02:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
return ProfileLockedDialog(profile, unlocker, aNative, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:34:18 -08:00
|
|
|
return ShowProfileManager(aProfileSvc, aNative);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-10-15 23:32:29 -07:00
|
|
|
/**
|
|
|
|
* Checks the compatibility.ini file to see if we have updated our application
|
|
|
|
* or otherwise invalidated our caches. If the application has been updated,
|
2011-10-17 07:59:28 -07:00
|
|
|
* we return false; otherwise, we return true. We also write the status
|
2009-10-15 23:32:29 -07:00
|
|
|
* of the caches (valid/invalid) into the return param aCachesOK. The aCachesOK
|
|
|
|
* is always invalid if the application has been updated.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
CheckCompatibility(nsIFile* aProfileDir, const nsCString& aVersion,
|
|
|
|
const nsCString& aOSABI, nsIFile* aXULRunnerDir,
|
2012-06-05 19:08:30 -07:00
|
|
|
nsIFile* aAppDir, nsIFile* aFlagFile,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCachesOK)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aCachesOK = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
file->AppendNative(FILE_COMPATIBILITY_INFO);
|
|
|
|
|
|
|
|
nsINIParser parser;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult rv = parser.Init(file);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buf;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = parser.GetString("Compatibility", "LastVersion", buf);
|
|
|
|
if (NS_FAILED(rv) || !aVersion.Equals(buf))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = parser.GetString("Compatibility", "LastOSABI", buf);
|
|
|
|
if (NS_FAILED(rv) || !aOSABI.Equals(buf))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = parser.GetString("Compatibility", "LastPlatformDir", buf);
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = NS_NewNativeLocalFile(buf, false,
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool eq;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = lf->Equals(aXULRunnerDir, &eq);
|
|
|
|
if (NS_FAILED(rv) || !eq)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aAppDir) {
|
|
|
|
rv = parser.GetString("Compatibility", "LastAppDir", buf);
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = NS_NewNativeLocalFile(buf, false,
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = lf->Equals(aAppDir, &eq);
|
|
|
|
if (NS_FAILED(rv) || !eq)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-10-15 23:32:29 -07:00
|
|
|
// If we see this flag, caches are invalid.
|
2010-07-02 16:59:17 -07:00
|
|
|
rv = parser.GetString("Compatibility", "InvalidateCaches", buf);
|
2009-10-15 23:32:29 -07:00
|
|
|
*aCachesOK = (NS_FAILED(rv) || !buf.EqualsLiteral("1"));
|
2010-07-02 16:59:17 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool purgeCaches = false;
|
2010-07-02 16:59:17 -07:00
|
|
|
if (aFlagFile) {
|
|
|
|
aFlagFile->Exists(&purgeCaches);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aCachesOK = !purgeCaches && *aCachesOK;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BuildVersion(nsCString &aBuf)
|
|
|
|
{
|
|
|
|
aBuf.Assign(gAppData->version);
|
|
|
|
aBuf.Append('_');
|
|
|
|
aBuf.Append(gAppData->buildID);
|
|
|
|
aBuf.Append('/');
|
2007-07-02 11:20:24 -07:00
|
|
|
aBuf.Append(gToolkitBuildID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
WriteVersion(nsIFile* aProfileDir, const nsCString& aVersion,
|
|
|
|
const nsCString& aOSABI, nsIFile* aXULRunnerDir,
|
2012-10-23 09:46:51 -07:00
|
|
|
nsIFile* aAppDir, bool invalidateCache)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
file->AppendNative(FILE_COMPATIBILITY_INFO);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString platformDir;
|
2007-03-22 10:30:00 -07:00
|
|
|
aXULRunnerDir->GetNativePath(platformDir);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString appDir;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aAppDir)
|
|
|
|
aAppDir->GetNativePath(appDir);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
PRFileDesc *fd = nullptr;
|
2012-06-05 19:08:30 -07:00
|
|
|
file->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0600, &fd);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!fd) {
|
|
|
|
NS_ERROR("could not create output stream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char kHeader[] = "[Compatibility]" NS_LINEBREAK
|
|
|
|
"LastVersion=";
|
|
|
|
|
|
|
|
PR_Write(fd, kHeader, sizeof(kHeader) - 1);
|
|
|
|
PR_Write(fd, aVersion.get(), aVersion.Length());
|
|
|
|
|
|
|
|
static const char kOSABIHeader[] = NS_LINEBREAK "LastOSABI=";
|
|
|
|
PR_Write(fd, kOSABIHeader, sizeof(kOSABIHeader) - 1);
|
|
|
|
PR_Write(fd, aOSABI.get(), aOSABI.Length());
|
|
|
|
|
|
|
|
static const char kPlatformDirHeader[] = NS_LINEBREAK "LastPlatformDir=";
|
|
|
|
|
|
|
|
PR_Write(fd, kPlatformDirHeader, sizeof(kPlatformDirHeader) - 1);
|
|
|
|
PR_Write(fd, platformDir.get(), platformDir.Length());
|
|
|
|
|
|
|
|
static const char kAppDirHeader[] = NS_LINEBREAK "LastAppDir=";
|
|
|
|
if (aAppDir) {
|
|
|
|
PR_Write(fd, kAppDirHeader, sizeof(kAppDirHeader) - 1);
|
|
|
|
PR_Write(fd, appDir.get(), appDir.Length());
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:46:51 -07:00
|
|
|
static const char kInvalidationHeader[] = "InvalidateCaches=1" NS_LINEBREAK;
|
|
|
|
if (invalidateCache)
|
|
|
|
PR_Write(fd, kInvalidationHeader, sizeof(kInvalidationHeader) - 1);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const char kNL[] = NS_LINEBREAK;
|
|
|
|
PR_Write(fd, kNL, sizeof(kNL) - 1);
|
|
|
|
|
|
|
|
PR_Close(fd);
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:46:51 -07:00
|
|
|
/**
|
|
|
|
* Returns true if the startup cache file was successfully removed.
|
|
|
|
* Returns false if file->Clone fails at any point (OOM) or if unable
|
|
|
|
* to remove the startup cache file. Note in particular the return value
|
|
|
|
* is unaffected by a failure to remove extensions.ini
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
RemoveComponentRegistries(nsIFile* aProfileDir, nsIFile* aLocalProfileDir,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRemoveEMFiles)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
2012-10-23 09:46:51 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aRemoveEMFiles) {
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("extensions.ini"));
|
2011-10-17 07:59:28 -07:00
|
|
|
file->Remove(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
aLocalProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
2012-10-23 09:46:51 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-17 15:53:52 -07:00
|
|
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
|
|
|
#define PLATFORM_FASL_SUFFIX ".mfasl"
|
|
|
|
#elif defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
#define PLATFORM_FASL_SUFFIX ".mfl"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("XUL" PLATFORM_FASL_SUFFIX));
|
2011-10-17 07:59:28 -07:00
|
|
|
file->Remove(false);
|
2009-10-15 23:32:29 -07:00
|
|
|
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("XPC" PLATFORM_FASL_SUFFIX));
|
2011-10-17 07:59:28 -07:00
|
|
|
file->Remove(false);
|
2010-08-12 12:37:44 -07:00
|
|
|
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("startupCache"));
|
2012-10-23 09:46:51 -07:00
|
|
|
nsresult rv = file->Remove(true);
|
|
|
|
return NS_SUCCEEDED(rv) || rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-12 22:47:04 -07:00
|
|
|
// To support application initiated restart via nsIAppStartup.quit, we
|
|
|
|
// need to save various environment variables, and then restore them
|
|
|
|
// before re-launching the application.
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
static struct SavedVar {
|
2007-10-12 22:47:04 -07:00
|
|
|
const char *name;
|
|
|
|
char *value;
|
|
|
|
} gSavedVars[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{"XUL_APP_FILE", nullptr}
|
2007-10-12 22:47:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void SaveStateForAppInitiatedRestart()
|
|
|
|
{
|
2011-10-10 22:50:08 -07:00
|
|
|
for (size_t i = 0; i < ArrayLength(gSavedVars); ++i) {
|
2007-10-12 22:47:04 -07:00
|
|
|
const char *s = PR_GetEnv(gSavedVars[i].name);
|
|
|
|
if (s)
|
|
|
|
gSavedVars[i].value = PR_smprintf("%s=%s", gSavedVars[i].name, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RestoreStateForAppInitiatedRestart()
|
|
|
|
{
|
2011-10-10 22:50:08 -07:00
|
|
|
for (size_t i = 0; i < ArrayLength(gSavedVars); ++i) {
|
2007-10-12 22:47:04 -07:00
|
|
|
if (gSavedVars[i].value)
|
|
|
|
PR_SetEnv(gSavedVars[i].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
// When we first initialize the crash reporter we don't have a profile,
|
2007-03-22 10:30:00 -07:00
|
|
|
// so we set the minidump path to $TEMP. Once we have a profile,
|
|
|
|
// we set it to $PROFILE/minidumps, creating the directory
|
|
|
|
// if needed.
|
|
|
|
static void MakeOrSetMinidumpPath(nsIFile* profD)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> dumpD;
|
2013-03-17 08:04:57 -07:00
|
|
|
profD->Clone(getter_AddRefs(dumpD));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if(dumpD) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool fileExists;
|
2007-03-22 10:30:00 -07:00
|
|
|
//XXX: do some more error checking here
|
|
|
|
dumpD->Append(NS_LITERAL_STRING("minidumps"));
|
2013-03-17 08:04:57 -07:00
|
|
|
dumpD->Exists(&fileExists);
|
2007-03-22 10:30:00 -07:00
|
|
|
if(!fileExists) {
|
|
|
|
dumpD->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString pathStr;
|
|
|
|
if(NS_SUCCEEDED(dumpD->GetPath(pathStr)))
|
2007-03-27 11:02:02 -07:00
|
|
|
CrashReporter::SetMinidumpPath(pathStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsXREAppData* gAppData = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if defined(XP_OS2)
|
|
|
|
// because we use early returns, we use a stack-based helper to un-set the OS2 FP handler
|
|
|
|
class ScopedFPHandler {
|
|
|
|
private:
|
|
|
|
EXCEPTIONREGISTRATIONRECORD excpreg;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScopedFPHandler() { PR_OS2_SetFloatExcpHandler(&excpreg); }
|
|
|
|
~ScopedFPHandler() { PR_OS2_UnsetFloatExcpHandler(&excpreg); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prlink.h"
|
|
|
|
typedef void (*_g_set_application_name_fn)(const gchar *application_name);
|
|
|
|
typedef void (*_gtk_window_set_auto_startup_notification_fn)(gboolean setting);
|
|
|
|
|
|
|
|
static PRFuncPtr FindFunction(const char* aName)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
PRLibrary *lib = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRFuncPtr result = PR_FindFunctionSymbolAndLibrary(aName, &lib);
|
|
|
|
// Since the library was already loaded, we can safely unload it here.
|
|
|
|
if (lib) {
|
|
|
|
PR_UnloadLibrary(lib);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-10-03 14:44:05 -07:00
|
|
|
static void MOZ_gdk_display_close(GdkDisplay *display)
|
|
|
|
{
|
2008-04-08 23:42:49 -07:00
|
|
|
// XXX wallpaper for bug 417163: don't close the Display if we're using the
|
|
|
|
// Qt theme because we crash (in Qt code) when using jemalloc.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool theme_is_qt = false;
|
2008-04-08 23:42:49 -07:00
|
|
|
GtkSettings* settings =
|
|
|
|
gtk_settings_get_for_screen(gdk_display_get_default_screen(display));
|
|
|
|
gchar *theme_name;
|
|
|
|
g_object_get(settings, "gtk-theme-name", &theme_name, NULL);
|
|
|
|
if (theme_name) {
|
|
|
|
theme_is_qt = strcmp(theme_name, "Qt") == 0;
|
|
|
|
if (theme_is_qt)
|
|
|
|
NS_WARNING("wallpaper bug 417163 for Qt theme");
|
|
|
|
g_free(theme_name);
|
|
|
|
}
|
|
|
|
|
2008-09-25 15:38:25 -07:00
|
|
|
#if CLEANUP_MEMORY
|
2013-05-30 05:10:02 -07:00
|
|
|
// Get a (new) Pango context that holds a reference to the fontmap that
|
|
|
|
// GTK has been using. gdk_pango_context_get() must be called while GTK
|
|
|
|
// has a default display.
|
|
|
|
PangoContext *pangoContext = gdk_pango_context_get();
|
2008-09-25 15:38:25 -07:00
|
|
|
#endif
|
|
|
|
|
2013-05-30 05:10:02 -07:00
|
|
|
bool buggyCairoShutdown = cairo_version() < CAIRO_VERSION_ENCODE(1, 4, 0);
|
2009-01-26 08:21:46 -08:00
|
|
|
|
2013-05-30 05:10:02 -07:00
|
|
|
if (!buggyCairoShutdown) {
|
|
|
|
// We should shut down GDK before we shut down libraries it depends on
|
|
|
|
// like Pango and cairo. But if cairo shutdown is buggy, we should
|
|
|
|
// shut down cairo first otherwise it may crash because of dangling
|
|
|
|
// references to Display objects (see bug 469831).
|
|
|
|
if (!theme_is_qt)
|
|
|
|
gdk_display_close(display);
|
|
|
|
}
|
2008-09-25 15:38:25 -07:00
|
|
|
|
|
|
|
#if CLEANUP_MEMORY
|
2013-05-30 05:10:02 -07:00
|
|
|
// This doesn't take a reference.
|
|
|
|
PangoFontMap *fontmap = pango_context_get_font_map(pangoContext);
|
|
|
|
// Do some shutdown of the fontmap, which releases the fonts, clearing a
|
|
|
|
// bunch of circular references from the fontmap through the fonts back to
|
|
|
|
// itself. The shutdown that this does is much less than what's done by
|
|
|
|
// the fontmap's finalize, though.
|
|
|
|
if (PANGO_IS_FC_FONT_MAP(fontmap))
|
|
|
|
pango_fc_font_map_shutdown(PANGO_FC_FONT_MAP(fontmap));
|
|
|
|
g_object_unref(pangoContext);
|
|
|
|
// PangoCairo still holds a reference to the fontmap.
|
|
|
|
// Now that we have finished with GTK and Pango, we could unref fontmap,
|
|
|
|
// which would allow us to call FcFini, but removing what is really
|
|
|
|
// Pango's ref feels a bit evil. Pango-1.22 will have support for
|
|
|
|
// pango_cairo_font_map_set_default(NULL), which would release the
|
|
|
|
// reference on the old fontmap.
|
|
|
|
|
|
|
|
// cairo_debug_reset_static_data() is prototyped through cairo.h included
|
|
|
|
// by gtk.h.
|
2008-09-25 15:38:25 -07:00
|
|
|
#ifdef cairo_debug_reset_static_data
|
|
|
|
#error "Looks like we're including Mozilla's cairo instead of system cairo"
|
2008-02-11 22:47:40 -08:00
|
|
|
#endif
|
2013-05-30 05:10:02 -07:00
|
|
|
cairo_debug_reset_static_data();
|
2008-09-25 15:38:25 -07:00
|
|
|
#endif // CLEANUP_MEMORY
|
2009-01-26 08:21:46 -08:00
|
|
|
|
2013-05-30 05:10:02 -07:00
|
|
|
if (buggyCairoShutdown) {
|
|
|
|
if (!theme_is_qt)
|
|
|
|
gdk_display_close(display);
|
2007-10-03 14:44:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_GTK2
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NSPR will search for the "nspr_use_zone_allocator" symbol throughout
|
|
|
|
* the process and use it to determine whether the application defines its own
|
|
|
|
* memory allocator or not.
|
|
|
|
*
|
|
|
|
* Since most applications (e.g. Firefox and Thunderbird) don't use any special
|
|
|
|
* allocators and therefore don't define this symbol, NSPR must search the
|
|
|
|
* entire process, which reduces startup performance.
|
|
|
|
*
|
|
|
|
* By defining the symbol here, we can avoid the wasted lookup and hopefully
|
|
|
|
* improve startup performance.
|
|
|
|
*/
|
2012-10-25 09:32:24 -07:00
|
|
|
NS_VISIBILITY_DEFAULT PRBool nspr_use_zone_allocator = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-23 02:45:00 -08:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2011-01-21 08:44:33 -08:00
|
|
|
|
|
|
|
#include <dwrite.h>
|
|
|
|
|
|
|
|
typedef HRESULT (WINAPI*DWriteCreateFactoryFunc)(
|
2011-07-12 02:17:20 -07:00
|
|
|
DWRITE_FACTORY_TYPE factoryType,
|
|
|
|
REFIID iid,
|
|
|
|
IUnknown **factory
|
2011-01-21 08:44:33 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
#ifdef DEBUG_DWRITE_STARTUP
|
|
|
|
|
|
|
|
#define LOGREGISTRY(msg) LogRegistryEvent(msg)
|
|
|
|
|
|
|
|
// for use when monitoring process
|
|
|
|
static void LogRegistryEvent(const wchar_t *msg)
|
|
|
|
{
|
|
|
|
HKEY dummyKey;
|
|
|
|
HRESULT hr;
|
|
|
|
wchar_t buf[512];
|
|
|
|
|
|
|
|
wsprintf(buf, L" log %s", msg);
|
|
|
|
hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, buf, 0, KEY_READ, &dummyKey);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
RegCloseKey(dummyKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define LOGREGISTRY(msg)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static DWORD InitDwriteBG(LPVOID lpdwThreadParam)
|
|
|
|
{
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN);
|
|
|
|
LOGREGISTRY(L"loading dwrite.dll");
|
|
|
|
HMODULE dwdll = LoadLibraryW(L"dwrite.dll");
|
2011-02-28 01:55:14 -08:00
|
|
|
if (dwdll) {
|
|
|
|
DWriteCreateFactoryFunc createDWriteFactory = (DWriteCreateFactoryFunc)
|
|
|
|
GetProcAddress(dwdll, "DWriteCreateFactory");
|
|
|
|
if (createDWriteFactory) {
|
|
|
|
LOGREGISTRY(L"creating dwrite factory");
|
|
|
|
IDWriteFactory *factory;
|
|
|
|
HRESULT hr = createDWriteFactory(
|
|
|
|
DWRITE_FACTORY_TYPE_SHARED,
|
|
|
|
__uuidof(IDWriteFactory),
|
|
|
|
reinterpret_cast<IUnknown**>(&factory));
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
LOGREGISTRY(L"dwrite factory done");
|
|
|
|
factory->Release();
|
|
|
|
LOGREGISTRY(L"freed factory");
|
|
|
|
} else {
|
|
|
|
LOGREGISTRY(L"failed to create factory");
|
|
|
|
}
|
|
|
|
}
|
2011-01-21 08:44:33 -08:00
|
|
|
}
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-17 07:17:45 -07:00
|
|
|
#endif
|
|
|
|
|
2012-04-11 14:55:22 -07:00
|
|
|
#ifdef USE_GLX_TEST
|
2011-06-10 12:07:54 -07:00
|
|
|
bool fire_glxtest_process();
|
2011-05-03 13:07:17 -07:00
|
|
|
#endif
|
|
|
|
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2011-08-26 17:05:37 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Encapsulates startup and shutdown state for XRE_main
|
|
|
|
class XREMain
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XREMain() :
|
2012-07-30 07:20:58 -07:00
|
|
|
mScopedXPCom(nullptr)
|
|
|
|
, mAppData(nullptr)
|
2012-03-27 06:37:35 -07:00
|
|
|
, mStartOffline(false)
|
|
|
|
, mShuttingDown(false)
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
, mDisableRemote(false)
|
|
|
|
#endif
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mGdkDisplay(nullptr)
|
2012-03-27 06:37:35 -07:00
|
|
|
#endif
|
|
|
|
{};
|
|
|
|
|
|
|
|
~XREMain() {
|
|
|
|
if (mAppData) {
|
|
|
|
delete mAppData;
|
|
|
|
}
|
|
|
|
if (mScopedXPCom) {
|
|
|
|
NS_WARNING("Scoped xpcom should have been deleted!");
|
|
|
|
delete mScopedXPCom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int XRE_main(int argc, char* argv[], const nsXREAppData* aAppData);
|
2013-03-27 08:19:10 -07:00
|
|
|
int XRE_mainInit(bool* aExitFlag);
|
2012-03-27 06:37:35 -07:00
|
|
|
int XRE_mainStartup(bool* aExitFlag);
|
|
|
|
nsresult XRE_mainRun();
|
|
|
|
|
|
|
|
nsCOMPtr<nsINativeAppSupport> mNativeApp;
|
|
|
|
nsCOMPtr<nsIToolkitProfileService> mProfileSvc;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> mProfD;
|
|
|
|
nsCOMPtr<nsIFile> mProfLD;
|
2012-03-27 06:37:35 -07:00
|
|
|
nsCOMPtr<nsIProfileLock> mProfileLock;
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
nsCOMPtr<nsIRemoteService> mRemoteService;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ScopedXPCOMStartup* mScopedXPCom;
|
|
|
|
ScopedAppData* mAppData;
|
|
|
|
nsXREDirProvider mDirProvider;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString mProfileName;
|
|
|
|
nsAutoCString mDesktopStartupID;
|
2012-03-27 06:37:35 -07:00
|
|
|
|
|
|
|
bool mStartOffline;
|
|
|
|
bool mShuttingDown;
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
bool mDisableRemote;
|
|
|
|
#endif
|
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2012-03-27 06:37:35 -07:00
|
|
|
GdkDisplay* mGdkDisplay;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XRE_mainInit - Initial setup and command line parameter processing.
|
|
|
|
* Main() will exit early if either return value != 0 or if aExitFlag is
|
|
|
|
* true.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
int
|
2013-03-27 08:19:10 -07:00
|
|
|
XREMain::XRE_mainInit(bool* aExitFlag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!aExitFlag)
|
|
|
|
return 1;
|
|
|
|
*aExitFlag = false;
|
2010-04-26 11:13:03 -07:00
|
|
|
|
2011-11-17 23:54:27 -08:00
|
|
|
StartupTimeline::Record(StartupTimeline::MAIN);
|
2011-01-13 12:18:51 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
2007-07-10 22:59:56 -07:00
|
|
|
ArgResult ar;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (PR_GetEnv("XRE_MAIN_BREAK"))
|
|
|
|
NS_BREAK();
|
|
|
|
#endif
|
|
|
|
|
2012-04-11 14:55:22 -07:00
|
|
|
#ifdef USE_GLX_TEST
|
2012-03-27 06:37:35 -07:00
|
|
|
// bug 639842 - it's very important to fire this process BEFORE we set up
|
|
|
|
// error handling. indeed, this process is expected to be crashy, and we
|
|
|
|
// don't want the user to see its crashes. That's the whole reason for
|
|
|
|
// doing this in a separate process.
|
|
|
|
if (fire_glxtest_process()) {
|
|
|
|
*aExitFlag = true;
|
2011-06-10 12:07:54 -07:00
|
|
|
return 0;
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2011-05-03 13:07:17 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
SetupErrorHandling(gArgv[0]);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-23 02:45:00 -08:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2012-03-27 06:37:35 -07:00
|
|
|
{
|
|
|
|
// Bug 602792 - when DWriteCreateFactory is called the dwrite client dll
|
|
|
|
// starts the FntCache service if it isn't already running (it's set
|
|
|
|
// to manual startup by default in Windows 7 RTM). Subsequent DirectWrite
|
|
|
|
// calls cause the IDWriteFactory object to communicate with the FntCache
|
|
|
|
// service with a timeout; if there's no response after the timeout, the
|
|
|
|
// DirectWrite client library will assume the service isn't around and do
|
|
|
|
// manual font file I/O on _all_ system fonts. To avoid this, load the
|
|
|
|
// dwrite library and create a factory as early as possible so that the
|
|
|
|
// FntCache service is ready by the time it's needed.
|
2011-01-21 08:44:33 -08:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
OSVERSIONINFO vinfo;
|
|
|
|
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
|
|
|
|
if (GetVersionEx(&vinfo) && vinfo.dwMajorVersion >= 6) {
|
|
|
|
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&InitDwriteBG, NULL, 0, NULL);
|
|
|
|
}
|
2011-01-21 08:44:33 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-29 00:19:50 -07:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
const char *home = PR_GetEnv("HOME");
|
|
|
|
if (!home || !*home) {
|
|
|
|
struct passwd *pw = getpwuid(geteuid());
|
|
|
|
if (!pw || !pw->pw_dir) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Could not determine HOME directory");
|
2010-04-29 00:19:50 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
SaveWordToEnv("HOME", nsDependentCString(pw->pw_dir));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-15 06:18:45 -08:00
|
|
|
#ifdef MOZ_ACCESSIBILITY_ATK
|
|
|
|
// Reset GTK_MODULES, strip atk-bridge if exists
|
|
|
|
// Mozilla will load libatk-bridge.so later if necessary
|
|
|
|
const char* gtkModules = PR_GetEnv("GTK_MODULES");
|
|
|
|
if (gtkModules && *gtkModules) {
|
|
|
|
nsCString gtkModulesStr(gtkModules);
|
|
|
|
gtkModulesStr.ReplaceSubstring("atk-bridge", "");
|
|
|
|
char* expr = PR_smprintf("GTK_MODULES=%s", gtkModulesStr.get());
|
|
|
|
if (expr)
|
|
|
|
PR_SetEnv(expr);
|
|
|
|
// We intentionally leak |expr| here since it is required by PR_SetEnv.
|
|
|
|
}
|
2008-12-21 22:46:30 -08:00
|
|
|
|
|
|
|
// Suppress atk-bridge init at startup, it works after GNOME 2.24.2
|
2011-03-23 10:28:18 -07:00
|
|
|
SaveToEnv("NO_AT_BRIDGE=1");
|
2008-12-15 06:18:45 -08:00
|
|
|
#endif
|
|
|
|
|
2007-12-19 03:23:22 -08:00
|
|
|
// Check for application.ini overrides
|
2012-07-30 07:20:58 -07:00
|
|
|
const char* override = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("override", true, &override);
|
2007-12-19 03:23:22 -08:00
|
|
|
if (ar == ARG_BAD) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Incorrect number of arguments passed to -override");
|
2007-12-19 03:23:22 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (ar == ARG_FOUND) {
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> overrideLF;
|
2007-12-19 03:23:22 -08:00
|
|
|
rv = XRE_GetFileFromPath(override, getter_AddRefs(overrideLF));
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Error: unrecognized override.ini path.\n");
|
2007-12-19 03:23:22 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-03-27 08:19:10 -07:00
|
|
|
rv = XRE_ParseAppData(overrideLF, mAppData);
|
2007-12-19 03:23:22 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Couldn't read override.ini");
|
2007-12-19 03:23:22 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check sanity and correctness of app data.
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mAppData->name) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Error: App:Name not specified in application.ini\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mAppData->buildID) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Error: App:BuildID not specified in application.ini\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// XXX Originally ScopedLogging was here? Now it's in XRE_main above
|
|
|
|
// XRE_mainInit.
|
2007-06-26 12:22:51 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mAppData->xreDirectory) {
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> lf;
|
2007-06-26 12:22:51 -07:00
|
|
|
rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> greDir;
|
|
|
|
rv = lf->GetParent(getter_AddRefs(greDir));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 2;
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = CallQueryInterface(greDir, &mAppData->xreDirectory);
|
2007-06-26 12:22:51 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mAppData->directory) {
|
|
|
|
NS_IF_ADDREF(mAppData->directory = mAppData->xreDirectory);
|
2011-11-21 23:05:59 -08:00
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (mAppData->size > offsetof(nsXREAppData, minVersion)) {
|
|
|
|
if (!mAppData->minVersion) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Error: Gecko:MinVersion not specified in application.ini\n");
|
2007-07-02 11:20:24 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mAppData->maxVersion) {
|
2007-07-02 11:20:24 -07:00
|
|
|
// If no maxVersion is specified, we assume the app is only compatible
|
|
|
|
// with the initial preview release. Do not increment this number ever!
|
2012-03-27 06:37:35 -07:00
|
|
|
SetAllocatedString(mAppData->maxVersion, "1.*");
|
2007-07-02 11:20:24 -07:00
|
|
|
}
|
|
|
|
|
2012-04-18 20:22:29 -07:00
|
|
|
if (mozilla::Version(mAppData->minVersion) > gToolkitVersion ||
|
|
|
|
mozilla::Version(mAppData->maxVersion) < gToolkitVersion) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Output(true, "Error: Platform version '%s' is not compatible with\n"
|
2007-07-02 11:20:24 -07:00
|
|
|
"minVersion >= %s\nmaxVersion <= %s\n",
|
|
|
|
gToolkitVersion,
|
2012-03-27 06:37:35 -07:00
|
|
|
mAppData->minVersion, mAppData->maxVersion);
|
2007-07-02 11:20:24 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = mDirProvider.Initialize(mAppData->directory, mAppData->xreDirectory);
|
2010-05-21 10:58:32 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 1;
|
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2011-03-23 10:28:18 -07:00
|
|
|
if (EnvHasValue("MOZ_CRASHREPORTER")) {
|
2012-03-27 06:37:35 -07:00
|
|
|
mAppData->flags |= NS_XRE_ENABLE_CRASH_REPORTER;
|
2007-05-22 13:20:55 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if ((mAppData->flags & NS_XRE_ENABLE_CRASH_REPORTER) &&
|
2007-05-22 13:20:55 -07:00
|
|
|
NS_SUCCEEDED(
|
2012-03-27 06:37:35 -07:00
|
|
|
CrashReporter::SetExceptionHandler(mAppData->xreDirectory))) {
|
|
|
|
if (mAppData->crashReporterURL)
|
|
|
|
CrashReporter::SetServerURL(nsDependentCString(mAppData->crashReporterURL));
|
2009-09-30 07:07:50 -07:00
|
|
|
|
2007-05-22 13:20:55 -07:00
|
|
|
// pass some basic info from the app data
|
2012-03-27 06:37:35 -07:00
|
|
|
if (mAppData->vendor)
|
2007-05-22 13:20:55 -07:00
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Vendor"),
|
2012-03-27 06:37:35 -07:00
|
|
|
nsDependentCString(mAppData->vendor));
|
|
|
|
if (mAppData->name)
|
2007-05-22 13:20:55 -07:00
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ProductName"),
|
2012-03-27 06:37:35 -07:00
|
|
|
nsDependentCString(mAppData->name));
|
|
|
|
if (mAppData->ID)
|
2011-12-01 19:24:10 -08:00
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ProductID"),
|
2012-03-27 06:37:35 -07:00
|
|
|
nsDependentCString(mAppData->ID));
|
|
|
|
if (mAppData->version)
|
2007-05-22 13:20:55 -07:00
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Version"),
|
2012-03-27 06:37:35 -07:00
|
|
|
nsDependentCString(mAppData->version));
|
|
|
|
if (mAppData->buildID)
|
2007-05-22 13:20:55 -07:00
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("BuildID"),
|
2012-03-27 06:37:35 -07:00
|
|
|
nsDependentCString(mAppData->buildID));
|
2011-11-22 13:46:57 -08:00
|
|
|
|
|
|
|
nsDependentCString releaseChannel(NS_STRINGIFY(MOZ_UPDATE_CHANNEL));
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ReleaseChannel"),
|
|
|
|
releaseChannel);
|
2012-03-27 06:37:35 -07:00
|
|
|
CrashReporter::SetRestartArgs(gArgc, gArgv);
|
2007-07-16 10:07:20 -07:00
|
|
|
|
|
|
|
// annotate other data (user id etc)
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> userAppDataDir;
|
2012-03-27 06:37:35 -07:00
|
|
|
if (NS_SUCCEEDED(mDirProvider.GetUserAppDataDirectory(
|
2008-01-26 08:49:29 -08:00
|
|
|
getter_AddRefs(userAppDataDir)))) {
|
2007-07-17 08:02:29 -07:00
|
|
|
CrashReporter::SetupExtraData(userAppDataDir,
|
2012-03-27 06:37:35 -07:00
|
|
|
nsDependentCString(mAppData->buildID));
|
2008-01-26 08:49:29 -08:00
|
|
|
|
|
|
|
// see if we have a crashreporter-override.ini in the application directory
|
|
|
|
nsCOMPtr<nsIFile> overrideini;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool exists;
|
2012-03-27 06:37:35 -07:00
|
|
|
if (NS_SUCCEEDED(mDirProvider.GetAppDir()->Clone(getter_AddRefs(overrideini))) &&
|
2008-01-26 08:49:29 -08:00
|
|
|
NS_SUCCEEDED(overrideini->AppendNative(NS_LITERAL_CSTRING("crashreporter-override.ini"))) &&
|
|
|
|
NS_SUCCEEDED(overrideini->Exists(&exists)) &&
|
|
|
|
exists) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsAutoString overridePathW;
|
|
|
|
overrideini->GetPath(overridePathW);
|
|
|
|
NS_ConvertUTF16toUTF8 overridePath(overridePathW);
|
|
|
|
#else
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString overridePath;
|
2008-01-26 08:49:29 -08:00
|
|
|
overrideini->GetNativePath(overridePath);
|
|
|
|
#endif
|
|
|
|
|
2011-06-27 06:31:04 -07:00
|
|
|
SaveWordToEnv("MOZ_CRASHREPORTER_STRINGS_OVERRIDE", overridePath);
|
2008-01-26 08:49:29 -08:00
|
|
|
}
|
2007-07-16 10:07:20 -07:00
|
|
|
}
|
2007-05-22 13:20:55 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2011-03-23 10:28:18 -07:00
|
|
|
if (EnvHasValue("MOZ_LAUNCHED_CHILD")) {
|
2007-05-16 19:10:19 -07:00
|
|
|
// This is needed, on relaunch, to force the OS to use the "Cocoa Dock
|
|
|
|
// API". Otherwise the call to ReceiveNextEvent() below will make it
|
|
|
|
// use the "Carbon Dock API". For more info see bmo bug 377166.
|
|
|
|
EnsureUseCocoaDockAPI();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// When the app relaunches, the original process exits. This causes
|
|
|
|
// the dock tile to stop bouncing, lose the "running" triangle, and
|
|
|
|
// if the tile does not permanently reside in the Dock, even disappear.
|
|
|
|
// This can be confusing to the user, who is expecting the app to launch.
|
|
|
|
// Calling ReceiveNextEvent without requesting any event is enough to
|
|
|
|
// cause a dock tile for the child process to appear.
|
|
|
|
const EventTypeSpec kFakeEventList[] = { { INT_MAX, INT_MAX } };
|
|
|
|
EventRef event;
|
|
|
|
::ReceiveNextEvent(GetEventTypeCount(kFakeEventList), kFakeEventList,
|
2011-10-17 07:59:28 -07:00
|
|
|
kEventDurationNoWait, false, &event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckArg("foreground")) {
|
|
|
|
// The original process communicates that it was in the foreground by
|
|
|
|
// adding this argument. This new process, which is taking over for
|
|
|
|
// the old one, should make itself the active application.
|
|
|
|
ProcessSerialNumber psn;
|
|
|
|
if (::GetCurrentProcess(&psn) == noErr)
|
|
|
|
::SetFrontProcess(&psn);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-19 01:29:18 -07:00
|
|
|
SaveToEnv("MOZ_LAUNCHED_CHILD=");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gRestartArgc = gArgc;
|
2008-08-16 08:19:43 -07:00
|
|
|
gRestartArgv = (char**) malloc(sizeof(char*) * (gArgc + 1 + (override ? 2 : 0)));
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!gRestartArgv) {
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-12 22:47:04 -07:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < gArgc; ++i) {
|
|
|
|
gRestartArgv[i] = gArgv[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-08-16 08:19:43 -07:00
|
|
|
|
|
|
|
// Add the -override argument back (it is removed automatically be CheckArg) if there is one
|
|
|
|
if (override) {
|
|
|
|
gRestartArgv[gRestartArgc++] = const_cast<char*>("-override");
|
|
|
|
gRestartArgv[gRestartArgc++] = const_cast<char*>(override);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gRestartArgv[gRestartArgc] = nullptr;
|
2008-08-16 08:19:43 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if defined(XP_OS2)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool StartOS2App(int aArgc, char **aArgv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!StartOS2App(gArgc, gArgv))
|
|
|
|
return 1;
|
|
|
|
ScopedFPHandler handler;
|
|
|
|
#endif /* XP_OS2 */
|
|
|
|
|
2011-03-23 10:28:18 -07:00
|
|
|
if (EnvHasValue("MOZ_SAFE_MODE_RESTART")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
gSafeMode = true;
|
2010-09-21 19:36:53 -07:00
|
|
|
// unset the env variable
|
2011-03-23 10:28:18 -07:00
|
|
|
SaveToEnv("MOZ_SAFE_MODE_RESTART=");
|
2010-09-21 19:36:53 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("safe-mode", true);
|
2007-07-10 22:59:56 -07:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -safe-mode is invalid when argument -osint is specified\n");
|
|
|
|
return 1;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
2011-10-17 07:59:28 -07:00
|
|
|
gSafeMode = true;
|
2007-07-10 22:59:56 -07:00
|
|
|
}
|
|
|
|
|
2010-11-18 17:20:05 -08:00
|
|
|
#ifdef XP_WIN
|
2010-12-21 16:32:14 -08:00
|
|
|
// If the shift key is pressed and the ctrl and / or alt keys are not pressed
|
|
|
|
// during startup start in safe mode. GetKeyState returns a short and the high
|
|
|
|
// order bit will be 1 if the key is pressed. By masking the returned short
|
|
|
|
// with 0x8000 the result will be 0 if the key is not pressed and non-zero
|
|
|
|
// otherwise.
|
|
|
|
if (GetKeyState(VK_SHIFT) & 0x8000 &&
|
|
|
|
!(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
gSafeMode = true;
|
2010-12-21 16:32:14 -08:00
|
|
|
}
|
2010-11-18 17:20:05 -08:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2008-03-04 09:58:52 -08:00
|
|
|
if (GetCurrentEventKeyModifiers() & optionKey)
|
2011-10-17 07:59:28 -07:00
|
|
|
gSafeMode = true;
|
2007-07-10 22:59:56 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-19 22:12:00 -08:00
|
|
|
// Handle -no-remote and -new-instance command line arguments. Setup
|
|
|
|
// the environment to better accommodate other components and various
|
|
|
|
// restart scenarios.
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("no-remote", true);
|
2007-07-10 22:59:56 -07:00
|
|
|
if (ar == ARG_BAD) {
|
2012-01-19 22:12:00 -08:00
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -no-remote is invalid when argument -osint is specified\n");
|
2007-07-10 22:59:56 -07:00
|
|
|
return 1;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
2010-04-19 01:29:18 -07:00
|
|
|
SaveToEnv("MOZ_NO_REMOTE=1");
|
2007-07-10 22:59:56 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
|
2012-01-19 22:12:00 -08:00
|
|
|
ar = CheckArg("new-instance", true);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -new-instance is invalid when argument -osint is specified\n");
|
|
|
|
return 1;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
SaveToEnv("MOZ_NEW_INSTANCE=1");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Handle -help and -version command line arguments.
|
|
|
|
// They should return quickly, so we deal with them here.
|
|
|
|
if (CheckArg("h") || CheckArg("help") || CheckArg("?")) {
|
|
|
|
DumpHelp();
|
2012-03-27 06:37:35 -07:00
|
|
|
*aExitFlag = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckArg("v") || CheckArg("version")) {
|
|
|
|
DumpVersion();
|
2012-03-27 06:37:35 -07:00
|
|
|
*aExitFlag = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_TRACE_MALLOC
|
2012-03-27 06:37:35 -07:00
|
|
|
gArgc = NS_TraceMallocStartupArgs(gArgc, gArgv);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2009-11-03 21:12:18 -08:00
|
|
|
rv = XRE_InitCommandLine(gArgc, gArgv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Check for -register, which registers chrome and then exits immediately.
|
|
|
|
ar = CheckArg("register", true);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -register is invalid when argument -osint is specified\n");
|
|
|
|
return 1;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChromeRegistry> chromeReg =
|
|
|
|
mozilla::services::GetChromeRegistryService();
|
|
|
|
NS_ENSURE_TRUE(chromeReg, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
chromeReg->CheckForNewChrome();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
*aExitFlag = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 11:47:40 -07:00
|
|
|
if (PR_GetEnv("MOZ_RUN_GTEST")) {
|
|
|
|
int result;
|
|
|
|
// RunGTest will only be set if we're in xul-unit
|
|
|
|
if (mozilla::RunGTest) {
|
|
|
|
result = mozilla::RunGTest();
|
|
|
|
} else {
|
|
|
|
result = 1;
|
|
|
|
printf("TEST-UNEXPECTED-FAIL | gtest | Not compiled with enable-tests\n");
|
|
|
|
}
|
2012-05-22 13:45:24 -07:00
|
|
|
*aExitFlag = true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-11 09:05:59 -08:00
|
|
|
namespace mozilla {
|
2013-02-12 11:43:52 -08:00
|
|
|
ShutdownChecksMode gShutdownChecks = SCM_NOTHING;
|
2013-02-11 09:05:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetShutdownChecks() {
|
|
|
|
// Set default first. On debug builds we crash. On nightly and local
|
|
|
|
// builds we record. Nightlies will then send the info via telemetry,
|
|
|
|
// but it is usefull to have the data in about:telemetry in local builds
|
|
|
|
// too.
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-02-12 11:43:52 -08:00
|
|
|
gShutdownChecks = SCM_CRASH;
|
2013-02-11 09:05:59 -08:00
|
|
|
#else
|
|
|
|
const char* releaseChannel = NS_STRINGIFY(MOZ_UPDATE_CHANNEL);
|
|
|
|
if (strcmp(releaseChannel, "nightly") == 0 ||
|
|
|
|
strcmp(releaseChannel, "default") == 0) {
|
2013-02-12 11:43:52 -08:00
|
|
|
gShutdownChecks = SCM_RECORD;
|
2013-02-11 09:05:59 -08:00
|
|
|
} else {
|
2013-02-12 11:43:52 -08:00
|
|
|
gShutdownChecks = SCM_NOTHING;
|
2013-02-11 09:05:59 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// We let an environment variable override the default so that addons
|
|
|
|
// authors can use it for debugging shutdown with released firefox versions.
|
|
|
|
const char* mozShutdownChecksEnv = PR_GetEnv("MOZ_SHUTDOWN_CHECKS");
|
|
|
|
if (mozShutdownChecksEnv) {
|
|
|
|
if (strcmp(mozShutdownChecksEnv, "crash") == 0) {
|
2013-02-12 11:43:52 -08:00
|
|
|
gShutdownChecks = SCM_CRASH;
|
2013-02-11 09:05:59 -08:00
|
|
|
} else if (strcmp(mozShutdownChecksEnv, "record") == 0) {
|
2013-02-12 11:43:52 -08:00
|
|
|
gShutdownChecks = SCM_RECORD;
|
2013-02-11 09:05:59 -08:00
|
|
|
} else if (strcmp(mozShutdownChecksEnv, "nothing") == 0) {
|
2013-02-12 11:43:52 -08:00
|
|
|
gShutdownChecks = SCM_NOTHING;
|
2013-02-11 09:05:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
/*
|
|
|
|
* XRE_mainStartup - Initializes the profile and various other services.
|
|
|
|
* Main() will exit early if either return value != 0 or if aExitFlag is
|
|
|
|
* true.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
XREMain::XRE_mainStartup(bool* aExitFlag)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!aExitFlag)
|
|
|
|
return 1;
|
|
|
|
*aExitFlag = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-11 09:05:59 -08:00
|
|
|
SetShutdownChecks();
|
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK) || defined(MOZ_ENABLE_XREMOTE)
|
2012-03-27 06:37:35 -07:00
|
|
|
// Stash DESKTOP_STARTUP_ID in malloc'ed memory because gtk_init will clear it.
|
2007-03-22 10:30:00 -07:00
|
|
|
#define HAVE_DESKTOP_STARTUP_ID
|
2012-03-27 06:37:35 -07:00
|
|
|
const char* desktopStartupIDEnv = PR_GetEnv("DESKTOP_STARTUP_ID");
|
|
|
|
if (desktopStartupIDEnv) {
|
|
|
|
mDesktopStartupID.Assign(desktopStartupIDEnv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-04-19 06:21:59 -07:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
2012-03-27 06:37:35 -07:00
|
|
|
nsQAppInstance::AddRef(gArgc, gArgv, true);
|
2010-08-03 10:44:46 -07:00
|
|
|
|
2010-08-30 16:40:14 -07:00
|
|
|
#if MOZ_PLATFORM_MAEMO > 5
|
2012-03-27 06:37:35 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
// try to get the MInputContext if possible to support the MeeGo VKB
|
|
|
|
QInputContext* inputContext = qApp->inputContext();
|
|
|
|
if (inputContext && inputContext->identifierName() != "MInputContext") {
|
|
|
|
QInputContext* context = QInputContextFactory::create("MInputContext",
|
|
|
|
qApp);
|
|
|
|
if (context)
|
|
|
|
qApp->setInputContext(context);
|
2010-08-03 11:33:12 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2010-08-30 16:40:14 -07:00
|
|
|
#endif
|
2012-03-27 06:37:35 -07:00
|
|
|
QStringList nonQtArguments = qApp->arguments();
|
|
|
|
gQtOnlyArgc = 1;
|
|
|
|
gQtOnlyArgv = (char**) malloc(sizeof(char*)
|
|
|
|
* (gRestartArgc - nonQtArguments.size() + 2));
|
2010-07-16 23:52:23 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// copy binary path
|
|
|
|
gQtOnlyArgv[0] = gRestartArgv[0];
|
2010-07-16 23:52:23 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
for (int i = 1; i < gRestartArgc; ++i) {
|
|
|
|
if (!nonQtArguments.contains(gRestartArgv[i])) {
|
|
|
|
// copy arguments used by Qt for later
|
|
|
|
gQtOnlyArgv[gQtOnlyArgc++] = gRestartArgv[i];
|
2010-07-16 23:52:23 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
gQtOnlyArgv[gQtOnlyArgc] = nullptr;
|
2008-04-19 06:21:59 -07:00
|
|
|
#endif
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2012-03-27 06:37:35 -07:00
|
|
|
// setup for private colormap. Ideally we'd like to do this
|
|
|
|
// in nsAppShell::Create, but we need to get in before gtk
|
|
|
|
// has been initialized to make sure everything is running
|
|
|
|
// consistently.
|
2012-06-15 23:06:10 -07:00
|
|
|
#if (MOZ_WIDGET_GTK == 2)
|
2012-03-27 06:37:35 -07:00
|
|
|
if (CheckArg("install"))
|
|
|
|
gdk_rgb_set_install(TRUE);
|
2012-06-15 23:06:10 -07:00
|
|
|
#endif
|
2012-03-27 06:37:35 -07:00
|
|
|
|
2012-08-09 07:34:26 -07:00
|
|
|
// Set program name to the one defined in application.ini.
|
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString program(gAppData->name);
|
2012-08-09 07:34:26 -07:00
|
|
|
ToLowerCase(program);
|
|
|
|
g_set_prgname(program.get());
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Initialize GTK here for splash.
|
|
|
|
|
|
|
|
// Open the display ourselves instead of using gtk_init, so that we can
|
|
|
|
// close it without fear that one day gtk might clean up the display it
|
|
|
|
// opens.
|
|
|
|
if (!gtk_parse_args(&gArgc, &gArgv))
|
|
|
|
return 1;
|
2007-09-27 14:14:11 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// display_name is owned by gdk.
|
|
|
|
const char *display_name = gdk_get_display_arg_name();
|
|
|
|
if (display_name) {
|
|
|
|
SaveWordToEnv("DISPLAY", nsDependentCString(display_name));
|
|
|
|
} else {
|
|
|
|
display_name = PR_GetEnv("DISPLAY");
|
|
|
|
if (!display_name) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: no display specified\n");
|
|
|
|
return 1;
|
2007-09-27 14:14:11 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2008-08-16 08:18:43 -07:00
|
|
|
#endif /* MOZ_WIDGET_GTK2 */
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2012-03-27 06:37:35 -07:00
|
|
|
// handle -remote now that xpcom is fired up
|
|
|
|
bool newInstance;
|
|
|
|
{
|
|
|
|
char *e = PR_GetEnv("MOZ_NO_REMOTE");
|
|
|
|
mDisableRemote = (e && *e);
|
|
|
|
if (mDisableRemote) {
|
|
|
|
newInstance = true;
|
|
|
|
} else {
|
|
|
|
e = PR_GetEnv("MOZ_NEW_INSTANCE");
|
|
|
|
newInstance = (e && *e);
|
2011-08-24 10:56:57 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2008-08-16 08:18:43 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
const char* xremotearg;
|
|
|
|
ArgResult ar = CheckArg("remote", true, &xremotearg);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: -remote requires an argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const char* desktopStartupIDPtr =
|
2012-07-30 07:20:58 -07:00
|
|
|
mDesktopStartupID.IsEmpty() ? nullptr : mDesktopStartupID.get();
|
2012-03-27 06:37:35 -07:00
|
|
|
if (ar) {
|
|
|
|
*aExitFlag = true;
|
|
|
|
return HandleRemoteArgument(xremotearg, desktopStartupIDPtr);
|
|
|
|
}
|
2008-08-16 08:18:43 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!newInstance) {
|
|
|
|
// Try to remote the entire command line. If this fails, start up normally.
|
|
|
|
RemoteResult rr = RemoteCommandLine(desktopStartupIDPtr);
|
|
|
|
if (rr == REMOTE_FOUND) {
|
|
|
|
*aExitFlag = true;
|
|
|
|
return 0;
|
2008-08-16 08:18:43 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
else if (rr == REMOTE_ARG_BAD)
|
|
|
|
return 1;
|
|
|
|
}
|
2008-08-16 08:18:43 -07:00
|
|
|
#endif
|
2012-05-22 08:34:34 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// Init X11 in thread-safe mode. Must be called prior to the first call to XOpenDisplay
|
|
|
|
// (called inside gdk_display_open). This is a requirement for off main tread compositing.
|
|
|
|
// This is done only on X11 platforms if the environment variable MOZ_USE_OMTC is set so
|
|
|
|
// as to avoid overhead when omtc is not used.
|
|
|
|
// An environment variable is used instead of a pref on X11 platforms because we start having
|
|
|
|
// access to prefs long after the first call to XOpenDisplay which is hard to change due to
|
|
|
|
// interdependencies in the initialization.
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
if (PR_GetEnv("MOZ_USE_OMTC") ||
|
|
|
|
PR_GetEnv("MOZ_OMTC_ENABLED")) {
|
2012-05-22 08:34:34 -07:00
|
|
|
XInitThreads();
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2012-03-27 06:37:35 -07:00
|
|
|
mGdkDisplay = gdk_display_open(display_name);
|
|
|
|
if (!mGdkDisplay) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
gdk_display_manager_set_default_display (gdk_display_manager_get(),
|
|
|
|
mGdkDisplay);
|
2007-09-27 14:14:11 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// g_set_application_name () is only defined in glib2.2 and higher.
|
|
|
|
_g_set_application_name_fn _g_set_application_name =
|
|
|
|
(_g_set_application_name_fn)FindFunction("g_set_application_name");
|
|
|
|
if (_g_set_application_name) {
|
|
|
|
_g_set_application_name(mAppData->name);
|
|
|
|
}
|
|
|
|
_gtk_window_set_auto_startup_notification_fn _gtk_window_set_auto_startup_notification =
|
|
|
|
(_gtk_window_set_auto_startup_notification_fn)FindFunction("gtk_window_set_auto_startup_notification");
|
|
|
|
if (_gtk_window_set_auto_startup_notification) {
|
|
|
|
_gtk_window_set_auto_startup_notification(false);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if (MOZ_WIDGET_GTK == 2)
|
2012-03-27 06:37:35 -07:00
|
|
|
gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
|
2012-06-15 23:06:10 -07:00
|
|
|
#endif /* (MOZ_WIDGET_GTK == 2) */
|
|
|
|
#endif /* defined(MOZ_WIDGET_GTK) */
|
2010-02-24 14:25:16 -08:00
|
|
|
#ifdef MOZ_X11
|
2012-03-27 06:37:35 -07:00
|
|
|
// Do this after initializing GDK, or GDK will install its own handler.
|
|
|
|
InstallX11ErrorHandler();
|
2010-02-24 14:25:16 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Call the code to install our handler
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_JPROF
|
2012-03-27 06:37:35 -07:00
|
|
|
setupProfilingStuff();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = NS_CreateNativeAppSupport(getter_AddRefs(mNativeApp));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
bool canRun = false;
|
|
|
|
rv = mNativeApp->Start(&canRun);
|
|
|
|
if (NS_FAILED(rv) || !canRun) {
|
|
|
|
return 1;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK)
|
2012-03-27 06:37:35 -07:00
|
|
|
// DESKTOP_STARTUP_ID is cleared now,
|
|
|
|
// we recover it in case we need a restart.
|
|
|
|
if (!mDesktopStartupID.IsEmpty()) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString desktopStartupEnv;
|
2012-03-27 06:37:35 -07:00
|
|
|
desktopStartupEnv.AssignLiteral("DESKTOP_STARTUP_ID=");
|
|
|
|
desktopStartupEnv.Append(mDesktopStartupID);
|
|
|
|
// Leak it with extreme prejudice!
|
|
|
|
PR_SetEnv(ToNewCString(desktopStartupEnv));
|
|
|
|
}
|
2011-02-22 23:18:17 -08:00
|
|
|
#endif
|
|
|
|
|
2012-08-27 08:27:14 -07:00
|
|
|
#if defined(USE_MOZ_UPDATER)
|
2012-03-27 06:37:35 -07:00
|
|
|
// Check for and process any available updates
|
|
|
|
nsCOMPtr<nsIFile> updRoot;
|
|
|
|
bool persistent;
|
|
|
|
rv = mDirProvider.GetFile(XRE_UPDATE_ROOT_DIR, &persistent,
|
|
|
|
getter_AddRefs(updRoot));
|
|
|
|
// XRE_UPDATE_ROOT_DIR may fail. Fallback to appDir if failed
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
updRoot = mDirProvider.GetAppDir();
|
|
|
|
|
|
|
|
// If the MOZ_PROCESS_UPDATES environment variable already exists, then
|
|
|
|
// we are being called from the callback application.
|
|
|
|
if (EnvHasValue("MOZ_PROCESS_UPDATES")) {
|
|
|
|
// If the caller has asked us to log our arguments, do so. This is used
|
|
|
|
// to make sure that the maintenance service successfully launches the
|
|
|
|
// callback application.
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *logFile = nullptr;
|
2012-03-27 06:37:35 -07:00
|
|
|
if (ARG_FOUND == CheckArg("dump-args", false, &logFile)) {
|
|
|
|
FILE* logFP = fopen(logFile, "wb");
|
|
|
|
if (logFP) {
|
|
|
|
for (int i = 1; i < gRestartArgc; ++i) {
|
|
|
|
fprintf(logFP, "%s\n", gRestartArgv[i]);
|
2011-12-28 18:08:37 -08:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
fclose(logFP);
|
2011-12-28 18:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
*aExitFlag = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-28 18:08:37 -08:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Support for processing an update and exiting. The MOZ_PROCESS_UPDATES
|
|
|
|
// environment variable will be part of the updater's environment and the
|
|
|
|
// application that is relaunched by the updater. When the application is
|
|
|
|
// relaunched by the updater it will be removed below and the application
|
|
|
|
// will exit.
|
|
|
|
if (CheckArg("process-updates")) {
|
|
|
|
SaveToEnv("MOZ_PROCESS_UPDATES=1");
|
|
|
|
}
|
2013-02-08 06:58:52 -08:00
|
|
|
nsCOMPtr<nsIFile> exeFile, exeDir;
|
|
|
|
rv = mDirProvider.GetFile(XRE_EXECUTABLE_FILE, &persistent,
|
|
|
|
getter_AddRefs(exeFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
rv = exeFile->GetParent(getter_AddRefs(exeDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2012-03-27 06:37:35 -07:00
|
|
|
ProcessUpdates(mDirProvider.GetGREDir(),
|
2013-02-08 06:58:52 -08:00
|
|
|
exeDir,
|
2012-03-27 06:37:35 -07:00
|
|
|
updRoot,
|
|
|
|
gRestartArgc,
|
|
|
|
gRestartArgv,
|
|
|
|
mAppData->version);
|
|
|
|
if (EnvHasValue("MOZ_PROCESS_UPDATES")) {
|
|
|
|
SaveToEnv("MOZ_PROCESS_UPDATES=");
|
|
|
|
*aExitFlag = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc));
|
|
|
|
if (rv == NS_ERROR_FILE_ACCESS_DENIED) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: Access was denied while trying to open files in " \
|
|
|
|
"your profile directory.\n");
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// We failed to choose or create profile - notify user and quit
|
|
|
|
ProfileMissingDialog(mNativeApp);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-02-23 19:34:18 -08:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = SelectProfile(getter_AddRefs(mProfileLock), mProfileSvc, mNativeApp, &mStartOffline,
|
|
|
|
&mProfileName);
|
|
|
|
if (rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ||
|
|
|
|
rv == NS_ERROR_ABORT) {
|
|
|
|
*aExitFlag = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-06 07:40:33 -08:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// We failed to choose or create profile - notify user and quit
|
|
|
|
ProfileMissingDialog(mNativeApp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
gProfileLock = mProfileLock;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = mProfileLock->GetDirectory(getter_AddRefs(mProfD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = mProfileLock->GetLocalDirectory(getter_AddRefs(mProfLD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = mDirProvider.SetProfile(mProfD, mProfLD);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
//////////////////////// NOW WE HAVE A PROFILE ////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-03-27 06:37:35 -07:00
|
|
|
if (mAppData->flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
|
|
|
MakeOrSetMinidumpPath(mProfD);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString version;
|
2012-03-27 06:37:35 -07:00
|
|
|
BuildVersion(version);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef TARGET_OS_ABI
|
2012-03-27 06:37:35 -07:00
|
|
|
NS_NAMED_LITERAL_CSTRING(osABI, TARGET_OS_ABI);
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2012-03-27 06:37:35 -07:00
|
|
|
// No TARGET_XPCOM_ABI, but at least the OS is known
|
|
|
|
NS_NAMED_LITERAL_CSTRING(osABI, OS_TARGET "_UNKNOWN");
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Check for version compatibility with the last version of the app this
|
|
|
|
// profile was started with. The format of the version stamp is defined
|
|
|
|
// by the BuildVersion function.
|
|
|
|
// Also check to see if something has happened to invalidate our
|
|
|
|
// fastload caches, like an extension upgrade or installation.
|
2010-07-02 16:59:17 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// If we see .purgecaches, that means someone did a make.
|
|
|
|
// Re-register components to catch potential changes.
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> flagFile;
|
2010-09-23 13:41:26 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
nsCOMPtr<nsIFile> fFlagFile;
|
|
|
|
if (mAppData->directory) {
|
|
|
|
rv = mAppData->directory->Clone(getter_AddRefs(fFlagFile));
|
|
|
|
}
|
|
|
|
flagFile = do_QueryInterface(fFlagFile);
|
|
|
|
if (flagFile) {
|
|
|
|
flagFile->AppendNative(FILE_INVALIDATE_CACHES);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cachesOK;
|
|
|
|
bool versionOK = CheckCompatibility(mProfD, version, osABI,
|
|
|
|
mDirProvider.GetGREDir(),
|
|
|
|
mAppData->directory, flagFile,
|
|
|
|
&cachesOK);
|
|
|
|
if (CheckArg("purgecaches")) {
|
|
|
|
cachesOK = false;
|
|
|
|
}
|
|
|
|
if (PR_GetEnv("MOZ_PURGE_CACHES")) {
|
|
|
|
cachesOK = false;
|
|
|
|
}
|
2010-07-02 16:59:17 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Every time a profile is loaded by a build with a different version,
|
|
|
|
// it updates the compatibility.ini file saying what version last wrote
|
|
|
|
// the fastload caches. On subsequent launches if the version matches,
|
|
|
|
// there is no need for re-registration. If the user loads the same
|
|
|
|
// profile in different builds the component registry must be
|
|
|
|
// re-generated to prevent mysterious component loading failures.
|
|
|
|
//
|
2012-10-23 09:46:51 -07:00
|
|
|
bool startupCacheValid = true;
|
2012-03-27 06:37:35 -07:00
|
|
|
if (gSafeMode) {
|
2012-10-23 09:46:51 -07:00
|
|
|
startupCacheValid = RemoveComponentRegistries(mProfD, mProfLD, false);
|
2012-03-27 06:37:35 -07:00
|
|
|
WriteVersion(mProfD, NS_LITERAL_CSTRING("Safe Mode"), osABI,
|
2012-10-23 09:46:51 -07:00
|
|
|
mDirProvider.GetGREDir(), mAppData->directory, !startupCacheValid);
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
|
|
|
else if (versionOK) {
|
|
|
|
if (!cachesOK) {
|
|
|
|
// Remove caches, forcing component re-registration.
|
|
|
|
// The new list of additional components directories is derived from
|
|
|
|
// information in "extensions.ini".
|
2012-10-23 09:46:51 -07:00
|
|
|
startupCacheValid = RemoveComponentRegistries(mProfD, mProfLD, false);
|
2009-10-15 23:32:29 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Rewrite compatibility.ini to remove the flag
|
|
|
|
WriteVersion(mProfD, version, osABI,
|
2012-10-23 09:46:51 -07:00
|
|
|
mDirProvider.GetGREDir(), mAppData->directory, !startupCacheValid);
|
2010-07-02 16:59:17 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
// Nothing need be done for the normal startup case.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Remove caches, forcing component re-registration
|
|
|
|
// with the default set of components (this disables any potentially
|
|
|
|
// troublesome incompatible XPCOM components).
|
2012-10-23 09:46:51 -07:00
|
|
|
startupCacheValid = RemoveComponentRegistries(mProfD, mProfLD, true);
|
2010-09-23 13:41:26 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Write out version
|
|
|
|
WriteVersion(mProfD, version, osABI,
|
2012-10-23 09:46:51 -07:00
|
|
|
mDirProvider.GetGREDir(), mAppData->directory, !startupCacheValid);
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2010-04-26 11:13:03 -07:00
|
|
|
|
2012-10-23 09:46:51 -07:00
|
|
|
if (!startupCacheValid)
|
|
|
|
StartupCache::IgnoreDiskCache();
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (flagFile) {
|
|
|
|
flagFile->Remove(true);
|
|
|
|
}
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
/*
|
|
|
|
* XRE_mainRun - Command line startup, profile migration, and
|
|
|
|
* the calling of appStartup->Run().
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
XREMain::XRE_mainRun()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
NS_ASSERTION(mScopedXPCom, "Scoped xpcom not initialized.");
|
2010-05-19 16:22:19 -07:00
|
|
|
|
|
|
|
#ifdef NS_FUNCTION_TIMER
|
2012-03-27 06:37:35 -07:00
|
|
|
// initialize some common services, so we don't pay the cost for these at odd times later on;
|
|
|
|
// SetWindowCreator -> ChromeRegistry -> IOService -> SocketTransportService -> (nspr wspm init), Prefs
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> comp;
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
comp = do_GetService("@mozilla.org/preferences-service;1");
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
comp = do_GetService("@mozilla.org/network/socket-transport-service;1");
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
comp = do_GetService("@mozilla.org/network/dns-service;1");
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
comp = do_GetService("@mozilla.org/network/io-service;1");
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
comp = do_GetService("@mozilla.org/chrome/chrome-registry;1");
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
comp = do_GetService("@mozilla.org/focus-event-suppressor-service;1");
|
|
|
|
}
|
2010-05-19 16:22:19 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = mScopedXPCom->SetWindowCreator(mNativeApp);
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-11-13 15:05:14 -08:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-03-27 06:37:35 -07:00
|
|
|
// tell the crash reporter to also send the release channel
|
|
|
|
nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIPrefBranch> defaultPrefBranch;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = prefs->GetDefaultBranch(nullptr, getter_AddRefs(defaultPrefBranch));
|
2012-03-27 06:37:35 -07:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsXPIDLCString sval;
|
|
|
|
rv = defaultPrefBranch->GetCharPref("app.update.channel", getter_Copies(sval));
|
2009-11-13 15:05:14 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-27 06:37:35 -07:00
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ReleaseChannel"),
|
|
|
|
sval);
|
2009-11-13 15:05:14 -08:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
|
|
|
}
|
2009-11-13 15:05:14 -08:00
|
|
|
#endif
|
2010-04-26 11:13:03 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (mStartOffline) {
|
|
|
|
nsCOMPtr<nsIIOService2> io (do_GetService("@mozilla.org/network/io-service;1"));
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_TRUE(io, NS_ERROR_FAILURE);
|
2012-03-27 06:37:35 -07:00
|
|
|
io->SetManageOfflineStatus(false);
|
|
|
|
io->SetOffline(true);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserver> startupNotifier
|
|
|
|
(do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID, &rv));
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
startupNotifier->Observe(nullptr, APPSTARTUP_TOPIC, nullptr);
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup
|
|
|
|
(do_GetService(NS_APPSTARTUP_CONTRACTID));
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (gDoMigration) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
mDirProvider.GetAppDir()->Clone(getter_AddRefs(file));
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("override.ini"));
|
|
|
|
nsINIParser parser;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult rv = parser.Init(file);
|
2012-03-27 06:37:35 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buf;
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = parser.GetString("XRE", "EnableProfileMigrator", buf);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
|
2011-10-17 07:59:28 -07:00
|
|
|
gDoMigration = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-19 17:01:49 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIToolkitProfile> selectedProfile;
|
|
|
|
if (gDoProfileReset) {
|
|
|
|
// At this point we can be sure that profile reset is happening on the default profile.
|
|
|
|
rv = mProfileSvc->GetSelectedProfile(getter_AddRefs(selectedProfile));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
gDoProfileReset = false;
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-03-19 17:01:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Profile Migration
|
|
|
|
if (mAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR && gDoMigration) {
|
|
|
|
gDoMigration = false;
|
|
|
|
nsCOMPtr<nsIProfileMigrator> pm(do_CreateInstance(NS_PROFILEMIGRATOR_CONTRACTID));
|
|
|
|
if (pm) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString aKey;
|
2012-03-19 17:01:49 -07:00
|
|
|
if (gDoProfileReset) {
|
|
|
|
// Automatically migrate from the current application if we just
|
|
|
|
// reset the profile.
|
|
|
|
aKey = MOZ_APP_NAME;
|
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
pm->Migrate(&mDirProvider, aKey);
|
|
|
|
}
|
|
|
|
}
|
2012-03-19 17:01:49 -07:00
|
|
|
|
|
|
|
if (gDoProfileReset) {
|
|
|
|
nsresult backupCreated = ProfileResetCleanup(selectedProfile);
|
|
|
|
if (NS_FAILED(backupCreated)) NS_WARNING("Could not cleanup the profile that was reset");
|
|
|
|
|
|
|
|
// Set the new profile as the default after we're done cleaning up the old default.
|
|
|
|
rv = SetCurrentProfileAsDefault(mProfileSvc, mProfD);
|
|
|
|
if (NS_FAILED(rv)) NS_WARNING("Could not set current profile as the default");
|
|
|
|
}
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
mDirProvider.DoStartup();
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
appStartup->GetShuttingDown(&mShuttingDown);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdLine;
|
2009-04-21 11:53:43 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
nsCOMPtr<nsIFile> workingDir;
|
|
|
|
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mShuttingDown) {
|
|
|
|
cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
|
2009-04-21 11:36:44 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = cmdLine->Init(gArgc, gArgv, workingDir,
|
|
|
|
nsICommandLine::STATE_INITIAL_LAUNCH);
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
/* Special-case services that need early access to the command
|
|
|
|
line. */
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
2012-07-30 07:20:58 -07:00
|
|
|
obsService->NotifyObservers(cmdLine, "command-line-startup", nullptr);
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveStateForAppInitiatedRestart();
|
2009-04-21 11:36:44 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// clear out any environment variables which may have been set
|
|
|
|
// during the relaunch process now that we know we won't be relaunching.
|
|
|
|
SaveToEnv("XRE_PROFILE_PATH=");
|
|
|
|
SaveToEnv("XRE_PROFILE_LOCAL_PATH=");
|
|
|
|
SaveToEnv("XRE_PROFILE_NAME=");
|
|
|
|
SaveToEnv("XRE_START_OFFLINE=");
|
|
|
|
SaveToEnv("NO_EM_RESTART=");
|
|
|
|
SaveToEnv("XUL_APP_FILE=");
|
|
|
|
SaveToEnv("XRE_BINARY_PATH=");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mShuttingDown) {
|
|
|
|
rv = appStartup->CreateHiddenWindow();
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2010-04-29 13:11:23 -07:00
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK)
|
2012-03-27 06:37:35 -07:00
|
|
|
nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
|
|
|
|
if (toolkit && !mDesktopStartupID.IsEmpty()) {
|
|
|
|
toolkit->SetDesktopStartupID(mDesktopStartupID);
|
|
|
|
}
|
|
|
|
// Clear the environment variable so it won't be inherited by
|
|
|
|
// child processes and confuse things.
|
|
|
|
g_unsetenv ("DESKTOP_STARTUP_ID");
|
2010-04-29 13:11:23 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2012-03-27 06:37:35 -07:00
|
|
|
// Set up ability to respond to system (Apple) events. This must be
|
|
|
|
// done before setting up the command line service.
|
|
|
|
SetupMacApplicationDelegate();
|
2011-01-03 08:08:36 -08:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// we re-initialize the command-line service and do appleevents munging
|
|
|
|
// after we are sure that we're not restarting
|
|
|
|
cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gArgc, gArgv, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = cmdLine->Init(gArgc, gArgv,
|
|
|
|
workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService)
|
2012-07-30 07:20:58 -07:00
|
|
|
obsService->NotifyObservers(nullptr, "final-ui-startup", nullptr);
|
2009-04-21 11:36:44 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
appStartup->GetShuttingDown(&mShuttingDown);
|
|
|
|
}
|
2009-04-21 11:36:44 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mShuttingDown) {
|
|
|
|
rv = cmdLine->Run();
|
2012-07-30 02:24:36 -07:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, NS_ERROR_FAILURE);
|
2009-04-21 11:36:44 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
appStartup->GetShuttingDown(&mShuttingDown);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mShuttingDown) {
|
2009-04-21 11:53:43 -07:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2012-03-27 06:37:35 -07:00
|
|
|
// if we have X remote support, start listening for requests on the
|
|
|
|
// proxy window.
|
|
|
|
if (!mDisableRemote)
|
|
|
|
mRemoteService = do_GetService("@mozilla.org/toolkit/remote-service;1");
|
|
|
|
if (mRemoteService)
|
2012-12-22 12:40:37 -08:00
|
|
|
mRemoteService->Startup(mAppData->name, mProfileName.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
mNativeApp->Enable();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-03 08:20:02 -08:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
2013-03-15 21:47:02 -07:00
|
|
|
if (PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP") || profiler_is_active()) {
|
2013-03-22 09:16:52 -07:00
|
|
|
bool logToConsole = !!PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP");
|
|
|
|
mozilla::InitEventTracing(logToConsole);
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2011-03-03 08:20:02 -08:00
|
|
|
#endif /* MOZ_INSTRUMENT_EVENT_LOOP */
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
{
|
|
|
|
rv = appStartup->Run();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("failed to run appstartup");
|
|
|
|
gLogConsoleErrors = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XRE_main - A class based main entry point used by most platforms.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
XREMain::XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
|
|
|
|
{
|
2013-05-28 05:03:38 -07:00
|
|
|
char aLocal;
|
|
|
|
GeckoProfilerInitRAII profilerGuard(&aLocal);
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("Startup", "XRE_Main");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
gArgc = argc;
|
|
|
|
gArgv = argv;
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
NS_ENSURE_TRUE(aAppData, 2);
|
|
|
|
|
|
|
|
mAppData = new ScopedAppData(aAppData);
|
|
|
|
if (!mAppData)
|
|
|
|
return 1;
|
|
|
|
// used throughout this file
|
|
|
|
gAppData = mAppData;
|
|
|
|
|
|
|
|
ScopedLogging log;
|
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2012-10-17 07:36:43 -07:00
|
|
|
#if defined(MOZ_MEMORY) || defined(__FreeBSD__) \
|
|
|
|
|| defined(__NetBSD__) && __NetBSD_Version__ >= 500000000
|
2012-03-27 06:37:35 -07:00
|
|
|
// Disable the slice allocator, since jemalloc already uses similar layout
|
|
|
|
// algorithms, and using a sub-allocator tends to increase fragmentation.
|
|
|
|
// This must be done before g_thread_init() is called.
|
|
|
|
g_slice_set_config(G_SLICE_CONFIG_ALWAYS_MALLOC, 1);
|
|
|
|
#endif
|
|
|
|
g_thread_init(NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// init
|
|
|
|
bool exit = false;
|
2013-03-27 08:19:10 -07:00
|
|
|
int result = XRE_mainInit(&exit);
|
2012-03-27 06:37:35 -07:00
|
|
|
if (result != 0 || exit)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// startup
|
|
|
|
result = XRE_mainStartup(&exit);
|
|
|
|
if (result != 0 || exit)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
bool appInitiatedRestart = false;
|
|
|
|
|
|
|
|
// Start the real application
|
|
|
|
mScopedXPCom = new ScopedXPCOMStartup();
|
|
|
|
if (!mScopedXPCom)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
rv = mScopedXPCom->Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
|
|
|
|
// run!
|
|
|
|
rv = XRE_mainRun();
|
|
|
|
|
2011-03-03 08:20:02 -08:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
2012-03-27 06:37:35 -07:00
|
|
|
mozilla::ShutdownEventTracing();
|
2011-03-03 08:20:02 -08:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Check for an application initiated restart. This is one that
|
|
|
|
// corresponds to nsIAppStartup.quit(eRestart)
|
|
|
|
if (rv == NS_SUCCESS_RESTART_APP) {
|
|
|
|
appInitiatedRestart = true;
|
2012-10-31 11:18:03 -07:00
|
|
|
} else {
|
|
|
|
// We will have a real shutdown, let ShutdownXPCOM poison writes to
|
|
|
|
// find any late ones.
|
|
|
|
mozilla::EnableWritePoisoning();
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
if (!mShuttingDown) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2012-03-27 06:37:35 -07:00
|
|
|
// shut down the x remote proxy window
|
|
|
|
if (mRemoteService) {
|
|
|
|
mRemoteService->Shutdown();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
delete mScopedXPCom;
|
2012-07-30 07:20:58 -07:00
|
|
|
mScopedXPCom = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// unlock the profile after ScopedXPCOMStartup object (xpcom)
|
|
|
|
// has gone out of scope. see bug #386739 for more details
|
|
|
|
mProfileLock->Unlock();
|
2012-07-30 07:20:58 -07:00
|
|
|
gProfileLock = nullptr;
|
2007-07-11 17:30:45 -07:00
|
|
|
|
2011-10-17 17:53:37 -07:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
2012-03-27 06:37:35 -07:00
|
|
|
nsQAppInstance::Release();
|
2011-10-17 17:53:37 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Restart the app after XPCOM has been shut down cleanly.
|
|
|
|
if (appInitiatedRestart) {
|
|
|
|
RestoreStateForAppInitiatedRestart();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
// Ensure that these environment variables are set:
|
|
|
|
SaveFileToEnvIfUnset("XRE_PROFILE_PATH", mProfD);
|
|
|
|
SaveFileToEnvIfUnset("XRE_PROFILE_LOCAL_PATH", mProfLD);
|
|
|
|
SaveWordToEnvIfUnset("XRE_PROFILE_NAME", mProfileName);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2012-03-27 06:37:35 -07:00
|
|
|
MOZ_gdk_display_close(mGdkDisplay);
|
2007-09-27 14:14:11 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
rv = LaunchChild(mNativeApp, true);
|
2007-03-27 11:02:02 -07:00
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-03-27 06:37:35 -07:00
|
|
|
if (mAppData->flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
|
|
|
CrashReporter::UnsetExceptionHandler();
|
2007-03-27 11:21:57 -07:00
|
|
|
#endif
|
2012-03-27 06:37:35 -07:00
|
|
|
return rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ? 0 : 1;
|
|
|
|
}
|
2007-09-27 14:14:11 -07:00
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2012-03-27 06:37:35 -07:00
|
|
|
// gdk_display_close also calls gdk_display_manager_set_default_display
|
|
|
|
// appropriately when necessary.
|
|
|
|
MOZ_gdk_display_close(mGdkDisplay);
|
2007-09-27 14:14:11 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-03-27 06:37:35 -07:00
|
|
|
if (mAppData->flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
2007-05-16 10:14:59 -07:00
|
|
|
CrashReporter::UnsetExceptionHandler();
|
2007-03-27 11:21:57 -07:00
|
|
|
#endif
|
|
|
|
|
2009-12-04 16:15:44 -08:00
|
|
|
XRE_DeinitCommandLine();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_FAILED(rv) ? 1 : 0;
|
|
|
|
}
|
2009-12-14 14:13:00 -08:00
|
|
|
|
2012-11-05 03:26:12 -08:00
|
|
|
#if defined(MOZ_METRO) && defined(XP_WIN)
|
|
|
|
extern bool XRE_MetroCoreApplicationRun();
|
|
|
|
static XREMain* xreMainPtr;
|
|
|
|
|
|
|
|
// must be called by the thread we want as the main thread
|
|
|
|
nsresult
|
2013-03-24 16:10:46 -07:00
|
|
|
XRE_metroStartup(bool runXREMain)
|
2012-11-05 03:26:12 -08:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
bool exit = false;
|
|
|
|
if (xreMainPtr->XRE_mainStartup(&exit) != 0 || exit)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Start the real application
|
|
|
|
xreMainPtr->mScopedXPCom = new ScopedXPCOMStartup();
|
|
|
|
if (!xreMainPtr->mScopedXPCom)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = xreMainPtr->mScopedXPCom->Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-03-24 16:10:46 -07:00
|
|
|
if (runXREMain) {
|
|
|
|
rv = xreMainPtr->XRE_mainRun();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2012-11-05 03:26:12 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XRE_metroShutdown()
|
|
|
|
{
|
|
|
|
delete xreMainPtr->mScopedXPCom;
|
|
|
|
xreMainPtr->mScopedXPCom = nullptr;
|
|
|
|
|
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
|
|
|
mozilla::ShutdownEventTracing();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// unlock the profile after ScopedXPCOMStartup object (xpcom)
|
|
|
|
// has gone out of scope. see bug #386739 for more details
|
|
|
|
xreMainPtr->mProfileLock->Unlock();
|
|
|
|
gProfileLock = nullptr;
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
if (xreMainPtr->mAppData->flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
|
|
|
CrashReporter::UnsetExceptionHandler();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
XRE_DeinitCommandLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
class WinRTInitWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WinRTInitWrapper() {
|
|
|
|
mResult = ::RoInitialize(RO_INIT_MULTITHREADED);
|
|
|
|
}
|
|
|
|
~WinRTInitWrapper() {
|
|
|
|
if (SUCCEEDED(mResult)) {
|
|
|
|
::RoUninitialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HRESULT mResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
XRE_mainMetro(int argc, char* argv[], const nsXREAppData* aAppData)
|
|
|
|
{
|
2013-05-28 05:03:38 -07:00
|
|
|
char aLocal;
|
|
|
|
GeckoProfilerInitRAII profilerGuard(&aLocal);
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("Startup", "XRE_Main");
|
2012-11-05 03:26:12 -08:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
xreMainPtr = new XREMain();
|
|
|
|
if (!xreMainPtr) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inits Winrt and COM underneath it.
|
|
|
|
WinRTInitWrapper wrap;
|
|
|
|
|
|
|
|
gArgc = argc;
|
|
|
|
gArgv = argv;
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aAppData, 2);
|
|
|
|
|
|
|
|
xreMainPtr->mAppData = new ScopedAppData(aAppData);
|
|
|
|
if (!xreMainPtr->mAppData)
|
|
|
|
return 1;
|
|
|
|
// used throughout this file
|
|
|
|
gAppData = xreMainPtr->mAppData;
|
|
|
|
|
|
|
|
ScopedLogging log;
|
|
|
|
|
|
|
|
// init
|
|
|
|
bool exit = false;
|
2013-03-27 08:19:10 -07:00
|
|
|
if (xreMainPtr->XRE_mainInit(&exit) != 0 || exit)
|
2012-11-05 03:26:12 -08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
// Located in widget, will call back into XRE_metroStartup and
|
|
|
|
// XRE_metroShutdown above.
|
|
|
|
if (!XRE_MetroCoreApplicationRun()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XRE_metroShutdown should have already been called on the worker
|
|
|
|
// thread that called XRE_metroStartup.
|
|
|
|
NS_ASSERTION(!xreMainPtr->mScopedXPCom,
|
|
|
|
"XPCOM Shutdown hasn't occured, and we are exiting.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetWindowsEnvironment(WindowsEnvironmentType aEnvID);
|
|
|
|
#endif // MOZ_METRO || !defined(XP_WIN)
|
|
|
|
|
2013-01-04 07:27:41 -08:00
|
|
|
void
|
|
|
|
XRE_DisableWritePoisoning(void) {
|
|
|
|
mozilla::DisableWritePoisoning();
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:37:35 -07:00
|
|
|
int
|
2012-08-22 08:56:38 -07:00
|
|
|
XRE_main(int argc, char* argv[], const nsXREAppData* aAppData, uint32_t aFlags)
|
2012-03-27 06:37:35 -07:00
|
|
|
{
|
2012-11-05 03:26:12 -08:00
|
|
|
#if !defined(MOZ_METRO) || !defined(XP_WIN)
|
2012-03-27 06:37:35 -07:00
|
|
|
XREMain main;
|
2012-07-06 15:29:53 -07:00
|
|
|
int result = main.XRE_main(argc, argv, aAppData);
|
|
|
|
mozilla::RecordShutdownEndTimeStamp();
|
|
|
|
return result;
|
2012-11-05 03:26:12 -08:00
|
|
|
#else
|
|
|
|
if (aFlags == XRE_MAIN_FLAG_USE_METRO) {
|
|
|
|
SetWindowsEnvironment(WindowsEnvironmentType_Metro);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Desktop
|
|
|
|
if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
|
|
|
|
XREMain main;
|
|
|
|
int result = main.XRE_main(argc, argv, aAppData);
|
|
|
|
mozilla::RecordShutdownEndTimeStamp();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metro
|
|
|
|
NS_ASSERTION(XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro,
|
|
|
|
"Unknown Windows environment");
|
|
|
|
|
|
|
|
int result = XRE_mainMetro(argc, argv, aAppData);
|
|
|
|
mozilla::RecordShutdownEndTimeStamp();
|
|
|
|
return result;
|
|
|
|
#endif // MOZ_METRO || !defined(XP_WIN)
|
2012-03-27 06:37:35 -07:00
|
|
|
}
|
|
|
|
|
2009-12-14 14:13:00 -08:00
|
|
|
nsresult
|
|
|
|
XRE_InitCommandLine(int aArgc, char* aArgv[])
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
CommandLine::Init(aArgc, aArgv);
|
|
|
|
#else
|
2010-06-25 13:29:43 -07:00
|
|
|
|
2009-12-14 14:13:00 -08:00
|
|
|
// these leak on error, but that's OK: we'll just exit()
|
|
|
|
char** canonArgs = new char*[aArgc];
|
|
|
|
|
|
|
|
// get the canonical version of the binary's path
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> binFile;
|
2009-12-14 14:13:00 -08:00
|
|
|
rv = XRE_GetBinaryPath(aArgv[0], getter_AddRefs(binFile));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString canonBinPath;
|
2009-12-14 14:13:00 -08:00
|
|
|
rv = binFile->GetNativePath(canonBinPath);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
canonArgs[0] = strdup(canonBinPath.get());
|
|
|
|
|
|
|
|
for (int i = 1; i < aArgc; ++i) {
|
|
|
|
if (aArgv[i]) {
|
|
|
|
canonArgs[i] = strdup(aArgv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!CommandLine::IsInitialized(), "Bad news!");
|
|
|
|
CommandLine::Init(aArgc, canonArgs);
|
|
|
|
|
|
|
|
for (int i = 0; i < aArgc; ++i)
|
|
|
|
free(canonArgs[i]);
|
|
|
|
delete[] canonArgs;
|
|
|
|
#endif
|
2010-08-10 15:08:06 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *path = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
ArgResult ar = CheckArg("greomni", false, &path);
|
2010-08-10 15:08:06 -07:00
|
|
|
if (ar == ARG_BAD) {
|
2011-02-25 03:53:36 -08:00
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -greomni requires a path argument\n");
|
2010-08-10 15:08:06 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-02-25 03:53:36 -08:00
|
|
|
if (!path)
|
2010-08-10 15:08:06 -07:00
|
|
|
return rv;
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> greOmni;
|
2011-02-25 03:53:36 -08:00
|
|
|
rv = XRE_GetFileFromPath(path, getter_AddRefs(greOmni));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -greomni requires a valid path\n");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
ar = CheckArg("appomni", false, &path);
|
2011-02-25 03:53:36 -08:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -appomni requires a path argument\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> appOmni;
|
2011-02-25 03:53:36 -08:00
|
|
|
if (path) {
|
|
|
|
rv = XRE_GetFileFromPath(path, getter_AddRefs(appOmni));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -appomni requires a valid path\n");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2011-03-24 07:28:14 -07:00
|
|
|
|
2011-02-25 03:53:36 -08:00
|
|
|
mozilla::Omnijar::Init(greOmni, appOmni);
|
2011-03-24 21:07:05 -07:00
|
|
|
return rv;
|
2009-12-14 14:13:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XRE_DeinitCommandLine()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
CommandLine::Terminate();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoProcessType
|
|
|
|
XRE_GetProcessType()
|
|
|
|
{
|
|
|
|
return mozilla::startup::sChildProcessType;
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:16:38 -08:00
|
|
|
void
|
2009-12-18 14:14:53 -08:00
|
|
|
SetupErrorHandling(const char* progname)
|
2009-12-18 13:16:38 -08:00
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
/* On Windows XPSP3 and Windows Vista if DEP is configured off-by-default
|
|
|
|
we still want DEP protection: enable it explicitly and programmatically.
|
|
|
|
|
|
|
|
This function is not available on WinXPSP2 so we dynamically load it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
|
|
|
|
SetProcessDEPPolicyFunc _SetProcessDEPPolicy =
|
|
|
|
(SetProcessDEPPolicyFunc) GetProcAddress(kernel32, "SetProcessDEPPolicy");
|
|
|
|
if (_SetProcessDEPPolicy)
|
|
|
|
_SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
|
|
|
|
#endif
|
|
|
|
|
2011-04-29 03:38:26 -07:00
|
|
|
#ifdef XP_WIN32
|
2009-12-18 13:16:38 -08:00
|
|
|
// Suppress the "DLL Foo could not be found" dialog, such that if dependent
|
|
|
|
// libraries (such as GDI+) are not preset, we gracefully fail to load those
|
|
|
|
// XPCOM components, instead of being ungraceful.
|
|
|
|
UINT realMode = SetErrorMode(0);
|
|
|
|
realMode |= SEM_FAILCRITICALERRORS;
|
|
|
|
// If XRE_NO_WINDOWS_CRASH_DIALOG is set, suppress displaying the "This
|
|
|
|
// application has crashed" dialog box. This is mainly useful for
|
|
|
|
// automated testing environments, e.g. tinderbox, where there's no need
|
|
|
|
// for a dozen of the dialog boxes to litter the console
|
|
|
|
if (getenv("XRE_NO_WINDOWS_CRASH_DIALOG"))
|
|
|
|
realMode |= SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX;
|
|
|
|
|
|
|
|
SetErrorMode(realMode);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-08-27 12:12:32 -07:00
|
|
|
#if defined (DEBUG) && defined(XP_WIN)
|
|
|
|
// Send MSCRT Warnings, Errors and Assertions to stderr.
|
|
|
|
// See http://msdn.microsoft.com/en-us/library/1y71x448(v=VS.80).aspx
|
|
|
|
// and http://msdn.microsoft.com/en-us/library/a68f826y(v=VS.80).aspx.
|
|
|
|
|
|
|
|
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
|
|
|
|
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
|
|
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
|
|
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
|
|
|
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
|
|
|
|
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
|
|
|
|
|
|
|
_CrtSetReportHook(MSCRTReportHook);
|
|
|
|
#endif
|
|
|
|
|
2010-01-30 04:48:32 -08:00
|
|
|
#ifndef XP_OS2
|
2009-12-18 14:14:53 -08:00
|
|
|
InstallSignalHandlers(progname);
|
2010-01-30 04:48:32 -08:00
|
|
|
#endif
|
2009-12-18 13:16:38 -08:00
|
|
|
|
|
|
|
// Unbuffer stdout, needed for tinderbox tests.
|
|
|
|
setbuf(stdout, 0);
|
|
|
|
}
|
2011-10-14 12:22:11 -07:00
|
|
|
|