Add better logging for when the view visibility state changes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2019 00:11:57 +0000 (00:11 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2019 00:11:57 +0000 (00:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202008

Reviewed by Geoffrey Garen.

* UIProcess/ApplicationStateTracker.mm:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::updateActivityState):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applicationDidEnterBackground):
(WebKit::WebPageProxy::applicationWillEnterForeground):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ApplicationStateTracker.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

index 3f39d0f..80d4d75 100644 (file)
@@ -1,5 +1,19 @@
 2019-09-19  Chris Dumez  <cdumez@apple.com>
 
+        Add better logging for when the view visibility state changes
+        https://bugs.webkit.org/show_bug.cgi?id=202008
+
+        Reviewed by Geoffrey Garen.
+
+        * UIProcess/ApplicationStateTracker.mm:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::updateActivityState):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applicationDidEnterBackground):
+        (WebKit::WebPageProxy::applicationWillEnterForeground):
+
+2019-09-19  Chris Dumez  <cdumez@apple.com>
+
         Regression(r248832): Unable to quicklook HTML files in Mail
         https://bugs.webkit.org/show_bug.cgi?id=202012
         <rdar://problem/55285295>
index 507922f..adab1a3 100644 (file)
@@ -105,19 +105,24 @@ 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_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
             applicationDidEnterBackground();
         }];
 
 #if HAVE(UISCENE)
         m_willEnterForegroundObserver = [notificationCenter addObserverForName:UISceneWillEnterForegroundNotification object:window.windowScene queue:nil usingBlock:[this](NSNotification *) {
+            RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker: UISceneWillEnterForeground", this);
 #else
         m_willEnterForegroundObserver = [notificationCenter addObserverForName:UIApplicationWillEnterForegroundNotification object:application queue:nil usingBlock:[this](NSNotification *) {
+            RELEASE_LOG(ProcessSuspension, "%p - ApplicationStateTracker: UIApplicationWillEnterForeground", this);
 #endif
             applicationWillEnterForeground();
         }];
index 5a4645f..b0943bf 100644 (file)
@@ -1726,13 +1726,19 @@ void WebPageProxy::setSuppressVisibilityUpdates(bool flag)
 
 void WebPageProxy::updateActivityState(OptionSet<ActivityState::Flag> flagsToUpdate)
 {
+    bool wasVisible = isViewVisible();
     m_activityState.remove(flagsToUpdate);
     if (flagsToUpdate & ActivityState::IsFocused && pageClient().isViewFocused())
         m_activityState.add(ActivityState::IsFocused);
     if (flagsToUpdate & ActivityState::WindowIsActive && pageClient().isViewWindowActive())
         m_activityState.add(ActivityState::WindowIsActive);
-    if (flagsToUpdate & ActivityState::IsVisible && pageClient().isViewVisible())
-        m_activityState.add(ActivityState::IsVisible);
+    if (flagsToUpdate & ActivityState::IsVisible) {
+        bool isNowVisible = pageClient().isViewVisible();
+        if (isNowVisible)
+            m_activityState.add(ActivityState::IsVisible);
+        if (wasVisible != isNowVisible)
+            RELEASE_LOG_IF_ALLOWED(ViewState, "updateActivityState: view visibility state changed %d -> %d", wasVisible, isNowVisible);
+    }
     if (flagsToUpdate & ActivityState::IsVisibleOrOccluded && pageClient().isViewVisibleOrOccluded())
         m_activityState.add(ActivityState::IsVisibleOrOccluded);
     if (flagsToUpdate & ActivityState::IsInWindow && pageClient().isViewInWindow())
index 407d96a..e970ac4 100644 (file)
@@ -74,6 +74,8 @@
 #import <wtf/text/WTFString.h>
 #endif
 
+#define RELEASE_LOG_IF_ALLOWED(channel, fmt, ...) RELEASE_LOG_IF(isAlwaysOnLoggingAllowed(), channel, "%p - [pageProxyID=%llu, webPageID=%llu, PID=%i] WebPageProxy::" fmt, this, m_identifier.toUInt64(), m_webPageID.toUInt64(), m_process->processIdentifier(), ##__VA_ARGS__)
+
 namespace WebKit {
 using namespace WebCore;
 
@@ -647,6 +649,8 @@ void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, u
 void WebPageProxy::applicationDidEnterBackground()
 {
     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
+    
+    RELEASE_LOG_IF_ALLOWED(ViewState, "applicationDidEnterBackground: isSuspendedUnderLock? %d", isSuspendedUnderLock);
 
 #if !PLATFORM(WATCHOS)
     // We normally delay process suspension when the app is backgrounded until the current page load completes. However,
@@ -674,6 +678,8 @@ bool WebPageProxy::isInHardwareKeyboardMode()
 void WebPageProxy::applicationWillEnterForeground()
 {
     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
+    RELEASE_LOG_IF_ALLOWED(ViewState, "applicationWillEnterForeground: isSuspendedUnderLock? %d", isSuspendedUnderLock);
+
     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(isSuspendedUnderLock), m_webPageID);
     m_process->send(Messages::WebPage::HardwareKeyboardAvailabilityChanged(isInHardwareKeyboardMode()), m_webPageID);
 }
@@ -1467,4 +1473,6 @@ WebContentMode WebPageProxy::effectiveContentModeAfterAdjustingPolicies(API::Web
 
 } // namespace WebKit
 
+#undef RELEASE_LOG_IF_ALLOWED
+
 #endif // PLATFORM(IOS_FAMILY)