Skip to content

Commit

Permalink
WebKit shouldn't be modifying the value of UIApplication.idleTimerDis…
Browse files Browse the repository at this point in the history
…abled

https://bugs.webkit.org/show_bug.cgi?id=259706

Reviewed by Jer Noble.

WebKit shouldn't be modifying the value of UIApplication.idleTimerDisabled
because we're a framework. The hosting application can rely on this flag to
prevent screen sleep and it is not good for WebKit to be potentially overriding
a value set by the application.

To address the issue, the UIKit code indicates that frameworks are expected to
call the `_setIdleTimerDisabled:forReason:` SPI instead.

* Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h:
* Source/WebCore/PAL/pal/system/ios/SleepDisablerIOS.mm:
(PAL::ScreenSleepDisabler::updateState):

Canonical link: https://commits.webkit.org/266499@main
  • Loading branch information
cdumez committed Aug 1, 2023
1 parent 864524d commit 9ed33f8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Source/WebCore/PAL/pal/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ void registerNotifyCallback(ASCIILiteral notifyID, Function<void()>&& callback)
#endif
}

#if !LOG_DISABLED || !RELEASE_LOG_DISABLED

#define DEFINE_PAL_LOG_CHANNEL(name) DEFINE_LOG_CHANNEL(name, LOG_CHANNEL_WEBKIT_SUBSYSTEM)
PAL_LOG_CHANNELS(DEFINE_PAL_LOG_CHANNEL)

#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED

} // namespace WebCore
17 changes: 17 additions & 0 deletions Source/WebCore/PAL/pal/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,22 @@ namespace PAL {

PAL_EXPORT void registerNotifyCallback(ASCIILiteral, Function<void()>&&);

#if !LOG_DISABLED || !RELEASE_LOG_DISABLED

#ifndef LOG_CHANNEL_PREFIX
#define LOG_CHANNEL_PREFIX Log
#endif

#define PAL_LOG_CHANNELS(M) \
M(Media)

#undef DECLARE_LOG_CHANNEL
#define DECLARE_LOG_CHANNEL(name) \
PAL_EXPORT extern WTFLogChannel JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, name);

PAL_LOG_CHANNELS(DECLARE_LOG_CHANNEL)

#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED

} // namespace PAL

1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ typedef enum {
- (BOOL)_isClassic;
+ (UIApplicationSceneClassicMode)_classicMode;
- (GSKeyboardRef)_hardwareKeyboard;
- (void)_setIdleTimerDisabled:(BOOL)disabled forReason:(NSString *)reason;
@end

@interface UIColor ()
Expand Down
5 changes: 4 additions & 1 deletion Source/WebCore/PAL/pal/system/ios/SleepDisablerIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#import "SleepDisablerCocoa.h"

#if PLATFORM(IOS_FAMILY)
#import "Logging.h"
#import <pal/spi/ios/UIKitSPI.h>
#import <wtf/NeverDestroyed.h>

#import <pal/ios/UIKitSoftLink.h>
Expand Down Expand Up @@ -64,10 +66,11 @@ void updateState()
return;

bool shouldKeepScreenAwake = !!m_screenSleepDisablerCount.value();
RELEASE_LOG(Media, "ScreenSleepDisabler::updateState() shouldKeepScreenAwake=%d", shouldKeepScreenAwake);
ensureOnMainRunLoop([this, shouldKeepScreenAwake] {
if (m_screenWakeLockHandler && m_screenWakeLockHandler(shouldKeepScreenAwake))
return;
[PAL::getUIApplicationClass() sharedApplication].idleTimerDisabled = shouldKeepScreenAwake;
[[PAL::getUIApplicationClass() sharedApplication] _setIdleTimerDisabled:shouldKeepScreenAwake forReason:@"WebKit SleepDisabler"];
});
}
ScreenSleepDisablerCounter m_screenSleepDisablerCount;
Expand Down

0 comments on commit 9ed33f8

Please sign in to comment.