зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1334862 - Remove Windows XP support from HAL. r=jimm
MozReview-Commit-ID: 72mQbhyCohg --HG-- extra : rebase_source : 9e151ded3b2b72207bb0a2d0475f98ec77848f00
This commit is contained in:
Родитель
ce6e6eeda0
Коммит
9dc92bce56
|
@ -5,45 +5,20 @@
|
||||||
|
|
||||||
#include "Hal.h"
|
#include "Hal.h"
|
||||||
#include "HalImpl.h"
|
#include "HalImpl.h"
|
||||||
#include "nsITimer.h"
|
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "mozilla/dom/battery/Constants.h"
|
#include "mozilla/dom/battery/Constants.h"
|
||||||
#include "nsComponentManagerUtils.h"
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "mozilla/WindowsVersion.h"
|
|
||||||
|
|
||||||
using namespace mozilla::dom::battery;
|
using namespace mozilla::dom::battery;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace hal_impl {
|
namespace hal_impl {
|
||||||
|
|
||||||
static nsCOMPtr<nsITimer> sUpdateTimer;
|
|
||||||
|
|
||||||
/* Power Event API is Vista or later */
|
|
||||||
static decltype(RegisterPowerSettingNotification)* sRegisterPowerSettingNotification = nullptr;
|
|
||||||
static decltype(UnregisterPowerSettingNotification)* sUnregisterPowerSettingNotification = nullptr;
|
|
||||||
static HPOWERNOTIFY sPowerHandle = nullptr;
|
static HPOWERNOTIFY sPowerHandle = nullptr;
|
||||||
static HPOWERNOTIFY sCapacityHandle = nullptr;
|
static HPOWERNOTIFY sCapacityHandle = nullptr;
|
||||||
static HWND sHWnd = nullptr;
|
static HWND sHWnd = nullptr;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
hal_impl::GetCurrentBatteryInformation(¤tInfo);
|
|
||||||
if (sLastInfo.level() != currentInfo.level() ||
|
|
||||||
sLastInfo.charging() != currentInfo.charging() ||
|
|
||||||
sLastInfo.remainingTime() != currentInfo.remainingTime()) {
|
|
||||||
hal::NotifyBatteryChange(currentInfo);
|
|
||||||
sLastInfo = currentInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||||
|
@ -63,94 +38,56 @@ BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||||
void
|
void
|
||||||
EnableBatteryNotifications()
|
EnableBatteryNotifications()
|
||||||
{
|
{
|
||||||
if (IsVistaOrLater()) {
|
// Create custom window to watch battery event
|
||||||
// RegisterPowerSettingNotification is from Vista or later.
|
// If we can get Gecko's window handle, this is unnecessary.
|
||||||
// Use this API if available.
|
|
||||||
HMODULE hUser32 = GetModuleHandleW(L"USER32.DLL");
|
|
||||||
if (!sRegisterPowerSettingNotification)
|
|
||||||
sRegisterPowerSettingNotification = (decltype(RegisterPowerSettingNotification)*)
|
|
||||||
GetProcAddress(hUser32, "RegisterPowerSettingNotification");
|
|
||||||
if (!sUnregisterPowerSettingNotification)
|
|
||||||
sUnregisterPowerSettingNotification = (decltype(UnregisterPowerSettingNotification)*)
|
|
||||||
GetProcAddress(hUser32, "UnregisterPowerSettingNotification");
|
|
||||||
|
|
||||||
if (!sRegisterPowerSettingNotification ||
|
if (sHWnd == nullptr) {
|
||||||
!sUnregisterPowerSettingNotification) {
|
WNDCLASSW wc;
|
||||||
NS_ASSERTION(false, "Canot find PowerSettingNotification functions.");
|
HMODULE hSelf = GetModuleHandle(nullptr);
|
||||||
return;
|
|
||||||
|
if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) {
|
||||||
|
ZeroMemory(&wc, sizeof(WNDCLASSW));
|
||||||
|
wc.hInstance = hSelf;
|
||||||
|
wc.lpfnWndProc = BatteryWindowProc;
|
||||||
|
wc.lpszClassName = L"MozillaBatteryClass";
|
||||||
|
RegisterClassW(&wc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create custom window to watch battery event
|
sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher",
|
||||||
// If we can get Gecko's window handle, this is unnecessary.
|
0, 0, 0, 0, 0,
|
||||||
|
nullptr, nullptr, hSelf, nullptr);
|
||||||
if (sHWnd == nullptr) {
|
|
||||||
WNDCLASSW wc;
|
|
||||||
HMODULE hSelf = GetModuleHandle(nullptr);
|
|
||||||
|
|
||||||
if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) {
|
|
||||||
ZeroMemory(&wc, sizeof(WNDCLASSW));
|
|
||||||
wc.hInstance = hSelf;
|
|
||||||
wc.lpfnWndProc = BatteryWindowProc;
|
|
||||||
wc.lpszClassName = L"MozillaBatteryClass";
|
|
||||||
RegisterClassW(&wc);
|
|
||||||
}
|
|
||||||
|
|
||||||
sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher",
|
|
||||||
0, 0, 0, 0, 0,
|
|
||||||
nullptr, nullptr, hSelf, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sHWnd == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sPowerHandle =
|
|
||||||
sRegisterPowerSettingNotification(sHWnd,
|
|
||||||
&GUID_ACDC_POWER_SOURCE,
|
|
||||||
DEVICE_NOTIFY_WINDOW_HANDLE);
|
|
||||||
sCapacityHandle =
|
|
||||||
sRegisterPowerSettingNotification(sHWnd,
|
|
||||||
&GUID_BATTERY_PERCENTAGE_REMAINING,
|
|
||||||
DEVICE_NOTIFY_WINDOW_HANDLE);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
// for Windows XP. If we remove Windows XP support,
|
|
||||||
// we should remove timer-based power notification
|
|
||||||
sUpdateTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
||||||
if (sUpdateTimer) {
|
|
||||||
sUpdateTimer->InitWithFuncCallback(UpdateHandler,
|
|
||||||
nullptr,
|
|
||||||
Preferences::GetInt("dom.battery.timer",
|
|
||||||
30000 /* 30s */),
|
|
||||||
nsITimer::TYPE_REPEATING_SLACK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sHWnd == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sPowerHandle =
|
||||||
|
RegisterPowerSettingNotification(sHWnd,
|
||||||
|
&GUID_ACDC_POWER_SOURCE,
|
||||||
|
DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||||
|
sCapacityHandle =
|
||||||
|
RegisterPowerSettingNotification(sHWnd,
|
||||||
|
&GUID_BATTERY_PERCENTAGE_REMAINING,
|
||||||
|
DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DisableBatteryNotifications()
|
DisableBatteryNotifications()
|
||||||
{
|
{
|
||||||
if (IsVistaOrLater()) {
|
if (sPowerHandle) {
|
||||||
if (sPowerHandle) {
|
UnregisterPowerSettingNotification(sPowerHandle);
|
||||||
sUnregisterPowerSettingNotification(sPowerHandle);
|
sPowerHandle = nullptr;
|
||||||
sPowerHandle = nullptr;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (sCapacityHandle) {
|
if (sCapacityHandle) {
|
||||||
sUnregisterPowerSettingNotification(sCapacityHandle);
|
UnregisterPowerSettingNotification(sCapacityHandle);
|
||||||
sCapacityHandle = nullptr;
|
sCapacityHandle = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sHWnd) {
|
if (sHWnd) {
|
||||||
DestroyWindow(sHWnd);
|
DestroyWindow(sHWnd);
|
||||||
sHWnd = nullptr;
|
sHWnd = nullptr;
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (sUpdateTimer) {
|
|
||||||
sUpdateTimer->Cancel();
|
|
||||||
sUpdateTimer = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче