Title: [236860] trunk/Source
Revision
236860
Author
[email protected]
Date
2018-10-04 16:52:39 -0700 (Thu, 04 Oct 2018)

Log Message

Unify implementation in VideoFullscreenInterfaceAVKit
https://bugs.webkit.org/show_bug.cgi?id=190091
rdar://problem/44734523

Patch by Jeremy Jones <[email protected]> on 2018-10-04
Reviewed by Jer Noble.

Source/WebCore:

No new tests because no behavior change.

Unified code in VideoFullscreenInterfaceAVKit now that new code path is proven and include
any changes that had been made in the old path.

* platform/ios/VideoFullscreenInterfaceAVKit.h:
* platform/ios/VideoFullscreenInterfaceAVKit.mm:
(-[WebAVPlayerViewControllerDelegate playerViewControllerShouldStartPictureInPictureFromInlineWhenEnteringBackground:]):
(VideoFullscreenInterfaceAVKit::preparedToExitFullscreen):
(VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
* platform/ios/WebVideoFullscreenControllerAVKit.mm:
(VideoFullscreenControllerContext::requestUpdateInlineRect):
(VideoFullscreenControllerContext::requestVideoContentLayer):
(VideoFullscreenControllerContext::returnVideoContentLayer):
(VideoFullscreenControllerContext::didSetupFullscreen):
(VideoFullscreenControllerContext::didExitFullscreen):

Source/WebKit:

Unified code in VideoFullscreenInterfaceAVKit now that new code path is proven and include
any changes that had been made in the old path.

* UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
* WebProcess/cocoa/VideoFullscreenManager.mm:
(WebKit::VideoFullscreenManager::supportsVideoFullscreenStandby const):
(WebKit::VideoFullscreenManager::didSetupFullscreen):
(WebKit::VideoFullscreenManager::didExitFullscreen):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (236859 => 236860)


--- trunk/Source/WebCore/ChangeLog	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebCore/ChangeLog	2018-10-04 23:52:39 UTC (rev 236860)
@@ -1,3 +1,28 @@
+2018-10-04  Jeremy Jones  <[email protected]>
+
+        Unify implementation in VideoFullscreenInterfaceAVKit
+        https://bugs.webkit.org/show_bug.cgi?id=190091
+        rdar://problem/44734523
+
+        Reviewed by Jer Noble.
+
+        No new tests because no behavior change.
+
+        Unified code in VideoFullscreenInterfaceAVKit now that new code path is proven and include
+        any changes that had been made in the old path.
+
+        * platform/ios/VideoFullscreenInterfaceAVKit.h:
+        * platform/ios/VideoFullscreenInterfaceAVKit.mm:
+        (-[WebAVPlayerViewControllerDelegate playerViewControllerShouldStartPictureInPictureFromInlineWhenEnteringBackground:]):
+        (VideoFullscreenInterfaceAVKit::preparedToExitFullscreen):
+        (VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
+        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
+        (VideoFullscreenControllerContext::requestUpdateInlineRect):
+        (VideoFullscreenControllerContext::requestVideoContentLayer):
+        (VideoFullscreenControllerContext::returnVideoContentLayer):
+        (VideoFullscreenControllerContext::didSetupFullscreen):
+        (VideoFullscreenControllerContext::didExitFullscreen):
+
 2018-10-04  Justin Michaud  <[email protected]>
 
         Bindings generator should support static attributes that are interfaces with CallWith

Modified: trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h (236859 => 236860)


--- trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2018-10-04 23:52:39 UTC (rev 236860)
@@ -86,10 +86,8 @@
     WEBCORE_EXPORT void requestHideAndExitFullscreen();
     WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
     WEBCORE_EXPORT void preparedToExitFullscreen();
-#if ENABLE(FULLSCREEN_API)
     WEBCORE_EXPORT void setHasVideoContentLayer(bool);
     WEBCORE_EXPORT void setInlineRect(const IntRect&, bool visible);
-#endif
 
     enum class ExitFullScreenReason {
         DoneButtonTapped,
@@ -127,9 +125,7 @@
     };
 
     Mode m_currentMode;
-#if ENABLE(FULLSCREEN_API)
     Mode m_targetMode;
-#endif
 
     VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
     bool shouldExitFullscreenWithReason(ExitFullScreenReason);
@@ -146,10 +142,8 @@
     void willStopPictureInPicture();
     void didStopPictureInPicture();
     void prepareForPictureInPictureStopWithCompletionHandler(void (^)(BOOL));
-#if ENABLE(FULLSCREEN_API)
     void exitFullscreenHandler(BOOL success, NSError *);
     void enterFullscreenHandler(BOOL success, NSError *);
-#endif
     bool isPlayingVideoInEnhancedFullscreen() const;
 
     WEBCORE_EXPORT void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
@@ -166,15 +160,10 @@
 protected:
     WEBCORE_EXPORT VideoFullscreenInterfaceAVKit(PlaybackSessionInterfaceAVKit&);
 
-#if ENABLE(FULLSCREEN_API)
     void doSetup();
     void finalizeSetup();
     void doExitFullscreen();
     void returnToStandby();
-#else
-    void enterPictureInPicture();
-    void enterFullscreenStandard();
-#endif
     void doEnterFullscreen();
     void watchdogTimerFired();
     WebAVPlayerController *playerController() const;
@@ -200,7 +189,6 @@
     bool m_shouldReturnToFullscreenWhenStoppingPiP { false };
     bool m_restoringFullscreenForPictureInPictureStop { false };
 
-#if ENABLE(FULLSCREEN_API)
     bool m_setupNeedsInlineRect { false };
     bool m_exitFullscreenNeedInlineRect { false };
 
@@ -225,13 +213,8 @@
     bool m_inlineIsVisible { false };
     bool m_standby { false };
     bool m_targetStandby { false };
-#else
-    bool m_exitRequested { false };
-    bool m_exitCompleted { false };
-    bool m_enterRequested { false };
-    bool m_shouldReturnToFullscreenAfterEnteringForeground { false };
+
     bool m_waitingForPreparedToExit { false };
-#endif
 };
 
 }

Modified: trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm (236859 => 236860)


--- trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm	2018-10-04 23:52:39 UTC (rev 236860)
@@ -187,13 +187,11 @@
     self.fullscreenInterface->prepareForPictureInPictureStopWithCompletionHandler(completionHandler);
 }
 
-#if ENABLE(FULLSCREEN_API)
 - (BOOL)playerViewControllerShouldStartPictureInPictureFromInlineWhenEnteringBackground:(AVPlayerViewController *)playerViewController
 {
     UNUSED_PARAM(playerViewController);
     return YES;
 }
-#endif
 
 @end
 
@@ -802,138 +800,6 @@
     return [m_playerViewController pictureInPictureWasStartedWhenEnteringBackground];
 }
 
-#if !ENABLE(FULLSCREEN_API)
-
-void VideoFullscreenInterfaceAVKit::applicationDidBecomeActive()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::applicationDidBecomeActive(%p)", this);
-    if (m_shouldReturnToFullscreenAfterEnteringForeground && m_videoFullscreenModel && m_videoFullscreenModel->isVisible()) {
-        [m_playerViewController stopPictureInPicture];
-        return;
-    }
-
-    // If we are both in PiP and in Fullscreen (i.e., via auto-PiP), and we did not stop fullscreen upon returning, it must be
-    // because the originating view is not visible, so hide the fullscreen window.
-    if (m_currentMode.hasFullscreen() && m_currentMode.hasPictureInPicture()) {
-        [[m_playerViewController view] layoutIfNeeded];
-        [m_playerViewController exitFullScreenAnimated:NO completionHandler:[protectedThis = makeRefPtr(this), this] (BOOL success, NSError* error) {
-            if (!success)
-                WTFLogAlways("-[AVPlayerViewController exitFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-
-            [m_window setHidden:YES];
-            [[m_playerViewController view] setHidden:YES];
-        }];
-    }
-}
-
-void VideoFullscreenInterfaceAVKit::setupFullscreen(UIView& videoView, const IntRect& initialRect, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode mode, bool allowsPictureInPicturePlayback, bool standby)
-{
-    ASSERT(mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::setupFullscreen(%p)", this);
-
-    m_allowsPictureInPicturePlayback = allowsPictureInPicturePlayback;
-    m_videoView = &videoView;
-    m_parentView = parentView;
-    m_parentWindow = parentView.window;
-
-    ASSERT_UNUSED(standby, !standby);
-    bool isInPictureInPictureMode = m_currentMode.hasPictureInPicture();
-    m_currentMode = mode;
-    m_inlineRect = initialRect;
-
-    [CATransaction begin];
-    [CATransaction setDisableActions:YES];
-
-#if !PLATFORM(WATCHOS)
-    if (![[m_parentView window] _isHostedInAnotherProcess]) {
-        if (!m_window)
-            m_window = adoptNS([allocUIWindowInstance() initWithFrame:[[getUIScreenClass() mainScreen] bounds]]);
-        [m_window setBackgroundColor:clearUIColor()];
-        if (!m_viewController)
-            m_viewController = adoptNS([allocUIViewControllerInstance() init]);
-        [[m_viewController view] setFrame:[m_window bounds]];
-        [m_viewController _setIgnoreAppSupportedOrientations:YES];
-        [m_window setRootViewController:m_viewController.get()];
-        [m_window setWindowLevel:getUITextEffectsBeneathStatusBarWindowLevel() + 1];
-        [m_window makeKeyAndVisible];
-    }
-#endif
-
-    if (!m_playerLayerView)
-        m_playerLayerView = adoptNS([allocWebAVPlayerLayerViewInstance() init]);
-    [m_playerLayerView setHidden:[playerController() isExternalPlaybackActive]];
-    [m_playerLayerView setBackgroundColor:clearUIColor()];
-
-    if (!isInPictureInPictureMode) {
-        [m_playerLayerView setVideoView:m_videoView.get()];
-        [m_playerLayerView addSubview:m_videoView.get()];
-    }
-
-    WebAVPlayerLayer *playerLayer = (WebAVPlayerLayer *)[m_playerLayerView playerLayer];
-    [playerLayer setModelVideoLayerFrame:CGRectMake(0, 0, m_inlineRect.width(), m_inlineRect.height())];
-    [playerLayer setVideoDimensions:[playerController() contentDimensions]];
-    playerLayer.fullscreenInterface = this;
-
-    if (!m_playerViewController)
-        m_playerViewController = adoptNS([[WebAVPlayerViewController alloc] initWithFullscreenInterface:this]);
-
-    [m_playerViewController setShowsPlaybackControls:NO];
-    [m_playerViewController setPlayerController:(AVPlayerController *)playerController()];
-    [m_playerViewController setDelegate:m_playerViewControllerDelegate.get()];
-    [m_playerViewController setAllowsPictureInPicturePlayback:m_allowsPictureInPicturePlayback];
-    [playerController() setPictureInPicturePossible:m_allowsPictureInPicturePlayback];
-
-#if PLATFORM(WATCHOS)
-    m_viewController = videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController);
-#endif
-
-    if (m_viewController) {
-        [m_viewController addChildViewController:m_playerViewController.get().avPlayerViewController];
-        [[m_viewController view] addSubview:[m_playerViewController view]];
-    } else
-        [m_parentView addSubview:[m_playerViewController view]];
-
-    [m_playerViewController view].frame = [m_parentView convertRect:m_inlineRect toView:[m_playerViewController view].superview];
-    [[m_playerViewController view] setBackgroundColor:clearUIColor()];
-    [[m_playerViewController view] setAutoresizingMask:(UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin)];
-
-    [[m_playerViewController view] setNeedsLayout];
-    [[m_playerViewController view] layoutIfNeeded];
-
-    [CATransaction commit];
-
-    dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
-        if (m_fullscreenChangeObserver)
-            m_fullscreenChangeObserver->didSetupFullscreen();
-    });
-}
-
-void VideoFullscreenInterfaceAVKit::enterFullscreen()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::enterFullscreen(%p) %d", this, mode());
-
-    m_exitCompleted = false;
-    m_exitRequested = false;
-    m_enterRequested = true;
-
-    if (m_currentMode.isPictureInPicture())
-        enterPictureInPicture();
-    else if (m_currentMode.isFullscreen())
-        enterFullscreenStandard();
-    else
-        ASSERT_NOT_REACHED();
-}
-
-void VideoFullscreenInterfaceAVKit::enterPictureInPicture()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::enterPictureInPicture(%p)", this);
-    
-    if ([m_playerViewController isPictureInPicturePossible])
-        [m_playerViewController startPictureInPicture];
-    else
-        failedToStartPictureInPicture();
-}
-
 static UIViewController *fallbackViewController(UIView *view)
 {
     for (UIView *currentView = view; currentView; currentView = currentView.superview) {
@@ -956,350 +822,6 @@
     return controller;
 }
 
-void VideoFullscreenInterfaceAVKit::enterFullscreenStandard()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::enterFullscreenStandard(%p)", this);
-
-    if ([m_playerViewController isPictureInPictureActive]) {
-        // NOTE: The fullscreen mode will be restored in prepareForPictureInPictureStopWithCompletionHandler().
-        m_shouldReturnToFullscreenWhenStoppingPiP = true;
-        [m_playerViewController stopPictureInPicture];
-        return;
-    }
-
-    [[m_playerViewController view] layoutIfNeeded];
-    [m_playerViewController enterFullScreenAnimated:YES completionHandler:[this, protectedThis = makeRefPtr(this)] (BOOL succeeded, NSError* error) {
-        if (!succeeded)
-            WTFLogAlways("-[AVPlayerViewController enterFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-
-        LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::enterFullscreenStandard - lambda(%p) - succeeded(%s)", this, boolString(succeeded));
-        [m_playerViewController setShowsPlaybackControls:YES];
-
-        if (m_fullscreenChangeObserver)
-            m_fullscreenChangeObserver->didEnterFullscreen();
-    }];
-}
-
-void VideoFullscreenInterfaceAVKit::exitFullscreen(const IntRect& finalRect)
-{
-    m_watchdogTimer.stop();
-
-    m_exitRequested = true;
-    if (m_exitCompleted) {
-        if (m_fullscreenChangeObserver)
-            m_fullscreenChangeObserver->didExitFullscreen();
-        return;
-    }
-
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::exitFullscreen(%p)", this);
-    [m_playerViewController setShowsPlaybackControls:NO];
-    
-    [m_playerViewController view].frame = [m_parentView convertRect:finalRect toView:[m_playerViewController view].superview];
-
-    WebAVPlayerLayer *playerLayer = (WebAVPlayerLayer *)[m_playerLayerView playerLayer];
-    if ([playerLayer videoGravity] != getAVLayerVideoGravityResizeAspect())
-        [playerLayer setVideoGravity:getAVLayerVideoGravityResizeAspect()];
-
-    [[m_playerViewController view] layoutIfNeeded];
-    if (m_currentMode.isPictureInPicture()) {
-        m_shouldReturnToFullscreenWhenStoppingPiP = false;
-        [m_window setHidden:NO];
-        [m_playerViewController stopPictureInPicture];
-    } else if (m_currentMode.hasPictureInPicture() && m_currentMode.hasFullscreen()) {
-        [m_playerViewController exitFullScreenAnimated:NO completionHandler:[protectedThis = makeRefPtr(this), this] (BOOL success, NSError* error) {
-            if (!success)
-                WTFLogAlways("-[AVPlayerViewController exitFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-
-            clearMode(HTMLMediaElementEnums::VideoFullscreenModeStandard);
-            [m_window setHidden:NO];
-            [m_playerViewController stopPictureInPicture];
-        }];
-    } else if (m_currentMode.isFullscreen()) {
-        [m_playerViewController exitFullScreenAnimated:YES completionHandler:[protectedThis = makeRefPtr(this), this] (BOOL success, NSError* error) mutable {
-            if (!success)
-                WTFLogAlways("-[AVPlayerViewController exitFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-
-            m_exitCompleted = true;
-
-            [CATransaction begin];
-            [CATransaction setDisableActions:YES];
-            [m_playerLayerView setBackgroundColor:clearUIColor()];
-            [[m_playerViewController view] setBackgroundColor:clearUIColor()];
-            [CATransaction commit];
-
-            dispatch_async(dispatch_get_main_queue(), [protectedThis = WTFMove(protectedThis), this]() {
-                if (m_fullscreenChangeObserver)
-                    m_fullscreenChangeObserver->didExitFullscreen();
-            });
-        }];
-    };
-}
-
-void VideoFullscreenInterfaceAVKit::cleanupFullscreen()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::cleanupFullscreen(%p)", this);
-
-    if (m_window) {
-        [m_window setHidden:YES];
-        [m_window setRootViewController:nil];
-    }
-    
-    [m_playerViewController setDelegate:nil];
-    [m_playerViewController setPlayerController:nil];
-    
-    if (m_currentMode.hasPictureInPicture())
-        [m_playerViewController stopPictureInPicture];
-    if (m_currentMode.hasFullscreen()) {
-        [[m_playerViewController view] layoutIfNeeded];
-        [m_playerViewController exitFullScreenAnimated:NO completionHandler:[] (BOOL success, NSError* error) {
-            if (!success)
-                WTFLogAlways("-[AVPlayerViewController exitFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-        }];
-    }
-    
-    [[m_playerViewController view] removeFromSuperview];
-    if (m_viewController)
-        [m_playerViewController removeFromParentViewController];
-    
-    [m_playerLayerView removeFromSuperview];
-    [[m_viewController view] removeFromSuperview];
-
-    m_playerLayerView = nil;
-    m_playerViewController = nil;
-    m_window = nil;
-    m_videoView = nil;
-    m_parentView = nil;
-    m_parentWindow = nil;
-    
-    if (m_fullscreenChangeObserver)
-        m_fullscreenChangeObserver->didCleanupFullscreen();
-
-    m_enterRequested = false;
-}
-
-void VideoFullscreenInterfaceAVKit::invalidate()
-{
-    m_videoFullscreenModel = nil;
-    m_fullscreenChangeObserver = nil;
-    
-    cleanupFullscreen();
-}
-
-void VideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen()
-{
-    if (!m_enterRequested)
-        return;
-    
-    if (m_currentMode.hasPictureInPicture())
-        return;
-    
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen(%p)", this);
-
-    [m_window setHidden:YES];
-    [[m_playerViewController view] setHidden:YES];
-
-    if (playbackSessionModel() && m_videoFullscreenModel && !m_exitRequested) {
-        playbackSessionModel()->pause();
-        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
-    }
-}
-
-void VideoFullscreenInterfaceAVKit::preparedToReturnToInline(bool visible, const IntRect& inlineRect)
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::preparedToReturnToInline(%p) - visible(%s)", this, boolString(visible));
-    if (m_prepareToInlineCallback) {
-        [m_playerViewController view].frame = [m_parentView convertRect:inlineRect toView:[m_playerViewController view].superview];
-        WTF::Function<void(bool)> callback = WTFMove(m_prepareToInlineCallback);
-        callback(visible);
-    }
-}
-
-void VideoFullscreenInterfaceAVKit::preparedToExitFullscreen()
-{
-    if (!m_waitingForPreparedToExit)
-        return;
-
-    m_waitingForPreparedToExit = false;
-    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, true);
-}
-
-bool VideoFullscreenInterfaceAVKit::mayAutomaticallyShowVideoPictureInPicture() const
-{
-    return [playerController() isPlaying] && m_currentMode.isFullscreen() && supportsPictureInPicture();
-}
-
-void VideoFullscreenInterfaceAVKit::fullscreenMayReturnToInline(WTF::Function<void(bool)>&& callback)
-{
-    m_prepareToInlineCallback = WTFMove(callback);
-    if (m_fullscreenChangeObserver)
-        m_fullscreenChangeObserver->fullscreenMayReturnToInline();
-}
-
-void VideoFullscreenInterfaceAVKit::willStartPictureInPicture()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::willStartPictureInPicture(%p)", this);
-    setMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->willEnterPictureInPicture();
-}
-
-void VideoFullscreenInterfaceAVKit::didStartPictureInPicture()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::didStartPictureInPicture(%p)", this);
-    m_shouldReturnToFullscreenAfterEnteringForeground = pictureInPictureWasStartedWhenEnteringBackground();
-    [m_playerViewController setShowsPlaybackControls:YES];
-
-    if (m_currentMode.hasFullscreen()) {
-        if (!pictureInPictureWasStartedWhenEnteringBackground()) {
-            [[m_playerViewController view] layoutIfNeeded];
-            [m_playerViewController exitFullScreenAnimated:YES completionHandler:[protectedThis = makeRefPtr(this), this] (BOOL success, NSError* error) {
-                if (!success)
-                    WTFLogAlways("-[AVPlayerViewController exitFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-                [m_window setHidden:YES];
-                [[m_playerViewController view] setHidden:YES];
-            }];
-        }
-    } else {
-        [m_window setHidden:YES];
-        [[m_playerViewController view] setHidden:YES];
-    }
-
-    if (m_fullscreenChangeObserver)
-        m_fullscreenChangeObserver->didEnterFullscreen();
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->didEnterPictureInPicture();
-}
-
-void VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture(%p)", this);
-    [m_playerViewController setShowsPlaybackControls:YES];
-
-    if (m_currentMode.hasFullscreen())
-        return;
-
-    m_exitCompleted = true;
-
-    if (m_fullscreenChangeObserver)
-        m_fullscreenChangeObserver->didEnterFullscreen();
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->failedToEnterPictureInPicture();
-
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
-}
-
-void VideoFullscreenInterfaceAVKit::willStopPictureInPicture()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::willStopPictureInPicture(%p)", this);
-
-    m_shouldReturnToFullscreenWhenStoppingPiP = false;
-    m_shouldReturnToFullscreenAfterEnteringForeground = false;
-
-    if (m_currentMode.hasFullscreen() || m_restoringFullscreenForPictureInPictureStop)
-        return;
-
-    [m_window setHidden:NO];
-    [[m_playerViewController view] setHidden:NO];
-
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->willExitPictureInPicture();
-}
-
-void VideoFullscreenInterfaceAVKit::didStopPictureInPicture()
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::didStopPictureInPicture(%p)", this);
-
-    if (m_currentMode.hasFullscreen() || m_restoringFullscreenForPictureInPictureStop) {
-        clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
-        [m_playerViewController setShowsPlaybackControls:YES];
-
-        return;
-    }
-
-    m_exitCompleted = true;
-
-    [m_playerLayerView setBackgroundColor:clearUIColor()];
-    [[m_playerViewController view] setBackgroundColor:clearUIColor()];
-
-    clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
-
-    if (m_fullscreenChangeObserver)
-        m_fullscreenChangeObserver->didExitFullscreen();
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel->didExitPictureInPicture();
-}
-
-void VideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler(void (^completionHandler)(BOOL restored))
-{
-    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler(%p)", this);
-    if (m_shouldReturnToFullscreenWhenStoppingPiP || m_shouldReturnToFullscreenAfterEnteringForeground) {
-
-        m_shouldReturnToFullscreenAfterEnteringForeground = false;
-        m_shouldReturnToFullscreenWhenStoppingPiP = false;
-        m_restoringFullscreenForPictureInPictureStop = true;
-
-        [m_window setHidden:NO];
-        [[m_playerViewController view] setHidden:NO];
-
-        [[m_playerViewController view] layoutIfNeeded];
-        [m_playerViewController enterFullScreenAnimated:YES completionHandler:^(BOOL succeeded, NSError *error) {
-            if (!succeeded)
-                WTFLogAlways("-[AVPlayerViewController enterFullScreenAnimated:completionHandler:] failed with error %s", [[error localizedDescription] UTF8String]);
-
-            m_restoringFullscreenForPictureInPictureStop = false;
-            setMode(HTMLMediaElementEnums::VideoFullscreenModeStandard);
-            completionHandler(succeeded);
-            if (m_fullscreenChangeObserver)
-                m_fullscreenChangeObserver->didEnterFullscreen();
-        }];
-        return;
-    }
-
-    fullscreenMayReturnToInline([protectedThis = makeRefPtr(this), strongCompletionHandler = adoptNS([completionHandler copy])](bool restored)  {
-        LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler lambda(%p) - restored(%s)", protectedThis.get(), boolString(restored));
-        ((void (^)(BOOL))strongCompletionHandler.get())(restored);
-    });
-}
-
-bool VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason(VideoFullscreenInterfaceAVKit::ExitFullScreenReason reason)
-{
-    if (!m_videoFullscreenModel)
-        return true;
-
-    if (reason == ExitFullScreenReason::PictureInPictureStarted) {
-        if (pictureInPictureWasStartedWhenEnteringBackground())
-            return false;
-
-        m_shouldReturnToFullscreenWhenStoppingPiP = m_currentMode.hasFullscreen();
-        clearMode(HTMLMediaElementEnums::VideoFullscreenModeStandard);
-        return true;
-    }
-
-    if (playbackSessionModel() && (reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::RemoteControlStopEventReceived))
-        playbackSessionModel()->pause();
-
-    if (!m_watchdogTimer.isActive() && !ignoreWatchdogForDebugging)
-        m_watchdogTimer.startOneShot(defaultWatchdogTimerInterval);
-
-#if PLATFORM(WATCHOS)
-    if (m_fullscreenChangeObserver) {
-        m_waitingForPreparedToExit = true;
-        m_fullscreenChangeObserver->willExitFullscreen();
-        return false;
-    }
-#endif
-
-    BOOL finished = reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::PinchGestureHandled;
-    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished);
-
-    return false;
-}
-
-#else // ENABLE(FULLSCREEN_API)
-
 void VideoFullscreenInterfaceAVKit::applicationDidBecomeActive()
 {
     LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::applicationDidBecomeActive(%p)", this);
@@ -1421,6 +943,13 @@
 
 void VideoFullscreenInterfaceAVKit::preparedToExitFullscreen()
 {
+#if PLATFORM(WATCHOS)
+    if (!m_waitingForPreparedToExit)
+        return;
+
+    m_waitingForPreparedToExit = false;
+    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, true);
+#endif
 }
 
 bool VideoFullscreenInterfaceAVKit::mayAutomaticallyShowVideoPictureInPicture() const
@@ -1576,12 +1105,20 @@
     if (playbackSessionModel() && (reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::RemoteControlStopEventReceived))
         playbackSessionModel()->pause();
 
+    if (!m_watchdogTimer.isActive() && !ignoreWatchdogForDebugging)
+        m_watchdogTimer.startOneShot(defaultWatchdogTimerInterval);
+
+#if PLATFORM(WATCHOS)
+    if (m_fullscreenChangeObserver) {
+        m_waitingForPreparedToExit = true;
+        m_fullscreenChangeObserver->willExitFullscreen();
+        return false;
+    }
+#endif
+    
     BOOL finished = reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::PinchGestureHandled;
     m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished);
 
-    if (!m_watchdogTimer.isActive() && !ignoreWatchdogForDebugging)
-        m_watchdogTimer.startOneShot(defaultWatchdogTimerInterval);
-
     return false;
 }
 
@@ -1876,8 +1413,6 @@
     [[m_playerViewController view] setHidden:YES];
 }
 
-#endif // ENABLE(FULLSCREEN_API)
-
 NO_RETURN_DUE_TO_ASSERT void VideoFullscreenInterfaceAVKit::watchdogTimerFired()
 {
     LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::watchdogTimerFired(%p) - no exit fullscreen response in %gs; forcing fullscreen hidden.", this, defaultWatchdogTimerInterval.value());

Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm (236859 => 236860)


--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm	2018-10-04 23:52:39 UTC (rev 236860)
@@ -224,7 +224,7 @@
 
 void VideoFullscreenControllerContext::requestUpdateInlineRect()
 {
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     ASSERT(isUIThread());
     WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable {
         IntRect clientRect = elementRectInWindow(m_videoElement.get());
@@ -239,7 +239,7 @@
 
 void VideoFullscreenControllerContext::requestVideoContentLayer()
 {
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     ASSERT(isUIThread());
     WebThreadRun([protectedThis = makeRefPtr(this), this, videoFullscreenLayer = retainPtr([m_videoFullscreenView layer])] () mutable {
         [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparent)];
@@ -256,7 +256,7 @@
 
 void VideoFullscreenControllerContext::returnVideoContentLayer()
 {
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     ASSERT(isUIThread());
     WebThreadRun([protectedThis = makeRefPtr(this), this, videoFullscreenLayer = retainPtr([m_videoFullscreenView layer])] () mutable {
         [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparent)];
@@ -274,7 +274,7 @@
 void VideoFullscreenControllerContext::didSetupFullscreen()
 {
     ASSERT(isUIThread());
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
         m_interface->enterFullscreen();
     });
@@ -303,7 +303,7 @@
 void VideoFullscreenControllerContext::didExitFullscreen()
 {
     ASSERT(isUIThread());
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
         m_interface->cleanupFullscreen();
     });

Modified: trunk/Source/WebKit/ChangeLog (236859 => 236860)


--- trunk/Source/WebKit/ChangeLog	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebKit/ChangeLog	2018-10-04 23:52:39 UTC (rev 236860)
@@ -1,3 +1,20 @@
+2018-10-04  Jeremy Jones  <[email protected]>
+
+        Unify implementation in VideoFullscreenInterfaceAVKit
+        https://bugs.webkit.org/show_bug.cgi?id=190091
+        rdar://problem/44734523
+
+        Reviewed by Jer Noble.
+
+        Unified code in VideoFullscreenInterfaceAVKit now that new code path is proven and include
+        any changes that had been made in the old path.
+
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
+        * WebProcess/cocoa/VideoFullscreenManager.mm:
+        (WebKit::VideoFullscreenManager::supportsVideoFullscreenStandby const):
+        (WebKit::VideoFullscreenManager::didSetupFullscreen):
+        (WebKit::VideoFullscreenManager::didExitFullscreen):
+
 2018-10-04  Matt Lewis  <[email protected]>
 
         Unreviewed, rolling out r236730.

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm (236859 => 236860)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2018-10-04 23:52:39 UTC (rev 236860)
@@ -538,7 +538,7 @@
 }
 #endif
 
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
 
 void VideoFullscreenManagerProxy::setInlineRect(uint64_t contextId, const WebCore::IntRect& inlineRect, bool visible)
 {

Modified: trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm (236859 => 236860)


--- trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2018-10-04 23:31:06 UTC (rev 236859)
+++ trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2018-10-04 23:52:39 UTC (rev 236860)
@@ -233,7 +233,7 @@
 
 bool VideoFullscreenManager::supportsVideoFullscreenStandby() const
 {
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     return true;
 #else
     return false;
@@ -411,7 +411,7 @@
     RefPtr<VideoFullscreenInterfaceContext> interface;
     std::tie(model, interface) = ensureModelAndInterface(contextId);
 
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this, contextId] {
         if (protectedThis->m_page)
             m_page->send(Messages::VideoFullscreenManagerProxy::EnterFullscreen(contextId), protectedThis->m_page->pageID());
@@ -484,7 +484,7 @@
     RefPtr<VideoFullscreenInterfaceContext> interface;
     std::tie(model, interface) = ensureModelAndInterface(contextId);
 
-#if PLATFORM(IOS) && ENABLE(FULLSCREEN_API)
+#if PLATFORM(IOS)
     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), contextId, interface] {
         if (protectedThis->m_page)
             protectedThis->m_page->send(Messages::VideoFullscreenManagerProxy::CleanupFullscreen(contextId), protectedThis->m_page->pageID());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to