diff --git a/dom/plugins/base/nsNPAPIPlugin.cpp b/dom/plugins/base/nsNPAPIPlugin.cpp index 501f8245521..2b9c1ec6042 100644 --- a/dom/plugins/base/nsNPAPIPlugin.cpp +++ b/dom/plugins/base/nsNPAPIPlugin.cpp @@ -93,7 +93,7 @@ using mozilla::plugins::PluginModuleParent; #ifdef XP_WIN #include -#include "nsWindowsHelpers.h" +#include "mozilla/WindowsVersion.h" #ifdef ACCESSIBILITY #include "mozilla/a11y/Compatibility.h" #endif diff --git a/hal/windows/WindowsBattery.cpp b/hal/windows/WindowsBattery.cpp index 70b5852ba10..4826648e071 100644 --- a/hal/windows/WindowsBattery.cpp +++ b/hal/windows/WindowsBattery.cpp @@ -11,7 +11,7 @@ #include "nsComponentManagerUtils.h" #include -#include "nsWindowsHelpers.h" +#include "mozilla/WindowsVersion.h" using namespace mozilla::dom::battery; diff --git a/toolkit/mozapps/update/common/uachelper.cpp b/toolkit/mozapps/update/common/uachelper.cpp index aaf9180c45c..2905f7f18c5 100644 --- a/toolkit/mozapps/update/common/uachelper.cpp +++ b/toolkit/mozapps/update/common/uachelper.cpp @@ -55,20 +55,6 @@ LPCTSTR UACHelper::PrivsToDisable[] = { SE_UNSOLICITED_INPUT_NAME }; -/** - * Determines if the OS is vista or later - * - * @return TRUE if the OS is vista or later. - */ -BOOL -UACHelper::IsVistaOrLater() -{ - // Check if we are running Vista or later. - OSVERSIONINFO osInfo; - osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - return GetVersionEx(&osInfo) && osInfo.dwMajorVersion >= 6; -} - /** * Opens a user token for the given session ID * diff --git a/toolkit/mozapps/update/common/uachelper.h b/toolkit/mozapps/update/common/uachelper.h index 0d82f8cb993..987a8699e59 100644 --- a/toolkit/mozapps/update/common/uachelper.h +++ b/toolkit/mozapps/update/common/uachelper.h @@ -8,7 +8,6 @@ class UACHelper { public: - static BOOL IsVistaOrLater(); static HANDLE OpenUserToken(DWORD sessionID); static HANDLE OpenLinkedToken(HANDLE token); static BOOL DisablePrivileges(HANDLE token); diff --git a/toolkit/xre/nsWindowsDllBlocklist.cpp b/toolkit/xre/nsWindowsDllBlocklist.cpp index 622c7c83c6d..c3e78a7157f 100644 --- a/toolkit/xre/nsWindowsDllBlocklist.cpp +++ b/toolkit/xre/nsWindowsDllBlocklist.cpp @@ -19,7 +19,7 @@ #include "prlog.h" #include "nsWindowsDllInterceptor.h" -#include "nsWindowsHelpers.h" +#include "mozilla/WindowsVersion.h" using namespace mozilla; @@ -304,16 +304,6 @@ wchar_t* getFullPath (PWCHAR filePath, wchar_t* fname) return full_fname; } -static bool -IsWin8OrLater() -{ - OSVERSIONINFOW osInfo; - osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); - GetVersionExW(&osInfo); - return (osInfo.dwMajorVersion > 6) || - (osInfo.dwMajorVersion >= 6 && osInfo.dwMinorVersion >= 2); -} - static NTSTATUS NTAPI patched_LdrLoadDll (PWCHAR filePath, PULONG flags, PUNICODE_STRING moduleFileName, PHANDLE handle) { diff --git a/xpcom/base/WindowsVersion.h b/xpcom/base/WindowsVersion.h new file mode 100644 index 00000000000..698b1ce1284 --- /dev/null +++ b/xpcom/base/WindowsVersion.h @@ -0,0 +1,70 @@ +/* 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 mozilla_WindowsVersion_h +#define mozilla_WindowsVersion_h + +#include "nscore.h" +#include + +namespace mozilla +{ + inline bool + IsWindowsVersionOrLater(uint64_t aVersion) + { + static uint64_t minVersion = 0; + static uint64_t maxVersion = UINT64_MAX; + + if (minVersion >= aVersion) { + return true; + } + + if (aVersion >= maxVersion) { + return false; + } + + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + info.dwMajorVersion = aVersion >> 48; + info.dwMinorVersion = (aVersion >> 32) & 0xFFFF; + info.wServicePackMajor = (aVersion >> 16) & 0xFFFF; + info.wServicePackMinor = aVersion & 0xFFFF; + + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); + + if (VerifyVersionInfo(&info, + VER_MAJORVERSION | VER_MINORVERSION | + VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, + conditionMask)) { + minVersion = aVersion; + return true; + } + + maxVersion = aVersion; + return false; + } + + MOZ_ALWAYS_INLINE bool + IsVistaOrLater() + { return IsWindowsVersionOrLater(0x0006000000000000ull); } + + MOZ_ALWAYS_INLINE bool + IsWin7OrLater() + { return IsWindowsVersionOrLater(0x0006000100000000ull); } + + MOZ_ALWAYS_INLINE bool + IsWin7SP1OrLater() + { return IsWindowsVersionOrLater(0x0006000100010000ull); } + + MOZ_ALWAYS_INLINE bool + IsWin8OrLater() + { return IsWindowsVersionOrLater(0x0006000200000000ull); } +} + +#endif /* mozilla_WindowsVersion_h */ diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index 10bbbbce957..d5bf89f4cea 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -82,6 +82,11 @@ EXPORTS.mozilla += [ 'nsMemoryInfoDumper.h', ] +if CONFIG['OS_ARCH'] == 'WINNT': + EXPORTS.mozilla += [ + 'WindowsVersion.h', + ] + CPP_SOURCES += [ 'AvailableMemoryTracker.cpp', 'ClearOnShutdown.cpp', diff --git a/xpcom/base/nsWindowsHelpers.h b/xpcom/base/nsWindowsHelpers.h index f647041944c..f53ef775f37 100644 --- a/xpcom/base/nsWindowsHelpers.h +++ b/xpcom/base/nsWindowsHelpers.h @@ -105,16 +105,6 @@ typedef nsAutoRef nsModuleHandle; namespace { - bool - IsVistaOrLater() - { - OSVERSIONINFO info; - ZeroMemory(&info, sizeof(OSVERSIONINFO)); - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&info); - return info.dwMajorVersion >= 6; - } - bool IsRunningInWindowsMetro() { diff --git a/xpcom/glue/nsThreadUtils.cpp b/xpcom/glue/nsThreadUtils.cpp index f2deb747d72..661f5a5dadf 100644 --- a/xpcom/glue/nsThreadUtils.cpp +++ b/xpcom/glue/nsThreadUtils.cpp @@ -18,7 +18,8 @@ #ifdef XP_WIN #include -#include "nsWindowsHelpers.h" +#include "mozilla/WindowsVersion.h" +using mozilla::IsVistaOrLater; #elif defined(XP_MACOSX) #include #endif