Changeset 271640 in webkit


Ignore:
Timestamp:
Jan 20, 2021 12:57:03 AM (18 months ago)
Author:
youenn@apple.com
Message:

On page close, make sure to notify of capture state immediately
https://bugs.webkit.org/show_bug.cgi?id=220588

Reviewed by Geoffrey Garen.

Source/WebKit:

If page is getting closed or reset (for instance in case of process swap), we immediately notify the client of the capture state,
instead of waiting for 3 seconds if capture just started.

Covered by API test.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::isPlayingMediaDidChange):
(WebKit::WebPageProxy::updatePlayingMediaDidChange):
(WebKit::WebPageProxy::updateReportedMediaCaptureState):

  • UIProcess/WebPageProxy.h:

Tools:

  • TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r271636 r271640  
     12021-01-20  Youenn Fablet  <youenn@apple.com>
     2
     3        On page close, make sure to notify of capture state immediately
     4        https://bugs.webkit.org/show_bug.cgi?id=220588
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        If page is getting closed or reset (for instance in case of process swap), we immediately notify the client of the capture state,
     9        instead of waiting for 3 seconds if capture just started.
     10
     11        Covered by API test.
     12
     13        * UIProcess/WebPageProxy.cpp:
     14        (WebKit::WebPageProxy::isPlayingMediaDidChange):
     15        (WebKit::WebPageProxy::updatePlayingMediaDidChange):
     16        (WebKit::WebPageProxy::updateReportedMediaCaptureState):
     17        * UIProcess/WebPageProxy.h:
     18
    1192021-01-19  Sihui Liu  <sihui_liu@appe.com>
    220
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r271469 r271640  
    90349034
    90359035    if (!m_isClosed)
    9036         updatePlayingMediaDidChange(newState);
    9037 }
    9038 
    9039 void WebPageProxy::updatePlayingMediaDidChange(MediaProducer::MediaStateFlags newState)
    9040 {
    9041     if (newState == m_mediaState)
    9042         return;
     9036        updatePlayingMediaDidChange(newState, CanDelayNotification::Yes);
     9037}
     9038
     9039void WebPageProxy::updatePlayingMediaDidChange(MediaProducer::MediaStateFlags newState, CanDelayNotification canDelayNotification)
     9040{
     9041#if ENABLE(MEDIA_STREAM)
     9042    auto updateMediaCaptureStateImmediatelyIfNeeded = [&] {
     9043        if (canDelayNotification == CanDelayNotification::No && m_updateReportedMediaCaptureStateTimer.isActive()) {
     9044            m_updateReportedMediaCaptureStateTimer.stop();
     9045            updateReportedMediaCaptureState();
     9046        }
     9047    };
     9048#endif
     9049
     9050    if (newState == m_mediaState) {
     9051#if ENABLE(MEDIA_STREAM)
     9052        updateMediaCaptureStateImmediatelyIfNeeded();
     9053#endif
     9054        return;
     9055    }
    90439056
    90449057#if PLATFORM(MACCATALYST)
     
    90759088            m_userMediaPermissionRequestManager->captureStateChanged(oldMediaCaptureState, newMediaCaptureState);
    90769089    }
     9090    updateMediaCaptureStateImmediatelyIfNeeded();
    90779091#endif
    90789092
     
    91039117    if (!haveReportedCapture && willReportCapture)
    91049118        m_updateReportedMediaCaptureStateTimer.startOneShot(m_mediaCaptureReportingDelay);
     9119
     9120    RELEASE_LOG_IF_ALLOWED(WebRTC, "updateReportedMediaCaptureState: from %d to %d", m_reportedMediaCaptureState, activeCaptureState);
    91059121
    91069122    m_reportedMediaCaptureState = activeCaptureState;
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r271543 r271640  
    14411441    void updateReportedMediaCaptureState();
    14421442
    1443     void updatePlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags);
     1443    enum class CanDelayNotification { No, Yes };
     1444    void updatePlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, CanDelayNotification = CanDelayNotification::No);
    14441445    bool isCapturingAudio() const { return m_mediaState & WebCore::MediaProducer::AudioCaptureMask; }
    14451446    bool isCapturingVideo() const { return m_mediaState & WebCore::MediaProducer::VideoCaptureMask; }
  • trunk/Tools/ChangeLog

    r271636 r271640  
     12021-01-20  Youenn Fablet  <youenn@apple.com>
     2
     3        On page close, make sure to notify of capture state immediately
     4        https://bugs.webkit.org/show_bug.cgi?id=220588
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:
     9        (TestWebKitAPI::TEST):
     10
    1112021-01-19  Sihui Liu  <sihui_liu@appe.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm

    r267563 r271640  
    240240    // One additional second should allow us to go back to no capture being reported.
    241241    EXPECT_TRUE(waitUntilCaptureState(webView, _WKMediaCaptureStateNone));
    242 
     242}
     243
     244TEST(WebKit2, CaptureIndicatorDelayWhenClosed)
     245{
     246    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     247    auto processPoolConfig = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     248    auto preferences = [configuration preferences];
     249    preferences._mediaCaptureRequiresSecureConnection = NO;
     250    configuration.get()._mediaCaptureEnabled = YES;
     251    preferences._mockCaptureDevicesEnabled = YES;
     252
     253    auto messageHandler = adoptNS([[GUMMessageHandler alloc] init]);
     254    [[configuration.get() userContentController] addScriptMessageHandler:messageHandler.get() name:@"gum"];
     255
     256    auto webView = [[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get() processPoolConfiguration:processPoolConfig.get()];
     257    webView._mediaCaptureReportingDelayForTesting = 2;
     258
     259    auto delegate = adoptNS([[GetUserMediaCaptureUIDelegate alloc] init]);
     260    webView.UIDelegate = delegate.get();
     261
     262    wasPrompted = false;
     263
     264    [webView loadTestPageNamed:@"getUserMedia"];
     265    EXPECT_TRUE(waitUntilCaptureState(webView, _WKMediaCaptureStateActiveCamera));
     266
     267    TestWebKitAPI::Util::run(&wasPrompted);
     268    wasPrompted = false;
     269
     270    [webView _close];
     271
     272    EXPECT_EQ([webView _mediaCaptureState], _WKMediaCaptureStateNone);
    243273}
    244274
Note: See TracChangeset for help on using the changeset viewer.