Bug 1891340 - Part 1: Add parameters to customize the before and after icon tints...
[gecko.git] / ipc / glue / UtilityProcessSandboxing.cpp
blob0c333fdeca715c73d3e75dd70fb28fa9c5ab2c64
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"
8 #include <vector>
9 #include <string>
11 #include "prenv.h"
13 namespace mozilla::ipc {
15 std::vector<std::string> split(const std::string& str, char s) {
16 std::vector<std::string> rv;
17 size_t last = 0;
18 size_t i;
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));
23 last = i + 1;
26 return rv;
29 bool IsUtilitySandboxEnabled(const char* envVar, SandboxingKind aKind) {
30 #ifdef XP_WIN
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) {
41 return false;
43 #endif
45 if (envVar == nullptr) {
46 return true;
49 const std::string disableUtility(envVar);
50 if (disableUtility == "1") {
51 return false;
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) {
58 return false;
62 return true;
65 bool IsUtilitySandboxEnabled(SandboxingKind aKind) {
66 return IsUtilitySandboxEnabled(PR_GetEnv("MOZ_DISABLE_UTILITY_SANDBOX"),
67 aKind);
70 } // namespace mozilla::ipc