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/. */ 6 7 #ifndef __DEFAULT_BROWSER_AGENT_REGISTRY_H__ 8 #define __DEFAULT_BROWSER_AGENT_REGISTRY_H__ 9 10 #include <cstdint> 11 #include <windows.h> 12 13 #include "mozilla/Maybe.h" 14 #include "mozilla/Result.h" 15 #include "mozilla/WinHeaderOnlyUtils.h" 16 17 // Indicates whether or not a registry value name is prefixed with the install 18 // directory path (Prefixed), or not (Unprefixed). Prefixing a registry value 19 // name with the install directory makes that value specific to this 20 // installation's default browser agent. 21 enum class IsPrefixed { 22 Prefixed, 23 Unprefixed, 24 }; 25 26 // The result of an operation only, containing no other data on success. 27 using VoidResult = mozilla::WindowsErrorResult<mozilla::Ok>; 28 29 using MaybeString = mozilla::Maybe<std::string>; 30 using MaybeStringResult = mozilla::WindowsErrorResult<MaybeString>; 31 // Get a string from the registry. If necessary, value name prefixing will be 32 // performed automatically. 33 // Strings are stored as wide strings, but are converted to narrow UTF-8 before 34 // being returned. 35 MaybeStringResult RegistryGetValueString(IsPrefixed isPrefixed, 36 const wchar_t* registryValueName, 37 const wchar_t* subKey = nullptr); 38 39 // Set a string in the registry. If necessary, value name prefixing will be 40 // performed automatically. 41 // Strings are converted to wide strings for registry storage. 42 VoidResult RegistrySetValueString(IsPrefixed isPrefixed, 43 const wchar_t* registryValueName, 44 const char* newValue, 45 const wchar_t* subKey = nullptr); 46 47 using MaybeBoolResult = mozilla::WindowsErrorResult<mozilla::Maybe<bool>>; 48 // Get a bool from the registry. 49 // Bools are stored as a single DWORD, with 0 meaning false and any other value 50 // meaning true. 51 MaybeBoolResult RegistryGetValueBool(IsPrefixed isPrefixed, 52 const wchar_t* registryValueName, 53 const wchar_t* subKey = nullptr); 54 55 // Set a bool in the registry. If necessary, value name prefixing will be 56 // performed automatically. 57 // Bools are stored as a single DWORD, with 0 meaning false and any other value 58 // meaning true. 59 VoidResult RegistrySetValueBool(IsPrefixed isPrefixed, 60 const wchar_t* registryValueName, bool newValue, 61 const wchar_t* subKey = nullptr); 62 63 using MaybeQwordResult = mozilla::WindowsErrorResult<mozilla::Maybe<ULONGLONG>>; 64 // Get a QWORD (ULONGLONG) from the registry. If necessary, value name prefixing 65 // will be performed automatically. 66 MaybeQwordResult RegistryGetValueQword(IsPrefixed isPrefixed, 67 const wchar_t* registryValueName, 68 const wchar_t* subKey = nullptr); 69 70 // Get a QWORD (ULONGLONG) in the registry. If necessary, value name prefixing 71 // will be performed automatically. 72 VoidResult RegistrySetValueQword(IsPrefixed isPrefixed, 73 const wchar_t* registryValueName, 74 ULONGLONG newValue, 75 const wchar_t* subKey = nullptr); 76 77 using MaybeDword = mozilla::Maybe<uint32_t>; 78 using MaybeDwordResult = mozilla::WindowsErrorResult<MaybeDword>; 79 // Get a DWORD (uint32_t) from the registry. If necessary, value name prefixing 80 // will be performed automatically. 81 MaybeDwordResult RegistryGetValueDword(IsPrefixed isPrefixed, 82 const wchar_t* registryValueName, 83 const wchar_t* subKey = nullptr); 84 85 // Get a DWORD (uint32_t) in the registry. If necessary, value name prefixing 86 // will be performed automatically. 87 VoidResult RegistrySetValueDword(IsPrefixed isPrefixed, 88 const wchar_t* registryValueName, 89 uint32_t newValue, 90 const wchar_t* subKey = nullptr); 91 92 VoidResult RegistryDeleteValue(IsPrefixed isPrefixed, 93 const wchar_t* registryValueName, 94 const wchar_t* subKey = nullptr); 95 96 #endif // __DEFAULT_BROWSER_AGENT_REGISTRY_H__ 97