Changeset 289696 in webkit


Ignore:
Timestamp:
Feb 12, 2022 8:08:49 AM (5 months ago)
Author:
eric.carlson@apple.com
Message:

[macOS] Use system window and screen picker when available
https://bugs.webkit.org/show_bug.cgi?id=236531
rdar://87111816

Reviewed by Jer Noble.

Source/WebCore:

Tested manually.

  • SourcesCocoa.txt: Add new files.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • en.lproj/Localizable.strings: Update prompts.
  • platform/mediastream/cocoa/DisplayCaptureSourceCocoa.cpp:

(WebCore::DisplayCaptureSourceCocoa::capturerConfigurationChanged): Allow a capturer
to notify the source of a configuration change.

  • platform/mediastream/cocoa/DisplayCaptureSourceCocoa.h:

(WebCore::CapturerObserver::capturerConfigurationChanged):

  • platform/mediastream/mac/ScreenCaptureKitCaptureSource.h:
  • platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm:

(-[WebCoreScreenCaptureKitHelper stream:didStopWithError:]): Forward delegate callbacks
to the capture source.
(-[WebCoreScreenCaptureKitHelper sessionDidEnd:]): Ditto.
(-[WebCoreScreenCaptureKitHelper sessionDidChangeContent:]): Ditto.
(-[WebCoreScreenCaptureKitHelper pickerCanceledForSession:]): Ditto.
(WebCore::ScreenCaptureKitCaptureSource::sessionDidChangeContent): React to a
reconfiguration.
(WebCore::ScreenCaptureKitCaptureSource::sessionDidEnd):
(WebCore::ScreenCaptureKitCaptureSource::startContentStream): Use the sharing
session manager when available.
(WebCore::ScreenCaptureKitCaptureSource::intrinsicSize const): Get the size from
the content when possible.

  • platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.h: Added.

(WebCore::ScreenCaptureKitSharingSessionManager::SharingSessionObserver::operator== const):

  • platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm: Added.

(-[WebDisplayMediaPromptHelper initWithCallback:]):
(-[WebDisplayMediaPromptHelper disconnect]):
(-[WebDisplayMediaPromptHelper startObservingSession:]):
(-[WebDisplayMediaPromptHelper stopObservingSession:]):
(-[WebDisplayMediaPromptHelper sessionDidEnd:]):
(-[WebDisplayMediaPromptHelper sessionDidChangeContent:]):
(-[WebDisplayMediaPromptHelper pickerCanceledForSession:]):
(WebCore::ScreenCaptureKitSharingSessionManager::isAvailable):
(WebCore::ScreenCaptureKitSharingSessionManager::singleton):
(WebCore::ScreenCaptureKitSharingSessionManager::ScreenCaptureKitSharingSessionManager):
(WebCore::ScreenCaptureKitSharingSessionManager::~ScreenCaptureKitSharingSessionManager):
(WebCore::ScreenCaptureKitSharingSessionManager::pickerCanceledForSession):
(WebCore::ScreenCaptureKitSharingSessionManager::sessionDidEnd):
(WebCore::ScreenCaptureKitSharingSessionManager::sessionDidChangeContent):
(WebCore::ScreenCaptureKitSharingSessionManager::showWindowPicker):
(WebCore::ScreenCaptureKitSharingSessionManager::showScreenPicker):
(WebCore::ScreenCaptureKitSharingSessionManager::promptForGetDisplayMedia):
(WebCore::ScreenCaptureKitSharingSessionManager::takeSharingSessionForFilter):

Source/WebCore/PAL:

  • PAL.xcodeproj/project.pbxproj:
  • pal/mac/ScreenCaptureKitSoftLink.h:
  • pal/mac/ScreenCaptureKitSoftLink.mm:
  • pal/spi/mac/ScreenCaptureKitSPI.h: Added.

Source/WebKit:

  • Platform/spi/Cocoa/SafeBrowsingSPI.h:
  • UIProcess/mac/DisplayCaptureSessionManager.mm:

(WebKit::DisplayCaptureSessionManager::alertForGetDisplayMedia): Update prompt strings.
(WebKit::DisplayCaptureSessionManager::showWindowPicker): Use capture session
manager when available.
(WebKit::DisplayCaptureSessionManager::showScreenPicker): Ditto.

Source/WTF:

  • wtf/PlatformHave.h: Define HAVE_SC_CONTENT_SHARING_SESSION.
Location:
trunk/Source
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r289683 r289696  
     12022-02-12  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [macOS] Use system window and screen picker when available
     4        https://bugs.webkit.org/show_bug.cgi?id=236531
     5        rdar://87111816
     6
     7        Reviewed by Jer Noble.
     8
     9        * wtf/PlatformHave.h: Define HAVE_SC_CONTENT_SHARING_SESSION.
     10
    1112022-02-11  Nikolaos Mouchtaris  <nmouchtaris@apple.com>
    212
  • trunk/Source/WTF/wtf/PlatformHave.h

    r289681 r289696  
    11471147#endif
    11481148
     1149#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000)
     1150#define HAVE_SC_CONTENT_SHARING_SESSION 1
     1151#endif
     1152
    11491153#if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000) \
    11501154    || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000))
  • trunk/Source/WebCore/ChangeLog

    r289693 r289696  
     12022-02-12  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [macOS] Use system window and screen picker when available
     4        https://bugs.webkit.org/show_bug.cgi?id=236531
     5        rdar://87111816
     6
     7        Reviewed by Jer Noble.
     8
     9        Tested manually.
     10
     11        * SourcesCocoa.txt: Add new files.
     12        * WebCore.xcodeproj/project.pbxproj: Ditto.
     13
     14        * en.lproj/Localizable.strings: Update prompts.
     15
     16        * platform/mediastream/cocoa/DisplayCaptureSourceCocoa.cpp:
     17        (WebCore::DisplayCaptureSourceCocoa::capturerConfigurationChanged): Allow a capturer
     18        to notify the source of a configuration change.
     19        * platform/mediastream/cocoa/DisplayCaptureSourceCocoa.h:
     20        (WebCore::CapturerObserver::capturerConfigurationChanged):
     21
     22        * platform/mediastream/mac/ScreenCaptureKitCaptureSource.h:
     23        * platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm:
     24        (-[WebCoreScreenCaptureKitHelper stream:didStopWithError:]): Forward delegate callbacks
     25        to the capture source.
     26        (-[WebCoreScreenCaptureKitHelper sessionDidEnd:]): Ditto.
     27        (-[WebCoreScreenCaptureKitHelper sessionDidChangeContent:]): Ditto.
     28        (-[WebCoreScreenCaptureKitHelper pickerCanceledForSession:]): Ditto.
     29        (WebCore::ScreenCaptureKitCaptureSource::sessionDidChangeContent): React to a
     30        reconfiguration.
     31        (WebCore::ScreenCaptureKitCaptureSource::sessionDidEnd):
     32        (WebCore::ScreenCaptureKitCaptureSource::startContentStream): Use the sharing
     33        session manager when available.
     34        (WebCore::ScreenCaptureKitCaptureSource::intrinsicSize const): Get the size from
     35        the content when possible.
     36
     37        * platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.h: Added.
     38        (WebCore::ScreenCaptureKitSharingSessionManager::SharingSessionObserver::operator== const):
     39        * platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm: Added.
     40        (-[WebDisplayMediaPromptHelper initWithCallback:]):
     41        (-[WebDisplayMediaPromptHelper disconnect]):
     42        (-[WebDisplayMediaPromptHelper startObservingSession:]):
     43        (-[WebDisplayMediaPromptHelper stopObservingSession:]):
     44        (-[WebDisplayMediaPromptHelper sessionDidEnd:]):
     45        (-[WebDisplayMediaPromptHelper sessionDidChangeContent:]):
     46        (-[WebDisplayMediaPromptHelper pickerCanceledForSession:]):
     47        (WebCore::ScreenCaptureKitSharingSessionManager::isAvailable):
     48        (WebCore::ScreenCaptureKitSharingSessionManager::singleton):
     49        (WebCore::ScreenCaptureKitSharingSessionManager::ScreenCaptureKitSharingSessionManager):
     50        (WebCore::ScreenCaptureKitSharingSessionManager::~ScreenCaptureKitSharingSessionManager):
     51        (WebCore::ScreenCaptureKitSharingSessionManager::pickerCanceledForSession):
     52        (WebCore::ScreenCaptureKitSharingSessionManager::sessionDidEnd):
     53        (WebCore::ScreenCaptureKitSharingSessionManager::sessionDidChangeContent):
     54        (WebCore::ScreenCaptureKitSharingSessionManager::showWindowPicker):
     55        (WebCore::ScreenCaptureKitSharingSessionManager::showScreenPicker):
     56        (WebCore::ScreenCaptureKitSharingSessionManager::promptForGetDisplayMedia):
     57        (WebCore::ScreenCaptureKitSharingSessionManager::takeSharingSessionForFilter):
     58
    1592022-02-12  Rob Buis  <rbuis@igalia.com>
    260
  • trunk/Source/WebCore/PAL/ChangeLog

    r289547 r289696  
     12022-02-12  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [macOS] Use system window and screen picker when available
     4        https://bugs.webkit.org/show_bug.cgi?id=236531
     5        rdar://87111816
     6
     7        Reviewed by Jer Noble.
     8
     9        * PAL.xcodeproj/project.pbxproj:
     10        * pal/mac/ScreenCaptureKitSoftLink.h:
     11        * pal/mac/ScreenCaptureKitSoftLink.mm:
     12        * pal/spi/mac/ScreenCaptureKitSPI.h: Added.
     13
    1142022-02-10  Eric Carlson  <eric.carlson@apple.com>
    215
  • trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

    r288604 r289696  
    2222
    2323/* Begin PBXBuildFile section */
     24                07035D3127A9B33000FB03E4 /* ScreenCaptureKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 07035D3027A9B32E00FB03E4 /* ScreenCaptureKitSPI.h */; };
    2425                071C00372707EDF000D027C7 /* ReplayKitSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 071C00352707EDF000D027C7 /* ReplayKitSoftLink.mm */; };
    2526                071C00382707EDF000D027C7 /* ReplayKitSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 071C00362707EDF000D027C7 /* ReplayKitSoftLink.h */; };
     
    431432
    432433/* Begin PBXFileReference section */
     434                07035D3027A9B32E00FB03E4 /* ScreenCaptureKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenCaptureKitSPI.h; sourceTree = "<group>"; };
    433435                071C00352707EDF000D027C7 /* ReplayKitSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ReplayKitSoftLink.mm; sourceTree = "<group>"; };
    434436                071C00362707EDF000D027C7 /* ReplayKitSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReplayKitSoftLink.h; sourceTree = "<group>"; };
     
    10561058                                0C7785851F45130F00F4EBB6 /* PIPSPI.h */,
    10571059                                0C7785871F45130F00F4EBB6 /* QuickLookMacSPI.h */,
    1058                                 A1175B481F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h */,
     1060                                07035D3027A9B32E00FB03E4 /* ScreenCaptureKitSPI.h */,
    10591061                                71B1141F26823ACD004D6701 /* SystemPreviewSPI.h */,
    10601062                                0C7785881F45130F00F4EBB6 /* TelephonyUtilitiesSPI.h */,
     
    16781680                                BC4DDD9F273EF56E00660EBB /* SceneKitSPI.h in Headers */,
    16791681                                07789182273B14FF00E408D1 /* ScreenCaptureKitSoftLink.h in Headers */,
     1682                                07035D3127A9B33000FB03E4 /* ScreenCaptureKitSPI.h in Headers */,
    16801683                                570AB8F120AE2E8D00B8BE87 /* SecKeyProxySPI.h in Headers */,
    16811684                                0C2DA1581F3BEB4900DBC317 /* ServersSPI.h in Headers */,
  • trunk/Source/WebCore/PAL/pal/mac/ScreenCaptureKitSoftLink.h

    r289547 r289696  
    3737SOFT_LINK_CLASS_FOR_HEADER_WITH_AVAILABILITY(PAL, SCStreamConfiguration, API_AVAILABLE(macos(12.3)))
    3838SOFT_LINK_CLASS_FOR_HEADER_WITH_AVAILABILITY(PAL, SCStream, API_AVAILABLE(macos(12.3)))
     39SOFT_LINK_CLASS_FOR_HEADER(PAL, SCContentSharingSession)
    3940
    4041SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, ScreenCaptureKit, SCStreamFrameInfoStatus, NSString *)
  • trunk/Source/WebCore/PAL/pal/mac/ScreenCaptureKitSoftLink.mm

    r289547 r289696  
    3737SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT_AND_AVAILABILITY(PAL, ScreenCaptureKit, SCStreamConfiguration, PAL_EXPORT, API_AVAILABLE(macos(12.3)))
    3838SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT_AND_AVAILABILITY(PAL, ScreenCaptureKit, SCStream, PAL_EXPORT, API_AVAILABLE(macos(12.3)))
     39SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT(PAL, ScreenCaptureKit, SCContentSharingSession, PAL_EXPORT)
    3940
    4041SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, ScreenCaptureKit, SCStreamFrameInfoStatus, NSString *, PAL_EXPORT)
  • trunk/Source/WebCore/SourcesCocoa.txt

    r289549 r289696  
    566566platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp
    567567platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm
     568platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm
    568569platform/mediastream/mac/WebAudioSourceProviderCocoa.mm
    569570platform/mock/MediaPlaybackTargetMock.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r289637 r289696  
    119119                073794FE19F5864E00E5A045 /* RTCNotifiersMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 073794F819F5864E00E5A045 /* RTCNotifiersMock.h */; };
    120120                0738E5EC2499839000DA101C /* AVOutputDeviceMenuControllerTargetPicker.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0738E5EA249968AD00DA101C /* AVOutputDeviceMenuControllerTargetPicker.mm */; };
     121                073955BB27AB277F009A08D2 /* ScreenCaptureKitSharingSessionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 07035D3227A9B60B00FB03E4 /* ScreenCaptureKitSharingSessionManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
    121122                073A15542177A42600EA08F2 /* RemoteVideoSample.h in Headers */ = {isa = PBXBuildFile; fileRef = 073A15532177A39A00EA08F2 /* RemoteVideoSample.h */; settings = {ATTRIBUTES = (Private, ); }; };
    122123                073B87671E4385AC0071C0EC /* AudioSampleBufferList.h in Headers */ = {isa = PBXBuildFile; fileRef = 073B87631E43859D0071C0EC /* AudioSampleBufferList.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    59275928                070334D8145A006F008D8D45 /* TrackBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackBase.cpp; sourceTree = "<group>"; };
    59285929                070334E8145A1F35008D8D45 /* JSTrackCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTrackCustom.cpp; sourceTree = "<group>"; };
     5930                07035D3227A9B60B00FB03E4 /* ScreenCaptureKitSharingSessionManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenCaptureKitSharingSessionManager.h; sourceTree = "<group>"; };
     5931                07035D3427A9B61100FB03E4 /* ScreenCaptureKitSharingSessionManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScreenCaptureKitSharingSessionManager.mm; sourceTree = "<group>"; };
    59295932                070363DA181A1CDC00C074A5 /* AVCaptureDeviceManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVCaptureDeviceManager.h; sourceTree = "<group>"; };
    59305933                070363DB181A1CDC00C074A5 /* AVCaptureDeviceManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AVCaptureDeviceManager.mm; sourceTree = "<group>"; };
     
    1873118734                                070BED97273F415600583926 /* ScreenCaptureKitCaptureSource.h */,
    1873218735                                070BED96273F415600583926 /* ScreenCaptureKitCaptureSource.mm */,
     18736                                07035D3227A9B60B00FB03E4 /* ScreenCaptureKitSharingSessionManager.h */,
     18737                                07035D3427A9B61100FB03E4 /* ScreenCaptureKitSharingSessionManager.mm */,
    1873318738                                07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderCocoa.h */,
    1873418739                                07D6373F1BB0B11300256CE9 /* WebAudioSourceProviderCocoa.mm */,
     
    3707237077                                BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */,
    3707337078                                070BED98273F415D00583926 /* ScreenCaptureKitCaptureSource.h in Headers */,
     37079                                073955BB27AB277F009A08D2 /* ScreenCaptureKitSharingSessionManager.h in Headers */,
    3707437080                                C1E1D236203DF15400584665 /* ScreenProperties.h in Headers */,
    3707537081                                A84D82C111D3474800972990 /* ScriptableDocumentParser.h in Headers */,
  • trunk/Source/WebCore/en.lproj/Localizable.strings

    r288604 r289696  
    147147
    148148/* Allow screen button title in window and screen sharing prompt */
    149 "Allow Observing a Screen" = "Allow Observing a Screen";
     149"Allow to Share Screen" = "Allow to Share Screen";
    150150
    151151/* Allow window button title in window and screen sharing prompt */
    152 "Allow Observing a Window" = "Allow Observing a Window";
     152"Allow to Share Window" = "Allow to Share Window";
    153153
    154154/* Button title in Storage Access API prompt */
  • trunk/Source/WebCore/platform/mediastream/cocoa/DisplayCaptureSourceCocoa.cpp

    r289149 r289696  
    325325}
    326326
     327void DisplayCaptureSourceCocoa::capturerConfigurationChanged()
     328{
     329    m_currentSettings = { };
     330    auto capturerIntrinsicSize = m_capturer->intrinsicSize();
     331    if (this->intrinsicSize() != capturerIntrinsicSize) {
     332        m_capabilities = { };
     333        setIntrinsicSize(capturerIntrinsicSize);
     334    }
     335}
     336
    327337void DisplayCaptureSourceCocoa::setLogger(const Logger& logger, const void* identifier)
    328338{
  • trunk/Source/WebCore/platform/mediastream/cocoa/DisplayCaptureSourceCocoa.h

    r288604 r289696  
    5858    virtual void capturerIsRunningChanged(bool) { }
    5959    virtual void capturerFailed() { };
     60    virtual void capturerConfigurationChanged() { };
    6061};
    6162
     
    100101                m_observer->capturerFailed();
    101102        }
     103        void configurationChanged()
     104        {
     105            if (m_observer)
     106                m_observer->capturerConfigurationChanged();
     107        }
    102108
    103109    private:
     
    133139    void capturerIsRunningChanged(bool isRunning) final { notifyMutedChange(!isRunning); }
    134140    void capturerFailed() final { captureFailed(); }
     141    void capturerConfigurationChanged() final;
    135142
    136143    void emitFrame();
  • trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.h

    r289547 r289696  
    4040OBJC_CLASS SCStream;
    4141OBJC_CLASS SCContentFilter;
     42OBJC_CLASS SCContentSharingSession;
    4243OBJC_CLASS SCStreamConfiguration;
    4344OBJC_CLASS SCWindow;
    4445OBJC_CLASS WebCoreScreenCaptureKitHelper;
    4546using CMSampleBufferRef = struct opaqueCMSampleBuffer*;
    46 
    47 typedef struct __IOSurface* IOSurfaceRef;
    4847
    4948namespace WebCore {
     
    7170    enum class SampleType { Video };
    7271    void streamDidOutputSampleBuffer(RetainPtr<CMSampleBufferRef>, SampleType);
     72    void sessionDidChangeContent(RetainPtr<SCContentSharingSession>);
     73    void sessionDidEnd(RetainPtr<SCContentSharingSession>);
    7374
    7475private:
     
    105106    RetainPtr<SCStream> m_contentStream;
    106107    RetainPtr<SCStreamConfiguration> m_streamConfiguration;
     108    RetainPtr<SCContentSharingSession> m_contentSharingSession;
    107109    OSObjectPtr<dispatch_queue_t> m_captureQueue;
    108110    BlockPtr<void(SCStream *, CMSampleBufferRef)> m_frameAvailableHandler;
  • trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm

    r289547 r289696  
    2424 */
    2525
    26 #include "config.h"
    27 #include "ScreenCaptureKitCaptureSource.h"
     26#import "config.h"
     27#import "ScreenCaptureKitCaptureSource.h"
    2828
    2929#if HAVE(SCREEN_CAPTURE_KIT)
     
    3535#import "RealtimeMediaSourceCenter.h"
    3636#import "RealtimeVideoUtilities.h"
     37#import "ScreenCaptureKitSharingSessionManager.h"
    3738#import <ScreenCaptureKit/ScreenCaptureKit.h>
     39#import <pal/spi/mac/ScreenCaptureKitSPI.h>
    3840#import <wtf/BlockObjCExceptions.h>
    3941#import <wtf/BlockPtr.h>
     
    9294
    9395using namespace WebCore;
    94 @interface WebCoreScreenCaptureKitHelper : NSObject<SCStreamDelegate, WKSCStreamOutput> {
     96@interface WebCoreScreenCaptureKitHelper : NSObject<SCStreamDelegate,
     97#if HAVE(SC_CONTENT_SHARING_SESSION)
     98    SCContentSharingSessionProtocol,
     99#endif
     100    WKSCStreamOutput> {
    95101    WeakPtr<ScreenCaptureKitCaptureSource> _callback;
    96102}
     
    100106- (void)stream:(SCStream *)stream didStopWithError:(NSError *)error;
    101107- (void)stream:(SCStream *)stream didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(WKSCStreamOutputType)type;
     108- (void)sessionDidEnd:(SCContentSharingSession *)session;
     109- (void)sessionDidChangeContent:(SCContentSharingSession *)session;
     110- (void)pickerCanceledForSession:(SCContentSharingSession *)session;
    102111@end
    103112
     
    120129- (void)stream:(SCStream *)stream didStopWithError:(NSError *)error
    121130{
    122     callOnMainRunLoop([strongSelf = RetainPtr { self }, error = RetainPtr { error }]() mutable {
    123         if (!strongSelf->_callback)
    124             return;
    125 
    126         strongSelf->_callback->streamFailedWithError(WTFMove(error), "-[SCStreamDelegate stream:didStopWithError:] called"_s);
     131    callOnMainRunLoop([self, strongSelf = RetainPtr { self }, error = RetainPtr { error }]() mutable {
     132        if (!_callback)
     133            return;
     134
     135        _callback->streamFailedWithError(WTFMove(error), "-[SCStreamDelegate stream:didStopWithError:] called"_s);
    127136    });
    128137}
     
    138147}
    139148
     149- (void)sessionDidEnd:(SCContentSharingSession *)session
     150{
     151    RunLoop::main().dispatch([self, strongSelf = RetainPtr { self }, session = RetainPtr { session }]() mutable {
     152        if (_callback)
     153            _callback->sessionDidEnd(session);
     154    });
     155}
     156
     157- (void)sessionDidChangeContent:(SCContentSharingSession *)session
     158{
     159    RunLoop::main().dispatch([self, strongSelf = RetainPtr { self }, session = RetainPtr { session }]() mutable {
     160        if (_callback)
     161            _callback->sessionDidChangeContent(session);
     162    });
     163}
     164
     165- (void)pickerCanceledForSession:(SCContentSharingSession *)session
     166{
     167}
    140168@end
    141169
     
    235263
    236264    captureFailed();
     265}
     266
     267void ScreenCaptureKitCaptureSource::sessionDidChangeContent(RetainPtr<SCContentSharingSession> session)
     268{
     269    ASSERT(isMainThread());
     270
     271    if ([session content].type == SCContentFilterTypeNothing)
     272        return;
     273
     274    std::optional<CaptureDevice> device;
     275    SCContentFilter* content = [session content];
     276    switch (content.type) {
     277    case SCContentFilterTypeDesktopIndependentWindow:
     278        device = windowCaptureDeviceWithPersistentID(String::number(content.desktopIndependentWindowInfo.window.windowID));
     279        m_content = content.desktopIndependentWindowInfo.window;
     280        break;
     281    case SCContentFilterTypeDisplay:
     282        device = screenCaptureDeviceWithPersistentID(String::number(content.displayInfo.display.displayID));
     283        m_content = content.displayInfo.display;
     284        break;
     285    case SCContentFilterTypeNothing:
     286    case SCContentFilterTypeAppsAndWindowsPinnedToDisplay:
     287    case SCContentFilterTypeClientShouldImplementDefault:
     288        ASSERT_NOT_REACHED();
     289        return;
     290    }
     291    if (!device) {
     292        streamFailedWithError(nil, "Failed find CaptureDevice after content change"_s);
     293        return;
     294    }
     295
     296    m_captureDevice = device.value();
     297    m_intrinsicSize = { };
     298    configurationChanged();
     299}
     300
     301void ScreenCaptureKitCaptureSource::sessionDidEnd(RetainPtr<SCContentSharingSession>)
     302{
     303    streamFailedWithError(nil, "sessionDidEnd"_s);
    237304}
    238305
     
    349416        m_contentStream = adoptNS([PAL::allocSCStreamInstance() initWithFilter:m_contentFilter.get() captureOutputProperties:streamConfiguration().get() delegate:m_captureHelper.get()]);
    350417
     418#if HAVE(SC_CONTENT_SHARING_SESSION)
     419    if (ScreenCaptureKitSharingSessionManager::isAvailable()) {
     420        m_contentSharingSession = ScreenCaptureKitSharingSessionManager::singleton().takeSharingSessionForFilter(m_contentFilter.get());
     421        if (!m_contentSharingSession) {
     422            streamFailedWithError(nil, "Failed to get SharingSession"_s);
     423            return;
     424        }
     425
     426        m_contentStream = adoptNS([PAL::allocSCStreamInstance() initWithSharingSession:m_contentSharingSession.get() captureOutputProperties:streamConfiguration().get() delegate:m_captureHelper.get()]);
     427    } else
     428#endif
     429        m_contentStream = adoptNS([PAL::allocSCStreamInstance() initWithFilter:m_contentFilter.get() captureOutputProperties:streamConfiguration().get() delegate:m_captureHelper.get()]);
     430
     431
    351432    if (!m_contentStream) {
    352         streamFailedWithError(nil, "Failed to allocate SLContentStream"_s);
     433        streamFailedWithError(nil, "Failed to allocate ContentStream"_s);
    353434        return;
    354435    }
     
    385466    if (m_intrinsicSize)
    386467        return m_intrinsicSize.value();
     468
     469    if (m_content) {
     470        auto frame = switchOn(m_content.value(),
     471            [] (const RetainPtr<SCDisplay> display) -> CGRect {
     472                return [display frame];
     473            },
     474            [] (const RetainPtr<SCWindow> window) -> CGRect {
     475                return [window frame];
     476            }
     477        );
     478
     479        return { static_cast<int>(frame.size.width), static_cast<int>(frame.size.height) };
     480    }
    387481
    388482    if (m_captureDevice.type() == CaptureDevice::DeviceType::Screen) {
  • trunk/Source/WebKit/ChangeLog

    r289694 r289696  
     12022-02-12  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [macOS] Use system window and screen picker when available
     4        https://bugs.webkit.org/show_bug.cgi?id=236531
     5        rdar://87111816
     6
     7        Reviewed by Jer Noble.
     8
     9        * Platform/spi/Cocoa/SafeBrowsingSPI.h:
     10        * UIProcess/mac/DisplayCaptureSessionManager.mm:
     11        (WebKit::DisplayCaptureSessionManager::alertForGetDisplayMedia): Update prompt strings.
     12        (WebKit::DisplayCaptureSessionManager::showWindowPicker): Use capture session
     13        manager when available.
     14        (WebKit::DisplayCaptureSessionManager::showScreenPicker): Ditto.
     15
    1162022-02-12  Kevin Turner  <kevin_turner@apple.com>
    217
  • trunk/Source/WebKit/Platform/spi/Cocoa/SafeBrowsingSPI.h

    r289573 r289696  
    2828#import <Foundation/Foundation.h>
    2929
    30 #if USE(APPLE_INTERNAL_SDK)
     30#if 0 && USE(APPLE_INTERNAL_SDK)
    3131
    3232#import <SafariSafeBrowsing/SafariSafeBrowsing.h>
  • trunk/Source/WebKit/UIProcess/mac/DisplayCaptureSessionManager.mm

    r288604 r289696  
    3737#import <WebCore/MockRealtimeMediaSourceCenter.h>
    3838#import <WebCore/ScreenCaptureKitCaptureSource.h>
     39#import <WebCore/ScreenCaptureKitSharingSessionManager.h>
    3940#import <WebCore/SecurityOriginData.h>
    4041#import <wtf/BlockPtr.h>
     
    142143
    143144    NSString *alertTitle = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to observe one of your windows or screens?", "Message for window and screen sharing prompt"), visibleOrigin];
    144     auto *allowWindowButtonString = WEB_UI_NSSTRING(@"Allow Observing a Window", "Allow window button title in window and screen sharing prompt");
    145     auto *allowScreenButtonString = WEB_UI_NSSTRING(@"Allow Observing a Screen", "Allow screen button title in window and screen sharing prompt");
     145    auto *allowWindowButtonString = WEB_UI_NSSTRING(@"Allow to Share Window", "Allow window button title in window and screen sharing prompt");
     146    auto *allowScreenButtonString = WEB_UI_NSSTRING(@"Allow to Share Screen", "Allow screen button title in window and screen sharing prompt");
    146147    auto *doNotAllowButtonString = WEB_UI_NSSTRING(@"Don’t Allow (window and screen sharing)", "Disallow button title in window and screen sharing prompt");
    147148
     
    199200    }
    200201
     202#if HAVE(SC_CONTENT_SHARING_SESSION)
     203    if (ScreenCaptureKitSharingSessionManager::isAvailable()) {
     204        ScreenCaptureKitSharingSessionManager::singleton().showWindowPicker(WTFMove(completionHandler));
     205        return;
     206    }
     207#endif
     208
    201209    alertForWindowSelection(page, origin, [completionHandler = WTFMove(completionHandler)] (std::optional<String> windowID, std::optional<String> windowTitle) mutable {
    202210
     
    217225        return;
    218226    }
     227
     228#if HAVE(SC_CONTENT_SHARING_SESSION)
     229    if (ScreenCaptureKitSharingSessionManager::isAvailable()) {
     230        ScreenCaptureKitSharingSessionManager::singleton().showScreenPicker(WTFMove(completionHandler));
     231        return;
     232    }
     233#endif
    219234
    220235    callOnMainRunLoop([completionHandler = WTFMove(completionHandler)] () mutable {
Note: See TracChangeset for help on using the changeset viewer.