Bug 1690340 - Part 4: Insert the "Page Source" before the "Extensions for Developers...
[gecko.git] / ipc / app / MozillaRuntimeMain.cpp
blob2a5b184988683e250375469154e1cee64573686f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "../contentproc/plugin-container.cpp"
9 #include "mozilla/Bootstrap.h"
10 #if defined(XP_WIN)
11 # include "mozilla/WindowsDllBlocklist.h"
12 #endif // defined(XP_WIN)
14 using namespace mozilla;
16 static bool UseForkServer(int argc, char* argv[]) {
17 #if defined(MOZ_ENABLE_FORKSERVER)
18 return strcmp(argv[argc - 1], "forkserver") == 0;
19 #else
20 return false;
21 #endif
24 static int RunForkServer(Bootstrap::UniquePtr&& bootstrap, int argc,
25 char* argv[]) {
26 #if defined(MOZ_ENABLE_FORKSERVER)
27 int ret = 0;
29 bootstrap->NS_LogInit();
31 // Run a fork server in this process, single thread. When it
32 // returns, it means the fork server have been stopped or a new
33 // content process is created.
35 // For the later case, XRE_ForkServer() will return false, running
36 // in a content process just forked from the fork server process.
37 // argc & argv will be updated with the values passing from the
38 // chrome process. With the new values, this function
39 // continues the reset of the code acting as a content process.
40 if (bootstrap->XRE_ForkServer(&argc, &argv)) {
41 // Return from the fork server in the fork server process.
42 // Stop the fork server.
43 } else {
44 // In a content process forked from the fork server.
45 // Start acting as a content process.
46 ret = content_process_main(bootstrap.get(), argc, argv);
49 bootstrap->NS_LogTerm();
50 return ret;
51 #else
52 return 0;
53 #endif
56 int main(int argc, char* argv[]) {
57 Bootstrap::UniquePtr bootstrap = GetBootstrap();
58 if (!bootstrap) {
59 return 2;
62 int ret;
63 if (UseForkServer(argc, argv)) {
64 ret = RunForkServer(std::move(bootstrap), argc, argv);
65 } else {
66 #ifdef HAS_DLL_BLOCKLIST
67 DllBlocklist_Initialize(eDllBlocklistInitFlagIsChildProcess);
68 #endif
70 ret = content_process_main(bootstrap.get(), argc, argv);
72 #if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
73 DllBlocklist_Shutdown();
74 #endif
77 return ret;