Handle timeout of prepareForPictureInPictureStopWithCompletionHandler.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Jun 2017 22:56:44 +0000 (22:56 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Jun 2017 22:56:44 +0000 (22:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173462
rdar://problem/32128170

Patch by Jeremy Jones <jeremyj@apple.com> on 2017-06-16
Reviewed by Jer Noble.

No new tests because no effect on the DOM.

If WebVideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler doesn't respond fast enough,
the caller will timeout and call will/didStopPictureInPicture.

This is getting fullscreen state confused.

This change keeps state consistent by handling will/didStopPictureInPicture possibly being called before
prepareForPictureInPictureStopWithCompletionHandler calls its callback.

* platform/ios/WebVideoFullscreenInterfaceAVKit.h:
* platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
(WebVideoFullscreenInterfaceAVKit::willStopPictureInPicture):
(WebVideoFullscreenInterfaceAVKit::didStopPictureInPicture):
(WebVideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler):
(WebVideoFullscreenInterfaceAVKit::watchdogTimerFired):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h
Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm

index 4284d79..679072e 100644 (file)
@@ -1,3 +1,28 @@
+2017-06-16  Jeremy Jones  <jeremyj@apple.com>
+
+        Handle timeout of prepareForPictureInPictureStopWithCompletionHandler.
+        https://bugs.webkit.org/show_bug.cgi?id=173462
+        rdar://problem/32128170
+
+        Reviewed by Jer Noble.
+
+        No new tests because no effect on the DOM.
+
+        If WebVideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler doesn't respond fast enough,
+        the caller will timeout and call will/didStopPictureInPicture.
+
+        This is getting fullscreen state confused.
+
+        This change keeps state consistent by handling will/didStopPictureInPicture possibly being called before
+        prepareForPictureInPictureStopWithCompletionHandler calls its callback.
+
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
+        (WebVideoFullscreenInterfaceAVKit::willStopPictureInPicture):
+        (WebVideoFullscreenInterfaceAVKit::didStopPictureInPicture):
+        (WebVideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler):
+        (WebVideoFullscreenInterfaceAVKit::watchdogTimerFired):
+
 2017-06-16  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Make builds faster after r218371
index edafdc9..8d3c473 100644 (file)
@@ -147,6 +147,7 @@ protected:
     bool m_wirelessVideoPlaybackDisabled { true };
     bool m_shouldReturnToFullscreenWhenStoppingPiP { false };
     bool m_shouldReturnToFullscreenAfterEnteringForeground { false };
+    bool m_restoringFullscreenForPictureInPictureStop { false };
 
     void doEnterFullscreen();
 };
index c1f1975..6babc1e 100644 (file)
@@ -909,8 +909,11 @@ void WebVideoFullscreenInterfaceAVKit::failedToStartPictureInPicture()
 
 void WebVideoFullscreenInterfaceAVKit::willStopPictureInPicture()
 {
+    m_shouldReturnToFullscreenWhenStoppingPiP = false;
+    m_shouldReturnToFullscreenAfterEnteringForeground = false;
+
     LOG(Fullscreen, "WebVideoFullscreenInterfaceAVKit::willStopPictureInPicture(%p)", this);
-    if (hasMode(HTMLMediaElementEnums::VideoFullscreenModeStandard))
+    if (hasMode(HTMLMediaElementEnums::VideoFullscreenModeStandard) || m_restoringFullscreenForPictureInPictureStop)
         return;
 
     [m_window setHidden:NO];
@@ -923,13 +926,10 @@ void WebVideoFullscreenInterfaceAVKit::willStopPictureInPicture()
 void WebVideoFullscreenInterfaceAVKit::didStopPictureInPicture()
 {
     LOG(Fullscreen, "WebVideoFullscreenInterfaceAVKit::didStopPictureInPicture(%p)", this);
-    if (hasMode(HTMLMediaElementEnums::VideoFullscreenModeStandard)) {
+    if (hasMode(HTMLMediaElementEnums::VideoFullscreenModeStandard) || m_restoringFullscreenForPictureInPictureStop) {
         // ASSUMPTION: we are exiting pip because we are entering fullscreen
         clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
         [m_playerViewController setShowsPlaybackControls:YES];
-
-        if (m_fullscreenChangeObserver)
-            m_fullscreenChangeObserver->didEnterFullscreen();
         return;
     }
 
@@ -950,14 +950,17 @@ void WebVideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithComplet
     if (m_shouldReturnToFullscreenWhenStoppingPiP || m_shouldReturnToFullscreenAfterEnteringForeground) {
         m_shouldReturnToFullscreenWhenStoppingPiP = false;
         m_shouldReturnToFullscreenAfterEnteringForeground = false;
+        m_restoringFullscreenForPictureInPictureStop = true;
 
-        // ASSUMPTION: we are exiting pip because we are entering fullscreen
         [m_window setHidden:NO];
         [[m_playerViewController view] setHidden:NO];
 
         [m_playerViewController enterFullScreenAnimated:YES completionHandler:^(BOOL success, NSError*) {
+            m_restoringFullscreenForPictureInPictureStop = false;
             setMode(HTMLMediaElementEnums::VideoFullscreenModeStandard);
             completionHandler(success);
+            if (m_fullscreenChangeObserver)
+                m_fullscreenChangeObserver->didEnterFullscreen();
         }];
         return;
     }
@@ -998,7 +1001,7 @@ bool WebVideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason(WebVideoFu
 
 NO_RETURN_DUE_TO_ASSERT void WebVideoFullscreenInterfaceAVKit::watchdogTimerFired()
 {
-    LOG(Fullscreen, "WebVideoFullscreenInterfaceAVKit::watchdogTimerFired(%p) - no exit fullscreen response in %gs; forcing fullscreen hidden.", this, defaultWatchdogTimerInterval);
+    LOG(Fullscreen, "WebVideoFullscreenInterfaceAVKit::watchdogTimerFired(%p) - no exit fullscreen response in %gs; forcing fullscreen hidden.", this, defaultWatchdogTimerInterval.value());
     ASSERT_NOT_REACHED();
     [m_window setHidden:YES];
     [[m_playerViewController view] setHidden:YES];