Bug 1373888 - part3 : rename the topic of the wake lock. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 29 Aug 2017 10:54:28 +0800
changeset 654647 70fd76bbef317ab3e502377db33832ab705c30d4
parent 654646 556055a8a9f22ed2156e0d99eeda26e67c152eb0
child 654648 56cc217c4ea29163567c8d6f6f4a54c7162a2d0a
child 654753 c60c73749a84f65e1729db8fef2c37f0168949fa
push id76630
push useralwu@mozilla.com
push dateTue, 29 Aug 2017 03:03:25 +0000
bugs1373888
milestone57.0a1
Bug 1373888 - part3 : rename the topic of the wake lock. For knowing the wake lock usage more clearly, we should use more specific topic name. In OSX, you can use "$ pmset -g assertions" to check all the wakelock. In Windows, using "$ powser -energy" to generate the energy report. MozReview-Commit-ID: rAXnkxTvLc
dom/html/HTMLMediaElement.cpp
dom/html/HTMLVideoElement.cpp
widget/cocoa/nsAppShell.mm
widget/gtk/WakeLockListener.cpp
widget/windows/nsAppShell.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4184,17 +4184,17 @@ void
 HTMLMediaElement::WakeLockCreate()
 {
   if (!mWakeLock) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
     NS_ENSURE_TRUE_VOID(pmService);
 
     ErrorResult rv;
-    mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("cpu"),
+    mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("audio-playing"),
                                        OwnerDoc()->GetInnerWindow(),
                                        rv);
   }
 }
 
 void
 HTMLMediaElement::WakeLockRelease()
 {
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -329,17 +329,17 @@ HTMLVideoElement::UpdateScreenWakeLock()
   }
 
   if (!mScreenWakeLock && !mPaused && !hidden && HasVideo()) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
     NS_ENSURE_TRUE_VOID(pmService);
 
     ErrorResult rv;
-    mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("screen"),
+    mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("video-playing"),
                                              OwnerDoc()->GetInnerWindow(),
                                              rv);
   }
 }
 
 void
 HTMLVideoElement::Init()
 {
--- a/widget/cocoa/nsAppShell.mm
+++ b/widget/cocoa/nsAppShell.mm
@@ -55,17 +55,19 @@ public:
   NS_DECL_ISUPPORTS;
 
 private:
   ~MacWakeLockListener() {}
 
   IOPMAssertionID mAssertionID = kIOPMNullAssertionID;
 
   NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) override {
-    if (!aTopic.EqualsASCII("screen")) {
+    if (!aTopic.EqualsASCII("screen") &&
+        !aTopic.EqualsASCII("audio-playing") &&
+        !aTopic.EqualsASCII("video-playing")) {
       return NS_OK;
     }
     // Note the wake lock code ensures that we're not sent duplicate
     // "locked-foreground" notifications when multiple wake locks are held.
     if (aState.EqualsASCII("locked-foreground")) {
       // Prevent screen saver.
       CFStringRef cf_topic =
         ::CFStringCreateWithCharacters(kCFAllocatorDefault,
--- a/widget/gtk/WakeLockListener.cpp
+++ b/widget/gtk/WakeLockListener.cpp
@@ -338,17 +338,19 @@ WakeLockListener::Shutdown()
 
 nsresult
 WakeLockListener::Callback(const nsAString& topic, const nsAString& state)
 {
   if (!mConnection) {
     return NS_ERROR_FAILURE;
   }
 
-  if(!topic.Equals(NS_LITERAL_STRING("screen")))
+  if(!topic.Equals(NS_LITERAL_STRING("screen")) &&
+     !topic.Equals(NS_LITERAL_STRING("audio-playing")) &&
+     !topic.Equals(NS_LITERAL_STRING("video-playing")))
     return NS_OK;
 
   WakeLockTopic* topicLock = mTopics.Get(topic);
   if (!topicLock) {
     topicLock = new WakeLockTopic(topic, mConnection);
     mTopics.Put(topic, topicLock);
   }
 
--- a/widget/windows/nsAppShell.cpp
+++ b/widget/windows/nsAppShell.cpp
@@ -46,17 +46,19 @@ class WinWakeLockListener final : public
 {
 public:
   NS_DECL_ISUPPORTS;
 
 private:
   ~WinWakeLockListener() {}
 
   NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) {
-    if (!aTopic.EqualsASCII("screen")) {
+    if (!aTopic.EqualsASCII("screen") &&
+        !aTopic.EqualsASCII("audio-playing") &&
+        !aTopic.EqualsASCII("video-playing")) {
       return NS_OK;
     }
     // Note the wake lock code ensures that we're not sent duplicate
     // "locked-foreground" notifications when multiple wake locks are held.
     if (aState.EqualsASCII("locked-foreground")) {
       WAKE_LOCK_LOG("WinWakeLock: Blocking screen saver");
       // Prevent the display turning off and block the screen saver.
       SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);