Skip to content

Commit 1971025

Browse files
committed
🐛 Update code for new IPC system
1 parent b630796 commit 1971025

File tree

1 file changed

+45
-63
lines changed

1 file changed

+45
-63
lines changed

src/quark-runtime/app/QuarkRuntime.cpp

+45-63
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// macOS todos:
1313
// TODO: Allow disabling content processes on macOS
1414

15+
#include "XREChildData.h"
1516
#include "mozilla/Bootstrap.h"
1617
#include <stdio.h>
1718
#include <stdlib.h>
@@ -24,15 +25,15 @@
2425
#endif
2526

2627
#include "nsAppRunner.h"
27-
#include "nsIFile.h"
2828
#include "nsCOMPtr.h"
29-
#include "nsMemory.h"
3029
#include "nsCRTGlue.h"
30+
#include "nsIFile.h"
31+
#include "nsMemory.h"
3132
// #include "nsStringAPI.h"
3233
// #include "nsServiceManagerUtils.h"
3334
#include "plstr.h"
34-
#include "prprf.h"
3535
#include "prenv.h"
36+
#include "prprf.h"
3637
// #include "nsINIParser.h" GRE Versioning stuff that needs to be in libxul :(
3738
#include "application.ini.h"
3839

@@ -45,12 +46,8 @@
4546

4647
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
4748

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
5451

5552
using namespace mozilla;
5653

@@ -63,14 +60,14 @@ using namespace mozilla;
6360
* @param fmt
6461
* printf-style format string followed by arguments.
6562
*/
66-
static void Output(bool isError, const char *fmt, ...)
67-
{
63+
static void Output(bool isError, const char *fmt, ...) {
6864
va_list ap;
6965
va_start(ap, fmt);
7066

7167
#if (defined(XP_WIN) && !MOZ_WINCONSOLE)
7268
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);
7471

7572
UINT flags = MB_OK;
7673
if (isError)
@@ -89,10 +86,8 @@ static void Output(bool isError, const char *fmt, ...)
8986
/**
9087
* Return true if |arg| matches the given argument name.
9188
*/
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 == '-') {
9691
if (*++arg == '-')
9792
++arg;
9893
return !strcasecmp(arg, s);
@@ -140,8 +135,7 @@ static bool IsArg(const char *arg, const char *s)
140135
// return NS_OK;
141136
// }
142137

143-
static void Usage(const char *argv0)
144-
{
138+
static void Usage(const char *argv0) {
145139
// nsAutoCString milestone;
146140
// GetGREVersion(argv0, &milestone, nullptr);
147141

@@ -168,26 +162,26 @@ static void Usage(const char *argv0)
168162
Bootstrap::UniquePtr gBootstrap;
169163

170164
static nsresult initXPCOMGlue(LibLoadingStrategy libLoadingStrategy) {
171-
if (gBootstrap) return NS_OK;
165+
if (gBootstrap)
166+
return NS_OK;
172167

173168
UniqueFreePtr<char> exePathPtr = BinaryPath::Get();
174-
if (!exePathPtr)
175-
{
169+
if (!exePathPtr) {
176170
Output(true, "Couldn't calculate the application directory.\n");
177171
return NS_ERROR_FAILURE;
178172
}
179173

180174
char *exePath = exePathPtr.get();
181175

182176
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))
184179
return NS_ERROR_FAILURE;
185180

186181
strcpy(++lastSlash, XPCOM_DLL);
187182

188183
auto bootstrapResult = mozilla::GetBootstrap(exePath, libLoadingStrategy);
189-
if (bootstrapResult.isErr())
190-
{
184+
if (bootstrapResult.isErr()) {
191185
Output(true, "Couldn't load XPCOM.\n");
192186
return NS_ERROR_FAILURE;
193187
}
@@ -199,14 +193,11 @@ static nsresult initXPCOMGlue(LibLoadingStrategy libLoadingStrategy) {
199193
return NS_OK;
200194
}
201195

202-
int main(int argc, char *argv[])
203-
{
196+
int main(int argc, char *argv[]) {
204197
#if defined(MOZ_ENABLE_FORKSERVER)
205-
if (strcmp(argv[argc - 1], "forkserver") == 0)
206-
{
198+
if (strcmp(argv[argc - 1], "forkserver") == 0) {
207199
nsresult rv = InitXPCOMGlue(LibLoadingStrategy::NoReadAhead);
208-
if (NS_FAILED(rv))
209-
{
200+
if (NS_FAILED(rv)) {
210201
return 255;
211202
}
212203

@@ -219,8 +210,7 @@ int main(int argc, char *argv[])
219210
// argc & argv will be updated with the values passing from the
220211
// chrome process. With the new values, this function
221212
// 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)) {
224214
// Return from the fork server in the fork server process.
225215
// Stop the fork server.
226216
gBootstrap->NS_LogTerm();
@@ -235,31 +225,32 @@ int main(int argc, char *argv[])
235225
// Set the process type. We don't remove the arg here as that will be done
236226
// later in common code.
237227
SetGeckoProcessType(argv[argc - 1]);
228+
SetGeckoChildID(argv[--argc]);
238229

239-
nsresult initXPCOMGlueResult = initXPCOMGlue(LibLoadingStrategy::NoReadAhead);
230+
nsresult initXPCOMGlueResult =
231+
initXPCOMGlue(LibLoadingStrategy::NoReadAhead);
240232
if (NS_FAILED(initXPCOMGlueResult)) {
241233
Output(true, "Failed to load xpcom glue");
242234
return 255;
243235
}
244236

245-
int contentProcMainResult = content_process_main(gBootstrap.get(), argc, argv);
237+
XREChildData childData;
238+
nsresult contentProcMainResult =
239+
gBootstrap->XRE_InitChildProcess(argc, argv, &childData);
246240

247241
// InitXPCOMGlue calls NS_LogInit, so we need to balance it here.
248242
gBootstrap->NS_LogTerm();
249243

250-
return contentProcMainResult;
244+
return NS_FAILED(contentProcMainResult) ? 1 : 0;
251245
}
252246

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], "?"))) {
257249
Usage(argv[0]);
258250
return 0;
259251
}
260252

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"))) {
263254
// nsAutoCString milestone;
264255
// nsAutoCString version;
265256
// GetGREVersion(argv[0], &milestone, &version);
@@ -269,17 +260,14 @@ int main(int argc, char *argv[])
269260
return 0;
270261
}
271262

272-
if (argc > 1)
273-
{
263+
if (argc > 1) {
274264
// nsAutoCString milestone;
275265
// nsresult rv = GetGREVersion(argv[0], &milestone, nullptr);
276266
// if (NS_FAILED(rv))
277267
// return 2;
278268

279-
if (IsArg(argv[1], "gre-version"))
280-
{
281-
if (argc != 2)
282-
{
269+
if (IsArg(argv[1], "gre-version")) {
270+
if (argc != 2) {
283271
Usage(argv[0]);
284272
return 1;
285273
}
@@ -289,27 +277,23 @@ int main(int argc, char *argv[])
289277
return 0;
290278
}
291279

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");
295283
return 1;
296284
}
297285
}
298286

299287
const char *appDataFile = getenv("XUL_APP_FILE");
300288

301-
if (!(appDataFile && *appDataFile))
302-
{
303-
if (argc < 2)
304-
{
289+
if (!(appDataFile && *appDataFile)) {
290+
if (argc < 2) {
305291
Usage(argv[0]);
306292
return 1;
307293
}
308294

309-
if (IsArg(argv[1], "app"))
310-
{
311-
if (argc == 2)
312-
{
295+
if (IsArg(argv[1], "app")) {
296+
if (argc == 2) {
313297
Usage(argv[0]);
314298
return 1;
315299
}
@@ -330,13 +314,10 @@ int main(int argc, char *argv[])
330314

331315
BootstrapConfig config;
332316

333-
if (appDataFile[0] != '-')
334-
{
317+
if (appDataFile[0] != '-') {
335318
config.appData = nullptr;
336319
config.appDataPath = appDataFile;
337-
}
338-
else
339-
{
320+
} else {
340321
config.appData = &sAppData;
341322
config.appDataPath = "quark-runtime";
342323
}
@@ -347,6 +328,7 @@ int main(int argc, char *argv[])
347328
return 255;
348329
}
349330

331+
gBootstrap->XRE_EnableSameExecutableForContentProc();
350332
int xreMainResult = gBootstrap->XRE_main(argc, argv, config);
351333

352334
gBootstrap->NS_LogTerm();

0 commit comments

Comments
 (0)