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 "UtilityProcessSandboxing.h"
13 namespace mozilla::ipc
{
15 std::vector
<std::string
> split(const std::string
& str
, char s
) {
16 std::vector
<std::string
> rv
;
19 size_t c
= str
.size();
20 for (i
= 0; i
<= c
; ++i
) {
21 if (i
== c
|| str
[i
] == s
) {
22 rv
.push_back(str
.substr(last
, i
- last
));
29 bool IsUtilitySandboxEnabled(const char* envVar
, SandboxingKind aKind
) {
31 // Sandboxing the Windows file dialog is probably not useful.
33 // (Additionally, it causes failures in our test environments: when running
34 // tests on windows-11-2009-qr machines, sandboxed child processes can't see
35 // or interact with any other process's windows -- which means they can't
36 // select a window from the parent process as the file dialog's parent. This
37 // occurs regardless of the sandbox preferences, which is why we disable
38 // sandboxing entirely rather than use a maximally permissive preference-set.
39 // This behavior has not been seen in user-facing environments.)
40 if (aKind
== SandboxingKind::WINDOWS_FILE_DIALOG
) {
45 if (envVar
== nullptr) {
49 const std::string
disableUtility(envVar
);
50 if (disableUtility
== "1") {
54 std::vector
<std::string
> components
= split(disableUtility
, ',');
55 const std::string thisKind
= "utility:" + std::to_string(aKind
);
56 for (const std::string
& thisOne
: components
) {
57 if (thisOne
== thisKind
) {
65 bool IsUtilitySandboxEnabled(SandboxingKind aKind
) {
66 return IsUtilitySandboxEnabled(PR_GetEnv("MOZ_DISABLE_UTILITY_SANDBOX"),
70 } // namespace mozilla::ipc