зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1737177: Add `nsSystemInfo` runtime flag for whether running application is running under Microsoft Windows S Mode. r=mhowell
This patch uses the Windows.System.Profile.WindowsIntegrityPolicy class to determine whether or not Windows is in S mode. This class is only available beginning with SDK 17763 (newer than what we use right now), so we need to fetch it at runtime with some magic. This is a completely no-op for Windows versions older than 1810, where the WindowsIntegrityPolicy class is not available. Differential Revision: https://phabricator.services.mozilla.com/D130397
This commit is contained in:
Родитель
0f0b78cc1d
Коммит
72b7841950
|
@ -28,10 +28,12 @@
|
|||
# include <windows.h>
|
||||
# include <winioctl.h>
|
||||
# ifndef __MINGW32__
|
||||
# include <wrl.h>
|
||||
# include <wscapi.h>
|
||||
# endif // __MINGW32__
|
||||
# include "base/scoped_handle_win.h"
|
||||
# include "mozilla/DynamicallyLinkedFunctionPtr.h"
|
||||
# include "mozilla/WindowsVersion.h"
|
||||
# include "nsAppDirectoryServiceDefs.h"
|
||||
# include "nsDirectoryServiceDefs.h"
|
||||
# include "nsDirectoryServiceUtils.h"
|
||||
|
@ -83,6 +85,16 @@ uint32_t nsSystemInfo::gUserUmask = 0;
|
|||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
#if defined(XP_WIN)
|
||||
# define RuntimeClass_Windows_System_Profile_WindowsIntegrityPolicy \
|
||||
L"Windows.System.Profile.WindowsIntegrityPolicy"
|
||||
# ifndef __MINGW32__
|
||||
using namespace Microsoft::WRL;
|
||||
using namespace Microsoft::WRL::Wrappers;
|
||||
using namespace ABI::Windows::Foundation;
|
||||
# endif // __MINGW32__
|
||||
#endif
|
||||
|
||||
#if defined(XP_LINUX) && !defined(ANDROID)
|
||||
static void SimpleParseKeyValuePairs(
|
||||
const std::string& aFilename,
|
||||
|
@ -625,6 +637,32 @@ nsresult CollectProcessInfo(ProcessInfo& info) {
|
|||
nativeMachine == IMAGE_FILE_MACHINE_ARM64);
|
||||
}
|
||||
|
||||
// S Mode
|
||||
|
||||
# ifndef __MINGW32__
|
||||
// WindowsIntegrityPolicy is only available on newer versions
|
||||
// of Windows 10, so there's no point in trying to check this
|
||||
// on earlier versions. We know GetActivationFactory crashes on
|
||||
// Windows 7 when trying to retrieve this class, and may also
|
||||
// crash on very old versions of Windows 10.
|
||||
if (IsWin10Sep2018UpdateOrLater()) {
|
||||
ComPtr<IWindowsIntegrityPolicyStatics> wip;
|
||||
HRESULT hr = GetActivationFactory(
|
||||
HStringReference(
|
||||
RuntimeClass_Windows_System_Profile_WindowsIntegrityPolicy)
|
||||
.Get(),
|
||||
&wip);
|
||||
if (SUCCEEDED(hr)) {
|
||||
// info.isWindowsSMode ends up true if Windows is in S mode, otherwise
|
||||
// false
|
||||
// https://docs.microsoft.com/en-us/uwp/api/windows.system.profile.windowsintegritypolicy.isenabled?view=winrt-22000
|
||||
hr = wip->get_IsEnabled(&info.isWindowsSMode);
|
||||
NS_WARNING_ASSERTION(SUCCEEDED(hr),
|
||||
"WindowsIntegrityPolicy.IsEnabled failed");
|
||||
}
|
||||
}
|
||||
# endif // __MINGW32__
|
||||
|
||||
// CPU speed
|
||||
HKEY key;
|
||||
static const WCHAR keyName[] =
|
||||
|
@ -1258,6 +1296,10 @@ JSObject* GetJSObjForProcessInfo(JSContext* aCx, const ProcessInfo& info) {
|
|||
|
||||
JS::Rooted<JS::Value> valisWowARM64(aCx, JS::BooleanValue(info.isWowARM64));
|
||||
JS_SetProperty(aCx, jsInfo, "isWowARM64", valisWowARM64);
|
||||
|
||||
JS::Rooted<JS::Value> valisWindowsSMode(
|
||||
aCx, JS::BooleanValue(info.isWindowsSMode));
|
||||
JS_SetProperty(aCx, jsInfo, "isWindowsSMode", valisWindowsSMode);
|
||||
#endif
|
||||
|
||||
JS::Rooted<JS::Value> valCountInfo(aCx, JS::Int32Value(info.cpuCount));
|
||||
|
|
|
@ -15,6 +15,18 @@
|
|||
# include "mozilla/dom/PContent.h"
|
||||
#endif // MOZ_WIDGET_ANDROID
|
||||
|
||||
#if defined(XP_WIN)
|
||||
# include <inspectable.h>
|
||||
|
||||
// The UUID comes from winrt/windows.system.profile.idl
|
||||
// in the Windows SDK
|
||||
MIDL_INTERFACE("7D1D81DB-8D63-4789-9EA5-DDCF65A94F3C")
|
||||
IWindowsIntegrityPolicyStatics : public IInspectable {
|
||||
public:
|
||||
virtual HRESULT STDMETHODCALLTYPE get_IsEnabled(bool* value) = 0;
|
||||
};
|
||||
#endif
|
||||
|
||||
class nsISerialEventTarget;
|
||||
|
||||
struct FolderDiskInfo {
|
||||
|
@ -38,6 +50,10 @@ struct OSInfo {
|
|||
struct ProcessInfo {
|
||||
bool isWow64 = false;
|
||||
bool isWowARM64 = false;
|
||||
// Whether or not the system is Windows 10 or 11 in S Mode.
|
||||
// S Mode existed prior to us being able to query it, so this
|
||||
// is unreliable on Windows versions prior to 1810.
|
||||
bool isWindowsSMode = false;
|
||||
int32_t cpuCount = 0;
|
||||
int32_t cpuCores = 0;
|
||||
nsCString cpuVendor;
|
||||
|
|
Загрузка…
Ссылка в новой задаче