Bug 1043489 - Fix MacOS X holding screensaver lock with fullscreen video. r=smichaud

This ports the fix Chris Pearce made to the windows code in bug 1063995.
We just listen for the 'screen' topic and rely on the notification
machinery to filter duplicates. This avoids incrementing the
lock count on both playback start and fullscreen, and thus waiting
until fullscreen exits after playback stops before enabling the
screensaver again.
This commit is contained in:
Ralph Giles 2014-10-07 18:20:00 -07:00
Родитель 1a2c9fd8d4
Коммит d2a60e7b9b
1 изменённых файлов: 24 добавлений и 35 удалений

Просмотреть файл

@ -54,50 +54,39 @@ private:
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) {
if (!aTopic.EqualsASCII("screen")) {
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");
}
// 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,
reinterpret_cast<const UniChar*>
(aTopic.Data()),
aTopic.Length());
IOReturn success =
::IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn,
cf_topic,
&mAssertionID);
CFRelease(cf_topic);
if (success != kIOReturnSuccess) {
NS_WARNING("failed 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");
}
// Re-enable screen saver.
NS_WARNING("Releasing screensaver");
if (mAssertionID != kIOPMNullAssertionID) {
IOReturn result = ::IOPMAssertionRelease(mAssertionID);
if (result != kIOReturnSuccess) {
NS_WARNING("failed 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