Bug 925599 - Introduce version test functions using VerifyVersionInfo(). r=bbondy

This commit is contained in:
Masatoshi Kimura 2013-10-19 03:14:31 +09:00
parent d2538a4815
commit 11b1ec2573
9 changed files with 80 additions and 39 deletions

View File

@ -93,7 +93,7 @@ using mozilla::plugins::PluginModuleParent;
#ifdef XP_WIN
#include <windows.h>
#include "nsWindowsHelpers.h"
#include "mozilla/WindowsVersion.h"
#ifdef ACCESSIBILITY
#include "mozilla/a11y/Compatibility.h"
#endif

View File

@ -11,7 +11,7 @@
#include "nsComponentManagerUtils.h"
#include <windows.h>
#include "nsWindowsHelpers.h"
#include "mozilla/WindowsVersion.h"
using namespace mozilla::dom::battery;

View File

@ -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
*

View File

@ -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);

View File

@ -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)
{

View File

@ -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 <windows.h>
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 */

View File

@ -82,6 +82,11 @@ EXPORTS.mozilla += [
'nsMemoryInfoDumper.h',
]
if CONFIG['OS_ARCH'] == 'WINNT':
EXPORTS.mozilla += [
'WindowsVersion.h',
]
CPP_SOURCES += [
'AvailableMemoryTracker.cpp',
'ClearOnShutdown.cpp',

View File

@ -105,16 +105,6 @@ typedef nsAutoRef<HMODULE> nsModuleHandle;
namespace
{
bool
IsVistaOrLater()
{
OSVERSIONINFO info;
ZeroMemory(&info, sizeof(OSVERSIONINFO));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&info);
return info.dwMajorVersion >= 6;
}
bool
IsRunningInWindowsMetro()
{

View File

@ -18,7 +18,8 @@
#ifdef XP_WIN
#include <windows.h>
#include "nsWindowsHelpers.h"
#include "mozilla/WindowsVersion.h"
using mozilla::IsVistaOrLater;
#elif defined(XP_MACOSX)
#include <sys/resource.h>
#endif