Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / toolkit / xre / PolicyChecks.h
bloba876ff917dbde5061b59a167cc0eb5b588103185
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 https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_PolicyChecks_h
8 #define mozilla_PolicyChecks_h
10 #if defined(XP_WIN)
12 # include <windows.h>
13 # include "mozilla/Maybe.h"
15 # define POLICY_REGKEY_NAME L"SOFTWARE\\Policies\\Mozilla\\" MOZ_APP_BASENAME
17 // NB: This code must be able to run apart from XPCOM
19 namespace mozilla {
21 // Returns Some(true) if the registry value is 1
22 // Returns Some(false) if the registry value is not 1
23 // Returns Nothing() if the registry value is not present
24 inline Maybe<bool> PolicyHasRegValueOfOne(HKEY aKey, LPCWSTR aName) {
26 DWORD len = sizeof(DWORD);
27 DWORD value;
28 LONG ret = ::RegGetValueW(aKey, POLICY_REGKEY_NAME, aName, RRF_RT_DWORD,
29 nullptr, &value, &len);
30 if (ret == ERROR_SUCCESS) {
31 return Some(value == 1);
35 ULONGLONG value;
36 DWORD len = sizeof(ULONGLONG);
37 LONG ret = ::RegGetValueW(aKey, POLICY_REGKEY_NAME, aName, RRF_RT_QWORD,
38 nullptr, &value, &len);
39 if (ret == ERROR_SUCCESS) {
40 return Some(value == 1);
43 return Nothing();
46 inline bool PolicyCheckBoolean(LPCWSTR aPolicyName) {
47 Maybe<bool> localMachineResult =
48 PolicyHasRegValueOfOne(HKEY_LOCAL_MACHINE, aPolicyName);
49 if (localMachineResult.isSome()) {
50 return localMachineResult.value();
53 Maybe<bool> currentUserResult =
54 PolicyHasRegValueOfOne(HKEY_CURRENT_USER, aPolicyName);
55 if (currentUserResult.isSome()) {
56 return currentUserResult.value();
59 return false;
62 } // namespace mozilla
64 #endif // defined(XP_WIN)
66 #endif // mozilla_PolicyChecks_h