2002-08-21 14:25:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2005-02-01 20:07:35 +03:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-08-21 14:25:54 +04:00
|
|
|
*
|
2005-02-01 20:07:35 +03: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 14:25:54 +04: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 20:07:35 +03:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-08-21 14:25:54 +04: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 23:51:19 +04:00
|
|
|
* Benjamin Smedberg <benjamin@smedbergs.us>
|
2004-06-18 01:23:51 +04:00
|
|
|
* Ben Goodger <ben@mozilla.org>
|
2005-04-15 19:13:11 +04:00
|
|
|
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
|
2006-02-22 00:10:55 +03:00
|
|
|
* Ben Turner <mozilla@songbirdnest.com>
|
2006-06-08 22:20:07 +04:00
|
|
|
* Sergei Dolgov <sergei_d@fi.tartu.ee>
|
2002-08-21 14:25:54 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2005-02-01 20:07:35 +03:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2002-08-21 14:25:54 +04: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 20:07:35 +03:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-08-21 14:25:54 +04: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 20:07:35 +03:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-08-21 14:25:54 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
|
2005-07-21 17:33:43 +04:00
|
|
|
#define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsAppRunner.h"
|
2005-06-08 21:40:38 +04:00
|
|
|
#include "nsUpdateDriver.h"
|
2004-12-07 11:10:39 +03:00
|
|
|
#include "nsBuildID.h"
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "MacLaunchHelper.h"
|
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-03-31 20:48:48 +04:00
|
|
|
#ifdef XP_OS2
|
|
|
|
#include "private/pprthred.h"
|
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "prnetdb.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "prproces.h"
|
2004-04-08 18:01:17 +04:00
|
|
|
#include "prenv.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
2004-10-29 23:28:38 +04:00
|
|
|
#include "nsIAppStartup.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "nsIAppStartupNotifier.h"
|
2006-04-12 19:43:32 +04:00
|
|
|
#include "nsIMutableArray.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIChromeRegistry.h"
|
2005-01-17 21:50:18 +03:00
|
|
|
#include "nsICommandLineRunner.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIContentHandler.h"
|
|
|
|
#include "nsIDialogParamBlock.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIExtensionManager.h"
|
2005-05-12 17:23:30 +04:00
|
|
|
#include "nsIFastLoadService.h" // for PLATFORM_FASL_SUFFIX
|
2005-07-21 17:33:43 +04:00
|
|
|
#include "nsIGenericFactory.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIIOService.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "nsIObserverService.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsINativeAppSupport.h"
|
|
|
|
#include "nsIProcess.h"
|
2005-03-15 23:01:12 +03:00
|
|
|
#include "nsIProfileUnlocker.h"
|
|
|
|
#include "nsIPromptService.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2005-03-15 23:01:12 +03:00
|
|
|
#include "nsIStringBundle.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsITimelineService.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIToolkitProfile.h"
|
|
|
|
#include "nsIToolkitProfileService.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIWindowCreator.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "nsIWindowMediator.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsIWindowWatcher.h"
|
2004-12-04 21:25:46 +03:00
|
|
|
#include "nsIXULAppInfo.h"
|
2005-05-12 17:23:30 +04:00
|
|
|
#include "nsIXULRuntime.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2005-01-17 21:50:18 +03:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2005-03-15 23:01:12 +03:00
|
|
|
#include "nsEmbedCID.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#include "nsNetUtil.h"
|
2005-07-21 17:33:43 +04:00
|
|
|
#include "nsStaticComponents.h"
|
2003-03-08 07:15:01 +03:00
|
|
|
#include "nsXPCOM.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2004-10-29 23:28:38 +04:00
|
|
|
#include "nsXPFEComponentsCID.h"
|
2006-08-17 18:22:04 +04:00
|
|
|
#include "nsVersionComparator.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsXREDirProvider.h"
|
2005-04-04 23:08:55 +04:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#include "nsINIParser.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2006-01-12 04:25:40 +03:00
|
|
|
#ifdef MOZ_XPINSTALL
|
2002-08-21 14:25:54 +04:00
|
|
|
#include "InstallCleanupDefines.h"
|
2006-01-12 04:25:40 +03:00
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-15 19:13:11 +04:00
|
|
|
#ifdef XP_BEOS
|
2006-06-08 22:20:07 +04:00
|
|
|
// execv() behaves bit differently in R5 and Zeta, looks unreliable in such situation
|
2005-04-15 19:13:11 +04:00
|
|
|
//#include <unistd.h>
|
|
|
|
#include <AppKit.h>
|
|
|
|
#include <AppFileInfo.h>
|
|
|
|
#endif //XP_BEOS
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_OS2
|
|
|
|
#include <process.h>
|
2006-06-08 22:20:07 +04:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsILocalFileMac.h"
|
2005-01-26 23:56:43 +03:00
|
|
|
#include "nsCommandLineServiceMac.h"
|
2004-06-18 01:23:51 +04:00
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
|
|
|
// for X remote support
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2005-04-04 23:08:55 +04:00
|
|
|
#ifdef MOZ_WIDGET_PHOTON
|
|
|
|
#include "PhRemoteClient.h"
|
|
|
|
#else
|
|
|
|
#include "XRemoteClient.h"
|
|
|
|
#endif
|
|
|
|
#include "nsIRemoteService.h"
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS_TRACE_MALLOC
|
|
|
|
#include "nsTraceMalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(XP_WIN32)
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-08 07:15:01 +03:00
|
|
|
#if defined (XP_MACOSX)
|
|
|
|
#include <Processes.h>
|
2005-10-07 22:09:43 +04:00
|
|
|
#include <Events.h>
|
2003-03-08 07:15:01 +03:00
|
|
|
#endif
|
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
extern "C" void ShowOSAlert(const char* aMessage);
|
|
|
|
|
2006-07-28 21:39:59 +04:00
|
|
|
#define HELP_SPACER_1 "\t"
|
|
|
|
#define HELP_SPACER_2 "\t\t"
|
|
|
|
#define HELP_SPACER_4 "\t\t\t\t"
|
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
#include "jprof.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// on x86 linux, the current builds of some popular plugins (notably
|
|
|
|
// flashplayer and real) expect a few builtin symbols from libgcc
|
|
|
|
// which were available in some older versions of gcc. However,
|
|
|
|
// they're _NOT_ available in newer versions of gcc (eg 3.1), so if
|
|
|
|
// we want those plugin to work with a gcc-3.1 built binary, we need
|
|
|
|
// to provide these symbols. MOZ_ENABLE_OLD_ABI_COMPAT_WRAPPERS defaults
|
|
|
|
// to true on x86 linux, and false everywhere else.
|
|
|
|
//
|
|
|
|
// The fact that the new and free operators are mismatched
|
|
|
|
// mirrors the way the original functions in egcs 1.1.2 worked.
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_OLD_ABI_COMPAT_WRAPPERS
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
# ifndef HAVE___BUILTIN_VEC_NEW
|
|
|
|
void *__builtin_vec_new(size_t aSize, const std::nothrow_t &aNoThrow) throw()
|
|
|
|
{
|
|
|
|
return ::operator new(aSize, aNoThrow);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef HAVE___BUILTIN_VEC_DELETE
|
|
|
|
void __builtin_vec_delete(void *aPtr, const std::nothrow_t &) throw ()
|
|
|
|
{
|
|
|
|
if (aPtr) {
|
|
|
|
free(aPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef HAVE___BUILTIN_NEW
|
|
|
|
void *__builtin_new(int aSize)
|
|
|
|
{
|
|
|
|
return malloc(aSize);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef HAVE___BUILTIN_DELETE
|
|
|
|
void __builtin_delete(void *aPtr)
|
|
|
|
{
|
|
|
|
free(aPtr);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef HAVE___PURE_VIRTUAL
|
|
|
|
void __pure_virtual(void) {
|
|
|
|
extern void __cxa_pure_virtual(void);
|
|
|
|
|
|
|
|
__cxa_pure_virtual();
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
|
|
|
extern void InstallUnixSignalHandlers(const char *ProgramName);
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
int gArgc;
|
|
|
|
char **gArgv;
|
|
|
|
|
|
|
|
static int gRestartArgc;
|
|
|
|
static char **gRestartArgv;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2003-03-07 01:01:01 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_GTK2)
|
2002-08-21 14:25:54 +04:00
|
|
|
#include <gtk/gtk.h>
|
2003-03-08 07:15:01 +03:00
|
|
|
#endif //MOZ_WIDGET_GTK || MOZ_WIDGET_GTK2
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-12-21 00:53:33 +03:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
#include <qapplication.h>
|
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-09-02 00:59:50 +04:00
|
|
|
// Save the path of the given file to the specified environment variable.
|
2005-09-01 22:55:27 +04:00
|
|
|
static void
|
|
|
|
SaveFileToEnv(const char *name, nsIFile *file)
|
|
|
|
{
|
|
|
|
nsCAutoString path;
|
|
|
|
file->GetNativePath(path);
|
|
|
|
|
|
|
|
char *expr = PR_smprintf("%s=%s", name, path.get());
|
|
|
|
if (expr)
|
|
|
|
PR_SetEnv(expr);
|
|
|
|
// We intentionally leak |expr| here since it is required by PR_SetEnv.
|
|
|
|
}
|
|
|
|
|
2005-09-02 00:59:50 +04: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)
|
|
|
|
{
|
|
|
|
const char *val = PR_GetEnv(name);
|
|
|
|
if (!(val && *val))
|
|
|
|
SaveFileToEnv(name, file);
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04: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 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
++lowerstr;
|
|
|
|
++mixedstr;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
if (*mixedstr) return PR_FALSE; // lowerstr is shorter
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return PR_TRUE;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2006-08-17 18:22:04 +04: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;
|
|
|
|
MessageBox(NULL, msg, "XULRunner", flags);
|
|
|
|
PR_smprintf_free(msg);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
enum ArgResult {
|
|
|
|
ARG_NONE = 0,
|
|
|
|
ARG_FOUND = 1,
|
|
|
|
ARG_BAD = 2 // you wanted a param, but there isn't one
|
|
|
|
};
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
static void RemoveArg(char **argv)
|
|
|
|
{
|
|
|
|
do {
|
2005-01-17 23:27:23 +03:00
|
|
|
*argv = *(argv + 1);
|
|
|
|
++argv;
|
2005-01-17 21:50:18 +03:00
|
|
|
} while (*argv);
|
|
|
|
|
|
|
|
--gArgc;
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04: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.
|
|
|
|
* @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
|
|
|
|
CheckArg(const char* aArg, const char **aParam = nsnull)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
char **curarg = gArgv + 1; // skip argv[0]
|
|
|
|
|
|
|
|
while (*curarg) {
|
|
|
|
char *arg = curarg[0];
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
if (arg[0] == '-'
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
|| *arg == '/'
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
) {
|
|
|
|
++arg;
|
|
|
|
if (*arg == '-')
|
|
|
|
++arg;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
if (strimatch(aArg, arg)) {
|
2005-01-17 21:50:18 +03:00
|
|
|
RemoveArg(curarg);
|
|
|
|
if (!aParam) {
|
|
|
|
return ARG_FOUND;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
if (*curarg) {
|
2004-06-18 01:23:51 +04:00
|
|
|
if (**curarg == '-'
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
|| **curarg == '/'
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
return ARG_BAD;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
*aParam = *curarg;
|
2005-01-17 21:50:18 +03:00
|
|
|
RemoveArg(curarg);
|
2004-06-18 01:23:51 +04:00
|
|
|
return ARG_FOUND;
|
|
|
|
}
|
|
|
|
return ARG_BAD;
|
|
|
|
}
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
++curarg;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return ARG_NONE;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2005-05-12 17:23:30 +04:00
|
|
|
PRBool gSafeMode = PR_FALSE;
|
|
|
|
|
2004-12-04 21:25:46 +03:00
|
|
|
/**
|
|
|
|
* The nsXULAppInfo object implements nsIFactory so that it can be its own
|
|
|
|
* singleton.
|
|
|
|
*/
|
|
|
|
class nsXULAppInfo : public nsIXULAppInfo,
|
2005-07-21 17:33:43 +04:00
|
|
|
public nsIXULRuntime
|
2004-12-04 21:25:46 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIXULAPPINFO
|
2005-05-12 17:23:30 +04:00
|
|
|
NS_DECL_NSIXULRUNTIME
|
2004-12-04 21:25:46 +03:00
|
|
|
};
|
|
|
|
|
2005-08-08 17:54:38 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXULAppInfo)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULRuntime)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULRuntime)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData)
|
|
|
|
NS_INTERFACE_MAP_END
|
2004-12-04 21:25:46 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXULAppInfo::AddRef()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsXULAppInfo::Release()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetVendor(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 17:23:30 +04:00
|
|
|
aResult.Assign(gAppData->vendor);
|
2004-12-04 21:25:46 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetName(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 17:23:30 +04:00
|
|
|
aResult.Assign(gAppData->name);
|
2004-12-04 21:25:46 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-07 07:53:07 +03:00
|
|
|
NS_IMETHODIMP
|
2005-05-12 17:23:30 +04:00
|
|
|
nsXULAppInfo::GetID(nsACString& aResult)
|
2004-12-07 07:53:07 +03:00
|
|
|
{
|
2005-05-12 17:23:30 +04:00
|
|
|
aResult.Assign(gAppData->ID);
|
2004-12-07 07:53:07 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-04 21:25:46 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetVersion(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 17:23:30 +04:00
|
|
|
aResult.Assign(gAppData->version);
|
2004-12-04 21:25:46 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-15 00:29:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetPlatformVersion(nsACString& aResult)
|
|
|
|
{
|
|
|
|
aResult.AssignLiteral(TOOLKIT_EM_VERSION);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-04 21:25:46 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetAppBuildID(nsACString& aResult)
|
|
|
|
{
|
2005-05-12 17:23:30 +04:00
|
|
|
aResult.Assign(gAppData->buildID);
|
2004-12-04 21:25:46 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-07-15 00:29:06 +04:00
|
|
|
nsXULAppInfo::GetPlatformBuildID(nsACString& aResult)
|
2004-12-04 21:25:46 +03:00
|
|
|
{
|
2005-03-28 23:36:24 +04:00
|
|
|
aResult.Assign(NS_STRINGIFY(BUILD_ID));
|
2004-12-04 21:25:46 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-07 23:28:23 +04: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 17:23:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULAppInfo::GetInSafeMode(PRBool *aResult)
|
|
|
|
{
|
|
|
|
*aResult = gSafeMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-10 22:23:28 +04: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
|
|
|
|
}
|
|
|
|
|
2005-07-21 17:33:43 +04:00
|
|
|
static const nsXULAppInfo kAppInfo;
|
|
|
|
static NS_METHOD AppInfoConstructor(nsISupports* aOuter,
|
|
|
|
REFNSIID aIID, void **aResult)
|
2004-12-04 21:25:46 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
|
|
|
|
2005-07-21 17:33:43 +04:00
|
|
|
return NS_CONST_CAST(nsXULAppInfo*, &kAppInfo)->
|
|
|
|
QueryInterface(aIID, aResult);
|
2004-12-04 21:25:46 +03:00
|
|
|
}
|
|
|
|
|
2005-06-07 23:28:23 +04: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-18 01:23:51 +04: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 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
public:
|
|
|
|
ScopedXPCOMStartup() :
|
|
|
|
mServiceManager(nsnull) { }
|
|
|
|
~ScopedXPCOMStartup();
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult Initialize();
|
|
|
|
nsresult DoAutoreg();
|
|
|
|
nsresult RegisterProfileService(nsIToolkitProfileService* aProfileService);
|
|
|
|
nsresult SetWindowCreator(nsINativeAppSupport* native);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsIServiceManager* mServiceManager;
|
|
|
|
};
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
ScopedXPCOMStartup::~ScopedXPCOMStartup()
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
if (mServiceManager) {
|
|
|
|
gDirServiceProvider->DoShutdown();
|
|
|
|
|
2005-06-07 23:28:23 +04:00
|
|
|
WriteConsoleLog();
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ShutdownXPCOM(mServiceManager);
|
|
|
|
mServiceManager = nsnull;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-04 21:25:46 +03:00
|
|
|
// {95d89e3e-a169-41a3-8e56-719978e15b12}
|
2005-07-21 19:01:35 +04:00
|
|
|
#define APPINFO_CID \
|
|
|
|
{ 0x95d89e3e, 0xa169, 0x41a3, { 0x8e, 0x56, 0x71, 0x99, 0x78, 0xe1, 0x5b, 0x12 } }
|
2004-12-04 21:25:46 +03:00
|
|
|
|
2005-07-21 17:33:43 +04:00
|
|
|
static nsModuleComponentInfo kComponents[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"nsXULAppInfo",
|
2005-07-21 19:01:35 +04:00
|
|
|
APPINFO_CID,
|
2005-07-21 17:33:43 +04:00
|
|
|
XULAPPINFO_SERVICE_CONTRACTID,
|
|
|
|
AppInfoConstructor
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_NSGETMODULE(Apprunner, kComponents)
|
|
|
|
|
|
|
|
#if !defined(_BUILD_STATIC_BIN) && !defined(MOZ_ENABLE_LIBXUL)
|
|
|
|
static nsStaticModuleInfo const kXREStaticModules[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"Apprunner",
|
|
|
|
Apprunner_NSGetModule
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsStaticModuleInfo const *const kPStaticModules = kXREStaticModules;
|
|
|
|
PRUint32 const kStaticModuleCount = NS_ARRAY_LENGTH(kXREStaticModules);
|
|
|
|
#endif
|
2004-12-04 21:25:46 +03:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::Initialize()
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ASSERTION(gDirServiceProvider, "Should not get here!");
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult rv;
|
2005-07-21 17:33:43 +04:00
|
|
|
rv = NS_InitXPCOM3(&mServiceManager, gDirServiceProvider->GetAppDir(),
|
|
|
|
gDirServiceProvider,
|
|
|
|
kPStaticModules, kStaticModuleCount);
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Couldn't start xpcom!");
|
|
|
|
mServiceManager = nsnull;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2004-12-04 21:25:46 +03:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIComponentRegistrar> reg =
|
|
|
|
do_QueryInterface(mServiceManager);
|
|
|
|
NS_ASSERTION(reg, "Service Manager doesn't QI to Registrar.");
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return rv;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
// {0C4A446C-EE82-41f2-8D04-D366D2C7A7D4}
|
|
|
|
static const nsCID kNativeAppSupportCID =
|
|
|
|
{ 0xc4a446c, 0xee82, 0x41f2, { 0x8d, 0x4, 0xd3, 0x66, 0xd2, 0xc7, 0xa7, 0xd4 } };
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
// {5F5E59CE-27BC-47eb-9D1F-B09CA9049836}
|
|
|
|
static const nsCID kProfileServiceCID =
|
|
|
|
{ 0x5f5e59ce, 0x27bc, 0x47eb, { 0x9d, 0x1f, 0xb0, 0x9c, 0xa9, 0x4, 0x98, 0x36 } };
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::RegisterProfileService(nsIToolkitProfileService* aProfileService)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mServiceManager, "Not initialized!");
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIFactory> factory = do_QueryInterface(aProfileService);
|
|
|
|
NS_ASSERTION(factory, "Supposed to be an nsIFactory!");
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> reg (do_QueryInterface(mServiceManager));
|
|
|
|
if (!reg) return NS_ERROR_NO_INTERFACE;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return reg->RegisterFactory(kProfileServiceCID,
|
|
|
|
"Toolkit Profile Service",
|
|
|
|
NS_PROFILESERVICE_CONTRACTID,
|
|
|
|
factory);
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::DoAutoreg()
|
|
|
|
{
|
2002-08-21 14:25:54 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// _Always_ autoreg if we're in a debug build, under the assumption
|
|
|
|
// that people are busily modifying components and will be angry if
|
|
|
|
// their changes aren't noticed.
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar
|
|
|
|
(do_QueryInterface(mServiceManager));
|
|
|
|
NS_ASSERTION(registrar, "Where's the component registrar?");
|
|
|
|
|
2003-03-08 07:15:01 +03:00
|
|
|
registrar->AutoRegister(nsnull);
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-11-08 08:00:27 +03: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 08:06:46 +03:00
|
|
|
~nsSingletonFactory() { }
|
2004-11-08 08:00:27 +03: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-18 01:23:51 +04:00
|
|
|
/**
|
|
|
|
* Set our windowcreator on the WindowWatcher service.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-11-08 08:00:27 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar
|
|
|
|
(do_QueryInterface(mServiceManager));
|
|
|
|
NS_ASSERTION(registrar, "Where's the component registrar?");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFactory> nativeFactory = new nsSingletonFactory(native);
|
|
|
|
NS_ENSURE_TRUE(nativeFactory, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
rv = registrar->RegisterFactory(kNativeAppSupportCID,
|
|
|
|
"Native App Support",
|
|
|
|
NS_NATIVEAPPSUPPORT_CONTRACTID,
|
|
|
|
nativeFactory);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
// Inform the chrome registry about OS accessibility
|
|
|
|
nsCOMPtr<nsIToolkitChromeRegistry> cr (do_GetService(NS_CHROMEREGISTRY_CONTRACTID));
|
|
|
|
if (cr)
|
|
|
|
cr->CheckForOSAccessibility();
|
|
|
|
|
2004-10-29 23:28:38 +04:00
|
|
|
nsCOMPtr<nsIWindowCreator> creator (do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
if (!creator) return NS_ERROR_UNEXPECTED;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIWindowWatcher> wwatch
|
|
|
|
(do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return wwatch->SetWindowCreator(creator);
|
|
|
|
}
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
static void DumpArbitraryHelp()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogInit();
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
{
|
|
|
|
nsXREDirProvider dirProvider;
|
2006-08-17 18:22:04 +04:00
|
|
|
dirProvider.Initialize(nsnull, gAppData->xreDirectory);
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
xpcom.Initialize();
|
|
|
|
xpcom.DoAutoreg();
|
|
|
|
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdline
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
if (!cmdline)
|
|
|
|
return;
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCString text;
|
|
|
|
rv = cmdline->GetHelpText(text);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
printf("%s", text.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_LogTerm();
|
2005-01-17 21:50:18 +03: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()
|
|
|
|
{
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("Usage: %s [ options ... ] [URL]\n", gArgv[0]);
|
|
|
|
printf(" where options include:\n");
|
|
|
|
printf("\n");
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
/* insert gtk options above moz options, like any other gtk app
|
|
|
|
*
|
|
|
|
* note: this isn't a very cool way to do things -- i'd rather get
|
|
|
|
* these straight from a user's gtk version -- but it seems to be
|
|
|
|
* what most gtk apps do. -dr
|
|
|
|
*/
|
|
|
|
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("GTK options\n");
|
|
|
|
printf("%s--gdk-debug=FLAGS%sGdk debugging flags to set\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--gdk-no-debug=FLAGS%sGdk debugging flags to unset\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--gtk-debug=FLAGS%sGtk+ debugging flags to set\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--gtk-no-debug=FLAGS%sGtk+ debugging flags to unset\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--gtk-module=MODULE%sLoad an additional Gtk module\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s-install%sInstall a private colormap\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
|
|
|
|
/* end gtk toolkit options */
|
2005-01-17 21:50:18 +03:00
|
|
|
#endif /* MOZ_WIDGET_GTK */
|
|
|
|
#if MOZ_WIDGET_XLIB
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("Xlib options\n");
|
|
|
|
printf("%s-display=DISPLAY%sX display to use\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s-visual=VISUALID%sX visual to use\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s-install_colormap%sInstall own colormap\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s-sync%sMake X calls synchronous\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s-no-xshm%sDon't use X shared memory extension\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
|
|
|
|
/* end xlib toolkit options */
|
2005-01-17 21:50:18 +03:00
|
|
|
#endif /* MOZ_WIDGET_XLIB */
|
|
|
|
#ifdef MOZ_X11
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("X11 options\n");
|
|
|
|
printf("%s--display=DISPLAY%sX display to use\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--sync%sMake X calls synchronous\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--no-xshm%sDon't use X shared memory extension\n", HELP_SPACER_1, HELP_SPACER_2);
|
|
|
|
printf("%s--xim-preedit=STYLE\n", HELP_SPACER_1);
|
|
|
|
printf("%s--xim-status=STYLE\n", HELP_SPACER_1);
|
2005-01-17 21:50:18 +03:00
|
|
|
#endif
|
|
|
|
#ifdef XP_UNIX
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("%s--g-fatal-warnings%sMake all warnings fatal\n", HELP_SPACER_1, HELP_SPACER_2);
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("\nMozilla options\n");
|
|
|
|
#endif
|
2006-07-28 18:51:13 +04:00
|
|
|
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("%s-height <value>%sSet height of startup window to <value>.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-h or -help%sPrint this message.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-width <value>%sSet width of startup window to <value>.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-v or -version%sPrint %s version.\n",HELP_SPACER_1,HELP_SPACER_2, gAppData->name);
|
|
|
|
printf("%s-P <profile>%sStart with <profile>.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-ProfileManager%sStart with Profile Manager.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-UILocale <locale>%sStart with <locale> resources as UI Locale.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-contentLocale <locale>%sStart with <locale> resources as content Locale.\n",HELP_SPACER_1,HELP_SPACER_2);
|
|
|
|
printf("%s-safe-mode%sDisables extensions and themes for this session.\n",HELP_SPACER_1,HELP_SPACER_2);
|
2005-03-07 21:28:40 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("%s-console%sStart %s with a debugging console.\n",HELP_SPACER_1,HELP_SPACER_2,gAppData->name);
|
2005-01-17 21:50:18 +03: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();
|
|
|
|
}
|
|
|
|
|
2006-01-12 04:25:40 +03:00
|
|
|
#ifdef MOZ_XPINSTALL
|
2004-06-18 01:23:51 +04:00
|
|
|
// don't modify aAppDir directly... clone it first
|
|
|
|
static int
|
|
|
|
VerifyInstallation(nsIFile* aAppDir)
|
|
|
|
{
|
|
|
|
static const char lastResortMessage[] =
|
|
|
|
"A previous install did not complete correctly. Finishing install.";
|
|
|
|
|
|
|
|
// Maximum allowed / used length of alert message is 255 chars, due to restrictions on Mac.
|
|
|
|
// Please make sure that file contents and fallback_alert_text are at most 255 chars.
|
|
|
|
|
|
|
|
char message[256];
|
|
|
|
PRInt32 numRead = 0;
|
|
|
|
const char *messageToShow = lastResortMessage;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFile> messageFile;
|
|
|
|
rv = aAppDir->Clone(getter_AddRefs(messageFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
messageFile->AppendNative(NS_LITERAL_CSTRING("res"));
|
|
|
|
messageFile->AppendNative(CLEANUP_MESSAGE_FILENAME);
|
|
|
|
PRFileDesc* fd = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf (do_QueryInterface(messageFile));
|
|
|
|
if (lf) {
|
|
|
|
rv = lf->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
numRead = PR_Read(fd, message, sizeof(message)-1);
|
|
|
|
if (numRead > 0) {
|
|
|
|
message[numRead] = 0;
|
|
|
|
messageToShow = message;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
ShowOSAlert(messageToShow);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIFile> cleanupUtility;
|
|
|
|
aAppDir->Clone(getter_AddRefs(cleanupUtility));
|
|
|
|
if (!cleanupUtility) return 1;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
cleanupUtility->AppendNative(CLEANUP_UTIL);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
if (NS_FAILED(rv)) return 1;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
{ // extra scoping needed to release things before xpcom shutdown
|
|
|
|
//Create the process framework to run the cleanup utility
|
|
|
|
nsCOMPtr<nsIProcess> cleanupProcess
|
|
|
|
(do_CreateInstance(NS_PROCESS_CONTRACTID));
|
|
|
|
rv = cleanupProcess->Init(cleanupUtility);
|
|
|
|
if (NS_FAILED(rv)) return 1;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
rv = cleanupProcess->Run(PR_FALSE,nsnull, 0, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return 1;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2006-01-12 04:25:40 +03:00
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef DEBUG_warren
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#if defined(FREEBSD)
|
|
|
|
// pick up fpsetmask prototype.
|
|
|
|
#include <ieeefp.h>
|
2003-03-08 07:15:01 +03:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-07-28 21:39:59 +04:00
|
|
|
static void
|
2004-06-18 01:23:51 +04:00
|
|
|
DumpVersion()
|
|
|
|
{
|
2006-07-28 21:39:59 +04:00
|
|
|
printf("%s %s %s, %s\n", gAppData->vendor ? gAppData->vendor : "", gAppData->name, gAppData->version, gAppData->copyright);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
|
|
|
// use int here instead of a PR type since it will be returned
|
|
|
|
// from main - just to keep types consistent
|
|
|
|
static int
|
|
|
|
HandleRemoteArgument(const char* remote)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
|
|
|
|
const char *profile = 0;
|
2005-05-12 17:23:30 +04:00
|
|
|
nsCAutoString program(gAppData->name);
|
2004-07-08 01:38:27 +04:00
|
|
|
ToLowerCase(program);
|
2004-06-18 01:23:51 +04:00
|
|
|
const char *username = getenv("LOGNAME");
|
|
|
|
|
|
|
|
ar = CheckArg("p", &profile);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -p requires a profile name\n");
|
|
|
|
return 1;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2004-07-08 01:38:27 +04:00
|
|
|
const char *temp = nsnull;
|
|
|
|
ar = CheckArg("a", &temp);
|
2004-06-18 01:23:51 +04:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
|
|
|
return 1;
|
2004-07-08 01:38:27 +04:00
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
program.Assign(temp);
|
2003-03-08 07:15:01 +03:00
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-07-08 01:38:27 +04:00
|
|
|
ar = CheckArg("u", &username);
|
2004-06-18 01:23:51 +04:00
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -u requires a username\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-04-04 23:08:55 +04: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 14:25:54 +04:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
nsXPIDLCString response;
|
|
|
|
PRBool success = PR_FALSE;
|
|
|
|
rv = client.SendCommand(program.get(), username, profile, remote,
|
|
|
|
getter_Copies(response), &success);
|
|
|
|
// did the command fail?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: Failed to send command: %s\n",
|
|
|
|
response ? response.get() : "No response included");
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
if (!success) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: No running window found\n");
|
|
|
|
return 2;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
static PRBool
|
|
|
|
RemoteCommandLine()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
ArgResult ar;
|
|
|
|
|
2005-05-12 17:23:30 +04:00
|
|
|
nsCAutoString program(gAppData->name);
|
2005-04-04 23:08:55 +04:00
|
|
|
ToLowerCase(program);
|
|
|
|
const char *username = getenv("LOGNAME");
|
|
|
|
|
|
|
|
const char *temp = nsnull;
|
|
|
|
ar = CheckArg("a", &temp);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
|
|
|
|
return PR_FALSE;
|
|
|
|
} else if (ar == ARG_FOUND) {
|
|
|
|
program.Assign(temp);
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
ar = CheckArg("u", &username);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -u requires a username\n");
|
|
|
|
return PR_FALSE;
|
2003-03-08 07:15:01 +03:00
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
XRemoteClient client;
|
|
|
|
rv = client.Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsXPIDLCString response;
|
|
|
|
PRBool success = PR_FALSE;
|
|
|
|
rv = client.SendCommandLine(program.get(), username, nsnull,
|
|
|
|
gArgc, gArgv,
|
|
|
|
getter_Copies(response), &success);
|
|
|
|
// did the command fail?
|
|
|
|
if (NS_FAILED(rv) || !success)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
#endif // MOZ_ENABLE_XREMOTE
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2005-07-26 02:16:56 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
static char const *gBinaryPath;
|
|
|
|
#endif
|
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
nsresult
|
|
|
|
XRE_GetBinaryPath(const char* argv0, nsILocalFile* *aResult)
|
2005-06-11 01:01:40 +04:00
|
|
|
{
|
2005-06-13 20:45:22 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
// We need to use platform-specific hackery to find the
|
|
|
|
// path of this executable. This is copied, with some modifications, from
|
|
|
|
// nsGREDirServiceProvider.cpp
|
2005-06-13 20:45:22 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
char exePath[MAXPATHLEN];
|
2005-06-13 20:45:22 +04:00
|
|
|
|
|
|
|
if (!::GetModuleFileName(0, exePath, MAXPATHLEN))
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2005-06-13 20:45:22 +04:00
|
|
|
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,
|
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
2005-07-26 02:16:56 +04:00
|
|
|
if (gBinaryPath)
|
|
|
|
return NS_NewNativeLocalFile(nsDependentCString(gBinaryPath), PR_FALSE,
|
|
|
|
aResult);
|
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(lf));
|
|
|
|
nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(lf));
|
|
|
|
if (!lfm)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
// Works even if we're not bundled.
|
|
|
|
CFBundleRef appBundle = CFBundleGetMainBundle();
|
2005-06-13 20:45:22 +04:00
|
|
|
if (!appBundle)
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
|
2005-06-13 20:45:22 +04:00
|
|
|
if (!bundleURL)
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
FSRef fileRef;
|
|
|
|
if (!CFURLGetFSRef(bundleURL, &fileRef)) {
|
|
|
|
CFRelease(bundleURL);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
rv = lfm->InitWithFSRef(&fileRef);
|
|
|
|
CFRelease(bundleURL);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
struct stat fileStat;
|
2005-06-10 23:52:45 +04:00
|
|
|
char exePath[MAXPATHLEN];
|
2006-02-02 20:23:26 +03:00
|
|
|
char tmpPath[MAXPATHLEN];
|
2005-06-13 20:45:22 +04:00
|
|
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// on unix, there is no official way to get the path of the current binary.
|
|
|
|
// instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to
|
|
|
|
// multiple applications, we will try a series of techniques:
|
|
|
|
//
|
|
|
|
// 1) look for /proc/<pid>/exe which is a symlink to the executable on newer
|
|
|
|
// Linux kernels
|
|
|
|
// 2) use realpath() on argv[0], which works unless we're loaded from the
|
|
|
|
// PATH
|
|
|
|
// 3) manually walk through the PATH and look for ourself
|
|
|
|
// 4) give up
|
|
|
|
|
|
|
|
// #ifdef __linux__
|
|
|
|
#if 0
|
|
|
|
int r = readlink("/proc/self/exe", exePath, MAXPATHLEN);
|
|
|
|
|
|
|
|
// apparently, /proc/self/exe can sometimes return weird data... check it
|
|
|
|
if (r > 0 && r < MAXPATHLEN && stat(exePath, &fileStat) == 0) {
|
|
|
|
rv = NS_OK;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
#endif
|
|
|
|
if (NS_FAILED(rv) &&
|
|
|
|
realpath(argv0, exePath) && stat(exePath, &fileStat) == 0) {
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
const char *path = getenv("PATH");
|
|
|
|
if (!path)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
char *pathdup = strdup(path);
|
|
|
|
if (!pathdup)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
char *newStr = pathdup;
|
|
|
|
char *token;
|
|
|
|
while ( (token = nsCRT::strtok(newStr, ":", &newStr)) ) {
|
2006-02-02 20:23:26 +03:00
|
|
|
sprintf(tmpPath, "%s/%s", token, argv0);
|
|
|
|
if (realpath(tmpPath, exePath) && stat(exePath, &fileStat) == 0) {
|
2005-06-13 20:45:22 +04:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(pathdup);
|
|
|
|
if (!found)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,
|
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#elif defined(XP_OS2)
|
|
|
|
PPIB ppib;
|
|
|
|
PTIB ptib;
|
|
|
|
char exePath[MAXPATHLEN];
|
2005-06-13 20:45:22 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
DosGetInfoBlocks( &ptib, &ppib);
|
|
|
|
DosQueryModuleName( ppib->pib_hmte, MAXPATHLEN, exePath);
|
2005-06-13 20:45:22 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,
|
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
int32 cookie = 0;
|
|
|
|
image_info info;
|
|
|
|
|
|
|
|
if(get_next_image_info(0, &cookie, &info) != B_OK)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(info.name), PR_TRUE,
|
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#elif
|
|
|
|
#error Oops, you need platform-specific code here
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
NS_ADDREF(*aResult = lf);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
#define NS_ERROR_LAUNCHED_CHILD_PROCESS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_PROFILE, 200)
|
|
|
|
|
2005-08-31 21:50:32 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsWindowsRestart.cpp"
|
|
|
|
#endif
|
|
|
|
|
2005-06-21 03:18:00 +04: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,
|
|
|
|
PRBool aBlankCommandLine = PR_FALSE)
|
2005-06-13 20:45:22 +04: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-21 03:18:00 +04:00
|
|
|
|
|
|
|
if (aBlankCommandLine) {
|
|
|
|
gRestartArgc = 1;
|
|
|
|
gRestartArgv[gRestartArgc] = nsnull;
|
|
|
|
}
|
2005-06-13 20:45:22 +04:00
|
|
|
|
2006-07-20 01:08:19 +04:00
|
|
|
PR_SetEnv("MOZ_LAUNCHED_CHILD=1");
|
|
|
|
|
2005-06-13 20:45:22 +04:00
|
|
|
#if defined(XP_MACOSX)
|
2005-06-11 01:01:40 +04:00
|
|
|
LaunchChildMac(gRestartArgc, gRestartArgv);
|
2005-06-13 20:45:22 +04:00
|
|
|
#else
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
|
|
|
nsresult rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCAutoString exePath;
|
|
|
|
rv = lf->GetNativePath(exePath);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2005-08-31 21:50:32 +04:00
|
|
|
if (!WinLaunchChild(exePath.get(), gRestartArgc, gRestartArgv))
|
2005-06-13 20:45:22 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#elif defined(XP_OS2)
|
|
|
|
if (_execv(exePath.get(), gRestartArgv) == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-18 01:23:51 +04:00
|
|
|
#elif defined(XP_UNIX)
|
2005-06-13 20:45:22 +04:00
|
|
|
if (execv(exePath.get(), gRestartArgv) == -1)
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-06-08 22:20:07 +04:00
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
extern char **environ;
|
|
|
|
status_t res;
|
|
|
|
res = resume_thread(load_image(gRestartArgc,(const char **)gRestartArgv,(const char **)environ));
|
|
|
|
if (res != B_OK)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-06-18 01:23:51 +04:00
|
|
|
#else
|
2005-06-13 20:45:22 +04:00
|
|
|
PRProcess* process = PR_CreateProcess(exePath.get(), gRestartArgv,
|
2004-06-18 01:23:51 +04:00
|
|
|
nsnull, nsnull);
|
|
|
|
if (!process) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 exitCode;
|
|
|
|
PRStatus failed = PR_WaitProcess(process, &exitCode);
|
|
|
|
if (failed || exitCode)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-06-13 20:45:22 +04:00
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_ERROR_LAUNCHED_CHILD_PROCESS;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 23:01:12 +03:00
|
|
|
static const char kProfileProperties[] =
|
|
|
|
"chrome://mozapps/locale/profile/profileSelection.properties";
|
|
|
|
|
|
|
|
static nsresult
|
2005-04-26 04:37:23 +04:00
|
|
|
ProfileLockedDialog(nsILocalFile* aProfileDir, nsILocalFile* aProfileLocalDir,
|
|
|
|
nsIProfileUnlocker* aUnlocker,
|
2005-03-15 23:01:12 +03:00
|
|
|
nsINativeAppSupport* aNative, nsIProfileLock* *aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = xpcom.DoAutoreg();
|
|
|
|
rv |= xpcom.SetWindowCreator(aNative);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
{ //extra scoping is needed so we release these components before xpcom shutdown
|
|
|
|
nsCOMPtr<nsIStringBundleService> sbs
|
|
|
|
(do_GetService(NS_STRINGBUNDLE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(sbs, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> sb;
|
|
|
|
sbs->CreateBundle(kProfileProperties, getter_AddRefs(sb));
|
2005-06-07 23:28:23 +04:00
|
|
|
NS_ENSURE_TRUE_LOG(sbs, NS_ERROR_FAILURE);
|
2005-03-15 23:01:12 +03:00
|
|
|
|
2005-05-12 17:23:30 +04:00
|
|
|
NS_ConvertUTF8toUTF16 appName(gAppData->name);
|
2005-03-15 23:01:12 +03:00
|
|
|
const PRUnichar* params[] = {appName.get(), appName.get()};
|
|
|
|
|
|
|
|
nsXPIDLString killMessage;
|
2006-07-20 19:35:22 +04: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 19:54:34 +04:00
|
|
|
|
|
|
|
sb->FormatStringFromName(aUnlocker ? kRestartUnlocker : kRestartNoUnlocker,
|
2005-03-15 23:01:12 +03: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;
|
|
|
|
rv = ps->ConfirmEx(nsnull, killTitle, killMessage, flags,
|
|
|
|
killTitle, nsnull, nsnull, nsnull, nsnull, &button);
|
2005-06-07 23:28:23 +04:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2005-03-15 23:01:12 +03:00
|
|
|
|
|
|
|
if (button == 1 && aUnlocker) {
|
|
|
|
rv = aUnlocker->Unlock(nsIProfileUnlocker::FORCE_QUIT);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
return NS_LockProfilePath(aProfileDir, aProfileLocalDir, nsnull, aResult);
|
2005-03-15 23:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char kProfileManagerURL[] =
|
|
|
|
"chrome://mozapps/content/profile/profileSelection.xul";
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
static nsresult
|
|
|
|
ShowProfileManager(nsIToolkitProfileService* aProfileSvc,
|
|
|
|
nsINativeAppSupport* aNative)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
nsCOMPtr<nsILocalFile> profD, profLD;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = xpcom.RegisterProfileService(aProfileSvc);
|
|
|
|
rv |= xpcom.DoAutoreg();
|
|
|
|
rv |= xpcom.SetWindowCreator(aNative);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
2006-07-20 01:08:19 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
SetupMacCommandLine(gRestartArgc, gRestartArgv);
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 01:23:51 +04: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 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
ioParamBlock->SetObjects(dlgArray);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-10-29 23:28:38 +04:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup
|
|
|
|
(do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> newWindow;
|
|
|
|
rv = windowWatcher->OpenWindow(nsnull,
|
|
|
|
kProfileManagerURL,
|
|
|
|
"_blank",
|
|
|
|
"centerscreen,chrome,modal,titlebar",
|
|
|
|
ioParamBlock,
|
|
|
|
getter_AddRefs(newWindow));
|
|
|
|
|
2005-06-07 23:28:23 +04:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2004-06-18 01:23:51 +04: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 23:28:23 +04:00
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, rv);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
rv = lock->GetDirectory(getter_AddRefs(profD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = lock->GetLocalDirectory(getter_AddRefs(profLD));
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
lock->Unlock();
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2005-09-01 22:55:27 +04:00
|
|
|
SaveFileToEnv("XRE_PROFILE_PATH", profD);
|
|
|
|
SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", profLD);
|
2003-09-24 09:28:13 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
PRBool offline = PR_FALSE;
|
|
|
|
aProfileSvc->GetStartOffline(&offline);
|
|
|
|
if (offline) {
|
|
|
|
PR_SetEnv("XRE_START_OFFLINE=1");
|
|
|
|
}
|
2003-09-24 09:28:13 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return LaunchChild(aNative);
|
2003-09-24 09:28:13 +04:00
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
static nsresult
|
|
|
|
ImportProfiles(nsIToolkitProfileService* aPService,
|
|
|
|
nsINativeAppSupport* aNative)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult rv;
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
PR_SetEnv("XRE_IMPORT_PROFILES=1");
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
// try to import old-style profiles
|
|
|
|
{ // scope XPCOM
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
xpcom.DoAutoreg();
|
|
|
|
xpcom.RegisterProfileService(aPService);
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2006-07-20 01:08:19 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
SetupMacCommandLine(gRestartArgc, gRestartArgv);
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIProfileMigrator> migrator
|
|
|
|
(do_GetService(NS_PROFILEMIGRATOR_CONTRACTID));
|
|
|
|
if (migrator) {
|
|
|
|
migrator->Import();
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
aPService->Flush();
|
|
|
|
return LaunchChild(aNative);
|
|
|
|
}
|
2004-04-13 08:50:19 +04:00
|
|
|
|
2004-06-18 01:23:51 +04: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 18:01:17 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
static PRBool gDoMigration = PR_FALSE;
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
SelectProfile(nsIProfileLock* *aResult, nsINativeAppSupport* aNative,
|
|
|
|
PRBool* aStartOffline)
|
|
|
|
{
|
2004-04-08 18:01:17 +04:00
|
|
|
nsresult rv;
|
2004-06-18 01:23:51 +04:00
|
|
|
ArgResult ar;
|
|
|
|
const char* arg;
|
|
|
|
*aResult = nsnull;
|
|
|
|
*aStartOffline = PR_FALSE;
|
|
|
|
|
|
|
|
arg = PR_GetEnv("XRE_START_OFFLINE");
|
|
|
|
if ((arg && *arg) || CheckArg("offline"))
|
|
|
|
*aStartOffline = PR_TRUE;
|
|
|
|
|
|
|
|
arg = PR_GetEnv("XRE_PROFILE_PATH");
|
|
|
|
if (arg && *arg) {
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(arg), PR_TRUE,
|
|
|
|
getter_AddRefs(lf));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
nsCOMPtr<nsILocalFile> localDir;
|
|
|
|
arg = PR_GetEnv("XRE_PROFILE_LOCAL_PATH");
|
|
|
|
if (arg && *arg) {
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(arg), PR_TRUE,
|
|
|
|
getter_AddRefs(localDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
localDir = lf;
|
|
|
|
}
|
|
|
|
|
2005-07-26 02:16:56 +04:00
|
|
|
// Clear out flags that we handled (or should have handled!) last startup.
|
2005-07-26 02:41:54 +04:00
|
|
|
const char *dummy;
|
2005-07-26 02:16:56 +04:00
|
|
|
CheckArg("p", &dummy);
|
|
|
|
CheckArg("profile", &dummy);
|
2005-08-31 21:50:32 +04:00
|
|
|
CheckArg("profilemanager");
|
2005-07-26 02:16:56 +04:00
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
return NS_LockProfilePath(lf, localDir, nsnull, aResult);
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
if (CheckArg("migration"))
|
|
|
|
gDoMigration = PR_TRUE;
|
|
|
|
|
|
|
|
ar = CheckArg("profile", &arg);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: argument -profile requires a path\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
if (ar) {
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
2005-03-19 00:24:05 +03:00
|
|
|
rv = XRE_GetFileFromPath(arg, getter_AddRefs(lf));
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2005-03-15 23:01:12 +03:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
|
2005-04-26 04:37:23 +04: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 23:01:12 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
return ProfileLockedDialog(lf, lf, unlocker, aNative, aResult);
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsCOMPtr<nsIToolkitProfileService> profileSvc;
|
|
|
|
rv = NS_NewToolkitProfileService(getter_AddRefs(profileSvc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
ar = CheckArg("createprofile", &arg);
|
|
|
|
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 20:41:17 +04: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)) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: profile path not valid.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-04-26 04:37:23 +04: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 20:41:17 +04:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
} else {
|
2005-04-26 04:37:23 +04:00
|
|
|
rv = profileSvc->CreateProfile(nsnull, nsnull, nsDependentCString(arg),
|
2004-07-03 20:41:17 +04:00
|
|
|
getter_AddRefs(profile));
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = NS_ERROR_ABORT;
|
|
|
|
PR_fprintf(PR_STDERR, "Success: created profile '%s'\n", arg);
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04: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"));
|
|
|
|
PRBool exists;
|
|
|
|
prefsJSFile->Exists(&exists);
|
|
|
|
if (!exists)
|
|
|
|
prefsJSFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
2005-04-26 04:37:23 +04:00
|
|
|
// XXXdarin perhaps 0600 would be better?
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
rv = profileSvc->GetProfileCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR) {
|
|
|
|
arg = PR_GetEnv("XRE_IMPORT_PROFILES");
|
|
|
|
if (!count && (!arg || !*arg)) {
|
|
|
|
return ImportProfiles(profileSvc, aNative);
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ar = CheckArg("p", &arg);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
|
|
|
}
|
|
|
|
if (ar) {
|
|
|
|
nsCOMPtr<nsIToolkitProfile> profile;
|
|
|
|
rv = profileSvc->GetProfileByName(nsDependentCString(arg),
|
|
|
|
getter_AddRefs(profile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-03-15 23:01:12 +03:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
rv = profile->Lock(nsnull, aResult);
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return NS_OK;
|
2005-03-15 23:01:12 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> profileDir;
|
|
|
|
rv = profile->GetRootDir(getter_AddRefs(profileDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 04:37:23 +04: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 14:25:54 +04:00
|
|
|
}
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
if (CheckArg("profilemanager")) {
|
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2004-04-08 18:01:17 +04:00
|
|
|
|
2004-06-18 01:23:51 +04: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 04:37:23 +04:00
|
|
|
nsnull, // choose a default dir for us
|
2004-06-18 01:23:51 +04:00
|
|
|
NS_LITERAL_CSTRING("default"),
|
|
|
|
getter_AddRefs(profile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
profileSvc->Flush();
|
2005-03-15 23:01:12 +03:00
|
|
|
rv = profile->Lock(nsnull, aResult);
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return NS_OK;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04: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 23:01:12 +03:00
|
|
|
nsCOMPtr<nsIProfileUnlocker> unlocker;
|
|
|
|
rv = profile->Lock(getter_AddRefs(unlocker), aResult);
|
2004-06-18 01:23:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return NS_OK;
|
2005-03-15 23:01:12 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> profileDir;
|
|
|
|
rv = profile->GetRootDir(getter_AddRefs(profileDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-26 04:37:23 +04: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 14:25:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return ShowProfileManager(profileSvc, aNative);
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2004-12-07 11:10:39 +03:00
|
|
|
#define FILE_COMPATIBILITY_INFO NS_LITERAL_CSTRING("compatibility.ini")
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2005-07-23 18:00:07 +04:00
|
|
|
static PRBool
|
|
|
|
CheckCompatibility(nsIFile* aProfileDir, const nsCString& aVersion,
|
2006-02-15 06:14:27 +03:00
|
|
|
const nsCString& aOSABI, nsIFile* aXULRunnerDir,
|
|
|
|
nsIFile* aAppDir)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-12-07 11:10:39 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
2005-07-23 18:00:07 +04:00
|
|
|
return PR_FALSE;
|
2004-12-07 11:10:39 +03:00
|
|
|
file->AppendNative(FILE_COMPATIBILITY_INFO);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
nsINIParser parser;
|
2004-12-07 11:10:39 +03:00
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
|
|
|
nsresult rv = parser.Init(localFile);
|
|
|
|
if (NS_FAILED(rv))
|
2005-07-23 18:00:07 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-08-15 22:29:55 +04:00
|
|
|
nsCAutoString buf;
|
|
|
|
rv = parser.GetString("Compatibility", "LastVersion", buf);
|
2006-02-15 06:14:27 +03:00
|
|
|
if (NS_FAILED(rv) || !aVersion.Equals(buf))
|
2005-07-23 18:00:07 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2006-02-15 06:14:27 +03:00
|
|
|
rv = parser.GetString("Compatibility", "LastOSABI", buf);
|
|
|
|
if (NS_FAILED(rv) || !aOSABI.Equals(buf))
|
2005-07-23 18:00:07 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-08-15 22:29:55 +04:00
|
|
|
rv = parser.GetString("Compatibility", "LastPlatformDir", buf);
|
2005-07-23 18:00:07 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
2005-08-15 22:29:55 +04:00
|
|
|
rv = NS_NewNativeLocalFile(buf, PR_FALSE,
|
2005-07-23 18:00:07 +04: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 22:29:55 +04:00
|
|
|
rv = parser.GetString("Compatibility", "LastAppDir", buf);
|
2005-07-23 18:00:07 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-08-15 22:29:55 +04:00
|
|
|
rv = NS_NewNativeLocalFile(buf, PR_FALSE,
|
2005-07-23 18:00:07 +04:00
|
|
|
getter_AddRefs(lf));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-07-28 00:49:34 +04:00
|
|
|
rv = lf->Equals(aAppDir, &eq);
|
2005-07-23 18:00:07 +04:00
|
|
|
if (NS_FAILED(rv) || !eq)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
|
|
|
|
2004-12-07 11:10:39 +03:00
|
|
|
static void BuildVersion(nsCString &aBuf)
|
2004-06-18 01:23:51 +04:00
|
|
|
{
|
2005-05-12 17:23:30 +04:00
|
|
|
aBuf.Assign(gAppData->version);
|
2004-12-07 11:10:39 +03:00
|
|
|
aBuf.Append('_');
|
2005-05-12 17:23:30 +04:00
|
|
|
aBuf.Append(gAppData->buildID);
|
2004-12-07 11:10:39 +03:00
|
|
|
aBuf.Append('/');
|
|
|
|
aBuf.AppendLiteral(GRE_BUILD_ID);
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-07-23 18:00:07 +04:00
|
|
|
static void
|
|
|
|
WriteVersion(nsIFile* aProfileDir, const nsCString& aVersion,
|
2006-02-15 06:14:27 +03:00
|
|
|
const nsCString& aOSABI, nsIFile* aXULRunnerDir,
|
|
|
|
nsIFile* aAppDir)
|
2004-12-07 11:10:39 +03: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 18:00:07 +04:00
|
|
|
nsCAutoString platformDir;
|
|
|
|
aXULRunnerDir->GetNativePath(platformDir);
|
|
|
|
|
|
|
|
nsCAutoString appDir;
|
|
|
|
if (aAppDir)
|
|
|
|
aAppDir->GetNativePath(appDir);
|
|
|
|
|
2004-12-07 11:10:39 +03: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 18:00:07 +04: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 06:14:27 +03: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 18:00:07 +04: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-18 01:23:51 +04:00
|
|
|
|
2004-12-07 11:10:39 +03:00
|
|
|
PR_Close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool ComponentsListChanged(nsIFile* aProfileDir)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return PR_TRUE;
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING(".autoreg"));
|
|
|
|
|
|
|
|
PRBool exists = PR_FALSE;
|
|
|
|
file->Exists(&exists);
|
|
|
|
return exists;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
2005-07-23 18:00:07 +04:00
|
|
|
static void RemoveComponentRegistries(nsIFile* aProfileDir, nsIFile* aLocalProfileDir,
|
|
|
|
PRBool aRemoveEMFiles)
|
2004-06-18 01:23:51 +04:00
|
|
|
{
|
2004-12-07 11:10:39 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("compreg.dat"));
|
|
|
|
file->Remove(PR_FALSE);
|
|
|
|
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("xpti.dat"));
|
|
|
|
file->Remove(PR_FALSE);
|
|
|
|
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING(".autoreg"));
|
|
|
|
file->Remove(PR_FALSE);
|
2005-05-12 17:23:30 +04:00
|
|
|
|
2005-07-23 18:00:07 +04:00
|
|
|
if (aRemoveEMFiles) {
|
|
|
|
file->SetNativeLeafName(NS_LITERAL_CSTRING("extensions.ini"));
|
|
|
|
file->Remove(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2005-05-12 17:23:30 +04:00
|
|
|
aLocalProfileDir->Clone(getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("XUL" PLATFORM_FASL_SUFFIX));
|
|
|
|
file->Remove(PR_FALSE);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
2005-06-21 03:18:00 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 01:23:51 +04: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 07:15:01 +03:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-03-08 01:40:36 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
#include "prlink.h"
|
|
|
|
typedef void (*_g_set_application_name_fn)(const gchar *application_name);
|
|
|
|
#endif
|
|
|
|
|
2005-03-19 00:24:05 +03:00
|
|
|
int
|
|
|
|
XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
|
2002-08-21 14:25:54 +04:00
|
|
|
{
|
2004-06-18 01:23:51 +04:00
|
|
|
nsresult rv;
|
2002-08-21 14:25:54 +04:00
|
|
|
NS_TIMELINE_MARK("enter main");
|
|
|
|
|
2005-04-26 04:37:23 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (PR_GetEnv("XRE_MAIN_BREAK"))
|
|
|
|
NS_BREAK();
|
|
|
|
#endif
|
|
|
|
|
2005-04-15 16:34:32 +04:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
// 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.
|
2005-12-12 22:09:58 +03:00
|
|
|
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);
|
2005-04-15 16:34:32 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-08-21 14:25:54 +04:00
|
|
|
// Disable small heap allocator to get heapwalk() giving us
|
|
|
|
// accurate heap numbers. Win2k non-debug does not use small heap allocator.
|
|
|
|
// Win2k debug seems to be still using it.
|
|
|
|
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__set_sbh_threshold.asp
|
|
|
|
_set_sbh_threshold(0);
|
|
|
|
#endif
|
2005-04-15 16:34:32 +04:00
|
|
|
#endif
|
2002-08-21 14:25:54 +04:00
|
|
|
|
|
|
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
|
|
|
InstallUnixSignalHandlers(argv[0]);
|
|
|
|
#endif
|
|
|
|
|
2006-02-13 09:04:10 +03:00
|
|
|
#ifdef MOZ_ACCESSIBILITY_ATK
|
|
|
|
// Reset GTK_MODULES, strip atk-bridge if exists
|
|
|
|
// Mozilla will load libatk-bridge.so later if necessary
|
2006-02-27 14:09:59 +03:00
|
|
|
const char* gtkModules = PR_GetEnv("GTK_MODULES");
|
|
|
|
if (gtkModules && *gtkModules) {
|
2006-02-13 09:04:10 +03:00
|
|
|
nsCString gtkModulesStr(gtkModules);
|
|
|
|
gtkModulesStr.ReplaceSubstring("atk-bridge", "");
|
2006-02-27 14:09:59 +03:00
|
|
|
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.
|
2006-02-13 09:04:10 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 09:38:03 +04:00
|
|
|
// Unbuffer stdout, needed for tinderbox tests.
|
|
|
|
setbuf(stdout, 0);
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#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
|
|
|
|
|
|
|
|
gArgc = argc;
|
|
|
|
gArgv = argv;
|
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
NS_ENSURE_TRUE(aAppData, 2);
|
2005-05-12 17:23:30 +04:00
|
|
|
|
2005-07-26 02:16:56 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// The xulrunner stub executable tricks CFBundleGetMainBundle on
|
|
|
|
// purpose into lying about the main bundle path. It will set
|
|
|
|
// XRE_BINARY_PATH to inform us of our real location.
|
|
|
|
gBinaryPath = getenv("XRE_BINARY_PATH");
|
|
|
|
|
|
|
|
if (gBinaryPath && !*gBinaryPath)
|
|
|
|
gBinaryPath = nsnull;
|
2006-08-17 18:22:04 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-08-17 19:37:22 +04:00
|
|
|
if (appData.size > offsetof(nsXREAppData, minVersion)) {
|
|
|
|
if (!appData.minVersion) {
|
|
|
|
Output(PR_TRUE, "Error: Gecko:MinVersion not specified in application.ini\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-17 18:22:04 +04:00
|
|
|
|
2006-08-17 19:37:22 +04:00
|
|
|
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, TOOLKIT_EM_VERSION) > 0 ||
|
|
|
|
NS_CompareVersions(appData.maxVersion, TOOLKIT_EM_VERSION) < 0) {
|
|
|
|
Output(PR_TRUE, "Error: Platform version " TOOLKIT_EM_VERSION " is not compatible with\n"
|
|
|
|
"minVersion >= %s\nmaxVersion <= %s\n",
|
|
|
|
appData.minVersion, appData.maxVersion);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-17 18:22:04 +04:00
|
|
|
}
|
2006-07-20 01:08:19 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2006-07-20 01:08:19 +04:00
|
|
|
if (PR_GetEnv("MOZ_LAUNCHED_CHILD")) {
|
|
|
|
// 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-26 02:16:56 +04:00
|
|
|
#endif
|
|
|
|
|
2006-07-20 01:08:19 +04:00
|
|
|
PR_SetEnv("MOZ_LAUNCHED_CHILD=");
|
|
|
|
|
|
|
|
gRestartArgc = gArgc;
|
|
|
|
gRestartArgv = (char**) malloc(sizeof(char*) * (gArgc + 1));
|
2004-06-18 01:23:51 +04:00
|
|
|
if (!gRestartArgv) return 1;
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
int i;
|
2006-07-20 01:08:19 +04:00
|
|
|
for (i = 0; i < gArgc; ++i) {
|
|
|
|
gRestartArgv[i] = gArgv[i];
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2006-07-20 01:08:19 +04:00
|
|
|
gRestartArgv[gArgc] = nsnull;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#if defined(XP_OS2)
|
2005-03-07 21:28:40 +03:00
|
|
|
PRBool StartOS2App(int aArgc, char **aArgv);
|
|
|
|
if (!StartOS2App(gArgc, gArgv))
|
|
|
|
return 1;
|
2005-03-11 04:55:48 +03:00
|
|
|
ScopedFPHandler handler;
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif /* XP_OS2 */
|
|
|
|
|
2005-10-07 22:09:43 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (CheckArg("safe-mode") || GetCurrentKeyModifiers() & optionKey)
|
|
|
|
#else
|
2005-05-12 17:23:30 +04:00
|
|
|
if (CheckArg("safe-mode"))
|
2005-10-07 22:09:43 +04:00
|
|
|
#endif
|
2005-05-12 17:23:30 +04:00
|
|
|
gSafeMode = PR_TRUE;
|
|
|
|
|
2006-02-09 04:17:19 +03:00
|
|
|
// Handle -no-remote command line argument. Setup the environment to
|
|
|
|
// better accommodate other components and various restart scenarios.
|
|
|
|
if (CheckArg("no-remote"))
|
|
|
|
PR_SetEnv("MOZ_NO_REMOTE=1");
|
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
// Handle -help and -version command line arguments.
|
2004-06-18 01:23:51 +04:00
|
|
|
// They should return quickly, so we deal with them here.
|
|
|
|
if (CheckArg("h") || CheckArg("help") || CheckArg("?")) {
|
|
|
|
DumpHelp();
|
2002-08-21 14:25:54 +04:00
|
|
|
return 0;
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
if (CheckArg("v") || CheckArg("version")) {
|
|
|
|
DumpVersion();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-21 14:25:54 +04:00
|
|
|
#ifdef NS_TRACE_MALLOC
|
2004-06-19 22:41:08 +04:00
|
|
|
gArgc = argc = NS_TraceMallocStartupArgs(argc, argv);
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogInit();
|
|
|
|
|
2004-09-07 22:59:07 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
nsXREDirProvider dirProvider;
|
2006-08-17 18:22:04 +04:00
|
|
|
rv = dirProvider.Initialize(gAppData->directory, gAppData->xreDirectory);
|
2004-09-07 22:59:07 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 1;
|
2003-12-04 22:39:40 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Check for -register, which registers chrome and then exits immediately.
|
|
|
|
if (CheckArg("register")) {
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2003-12-04 22:39:40 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChromeRegistry> chromeReg
|
|
|
|
(do_GetService("@mozilla.org/chrome/chrome-registry;1"));
|
|
|
|
NS_ENSURE_TRUE(chromeReg, 1);
|
2003-12-04 22:39:40 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
chromeReg->CheckForNewChrome();
|
|
|
|
}
|
|
|
|
return 0;
|
2003-12-04 22:39:40 +03:00
|
|
|
}
|
|
|
|
|
2003-03-04 13:32:14 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_GTK2)
|
2006-02-10 18:00:36 +03: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);
|
|
|
|
|
|
|
|
// Initialize GTK+1/2 here for splash
|
2003-03-04 13:32:14 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2006-02-10 18:00:36 +03:00
|
|
|
gtk_set_locale();
|
2003-03-04 13:32:14 +03:00
|
|
|
#endif
|
2006-02-10 18:00:36 +03:00
|
|
|
gtk_init(&gArgc, &gArgv);
|
2004-03-05 01:59:50 +03:00
|
|
|
|
2005-03-08 01:40:36 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2006-02-10 18:00:36 +03:00
|
|
|
// g_set_application_name () is only defined in glib2.2 and higher.
|
|
|
|
PRLibrary *glib2 = nsnull;
|
|
|
|
_g_set_application_name_fn _g_set_application_name =
|
2005-03-08 01:40:36 +03:00
|
|
|
(_g_set_application_name_fn)PR_FindFunctionSymbolAndLibrary("g_set_application_name", &glib2);
|
2006-02-10 18:00:36 +03:00
|
|
|
if (_g_set_application_name) {
|
|
|
|
_g_set_application_name(gAppData->name);
|
|
|
|
}
|
|
|
|
if (glib2) {
|
|
|
|
PR_UnloadLibrary(glib2);
|
|
|
|
}
|
2005-03-08 01:40:36 +03:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
gtk_widget_set_default_visual(gdk_rgb_get_visual());
|
|
|
|
gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
|
2003-03-04 13:32:14 +03:00
|
|
|
#endif /* MOZ_WIDGET_GTK || MOZ_WIDGET_GTK2 */
|
2004-12-21 00:53:33 +03:00
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_QT)
|
2006-02-10 18:00:36 +03:00
|
|
|
QApplication qapp(argc, argv);
|
2004-12-21 00:53:33 +03:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// #if defined(MOZ_WIDGET_XLIB)
|
|
|
|
// XXXtimeless fix me! How do we get a Display from here to nsAppShell.cpp ?
|
|
|
|
// #endif
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Call the code to install our handler
|
2002-08-21 14:25:54 +04:00
|
|
|
#ifdef MOZ_JPROF
|
2006-02-10 18:00:36 +03:00
|
|
|
setupProfilingStuff();
|
2002-08-21 14:25:54 +04:00
|
|
|
#endif
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Try to allocate "native app support."
|
|
|
|
nsCOMPtr<nsINativeAppSupport> nativeApp;
|
|
|
|
rv = NS_CreateNativeAppSupport(getter_AddRefs(nativeApp));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return 1;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
PRBool canRun = PR_FALSE;
|
|
|
|
rv = nativeApp->Start(&canRun);
|
|
|
|
if (NS_FAILED(rv) || !canRun) {
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2006-01-12 04:25:40 +03:00
|
|
|
#ifdef MOZ_XPINSTALL
|
2006-02-10 18:00:36 +03:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
// We need to check if a previous installation occured and
|
|
|
|
// if so, make sure it finished and cleaned up correctly.
|
|
|
|
//
|
|
|
|
// If there is an xpicleanup.dat file left around, that means the
|
|
|
|
// previous installation did not finish correctly. We must cleanup
|
|
|
|
// before a valid mozilla can run.
|
|
|
|
//
|
|
|
|
// Show the user a platform-specific Alert message, then spawn the
|
|
|
|
// xpicleanup utility, then exit.
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> registryFile;
|
|
|
|
rv = dirProvider.GetAppDir()->Clone(getter_AddRefs(registryFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
registryFile->AppendNative(CLEANUP_REGISTRY);
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
PRBool exists;
|
|
|
|
rv = registryFile->Exists(&exists);
|
|
|
|
if (NS_SUCCEEDED(rv) && exists) {
|
|
|
|
return VerifyInstallation(dirProvider.GetAppDir());
|
|
|
|
}
|
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
}
|
2006-01-12 04:25:40 +03:00
|
|
|
#endif
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2006-02-10 18:00:36 +03:00
|
|
|
// handle -remote now that xpcom is fired up
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
const char* xremotearg;
|
|
|
|
ArgResult ar = CheckArg("remote", &xremotearg);
|
|
|
|
if (ar == ARG_BAD) {
|
|
|
|
PR_fprintf(PR_STDERR, "Error: -remote requires an argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (ar) {
|
|
|
|
return HandleRemoteArgument(xremotearg);
|
|
|
|
}
|
2005-04-04 23:08:55 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
if (!PR_GetEnv("MOZ_NO_REMOTE")) {
|
|
|
|
// Try to remote the entire command line. If this fails, start up normally.
|
|
|
|
if (RemoteCommandLine())
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-08 07:15:01 +03:00
|
|
|
#endif
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2005-07-28 00:46:34 +04:00
|
|
|
#if defined(MOZ_UPDATER)
|
2006-02-22 00:10:55 +03:00
|
|
|
// Check for and process any available updates
|
|
|
|
ProcessUpdates(dirProvider.GetGREDir(),
|
|
|
|
dirProvider.GetAppDir(),
|
|
|
|
gRestartArgc,
|
|
|
|
gRestartArgv);
|
2005-07-28 00:46:34 +04:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCOMPtr<nsIProfileLock> profileLock;
|
|
|
|
PRBool startOffline = PR_FALSE;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
rv = SelectProfile(getter_AddRefs(profileLock), nativeApp, &startOffline);
|
|
|
|
if (rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ||
|
|
|
|
rv == NS_ERROR_ABORT) return 0;
|
|
|
|
if (NS_FAILED(rv)) return 1;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCOMPtr<nsILocalFile> profD;
|
|
|
|
rv = profileLock->GetDirectory(getter_AddRefs(profD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2005-04-26 04:37:23 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCOMPtr<nsILocalFile> profLD;
|
|
|
|
rv = profileLock->GetLocalDirectory(getter_AddRefs(profLD));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
rv = dirProvider.SetProfile(profD, profLD);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
//////////////////////// NOW WE HAVE A PROFILE ////////////////////////
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
PRBool upgraded = PR_FALSE;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCAutoString version;
|
|
|
|
BuildVersion(version);
|
2005-07-23 18:00:07 +04:00
|
|
|
|
2006-02-15 06:14:27 +03: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 18:00:36 +03: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.
|
2006-02-15 06:14:27 +03:00
|
|
|
PRBool versionOK = CheckCompatibility(profD, version, osABI,
|
2006-02-10 18:00:36 +03:00
|
|
|
dirProvider.GetGREDir(),
|
|
|
|
gAppData->directory);
|
2004-12-07 11:10:39 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Every time a profile is loaded by a build with a different version,
|
|
|
|
// it updates the compatibility.ini file saying what version last wrote
|
|
|
|
// the compreg.dat. On subsequent launches if the version matches,
|
|
|
|
// there is no need for re-registration. If the user loads the same
|
|
|
|
// profile in different builds the component registry must be
|
|
|
|
// re-generated to prevent mysterious component loading failures.
|
|
|
|
//
|
|
|
|
if (gSafeMode) {
|
2005-07-23 18:00:07 +04:00
|
|
|
RemoveComponentRegistries(profD, profLD, PR_FALSE);
|
2006-02-15 06:14:27 +03:00
|
|
|
WriteVersion(profD, NS_LITERAL_CSTRING("Safe Mode"), osABI,
|
2006-02-10 18:00:36 +03:00
|
|
|
dirProvider.GetGREDir(), gAppData->directory);
|
|
|
|
}
|
|
|
|
else if (versionOK) {
|
|
|
|
if (ComponentsListChanged(profD)) {
|
|
|
|
// Remove compreg.dat and xpti.dat, forcing component re-registration.
|
|
|
|
// The new list of additional components directories is derived from
|
|
|
|
// information in "extensions.ini".
|
|
|
|
RemoveComponentRegistries(profD, profLD, PR_FALSE);
|
|
|
|
}
|
|
|
|
// Nothing need be done for the normal startup case.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Remove compreg.dat and xpti.dat, forcing component re-registration
|
|
|
|
// with the default set of components (this disables any potentially
|
|
|
|
// troublesome incompatible XPCOM components).
|
|
|
|
RemoveComponentRegistries(profD, profLD, PR_TRUE);
|
|
|
|
|
|
|
|
// Tell the Extension Manager it should check for incompatible
|
|
|
|
// Extensions and re-write the "extensions.ini" file with a list of
|
|
|
|
// directories for compatible extensions
|
|
|
|
upgraded = PR_TRUE;
|
|
|
|
|
|
|
|
// Write out version
|
2006-02-15 06:14:27 +03:00
|
|
|
WriteVersion(profD, version, osABI,
|
2006-02-10 18:00:36 +03:00
|
|
|
dirProvider.GetGREDir(), gAppData->directory);
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
PRBool needsRestart = PR_FALSE;
|
|
|
|
PRBool appInitiatedRestart = PR_FALSE;
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03: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-18 01:23:51 +04:00
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
// Start the real application
|
|
|
|
ScopedXPCOMStartup xpcom;
|
|
|
|
rv = xpcom.Initialize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
rv = xpcom.DoAutoreg();
|
|
|
|
rv |= xpcom.SetWindowCreator(nativeApp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
{
|
2006-02-10 18:00:36 +03:00
|
|
|
if (startOffline) {
|
|
|
|
nsCOMPtr<nsIIOService> io (do_GetService("@mozilla.org/network/io-service;1"));
|
|
|
|
NS_ENSURE_TRUE(io, 1);
|
|
|
|
io->SetOffline(PR_TRUE);
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
{
|
|
|
|
NS_TIMELINE_ENTER("startupNotifier");
|
|
|
|
nsCOMPtr<nsIObserver> startupNotifier
|
|
|
|
(do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
startupNotifier->Observe(nsnull, APPSTARTUP_TOPIC, nsnull);
|
|
|
|
NS_TIMELINE_LEAVE("startupNotifier");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAppStartup> appStartup
|
|
|
|
(do_GetService(NS_APPSTARTUP_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appStartup, 1);
|
|
|
|
|
|
|
|
if (gDoMigration) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2006-02-28 18:28:38 +03:00
|
|
|
dirProvider.GetAppDir()->Clone(getter_AddRefs(file));
|
2006-02-10 18:00:36 +03:00
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("override.ini"));
|
|
|
|
nsINIParser parser;
|
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
|
|
|
|
nsresult rv = parser.Init(localFile);
|
2006-01-13 22:38:07 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-02-10 18:00:36 +03: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 22:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03: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);
|
|
|
|
}
|
|
|
|
dirProvider.DoStartup();
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdLine
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
NS_ENSURE_TRUE(cmdLine, 1);
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCOMPtr<nsIFile> workingDir;
|
|
|
|
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
rv = cmdLine->Init(gArgc, gArgv,
|
|
|
|
workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
/* Special-case services that need early access to the command
|
|
|
|
line. */
|
|
|
|
nsCOMPtr<nsIObserver> chromeObserver
|
|
|
|
(do_GetService("@mozilla.org/chrome/chrome-registry;1"));
|
|
|
|
if (chromeObserver) {
|
|
|
|
chromeObserver->Observe(cmdLine, "command-line-startup", nsnull);
|
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_TIMELINE_ENTER("appStartup->CreateHiddenWindow");
|
|
|
|
rv = appStartup->CreateHiddenWindow();
|
|
|
|
NS_TIMELINE_LEAVE("appStartup->CreateHiddenWindow");
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-07-03 20:41:17 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Extension Compatibility Checking and Startup
|
|
|
|
if (gAppData->flags & NS_XRE_ENABLE_EXTENSION_MANAGER) {
|
|
|
|
nsCOMPtr<nsIExtensionManager> em(do_GetService("@mozilla.org/extensions/manager;1"));
|
|
|
|
NS_ENSURE_TRUE(em, 1);
|
2004-09-09 22:10:25 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
if (CheckArg("install-global-extension") || CheckArg("install-global-theme")) {
|
|
|
|
// Do the required processing and then shut down.
|
|
|
|
em->HandleCommandLineArgs(cmdLine);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
if (upgraded) {
|
|
|
|
rv = em->CheckForMismatches(&needsRestart);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
needsRestart = PR_FALSE;
|
|
|
|
upgraded = PR_FALSE;
|
|
|
|
}
|
2004-09-09 22:10:25 +04:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
if (!upgraded || !needsRestart)
|
|
|
|
em->Start(cmdLine, &needsRestart);
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// We want to restart no more than 2 times. The first restart,
|
|
|
|
// NO_EM_RESTART == "0" , and the second time, "1".
|
|
|
|
char* noEMRestart = PR_GetEnv("NO_EM_RESTART");
|
|
|
|
if (noEMRestart && *noEMRestart && *noEMRestart == '1') {
|
|
|
|
if (upgraded || needsRestart) {
|
|
|
|
NS_WARNING("EM tried to force us to restart twice! Forcefully preventing that.");
|
|
|
|
}
|
|
|
|
needsRestart = upgraded = PR_FALSE;
|
2005-03-07 22:00:19 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
if (!upgraded && !needsRestart) {
|
|
|
|
SaveStateForAppInitiatedRestart();
|
2004-09-08 09:43:21 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// clear out any environment variables which may have been set
|
|
|
|
// during the relaunch process now that we know we won't be relaunching.
|
|
|
|
PR_SetEnv("XRE_PROFILE_PATH=");
|
|
|
|
PR_SetEnv("XRE_PROFILE_LOCAL_PATH=");
|
|
|
|
PR_SetEnv("XRE_START_OFFLINE=");
|
|
|
|
PR_SetEnv("XRE_IMPORT_PROFILES=");
|
|
|
|
PR_SetEnv("NO_EM_RESTART=");
|
|
|
|
PR_SetEnv("XUL_APP_FILE=");
|
|
|
|
PR_SetEnv("XRE_BINARY_PATH=");
|
2004-09-08 09:43:21 +04:00
|
|
|
|
2005-01-28 18:04:07 +03:00
|
|
|
#ifdef XP_MACOSX
|
2006-02-10 18:00:36 +03: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 18:04:07 +03:00
|
|
|
|
2006-07-20 01:08:19 +04:00
|
|
|
SetupMacCommandLine(gArgc, gArgv);
|
2005-01-28 18:04:07 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
rv = cmdLine->Init(gArgc, gArgv,
|
|
|
|
workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2004-06-29 03:52:30 +04:00
|
|
|
#endif
|
2006-02-10 18:00:36 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsService
|
|
|
|
(do_GetService("@mozilla.org/observer-service;1"));
|
|
|
|
if (obsService)
|
|
|
|
obsService->NotifyObservers(nsnull, "final-ui-startup", nsnull);
|
2004-06-29 03:52:30 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
rv = cmdLine->Run();
|
|
|
|
NS_ENSURE_SUCCESS_LOG(rv, 1);
|
2004-06-18 01:23:51 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2006-02-10 18:00:36 +03:00
|
|
|
// if we have X remote support, start listening for requests on the
|
|
|
|
// proxy window.
|
|
|
|
nsCOMPtr<nsIRemoteService> remoteService;
|
|
|
|
remoteService = do_GetService("@mozilla.org/toolkit/remote-service;1");
|
|
|
|
if (remoteService)
|
|
|
|
remoteService->Startup(gAppData->name, nsnull);
|
2004-06-18 01:23:51 +04:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// enable win32 DDE responses and Mac appleevents responses
|
|
|
|
nativeApp->Enable();
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_TIMELINE_ENTER("appStartup->Run");
|
|
|
|
rv = appStartup->Run();
|
|
|
|
NS_TIMELINE_LEAVE("appStartup->Run");
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("failed to run appstartup");
|
|
|
|
gLogConsoleErrors = PR_TRUE;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Check for an application initiated restart. This is one that
|
|
|
|
// corresponds to nsIAppStartup.quit(eRestart)
|
|
|
|
if (rv == NS_SUCCESS_RESTART_APP) {
|
|
|
|
needsRestart = PR_TRUE;
|
|
|
|
appInitiatedRestart = PR_TRUE;
|
|
|
|
}
|
2005-06-21 03:18:00 +04:00
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
#ifdef MOZ_ENABLE_XREMOTE
|
2006-02-10 18:00:36 +03:00
|
|
|
// shut down the x remote proxy window
|
|
|
|
if (remoteService)
|
|
|
|
remoteService->Shutdown();
|
2004-06-18 01:23:51 +04:00
|
|
|
#endif /* MOZ_ENABLE_XREMOTE */
|
|
|
|
|
|
|
|
#ifdef MOZ_TIMELINE
|
2006-02-10 18:00:36 +03:00
|
|
|
// Make sure we print this out even if timeline is runtime disabled
|
|
|
|
if (NS_FAILED(NS_TIMELINE_LEAVE("main1")))
|
|
|
|
NS_TimelineForceMark("...main1");
|
2003-03-08 07:15:01 +03:00
|
|
|
#endif
|
2006-02-10 18:00:36 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Upgrade condition (build id changes), but the restart hint was
|
|
|
|
// not set by the Extension Manager. This is because the compatibility
|
|
|
|
// resolution for Extensions is different than for the component
|
|
|
|
// registry - major milestone vs. build id.
|
|
|
|
needsRestart = PR_TRUE;
|
2006-07-20 01:08:19 +04:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
SetupMacCommandLine(gRestartArgc, gRestartArgv);
|
|
|
|
#endif
|
2006-02-10 18:00:36 +03:00
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
2002-08-21 14:25:54 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
profileLock->Unlock();
|
2005-05-31 23:10:26 +04:00
|
|
|
}
|
2006-02-10 18:00:36 +03:00
|
|
|
|
|
|
|
// Restart the app after XPCOM has been shut down cleanly.
|
|
|
|
if (needsRestart) {
|
|
|
|
if (appInitiatedRestart) {
|
|
|
|
RestoreStateForAppInitiatedRestart();
|
2005-06-21 03:18:00 +04:00
|
|
|
}
|
|
|
|
else {
|
2006-02-10 18:00:36 +03:00
|
|
|
char* noEMRestart = PR_GetEnv("NO_EM_RESTART");
|
|
|
|
if (noEMRestart && *noEMRestart) {
|
|
|
|
PR_SetEnv("NO_EM_RESTART=1");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PR_SetEnv("NO_EM_RESTART=0");
|
|
|
|
}
|
2005-06-21 03:18:00 +04:00
|
|
|
}
|
2005-03-07 22:00:19 +03:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
// Ensure that these environment variables are set:
|
|
|
|
SaveFileToEnvIfUnset("XRE_PROFILE_PATH", profD);
|
|
|
|
SaveFileToEnvIfUnset("XRE_PROFILE_LOCAL_PATH", profLD);
|
2003-03-08 07:15:01 +03:00
|
|
|
|
2005-07-26 02:16:56 +04:00
|
|
|
#ifdef XP_MACOSX
|
2006-02-10 18:00:36 +03:00
|
|
|
if (gBinaryPath) {
|
|
|
|
static char kEnvVar[MAXPATHLEN];
|
|
|
|
sprintf(kEnvVar, "XRE_BINARY_PATH=%s", gBinaryPath);
|
|
|
|
PR_SetEnv(kEnvVar);
|
|
|
|
}
|
2005-07-26 02:16:56 +04:00
|
|
|
#endif
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
rv = LaunchChild(nativeApp, appInitiatedRestart);
|
|
|
|
return rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ? 0 : 1;
|
|
|
|
}
|
2004-06-18 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_LogTerm();
|
|
|
|
|
2004-06-18 01:23:51 +04:00
|
|
|
return NS_FAILED(rv) ? 1 : 0;
|
2003-03-08 07:15:01 +03:00
|
|
|
}
|