Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6e15e1f73ee12ff54c3975e98860a893cb27fe25
      
https://github.com/WebKit/WebKit/commit/6e15e1f73ee12ff54c3975e98860a893cb27fe25
  Author: Jean-Yves Avenard <[email protected]>
  Date:   2026-04-19 (Sun, 19 Apr 2026)

  Changed paths:
    M Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp
    M Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h
    M Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm
    M Source/WebKit/WebProcess/cocoa/TextRecognitionRequest.cpp
    M Tools/TestWebKitAPI/Resources/cocoa/element-fullscreen.html
    M 
Tools/TestWebKitAPI/Tests/WebKit/WKWebView/FullscreenVideoTextRecognition.mm

  Log Message:
  -----------
  Safari doesn't really fully dismiss the text selection in video player after 
closing the video
https://bugs.webkit.org/show_bug.cgi?id=312462
rdar://173346436

Reviewed by Youenn Fablet.

When a video is paused in fullscreen, WebKit starts text recognition after a
250ms debounce timer. Two independent code paths trigger this: 
WebFullScreenManager
(via DOM pause/seeking/playing events) and TextRecognitionRequest (via
PlaybackSessionManager rate/time change events). Both use separate 250ms timers
and both call WebPage::beginTextRecognitionForVideoInElementFullScreen, which
sends an IPC to the UIProcess to perform VisionKit image analysis and install
a VKCImageAnalysisOverlayView.

There were several issues causing the overlay to persist after fullscreen exit:

1. TextRecognitionRequest's timer callback did not re-validate element state.
Between scheduling the timer and it firing, the video could have exited
fullscreen, started playing, or begun seeking. The timer callback now
re-checks isInFullscreenOrPictureInPicture(), paused(), and seeking()
before proceeding.
2. WebFullScreenManager::mainVideoElementTextRecognitionTimerFired similarly
did not re-check whether the video was still paused and not seeking when
the timer fired. If conditions changed, it now calls 
endTextRecognitionForMainVideoIfNeeded()
to cancel any in-flight recognition.
3. WebFullScreenManager::handleEvent returned early when the event target was
the fullscreen element itself (targetElement == m_element), skipping the
text recognition handling block. This meant that when the video element
was directly the fullscreen element (video.webkitRequestFullscreen() rather
than a container), seeking/playing events never triggered cancellation of
in-flight text recognition via the WebFullScreenManager path.
4. WebFullScreenManager::exitFullScreenForElement only cancelled the
WebFullScreenManager's own text recognition timer via
setMainVideoElement(nullptr). It did not cancel TextRecognitionRequest's
independent timer. If TextRecognitionRequest's timer fired after the
WebFullScreenManager cancel but before the fullscreen exit completed, it
would send a new beginTextRecognitionForVideoInElementFullScreen IPC,
causing the overlay to be re-installed after it had been removed. The exit
path now also calls PlaybackSessionManager::cancelTextRecognition() to
cancel both paths.

New API tests verify that no image analysis overlay remains installed after
exiting fullscreen. Tests cover both element fullscreen (container as
fullscreen element) and video fullscreen (video as fullscreen element),
with and without an in-progress seek at the time of exit.

We also reenable three previously disabled tests now that the underlying race 
conditions
are fixed
  - TogglePlaybackInElementFullscreen
  - AddVideoAfterEnteringFullscreen
  - DoNotAnalyzeVideoAfterExitingFullscreen

- Source/WebKit/WebProcess/cocoa/TextRecognitionRequest.cpp:
(WebKit::TextRecognitionRequest::requestTextRecognitionFor): Re-check
element state in timer callback before beginning text recognition.
- Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp:
(WebKit::WebFullScreenManager::exitFullScreenForElement): Cancel
TextRecognitionRequest via PlaybackSessionManager on fullscreen exit.
(WebKit::WebFullScreenManager::handleEvent): Remove early return when
targetElement == m_element so text recognition events are handled when the
video is the fullscreen element.
(WebKit::WebFullScreenManager::mainVideoElementTextRecognitionTimerFired):
Re-check paused/seeking state; cancel if conditions changed.
- Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h:
- Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm:
(WebKit::PlaybackSessionManager::cancelTextRecognition): Added.
- Tools/TestWebKitAPI/Resources/cocoa/element-fullscreen.html: Added
enterVideoFullscreen() function.
- Tools/TestWebKitAPI/Tests/WebKit/WKWebView/FullscreenVideoTextRecognition.mm:
(FullscreenVideoTextRecognitionWebView enterVideoFullscreen): Added.
(-[FullscreenVideoTextRecognitionWebView enterVideoFullscreen]): Added.

Canonical link: https://commits.webkit.org/311561@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to