Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / ipc / glue / UtilityProcessImpl.cpp
blob4eab90de8a709137534ecc89afea00439afbf634
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/. */
6 #include "UtilityProcessImpl.h"
8 #include "mozilla/ipc/IOThreadChild.h"
9 #include "mozilla/GeckoArgs.h"
11 #if defined(OS_WIN) && defined(MOZ_SANDBOX)
12 # include "mozilla/sandboxTarget.h"
13 #endif
15 namespace mozilla::ipc {
17 UtilityProcessImpl::UtilityProcessImpl(ProcessId aParentPid)
18 : ProcessChild(aParentPid) {
19 mUtility = new UtilityProcessChild();
22 UtilityProcessImpl::~UtilityProcessImpl() { mUtility = nullptr; }
24 bool UtilityProcessImpl::Init(int aArgc, char* aArgv[]) {
25 #if defined(MOZ_SANDBOX) && defined(OS_WIN)
26 // We delay load winmm.dll so that its dependencies don't interfere with COM
27 // initialization when win32k is locked down. We need to load it before we
28 // lower the sandbox in processes where the policy will prevent loading.
29 ::LoadLibraryW(L"winmm.dll");
30 mozilla::SandboxTarget::Instance()->StartSandbox();
31 #endif
33 Maybe<const char*> parentBuildID =
34 geckoargs::sParentBuildID.Get(aArgc, aArgv);
35 if (parentBuildID.isNothing()) {
36 return false;
39 Maybe<uint64_t> sandboxingKind = geckoargs::sSandboxingKind.Get(aArgc, aArgv);
40 if (sandboxingKind.isNothing()) {
41 return false;
44 if (*sandboxingKind >= SandboxingKind::COUNT) {
45 return false;
48 if (!ProcessChild::InitPrefs(aArgc, aArgv)) {
49 return false;
52 return mUtility->Init(ParentPid(), nsCString(*parentBuildID), *sandboxingKind,
53 IOThreadChild::TakeInitialPort());
56 void UtilityProcessImpl::CleanUp() { NS_ShutdownXPCOM(nullptr); }
58 } // namespace mozilla::ipc