ApplicationStateTracker::m_isBackground initialization does not account for UIScenes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2019 21:37:24 +0000 (21:37 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2019 21:37:24 +0000 (21:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202048

Reviewed by Geoffrey Garen.

ApplicationStateTracker::m_isBackground initialization does not account for UIScenes, it merely checks
the visibility state of the whole app. It should instead check the visibility state of the window's
UIScene.

This patch also refactors the code a little bit to reduce #ifdef'ing.

* UIProcess/ApplicationStateTracker.mm:
(WebKit::ApplicationStateTracker::ApplicationStateTracker):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250154 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ApplicationStateTracker.mm

index e05ca47..77b44b6 100644 (file)
@@ -1,5 +1,21 @@
 2019-09-20  Chris Dumez  <cdumez@apple.com>
 
+        ApplicationStateTracker::m_isBackground initialization does not account for UIScenes
+        https://bugs.webkit.org/show_bug.cgi?id=202048
+
+        Reviewed by Geoffrey Garen.
+
+        ApplicationStateTracker::m_isBackground initialization does not account for UIScenes, it merely checks
+        the visibility state of the whole app. It should instead check the visibility state of the window's
+        UIScene.
+
+        This patch also refactors the code a little bit to reduce #ifdef'ing.
+
+        * UIProcess/ApplicationStateTracker.mm:
+        (WebKit::ApplicationStateTracker::ApplicationStateTracker):
+
+2019-09-20  Chris Dumez  <cdumez@apple.com>
+
         Document no longer needs to store a SessionID
         https://bugs.webkit.org/show_bug.cgi?id=202024
 
index adab1a3..4a51108 100644 (file)
@@ -88,7 +88,7 @@ ApplicationStateTracker::ApplicationStateTracker(UIView *view, SEL didEnterBackg
     ASSERT([m_view.get() respondsToSelector:m_willEnterForegroundSelector]);
 
     UIWindow *window = [m_view.get() window];
-    ASSERT(window);
+    RELEASE_ASSERT(window);
 
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
     UIApplication *application = [UIApplication sharedApplication];
@@ -104,28 +104,33 @@ ApplicationStateTracker::ApplicationStateTracker(UIView *view, SEL didEnterBackg
 
     switch (applicationType(window)) {
     case ApplicationType::Application: {
-        m_isInBackground = application.applicationState == UIApplicationStateBackground;
-        RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker::ApplicationStateTracker(): m_isInBackground: %d", this, m_isInBackground);
-
 #if HAVE(UISCENE)
+        m_isInBackground = window.windowScene.activationState == UISceneActivationStateBackground || window.windowScene.activationState == UISceneActivationStateUnattached;
+        RELEASE_LOG(ViewState, "%p - ApplicationStateTracker::ApplicationStateTracker(): m_isInBackground: %d", this, m_isInBackground);
+
         m_didEnterBackgroundObserver = [notificationCenter addObserverForName:UISceneDidEnterBackgroundNotification object:window.windowScene queue:nil usingBlock:[this](NSNotification *) {
-            RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker: UISceneDidEnterBackground", this);
-#else
-        m_didEnterBackgroundObserver = [notificationCenter addObserverForName:UIApplicationDidEnterBackgroundNotification object:application queue:nil usingBlock:[this](NSNotification *) {
-            RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker: UIApplicationDidEnterBackground", this);
-#endif
+            RELEASE_LOG(ViewState, "%p - ApplicationStateTracker: UISceneDidEnterBackground", this);
             applicationDidEnterBackground();
         }];
 
-#if HAVE(UISCENE)
         m_willEnterForegroundObserver = [notificationCenter addObserverForName:UISceneWillEnterForegroundNotification object:window.windowScene queue:nil usingBlock:[this](NSNotification *) {
-            RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker: UISceneWillEnterForeground", this);
+            RELEASE_LOG(ViewState, "%p - ApplicationStateTracker: UISceneWillEnterForeground", this);
+            applicationWillEnterForeground();
+        }];
 #else
+        m_isInBackground = application.applicationState == UIApplicationStateBackground;
+        RELEASE_LOG(ViewState, "%p - ApplicationStateTracker::ApplicationStateTracker(): m_isInBackground: %d", this, m_isInBackground);
+
+        m_didEnterBackgroundObserver = [notificationCenter addObserverForName:UIApplicationDidEnterBackgroundNotification object:application queue:nil usingBlock:[this](NSNotification *) {
+            RELEASE_LOG(ViewState, "%p - ApplicationStateTracker: UIApplicationDidEnterBackground", this);
+            applicationDidEnterBackground();
+        }];
+
         m_willEnterForegroundObserver = [notificationCenter addObserverForName:UIApplicationWillEnterForegroundNotification object:application queue:nil usingBlock:[this](NSNotification *) {
-            RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker: UIApplicationWillEnterForeground", this);
-#endif
+            RELEASE_LOG(ViewState, "%p - ApplicationStateTracker: UIApplicationWillEnterForeground", this);
             applicationWillEnterForeground();
         }];
+#endif
         break;
     }