From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- browser/components/shell/WindowsUserChoice.h | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 browser/components/shell/WindowsUserChoice.h (limited to 'browser/components/shell/WindowsUserChoice.h') diff --git a/browser/components/shell/WindowsUserChoice.h b/browser/components/shell/WindowsUserChoice.h new file mode 100644 index 0000000000..d7e887b667 --- /dev/null +++ b/browser/components/shell/WindowsUserChoice.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef SHELL_WINDOWSUSERCHOICE_H__ +#define SHELL_WINDOWSUSERCHOICE_H__ + +#include + +#include "mozilla/UniquePtr.h" + +/* + * Check the UserChoice Hashes for https, http, .html, .htm + * + * This should be checked before attempting to set a new default browser via + * the UserChoice key, to confirm our understanding of the existing hash. + * If an incorrect hash is written, Windows will prompt the user to choose a + * new default (or, in recent versions, it will just reset the default to Edge). + * + * Assuming that the existing hash value is correct (since Windows is fairly + * diligent about replacing bad keys), if we can recompute it from scratch, + * then we should be able to compute a correct hash for our new UserChoice key. + * + * @return true if we matched all the hashes, false otherwise. + */ +bool CheckBrowserUserChoiceHashes(); + +/* + * Result from CheckUserChoiceHash() + * + * NOTE: Currently the only positive result is OK_V1 , but the enum + * could be extended to indicate different versions of the hash. + */ +enum class CheckUserChoiceHashResult { + OK_V1, // Matched the current version of the hash (as of Win10 20H2). + ERR_MISMATCH, // The hash did not match. + ERR_OTHER, // Error reading or generating the hash. +}; + +/* + * Generate a UserChoice Hash, compare it with the one that is stored. + * + * See comments on CheckBrowserUserChoiceHashes(), which calls this to check + * each of the browser associations. + * + * @param aExt File extension or protocol association to check + * @param aUserSid String SID of the current user + * + * @return Result of the check, see CheckUserChoiceHashResult + */ +CheckUserChoiceHashResult CheckUserChoiceHash(const wchar_t* aExt, + const wchar_t* aUserSid); + +/* + * Get the registry path for the given association, file extension or protocol. + * + * @return The path, or nullptr on failure. + */ +mozilla::UniquePtr GetAssociationKeyPath(const wchar_t* aExt); + +/* + * Get the current user's SID + * + * @return String SID for the user of the current process, nullptr on failure. + */ +mozilla::UniquePtr GetCurrentUserStringSid(); + +/* + * Generate the UserChoice Hash + * + * @param aExt file extension or protocol being registered + * @param aUserSid string SID of the current user + * @param aProgId ProgId to associate with aExt + * @param aTimestamp approximate write time of the UserChoice key (within + * the same minute) + * + * @return UserChoice Hash, nullptr on failure. + */ +mozilla::UniquePtr GenerateUserChoiceHash(const wchar_t* aExt, + const wchar_t* aUserSid, + const wchar_t* aProgId, + SYSTEMTIME aTimestamp); + +/* + * Build a ProgID from a base and AUMI + * + * @param aProgIDBase A base, such as FirefoxHTML or FirefoxURL + * @param aAumi The AUMI of the installation + * + * @return Formatted ProgID. + */ +mozilla::UniquePtr FormatProgID(const wchar_t* aProgIDBase, + const wchar_t* aAumi); + +/* + * Check that the given ProgID exists in HKCR + * + * @return true if it could be opened for reading, false otherwise. + */ +bool CheckProgIDExists(const wchar_t* aProgID); + +#endif // SHELL_WINDOWSUSERCHOICE_H__ -- cgit v1.2.3