Bug 772347 - Back out MacOS X video wakelock. a=sledru
authorRalph Giles <giles@mozilla.com>
Mon, 06 Oct 2014 10:48:51 -0700
changeset 258693 df37248fafcb
parent 258692 267c7a481bef
child 258694 d89ec5b69c01
push id4700
push userryanvm@gmail.com
push date2015-04-21 23:53 +0000
treeherdermozilla-beta@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssledru
bugs772347, 1043489
milestone33.0
Bug 772347 - Back out MacOS X video wakelock. a=sledru Backing out changeset dde8abeff07a based on bug 1043489. The wakelock isn't released when playback stops in fullscreen.
widget/cocoa/nsAppShell.mm
--- a/widget/cocoa/nsAppShell.mm
+++ b/widget/cocoa/nsAppShell.mm
@@ -29,82 +29,18 @@
 #include "nsCocoaUtils.h"
 #include "nsChildView.h"
 #include "nsToolkit.h"
 #include "TextInputHandler.h"
 #include "mozilla/HangMonitor.h"
 #include "GeckoProfiler.h"
 #include "pratom.h"
 
-#include <IOKit/pwr_mgt/IOPMLib.h>
-#include "nsIDOMWakeLockListener.h"
-#include "nsIPowerManagerService.h"
-
 using namespace mozilla::widget;
 
-// A wake lock listener that disables screen saver when requested by
-// Gecko. For example when we're playing video in a foreground tab we
-// don't want the screen saver to turn on.
-
-class MacWakeLockListener MOZ_FINAL : public nsIDOMMozWakeLockListener {
-public:
-  NS_DECL_ISUPPORTS;
-
-private:
-  ~MacWakeLockListener() {}
-
-  IOPMAssertionID mAssertionID = kIOPMNullAssertionID;
-
-  NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) {
-    bool isLocked = mLockedTopics.Contains(aTopic);
-    bool shouldLock = aState.EqualsLiteral("locked-foreground");
-    if (isLocked == shouldLock) {
-      return NS_OK;
-    }
-    if (shouldLock) {
-      if (!mLockedTopics.Count()) {
-        // This is the first topic to request the screen saver be disabled.
-        // Prevent screen saver.
-        CFStringRef cf_topic =
-          ::CFStringCreateWithCharacters(kCFAllocatorDefault,
-                                         reinterpret_cast<const UniChar*>
-                                           (aTopic.Data()),
-                                         aTopic.Length());
-        IOReturn success =
-          ::IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
-                                        kIOPMAssertionLevelOn,
-                                        cf_topic,
-                                        &mAssertionID);
-        CFRelease(cf_topic);
-        if (success != kIOReturnSuccess) {
-          NS_WARNING("fail to disable screensaver");
-        }
-      }
-      mLockedTopics.PutEntry(aTopic);
-    } else {
-      mLockedTopics.RemoveEntry(aTopic);
-      if (!mLockedTopics.Count()) {
-        // No other outstanding topics have requested screen saver be disabled.
-        // Re-enable screen saver.
-        if (mAssertionID != kIOPMNullAssertionID) {
-          IOReturn result = ::IOPMAssertionRelease(mAssertionID);
-          if (result != kIOReturnSuccess) {
-            NS_WARNING("fail to release screensaver");
-          }
-        }
-      }
-    }
-    return NS_OK;
-  }
-  // Keep track of all the topics that have requested a wake lock. When the
-  // number of topics in the hashtable reaches zero, we can uninhibit the
-  // screensaver again.
-  nsTHashtable<nsStringHashKey> mLockedTopics;
-};
-
 // defined in nsCocoaWindow.mm
 extern int32_t             gXULModalLevel;
 
 static bool gAppShellMethodsSwizzled = false;
 
 @implementation GeckoNSApplication
 
 - (void)sendEvent:(NSEvent *)anEvent
@@ -200,43 +136,16 @@ nsAppShell::~nsAppShell()
     ::CFRelease(mAutoreleasePools);
   }
 
   [mDelegate release];
 
   NS_OBJC_END_TRY_ABORT_BLOCK
 }
 
-NS_IMPL_ISUPPORTS(MacWakeLockListener, nsIDOMMozWakeLockListener)
-mozilla::StaticRefPtr<MacWakeLockListener> sWakeLockListener;
-
-static void
-AddScreenWakeLockListener()
-{
-  nsCOMPtr<nsIPowerManagerService> sPowerManagerService = do_GetService(
-                                                          POWERMANAGERSERVICE_CONTRACTID);
-  if (sPowerManagerService) {
-    sWakeLockListener = new MacWakeLockListener();
-    sPowerManagerService->AddWakeLockListener(sWakeLockListener);
-  } else {
-    NS_WARNING("Failed to retrieve PowerManagerService, wakelocks will be broken!");
-  }
-}
-
-static void
-RemoveScreenWakeLockListener()
-{
-  nsCOMPtr<nsIPowerManagerService> sPowerManagerService = do_GetService(
-                                                          POWERMANAGERSERVICE_CONTRACTID);
-  if (sPowerManagerService) {
-    sPowerManagerService->RemoveWakeLockListener(sWakeLockListener);
-    sPowerManagerService = nullptr;
-    sWakeLockListener = nullptr;
-  }
-}
 // Init
 //
 // Loads the nib (see bug 316076c21) and sets up the CFRunLoopSource used to
 // interrupt the main native run loop.
 //
 // public
 nsresult
 nsAppShell::Init()
@@ -636,23 +545,18 @@ nsAppShell::ProcessNextNativeEvent(bool 
 NS_IMETHODIMP
 nsAppShell::Run(void)
 {
   NS_ASSERTION(!mStarted, "nsAppShell::Run() called multiple times");
   if (mStarted || mTerminated)
     return NS_OK;
 
   mStarted = true;
-
-  AddScreenWakeLockListener();
-
   NS_OBJC_TRY_ABORT([NSApp run]);
 
-  RemoveScreenWakeLockListener();
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAppShell::Exit(void)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;