Bug 952835 - screen goes to sleep while video still playing in Metro Firefox r=jimm

--HG--
extra : rebase_source : 07926a411418a61e20df832ebb032fff5b218a77
This commit is contained in:
Rodrigo Silveira 2014-01-15 16:11:36 -08:00
parent d9b64b76ed
commit fde2cb01fe

View File

@ -17,6 +17,10 @@
#include "nsIAppStartup.h"
#include "nsToolkitCompsCID.h"
#include <shellapi.h>
#include "nsIDOMWakeLockListener.h"
#include "nsIPowerManagerService.h"
#include "mozilla/StaticPtr.h"
#include <windows.system.display.h>
using namespace mozilla;
using namespace mozilla::widget;
@ -46,6 +50,33 @@ namespace widget {
extern UINT sAppShellGeckoMsgId;
} }
class WakeLockListener : public nsIDOMMozWakeLockListener {
public:
NS_DECL_ISUPPORTS;
private:
ComPtr<ABI::Windows::System::Display::IDisplayRequest> mDisplayRequest;
NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) {
if (!mDisplayRequest) {
if (FAILED(ActivateGenericInstance(RuntimeClass_Windows_System_Display_DisplayRequest, mDisplayRequest))) {
NS_WARNING("Failed to instantiate IDisplayRequest, wakelocks will be broken!");
return NS_OK;
}
}
if (aState.Equals(NS_LITERAL_STRING("locked-foreground"))) {
mDisplayRequest->RequestActive();
} else {
mDisplayRequest->RequestRelease();
}
return NS_OK;
}
};
NS_IMPL_ISUPPORTS1(WakeLockListener, nsIDOMMozWakeLockListener)
StaticRefPtr<WakeLockListener> sWakeLockListener;
static ComPtr<ICoreWindowStatic> sCoreStatic;
static bool sIsDispatching = false;
static bool sShouldPurgeThreadQueue = false;
@ -196,11 +227,27 @@ MetroAppShell::Run(void)
rv = NS_ERROR_NOT_IMPLEMENTED;
break;
case GeckoProcessType_Default: {
nsCOMPtr<nsIPowerManagerService> sPowerManagerService = do_GetService(POWERMANAGERSERVICE_CONTRACTID);
if (sPowerManagerService) {
sWakeLockListener = new WakeLockListener();
sPowerManagerService->AddWakeLockListener(sWakeLockListener);
}
else {
NS_WARNING("Failed to retrieve PowerManagerService, wakelocks will be broken!");
}
mozilla::widget::StartAudioSession();
sFrameworkView->ActivateView();
rv = nsBaseAppShell::Run();
mozilla::widget::StopAudioSession();
if (sPowerManagerService) {
sPowerManagerService->RemoveWakeLockListener(sWakeLockListener);
sPowerManagerService = nullptr;
sWakeLockListener = nullptr;
}
nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID));
bool restartingInMetro = false, restartingInDesktop = false;