Changeset 271670 in webkit


Ignore:
Timestamp:
Jan 20, 2021 1:27:07 PM (18 months ago)
Author:
youenn@apple.com
Message:

Two pages in the same process should not be able to play media stream backed video elements at the same time
https://bugs.webkit.org/show_bug.cgi?id=220504

Reviewed by Eric Carlson.

Source/WebCore:

In case of ConcurrentPlaybackNotPermitted restrictions, we now make sure that media elements from different pages do not play concurrently.
We also make sure that a VideoAudio and Audio sessions can also pause each other so we update the check for same media session type accordingly.

Covered by API test.

  • platform/audio/PlatformMediaSession.cpp:

(WebCore::isPlayingAudio):
(WebCore::PlatformMediaSession::canPlayConcurrently const):

  • platform/audio/PlatformMediaSessionManager.cpp:

(WebCore::PlatformMediaSessionManager::sessionWillBeginPlayback):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKit/getUserMedia2.html: Added.
Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r271669 r271670  
     12021-01-20  Youenn Fablet  <youenn@apple.com>
     2
     3        Two pages in the same process should not be able to play media stream backed video elements at the same time
     4        https://bugs.webkit.org/show_bug.cgi?id=220504
     5
     6        Reviewed by Eric Carlson.
     7
     8        In case of ConcurrentPlaybackNotPermitted restrictions, we now make sure that media elements from different pages do not play concurrently.
     9        We also make sure that a VideoAudio and Audio sessions can also pause each other so we update the check for same media session type accordingly.
     10
     11        Covered by API test.
     12
     13        * platform/audio/PlatformMediaSession.cpp:
     14        (WebCore::isPlayingAudio):
     15        (WebCore::PlatformMediaSession::canPlayConcurrently const):
     16        * platform/audio/PlatformMediaSessionManager.cpp:
     17        (WebCore::PlatformMediaSessionManager::sessionWillBeginPlayback):
     18
    1192021-01-20  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp

    r267544 r271670  
    349349}
    350350
     351static inline bool isPlayingAudio(PlatformMediaSession::MediaType mediaType)
     352{
     353    return mediaType == MediaElementSession::MediaType::VideoAudio || mediaType == MediaElementSession::MediaType::Audio;
     354}
     355
    351356bool PlatformMediaSession::canPlayConcurrently(const PlatformMediaSession& otherSession) const
    352357{
     358    auto mediaType = this->mediaType();
     359    auto otherMediaType = otherSession.mediaType();
     360    if (otherMediaType != mediaType && (!isPlayingAudio(mediaType) || !isPlayingAudio(otherMediaType)))
     361        return true;
     362
     363    auto groupID = client().mediaSessionGroupIdentifier();
     364    auto otherGroupID = otherSession.client().mediaSessionGroupIdentifier();
     365    if (!groupID || !otherGroupID || groupID != otherGroupID)
     366        return false;
     367
    353368    return m_client.hasMediaStreamSource() && otherSession.m_client.hasMediaStreamSource();
    354369}
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp

    r271668 r271670  
    244244
    245245    if (restrictions & ConcurrentPlaybackNotPermitted) {
    246         forEachMatchingSession([&session, sessionType](auto& oneSession) {
     246        forEachMatchingSession([&session](auto& oneSession) {
    247247            return &oneSession != &session
    248                 && oneSession.mediaType() == sessionType
    249248                && oneSession.state() == PlatformMediaSession::Playing
    250249                && !oneSession.canPlayConcurrently(session);
  • trunk/Tools/ChangeLog

    r271650 r271670  
     12021-01-20  Youenn Fablet  <youenn@apple.com>
     2
     3        Two pages in the same process should not be able to play media stream backed video elements at the same time
     4        https://bugs.webkit.org/show_bug.cgi?id=220504
     5
     6        Reviewed by Eric Carlson.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:
     10        (TestWebKitAPI::TEST):
     11        * TestWebKitAPI/Tests/WebKit/getUserMedia2.html: Added.
     12
    1132021-01-20  Kate Cheney  <katherine_cheney@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r271656 r271670  
    5252                07492B3C1DF8B86600633DE1 /* enumerateMediaDevices.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 07492B391DF8ADA400633DE1 /* enumerateMediaDevices.html */; };
    5353                074994421EA5034B000DA44E /* getUserMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */; };
     54                074994521EA5034B000DA44E /* getUserMedia2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41BAF4E225AC9DB800D82F32 /* getUserMedia2.html */; };
    5455                074994421EA5034B000DA44F /* ondevicechange.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4A410F4D19AF7BEF002EBAB6 /* ondevicechange.html */; };
    5556                074994421EA5034B000DA45E /* getUserMediaAudioVideoCapture.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4A410F4D19AF7BEF002EBAC5 /* getUserMediaAudioVideoCapture.html */; };
     
    14441445                                41661C662355E85E00D33C27 /* getUserMedia-webaudio.html in Copy Resources */,
    14451446                                074994421EA5034B000DA44E /* getUserMedia.html in Copy Resources */,
     1447                                074994521EA5034B000DA44E /* getUserMedia2.html in Copy Resources */,
    14461448                                074994421EA5034B000DA45E /* getUserMediaAudioVideoCapture.html in Copy Resources */,
    14471449                                F46A095B1ED8A6E600D4AA55 /* gif-and-file-input.html in Copy Resources */,
     
    19851987                41882F0221010A70002FF288 /* ProcessPreWarming.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProcessPreWarming.mm; sourceTree = "<group>"; };
    19861988                41973B5C1AF22875006C7B36 /* SharedBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBuffer.cpp; sourceTree = "<group>"; };
     1989                41BAF4E225AC9DB800D82F32 /* getUserMedia2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = getUserMedia2.html; sourceTree = "<group>"; };
    19871990                44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorsTestIOS.mm; sourceTree = "<group>"; };
    19881991                442BBF681C91CAD90017087F /* RefLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefLogger.cpp; sourceTree = "<group>"; };
     
    43854388                                41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */,
    43864389                                4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */,
     4390                                41BAF4E225AC9DB800D82F32 /* getUserMedia2.html */,
    43874391                                4A410F4D19AF7BEF002EBAC5 /* getUserMediaAudioVideoCapture.html */,
    43884392                                BCBD372E125ABBE600D2C29F /* icon.png */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm

    r271640 r271670  
    302302}
    303303
     304TEST(WebKit, InterruptionBetweenSameProcessPages)
     305{
     306    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     307
     308#if PLATFORM(IOS_FAMILY)
     309    [configuration setAllowsInlineMediaPlayback:YES];
     310#endif
     311
     312    auto preferences = [configuration preferences];
     313    preferences._mediaCaptureRequiresSecureConnection = NO;
     314    configuration.get()._mediaCaptureEnabled = YES;
     315    preferences._mockCaptureDevicesEnabled = YES;
     316
     317    auto messageHandler = adoptNS([[GUMMessageHandler alloc] init]);
     318    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"gum"];
     319
     320    done = false;
     321    auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
     322    auto delegate = adoptNS([[GetUserMediaCaptureUIDelegate alloc] init]);
     323    webView1.get().UIDelegate = delegate.get();
     324    [webView1 loadTestPageNamed:@"getUserMedia2"];
     325    TestWebKitAPI::Util::run(&done);
     326
     327    configuration.get()._relatedWebView = webView1.get();
     328
     329    done = false;
     330    auto webView2 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
     331    webView2.get().UIDelegate = delegate.get();
     332    [webView2 loadTestPageNamed:@"getUserMedia2"];
     333    TestWebKitAPI::Util::run(&done);
     334
     335    done = false;
     336#if PLATFORM(IOS)
     337    [webView1 stringByEvaluatingJavaScript:@"checkIsNotPlaying()"];
     338#else
     339    [webView1 stringByEvaluatingJavaScript:@"checkIsPlaying()"];
     340#endif
     341    TestWebKitAPI::Util::run(&done);
     342}
     343
    304344#if WK_HAVE_C_SPI
    305345TEST(WebKit, WebAudioAndGetUserMedia)
Note: See TracChangeset for help on using the changeset viewer.