Skip to content

Commit

Permalink
Cherry-pick 6406ada. rdar://problem/109896538
Browse files Browse the repository at this point in the history
    getDisplayMedia capture should mute other tabs when starting
    https://bugs.webkit.org/show_bug.cgi?id=257386
    rdar://problem/109896538

    Reviewed by Eric Carlson.

    We were muting other tabs within UserMediaProcessManager::willCreateMediaStream but only for microphone and camera
    as the screen/window code path was exiting early.
    Move the call to mute other tabs in WebPageProxy::willStartCapture so that it covers all code paths.

    Covered by API test.

    * Source/WebKit/UIProcess/UserMediaProcessManager.cpp:
    (WebKit::UserMediaProcessManager::willCreateMediaStream):
    * Source/WebKit/UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::willStartCapture):
    * Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:
    (TestWebKitAPI::TEST):

    Canonical link: https://commits.webkit.org/264611@main
Identifier: 263319.527@safari-7616.1.14.11-branch
  • Loading branch information
youennf authored and MyahCobbs committed May 30, 2023
1 parent 1f44c52 commit 24069ad
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Source/WebKit/UIProcess/UserMediaProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ bool UserMediaProcessManager::willCreateMediaStream(UserMediaPermissionRequestMa
UNUSED_PARAM(request);
#endif

proxy.page().activateMediaStreamCaptureInPage();

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9585,6 +9585,8 @@ void WebPageProxy::setMockCaptureDevicesEnabledOverride(std::optional<bool> enab

void WebPageProxy::willStartCapture(const UserMediaPermissionRequestProxy& request, CompletionHandler<void()>&& callback)
{
activateMediaStreamCaptureInPage();

#if ENABLE(GPU_PROCESS)
if (!preferences().captureVideoInGPUProcessEnabled() && !preferences().captureAudioInGPUProcessEnabled())
return callback();
Expand Down
38 changes: 38 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,44 @@ bool waitUntilMicrophoneState(WKWebView *webView, WKMediaCaptureState expectedSt
TestWebKitAPI::Util::run(&done);
}

#if PLATFORM(MAC)
TEST(WebKit, InterruptionBetweenGetDisplayMediaAndGetUserMedia)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));

configuration.get().processPool = (WKProcessPool *)context.get();

initializeMediaCaptureConfiguration(configuration.get());

auto messageHandler = adoptNS([[GUMMessageHandler alloc] init]);
[[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"gum"];

auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
auto delegate = adoptNS([[UserMediaCaptureUIDelegate alloc] init]);
webView1.get().UIDelegate = delegate.get();

auto observer = adoptNS([[MediaCaptureObserver alloc] init]);
[webView1 addObserver:observer.get() forKeyPath:@"microphoneCaptureState" options:NSKeyValueObservingOptionNew context:nil];
[webView1 addObserver:observer.get() forKeyPath:@"cameraCaptureState" options:NSKeyValueObservingOptionNew context:nil];

cameraCaptureStateChange = false;
[webView1 loadTestPageNamed:@"getUserMedia"];

EXPECT_TRUE(waitUntilCameraState(webView1.get(), WKMediaCaptureStateActive));

auto webView2 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
webView2.get().UIDelegate = delegate.get();

[delegate setGetDisplayMediaDecision:WKDisplayCapturePermissionDecisionScreenPrompt];
[webView2 synchronouslyLoadTestPageNamed:@"getDisplayMedia"];
[webView2 stringByEvaluatingJavaScript:@"promptForCapture({ video : true })"];

cameraCaptureStateChange = false;
EXPECT_TRUE(waitUntilCameraState(webView1.get(), WKMediaCaptureStateMuted));
}
#endif // PLATFORM(MAC)

static constexpr auto mainFrameText = R"DOCDOCDOC(
<html><body>
<iframe src='http://127.0.0.1:9091/frame' allow='camera:http://127.0.0.1:9091'></iframe>
Expand Down

0 comments on commit 24069ad

Please sign in to comment.