RESOLVED FIXED 217228
Multiple calls to suspend media playback for the same page may result in resuming media playback too soon
https://bugs.webkit.org/show_bug.cgi?id=217228
Summary Multiple calls to suspend media playback for the same page may result in resu...
Kate Cheney
Reported 2020-10-02 08:59:23 PDT
It’s possible that multiple calls to _suspendAllMediaPlayback() could occur in the same WKWebView with different expectations of when to resume. The current implementation will resume after one call to _resumeAllMediaPlayback(). Instead, we should make sure that all calls to _suspendAllMediaPlayback() have been resolved with _resumeAllMediaPlayback() before actually resuming media content. Adding a counter to track how many calls to suspend have been made and only resuming when the counter is at 0 is a potential solution.
Attachments
Patch (9.10 KB, patch)
2020-10-02 09:20 PDT, Kate Cheney
no flags
Patch (9.50 KB, patch)
2020-10-02 13:58 PDT, Kate Cheney
no flags
Patch for landing (9.44 KB, patch)
2020-10-02 15:36 PDT, Kate Cheney
no flags
Kate Cheney
Comment 1 2020-10-02 08:59:40 PDT
Kate Cheney
Comment 2 2020-10-02 09:20:49 PDT
Kate Cheney
Comment 3 2020-10-02 13:58:03 PDT
Eric Carlson
Comment 4 2020-10-02 15:10:53 PDT
Comment on attachment 410366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=410366&action=review > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1897 > + return (NSInteger *)(static_cast<long>(_page->suspendMediaPlaybackCounter())); can you `return @(_page->suspendMediaPlaybackCounter())` ? > Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:345 > +- (NSInteger *)_suspendMediaPlaybackCounter WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); This should probably be WKWebViewPrivateForTesting.h > Source/WebKit/UIProcess/WebPageProxy.cpp:6045 > + if (!m_mediaPlaybackIsSuspended || m_suspendMediaPlaybackCounter > 0) if (!m_mediaPlaybackIsSuspended || m_suspendMediaPlaybackCounter) > Tools/TestWebKitAPI/Tests/WebKitCocoa/StopSuspendResumeAllMedia.mm:115 > + auto counter = [webView _suspendMediaPlaybackCounter]; > + if (counter >= (NSInteger *)(static_cast<long>(2))) if ([webView _suspendMediaPlaybackCounter] <= @(2)) > Tools/TestWebKitAPI/Tests/WebKitCocoa/StopSuspendResumeAllMedia.mm:123 > + auto counter = [webView _suspendMediaPlaybackCounter]; > + if (counter <= (NSInteger *)(static_cast<long>(1))) if ([webView _suspendMediaPlaybackCounter] <= @(1))
Kate Cheney
Comment 5 2020-10-02 15:32:15 PDT
(In reply to Eric Carlson from comment #4) > Comment on attachment 410366 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=410366&action=review > Thanks for the review! > > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1897 > > + return (NSInteger *)(static_cast<long>(_page->suspendMediaPlaybackCounter())); > > can you `return @(_page->suspendMediaPlaybackCounter())` ? > Yep, will change. > > Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:345 > > +- (NSInteger *)_suspendMediaPlaybackCounter WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); > > This should probably be WKWebViewPrivateForTesting.h > Cool, didn't know about this, I'll move it. > > Source/WebKit/UIProcess/WebPageProxy.cpp:6045 > > + if (!m_mediaPlaybackIsSuspended || m_suspendMediaPlaybackCounter > 0) > > if (!m_mediaPlaybackIsSuspended || m_suspendMediaPlaybackCounter) > Will fix. > > Tools/TestWebKitAPI/Tests/WebKitCocoa/StopSuspendResumeAllMedia.mm:115 > > + auto counter = [webView _suspendMediaPlaybackCounter]; > > + if (counter >= (NSInteger *)(static_cast<long>(2))) > > if ([webView _suspendMediaPlaybackCounter] <= @(2)) > > > Tools/TestWebKitAPI/Tests/WebKitCocoa/StopSuspendResumeAllMedia.mm:123 > > + auto counter = [webView _suspendMediaPlaybackCounter]; > > + if (counter <= (NSInteger *)(static_cast<long>(1))) > > if ([webView _suspendMediaPlaybackCounter] <= @(1)) I got 'error: direct comparison of a numeric literal has undefined behavior' with this change, but I can change it to if ([webView _suspendMediaPlaybackCounter].intValue <= 1) to avoid the casting.
Kate Cheney
Comment 6 2020-10-02 15:36:19 PDT
Created attachment 410382 [details] Patch for landing
EWS
Comment 7 2020-10-02 16:15:17 PDT
Committed r267899: <https://trac.webkit.org/changeset/267899> All reviewed patches have been landed. Closing bug and clearing flags on attachment 410382 [details].
Radar WebKit Bug Importer
Comment 8 2020-10-02 16:16:52 PDT
Note You need to log in before you can comment on or make changes to this bug.