2002-08-21 10:25:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2005-02-01 17:07:35 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-08-21 10:25:54 +00:00
|
|
|
*
|
2005-02-01 17:07:35 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2002-08-21 10:25:54 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2005-02-01 17:07:35 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-08-21 10:25:54 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
|
2005-05-26 19:51:19 +00:00
|
|
|
* Benjamin Smedberg <benjamin@smedbergs.us>
|
2004-06-17 21:23:51 +00:00
|
|
|
* Ben Goodger <ben@mozilla.org>
|
2005-04-15 15:13:11 +00:00
|
|
|
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
|
2006-02-21 21:10:55 +00:00
|
|
|
* Ben Turner <mozilla@songbirdnest.com>
|
2006-06-08 18:20:07 +00:00
|
|
|
* Sergei Dolgov <sergei_d@fi.tartu.ee>
|
2002-08-21 10:25:54 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2005-02-01 17:07:35 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2002-08-21 10:25:54 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2005-02-01 17:07:35 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-08-21 10:25:54 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2005-02-01 17:07:35 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-08-21 10:25:54 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2007-07-20 18:57:22 +00: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
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2005-07-21 13:33:43 +00:00
|
|
|
#define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
|
|
|
|
|
2008-04-19 13:21:59 +00:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
2010-08-03 18:33:12 +00:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtCore/QScopedPointer>
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QInputContextFactory>
|
|
|
|
#include <QtGui/QInputContext>
|
2011-06-25 13:22:34 +00:00
|
|
|
#ifdef MOZ_ENABLE_MEEGOTOUCH
|
|
|
|
#include <MComponentData>
|
|
|
|
#endif // MOZ_ENABLE_MEEGOTOUCH
|
2010-08-03 17:44:46 +00:00
|
|
|
#endif // MOZ_WIDGET_QT
|
2008-04-19 13:21:59 +00:00
|
|
|
|
2010-08-12 01:18:41 +00:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
|
2010-03-04 21:51:42 +00:00
|
|
|
#include "nsAppRunner.h"
|
|
|
|
#include "nsUpdateDriver.h"
|
|
|
|
|
2011-03-03 16:20:02 +00:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
|
|
|
#include "EventTracer.h"
|
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "MacLaunchHelper.h"
|
2006-12-14 22:00:46 +00:00
|
|
|
#include "MacApplicationDelegate.h"
|
2010-04-21 08:29:38 +00:00
|
|
|
#include "MacAutoreleasePool.h"
|
2006-12-14 22:00:46 +00:00
|
|
|
#endif
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-03-31 16:48:48 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
#include "private/pprthred.h"
|
|
|
|
#endif
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "prnetdb.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "prproces.h"
|
2004-04-08 14:01:17 +00:00
|
|
|
#include "prenv.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
2004-10-29 19:28:38 +00:00
|
|
|
#include "nsIAppStartup.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "nsIAppStartupNotifier.h"
|
2006-04-12 15:43:32 +00:00
|
|
|
#include "nsIMutableArray.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIChromeRegistry.h"
|
2005-01-17 18:50:18 +00:00
|
|
|
#include "nsICommandLineRunner.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIContentHandler.h"
|
|
|
|
#include "nsIDialogParamBlock.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2007-08-16 23:10:46 +00:00
|
|
|
#include "nsIIOService2.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "nsIObserverService.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsINativeAppSupport.h"
|
|
|
|
#include "nsIProcess.h"
|
2005-03-15 20:01:12 +00:00
|
|
|
#include "nsIProfileUnlocker.h"
|
|
|
|
#include "nsIPromptService.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2005-03-15 20:01:12 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsIToolkitProfile.h"
|
|
|
|
#include "nsIToolkitProfileService.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIWindowCreator.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "nsIWindowMediator.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsIWindowWatcher.h"
|
2004-12-04 18:25:46 +00:00
|
|
|
#include "nsIXULAppInfo.h"
|
2005-05-12 13:23:30 +00:00
|
|
|
#include "nsIXULRuntime.h"
|
2007-02-09 01:33:26 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsAppShellCID.h"
|
|
|
|
|
2010-04-26 18:13:03 +00:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsIWinAppHelper.h"
|
2009-07-17 14:17:45 +00:00
|
|
|
#include <windows.h>
|
2011-01-23 10:45:00 +00:00
|
|
|
#include "cairo/cairo-features.h"
|
2009-07-17 14:17:45 +00:00
|
|
|
|
|
|
|
#ifndef PROCESS_DEP_ENABLE
|
|
|
|
#define PROCESS_DEP_ENABLE 0x1
|
|
|
|
#endif
|
2007-01-30 05:14:50 +00:00
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2005-01-17 18:50:18 +00:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2005-03-15 20:01:12 +00:00
|
|
|
#include "nsEmbedCID.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#include "nsNetUtil.h"
|
2007-06-30 05:02:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2005-07-21 13:33:43 +00:00
|
|
|
#include "nsStaticComponents.h"
|
2003-03-08 04:15:01 +00:00
|
|
|
#include "nsXPCOM.h"
|
2009-01-12 16:05:10 +00:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2006-08-17 14:22:04 +00:00
|
|
|
#include "nsVersionComparator.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsXREDirProvider.h"
|
2005-04-04 19:08:55 +00:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
#include "nsINIParser.h"
|
2010-05-21 17:58:32 +00:00
|
|
|
#include "mozilla/Omnijar.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-06-16 18:59:35 +00:00
|
|
|
#if defined(MOZ_SPLASHSCREEN)
|
|
|
|
#include "nsSplashScreen.h"
|
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2010-04-29 07:19:50 +00:00
|
|
|
#include <pwd.h>
|
2004-06-17 21:23:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
2007-01-30 05:14:50 +00:00
|
|
|
#include <shlobj.h>
|
|
|
|
#include "nsThreadUtils.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsILocalFileMac.h"
|
2005-01-26 20:56:43 +00:00
|
|
|
#include "nsCommandLineServiceMac.h"
|
2004-06-17 21:23:51 +00:00
|
|
|
#endif
|
2002-08-21 10:25:54 +00:00
|
|
|
|
|
|
|
// for X remote support
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2005-04-04 19:08:55 +00:00
|
|
|
#include "XRemoteClient.h"
|
|
|
|
#include "nsIRemoteService.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS_TRACE_MALLOC
|
|
|
|
#include "nsTraceMalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(XP_WIN32)
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-08 04:15:01 +00:00
|
|
|
#if defined (XP_MACOSX)
|
2009-03-19 17:41:13 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
2003-03-08 04:15:01 +00:00
|
|
|
#endif
|
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
#include "jprof.h"
|
|
|
|
#endif
|
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
2007-04-10 19:15:16 +00:00
|
|
|
#include "nsICrashReporter.h"
|
|
|
|
#define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
|
2009-11-13 23:05:14 +00:00
|
|
|
#include "nsIPrefService.h"
|
2006-10-26 22:52:30 +00:00
|
|
|
#endif
|
|
|
|
|
2009-06-30 19:21:25 +00:00
|
|
|
#include "base/command_line.h"
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2010-06-04 01:16:20 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
2011-02-03 17:27:00 +00:00
|
|
|
extern PRUint32 gRestartMode;
|
2009-12-17 21:56:12 +00:00
|
|
|
extern void InstallSignalHandlers(const char *ProgramName);
|
2010-02-24 22:25:16 +00:00
|
|
|
#include "nsX11ErrorHandler.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2009-10-16 06:32:29 +00:00
|
|
|
#define FILE_COMPATIBILITY_INFO NS_LITERAL_CSTRING("compatibility.ini")
|
2010-07-02 23:59:17 +00:00
|
|
|
#define FILE_INVALIDATE_CACHES NS_LITERAL_CSTRING(".purgecaches")
|
2009-10-16 06:32:29 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
int gArgc;
|
|
|
|
char **gArgv;
|
|
|
|
|
2010-04-07 19:44:38 +00:00
|
|
|
static const char gToolkitVersion[] = NS_STRINGIFY(GRE_MILESTONE);
|
|
|
|
static const char gToolkitBuildID[] = NS_STRINGIFY(GRE_BUILDID);
|
2007-07-02 18:20:24 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
static int gRestartArgc;
|
|
|
|
static char **gRestartArgv;
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2010-07-17 06:52:23 +00:00
|
|
|
#ifdef MOZ_WIDGET_QT
|
|
|
|
static int gQtOnlyArgc;
|
|
|
|
static char **gQtOnlyArgv;
|
|
|
|
#endif
|
|
|
|
|
2007-02-09 01:33:26 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2008-09-25 22:38:25 +00: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 23:52:44 +00:00
|
|
|
#include <gtk/gtk.h>
|
2008-08-06 20:48:55 +00:00
|
|
|
#ifdef MOZ_X11
|
2007-10-03 21:44:05 +00:00
|
|
|
#include <gdk/gdkx.h>
|
2008-08-06 20:48:55 +00:00
|
|
|
#endif /* MOZ_X11 */
|
2007-02-09 01:33:26 +00:00
|
|
|
#include "nsGTKToolkit.h"
|
|
|
|
#endif
|
2011-05-22 06:23:20 +00:00
|
|
|
#include "BinaryPath.h"
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2011-07-15 10:31:34 +00:00
|
|
|
using mozilla::dom::ContentParent;
|
|
|
|
|
2010-04-19 08:29:18 +00: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 17:28:18 +00:00
|
|
|
// Tests that an environment variable exists and has a value
|
|
|
|
static PRBool
|
|
|
|
EnvHasValue(const char *name)
|
|
|
|
{
|
|
|
|
const char *val = PR_GetEnv(name);
|
|
|
|
return (val && *val);
|
|
|
|
}
|
|
|
|
|
2007-06-30 05:02:49 +00: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.
|
|
|
|
}
|
|
|
|
|
2005-09-01 20:59:50 +00:00
|
|
|
// Save the path of the given file to the specified environment variable.
|
2005-09-01 18:55:27 +00:00
|
|
|
static void
|
|
|
|
SaveFileToEnv(const char *name, nsIFile *file)
|
|
|
|
{
|
2007-12-31 15:15:43 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsAutoString path;
|
|
|
|
file->GetPath(path);
|
|
|
|
SetEnvironmentVariableW(NS_ConvertASCIItoUTF16(name).get(), path.get());
|
|
|
|
#else
|
2005-09-01 18:55:27 +00:00
|
|
|
nsCAutoString path;
|
|
|
|
file->GetNativePath(path);
|
2007-06-30 05:02:49 +00:00
|
|
|
SaveWordToEnv(name, path);
|
2007-12-31 15:15:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the path of a file saved with SaveFileToEnv
|
|
|
|
static already_AddRefed<nsILocalFile>
|
|
|
|
GetFileFromEnv(const char *name)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsILocalFile *file = nsnull;
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
WCHAR path[_MAX_PATH];
|
|
|
|
if (!GetEnvironmentVariableW(NS_ConvertASCIItoUTF16(name).get(),
|
|
|
|
path, _MAX_PATH))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
rv = NS_NewLocalFile(nsDependentString(path), PR_TRUE, &file);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return file;
|
|
|
|
#else
|
|
|
|
const char *arg = PR_GetEnv(name);
|
|
|
|
if (!arg || !*arg)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(arg), PR_TRUE, &file);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return file;
|
|
|
|
#endif
|
2007-06-30 05:02:49 +00:00
|
|
|
}
|
2005-09-01 18:55:27 +00:00
|
|
|
|
2007-06-30 05:02:49 +00: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 17:28:18 +00:00
|
|
|
if (!EnvHasValue(name))
|
2007-06-30 05:02:49 +00:00
|
|
|
SaveWordToEnv(name, word);
|
2005-09-01 18:55:27 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 20:59:50 +00: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 17:28:18 +00:00
|
|
|
if (!EnvHasValue(name))
|
2005-09-01 20:59:50 +00:00
|
|
|
SaveFileToEnv(name, file);
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
static PRBool
|
|
|
|
strimatch(const char* lowerstr, const char* mixedstr)
|
|
|
|
{
|
|
|
|
while(*lowerstr) {
|
|
|
|
if (!*mixedstr) return PR_FALSE; // mixedstr is shorter
|
|
|
|
if (tolower(*mixedstr) != *lowerstr) return PR_FALSE; // no match
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
++lowerstr;
|
|
|
|
++mixedstr;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
if (*mixedstr) return PR_FALSE; // lowerstr is shorter
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return PR_TRUE;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2006-08-17 14:22:04 +00: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.
|
|
|
|
*/
|
|
|
|
static void Output(PRBool isError, const char *fmt, ... )
|
|
|
|
{
|
|
|
|
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 21:34:53 +00: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);
|
2006-08-17 14:22:04 +00:00
|
|
|
PR_smprintf_free(msg);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2007-08-20 05:09:07 +00:00
|
|
|
enum RemoteResult {
|
|
|
|
REMOTE_NOT_FOUND = 0,
|
|
|
|
REMOTE_FOUND = 1,
|
|
|
|
REMOTE_ARG_BAD = 2
|
|
|
|
};
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
enum ArgResult {
|
|
|
|
ARG_NONE = 0,
|
|
|
|
ARG_FOUND = 1,
|
|
|
|
ARG_BAD = 2 // you wanted a param, but there isn't one
|
|
|
|
};
|
2003-03-08 04:15:01 +00:00
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
static void RemoveArg(char **argv)
|
|
|
|
{
|
|
|
|
do {
|
2005-01-17 20:27:23 +00:00
|
|
|
*argv = *(argv + 1);
|
|
|
|
++argv;
|
2005-01-17 18:50:18 +00:00
|
|
|
} while (*argv);
|
|
|
|
|
|
|
|
--gArgc;
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
/**
|
|
|
|
* 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-11 05:59:56 +00:00
|
|
|
* @param aCheckOSInt if true returns ARG_BAD if the osint argument is present
|
|
|
|
* when aArg is also present.
|
2004-06-17 21:23:51 +00:00
|
|
|
* @param if non-null, the -arg <data> will be stored in this pointer. This is *not*
|
|
|
|
* allocated, but rather a pointer to the argv data.
|
|
|
|
*/
|
|
|
|
static ArgResult
|
2009-08-26 23:10:48 +00:00
|
|
|
CheckArg(const char* aArg, PRBool aCheckOSInt = PR_FALSE, const char **aParam = nsnull, PRBool aRemArg = PR_TRUE)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2010-08-19 19:50:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(gArgv, "gArgv must be initialized before CheckArg()");
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
char **curarg = gArgv + 1; // skip argv[0]
|
2007-07-11 05:59:56 +00:00
|
|
|
ArgResult ar = ARG_NONE;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
while (*curarg) {
|
|
|
|
char *arg = curarg[0];
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
if (arg[0] == '-'
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
|| *arg == '/'
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
) {
|
|
|
|
++arg;
|
|
|
|
if (*arg == '-')
|
|
|
|
++arg;
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
if (strimatch(aArg, arg)) {
|
2009-08-26 23:10:48 +00:00
|
|
|
if (aRemArg)
|
|
|
|
RemoveArg(curarg);
|
2005-01-17 18:50:18 +00:00
|
|
|
if (!aParam) {
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = ARG_FOUND;
|
|
|
|
break;
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
if (*curarg) {
|
2004-06-17 21:23:51 +00:00
|
|
|
if (**curarg == '-'
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
|| **curarg == '/'
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
return ARG_BAD;
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
*aParam = *curarg;
|
2009-08-26 23:10:48 +00:00
|
|
|
if (aRemArg)
|
|
|
|
RemoveArg(curarg);
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = ARG_FOUND;
|
|
|
|
break;
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
return ARG_BAD;
|
|
|
|
}
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
++curarg;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 05:59:56 +00: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;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 05:14:50 +00: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-21 00:21:21 +00: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-01-30 05:14:50 +00:00
|
|
|
*/
|
|
|
|
static void
|
2008-06-21 00:21:21 +00:00
|
|
|
ProcessDDE(nsINativeAppSupport* aNative, PRBool aWait)
|
2007-01-30 05:14:50 +00: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-21 00:21:21 +00: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.
|
|
|
|
PRInt32 count = 20;
|
|
|
|
while(--count >= 0) {
|
|
|
|
NS_ProcessNextEvent(thread);
|
|
|
|
PR_Sleep(PR_MillisecondsToInterval(1));
|
|
|
|
}
|
2007-01-30 05:14:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
PRBool gSafeMode = PR_FALSE;
|
|
|
|
|
2004-12-04 18:25:46 +00:00
|
|
|
/**
|
|
|
|
* The nsXULAppInfo object implements nsIFactory so that it can be its own
|
|
|
|
* singleton.
|
|
|
|
*/
|
|
|
|
class nsXULAppInfo : public nsIXULAppInfo,
|
2007-01-30 05:14:50 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
public nsIWinAppHelper,
|
2007-04-10 19:15:16 +00:00
|
|
|
#endif
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-04-10 19:15:16 +00:00
|
|
|
public nsICrashReporter,
|
2007-01-30 05:14:50 +00:00
|
|
|
#endif
|
2005-07-21 13:33:43 +00:00
|
|
|
public nsIXULRuntime
|
2009-07-30 03:23:56 +00:00
|
|
|
|
2004-12-04 18:25:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-03-24 23:29:29 +00:00
|
|
|
nsXULAppInfo() {}
|
2004-12-04 18:25:46 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIXULAPPINFO
|
2005-05-12 13:23:30 +00:00
|
|
|
NS_DECL_NSIXULRUNTIME
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-04-10 19:15:16 +00:00
|
|
|
NS_DECL_NSICRASHREPORTER
|
|
|
|
#endif
|
2007-01-30 05:14:50 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
NS_DECL_NSIWINAPPHELPER
|
|
|
|
#endif
|
2004-12-04 18:25:46 +00:00
|
|
|
};
|
|
|
|
|
2005-08-08 13:54:38 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXULAppInfo)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULRuntime)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULRuntime)
|
2007-01-30 05:14:50 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWinAppHelper)
|
2007-04-10 19:15:16 +00:00
|
|
|
#endif
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-04-10 19:15:16 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICrashReporter)
|
2007-01-30 05:14:50 +00:00
|
|
|
#endif
|
2005-08-08 13:54:38 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData)
|
|
|
|
NS_INTERFACE_MAP_END
|
2004-12-04 18:25:46 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXULAppInfo::AddRef()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXULAppInfo::Release()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetVendor(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 13:23:30 +00:00
|
|
|
aResult.Assign(gAppData->vendor);
|
2004-12-04 18:25:46 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetName(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 13:23:30 +00:00
|
|
|
aResult.Assign(gAppData->name);
|
2004-12-04 18:25:46 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-07 04:53:07 +00:00
|
|
|
NS_IMETHODIMP
|
2005-05-12 13:23:30 +00:00
|
|
|
nsXULAppInfo::GetID(nsACString& aResult)
|
2004-12-07 04:53:07 +00:00
|
|
|
{
|
2005-05-12 13:23:30 +00:00
|
|
|
aResult.Assign(gAppData->ID);
|
2004-12-07 04:53:07 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-04 18:25:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetVersion(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 13:23:30 +00:00
|
|
|
aResult.Assign(gAppData->version);
|
2004-12-04 18:25:46 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-14 20:29:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetPlatformVersion(nsACString& aResult)
|
|
|
|
{
|
2007-07-19 13:51:44 +00:00
|
|
|
aResult.Assign(gToolkitVersion);
|
2005-07-14 20:29:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-04 18:25:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetAppBuildID(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 13:23:30 +00:00
|
|
|
aResult.Assign(gAppData->buildID);
|
2004-12-04 18:25:46 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-07-14 20:29:06 +00:00
|
|
|
nsXULAppInfo::GetPlatformBuildID(nsACString& aResult)
|
2004-12-04 18:25:46 +00:00
|
|
|
{
|
2007-07-02 18:20:24 +00:00
|
|
|
aResult.Assign(gToolkitBuildID);
|
2004-12-04 18:25:46 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-07 19:28:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetLogConsoleErrors(PRBool *aResult)
|
|
|
|
{
|
|
|
|
*aResult = gLogConsoleErrors;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::SetLogConsoleErrors(PRBool aValue)
|
|
|
|
{
|
|
|
|
gLogConsoleErrors = aValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetInSafeMode(PRBool *aResult)
|
|
|
|
{
|
|
|
|
*aResult = gSafeMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-10 18:23:28 +00:00
|
|
|
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 13:53:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetWidgetToolkit(nsACString& aResult)
|
|
|
|
{
|
|
|
|
aResult.AssignLiteral(MOZ_WIDGET_TOOLKIT);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 17:09:51 +00: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) \
|
|
|
|
PR_STATIC_ASSERT(nsIXULRuntime::PROCESS_TYPE_ ## a == \
|
|
|
|
static_cast<int>(GeckoProcessType_ ## b));
|
|
|
|
|
|
|
|
SYNC_ENUMS(DEFAULT, Default)
|
|
|
|
SYNC_ENUMS(PLUGIN, Plugin)
|
|
|
|
SYNC_ENUMS(CONTENT, Content)
|
2010-06-25 15:00:35 +00:00
|
|
|
SYNC_ENUMS(JETPACK, Jetpack)
|
2009-10-06 18:02:26 +00:00
|
|
|
SYNC_ENUMS(IPDLUNITTEST, IPDLUnitTest)
|
2009-08-19 17:09:51 +00:00
|
|
|
|
|
|
|
// .. and ensure that that is all of them:
|
2009-10-06 18:02:26 +00:00
|
|
|
PR_STATIC_ASSERT(GeckoProcessType_IPDLUnitTest + 1 == GeckoProcessType_End);
|
2009-08-19 17:09:51 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetProcessType(PRUint32* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = XRE_GetProcessType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-30 18:43:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::EnsureContentProcess()
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
ContentParent* c = ContentParent::GetSingleton();
|
|
|
|
if (!c)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-16 06:32:29 +00: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);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
|
|
|
nsINIParser parser;
|
|
|
|
rv = parser.Init(localFile);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString buf;
|
|
|
|
rv = parser.GetString("Compatibility", "InvalidateCaches", buf);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PRFileDesc *fd = nsnull;
|
|
|
|
localFile->OpenNSPRFileDesc(PR_RDWR | PR_APPEND, 0600, &fd);
|
|
|
|
if (!fd) {
|
|
|
|
NS_ERROR("could not create output stream");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
static const char kInvalidationHeader[] = NS_LINEBREAK "InvalidateCaches=1" NS_LINEBREAK;
|
|
|
|
rv = PR_Write(fd, kInvalidationHeader, sizeof(kInvalidationHeader) - 1);
|
|
|
|
PR_Close(fd);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#ifdef XP_WIN
|
2007-09-20 16:54:00 +00: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
|
|
|
|
nsXULAppInfo::GetUserCanElevate(PRBool *aUserCanElevate)
|
|
|
|
{
|
|
|
|
HANDLE hToken;
|
|
|
|
|
|
|
|
VISTA_TOKEN_ELEVATION_TYPE elevationType;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
|
|
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken) ||
|
|
|
|
!GetTokenInformation(hToken, VistaTokenElevationType, &elevationType,
|
|
|
|
sizeof(elevationType), &dwSize)) {
|
|
|
|
*aUserCanElevate = PR_FALSE;
|
|
|
|
}
|
|
|
|
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-23 07:18:17 +00:00
|
|
|
// elevated)
|
2007-09-20 16:54:00 +00:00
|
|
|
*aUserCanElevate = (elevationType == VistaTokenElevationTypeLimited);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hToken)
|
|
|
|
CloseHandle(hToken);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-01-30 05:14:50 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2009-04-02 15:41:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetEnabled(PRBool *aEnabled)
|
|
|
|
{
|
|
|
|
*aEnabled = CrashReporter::GetEnabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::SetEnabled(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
if (aEnabled) {
|
|
|
|
if (CrashReporter::GetEnabled())
|
|
|
|
// no point in erroring for double-enabling
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> xreDirectory;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
nsCAutoString data;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
PRBool schemeOk;
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
nsCAutoString spec;
|
|
|
|
rv = aServerURL->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CrashReporter::SetServerURL(spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetMinidumpPath(nsILocalFile** aMinidumpPath)
|
|
|
|
{
|
|
|
|
if (!CrashReporter::GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsAutoString path;
|
|
|
|
if (!CrashReporter::GetMinidumpPath(path))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv = NS_NewLocalFile(path, PR_FALSE, aMinidumpPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::SetMinidumpPath(nsILocalFile* aMinidumpPath)
|
|
|
|
{
|
|
|
|
nsAutoString path;
|
|
|
|
nsresult rv = aMinidumpPath->GetPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return CrashReporter::SetMinidumpPath(path);
|
|
|
|
}
|
|
|
|
|
2007-04-10 19:15:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::AnnotateCrashReport(const nsACString& key,
|
|
|
|
const nsACString& data)
|
|
|
|
{
|
|
|
|
return CrashReporter::AnnotateCrashReport(key, data);
|
|
|
|
}
|
2008-02-09 02:40:47 +00:00
|
|
|
|
2008-07-27 17:08:03 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::AppendAppNotesToCrashReport(const nsACString& data)
|
|
|
|
{
|
|
|
|
return CrashReporter::AppendAppNotesToCrashReport(data);
|
|
|
|
}
|
|
|
|
|
2011-07-08 00:31:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::RegisterAppMemory(PRUint64 pointer,
|
|
|
|
PRUint64 len)
|
|
|
|
{
|
|
|
|
return CrashReporter::RegisterAppMemory((void *)pointer, len);
|
|
|
|
}
|
|
|
|
|
2008-02-09 02:40:47 +00: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 19:15:16 +00:00
|
|
|
|
2008-08-28 04:41:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::AppendObjCExceptionInfoToAppNotes(void* aException)
|
|
|
|
{
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
return CrashReporter::AppendObjCExceptionInfoToAppNotes(aException);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
2010-02-10 01:05:31 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetSubmitReports(PRBool* aEnabled)
|
|
|
|
{
|
|
|
|
return CrashReporter::GetSubmitReports(aEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::SetSubmitReports(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
return CrashReporter::SetSubmitReports(aEnabled);
|
|
|
|
}
|
|
|
|
|
2008-08-28 05:23:43 +00:00
|
|
|
#endif
|
2008-08-28 04:41:38 +00:00
|
|
|
|
2005-07-21 13:33:43 +00:00
|
|
|
static const nsXULAppInfo kAppInfo;
|
2010-06-10 18:11:11 +00:00
|
|
|
static nsresult AppInfoConstructor(nsISupports* aOuter,
|
|
|
|
REFNSIID aIID, void **aResult)
|
2004-12-04 18:25:46 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
return const_cast<nsXULAppInfo*>(&kAppInfo)->
|
2005-07-21 13:33:43 +00:00
|
|
|
QueryInterface(aIID, aResult);
|
2004-12-04 18:25:46 +00:00
|
|
|
}
|
|
|
|
|
2005-06-07 19:28:23 +00:00
|
|
|
PRBool gLogConsoleErrors
|
|
|
|
#ifdef DEBUG
|
|
|
|
= PR_TRUE;
|
|
|
|
#else
|
|
|
|
= PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NS_ENSURE_TRUE_LOG(x, ret) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (NS_UNLIKELY(!(x))) { \
|
|
|
|
NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \
|
|
|
|
gLogConsoleErrors = PR_TRUE; \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define NS_ENSURE_SUCCESS_LOG(res, ret) \
|
|
|
|
NS_ENSURE_TRUE_LOG(NS_SUCCEEDED(res), ret)
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2004-06-17 21:23:51 +00:00
|
|
|
public:
|
|
|
|
ScopedXPCOMStartup() :
|
|
|
|
mServiceManager(nsnull) { }
|
|
|
|
~ScopedXPCOMStartup();
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult Initialize();
|
|
|
|
nsresult SetWindowCreator(nsINativeAppSupport* native);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static nsresult CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
private:
|
|
|
|
nsIServiceManager* mServiceManager;
|
2010-06-10 18:11:11 +00:00
|
|
|
static nsINativeAppSupport* gNativeAppSupport;
|
2004-06-17 21:23:51 +00:00
|
|
|
};
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
ScopedXPCOMStartup::~ScopedXPCOMStartup()
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2010-06-23 00:11:32 +00:00
|
|
|
NS_IF_RELEASE(gNativeAppSupport);
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
if (mServiceManager) {
|
2010-04-21 08:29:38 +00: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 10:35:02 +00:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
if (appStartup)
|
|
|
|
appStartup->DestroyHiddenWindow();
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
gDirServiceProvider->DoShutdown();
|
|
|
|
|
2005-06-07 19:28:23 +00:00
|
|
|
WriteConsoleLog();
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ShutdownXPCOM(mServiceManager);
|
|
|
|
mServiceManager = nsnull;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-04 18:25:46 +00:00
|
|
|
// {95d89e3e-a169-41a3-8e56-719978e15b12}
|
2005-07-21 15:01:35 +00:00
|
|
|
#define APPINFO_CID \
|
|
|
|
{ 0x95d89e3e, 0xa169, 0x41a3, { 0x8e, 0x56, 0x71, 0x99, 0x78, 0xe1, 0x5b, 0x12 } }
|
2004-12-04 18:25:46 +00:00
|
|
|
|
2010-06-10 18:11:11 +00: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)
|
2005-07-21 13:33:43 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00: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-23 00:18:45 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-06-10 18:11:11 +00:00
|
|
|
{ NS_CRASHREPORTER_CONTRACTID, &kAPPINFO_CID },
|
2010-06-23 00:18:45 +00:00
|
|
|
#endif
|
2010-06-10 18:11:11 +00:00
|
|
|
{ NS_PROFILESERVICE_CONTRACTID, &kProfileServiceCID },
|
|
|
|
{ NS_NATIVEAPPSUPPORT_CONTRACTID, &kNativeAppSupportCID },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module kXREModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kXRECIDs,
|
|
|
|
kXREContracts
|
2005-07-21 13:33:43 +00:00
|
|
|
};
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NSMODULE_DEFN(Apprunner) = &kXREModule;
|
2005-07-21 13:33:43 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::Initialize()
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ASSERTION(gDirServiceProvider, "Should not get here!");
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult rv;
|
2010-05-21 17:58:32 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = NS_InitXPCOM2(&mServiceManager, gDirServiceProvider->GetAppDir(),
|
|
|
|
gDirServiceProvider);
|
2004-06-17 21:23:51 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Couldn't start xpcom!");
|
|
|
|
mServiceManager = nsnull;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-12-04 18:25:46 +00:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIComponentRegistrar> reg =
|
|
|
|
do_QueryInterface(mServiceManager);
|
|
|
|
NS_ASSERTION(reg, "Service Manager doesn't QI to Registrar.");
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return rv;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2004-11-08 05:00:27 +00:00
|
|
|
/**
|
|
|
|
* This is a little factory class that serves as a singleton-service-factory
|
|
|
|
* for the nativeappsupport object.
|
|
|
|
*/
|
|
|
|
class nsSingletonFactory : public nsIFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFACTORY
|
|
|
|
|
|
|
|
nsSingletonFactory(nsISupports* aSingleton);
|
2004-11-08 05:06:46 +00:00
|
|
|
~nsSingletonFactory() { }
|
2004-11-08 05:00:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
nsSingletonFactory::LockFactory(PRBool)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
/**
|
|
|
|
* Set our windowcreator on the WindowWatcher service.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native)
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION;
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult rv;
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_IF_ADDREF(gNativeAppSupport = native);
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
// Inform the chrome registry about OS accessibility
|
2010-05-14 09:24:41 +00:00
|
|
|
nsCOMPtr<nsIToolkitChromeRegistry> cr =
|
|
|
|
mozilla::services::GetToolkitChromeRegistryService();
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Got ToolkitChromeRegistry service");
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
if (cr)
|
|
|
|
cr->CheckForOSAccessibility();
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("OS Accessibility check");
|
|
|
|
|
2004-10-29 19:28:38 +00:00
|
|
|
nsCOMPtr<nsIWindowCreator> creator (do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
if (!creator) return NS_ERROR_UNEXPECTED;
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Got AppStartup service");
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsCOMPtr<nsIWindowWatcher> wwatch
|
|
|
|
(do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-05-19 23:22:19 +00:00
|
|
|
|
|
|
|
NS_TIME_FUNCTION_MARK("Got WindowWatcher service");
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return wwatch->SetWindowCreator(creator);
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00: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-02-20 19:42:12 +00:00
|
|
|
/**
|
2007-08-06 02:00:53 +00:00
|
|
|
* A helper class which calls NS_LogInit/NS_LogTerm in its scope.
|
2007-02-20 19:42:12 +00:00
|
|
|
*/
|
|
|
|
class ScopedLogging
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScopedLogging() { NS_LogInit(); }
|
|
|
|
~ScopedLogging() { NS_LogTerm(); }
|
|
|
|
};
|
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
static void DumpArbitraryHelp()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2007-02-20 19:42:12 +00:00
|
|
|
ScopedLogging log;
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
{
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
xpcom.Initialize();
|
|
|
|
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdline
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
if (!cmdline)
|
|
|
|
return;
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
nsCString text;
|
|
|
|
rv = cmdline->GetHelpText(text);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
printf("%s", text.get());
|
|
|
|
}
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
2007-01-04 18:28:49 +00:00
|
|
|
printf("Usage: %s [ options ... ] [URL]\n"
|
|
|
|
" where options include:\n\n", gArgv[0]);
|
2005-01-17 18:50:18 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2007-01-04 18:28:49 +00:00
|
|
|
printf("X11 options\n"
|
2009-10-09 10:50:42 +00:00
|
|
|
" --display=DISPLAY X display to use\n"
|
2011-03-31 08:40:25 +00:00
|
|
|
" --sync Make X calls synchronous\n");
|
2005-01-17 18:50:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XP_UNIX
|
2009-10-09 10:50:42 +00:00
|
|
|
printf(" --g-fatal-warnings Make all warnings fatal\n"
|
2008-08-29 21:12:52 +00:00
|
|
|
"\n%s options\n", gAppData->name);
|
2006-07-28 17:39:59 +00:00
|
|
|
#endif
|
2006-07-28 14:51:13 +00:00
|
|
|
|
2009-10-09 10:50:42 +00: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"
|
|
|
|
" -no-remote Open new instance, not a new window in running instance.\n"
|
|
|
|
" -UILocale <locale> Start with <locale> resources as UI Locale.\n"
|
|
|
|
" -safe-mode Disables extensions and themes for this session.\n", gAppData->name);
|
2007-01-04 18:28:49 +00:00
|
|
|
|
2005-03-07 18:28:40 +00:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2009-10-09 10:50:42 +00:00
|
|
|
printf(" -console Start %s with a debugging console.\n", gAppData->name);
|
2005-01-17 18:50:18 +00: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();
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#ifdef DEBUG_warren
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
#if defined(FREEBSD)
|
|
|
|
// pick up fpsetmask prototype.
|
|
|
|
#include <ieeefp.h>
|
2003-03-08 04:15:01 +00:00
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2007-01-04 18:28:49 +00:00
|
|
|
static inline void
|
2004-06-17 21:23:51 +00:00
|
|
|
DumpVersion()
|
|
|
|
{
|
2007-11-30 20:08:55 +00:00
|
|
|
printf("%s %s %s",
|
|
|
|
gAppData->vendor ? gAppData->vendor : "", gAppData->name, gAppData->version);
|
|
|
|
if (gAppData->copyright)
|
|
|
|
printf(", %s", gAppData->copyright);
|
|
|
|
printf("\n");
|
2004-06-17 21:23:51 +00: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
|
2007-02-09 01:33:26 +00:00
|
|
|
HandleRemoteArgument(const char* remote, const char* aDesktopStartupID)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
|
|
|
|
const char *profile = 0;
|
2005-05-12 13:23:30 +00:00
|
|
|
nsCAutoString program(gAppData->name);
|
2004-07-07 21:38:27 +00:00
|
|
|
ToLowerCase(program);
|
2004-06-17 21:23:51 +00:00
|
|
|
const char *username = getenv("LOGNAME");
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("p", PR_FALSE, &profile);
|
2004-06-17 21:23:51 +00:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -p requires a profile name\n");
|
|
|
|
return 1;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2004-07-07 21:38:27 +00:00
|
|
|
const char *temp = nsnull;
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("a", PR_FALSE, &temp);
|
2004-06-17 21:23:51 +00:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
|
|
|
return 1;
|
2004-07-07 21:38:27 +00:00
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
program.Assign(temp);
|
2003-03-08 04:15:01 +00:00
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("u", PR_FALSE, &username);
|
2004-06-17 21:23:51 +00:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -u requires a username\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
XRemoteClient client;
|
|
|
|
rv = client.Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: Failed to connect to X server.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
nsXPIDLCString response;
|
|
|
|
PRBool success = PR_FALSE;
|
|
|
|
rv = client.SendCommand(program.get(), username, profile, remote,
|
2007-02-09 01:33:26 +00:00
|
|
|
aDesktopStartupID, getter_Copies(response), &success);
|
2005-04-04 19:08:55 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
if (!success) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: No running window found\n");
|
|
|
|
return 2;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2007-08-20 05:09:07 +00:00
|
|
|
static RemoteResult
|
2007-02-09 01:33:26 +00:00
|
|
|
RemoteCommandLine(const char* aDesktopStartupID)
|
2005-04-04 19:08:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
nsCAutoString program(gAppData->name);
|
2005-04-04 19:08:55 +00:00
|
|
|
ToLowerCase(program);
|
|
|
|
const char *username = getenv("LOGNAME");
|
|
|
|
|
|
|
|
const char *temp = nsnull;
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("a", PR_TRUE, &temp);
|
2005-04-04 19:08:55 +00:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
2007-08-20 05:09:07 +00:00
|
|
|
return REMOTE_ARG_BAD;
|
2005-04-04 19:08:55 +00:00
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
program.Assign(temp);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("u", PR_TRUE, &username);
|
2005-04-04 19:08:55 +00:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -u requires a username\n");
|
2007-08-20 05:09:07 +00:00
|
|
|
return REMOTE_ARG_BAD;
|
2003-03-08 04:15:01 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
XRemoteClient client;
|
|
|
|
rv = client.Init();
|
|
|
|
if (NS_FAILED(rv))
|
2007-08-20 05:09:07 +00:00
|
|
|
return REMOTE_NOT_FOUND;
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
nsXPIDLCString response;
|
|
|
|
PRBool success = PR_FALSE;
|
|
|
|
rv = client.SendCommandLine(program.get(), username, nsnull,
|
2007-02-09 01:33:26 +00:00
|
|
|
gArgc, gArgv, aDesktopStartupID,
|
2005-04-04 19:08:55 +00:00
|
|
|
getter_Copies(response), &success);
|
|
|
|
// did the command fail?
|
|
|
|
if (NS_FAILED(rv) || !success)
|
2007-08-20 05:09:07 +00:00
|
|
|
return REMOTE_NOT_FOUND;
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2007-08-20 05:09:07 +00:00
|
|
|
return REMOTE_FOUND;
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
#endif // MOZ_ENABLE_XREMOTE
|
2003-03-08 04:15:01 +00:00
|
|
|
|
2011-06-27 02:05:51 +00:00
|
|
|
void
|
|
|
|
XRE_InitOmnijar(nsILocalFile* greOmni, nsILocalFile* appOmni)
|
|
|
|
{
|
|
|
|
mozilla::Omnijar::Init(greOmni, appOmni);
|
|
|
|
}
|
|
|
|
|
2005-06-13 16:45:22 +00:00
|
|
|
nsresult
|
|
|
|
XRE_GetBinaryPath(const char* argv0, nsILocalFile* *aResult)
|
2005-06-10 21:01:40 +00:00
|
|
|
{
|
2011-05-22 06:23:20 +00:00
|
|
|
return mozilla::BinaryPath::GetFile(argv0, aResult);
|
2005-06-13 16:45:22 +00:00
|
|
|
}
|
2005-06-10 19:21:27 +00:00
|
|
|
|
2005-06-13 16:45:22 +00:00
|
|
|
#define NS_ERROR_LAUNCHED_CHILD_PROCESS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_PROFILE, 200)
|
|
|
|
|
2005-08-31 17:50:32 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsWindowsRestart.cpp"
|
2009-01-02 00:18:33 +00:00
|
|
|
#include <shellapi.h>
|
2011-01-23 10:45:00 +00:00
|
|
|
|
|
|
|
typedef BOOL (WINAPI* SetProcessDEPPolicyFunc)(DWORD dwFlags);
|
2005-08-31 17:50:32 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-11 11:49:03 +00:00
|
|
|
#if defined(XP_OS2) && (__KLIBC__ == 0 && __KLIBC_MINOR__ >= 6) // broken kLibc
|
2007-07-20 18:57:22 +00: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
|
|
|
|
|
2005-06-20 23:18:00 +00: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,
|
2008-06-23 19:06:37 +00:00
|
|
|
PRBool aBlankCommandLine = PR_FALSE)
|
2005-06-13 16:45:22 +00: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.
|
2005-06-20 23:18:00 +00:00
|
|
|
|
|
|
|
if (aBlankCommandLine) {
|
2010-07-17 06:52:23 +00:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
// Remove only arguments not given to Qt
|
|
|
|
gRestartArgc = gQtOnlyArgc;
|
|
|
|
gRestartArgv = gQtOnlyArgv;
|
|
|
|
#else
|
2007-10-13 05:47:04 +00:00
|
|
|
gRestartArgc = 1;
|
2005-06-20 23:18:00 +00:00
|
|
|
gRestartArgv[gRestartArgc] = nsnull;
|
2010-07-17 06:52:23 +00:00
|
|
|
#endif
|
2005-06-20 23:18:00 +00:00
|
|
|
}
|
2005-06-13 16:45:22 +00:00
|
|
|
|
2010-04-19 08:29:18 +00:00
|
|
|
SaveToEnv("MOZ_LAUNCHED_CHILD=1");
|
2006-07-19 21:08:19 +00:00
|
|
|
|
2010-06-04 01:16:20 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
mozilla::AndroidBridge::Bridge()->ScheduleRestart();
|
|
|
|
#else
|
2005-06-13 16:45:22 +00:00
|
|
|
#if defined(XP_MACOSX)
|
2010-06-08 22:26:12 +00:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
|
2011-02-07 18:32:52 +00:00
|
|
|
PRUint32 restartMode = 0;
|
|
|
|
restartMode = gRestartMode;
|
|
|
|
LaunchChildMac(gRestartArgc, gRestartArgv, restartMode);
|
2005-06-13 16:45:22 +00:00
|
|
|
#else
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
|
|
|
nsresult rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-12-31 15:15:43 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
nsAutoString exePath;
|
|
|
|
rv = lf->GetPath(exePath);
|
2005-06-13 16:45:22 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-01-02 00:18:33 +00:00
|
|
|
if (!WinLaunchChild(exePath.get(), gRestartArgc, gRestartArgv))
|
2005-06-13 16:45:22 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-31 15:15:43 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
nsCAutoString exePath;
|
|
|
|
rv = lf->GetNativePath(exePath);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2008-10-11 11:49:03 +00: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 18:57:22 +00:00
|
|
|
if (OS2LaunchChild(exePath.get(), gRestartArgc, gRestartArgv) == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-06-13 16:45:22 +00:00
|
|
|
#elif defined(XP_OS2)
|
|
|
|
if (_execv(exePath.get(), gRestartArgv) == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-17 21:23:51 +00:00
|
|
|
#elif defined(XP_UNIX)
|
2005-06-13 16:45:22 +00:00
|
|
|
if (execv(exePath.get(), gRestartArgv) == -1)
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#else
|
2005-06-13 16:45:22 +00:00
|
|
|
PRProcess* process = PR_CreateProcess(exePath.get(), gRestartArgv,
|
2004-06-17 21:23:51 +00:00
|
|
|
nsnull, nsnull);
|
|
|
|
if (!process) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 exitCode;
|
|
|
|
PRStatus failed = PR_WaitProcess(process, &exitCode);
|
|
|
|
if (failed || exitCode)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-31 15:15:43 +00:00
|
|
|
#endif // XP_OS2 series
|
|
|
|
#endif // WP_WIN
|
|
|
|
#endif // WP_MACOSX
|
2010-06-04 01:16:20 +00:00
|
|
|
#endif // ANDROID
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_ERROR_LAUNCHED_CHILD_PROCESS;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2005-03-15 20:01:12 +00:00
|
|
|
static const char kProfileProperties[] =
|
|
|
|
"chrome://mozapps/locale/profile/profileSelection.properties";
|
|
|
|
|
|
|
|
static nsresult
|
2005-04-26 00:37:23 +00:00
|
|
|
ProfileLockedDialog(nsILocalFile* aProfileDir, nsILocalFile* aProfileLocalDir,
|
|
|
|
nsIProfileUnlocker* aUnlocker,
|
2005-03-15 20:01:12 +00:00
|
|
|
nsINativeAppSupport* aNative, nsIProfileLock* *aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = xpcom.SetWindowCreator(aNative);
|
2005-03-15 20:01:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
{ //extra scoping is needed so we release these components before xpcom shutdown
|
2010-05-14 09:24:41 +00:00
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2005-03-15 20:01:12 +00:00
|
|
|
NS_ENSURE_TRUE(sbs, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> sb;
|
|
|
|
sbs->CreateBundle(kProfileProperties, getter_AddRefs(sb));
|
2005-06-07 19:28:23 +00:00
|
|
|
NS_ENSURE_TRUE_LOG(sbs, NS_ERROR_FAILURE);
|
2005-03-15 20:01:12 +00:00
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
NS_ConvertUTF8toUTF16 appName(gAppData->name);
|
2005-03-15 20:01:12 +00:00
|
|
|
const PRUnichar* params[] = {appName.get(), appName.get()};
|
|
|
|
|
|
|
|
nsXPIDLString killMessage;
|
2006-07-20 15:35:22 +00:00
|
|
|
#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
|
2005-07-29 15:54:34 +00:00
|
|
|
|
|
|
|
sb->FormatStringFromName(aUnlocker ? kRestartUnlocker : kRestartNoUnlocker,
|
2005-03-15 20:01:12 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
PRUint32 flags = nsIPromptService::BUTTON_TITLE_OK * nsIPromptService::BUTTON_POS_0;
|
|
|
|
|
|
|
|
if (aUnlocker) {
|
|
|
|
flags =
|
|
|
|
nsIPromptService::BUTTON_TITLE_CANCEL * nsIPromptService::BUTTON_POS_0 +
|
|
|
|
nsIPromptService::BUTTON_TITLE_IS_STRING * nsIPromptService::BUTTON_POS_1 +
|
|
|
|
nsIPromptService::BUTTON_POS_1_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 button;
|
2011-06-07 18:06:12 +00:00
|
|
|
// The actual value is irrelevant but we shouldn't be handing out
|
|
|
|
// malformed JSBools to XPConnect.
|
|
|
|
PRBool checkState = PR_FALSE;
|
2005-03-15 20:01:12 +00:00
|
|
|
rv = ps->ConfirmEx(nsnull, killTitle, killMessage, flags,
|
2009-06-11 17:09:34 +00:00
|
|
|
killTitle, nsnull, nsnull, nsnull, &checkState, &button);
|
2005-06-07 19:28:23 +00:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2005-03-15 20:01:12 +00:00
|
|
|
|
|
|
|
if (button == 1 && aUnlocker) {
|
|
|
|
rv = aUnlocker->Unlock(nsIProfileUnlocker::FORCE_QUIT);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
return NS_LockProfilePath(aProfileDir, aProfileLocalDir, nsnull, aResult);
|
2005-03-15 20:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-06 15:40:33 +00:00
|
|
|
static nsresult
|
|
|
|
ProfileMissingDialog(nsINativeAppSupport* aNative)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = xpcom.SetWindowCreator(aNative);
|
2010-03-06 15:40:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
{ //extra scoping is needed so we release these components before xpcom shutdown
|
2010-05-14 09:24:41 +00:00
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2010-03-06 15:40:33 +00: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);
|
|
|
|
|
|
|
|
ps->Alert(nsnull, missingTitle, missingMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-15 20:01:12 +00:00
|
|
|
static const char kProfileManagerURL[] =
|
|
|
|
"chrome://mozapps/content/profile/profileSelection.xul";
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
static nsresult
|
|
|
|
ShowProfileManager(nsIToolkitProfileService* aProfileSvc,
|
|
|
|
nsINativeAppSupport* aNative)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
nsCOMPtr<nsILocalFile> profD, profLD;
|
2007-06-30 05:02:49 +00:00
|
|
|
PRUnichar* profileNamePtr;
|
|
|
|
nsCAutoString profileName;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = xpcom.SetWindowCreator(aNative);
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
2006-07-19 21:08:19 +00:00
|
|
|
#ifdef XP_MACOSX
|
2010-06-08 22:26:12 +00:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
|
2006-07-19 21:08:19 +00:00
|
|
|
#endif
|
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#ifdef XP_WIN
|
2008-06-21 00:21:21 +00:00
|
|
|
// we don't have to wait here because profile manager window will pump
|
|
|
|
// and DDE message will be handled
|
|
|
|
ProcessDDE(aNative, PR_FALSE);
|
2007-01-30 05:14:50 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
{ //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);
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
ioParamBlock->SetObjects(dlgArray);
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-10-29 19:28:38 +00:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup
|
|
|
|
(do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> newWindow;
|
|
|
|
rv = windowWatcher->OpenWindow(nsnull,
|
|
|
|
kProfileManagerURL,
|
|
|
|
"_blank",
|
|
|
|
"centerscreen,chrome,modal,titlebar",
|
|
|
|
ioParamBlock,
|
|
|
|
getter_AddRefs(newWindow));
|
|
|
|
|
2005-06-07 19:28:23 +00:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
aProfileSvc->Flush();
|
|
|
|
|
|
|
|
PRInt32 dialogConfirmed;
|
|
|
|
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));
|
2005-06-07 19:28:23 +00:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
rv = lock->GetDirectory(getter_AddRefs(profD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = lock->GetLocalDirectory(getter_AddRefs(profLD));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-06-30 05:02:49 +00:00
|
|
|
rv = ioParamBlock->GetString(0, &profileNamePtr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
CopyUTF16toUTF8(profileNamePtr, profileName);
|
|
|
|
NS_Free(profileNamePtr);
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
lock->Unlock();
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 18:55:27 +00:00
|
|
|
SaveFileToEnv("XRE_PROFILE_PATH", profD);
|
|
|
|
SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", profLD);
|
2007-06-30 05:02:49 +00:00
|
|
|
SaveWordToEnv("XRE_PROFILE_NAME", profileName);
|
2003-09-24 05:28:13 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
PRBool offline = PR_FALSE;
|
|
|
|
aProfileSvc->GetStartOffline(&offline);
|
|
|
|
if (offline) {
|
2010-04-19 08:29:18 +00:00
|
|
|
SaveToEnv("XRE_START_OFFLINE=1");
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2003-09-24 05:28:13 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return LaunchChild(aNative);
|
2003-09-24 05:28:13 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
static nsresult
|
|
|
|
ImportProfiles(nsIToolkitProfileService* aPService,
|
|
|
|
nsINativeAppSupport* aNative)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult rv;
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2010-04-19 08:29:18 +00:00
|
|
|
SaveToEnv("XRE_IMPORT_PROFILES=1");
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
// try to import old-style profiles
|
|
|
|
{ // scope XPCOM
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-07-19 21:08:19 +00:00
|
|
|
#ifdef XP_MACOSX
|
2010-06-08 22:26:12 +00:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
|
2006-07-19 21:08:19 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsCOMPtr<nsIProfileMigrator> migrator
|
|
|
|
(do_GetService(NS_PROFILEMIGRATOR_CONTRACTID));
|
|
|
|
if (migrator) {
|
|
|
|
migrator->Import();
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
aPService->Flush();
|
|
|
|
return LaunchChild(aNative);
|
|
|
|
}
|
2004-04-13 04:50:19 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
// 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
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
static PRBool gDoMigration = PR_FALSE;
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
SelectProfile(nsIProfileLock* *aResult, nsINativeAppSupport* aNative,
|
2007-06-30 05:02:49 +00:00
|
|
|
PRBool* aStartOffline, nsACString* aProfileName)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
2004-04-08 14:01:17 +00:00
|
|
|
nsresult rv;
|
2004-06-17 21:23:51 +00:00
|
|
|
ArgResult ar;
|
|
|
|
const char* arg;
|
|
|
|
*aResult = nsnull;
|
|
|
|
*aStartOffline = PR_FALSE;
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("offline", PR_TRUE);
|
|
|
|
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 17:28:18 +00:00
|
|
|
if (ar || EnvHasValue("XRE_START_OFFLINE"))
|
2004-06-17 21:23:51 +00:00
|
|
|
*aStartOffline = PR_TRUE;
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
|
2007-12-31 15:15:43 +00:00
|
|
|
nsCOMPtr<nsILocalFile> lf = GetFileFromEnv("XRE_PROFILE_PATH");
|
|
|
|
if (lf) {
|
|
|
|
nsCOMPtr<nsILocalFile> localDir =
|
|
|
|
GetFileFromEnv("XRE_PROFILE_LOCAL_PATH");
|
|
|
|
if (!localDir) {
|
2005-04-26 00:37:23 +00:00
|
|
|
localDir = lf;
|
|
|
|
}
|
|
|
|
|
2007-06-30 05:02:49 +00:00
|
|
|
arg = PR_GetEnv("XRE_PROFILE_NAME");
|
|
|
|
if (arg && *arg && aProfileName)
|
|
|
|
aProfileName->Assign(nsDependentCString(arg));
|
|
|
|
|
2005-07-25 22:16:56 +00:00
|
|
|
// Clear out flags that we handled (or should have handled!) last startup.
|
2005-07-25 22:41:54 +00:00
|
|
|
const char *dummy;
|
2007-07-11 05:59:56 +00:00
|
|
|
CheckArg("p", PR_FALSE, &dummy);
|
|
|
|
CheckArg("profile", PR_FALSE, &dummy);
|
2005-08-31 17:50:32 +00:00
|
|
|
CheckArg("profilemanager");
|
2005-07-25 22:16:56 +00:00
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
return NS_LockProfilePath(lf, localDir, nsnull, aResult);
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("migration", PR_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) {
|
2004-06-17 21:23:51 +00:00
|
|
|
gDoMigration = PR_TRUE;
|
2007-07-11 05:59:56 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("profile", PR_TRUE, &arg);
|
2004-06-17 21:23:51 +00:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -profile requires a path\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
if (ar) {
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
2005-03-18 21:24:05 +00:00
|
|
|
rv = XRE_GetFileFromPath(arg, getter_AddRefs(lf));
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2005-03-15 20:01:12 +00:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
|
2009-12-02 19:00:56 +00:00
|
|
|
// Check if the profile path exists and it's a directory.
|
|
|
|
PRBool exists;
|
|
|
|
lf->Exists(&exists);
|
|
|
|
if (!exists) {
|
2010-09-10 02:08:25 +00:00
|
|
|
rv = lf->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2009-12-02 19:00:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2005-04-26 00:37:23 +00: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);
|
2005-03-15 20:01:12 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
return ProfileLockedDialog(lf, lf, unlocker, aNative, aResult);
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsCOMPtr<nsIToolkitProfileService> profileSvc;
|
|
|
|
rv = NS_NewToolkitProfileService(getter_AddRefs(profileSvc));
|
2010-03-06 15:40:33 +00:00
|
|
|
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");
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("createprofile", PR_TRUE, &arg);
|
2004-06-17 21:23:51 +00: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;
|
2004-07-03 16:41:17 +00:00
|
|
|
|
|
|
|
const char* delim = strchr(arg, ' ');
|
|
|
|
if (delim) {
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(delim + 1),
|
|
|
|
PR_TRUE, getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv)) {
|
2006-11-03 23:04:10 +00:00
|
|
|
PR_fprintf(PR_STDERR, "Error: profile path not valid.\n");
|
2004-07-03 16:41:17 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
// As with -profile, assume that the given path will be used for both the
|
|
|
|
// main profile directory and the temp profile directory.
|
|
|
|
rv = profileSvc->CreateProfile(lf, lf, nsDependentCSubstring(arg, delim),
|
2004-07-03 16:41:17 +00:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
} else {
|
2005-04-26 00:37:23 +00:00
|
|
|
rv = profileSvc->CreateProfile(nsnull, nsnull, nsDependentCString(arg),
|
2004-07-03 16:41:17 +00:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
}
|
2006-11-03 23:04:10 +00:00
|
|
|
// Some pathological arguments can make it this far
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error creating profile.\n");
|
|
|
|
return rv;
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
2006-11-03 23:04:10 +00:00
|
|
|
rv = NS_ERROR_ABORT;
|
2004-06-17 21:23:51 +00:00
|
|
|
profileSvc->Flush();
|
|
|
|
|
|
|
|
// XXXben need to ensure prefs.js exists here so the tinderboxes will
|
|
|
|
// not go orange.
|
|
|
|
nsCOMPtr<nsILocalFile> prefsJSFile;
|
|
|
|
profile->GetRootDir(getter_AddRefs(prefsJSFile));
|
|
|
|
prefsJSFile->AppendNative(NS_LITERAL_CSTRING("prefs.js"));
|
2007-04-26 02:56:25 +00:00
|
|
|
nsCAutoString pathStr;
|
|
|
|
prefsJSFile->GetNativePath(pathStr);
|
|
|
|
PR_fprintf(PR_STDERR, "Success: created profile '%s' at '%s'\n", arg, pathStr.get());
|
2004-06-17 21:23:51 +00:00
|
|
|
PRBool exists;
|
|
|
|
prefsJSFile->Exists(&exists);
|
|
|
|
if (!exists)
|
|
|
|
prefsJSFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
2005-04-26 00:37:23 +00:00
|
|
|
// XXXdarin perhaps 0600 would be better?
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
rv = profileSvc->GetProfileCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR) {
|
2011-03-23 17:28:18 +00:00
|
|
|
if (!count && !EnvHasValue("XRE_IMPORT_PROFILES")) {
|
2005-04-26 00:37:23 +00:00
|
|
|
return ImportProfiles(profileSvc, aNative);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("p", PR_FALSE, &arg);
|
2004-06-17 21:23:51 +00:00
|
|
|
if (ar == ARG_BAD) {
|
2007-07-11 05:59:56 +00: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;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
|
|
|
}
|
|
|
|
if (ar) {
|
2007-07-11 05:59:56 +00: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;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
rv = profileSvc->GetProfileByName(nsDependentCString(arg),
|
|
|
|
getter_AddRefs(profile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-03-15 20:01:12 +00:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
rv = profile->Lock(nsnull, aResult);
|
2007-06-30 05:02:49 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aProfileName)
|
|
|
|
aProfileName->Assign(nsDependentCString(arg));
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_OK;
|
2007-06-30 05:02:49 +00:00
|
|
|
}
|
2005-03-15 20:01:12 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> profileDir;
|
|
|
|
rv = profile->GetRootDir(getter_AddRefs(profileDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
nsCOMPtr<nsILocalFile> profileLocalDir;
|
|
|
|
rv = profile->GetLocalDir(getter_AddRefs(profileLocalDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return ProfileLockedDialog(profileDir, profileLocalDir, unlocker,
|
|
|
|
aNative, aResult);
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("profilemanager", PR_TRUE);
|
|
|
|
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) {
|
2004-06-17 21:23:51 +00:00
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-04-08 14:01:17 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
if (!count) {
|
|
|
|
gDoMigration = PR_TRUE;
|
|
|
|
|
|
|
|
// create a default profile
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
nsresult rv = profileSvc->CreateProfile(nsnull, // choose a default dir for us
|
2005-04-26 00:37:23 +00:00
|
|
|
nsnull, // choose a default dir for us
|
2004-06-17 21:23:51 +00:00
|
|
|
NS_LITERAL_CSTRING("default"),
|
|
|
|
getter_AddRefs(profile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
profileSvc->Flush();
|
2005-03-15 20:01:12 +00:00
|
|
|
rv = profile->Lock(nsnull, aResult);
|
2007-06-30 05:02:49 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aProfileName)
|
|
|
|
aProfileName->Assign(NS_LITERAL_CSTRING("default"));
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_OK;
|
2007-06-30 05:02:49 +00:00
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool useDefault = PR_TRUE;
|
|
|
|
if (count > 1)
|
|
|
|
profileSvc->GetStartWithLastProfile(&useDefault);
|
|
|
|
|
|
|
|
if (useDefault) {
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
// GetSelectedProfile will auto-select the only profile if there's just one
|
|
|
|
profileSvc->GetSelectedProfile(getter_AddRefs(profile));
|
|
|
|
if (profile) {
|
2005-03-15 20:01:12 +00:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
rv = profile->Lock(getter_AddRefs(unlocker), aResult);
|
2007-06-30 05:02:49 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Try to grab the profile name.
|
|
|
|
if (aProfileName) {
|
|
|
|
rv = profile->GetName(*aProfileName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aProfileName->Truncate(0);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_OK;
|
2007-06-30 05:02:49 +00:00
|
|
|
}
|
2005-03-15 20:01:12 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> profileDir;
|
|
|
|
rv = profile->GetRootDir(getter_AddRefs(profileDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
nsCOMPtr<nsILocalFile> profileLocalDir;
|
|
|
|
rv = profile->GetRootDir(getter_AddRefs(profileLocalDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return ProfileLockedDialog(profileDir, profileLocalDir, unlocker,
|
|
|
|
aNative, aResult);
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 06:32:29 +00: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,
|
|
|
|
* we return PR_FALSE; otherwise, we return PR_TRUE. We also write the status
|
|
|
|
* of the caches (valid/invalid) into the return param aCachesOK. The aCachesOK
|
|
|
|
* is always invalid if the application has been updated.
|
|
|
|
*/
|
2005-07-23 14:00:07 +00:00
|
|
|
static PRBool
|
|
|
|
CheckCompatibility(nsIFile* aProfileDir, const nsCString& aVersion,
|
2006-02-15 03:14:27 +00:00
|
|
|
const nsCString& aOSABI, nsIFile* aXULRunnerDir,
|
2010-07-02 23:59:17 +00:00
|
|
|
nsIFile* aAppDir, nsILocalFile* aFlagFile,
|
|
|
|
PRBool* aCachesOK)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2010-07-02 23:59:17 +00:00
|
|
|
*aCachesOK = PR_FALSE;
|
2004-12-07 08:10:39 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
2005-07-23 14:00:07 +00:00
|
|
|
return PR_FALSE;
|
2004-12-07 08:10:39 +00:00
|
|
|
file->AppendNative(FILE_COMPATIBILITY_INFO);
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsINIParser parser;
|
2004-12-07 08:10:39 +00:00
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
|
|
|
nsresult rv = parser.Init(localFile);
|
|
|
|
if (NS_FAILED(rv))
|
2005-07-23 14:00:07 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-08-15 18:29:55 +00:00
|
|
|
nsCAutoString buf;
|
|
|
|
rv = parser.GetString("Compatibility", "LastVersion", buf);
|
2006-02-15 03:14:27 +00:00
|
|
|
if (NS_FAILED(rv) || !aVersion.Equals(buf))
|
2005-07-23 14:00:07 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2006-02-15 03:14:27 +00:00
|
|
|
rv = parser.GetString("Compatibility", "LastOSABI", buf);
|
|
|
|
if (NS_FAILED(rv) || !aOSABI.Equals(buf))
|
2005-07-23 14:00:07 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-08-15 18:29:55 +00:00
|
|
|
rv = parser.GetString("Compatibility", "LastPlatformDir", buf);
|
2005-07-23 14:00:07 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
2005-08-15 18:29:55 +00:00
|
|
|
rv = NS_NewNativeLocalFile(buf, PR_FALSE,
|
2005-07-23 14:00:07 +00:00
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool eq;
|
|
|
|
rv = lf->Equals(aXULRunnerDir, &eq);
|
|
|
|
if (NS_FAILED(rv) || !eq)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aAppDir) {
|
2005-08-15 18:29:55 +00:00
|
|
|
rv = parser.GetString("Compatibility", "LastAppDir", buf);
|
2005-07-23 14:00:07 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-08-15 18:29:55 +00:00
|
|
|
rv = NS_NewNativeLocalFile(buf, PR_FALSE,
|
2005-07-23 14:00:07 +00:00
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-07-27 20:49:34 +00:00
|
|
|
rv = lf->Equals(aAppDir, &eq);
|
2005-07-23 14:00:07 +00:00
|
|
|
if (NS_FAILED(rv) || !eq)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-16 06:32:29 +00:00
|
|
|
// If we see this flag, caches are invalid.
|
2010-07-02 23:59:17 +00:00
|
|
|
rv = parser.GetString("Compatibility", "InvalidateCaches", buf);
|
2009-10-16 06:32:29 +00:00
|
|
|
*aCachesOK = (NS_FAILED(rv) || !buf.EqualsLiteral("1"));
|
2010-07-02 23:59:17 +00:00
|
|
|
|
|
|
|
PRBool purgeCaches = PR_FALSE;
|
|
|
|
if (aFlagFile) {
|
|
|
|
aFlagFile->Exists(&purgeCaches);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aCachesOK = !purgeCaches && *aCachesOK;
|
2005-07-23 14:00:07 +00:00
|
|
|
return PR_TRUE;
|
2002-08-21 10:25:54 +00:00
|
|
|
}
|
|
|
|
|
2004-12-07 08:10:39 +00:00
|
|
|
static void BuildVersion(nsCString &aBuf)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
2005-05-12 13:23:30 +00:00
|
|
|
aBuf.Assign(gAppData->version);
|
2004-12-07 08:10:39 +00:00
|
|
|
aBuf.Append('_');
|
2005-05-12 13:23:30 +00:00
|
|
|
aBuf.Append(gAppData->buildID);
|
2004-12-07 08:10:39 +00:00
|
|
|
aBuf.Append('/');
|
2007-07-02 18:20:24 +00:00
|
|
|
aBuf.Append(gToolkitBuildID);
|
2004-12-07 08:10:39 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-07-23 14:00:07 +00:00
|
|
|
static void
|
|
|
|
WriteVersion(nsIFile* aProfileDir, const nsCString& aVersion,
|
2006-02-15 03:14:27 +00:00
|
|
|
const nsCString& aOSABI, nsIFile* aXULRunnerDir,
|
|
|
|
nsIFile* aAppDir)
|
2004-12-07 08:10:39 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
file->AppendNative(FILE_COMPATIBILITY_INFO);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf = do_QueryInterface(file);
|
|
|
|
|
2005-07-23 14:00:07 +00:00
|
|
|
nsCAutoString platformDir;
|
|
|
|
aXULRunnerDir->GetNativePath(platformDir);
|
|
|
|
|
|
|
|
nsCAutoString appDir;
|
|
|
|
if (aAppDir)
|
|
|
|
aAppDir->GetNativePath(appDir);
|
|
|
|
|
2004-12-07 08:10:39 +00:00
|
|
|
PRFileDesc *fd = nsnull;
|
|
|
|
lf->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0600, &fd);
|
|
|
|
if (!fd) {
|
|
|
|
NS_ERROR("could not create output stream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-23 14:00:07 +00:00
|
|
|
static const char kHeader[] = "[Compatibility]" NS_LINEBREAK
|
|
|
|
"LastVersion=";
|
|
|
|
|
|
|
|
PR_Write(fd, kHeader, sizeof(kHeader) - 1);
|
|
|
|
PR_Write(fd, aVersion.get(), aVersion.Length());
|
|
|
|
|
2006-02-15 03:14:27 +00:00
|
|
|
static const char kOSABIHeader[] = NS_LINEBREAK "LastOSABI=";
|
|
|
|
PR_Write(fd, kOSABIHeader, sizeof(kOSABIHeader) - 1);
|
|
|
|
PR_Write(fd, aOSABI.get(), aOSABI.Length());
|
|
|
|
|
2005-07-23 14:00:07 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char kNL[] = NS_LINEBREAK;
|
|
|
|
PR_Write(fd, kNL, sizeof(kNL) - 1);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2004-12-07 08:10:39 +00:00
|
|
|
PR_Close(fd);
|
|
|
|
}
|
|
|
|
|
2005-07-23 14:00:07 +00:00
|
|
|
static void RemoveComponentRegistries(nsIFile* aProfileDir, nsIFile* aLocalProfileDir,
|
|
|
|
PRBool aRemoveEMFiles)
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
2004-12-07 08:10:39 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
2005-07-23 14:00:07 +00:00
|
|
|
if (aRemoveEMFiles) {
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("extensions.ini"));
|
|
|
|
file->Remove(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
aLocalProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
2011-06-17 22:53:52 +00: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
|
|
|
|
|
2005-05-12 13:23:30 +00:00
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("XUL" PLATFORM_FASL_SUFFIX));
|
|
|
|
file->Remove(PR_FALSE);
|
2009-10-16 06:32:29 +00:00
|
|
|
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("XPC" PLATFORM_FASL_SUFFIX));
|
|
|
|
file->Remove(PR_FALSE);
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("startupCache"));
|
|
|
|
file->Remove(PR_TRUE);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 05:47:04 +00: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.
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
char *value;
|
|
|
|
} gSavedVars[] = {
|
|
|
|
{"XUL_APP_FILE", nsnull}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void SaveStateForAppInitiatedRestart()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < NS_ARRAY_LENGTH(gSavedVars); ++i) {
|
|
|
|
const char *s = PR_GetEnv(gSavedVars[i].name);
|
|
|
|
if (s)
|
|
|
|
gSavedVars[i].value = PR_smprintf("%s=%s", gSavedVars[i].name, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RestoreStateForAppInitiatedRestart()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < NS_ARRAY_LENGTH(gSavedVars); ++i) {
|
|
|
|
if (gSavedVars[i].value)
|
|
|
|
PR_SetEnv(gSavedVars[i].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
// When we first initialize the crash reporter we don't have a profile,
|
2006-10-26 22:52:30 +00: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;
|
|
|
|
nsresult rv = profD->Clone(getter_AddRefs(dumpD));
|
|
|
|
|
|
|
|
if(dumpD) {
|
|
|
|
PRBool fileExists;
|
|
|
|
//XXX: do some more error checking here
|
|
|
|
dumpD->Append(NS_LITERAL_STRING("minidumps"));
|
|
|
|
rv = dumpD->Exists(&fileExists);
|
|
|
|
if(!fileExists) {
|
|
|
|
dumpD->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString pathStr;
|
|
|
|
if(NS_SUCCEEDED(dumpD->GetPath(pathStr)))
|
2007-03-27 18:02:02 +00:00
|
|
|
CrashReporter::SetMinidumpPath(pathStr);
|
2006-10-26 22:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
const nsXREAppData* gAppData = nsnull;
|
|
|
|
|
|
|
|
#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); }
|
|
|
|
};
|
2003-03-08 04:15:01 +00:00
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2005-03-07 22:40:36 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
#include "prlink.h"
|
|
|
|
typedef void (*_g_set_application_name_fn)(const gchar *application_name);
|
2007-02-09 01:33:26 +00:00
|
|
|
typedef void (*_gtk_window_set_auto_startup_notification_fn)(gboolean setting);
|
|
|
|
|
|
|
|
static PRFuncPtr FindFunction(const char* aName)
|
|
|
|
{
|
|
|
|
PRLibrary *lib = nsnull;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIWidget* GetMainWidget(nsIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
// get the native window for this instance
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aWindow));
|
|
|
|
NS_ENSURE_TRUE(window, nsnull);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow
|
|
|
|
(do_QueryInterface(window->GetDocShell()));
|
|
|
|
NS_ENSURE_TRUE(baseWindow, nsnull);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
|
|
|
|
return mainWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsGTKToolkit* GetGTKToolkit()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAppShellService> svc = do_GetService(NS_APPSHELLSERVICE_CONTRACTID);
|
|
|
|
if (!svc)
|
|
|
|
return nsnull;
|
2011-07-15 10:31:34 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
2007-02-09 01:33:26 +00:00
|
|
|
svc->GetHiddenDOMWindow(getter_AddRefs(window));
|
|
|
|
if (!window)
|
|
|
|
return nsnull;
|
|
|
|
nsIWidget* widget = GetMainWidget(window);
|
|
|
|
if (!widget)
|
|
|
|
return nsnull;
|
|
|
|
nsIToolkit* toolkit = widget->GetToolkit();
|
|
|
|
if (!toolkit)
|
|
|
|
return nsnull;
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<nsGTKToolkit*>(toolkit);
|
2007-02-09 01:33:26 +00:00
|
|
|
}
|
|
|
|
|
2007-10-03 21:44:05 +00:00
|
|
|
static void MOZ_gdk_display_close(GdkDisplay *display)
|
|
|
|
{
|
2008-04-09 06:42:49 +00: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.
|
|
|
|
PRBool theme_is_qt = PR_FALSE;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-03 21:44:05 +00:00
|
|
|
// gdk_display_close was broken prior to gtk+-2.10.0.
|
|
|
|
// (http://bugzilla.gnome.org/show_bug.cgi?id=85715)
|
|
|
|
// gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL)
|
|
|
|
// was also broken.
|
2008-04-09 06:42:49 +00:00
|
|
|
if (gtk_check_version(2,10,0) != NULL) {
|
2008-08-06 20:48:55 +00:00
|
|
|
#ifdef MOZ_X11
|
2007-10-03 21:44:05 +00:00
|
|
|
// Version check failed - broken gdk_display_close.
|
|
|
|
//
|
|
|
|
// Let the gdk structures leak but at least close the Display,
|
|
|
|
// assuming that gdk will not use it again.
|
|
|
|
Display* dpy = GDK_DISPLAY_XDISPLAY(display);
|
2008-04-09 06:42:49 +00:00
|
|
|
if (!theme_is_qt)
|
|
|
|
XCloseDisplay(dpy);
|
2008-08-06 20:48:55 +00:00
|
|
|
#else
|
|
|
|
gdk_display_close(display);
|
|
|
|
#endif /* MOZ_X11 */
|
2007-10-03 21:44:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-09-25 22:38:25 +00:00
|
|
|
#if CLEANUP_MEMORY
|
|
|
|
// 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();
|
|
|
|
#endif
|
|
|
|
|
2009-01-26 16:21:46 +00:00
|
|
|
PRBool buggyCairoShutdown = cairo_version() < CAIRO_VERSION_ENCODE(1, 4, 0);
|
|
|
|
|
|
|
|
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 22:38:25 +00:00
|
|
|
|
|
|
|
#if CLEANUP_MEMORY
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
#if GTK_CHECK_VERSION(2,8,0)
|
|
|
|
// cairo_debug_reset_static_data() is prototyped through cairo.h included
|
|
|
|
// by gtk.h.
|
|
|
|
#ifdef cairo_debug_reset_static_data
|
|
|
|
#error "Looks like we're including Mozilla's cairo instead of system cairo"
|
2008-02-12 06:47:40 +00:00
|
|
|
#endif
|
2008-09-25 22:38:25 +00:00
|
|
|
cairo_debug_reset_static_data();
|
|
|
|
#endif // 2.8.0
|
|
|
|
#endif // CLEANUP_MEMORY
|
2009-01-26 16:21:46 +00:00
|
|
|
|
|
|
|
if (buggyCairoShutdown) {
|
|
|
|
if (!theme_is_qt)
|
|
|
|
gdk_display_close(display);
|
|
|
|
}
|
2007-10-03 21:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_GTK2
|
2005-03-07 22:40:36 +00:00
|
|
|
|
2007-02-08 10:11:36 +00: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.
|
|
|
|
*/
|
2009-09-15 07:02:51 +00:00
|
|
|
NS_VISIBILITY_DEFAULT PRBool nspr_use_zone_allocator = PR_FALSE;
|
2007-02-08 10:11:36 +00:00
|
|
|
|
2009-06-16 18:59:35 +00:00
|
|
|
#ifdef MOZ_SPLASHSCREEN
|
|
|
|
#define MOZ_SPLASHSCREEN_UPDATE(_i) do { if (splashScreen) splashScreen->Update(_i); } while(0)
|
|
|
|
#else
|
|
|
|
#define MOZ_SPLASHSCREEN_UPDATE(_i) do { } while(0)
|
|
|
|
#endif
|
|
|
|
|
2011-01-23 10:45:00 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2011-01-21 16:44:33 +00:00
|
|
|
|
|
|
|
#include <dwrite.h>
|
|
|
|
|
|
|
|
typedef HRESULT (WINAPI*DWriteCreateFactoryFunc)(
|
2011-07-12 09:17:20 +00:00
|
|
|
DWRITE_FACTORY_TYPE factoryType,
|
|
|
|
REFIID iid,
|
|
|
|
IUnknown **factory
|
2011-01-21 16:44:33 +00: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 09:55:14 +00: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 16:44:33 +00:00
|
|
|
}
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-17 14:17:45 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-13 20:18:51 +00:00
|
|
|
PRTime gXRE_mainTimestamp = 0;
|
|
|
|
|
2011-05-03 20:07:17 +00:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#ifndef MOZ_PLATFORM_MAEMO
|
2011-06-10 19:07:54 +00:00
|
|
|
bool fire_glxtest_process();
|
2011-05-03 20:07:17 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-03-18 21:24:05 +00:00
|
|
|
int
|
|
|
|
XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
|
2002-08-21 10:25:54 +00:00
|
|
|
{
|
2010-04-26 18:13:03 +00:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2011-01-13 20:18:51 +00:00
|
|
|
gXRE_mainTimestamp = PR_Now();
|
|
|
|
|
2009-06-16 18:59:35 +00:00
|
|
|
#ifdef MOZ_SPLASHSCREEN
|
2009-08-22 07:13:49 +00:00
|
|
|
nsSplashScreen *splashScreen = nsnull;
|
2009-06-16 18:59:35 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
nsresult rv;
|
2007-07-11 05:59:56 +00:00
|
|
|
ArgResult ar;
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2005-04-26 00:37:23 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (PR_GetEnv("XRE_MAIN_BREAK"))
|
|
|
|
NS_BREAK();
|
|
|
|
#endif
|
|
|
|
|
2011-05-03 20:07:17 +00:00
|
|
|
// see 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.
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#ifndef MOZ_PLATFORM_MAEMO
|
2011-06-10 19:07:54 +00:00
|
|
|
if (fire_glxtest_process())
|
|
|
|
return 0;
|
2011-05-03 20:07:17 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-06-02 12:38:27 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Vista API. Mozilla is DPI Aware.
|
|
|
|
typedef BOOL (*SetProcessDPIAwareFunc)(VOID);
|
|
|
|
|
|
|
|
SetProcessDPIAwareFunc setDPIAware = (SetProcessDPIAwareFunc)
|
|
|
|
GetProcAddress(LoadLibraryW(L"user32.dll"), "SetProcessDPIAware");
|
|
|
|
|
|
|
|
if (setDPIAware)
|
|
|
|
setDPIAware();
|
|
|
|
#endif
|
|
|
|
|
2009-12-18 22:14:53 +00:00
|
|
|
SetupErrorHandling(argv[0]);
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2011-01-23 10:45:00 +00:00
|
|
|
#ifdef CAIRO_HAS_DWRITE_FONT
|
2011-01-21 16:44:33 +00: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.
|
|
|
|
|
|
|
|
OSVERSIONINFO vinfo;
|
|
|
|
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
|
|
|
|
if (GetVersionEx(&vinfo) && vinfo.dwMajorVersion >= 6) {
|
|
|
|
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&InitDwriteBG, NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-04-29 07:19:50 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
const char *home = PR_GetEnv("HOME");
|
|
|
|
if (!home || !*home) {
|
|
|
|
struct passwd *pw = getpwuid(geteuid());
|
|
|
|
if (!pw || !pw->pw_dir) {
|
|
|
|
Output(PR_TRUE, "Could not determine HOME directory");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
SaveWordToEnv("HOME", nsDependentCString(pw->pw_dir));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-15 14:18:45 +00: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-22 06:46:30 +00:00
|
|
|
|
|
|
|
// Suppress atk-bridge init at startup, it works after GNOME 2.24.2
|
2011-03-23 17:28:18 +00:00
|
|
|
SaveToEnv("NO_AT_BRIDGE=1");
|
2008-12-15 14:18:45 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
gArgc = argc;
|
|
|
|
gArgv = argv;
|
|
|
|
|
2006-08-17 14:22:04 +00:00
|
|
|
NS_ENSURE_TRUE(aAppData, 2);
|
2005-05-12 13:23:30 +00:00
|
|
|
|
2007-12-19 11:23:22 +00:00
|
|
|
// Check for application.ini overrides
|
|
|
|
const char* override = nsnull;
|
|
|
|
ar = CheckArg("override", PR_TRUE, &override);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
Output(PR_TRUE, "Incorrect number of arguments passed to -override");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (ar == ARG_FOUND) {
|
|
|
|
nsCOMPtr<nsILocalFile> overrideLF;
|
|
|
|
rv = XRE_GetFileFromPath(override, getter_AddRefs(overrideLF));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output(PR_TRUE, "Error: unrecognized override.ini path.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXREAppData* overrideAppData = const_cast<nsXREAppData*>(aAppData);
|
|
|
|
rv = XRE_ParseAppData(overrideLF, overrideAppData);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output(PR_TRUE, "Couldn't read override.ini");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-17 14:22:04 +00:00
|
|
|
ScopedAppData appData(aAppData);
|
|
|
|
gAppData = &appData;
|
|
|
|
|
|
|
|
// Check sanity and correctness of app data.
|
|
|
|
|
|
|
|
if (!appData.name) {
|
|
|
|
Output(PR_TRUE, "Error: App:Name not specified in application.ini\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!appData.buildID) {
|
|
|
|
Output(PR_TRUE, "Error: App:BuildID not specified in application.ini\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-08-22 07:13:49 +00:00
|
|
|
#ifdef MOZ_SPLASHSCREEN
|
|
|
|
// check to see if we need to do a splash screen
|
|
|
|
PRBool wantsSplash = PR_TRUE;
|
2009-08-26 23:10:48 +00:00
|
|
|
PRBool isNoSplash = (CheckArg("nosplash", PR_FALSE, NULL, PR_FALSE) == ARG_FOUND);
|
2009-12-30 01:21:46 +00:00
|
|
|
isNoSplash |= (PR_GetEnv("NO_SPLASH") != 0);
|
2009-08-26 23:10:48 +00:00
|
|
|
PRBool isNoRemote = (CheckArg("no-remote", PR_FALSE, NULL, PR_FALSE) == ARG_FOUND);
|
2009-08-22 07:13:49 +00:00
|
|
|
|
|
|
|
if (wantsSplash && !isNoSplash)
|
|
|
|
splashScreen = nsSplashScreen::GetOrCreate();
|
|
|
|
|
|
|
|
if (splashScreen)
|
|
|
|
splashScreen->Open();
|
2009-08-26 23:11:21 +00:00
|
|
|
#endif //MOZ_SPLASHSCREEN
|
2009-08-22 07:13:49 +00:00
|
|
|
|
|
|
|
|
2007-06-26 19:22:51 +00:00
|
|
|
ScopedLogging log;
|
|
|
|
|
|
|
|
if (!appData.xreDirectory) {
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
|
|
|
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;
|
|
|
|
|
|
|
|
rv = CallQueryInterface(greDir, &appData.xreDirectory);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2007-07-02 18:20:24 +00:00
|
|
|
if (appData.size > offsetof(nsXREAppData, minVersion)) {
|
|
|
|
if (!appData.minVersion) {
|
|
|
|
Output(PR_TRUE, "Error: Gecko:MinVersion not specified in application.ini\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!appData.maxVersion) {
|
|
|
|
// If no maxVersion is specified, we assume the app is only compatible
|
|
|
|
// with the initial preview release. Do not increment this number ever!
|
|
|
|
SetAllocatedString(appData.maxVersion, "1.*");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_CompareVersions(appData.minVersion, gToolkitVersion) > 0 ||
|
|
|
|
NS_CompareVersions(appData.maxVersion, gToolkitVersion) < 0) {
|
|
|
|
Output(PR_TRUE, "Error: Platform version '%s' is not compatible with\n"
|
|
|
|
"minVersion >= %s\nmaxVersion <= %s\n",
|
|
|
|
gToolkitVersion,
|
|
|
|
appData.minVersion, appData.maxVersion);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-21 17:58:32 +00:00
|
|
|
nsXREDirProvider dirProvider;
|
|
|
|
rv = dirProvider.Initialize(gAppData->directory, gAppData->xreDirectory);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 1;
|
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2011-03-23 17:28:18 +00:00
|
|
|
if (EnvHasValue("MOZ_CRASHREPORTER")) {
|
2007-05-22 20:20:55 +00:00
|
|
|
appData.flags |= NS_XRE_ENABLE_CRASH_REPORTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((appData.flags & NS_XRE_ENABLE_CRASH_REPORTER) &&
|
|
|
|
NS_SUCCEEDED(
|
2009-04-02 15:41:12 +00:00
|
|
|
CrashReporter::SetExceptionHandler(appData.xreDirectory))) {
|
2009-09-30 14:07:50 +00:00
|
|
|
if (appData.crashReporterURL)
|
|
|
|
CrashReporter::SetServerURL(nsDependentCString(appData.crashReporterURL));
|
|
|
|
|
2007-05-22 20:20:55 +00:00
|
|
|
// pass some basic info from the app data
|
|
|
|
if (appData.vendor)
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Vendor"),
|
2008-01-26 16:49:29 +00:00
|
|
|
nsDependentCString(appData.vendor));
|
2007-05-22 20:20:55 +00:00
|
|
|
if (appData.name)
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ProductName"),
|
2008-01-26 16:49:29 +00:00
|
|
|
nsDependentCString(appData.name));
|
2007-05-22 20:20:55 +00:00
|
|
|
if (appData.version)
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Version"),
|
2008-01-26 16:49:29 +00:00
|
|
|
nsDependentCString(appData.version));
|
2007-05-22 20:20:55 +00:00
|
|
|
if (appData.buildID)
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("BuildID"),
|
2008-01-26 16:49:29 +00:00
|
|
|
nsDependentCString(appData.buildID));
|
2007-05-29 10:54:26 +00:00
|
|
|
CrashReporter::SetRestartArgs(argc, argv);
|
2007-07-16 17:07:20 +00:00
|
|
|
|
|
|
|
// annotate other data (user id etc)
|
|
|
|
nsCOMPtr<nsILocalFile> userAppDataDir;
|
2010-05-21 17:58:32 +00:00
|
|
|
if (NS_SUCCEEDED(dirProvider.GetUserAppDataDirectory(
|
2008-01-26 16:49:29 +00:00
|
|
|
getter_AddRefs(userAppDataDir)))) {
|
2007-07-17 15:02:29 +00:00
|
|
|
CrashReporter::SetupExtraData(userAppDataDir,
|
|
|
|
nsDependentCString(appData.buildID));
|
2008-01-26 16:49:29 +00:00
|
|
|
|
|
|
|
// see if we have a crashreporter-override.ini in the application directory
|
|
|
|
nsCOMPtr<nsIFile> overrideini;
|
|
|
|
PRBool exists;
|
|
|
|
if (NS_SUCCEEDED(dirProvider.GetAppDir()->Clone(getter_AddRefs(overrideini))) &&
|
|
|
|
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
|
2008-01-26 17:26:26 +00:00
|
|
|
nsCAutoString overridePath;
|
2008-01-26 16:49:29 +00:00
|
|
|
overrideini->GetNativePath(overridePath);
|
|
|
|
#endif
|
|
|
|
|
2011-06-27 13:31:04 +00:00
|
|
|
SaveWordToEnv("MOZ_CRASHREPORTER_STRINGS_OVERRIDE", overridePath);
|
2008-01-26 16:49:29 +00:00
|
|
|
}
|
2007-07-16 17:07:20 +00:00
|
|
|
}
|
2007-05-22 20:20:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-08-17 14:22:04 +00:00
|
|
|
#ifdef XP_MACOSX
|
2011-03-23 17:28:18 +00:00
|
|
|
if (EnvHasValue("MOZ_LAUNCHED_CHILD")) {
|
2007-05-17 02:10:19 +00: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();
|
|
|
|
|
2006-07-19 21:08:19 +00: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,
|
|
|
|
kEventDurationNoWait, PR_FALSE, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2005-07-25 22:16:56 +00:00
|
|
|
#endif
|
|
|
|
|
2010-04-19 08:29:18 +00:00
|
|
|
SaveToEnv("MOZ_LAUNCHED_CHILD=");
|
2006-07-19 21:08:19 +00:00
|
|
|
|
|
|
|
gRestartArgc = gArgc;
|
2008-08-16 15:19:43 +00:00
|
|
|
gRestartArgv = (char**) malloc(sizeof(char*) * (gArgc + 1 + (override ? 2 : 0)));
|
2004-06-17 21:23:51 +00:00
|
|
|
if (!gRestartArgv) return 1;
|
2007-10-13 05:47:04 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < gArgc; ++i) {
|
|
|
|
gRestartArgv[i] = gArgv[i];
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2008-08-16 15:19:43 +00: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
gRestartArgv[gRestartArgc] = nsnull;
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
|
|
|
|
#if defined(XP_OS2)
|
2005-03-07 18:28:40 +00:00
|
|
|
PRBool StartOS2App(int aArgc, char **aArgv);
|
|
|
|
if (!StartOS2App(gArgc, gArgv))
|
|
|
|
return 1;
|
2005-03-11 01:55:48 +00:00
|
|
|
ScopedFPHandler handler;
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif /* XP_OS2 */
|
|
|
|
|
2011-03-23 17:28:18 +00:00
|
|
|
if (EnvHasValue("MOZ_SAFE_MODE_RESTART")) {
|
2010-09-22 02:36:53 +00:00
|
|
|
gSafeMode = PR_TRUE;
|
|
|
|
// unset the env variable
|
2011-03-23 17:28:18 +00:00
|
|
|
SaveToEnv("MOZ_SAFE_MODE_RESTART=");
|
2010-09-22 02:36:53 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("safe-mode", PR_TRUE);
|
|
|
|
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) {
|
|
|
|
gSafeMode = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-19 01:20:05 +00:00
|
|
|
#ifdef XP_WIN
|
2010-12-22 00:32:14 +00: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)) {
|
2010-11-19 01:20:05 +00:00
|
|
|
gSafeMode = PR_TRUE;
|
2010-12-22 00:32:14 +00:00
|
|
|
}
|
2010-11-19 01:20:05 +00:00
|
|
|
#endif
|
|
|
|
|
2005-10-07 18:09:43 +00:00
|
|
|
#ifdef XP_MACOSX
|
2008-03-04 17:58:52 +00:00
|
|
|
if (GetCurrentEventKeyModifiers() & optionKey)
|
2005-05-12 13:23:30 +00:00
|
|
|
gSafeMode = PR_TRUE;
|
2007-07-11 05:59:56 +00:00
|
|
|
#endif
|
2005-05-12 13:23:30 +00:00
|
|
|
|
2006-02-09 01:17:19 +00:00
|
|
|
// Handle -no-remote command line argument. Setup the environment to
|
|
|
|
// better accommodate other components and various restart scenarios.
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("no-remote", PR_TRUE);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
|
|
|
return 1;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
2010-04-19 08:29:18 +00:00
|
|
|
SaveToEnv("MOZ_NO_REMOTE=1");
|
2007-07-11 05:59:56 +00:00
|
|
|
}
|
2006-02-09 01:17:19 +00:00
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
// Handle -help and -version command line arguments.
|
2004-06-17 21:23:51 +00:00
|
|
|
// They should return quickly, so we deal with them here.
|
|
|
|
if (CheckArg("h") || CheckArg("help") || CheckArg("?")) {
|
|
|
|
DumpHelp();
|
2002-08-21 10:25:54 +00:00
|
|
|
return 0;
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
if (CheckArg("v") || CheckArg("version")) {
|
|
|
|
DumpVersion();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-21 10:25:54 +00:00
|
|
|
#ifdef NS_TRACE_MALLOC
|
2006-09-27 13:39:29 +00:00
|
|
|
gArgc = argc = NS_TraceMallocStartupArgs(gArgc, gArgv);
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
|
|
|
|
2009-06-16 18:59:35 +00:00
|
|
|
MOZ_SPLASHSCREEN_UPDATE(20);
|
|
|
|
|
2009-11-04 05:12:18 +00:00
|
|
|
rv = XRE_InitCommandLine(gArgc, gArgv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2009-07-02 16:54:22 +00:00
|
|
|
|
2004-09-07 18:59:07 +00:00
|
|
|
{
|
2006-02-10 15:00:36 +00:00
|
|
|
// Check for -register, which registers chrome and then exits immediately.
|
2007-07-11 05:59:56 +00:00
|
|
|
ar = CheckArg("register", PR_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) {
|
2006-02-10 15:00:36 +00:00
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2003-12-04 19:39:40 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
{
|
2010-05-14 09:24:41 +00:00
|
|
|
nsCOMPtr<nsIChromeRegistry> chromeReg =
|
|
|
|
mozilla::services::GetChromeRegistryService();
|
2006-02-10 15:00:36 +00:00
|
|
|
NS_ENSURE_TRUE(chromeReg, 1);
|
2003-12-04 19:39:40 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
chromeReg->CheckForNewChrome();
|
|
|
|
}
|
|
|
|
return 0;
|
2003-12-04 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 23:52:44 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK2) || defined(MOZ_ENABLE_XREMOTE)
|
2007-02-09 01:33:26 +00:00
|
|
|
// Stash DESKTOP_STARTUP_ID in malloc'ed memory because gtk_init will clear it.
|
|
|
|
#define HAVE_DESKTOP_STARTUP_ID
|
|
|
|
const char* desktopStartupIDEnv = PR_GetEnv("DESKTOP_STARTUP_ID");
|
|
|
|
nsCAutoString desktopStartupID;
|
|
|
|
if (desktopStartupIDEnv) {
|
|
|
|
desktopStartupID.Assign(desktopStartupIDEnv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 13:21:59 +00:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
2010-05-24 12:21:52 +00:00
|
|
|
const char* qgraphicssystemARG = NULL;
|
2010-06-02 09:24:16 +00:00
|
|
|
ar = CheckArg("graphicssystem", PR_TRUE, &qgraphicssystemARG, PR_FALSE);
|
2010-05-24 12:21:52 +00:00
|
|
|
if (ar == ARG_FOUND)
|
|
|
|
PR_SetEnv(PR_smprintf("MOZ_QT_GRAPHICSSYSTEM=%s", qgraphicssystemARG));
|
2010-07-17 06:52:23 +00:00
|
|
|
|
2010-08-03 17:44:46 +00:00
|
|
|
QScopedPointer<QApplication> app(new QApplication(gArgc, gArgv));
|
2011-06-25 13:22:34 +00:00
|
|
|
#ifdef MOZ_ENABLE_MEEGOTOUCH
|
|
|
|
gArgv[gArgc] = strdup("-software");
|
|
|
|
gArgc++;
|
|
|
|
QScopedPointer<MComponentData> meegotouch(new MComponentData(gArgc, gArgv));
|
|
|
|
#endif
|
2010-08-03 17:44:46 +00:00
|
|
|
|
2010-08-30 23:40:14 +00:00
|
|
|
#if MOZ_PLATFORM_MAEMO > 5
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
// try to get the MInputContext if possible to support the MeeGo VKB
|
|
|
|
QInputContext* inputContext = app->inputContext();
|
|
|
|
if (inputContext && inputContext->identifierName() != "MInputContext") {
|
|
|
|
QInputContext* context = QInputContextFactory::create("MInputContext",
|
|
|
|
app.data());
|
|
|
|
if (context)
|
|
|
|
app->setInputContext(context);
|
|
|
|
}
|
2010-08-03 18:33:12 +00:00
|
|
|
}
|
2010-08-30 23:40:14 +00:00
|
|
|
#endif
|
2010-08-03 17:44:46 +00:00
|
|
|
QStringList nonQtArguments = app->arguments();
|
2010-07-17 06:52:23 +00:00
|
|
|
gQtOnlyArgc = 1;
|
|
|
|
gQtOnlyArgv = (char**) malloc(sizeof(char*)
|
|
|
|
* (gRestartArgc - nonQtArguments.size() + 2));
|
|
|
|
|
|
|
|
// copy binary path
|
|
|
|
gQtOnlyArgv[0] = gRestartArgv[0];
|
|
|
|
|
|
|
|
for (int i = 1; i < gRestartArgc; ++i) {
|
|
|
|
if (!nonQtArguments.contains(gRestartArgv[i])) {
|
|
|
|
// copy arguments used by Qt for later
|
|
|
|
gQtOnlyArgv[gQtOnlyArgc++] = gRestartArgv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gQtOnlyArgv[gQtOnlyArgc] = nsnull;
|
2008-04-19 13:21:59 +00:00
|
|
|
#endif
|
2007-04-30 23:52:44 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2008-06-20 17:34:42 +00:00
|
|
|
#ifdef MOZ_MEMORY
|
|
|
|
// 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
|
2007-06-17 16:01:40 +00:00
|
|
|
g_thread_init(NULL);
|
2006-02-10 15:00:36 +00: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.
|
|
|
|
if (CheckArg("install"))
|
|
|
|
gdk_rgb_set_install(TRUE);
|
|
|
|
|
2007-09-27 21:14:11 +00:00
|
|
|
// Initialize GTK here for splash.
|
2004-03-04 22:59:50 +00:00
|
|
|
|
2007-09-27 21:14:11 +00:00
|
|
|
// 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;
|
|
|
|
|
2008-08-16 15:18:43 +00:00
|
|
|
// display_name is owned by gdk.
|
|
|
|
const char *display_name = gdk_get_display_arg_name();
|
2008-08-20 04:12:51 +00:00
|
|
|
if (display_name) {
|
|
|
|
SaveWordToEnv("DISPLAY", nsDependentCString(display_name));
|
|
|
|
} else {
|
2008-08-16 15:18:43 +00:00
|
|
|
display_name = PR_GetEnv("DISPLAY");
|
2007-09-27 21:14:11 +00:00
|
|
|
if (!display_name) {
|
2008-08-16 15:18:43 +00:00
|
|
|
PR_fprintf(PR_STDERR, "Error: no display specified\n");
|
2007-09-27 21:14:11 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2008-08-16 15:18:43 +00:00
|
|
|
#endif /* MOZ_WIDGET_GTK2 */
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
// handle -remote now that xpcom is fired up
|
|
|
|
|
|
|
|
const char* xremotearg;
|
|
|
|
ar = CheckArg("remote", PR_TRUE, &xremotearg);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: -remote requires an argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const char* desktopStartupIDPtr =
|
|
|
|
desktopStartupID.IsEmpty() ? nsnull : desktopStartupID.get();
|
|
|
|
if (ar) {
|
|
|
|
return HandleRemoteArgument(xremotearg, desktopStartupIDPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PR_GetEnv("MOZ_NO_REMOTE")) {
|
|
|
|
// Try to remote the entire command line. If this fails, start up normally.
|
|
|
|
RemoteResult rr = RemoteCommandLine(desktopStartupIDPtr);
|
|
|
|
if (rr == REMOTE_FOUND)
|
|
|
|
return 0;
|
|
|
|
else if (rr == REMOTE_ARG_BAD)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
GdkDisplay* display = nsnull;
|
|
|
|
display = gdk_display_open(display_name);
|
|
|
|
if (!display) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-09-27 21:14:11 +00:00
|
|
|
gdk_display_manager_set_default_display (gdk_display_manager_get(),
|
|
|
|
display);
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// g_set_application_name () is only defined in glib2.2 and higher.
|
|
|
|
_g_set_application_name_fn _g_set_application_name =
|
2007-02-09 01:33:26 +00:00
|
|
|
(_g_set_application_name_fn)FindFunction("g_set_application_name");
|
2006-02-10 15:00:36 +00:00
|
|
|
if (_g_set_application_name) {
|
|
|
|
_g_set_application_name(gAppData->name);
|
|
|
|
}
|
2007-02-09 01:33:26 +00:00
|
|
|
_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(PR_FALSE);
|
2006-02-10 15:00:36 +00:00
|
|
|
}
|
2005-03-07 22:40:36 +00:00
|
|
|
|
2009-02-02 17:49:58 +00:00
|
|
|
gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
|
2007-04-30 23:52:44 +00:00
|
|
|
#endif /* MOZ_WIDGET_GTK2 */
|
2010-02-24 22:25:16 +00:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// Do this after initializing GDK, or GDK will install its own handler.
|
|
|
|
InstallX11ErrorHandler();
|
|
|
|
#endif
|
2004-12-20 21:53:33 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// Call the code to install our handler
|
2002-08-21 10:25:54 +00:00
|
|
|
#ifdef MOZ_JPROF
|
2006-02-10 15:00:36 +00:00
|
|
|
setupProfilingStuff();
|
2002-08-21 10:25:54 +00:00
|
|
|
#endif
|
2003-03-08 04:15:01 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// Try to allocate "native app support."
|
|
|
|
nsCOMPtr<nsINativeAppSupport> nativeApp;
|
|
|
|
rv = NS_CreateNativeAppSupport(getter_AddRefs(nativeApp));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 1;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
PRBool canRun = PR_FALSE;
|
|
|
|
rv = nativeApp->Start(&canRun);
|
|
|
|
if (NS_FAILED(rv) || !canRun) {
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-21 10:25:54 +00:00
|
|
|
|
2011-02-23 07:18:17 +00:00
|
|
|
#if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK2)
|
|
|
|
// DESKTOP_STARTUP_ID is cleared now,
|
|
|
|
// we recover it in case we need a restart.
|
|
|
|
if (!desktopStartupID.IsEmpty()) {
|
|
|
|
nsCAutoString desktopStartupEnv;
|
|
|
|
desktopStartupEnv.AssignLiteral("DESKTOP_STARTUP_ID=");
|
|
|
|
desktopStartupEnv.Append(desktopStartupID);
|
|
|
|
// Leak it with extreme prejudice!
|
|
|
|
PR_SetEnv(ToNewCString(desktopStartupEnv));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-10 23:48:52 +00:00
|
|
|
#if defined(MOZ_UPDATER) && !defined(ANDROID)
|
2010-10-20 04:28:29 +00:00
|
|
|
// Check for and process any available updates
|
|
|
|
nsCOMPtr<nsIFile> updRoot;
|
|
|
|
PRBool persistent;
|
|
|
|
rv = dirProvider.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 = dirProvider.GetAppDir();
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
ProcessUpdates(dirProvider.GetGREDir(),
|
|
|
|
dirProvider.GetAppDir(),
|
|
|
|
updRoot,
|
|
|
|
gRestartArgc,
|
|
|
|
gRestartArgv,
|
|
|
|
appData.version);
|
2011-03-23 17:28:18 +00:00
|
|
|
if (EnvHasValue("MOZ_PROCESS_UPDATES")) {
|
|
|
|
SaveToEnv("MOZ_PROCESS_UPDATES=");
|
2010-10-20 04:28:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-07-27 20:46:34 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
nsCOMPtr<nsIProfileLock> profileLock;
|
|
|
|
PRBool startOffline = PR_FALSE;
|
2007-06-30 05:02:49 +00:00
|
|
|
nsCAutoString profileName;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2007-06-30 05:02:49 +00:00
|
|
|
rv = SelectProfile(getter_AddRefs(profileLock), nativeApp, &startOffline,
|
|
|
|
&profileName);
|
2006-02-10 15:00:36 +00:00
|
|
|
if (rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ||
|
|
|
|
rv == NS_ERROR_ABORT) return 0;
|
2010-03-06 15:40:33 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// We failed to choose or create profile - notify user and quit
|
|
|
|
ProfileMissingDialog(nativeApp);
|
|
|
|
return 1;
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
nsCOMPtr<nsILocalFile> profD;
|
|
|
|
rv = profileLock->GetDirectory(getter_AddRefs(profD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2005-04-26 00:37:23 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
nsCOMPtr<nsILocalFile> profLD;
|
|
|
|
rv = profileLock->GetLocalDirectory(getter_AddRefs(profLD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
rv = dirProvider.SetProfile(profD, profLD);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
//////////////////////// NOW WE HAVE A PROFILE ////////////////////////
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-05-16 17:14:59 +00:00
|
|
|
if (appData.flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
|
|
|
MakeOrSetMinidumpPath(profD);
|
2006-10-26 22:52:30 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
nsCAutoString version;
|
|
|
|
BuildVersion(version);
|
2005-07-23 14:00:07 +00:00
|
|
|
|
2006-02-15 03:14:27 +00:00
|
|
|
#ifdef TARGET_OS_ABI
|
|
|
|
NS_NAMED_LITERAL_CSTRING(osABI, TARGET_OS_ABI);
|
|
|
|
#else
|
|
|
|
// No TARGET_XPCOM_ABI, but at least the OS is known
|
|
|
|
NS_NAMED_LITERAL_CSTRING(osABI, OS_TARGET "_UNKNOWN");
|
|
|
|
#endif
|
|
|
|
|
2006-02-10 15:00:36 +00: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.
|
2009-10-16 06:32:29 +00:00
|
|
|
// Also check to see if something has happened to invalidate our
|
|
|
|
// fastload caches, like an extension upgrade or installation.
|
2010-07-02 23:59:17 +00:00
|
|
|
|
2010-10-20 04:28:29 +00:00
|
|
|
// If we see .purgecaches, that means someone did a make.
|
|
|
|
// Re-register components to catch potential changes.
|
|
|
|
// We only offer this in debug builds, though.
|
|
|
|
nsCOMPtr<nsILocalFile> flagFile;
|
|
|
|
|
|
|
|
rv = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
nsCOMPtr<nsIFile> fFlagFile;
|
|
|
|
if (gAppData->directory) {
|
|
|
|
rv = gAppData->directory->Clone(getter_AddRefs(fFlagFile));
|
|
|
|
}
|
|
|
|
flagFile = do_QueryInterface(fFlagFile);
|
|
|
|
if (flagFile) {
|
|
|
|
flagFile->AppendNative(FILE_INVALIDATE_CACHES);
|
|
|
|
}
|
2010-09-23 20:41:26 +00:00
|
|
|
|
2009-10-16 06:32:29 +00:00
|
|
|
PRBool cachesOK;
|
|
|
|
PRBool versionOK = CheckCompatibility(profD, version, osABI,
|
2006-02-10 15:00:36 +00:00
|
|
|
dirProvider.GetGREDir(),
|
2010-07-02 23:59:17 +00:00
|
|
|
gAppData->directory, flagFile,
|
|
|
|
&cachesOK);
|
2010-10-20 04:28:29 +00:00
|
|
|
if (CheckArg("purgecaches")) {
|
|
|
|
cachesOK = PR_FALSE;
|
|
|
|
}
|
|
|
|
if (PR_GetEnv("MOZ_PURGE_CACHES")) {
|
|
|
|
cachesOK = PR_FALSE;
|
|
|
|
}
|
2010-07-02 23:59:17 +00:00
|
|
|
|
2006-02-10 15:00:36 +00: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
|
2010-06-21 16:46:26 +00:00
|
|
|
// the fastload caches. On subsequent launches if the version matches,
|
2006-02-10 15:00:36 +00:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
if (gSafeMode) {
|
2005-07-23 14:00:07 +00:00
|
|
|
RemoveComponentRegistries(profD, profLD, PR_FALSE);
|
2006-02-15 03:14:27 +00:00
|
|
|
WriteVersion(profD, NS_LITERAL_CSTRING("Safe Mode"), osABI,
|
2006-02-10 15:00:36 +00:00
|
|
|
dirProvider.GetGREDir(), gAppData->directory);
|
|
|
|
}
|
|
|
|
else if (versionOK) {
|
2009-10-16 06:32:29 +00:00
|
|
|
if (!cachesOK) {
|
2010-06-21 16:46:26 +00:00
|
|
|
// Remove caches, forcing component re-registration.
|
2006-02-10 15:00:36 +00:00
|
|
|
// The new list of additional components directories is derived from
|
|
|
|
// information in "extensions.ini".
|
|
|
|
RemoveComponentRegistries(profD, profLD, PR_FALSE);
|
2009-10-16 06:32:29 +00:00
|
|
|
|
|
|
|
// Rewrite compatibility.ini to remove the flag
|
|
|
|
WriteVersion(profD, version, osABI,
|
|
|
|
dirProvider.GetGREDir(), gAppData->directory);
|
2006-02-10 15:00:36 +00:00
|
|
|
}
|
|
|
|
// Nothing need be done for the normal startup case.
|
|
|
|
}
|
|
|
|
else {
|
2010-06-21 16:46:26 +00:00
|
|
|
// Remove caches, forcing component re-registration
|
2006-02-10 15:00:36 +00:00
|
|
|
// with the default set of components (this disables any potentially
|
|
|
|
// troublesome incompatible XPCOM components).
|
|
|
|
RemoveComponentRegistries(profD, profLD, PR_TRUE);
|
|
|
|
|
|
|
|
// Write out version
|
2006-02-15 03:14:27 +00:00
|
|
|
WriteVersion(profD, version, osABI,
|
2006-02-10 15:00:36 +00:00
|
|
|
dirProvider.GetGREDir(), gAppData->directory);
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 23:59:17 +00:00
|
|
|
if (flagFile) {
|
|
|
|
flagFile->Remove(PR_TRUE);
|
|
|
|
}
|
2010-09-23 20:41:26 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
PRBool appInitiatedRestart = PR_FALSE;
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2009-06-16 18:59:35 +00:00
|
|
|
MOZ_SPLASHSCREEN_UPDATE(30);
|
|
|
|
|
2010-04-26 18:13:03 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Next: ScopedXPCOMStartup");
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup");
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// Allows the user to forcefully bypass the restart process at their
|
|
|
|
// own risk. Useful for debugging or for tinderboxes where child
|
|
|
|
// processes can be problematic.
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
2006-02-10 15:00:36 +00:00
|
|
|
// Start the real application
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: Initialize");
|
2006-02-10 15:00:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2010-05-19 23:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
comp = do_GetService("@mozilla.org/preferences-service;1");
|
|
|
|
NS_TIME_FUNCTION_MARK("Pref Service");
|
|
|
|
|
|
|
|
comp = do_GetService("@mozilla.org/network/socket-transport-service;1");
|
|
|
|
NS_TIME_FUNCTION_MARK("Socket Transport Service");
|
|
|
|
|
|
|
|
comp = do_GetService("@mozilla.org/network/dns-service;1");
|
|
|
|
NS_TIME_FUNCTION_MARK("DNS Service");
|
|
|
|
|
|
|
|
comp = do_GetService("@mozilla.org/network/io-service;1");
|
|
|
|
NS_TIME_FUNCTION_MARK("IO Service");
|
|
|
|
|
|
|
|
comp = do_GetService("@mozilla.org/chrome/chrome-registry;1");
|
|
|
|
NS_TIME_FUNCTION_MARK("Chrome Registry Service");
|
|
|
|
|
|
|
|
comp = do_GetService("@mozilla.org/focus-event-suppressor-service;1");
|
|
|
|
NS_TIME_FUNCTION_MARK("Focus Event Suppressor Service");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = xpcom.SetWindowCreator(nativeApp);
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: SetWindowCreator");
|
2006-02-10 15:00:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: Done");
|
|
|
|
|
2009-11-13 23:05:14 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
// 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;
|
|
|
|
rv = prefs->GetDefaultBranch(nsnull, getter_AddRefs(defaultPrefBranch));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsXPIDLCString sval;
|
|
|
|
rv = defaultPrefBranch->GetCharPref("app.update.channel", getter_Copies(sval));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ReleaseChannel"),
|
|
|
|
sval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-26 18:13:03 +00:00
|
|
|
|
|
|
|
NS_TIME_FUNCTION_MARK("Next: AppStartup");
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
{
|
2006-02-10 15:00:36 +00:00
|
|
|
if (startOffline) {
|
2007-08-16 23:10:46 +00:00
|
|
|
nsCOMPtr<nsIIOService2> io (do_GetService("@mozilla.org/network/io-service;1"));
|
2006-02-10 15:00:36 +00:00
|
|
|
NS_ENSURE_TRUE(io, 1);
|
2007-08-16 23:10:46 +00:00
|
|
|
io->SetManageOfflineStatus(PR_FALSE);
|
2006-02-10 15:00:36 +00:00
|
|
|
io->SetOffline(PR_TRUE);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserver> startupNotifier
|
|
|
|
(do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
startupNotifier->Observe(nsnull, APPSTARTUP_TOPIC, nsnull);
|
|
|
|
}
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Finished startupNotifier");
|
|
|
|
|
2011-03-25 15:03:35 +00:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup
|
2006-02-10 15:00:36 +00:00
|
|
|
(do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appStartup, 1);
|
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Created AppStartup");
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
if (gDoMigration) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2006-02-28 15:28:38 +00:00
|
|
|
dirProvider.GetAppDir()->Clone(getter_AddRefs(file));
|
2006-02-10 15:00:36 +00:00
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("override.ini"));
|
|
|
|
nsINIParser parser;
|
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
|
|
|
nsresult rv = parser.Init(localFile);
|
2006-01-13 19:38:07 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-02-10 15:00:36 +00:00
|
|
|
nsCAutoString buf;
|
|
|
|
rv = parser.GetString("XRE", "EnableProfileMigrator", buf);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
|
|
|
|
gDoMigration = PR_FALSE;
|
|
|
|
}
|
2006-01-13 19:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// Profile Migration
|
|
|
|
if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR && gDoMigration) {
|
|
|
|
gDoMigration = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIProfileMigrator> pm
|
|
|
|
(do_CreateInstance(NS_PROFILEMIGRATOR_CONTRACTID));
|
|
|
|
if (pm)
|
|
|
|
pm->Migrate(&dirProvider);
|
|
|
|
}
|
2010-05-19 23:22:19 +00:00
|
|
|
|
|
|
|
NS_TIME_FUNCTION_MARK("Profile migration");
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
dirProvider.DoStartup();
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("dirProvider.DoStartup() (profile-after-change)");
|
|
|
|
|
2009-04-21 18:36:44 +00:00
|
|
|
PRBool shuttingDown = PR_FALSE;
|
|
|
|
appStartup->GetShuttingDown(&shuttingDown);
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2009-04-21 18:36:44 +00:00
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdLine;
|
2004-07-03 16:41:17 +00:00
|
|
|
|
2009-04-21 18:53:43 +00:00
|
|
|
nsCOMPtr<nsIFile> workingDir;
|
|
|
|
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
|
2009-04-21 18:36:44 +00:00
|
|
|
if (!shuttingDown) {
|
|
|
|
cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
|
|
|
|
NS_ENSURE_TRUE(cmdLine, 1);
|
2004-09-09 18:10:25 +00:00
|
|
|
|
2009-04-21 18:36:44 +00:00
|
|
|
rv = cmdLine->Init(gArgc, gArgv,
|
|
|
|
workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
|
|
|
|
/* Special-case services that need early access to the command
|
|
|
|
line. */
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
2009-09-15 10:12:01 +00:00
|
|
|
if (obsService) {
|
|
|
|
obsService->NotifyObservers(cmdLine, "command-line-startup", nsnull);
|
2006-02-10 15:00:36 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Early command line init");
|
|
|
|
|
2010-04-26 18:13:03 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Next: prepare for Run");
|
2010-07-14 17:13:26 +00:00
|
|
|
}
|
2010-04-26 18:13:03 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
SaveStateForAppInitiatedRestart();
|
2009-04-21 18:36:44 +00:00
|
|
|
|
2010-07-14 17:13:26 +00: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("XRE_IMPORT_PROFILES=");
|
|
|
|
SaveToEnv("NO_EM_RESTART=");
|
|
|
|
SaveToEnv("XUL_APP_FILE=");
|
|
|
|
SaveToEnv("XRE_BINARY_PATH=");
|
2005-03-07 19:00:19 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("env munging");
|
2004-09-08 05:43:21 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
if (!shuttingDown) {
|
|
|
|
NS_TIME_FUNCTION_MARK("Next: CreateHiddenWindow");
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
rv = appStartup->CreateHiddenWindow();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
MOZ_SPLASHSCREEN_UPDATE(50);
|
2010-04-29 20:11:23 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK2)
|
2010-07-14 17:13:26 +00:00
|
|
|
nsRefPtr<nsGTKToolkit> toolkit = GetGTKToolkit();
|
|
|
|
if (toolkit && !desktopStartupID.IsEmpty()) {
|
|
|
|
toolkit->SetDesktopStartupID(desktopStartupID);
|
|
|
|
}
|
2011-02-23 07:18:17 +00:00
|
|
|
// Clear the environment variable so it won't be inherited by
|
|
|
|
// child processes and confuse things.
|
|
|
|
g_unsetenv ("DESKTOP_STARTUP_ID");
|
2010-04-29 20:11:23 +00:00
|
|
|
#endif
|
|
|
|
|
2005-01-28 15:04:07 +00:00
|
|
|
#ifdef XP_MACOSX
|
2011-01-03 16:08:36 +00:00
|
|
|
// Set up ability to respond to system (Apple) events. This must be
|
|
|
|
// done before setting up the command line service.
|
|
|
|
SetupMacApplicationDelegate();
|
|
|
|
|
2010-07-14 17:13:26 +00: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");
|
|
|
|
NS_ENSURE_TRUE(cmdLine, 1);
|
2005-01-28 15:04:07 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
CommandLineServiceMac::SetupMacCommandLine(gArgc, gArgv, PR_FALSE);
|
2005-01-28 15:04:07 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
rv = cmdLine->Init(gArgc, gArgv,
|
|
|
|
workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-28 23:52:30 +00:00
|
|
|
#endif
|
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
MOZ_SPLASHSCREEN_UPDATE(70);
|
2009-06-16 18:59:35 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService)
|
|
|
|
obsService->NotifyObservers(nsnull, "final-ui-startup", nsnull);
|
2009-04-21 18:36:44 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("final-ui-startup done");
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
appStartup->GetShuttingDown(&shuttingDown);
|
|
|
|
}
|
2009-04-21 18:36:44 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
if (!shuttingDown) {
|
|
|
|
rv = cmdLine->Run();
|
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, 1);
|
2009-04-21 18:36:44 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
appStartup->GetShuttingDown(&shuttingDown);
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2009-04-21 18:53:43 +00:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2010-07-14 17:13:26 +00:00
|
|
|
nsCOMPtr<nsIRemoteService> remoteService;
|
2009-04-21 18:53:43 +00:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
2010-07-14 17:13:26 +00:00
|
|
|
if (!shuttingDown) {
|
2009-04-21 18:36:44 +00:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2010-07-14 17:13:26 +00:00
|
|
|
// if we have X remote support, start listening for requests on the
|
|
|
|
// proxy window.
|
|
|
|
remoteService = do_GetService("@mozilla.org/toolkit/remote-service;1");
|
|
|
|
if (remoteService)
|
|
|
|
remoteService->Startup(gAppData->name,
|
|
|
|
PromiseFlatCString(profileName).get());
|
2004-06-17 21:23:51 +00:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
nativeApp->Enable();
|
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2011-03-03 16:20:02 +00:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
|
|
|
bool event_tracing_running = false;
|
|
|
|
if (PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP")) {
|
|
|
|
event_tracing_running = mozilla::InitEventTracing();
|
|
|
|
}
|
|
|
|
#endif /* MOZ_INSTRUMENT_EVENT_LOOP */
|
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Next: Run");
|
2010-04-26 18:13:03 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("appStartup->Run");
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
MOZ_SPLASHSCREEN_UPDATE(90);
|
|
|
|
{
|
|
|
|
rv = appStartup->Run();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("failed to run appstartup");
|
|
|
|
gLogConsoleErrors = PR_TRUE;
|
2006-02-10 15:00:36 +00:00
|
|
|
}
|
2010-07-14 17:13:26 +00:00
|
|
|
}
|
2004-06-17 21:23:51 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("Next: Finish");
|
2010-04-26 18:13:03 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
NS_TIME_FUNCTION_MARK("appStartup->Run done");
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2011-03-03 16:20:02 +00:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
|
|
|
if (event_tracing_running)
|
|
|
|
mozilla::ShutdownEventTracing();
|
|
|
|
#endif
|
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
// Check for an application initiated restart. This is one that
|
|
|
|
// corresponds to nsIAppStartup.quit(eRestart)
|
|
|
|
if (rv == NS_SUCCESS_RESTART_APP)
|
|
|
|
appInitiatedRestart = PR_TRUE;
|
2005-06-20 23:18:00 +00:00
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
if (!shuttingDown) {
|
2004-06-17 21:23:51 +00:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2010-07-14 17:13:26 +00:00
|
|
|
// shut down the x remote proxy window
|
|
|
|
if (remoteService)
|
|
|
|
remoteService->Shutdown();
|
2004-06-17 21:23:51 +00:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
2006-02-10 15:00:36 +00:00
|
|
|
}
|
2007-01-30 05:14:50 +00:00
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
2005-05-31 19:10:26 +00:00
|
|
|
}
|
2006-02-10 15:00:36 +00:00
|
|
|
|
2007-07-12 00:30:45 +00:00
|
|
|
// unlock the profile after ScopedXPCOMStartup object (xpcom)
|
|
|
|
// has gone out of scope. see bug #386739 for more details
|
|
|
|
profileLock->Unlock();
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// Restart the app after XPCOM has been shut down cleanly.
|
2010-07-14 17:13:26 +00:00
|
|
|
if (appInitiatedRestart) {
|
2009-06-16 18:59:35 +00:00
|
|
|
MOZ_SPLASHSCREEN_UPDATE(90);
|
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
RestoreStateForAppInitiatedRestart();
|
2005-03-07 19:00:19 +00:00
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
// Ensure that these environment variables are set:
|
|
|
|
SaveFileToEnvIfUnset("XRE_PROFILE_PATH", profD);
|
|
|
|
SaveFileToEnvIfUnset("XRE_PROFILE_LOCAL_PATH", profLD);
|
2007-06-30 05:02:49 +00:00
|
|
|
SaveWordToEnvIfUnset("XRE_PROFILE_NAME", profileName);
|
2003-03-08 04:15:01 +00:00
|
|
|
|
2007-09-27 21:14:11 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2007-10-03 21:44:05 +00:00
|
|
|
MOZ_gdk_display_close(display);
|
2007-09-27 21:14:11 +00:00
|
|
|
#endif
|
|
|
|
|
2010-07-14 17:13:26 +00:00
|
|
|
rv = LaunchChild(nativeApp, PR_TRUE);
|
2007-03-27 18:02:02 +00:00
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-05-16 17:14:59 +00:00
|
|
|
if (appData.flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
|
|
|
CrashReporter::UnsetExceptionHandler();
|
2007-03-27 18:21:57 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 15:00:36 +00:00
|
|
|
return rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ? 0 : 1;
|
|
|
|
}
|
2007-09-27 21:14:11 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
// gdk_display_close also calls gdk_display_manager_set_default_display
|
|
|
|
// appropriately when necessary.
|
2007-10-03 21:44:05 +00:00
|
|
|
MOZ_gdk_display_close(display);
|
2007-09-27 21:14:11 +00:00
|
|
|
#endif
|
2004-06-17 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 15:19:57 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2007-05-16 17:14:59 +00:00
|
|
|
if (appData.flags & NS_XRE_ENABLE_CRASH_REPORTER)
|
|
|
|
CrashReporter::UnsetExceptionHandler();
|
2007-03-27 18:21:57 +00:00
|
|
|
#endif
|
|
|
|
|
2009-12-05 00:15:44 +00:00
|
|
|
XRE_DeinitCommandLine();
|
|
|
|
|
2004-06-17 21:23:51 +00:00
|
|
|
return NS_FAILED(rv) ? 1 : 0;
|
2003-03-08 04:15:01 +00:00
|
|
|
}
|
2009-12-14 22:13:00 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
XRE_InitCommandLine(int aArgc, char* aArgv[])
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
CommandLine::Init(aArgc, aArgv);
|
|
|
|
#else
|
2010-06-25 20:29:43 +00:00
|
|
|
|
2009-12-14 22:13:00 +00: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
|
|
|
|
nsCOMPtr<nsILocalFile> binFile;
|
|
|
|
rv = XRE_GetBinaryPath(aArgv[0], getter_AddRefs(binFile));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString canonBinPath;
|
|
|
|
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 22:08:06 +00:00
|
|
|
|
2011-02-25 11:53:36 +00:00
|
|
|
const char *path = nsnull;
|
|
|
|
ArgResult ar = CheckArg("greomni", PR_FALSE, &path);
|
2010-08-10 22:08:06 +00:00
|
|
|
if (ar == ARG_BAD) {
|
2011-02-25 11:53:36 +00:00
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -greomni requires a path argument\n");
|
2010-08-10 22:08:06 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:53:36 +00:00
|
|
|
if (!path)
|
2010-08-10 22:08:06 +00:00
|
|
|
return rv;
|
|
|
|
|
2011-02-25 11:53:36 +00:00
|
|
|
nsCOMPtr<nsILocalFile> greOmni;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ar = CheckArg("appomni", PR_FALSE, &path);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -appomni requires a path argument\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> appOmni;
|
|
|
|
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 14:28:14 +00:00
|
|
|
|
2011-02-25 11:53:36 +00:00
|
|
|
mozilla::Omnijar::Init(greOmni, appOmni);
|
2011-03-25 04:07:05 +00:00
|
|
|
return rv;
|
2009-12-14 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XRE_DeinitCommandLine()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
CommandLine::Terminate();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoProcessType
|
|
|
|
XRE_GetProcessType()
|
|
|
|
{
|
|
|
|
return mozilla::startup::sChildProcessType;
|
|
|
|
}
|
|
|
|
|
2009-12-18 21:16:38 +00:00
|
|
|
void
|
2009-12-18 22:14:53 +00:00
|
|
|
SetupErrorHandling(const char* progname)
|
2009-12-18 21:16:38 +00: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 10:38:26 +00:00
|
|
|
#ifdef XP_WIN32
|
2009-12-18 21:16:38 +00: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
|
|
|
|
|
2010-01-30 12:48:32 +00:00
|
|
|
#ifndef XP_OS2
|
2009-12-18 22:14:53 +00:00
|
|
|
InstallSignalHandlers(progname);
|
2010-01-30 12:48:32 +00:00
|
|
|
#endif
|
2009-12-18 21:16:38 +00:00
|
|
|
|
|
|
|
// Unbuffer stdout, needed for tinderbox tests.
|
|
|
|
setbuf(stdout, 0);
|
|
|
|
|
|
|
|
#if defined(FREEBSD)
|
|
|
|
// Disable all SIGFPE's on FreeBSD, as it has non-IEEE-conformant fp
|
|
|
|
// trap behavior that trips up on floating-point tests performed by
|
|
|
|
// the JS engine. See bugzilla bug 9967 details.
|
|
|
|
fpsetmask(0);
|
|
|
|
#endif
|
|
|
|
}
|