1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
7 #ifndef __DEFAULT_BROWSER_AGENT_REGISTRY_H__
8 #define __DEFAULT_BROWSER_AGENT_REGISTRY_H__
13 #include "mozilla/Maybe.h"
14 #include "mozilla/Result.h"
15 #include "mozilla/WinHeaderOnlyUtils.h"
17 namespace mozilla::default_agent
{
19 // Indicates whether or not a registry value name is prefixed with the install
20 // directory path (Prefixed), or not (Unprefixed). Prefixing a registry value
21 // name with the install directory makes that value specific to this
22 // installation's default browser agent.
23 enum class IsPrefixed
{
28 // The result of an operation only, containing no other data on success.
29 using VoidResult
= mozilla::WindowsErrorResult
<mozilla::Ok
>;
31 using MaybeString
= mozilla::Maybe
<std::string
>;
32 using MaybeStringResult
= mozilla::WindowsErrorResult
<MaybeString
>;
33 // Get a string from the registry. If necessary, value name prefixing will be
34 // performed automatically.
35 // Strings are stored as wide strings, but are converted to narrow UTF-8 before
37 MaybeStringResult
RegistryGetValueString(IsPrefixed isPrefixed
,
38 const wchar_t* registryValueName
,
39 const wchar_t* subKey
= nullptr);
41 // Set a string in the registry. If necessary, value name prefixing will be
42 // performed automatically.
43 // Strings are converted to wide strings for registry storage.
44 VoidResult
RegistrySetValueString(IsPrefixed isPrefixed
,
45 const wchar_t* registryValueName
,
47 const wchar_t* subKey
= nullptr);
49 using MaybeBoolResult
= mozilla::WindowsErrorResult
<mozilla::Maybe
<bool>>;
50 // Get a bool from the registry.
51 // Bools are stored as a single DWORD, with 0 meaning false and any other value
53 MaybeBoolResult
RegistryGetValueBool(IsPrefixed isPrefixed
,
54 const wchar_t* registryValueName
,
55 const wchar_t* subKey
= nullptr);
57 // Set a bool in the registry. If necessary, value name prefixing will be
58 // performed automatically.
59 // Bools are stored as a single DWORD, with 0 meaning false and any other value
61 VoidResult
RegistrySetValueBool(IsPrefixed isPrefixed
,
62 const wchar_t* registryValueName
, bool newValue
,
63 const wchar_t* subKey
= nullptr);
65 using MaybeQwordResult
= mozilla::WindowsErrorResult
<mozilla::Maybe
<ULONGLONG
>>;
66 // Get a QWORD (ULONGLONG) from the registry. If necessary, value name prefixing
67 // will be performed automatically.
68 MaybeQwordResult
RegistryGetValueQword(IsPrefixed isPrefixed
,
69 const wchar_t* registryValueName
,
70 const wchar_t* subKey
= nullptr);
72 // Get a QWORD (ULONGLONG) in the registry. If necessary, value name prefixing
73 // will be performed automatically.
74 VoidResult
RegistrySetValueQword(IsPrefixed isPrefixed
,
75 const wchar_t* registryValueName
,
77 const wchar_t* subKey
= nullptr);
79 using MaybeDword
= mozilla::Maybe
<uint32_t>;
80 using MaybeDwordResult
= mozilla::WindowsErrorResult
<MaybeDword
>;
81 // Get a DWORD (uint32_t) from the registry. If necessary, value name prefixing
82 // will be performed automatically.
83 MaybeDwordResult
RegistryGetValueDword(IsPrefixed isPrefixed
,
84 const wchar_t* registryValueName
,
85 const wchar_t* subKey
= nullptr);
87 // Get a DWORD (uint32_t) in the registry. If necessary, value name prefixing
88 // will be performed automatically.
89 VoidResult
RegistrySetValueDword(IsPrefixed isPrefixed
,
90 const wchar_t* registryValueName
,
92 const wchar_t* subKey
= nullptr);
94 VoidResult
RegistryDeleteValue(IsPrefixed isPrefixed
,
95 const wchar_t* registryValueName
,
96 const wchar_t* subKey
= nullptr);
98 } // namespace mozilla::default_agent
100 #endif // __DEFAULT_BROWSER_AGENT_REGISTRY_H__