CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / toolkit / xre / nsAppRunner.h
blob68b7c4627615ec92e94f5bd75347daaa0a9b5e1f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsAppRunner_h__
39 #define nsAppRunner_h__
41 #ifdef XP_WIN
42 #include <windows.h>
43 #else
44 #include <limits.h>
45 #endif
47 #ifndef MAXPATHLEN
48 #ifdef PATH_MAX
49 #define MAXPATHLEN PATH_MAX
50 #elif defined(_MAX_PATH)
51 #define MAXPATHLEN _MAX_PATH
52 #elif defined(CCHMAXPATH)
53 #define MAXPATHLEN CCHMAXPATH
54 #else
55 #define MAXPATHLEN 1024
56 #endif
57 #endif
59 #include "nscore.h"
60 #include "nsXULAppAPI.h"
62 // This directory service key is a lot like NS_APP_LOCALSTORE_50_FILE,
63 // but it is always the "main" localstore file, even when we're in safe mode
64 // and we load localstore from somewhere else.
65 #define NS_LOCALSTORE_UNSAFE_FILE "LStoreS"
67 /**
68 * A directory service key which provides the update directory.
69 * At present this is supported only on Windows.
70 * Windows: Documents and Settings\<User>\Local Settings\Application Data\
71 * <Vendor>\<Application>\<relative path to app dir from Program Files>
72 * If appDir is not under the Program Files, directory service will fail.
73 * Callers should fallback to appDir.
75 #define XRE_UPDATE_ROOT_DIR "UpdRootD"
77 class nsACString;
78 struct nsStaticModuleInfo;
80 class nsINativeAppSupport;
81 class nsICmdLineService;
82 class nsXREDirProvider;
83 class nsIToolkitProfileService;
84 class nsILocalFile;
85 class nsIProfileLock;
86 class nsIProfileUnlocker;
87 class nsIFactory;
89 extern nsXREDirProvider* gDirServiceProvider;
91 // NOTE: gAppData will be null in embedded contexts. The "size" parameter
92 // will be the size of the original structure passed to XRE_main, but the
93 // structure will have all of the members available.
94 extern const nsXREAppData* gAppData;
95 extern PRBool gSafeMode;
97 extern int gArgc;
98 extern char **gArgv;
99 extern PRBool gLogConsoleErrors;
102 * Create the nativeappsupport implementation.
104 * @note XPCOMInit has not happened yet.
106 nsresult NS_CreateNativeAppSupport(nsINativeAppSupport* *aResult);
108 NS_HIDDEN_(nsresult)
109 NS_NewToolkitProfileService(nsIToolkitProfileService* *aResult);
111 NS_HIDDEN_(nsresult)
112 NS_NewToolkitProfileFactory(nsIFactory* *aResult);
115 * Try to acquire exclusive access to the specified profile directory.
117 * @param aPath
118 * The profile directory to lock.
119 * @param aTempPath
120 * The corresponding profile temporary directory.
121 * @param aUnlocker
122 * A callback interface used to attempt to unlock a profile that
123 * appears to be locked.
124 * @param aResult
125 * The resulting profile lock object (or null if the profile could
126 * not be locked).
128 * @return NS_ERROR_FILE_ACCESS_DENIED to indicate that the profile
129 * directory cannot be unlocked.
131 NS_HIDDEN_(nsresult)
132 NS_LockProfilePath(nsILocalFile* aPath, nsILocalFile* aTempPath,
133 nsIProfileUnlocker* *aUnlocker, nsIProfileLock* *aResult);
135 NS_HIDDEN_(void)
136 WriteConsoleLog();
138 #ifdef XP_WIN
139 BOOL
140 WinLaunchChild(const PRUnichar *exePath, int argc, char **argv);
141 #endif
143 #define NS_NATIVEAPPSUPPORT_CONTRACTID "@mozilla.org/toolkit/native-app-support;1"
145 // Like nsXREAppData, but releases all strong refs/allocated memory
146 // in the destructor.
147 class ScopedAppData : public nsXREAppData
149 public:
150 ScopedAppData() { Zero(); this->size = sizeof(*this); }
152 ScopedAppData(const nsXREAppData* aAppData);
154 void Zero() { memset(this, 0, sizeof(*this)); }
156 ~ScopedAppData();
160 * Given "str" is holding a string allocated with NS_Alloc, or null:
161 * replace the value in "str" with a new value.
163 * @param newvalue Null is permitted. The string is cloned with
164 * NS_strdup
166 void SetAllocatedString(const char *&str, const char *newvalue);
169 * Given "str" is holding a string allocated with NS_Alloc, or null:
170 * replace the value in "str" with a new value.
172 * @param newvalue If "newvalue" is the empty string, "str" will be set
173 * to null.
175 void SetAllocatedString(const char *&str, const nsACString &newvalue);
177 template<class T>
178 void SetStrongPtr(T *&ptr, T* newvalue)
180 NS_IF_RELEASE(ptr);
181 ptr = newvalue;
182 NS_IF_ADDREF(ptr);
185 #ifdef MOZ_IPC
186 namespace mozilla {
187 namespace startup {
188 extern GeckoProcessType sChildProcessType;
191 #endif
194 * Set up platform specific error handling such as suppressing DLL load dialog
195 * and the JIT debugger on Windows, and install unix signal handlers.
197 void SetupErrorHandling(const char* progname);
199 #endif // nsAppRunner_h__