Bug 1306327 - Use the new XRE Bootstrap API in Desktop Firefox. r=bsmedberg

This just wraps all the XRE method calls to go through the Bootstrap API
instead of relying on the XPCOM glue methods.

--HG--
extra : rebase_source : eccbe18b9b21ca1ab6c403515ffd60f0a9174d9c
This commit is contained in:
Mike Hommey 2016-12-16 11:10:02 +09:00
Родитель 5f3d2e8810
Коммит 09dc362a61
5 изменённых файлов: 53 добавлений и 66 удалений

Просмотреть файл

@ -161,40 +161,7 @@ static bool IsArg(const char* arg, const char* s)
return false;
}
XRE_GetFileFromPathType XRE_GetFileFromPath;
XRE_ParseAppDataType XRE_ParseAppData;
XRE_TelemetryAccumulateType XRE_TelemetryAccumulate;
XRE_StartupTimelineRecordType XRE_StartupTimelineRecord;
XRE_mainType XRE_main;
XRE_StopLateWriteChecksType XRE_StopLateWriteChecks;
XRE_XPCShellMainType XRE_XPCShellMain;
XRE_GetProcessTypeType XRE_GetProcessType;
XRE_SetProcessTypeType XRE_SetProcessType;
XRE_InitChildProcessType XRE_InitChildProcess;
XRE_EnableSameExecutableForContentProcType XRE_EnableSameExecutableForContentProc;
#ifdef LIBFUZZER
XRE_LibFuzzerSetMainType XRE_LibFuzzerSetMain;
XRE_LibFuzzerGetFuncsType XRE_LibFuzzerGetFuncs;
#endif
static const nsDynamicFunctionLoad kXULFuncs[] = {
{ "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
{ "XRE_ParseAppData", (NSFuncPtr*) &XRE_ParseAppData },
{ "XRE_TelemetryAccumulate", (NSFuncPtr*) &XRE_TelemetryAccumulate },
{ "XRE_StartupTimelineRecord", (NSFuncPtr*) &XRE_StartupTimelineRecord },
{ "XRE_main", (NSFuncPtr*) &XRE_main },
{ "XRE_StopLateWriteChecks", (NSFuncPtr*) &XRE_StopLateWriteChecks },
{ "XRE_XPCShellMain", (NSFuncPtr*) &XRE_XPCShellMain },
{ "XRE_GetProcessType", (NSFuncPtr*) &XRE_GetProcessType },
{ "XRE_SetProcessType", (NSFuncPtr*) &XRE_SetProcessType },
{ "XRE_InitChildProcess", (NSFuncPtr*) &XRE_InitChildProcess },
{ "XRE_EnableSameExecutableForContentProc", (NSFuncPtr*) &XRE_EnableSameExecutableForContentProc },
#ifdef LIBFUZZER
{ "XRE_LibFuzzerSetMain", (NSFuncPtr*) &XRE_LibFuzzerSetMain },
{ "XRE_LibFuzzerGetFuncs", (NSFuncPtr*) &XRE_LibFuzzerGetFuncs },
#endif
{ nullptr, nullptr }
};
Bootstrap::UniquePtr gBootstrap;
#ifdef LIBFUZZER
int libfuzzer_main(int argc, char **argv);
@ -203,7 +170,7 @@ int libfuzzer_main(int argc, char **argv);
void libFuzzerGetFuncs(const char* moduleName, LibFuzzerInitFunc* initFunc,
LibFuzzerTestingFunc* testingFunc) {
return XRE_LibFuzzerGetFuncs(moduleName, initFunc, testingFunc);
return gBootstrap->XRE_LibFuzzerGetFuncs(moduleName, initFunc, testingFunc);
}
#endif
@ -216,7 +183,7 @@ static int do_main(int argc, char* argv[], char* envp[])
// Note that -app must be the *first* argument.
const char *appDataFile = getenv("XUL_APP_FILE");
if (appDataFile && *appDataFile) {
rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
rv = gBootstrap->XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
if (NS_FAILED(rv)) {
Output("Invalid path found: '%s'", appDataFile);
return 255;
@ -228,7 +195,7 @@ static int do_main(int argc, char* argv[], char* envp[])
return 255;
}
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
rv = gBootstrap->XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
if (NS_FAILED(rv)) {
Output("application.ini path not recognized: '%s'", argv[2]);
return 255;
@ -254,13 +221,13 @@ static int do_main(int argc, char* argv[], char* envp[])
sandboxing::GetInitializedBrokerServices();
#endif
return XRE_XPCShellMain(--argc, argv, envp, &shellData);
return gBootstrap->XRE_XPCShellMain(--argc, argv, envp, &shellData);
}
XREAppData appData;
if (appini) {
rv = XRE_ParseAppData(appini, appData);
rv = gBootstrap->XRE_ParseAppData(appini, appData);
if (NS_FAILED(rv)) {
Output("Couldn't read application.ini");
return 255;
@ -303,10 +270,10 @@ static int do_main(int argc, char* argv[], char* envp[])
#ifdef LIBFUZZER
if (getenv("LIBFUZZER"))
XRE_LibFuzzerSetMain(argc, argv, libfuzzer_main);
gBootstrap->XRE_LibFuzzerSetMain(argc, argv, libfuzzer_main);
#endif
return XRE_main(argc, argv, appData);
return gBootstrap->XRE_main(argc, argv, appData);
}
static bool
@ -345,20 +312,14 @@ InitXPCOMGlue(const char *argv0)
return NS_ERROR_FAILURE;
}
rv = XPCOMGlueStartup(exePath);
if (NS_FAILED(rv)) {
gBootstrap = mozilla::GetBootstrap(exePath);
if (!gBootstrap) {
Output("Couldn't load XPCOM.\n");
return rv;
}
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
if (NS_FAILED(rv)) {
Output("Couldn't load XRE functions.\n");
return rv;
return NS_ERROR_FAILURE;
}
// This will set this thread as the main thread.
NS_LogInit();
gBootstrap->NS_LogInit();
return NS_OK;
}
@ -397,10 +358,10 @@ int main(int argc, char* argv[], char* envp[])
return 255;
}
int result = content_process_main(argc, argv);
int result = content_process_main(gBootstrap.get(), argc, argv);
// InitXPCOMGlue calls NS_LogInit, so we need to balance it here.
NS_LogTerm();
gBootstrap->NS_LogTerm();
return result;
}
@ -412,15 +373,15 @@ int main(int argc, char* argv[], char* envp[])
return 255;
}
XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start);
gBootstrap->XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start);
#ifdef MOZ_BROWSER_CAN_BE_CONTENTPROC
XRE_EnableSameExecutableForContentProc();
gBootstrap->XRE_EnableSameExecutableForContentProc();
#endif
int result = do_main(argc, argv, envp);
NS_LogTerm();
gBootstrap->NS_LogTerm();
#ifdef XP_MACOSX
// Allow writes again. While we would like to catch writes from static
@ -428,8 +389,10 @@ int main(int argc, char* argv[], char* envp[])
// at least one such write that we don't control (see bug 826029). For
// now we enable writes again and early exits will have to use exit instead
// of _exit.
XRE_StopLateWriteChecks();
gBootstrap->XRE_StopLateWriteChecks();
#endif
gBootstrap.reset();
return result;
}

Просмотреть файл

@ -6,8 +6,11 @@
#include "../contentproc/plugin-container.cpp"
#include "mozilla/Bootstrap.h"
#include "mozilla/WindowsDllBlocklist.h"
using namespace mozilla;
int
main(int argc, char *argv[])
{
@ -15,5 +18,10 @@ main(int argc, char *argv[])
DllBlocklist_Initialize();
#endif
return content_process_main(argc, argv);
Bootstrap::UniquePtr bootstrap;
XRE_GetBootstrap(bootstrap);
if (!bootstrap) {
return 2;
}
return content_process_main(bootstrap.get(), argc, argv);
}

Просмотреть файл

@ -7,6 +7,7 @@
#include "nsXPCOM.h"
#include "nsXULAppAPI.h"
#include "nsAutoPtr.h"
#include "mozilla/Bootstrap.h"
#ifdef XP_WIN
#include <windows.h>
@ -71,7 +72,7 @@ MakeSandboxStarter()
}
int
content_process_main(int argc, char* argv[])
content_process_main(mozilla::Bootstrap* bootstrap, int argc, char* argv[])
{
// Check for the absolute minimum number of args we need to move
// forward here. We expect the last arg to be the child process type.
@ -93,13 +94,13 @@ content_process_main(int argc, char* argv[])
}
#endif
XRE_SetProcessType(argv[--argc]);
bootstrap->XRE_SetProcessType(argv[--argc]);
#ifdef XP_WIN
// For plugins, this is done in PluginProcessChild::Init, as we need to
// avoid it for unsupported plugins. See PluginProcessChild::Init for
// the details.
if (XRE_GetProcessType() != GeckoProcessType_Plugin) {
if (bootstrap->XRE_GetProcessType() != GeckoProcessType_Plugin) {
mozilla::SanitizeEnvironmentVariables();
SetDllDirectoryW(L"");
}
@ -107,10 +108,10 @@ content_process_main(int argc, char* argv[])
#if !defined(XP_LINUX) && defined(MOZ_PLUGIN_CONTAINER)
// On Windows and MacOS, the GMPLoader lives in plugin-container, so that its
// code can be covered by an EME/GMP vendor's voucher.
if (XRE_GetProcessType() == GeckoProcessType_GMPlugin) {
if (bootstrap->XRE_GetProcessType() == GeckoProcessType_GMPlugin) {
childData.gmpLoader = mozilla::gmp::CreateGMPLoader(MakeSandboxStarter());
}
#endif
nsresult rv = XRE_InitChildProcess(argc, argv, &childData);
nsresult rv = bootstrap->XRE_InitChildProcess(argc, argv, &childData);
return NS_FAILED(rv);
}

Просмотреть файл

@ -2,13 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsXULAppAPI.h"
#define MOZ_IPDL_TESTS
#include "mozilla/Bootstrap.h"
#if defined(XP_WIN)
#include <windows.h>
#include "nsWindowsWMain.cpp"
#endif
using namespace mozilla;
int
main(int argc, char** argv)
{
@ -16,5 +19,10 @@ main(int argc, char** argv)
if (argc < 2)
return 1;
return XRE_RunIPDLTest(argc, argv);
Bootstrap::UniquePtr bootstrap;
XRE_GetBootstrap(bootstrap);
if (!bootstrap) {
return 2;
}
return bootstrap->XRE_RunIPDLTest(argc, argv);
}

Просмотреть файл

@ -9,6 +9,7 @@
#include <stdio.h>
#include "mozilla/WindowsDllBlocklist.h"
#include "mozilla/Bootstrap.h"
#include "nsXULAppAPI.h"
#ifdef XP_MACOSX
@ -59,7 +60,13 @@ main(int argc, char** argv, char** envp)
mozilla::sandboxing::GetInitializedBrokerServices();
#endif
int result = XRE_XPCShellMain(argc, argv, envp, &shellData);
mozilla::Bootstrap::UniquePtr bootstrap;
XRE_GetBootstrap(bootstrap);
if (!bootstrap) {
return 2;
}
int result = bootstrap->XRE_XPCShellMain(argc, argv, envp, &shellData);
#ifdef XP_MACOSX
FinishAutoreleasePool();