Bug 925599 - Replace GetVersionEx() in toolkit/. r=bsmedberg
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 22 Nov 2013 12:35:40 +0900
changeset 156989 34be216f6d0e8ef3a51140156a62a807ab315f48
parent 156988 6c1ed54cd96c20991bae5eaa20bfa04b2e3de4fc
child 156990 a148cd4445aad2f0d650d55dedc8ce7579098c5c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbsmedberg
bugs925599
milestone28.0a1
Bug 925599 - Replace GetVersionEx() in toolkit/. r=bsmedberg
toolkit/library/nsDllMain.cpp
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/library/nsDllMain.cpp
+++ b/toolkit/library/nsDllMain.cpp
@@ -2,16 +2,19 @@
 /* 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/. */
  
 #include <windows.h>
 #include <delayimp.h>
 #include "nsToolkit.h"
 #include "mozilla/Assertions.h"
+#include "mozilla/WindowsVersion.h"
+
+using mozilla::IsWin8OrLater;
 
 #if defined(__GNUC__)
 // If DllMain gets name mangled, it won't be seen.
 extern "C" {
 #endif
 
 BOOL APIENTRY DllMain(  
                       HINSTANCE hModule, 
@@ -58,46 +61,30 @@ BOOL APIENTRY DllMain(
  * - trap attempts to load entry points in dummyvccorlib. This is not expected
  *   to happen in release code. It can happen during development if winrt apis
  *   are accessed when running on the desktop, or when winrt objects are
  *   accidentially placed in the global scope.
  * - trap and handle calls to vccorlib's __abi_FailFast in a breakpad compatible
  *   way. __abi_FailFast is called by exception handling code generated by the
  *   compiler for delegate events.
  */
-static bool IsWin8OrHigher()
-{
-  static int32_t version = 0;
-
-  if (version) {
-    return (version >= 0x602);
-  }
-
-  // Match Win8 or Win8 Server or higher
-  OSVERSIONINFOEX osInfo;
-  osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-  ::GetVersionEx((OSVERSIONINFO*)&osInfo);
-  version =
-    (osInfo.dwMajorVersion & 0xff) << 8 | (osInfo.dwMinorVersion & 0xff);
-  return (version >= 0x602);
-}
 
 const char* kvccorlib = "vccorlib";
 const char* kwinrtprelim = "api-ms-win-core-winrt";
 const char* kfailfast = "?__abi_FailFast";
 
 static bool IsWinRTDLLNotPresent(PDelayLoadInfo pdli, const char* aLibToken)
 {
-  return (!IsWin8OrHigher() && pdli->szDll &&
+  return (!IsWin8OrLater() && pdli->szDll &&
           !strnicmp(pdli->szDll, aLibToken, strlen(aLibToken)));
 }
 
 static bool IsWinRTDLLPresent(PDelayLoadInfo pdli, const char* aLibToken)
 {
-  return (IsWin8OrHigher() && pdli->szDll &&
+  return (IsWin8OrLater() && pdli->szDll &&
           !strnicmp(pdli->szDll, aLibToken, strlen(aLibToken)));
 }
 
 void __stdcall __abi_MozFailFast()
 {
   MOZ_CRASH();
 }
 
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -94,16 +94,17 @@
 #include "mozilla/scache/StartupCache.h"
 
 #include "mozilla/unused.h"
 
 #ifdef XP_WIN
 #include "nsIWinAppHelper.h"
 #include <windows.h>
 #include "cairo/cairo-features.h"
+#include "mozilla/WindowsVersion.h"
 #ifdef MOZ_METRO
 #include <roapi.h>
 #endif
 
 #ifndef PROCESS_DEP_ENABLE
 #define PROCESS_DEP_ENABLE 0x1
 #endif
 #endif
@@ -2862,20 +2863,18 @@ XREMain::XRE_mainInit(bool* aExitFlag)
     // starts the FntCache service if it isn't already running (it's set
     // to manual startup by default in Windows 7 RTM).  Subsequent DirectWrite
     // calls cause the IDWriteFactory object to communicate with the FntCache
     // service with a timeout; if there's no response after the timeout, the
     // DirectWrite client library will assume the service isn't around and do
     // manual font file I/O on _all_ system fonts.  To avoid this, load the
     // dwrite library and create a factory as early as possible so that the
     // FntCache service is ready by the time it's needed.
-      
-    OSVERSIONINFO vinfo;
-    vinfo.dwOSVersionInfoSize = sizeof(vinfo);
-    if (GetVersionEx(&vinfo) && vinfo.dwMajorVersion >= 6) {
+
+    if (IsVistaOrLater()) {
       CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)&InitDwriteBG,
                    nullptr, 0, nullptr);
     }
   }
 #endif
 
 #ifdef XP_UNIX
   const char *home = PR_GetEnv("HOME");