Changeset 246928 in webkit


Ignore:
Timestamp:
Jun 28, 2019, 10:39:53 AM (6 years ago)
Author:
jer.noble@apple.com
Message:

Add new -[WKWebView _closeAllMediaPresentations] SPI
https://bugs.webkit.org/show_bug.cgi?id=199294
<rdar://problem/51965958>

Reviewed by Alex Christensen.

Source/WebKit:

Add a new SPI that will close all out-of-window media presentations, including
picture-in-picture, video fullscreen, and element fullscreen.

Drive-by fixes:

+ -[WKApplicationStateTrackingView didMoveToWindow] incorrectly assumes that a WKWebView will

never be moved frome one window to another, and asserts.

+ -[WKFullScreenWindowController close] doesn't fire the correct 'webkitfullscreenchange' event

when called in the middle of animating into fullscreen.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _closeAllMediaPresentations]):

  • UIProcess/API/Cocoa/WKWebViewPrivate.h:
  • UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
  • UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:

(WebKit::VideoFullscreenManagerProxy::forEachSession):

  • UIProcess/ios/WKApplicationStateTrackingView.mm:

(-[WKApplicationStateTrackingView didMoveToWindow]):

  • UIProcess/mac/WKFullScreenWindowController.h:
  • UIProcess/mac/WKFullScreenWindowController.mm:

(-[WKFullScreenWindowController exitFullScreenImmediately]):
(-[WKFullScreenWindowController close]):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/WKWebViewCloseAllMediaPresentations.mm: Added.

(TEST):

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246926 r246928  
     12019-06-28  Jer Noble  <jer.noble@apple.com>
     2
     3        Add new -[WKWebView _closeAllMediaPresentations] SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=199294
     5        <rdar://problem/51965958>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Add a new SPI that will close all out-of-window media presentations, including
     10        picture-in-picture, video fullscreen, and element fullscreen.
     11
     12        Drive-by fixes:
     13
     14        + -[WKApplicationStateTrackingView didMoveToWindow] incorrectly assumes that a WKWebView will
     15          never be moved frome one window to another, and asserts.
     16
     17        + -[WKFullScreenWindowController close] doesn't fire the correct 'webkitfullscreenchange' event
     18          when called in the middle of animating into fullscreen.
     19
     20        * UIProcess/API/Cocoa/WKWebView.mm:
     21        (-[WKWebView _closeAllMediaPresentations]):
     22        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     23        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
     24        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
     25        (WebKit::VideoFullscreenManagerProxy::forEachSession):
     26        * UIProcess/ios/WKApplicationStateTrackingView.mm:
     27        (-[WKApplicationStateTrackingView didMoveToWindow]):
     28        * UIProcess/mac/WKFullScreenWindowController.h:
     29        * UIProcess/mac/WKFullScreenWindowController.mm:
     30        (-[WKFullScreenWindowController exitFullScreenImmediately]):
     31        (-[WKFullScreenWindowController close]):
     32
    1332019-06-28  Antti Koivisto  <antti@apple.com>
    234
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r246892 r246928  
    5555#import "UserMediaProcessManager.h"
    5656#import "VersionChecks.h"
     57#import "VideoFullscreenManagerProxy.h"
    5758#import "ViewGestureController.h"
    5859#import "ViewSnapshotStore.h"
     
    47364737}
    47374738
     4739- (void)_closeAllMediaPresentations
     4740{
     4741    if (auto videoFullscreenManager = _page->videoFullscreenManager()) {
     4742        videoFullscreenManager->forEachSession([] (auto& model, auto& interface) {
     4743            model.requestFullscreenMode(WebCore::HTMLMediaElementEnums::VideoFullscreenModeNone);
     4744        });
     4745    }
     4746
     4747    if (auto fullScreenManager = _page->fullScreenManager(); fullScreenManager && fullScreenManager->isFullScreen())
     4748        fullScreenManager->close();
     4749}
     4750
    47384751- (void)_stopAllMediaPlayback
    47394752{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r246892 r246928  
    424424- (void)_suspendAllMediaPlayback;
    425425- (void)_resumeAllMediaPlayback;
     426- (void)_closeAllMediaPresentations;
    426427
    427428- (void)_requestTextInputContextsInRect:(CGRect)rect completionHandler:(void(^)(NSArray<_WKTextInputContext *> *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h

    r239709 r246928  
    139139    PlatformVideoFullscreenInterface* controlsManagerInterface();
    140140
     141    void forEachSession(Function<void(WebCore::VideoFullscreenModel&, PlatformVideoFullscreenInterface&)>&&);
     142
    141143private:
    142144    friend class VideoFullscreenModelContext;
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm

    r245796 r246928  
    467467}
    468468
     469void VideoFullscreenManagerProxy::forEachSession(Function<void(VideoFullscreenModel&, PlatformVideoFullscreenInterface&)>&& callback)
     470{
     471    if (m_contextMap.isEmpty())
     472        return;
     473
     474    Vector<ModelInterfaceTuple> values;
     475    values.reserveInitialCapacity(m_contextMap.size());
     476    for (auto& value : m_contextMap.values())
     477        values.uncheckedAppend(value);
     478
     479    for (auto& value : values) {
     480        RefPtr<VideoFullscreenModelContext> model;
     481        RefPtr<PlatformVideoFullscreenInterface> interface;
     482        std::tie(model, interface) = value;
     483
     484        ASSERT(model);
     485        ASSERT(interface);
     486        if (!model || !interface)
     487            continue;
     488
     489        callback(*model, *interface);
     490    }
     491}
     492
    469493#pragma mark Messages from VideoFullscreenManager
    470494
  • trunk/Source/WebKit/UIProcess/ios/WKApplicationStateTrackingView.mm

    r244113 r246928  
    6363- (void)didMoveToWindow
    6464{
    65     if (!self._contentView.window)
     65    if (!self._contentView.window || _applicationStateTracker)
    6666        return;
    6767
    68     ASSERT(!_applicationStateTracker);
    6968    _applicationStateTracker = std::make_unique<WebKit::ApplicationStateTracker>(self, @selector(_applicationDidEnterBackground), @selector(_applicationDidFinishSnapshottingAfterEnteringBackground), @selector(_applicationWillEnterForeground));
    7069   
  • trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.h

    r239475 r246928  
    7878- (void)enterFullScreen:(NSScreen *)screen;
    7979- (void)exitFullScreen;
     80- (void)exitFullScreenImmediately;
    8081- (void)requestExitFullScreen;
    8182- (void)close;
  • trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm

    r244545 r246928  
    421421}
    422422
     423- (void)exitFullScreenImmediately
     424{
     425    if (![self isFullScreen])
     426        return;
     427
     428    [self _manager]->requestExitFullScreen();
     429    [_webViewPlaceholder setExitWarningVisible:NO];
     430    [self _manager]->willExitFullScreen();
     431    _fullScreenState = ExitingFullScreen;
     432    [self finishedExitFullScreenAnimation:YES];
     433}
     434
    423435- (void)requestExitFullScreen
    424436{
     
    582594    // in response.
    583595    if ([self isFullScreen])
    584         [self exitFullScreen];
     596        [self exitFullScreenImmediately];
    585597   
    586598    if (_fullScreenState == ExitingFullScreen)
  • trunk/Tools/ChangeLog

    r246927 r246928  
     12019-06-28  Jer Noble  <jer.noble@apple.com>
     2
     3        Add new -[WKWebView _closeAllMediaPresentations] SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=199294
     5        <rdar://problem/51965958>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewCloseAllMediaPresentations.mm: Added.
     11        (TEST):
     12
    1132019-06-28  Sihui Liu  <sihui_liu@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r246927 r246928  
    852852                CDC9442F1EF205D60059C3C4 /* mediastreamtrack-detached.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDC9442B1EF1FBD20059C3C4 /* mediastreamtrack-detached.html */; };
    853853                CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDCFA7A91E45122F00C2433D /* SampleMap.cpp */; };
     854                CDD68F0D22C18317000CF0AE /* WKWebViewCloseAllMediaPresentations.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDD68F0C22C18317000CF0AE /* WKWebViewCloseAllMediaPresentations.mm */; };
    854855                CDE195B51CFE0B880053D256 /* FullscreenTopContentInset.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */; };
    855856                CDF0B78A216D48DC00421ECC /* CloseWebViewDuringEnterFullscreen.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDF0B789216D484300421ECC /* CloseWebViewDuringEnterFullscreen.mm */; };
     
    22512252                CDC9442C1EF1FC080059C3C4 /* MediaStreamTrackDetached.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaStreamTrackDetached.mm; sourceTree = "<group>"; };
    22522253                CDCFA7A91E45122F00C2433D /* SampleMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SampleMap.cpp; sourceTree = "<group>"; };
     2254                CDD68F0C22C18317000CF0AE /* WKWebViewCloseAllMediaPresentations.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCloseAllMediaPresentations.mm; sourceTree = "<group>"; };
    22532255                CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenTopContentInset.html; sourceTree = "<group>"; };
    22542256                CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenTopContentInset.mm; sourceTree = "<group>"; };
     
    28142816                                CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */,
    28152817                                9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */,
     2818                                CDD68F0C22C18317000CF0AE /* WKWebViewCloseAllMediaPresentations.mm */,
    28162819                        );
    28172820                        name = "WebKit Cocoa";
     
    43514354                                46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */,
    43524355                                8C10AF99206467A90018FD90 /* LocalStoragePersistence.mm in Sources */,
     4356                                CDD68F0D22C18317000CF0AE /* WKWebViewCloseAllMediaPresentations.mm in Sources */,
    43534357                                7A6A2C701DCCFA8C00C0D085 /* LocalStorageQuirkTest.mm in Sources */,
    43544358                                076E507F1F4513D6006E9F5A /* Logging.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.