12
12
// macOS todos:
13
13
// TODO: Allow disabling content processes on macOS
14
14
15
+ #include " XREChildData.h"
15
16
#include " mozilla/Bootstrap.h"
16
17
#include < stdio.h>
17
18
#include < stdlib.h>
24
25
#endif
25
26
26
27
#include " nsAppRunner.h"
27
- #include " nsIFile.h"
28
28
#include " nsCOMPtr.h"
29
- #include " nsMemory.h"
30
29
#include " nsCRTGlue.h"
30
+ #include " nsIFile.h"
31
+ #include " nsMemory.h"
31
32
// #include "nsStringAPI.h"
32
33
// #include "nsServiceManagerUtils.h"
33
34
#include " plstr.h"
34
- #include " prprf.h"
35
35
#include " prenv.h"
36
+ #include " prprf.h"
36
37
// #include "nsINIParser.h" GRE Versioning stuff that needs to be in libxul :(
37
38
#include " application.ini.h"
38
39
45
46
46
47
#include " nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
47
48
48
- // NOTE: In firefox this is wrapped in a check that excludes cocoa or android
49
- // because we are not targeting either platform right now, I am going
50
- // exclude that check
51
- //
52
- // This is the required include for content process stuff
53
- #include " ../../ipc/contentproc/plugin-container.cpp"
49
+ // NOTE: Firefox does not allow content processes on android and coccoa.
50
+ // We target neither, so we leave our content process code outside of macros
54
51
55
52
using namespace mozilla ;
56
53
@@ -63,14 +60,14 @@ using namespace mozilla;
63
60
* @param fmt
64
61
* printf-style format string followed by arguments.
65
62
*/
66
- static void Output (bool isError, const char *fmt, ...)
67
- {
63
+ static void Output (bool isError, const char *fmt, ...) {
68
64
va_list ap;
69
65
va_start (ap, fmt);
70
66
71
67
#if (defined(XP_WIN) && !MOZ_WINCONSOLE)
72
68
wchar_t msg[2048 ];
73
- _vsnwprintf (msg, sizeof (msg) / sizeof (msg[0 ]), NS_ConvertUTF8toUTF16(fmt).get (), ap);
69
+ _vsnwprintf (msg, sizeof (msg) / sizeof (msg[0 ]),
70
+ NS_ConvertUTF8toUTF16 (fmt).get(), ap);
74
71
75
72
UINT flags = MB_OK;
76
73
if (isError)
@@ -89,10 +86,8 @@ static void Output(bool isError, const char *fmt, ...)
89
86
/* *
90
87
* Return true if |arg| matches the given argument name.
91
88
*/
92
- static bool IsArg (const char *arg, const char *s)
93
- {
94
- if (*arg == ' -' )
95
- {
89
+ static bool IsArg (const char *arg, const char *s) {
90
+ if (*arg == ' -' ) {
96
91
if (*++arg == ' -' )
97
92
++arg;
98
93
return !strcasecmp (arg, s);
@@ -140,8 +135,7 @@ static bool IsArg(const char *arg, const char *s)
140
135
// return NS_OK;
141
136
// }
142
137
143
- static void Usage (const char *argv0)
144
- {
138
+ static void Usage (const char *argv0) {
145
139
// nsAutoCString milestone;
146
140
// GetGREVersion(argv0, &milestone, nullptr);
147
141
@@ -168,26 +162,26 @@ static void Usage(const char *argv0)
168
162
Bootstrap::UniquePtr gBootstrap ;
169
163
170
164
static nsresult initXPCOMGlue (LibLoadingStrategy libLoadingStrategy) {
171
- if (gBootstrap ) return NS_OK;
165
+ if (gBootstrap )
166
+ return NS_OK;
172
167
173
168
UniqueFreePtr<char > exePathPtr = BinaryPath::Get ();
174
- if (!exePathPtr)
175
- {
169
+ if (!exePathPtr) {
176
170
Output (true , " Couldn't calculate the application directory.\n " );
177
171
return NS_ERROR_FAILURE;
178
172
}
179
173
180
174
char *exePath = exePathPtr.get ();
181
175
182
176
char *lastSlash = strrchr (exePath, XPCOM_FILE_PATH_SEPARATOR[0 ]);
183
- if (!lastSlash || (size_t (lastSlash - exePath) > MAXPATHLEN - sizeof (XPCOM_DLL) - 1 ))
177
+ if (!lastSlash ||
178
+ (size_t (lastSlash - exePath) > MAXPATHLEN - sizeof (XPCOM_DLL) - 1 ))
184
179
return NS_ERROR_FAILURE;
185
180
186
181
strcpy (++lastSlash, XPCOM_DLL);
187
182
188
183
auto bootstrapResult = mozilla::GetBootstrap (exePath, libLoadingStrategy);
189
- if (bootstrapResult.isErr ())
190
- {
184
+ if (bootstrapResult.isErr ()) {
191
185
Output (true , " Couldn't load XPCOM.\n " );
192
186
return NS_ERROR_FAILURE;
193
187
}
@@ -199,14 +193,11 @@ static nsresult initXPCOMGlue(LibLoadingStrategy libLoadingStrategy) {
199
193
return NS_OK;
200
194
}
201
195
202
- int main (int argc, char *argv[])
203
- {
196
+ int main (int argc, char *argv[]) {
204
197
#if defined(MOZ_ENABLE_FORKSERVER)
205
- if (strcmp (argv[argc - 1 ], " forkserver" ) == 0 )
206
- {
198
+ if (strcmp (argv[argc - 1 ], " forkserver" ) == 0 ) {
207
199
nsresult rv = InitXPCOMGlue (LibLoadingStrategy::NoReadAhead);
208
- if (NS_FAILED(rv))
209
- {
200
+ if (NS_FAILED(rv)) {
210
201
return 255 ;
211
202
}
212
203
@@ -219,8 +210,7 @@ int main(int argc, char *argv[])
219
210
// argc & argv will be updated with the values passing from the
220
211
// chrome process. With the new values, this function
221
212
// continues the reset of the code acting as a content process.
222
- if (gBootstrap ->XRE_ForkServer (&argc, &argv))
223
- {
213
+ if (gBootstrap ->XRE_ForkServer (&argc, &argv)) {
224
214
// Return from the fork server in the fork server process.
225
215
// Stop the fork server.
226
216
gBootstrap ->NS_LogTerm ();
@@ -235,31 +225,32 @@ int main(int argc, char *argv[])
235
225
// Set the process type. We don't remove the arg here as that will be done
236
226
// later in common code.
237
227
SetGeckoProcessType (argv[argc - 1 ]);
228
+ SetGeckoChildID (argv[--argc]);
238
229
239
- nsresult initXPCOMGlueResult = initXPCOMGlue (LibLoadingStrategy::NoReadAhead);
230
+ nsresult initXPCOMGlueResult =
231
+ initXPCOMGlue (LibLoadingStrategy::NoReadAhead);
240
232
if (NS_FAILED(initXPCOMGlueResult)) {
241
233
Output (true , " Failed to load xpcom glue" );
242
234
return 255 ;
243
235
}
244
236
245
- int contentProcMainResult = content_process_main (gBootstrap .get (), argc, argv);
237
+ XREChildData childData;
238
+ nsresult contentProcMainResult =
239
+ gBootstrap ->XRE_InitChildProcess (argc, argv, &childData);
246
240
247
241
// InitXPCOMGlue calls NS_LogInit, so we need to balance it here.
248
242
gBootstrap ->NS_LogTerm ();
249
243
250
- return contentProcMainResult;
244
+ return NS_FAILED( contentProcMainResult) ? 1 : 0 ;
251
245
}
252
246
253
- if (argc > 1 && (IsArg (argv[1 ], " h" ) ||
254
- IsArg (argv[1 ], " help" ) ||
255
- IsArg (argv[1 ], " ?" )))
256
- {
247
+ if (argc > 1 &&
248
+ (IsArg (argv[1 ], " h" ) || IsArg (argv[1 ], " help" ) || IsArg (argv[1 ], " ?" ))) {
257
249
Usage (argv[0 ]);
258
250
return 0 ;
259
251
}
260
252
261
- if (argc == 2 && (IsArg (argv[1 ], " v" ) || IsArg (argv[1 ], " version" )))
262
- {
253
+ if (argc == 2 && (IsArg (argv[1 ], " v" ) || IsArg (argv[1 ], " version" ))) {
263
254
// nsAutoCString milestone;
264
255
// nsAutoCString version;
265
256
// GetGREVersion(argv[0], &milestone, &version);
@@ -269,17 +260,14 @@ int main(int argc, char *argv[])
269
260
return 0 ;
270
261
}
271
262
272
- if (argc > 1 )
273
- {
263
+ if (argc > 1 ) {
274
264
// nsAutoCString milestone;
275
265
// nsresult rv = GetGREVersion(argv[0], &milestone, nullptr);
276
266
// if (NS_FAILED(rv))
277
267
// return 2;
278
268
279
- if (IsArg (argv[1 ], " gre-version" ))
280
- {
281
- if (argc != 2 )
282
- {
269
+ if (IsArg (argv[1 ], " gre-version" )) {
270
+ if (argc != 2 ) {
283
271
Usage (argv[0 ]);
284
272
return 1 ;
285
273
}
@@ -289,27 +277,23 @@ int main(int argc, char *argv[])
289
277
return 0 ;
290
278
}
291
279
292
- if (IsArg (argv[1 ], " install-app" ))
293
- {
294
- Output ( true , " --install-app support has been removed. Use 'python install-app.py' instead.\n " );
280
+ if (IsArg (argv[1 ], " install-app" )) {
281
+ Output ( true , " --install-app support has been removed. Use 'python "
282
+ " install-app.py' instead.\n " );
295
283
return 1 ;
296
284
}
297
285
}
298
286
299
287
const char *appDataFile = getenv (" XUL_APP_FILE" );
300
288
301
- if (!(appDataFile && *appDataFile))
302
- {
303
- if (argc < 2 )
304
- {
289
+ if (!(appDataFile && *appDataFile)) {
290
+ if (argc < 2 ) {
305
291
Usage (argv[0 ]);
306
292
return 1 ;
307
293
}
308
294
309
- if (IsArg (argv[1 ], " app" ))
310
- {
311
- if (argc == 2 )
312
- {
295
+ if (IsArg (argv[1 ], " app" )) {
296
+ if (argc == 2 ) {
313
297
Usage (argv[0 ]);
314
298
return 1 ;
315
299
}
@@ -330,13 +314,10 @@ int main(int argc, char *argv[])
330
314
331
315
BootstrapConfig config;
332
316
333
- if (appDataFile[0 ] != ' -' )
334
- {
317
+ if (appDataFile[0 ] != ' -' ) {
335
318
config.appData = nullptr ;
336
319
config.appDataPath = appDataFile;
337
- }
338
- else
339
- {
320
+ } else {
340
321
config.appData = &sAppData ;
341
322
config.appDataPath = " quark-runtime" ;
342
323
}
@@ -347,6 +328,7 @@ int main(int argc, char *argv[])
347
328
return 255 ;
348
329
}
349
330
331
+ gBootstrap ->XRE_EnableSameExecutableForContentProc ();
350
332
int xreMainResult = gBootstrap ->XRE_main (argc, argv, config);
351
333
352
334
gBootstrap ->NS_LogTerm ();
0 commit comments