Bug 216287

Summary: Returning to element fullscreen from PiP is not stable under stress tests
Product: WebKit Reporter: Peng Liu <peng.liu6>
Component: MediaAssignee: Peng Liu <peng.liu6>
Status: RESOLVED FIXED    
Severity: Normal CC: eric.carlson, ews-watchlist, glenn, jer.noble, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=216571
Bug Depends on:    
Bug Blocks: 216051, 216426    
Attachments:
Description Flags
Patch
none
Fix an api test failure on Mac
none
Update the patch based on Jer's comments none

Description Peng Liu 2020-09-08 15:31:35 PDT
Return to element fullscreen from PiP is not stable under stress tests
Comment 1 Radar WebKit Bug Importer 2020-09-08 15:32:24 PDT
<rdar://problem/68533983>
Comment 2 Peng Liu 2020-09-08 16:39:47 PDT
Created attachment 408284 [details]
Patch
Comment 3 Peng Liu 2020-09-10 21:34:41 PDT
Created attachment 408510 [details]
Fix an api test failure on Mac
Comment 4 Jer Noble 2020-09-14 10:47:38 PDT
Comment on attachment 408510 [details]
Fix an api test failure on Mac

View in context: https://bugs.webkit.org/attachment.cgi?id=408510&action=review

> Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:700
> +                videoFullscreenManager->setClient(&_videoFullscreenManagerProxyClient);

Here.

> Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:851
> +                videoFullscreenManager->setClient(nullptr);

And here.

> Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:932
> +    if (![self isFullScreen]) {
> +        if (auto* videoFullscreenManager = self._videoFullscreenManager)
> +            videoFullscreenManager->setClient(nullptr);
> +    }

And here.

> Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm:655
> +    if (auto* videoFullscreenManager = self._videoFullscreenManager)
> +        videoFullscreenManager->setClient(nullptr);

And here.

> Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm:691
> +    if (auto* videoFullscreenManager = self._videoFullscreenManager)
> +        videoFullscreenManager->setClient(&_videoFullscreenManagerProxyClient);

And here.

What will happen if some other piece of code reset videoFullScreenManager's client, perhaps by requesting fullscreen before this animation is complete?  VideoFullscreenManager is a singleton, so would that cause us to get into a bad state in the manager's state machine?
Comment 5 Peng Liu 2020-09-14 11:24:39 PDT
Comment on attachment 408510 [details]
Fix an api test failure on Mac

View in context: https://bugs.webkit.org/attachment.cgi?id=408510&action=review

>> Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:851
>> +                videoFullscreenManager->setClient(nullptr);
> 
> And here.

I guess it is better to move this section out of the _repaintCallback?

>> Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm:691
>> +        videoFullscreenManager->setClient(&_videoFullscreenManagerProxyClient);
> 
> And here.
> 
> What will happen if some other piece of code reset videoFullScreenManager's client, perhaps by requesting fullscreen before this animation is complete?  VideoFullscreenManager is a singleton, so would that cause us to get into a bad state in the manager's state machine?

FullscreenManager has the logic to ignore a new fullscreen mode changing request if the current request is not completed yet. Also, WKFullScreenWindowControllerVideoFullscreenManagerProxyClient is the only one client of VideoFullscreenManagerProxy, and only WKFullScreenWindowController calls VideoFullscreenManagerProxy::setClient(). So I believe the code is safe.
Comment 6 Jer Noble 2020-09-14 12:02:29 PDT
(In reply to Peng Liu from comment #5)
> Comment on attachment 408510 [details]
> Fix an api test failure on Mac
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=408510&action=review
> 
> >> Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:851
> >> +                videoFullscreenManager->setClient(nullptr);
> > 
> > And here.
> 
> I guess it is better to move this section out of the _repaintCallback?
> 
> >> Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm:691
> >> +        videoFullscreenManager->setClient(&_videoFullscreenManagerProxyClient);
> > 
> > And here.
> > 
> > What will happen if some other piece of code reset videoFullScreenManager's client, perhaps by requesting fullscreen before this animation is complete?  VideoFullscreenManager is a singleton, so would that cause us to get into a bad state in the manager's state machine?
> 
> FullscreenManager has the logic to ignore a new fullscreen mode changing
> request if the current request is not completed yet. Also,
> WKFullScreenWindowControllerVideoFullscreenManagerProxyClient is the only
> one client of VideoFullscreenManagerProxy, and only
> WKFullScreenWindowController calls VideoFullscreenManagerProxy::setClient().
> So I believe the code is safe.

Might be worthwhile to put some ASSERT() statements around the setClient() calls, to catch this case should things ever go wrong.  I.e., assert that client is NULL when set, and that it's `this` when cleared.
Comment 7 Peng Liu 2020-09-14 13:27:40 PDT
Created attachment 408739 [details]
Update the patch based on Jer's comments
Comment 8 Peng Liu 2020-09-14 13:28:57 PDT
Comment on attachment 408510 [details]
Fix an api test failure on Mac

View in context: https://bugs.webkit.org/attachment.cgi?id=408510&action=review

>>>> Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:851
>>>> +                videoFullscreenManager->setClient(nullptr);
>>> 
>>> And here.
>> 
>> I guess it is better to move this section out of the _repaintCallback?
> 
> Might be worthwhile to put some ASSERT() statements around the setClient() calls, to catch this case should things ever go wrong.  I.e., assert that client is NULL when set, and that it's `this` when cleared.

Good point!
Comment 9 EWS 2020-09-14 15:39:55 PDT
Committed r267053: <https://trac.webkit.org/changeset/267053>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408739 [details].