Bug 774140 - Remove code duplication for IsVistaOrLater. r=bsmedberg
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -88,16 +88,17 @@ using mozilla::PluginPRLibrary;
using mozilla::plugins::PluginModuleParent;
#ifdef MOZ_X11
#include "mozilla/X11Util.h"
#endif
#ifdef XP_WIN
#include <windows.h>
+#include "nsWindowsHelpers.h"
#endif
#ifdef MOZ_WIDGET_ANDROID
#include <android/log.h>
#include "android_npapi.h"
#include "ANPBase.h"
#include "AndroidBridge.h"
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
@@ -276,30 +277,16 @@ static bool GMA9XXGraphics()
}
}
::CGLDestroyRendererInfo(renderer);
}
return hasIntelGMA9XX;
}
#endif
-#ifdef XP_WIN
-static bool
-IsVistaOrLater()
-{
- OSVERSIONINFO info;
-
- ZeroMemory(&info, sizeof(OSVERSIONINFO));
- info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&info);
-
- return info.dwMajorVersion >= 6;
-}
-#endif
-
bool
nsNPAPIPlugin::RunPluginOOP(const nsPluginTag *aPluginTag)
{
if (PR_GetEnv("MOZ_DISABLE_OOP_PLUGINS")) {
return false;
}
if (!aPluginTag) {
--- a/hal/windows/WindowsBattery.cpp
+++ b/hal/windows/WindowsBattery.cpp
@@ -5,16 +5,17 @@
#include "Hal.h"
#include "HalImpl.h"
#include "nsITimer.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/battery/Constants.h"
#include <windows.h>
+#include "nsWindowsHelpers.h"
using namespace mozilla::dom::battery;
namespace mozilla {
namespace hal_impl {
static nsCOMPtr<nsITimer> sUpdateTimer;
@@ -22,28 +23,16 @@ static nsCOMPtr<nsITimer> sUpdateTimer;
typedef HPOWERNOTIFY (WINAPI *REGISTERPOWERSETTINGNOTIFICATION) (HANDLE, LPCGUID, DWORD);
typedef BOOL (WINAPI *UNREGISTERPOWERSETTINGNOTIFICATION) (HPOWERNOTIFY);
static REGISTERPOWERSETTINGNOTIFICATION sRegisterPowerSettingNotification = nsnull;
static UNREGISTERPOWERSETTINGNOTIFICATION sUnregisterPowerSettingNotification = nsnull;
static HPOWERNOTIFY sPowerHandle = nsnull;
static HPOWERNOTIFY sCapacityHandle = nsnull;
static HWND sHWnd = nsnull;
-static bool
-IsVistaOrLater()
-{
- OSVERSIONINFO info;
-
- ZeroMemory(&info, sizeof(OSVERSIONINFO));
- info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&info);
-
- return info.dwMajorVersion >= 6;
-}
-
static void
UpdateHandler(nsITimer* aTimer, void* aClosure) {
NS_ASSERTION(!IsVistaOrLater(),
"We shouldn't call this function for Vista or later version!");
static hal::BatteryInformation sLastInfo;
hal::BatteryInformation currentInfo;
--- a/toolkit/xre/nsWindowsDllBlocklist.cpp
+++ b/toolkit/xre/nsWindowsDllBlocklist.cpp
@@ -14,16 +14,17 @@
#include "nsXULAppAPI.h"
#include "nsAutoPtr.h"
#include "nsThreadUtils.h"
#include "prlog.h"
#include "nsWindowsDllInterceptor.h"
+#include "nsWindowsHelpers.h"
using namespace mozilla;
#if defined(MOZ_CRASHREPORTER) && !defined(NO_BLOCKLIST_CRASHREPORTER)
#include "nsExceptionHandler.h"
#endif
#define ALL_VERSIONS ((unsigned long long)-1LL)
@@ -151,28 +152,16 @@ struct RVAMap {
operator const T*() const { return mMappedView; }
const T* operator->() const { return mMappedView; }
private:
const T* mMappedView;
void* mRealView;
};
bool
-IsVistaOrLater()
-{
- OSVERSIONINFO info;
-
- ZeroMemory(&info, sizeof(OSVERSIONINFO));
- info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&info);
-
- return info.dwMajorVersion >= 6;
-}
-
-bool
CheckASLR(const wchar_t* path)
{
bool retval = false;
HANDLE file = ::CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
if (file != INVALID_HANDLE_VALUE) {
--- a/xpcom/base/nsWindowsHelpers.h
+++ b/xpcom/base/nsWindowsHelpers.h
@@ -1,15 +1,16 @@
/* 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 nsWindowsHelpers_h
#define nsWindowsHelpers_h
+#include <windows.h>
#include "nsAutoRef.h"
#include "nscore.h"
template<>
class nsAutoRefTraits<HKEY>
{
public:
typedef HKEY RawRef;
@@ -77,9 +78,22 @@ public:
}
RawRef mRawRef;
};
typedef nsAutoRef<HKEY> nsAutoRegKey;
typedef nsAutoRef<SC_HANDLE> nsAutoServiceHandle;
typedef nsAutoRef<HANDLE> nsAutoHandle;
+namespace
+{
+ bool
+ IsVistaOrLater()
+ {
+ OSVERSIONINFO info;
+ ZeroMemory(&info, sizeof(OSVERSIONINFO));
+ info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&info);
+ return info.dwMajorVersion >= 6;
+ }
+}
+
#endif