diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index 3ca1c5c65ae25..5f50890ee47fa 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -32,6 +32,8 @@ static_library("chrome") { "//chrome/browser/icon_loader_win.cc", "//chrome/browser/icon_manager.cc", "//chrome/browser/icon_manager.h", + "//chrome/browser/media/webrtc/system_media_capture_permissions_mac.h", + "//chrome/browser/media/webrtc/system_media_capture_permissions_mac.mm", "//chrome/browser/net/chrome_mojo_proxy_resolver_factory.cc", "//chrome/browser/net/chrome_mojo_proxy_resolver_factory.h", "//chrome/browser/net/proxy_config_monitor.cc", diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index f8e12d04d0788..bf376ce46a9a0 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -91,7 +91,11 @@ The `desktopCapturer` module has the following methods: Returns `Promise` - Resolves with an array of [`DesktopCapturerSource`](structures/desktop-capturer-source.md) objects, each `DesktopCapturerSource` represents a screen or an individual window that can be captured. +**Note** Capturing the screen contents requires user consent on macOS 10.15 Catalina or higher, +which can detected by [`systemPreferences.getMediaAccessStatus`]. + [`navigator.mediaDevices.getUserMedia`]: https://developer.mozilla.org/en/docs/Web/API/MediaDevices/getUserMedia +[`systemPreferences.getMediaAccessStatus`]: system-preferences.md#systempreferencesgetmediaaccessstatusmediatype-macos ## Caveats diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 38672a4512818..aa27516197337 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -434,11 +434,13 @@ Returns `Boolean` - `true` if the current process is a trusted accessibility cli ### `systemPreferences.getMediaAccessStatus(mediaType)` _macOS_ -* `mediaType` String - `microphone` or `camera`. +* `mediaType` String - Can be `microphone`, `camera` or `screen`. Returns `String` - Can be `not-determined`, `granted`, `denied`, `restricted` or `unknown`. -This user consent was not required until macOS 10.14 Mojave, so this method will always return `granted` if your system is running 10.13 High Sierra or lower. +This user consent was not required on macOS 10.13 High Sierra or lower so this method will always return `granted`. +macOS 10.14 Mojave or higher requires consent for `microphone` and `camera` access. +macOS 10.15 Catalina or higher requires consent for `screen` access. ### `systemPreferences.askForMediaAccess(mediaType)` _macOS_ diff --git a/shell/browser/api/atom_api_system_preferences_mac.mm b/shell/browser/api/atom_api_system_preferences_mac.mm index b203587c327e7..2e24012d5dd61 100644 --- a/shell/browser/api/atom_api_system_preferences_mac.mm +++ b/shell/browser/api/atom_api_system_preferences_mac.mm @@ -21,6 +21,7 @@ #include "base/strings/sys_string_conversions.h" #include "base/threading/sequenced_task_runner_handle.h" #include "base/values.h" +#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h" #include "native_mate/object_template_builder_deprecated.h" #include "net/base/mac/url_conversions.h" #include "shell/browser/mac/atom_application.h" @@ -102,15 +103,17 @@ AVMediaType ParseMediaType(const std::string& media_type) { } } -std::string ConvertAuthorizationStatus(AVAuthorizationStatusMac status) { - switch (status) { - case AVAuthorizationStatusNotDeterminedMac: +std::string ConvertSystemPermission( + system_media_permissions::SystemPermission value) { + using SystemPermission = system_media_permissions::SystemPermission; + switch (value) { + case SystemPermission::kNotDetermined: return "not-determined"; - case AVAuthorizationStatusRestrictedMac: + case SystemPermission::kRestricted: return "restricted"; - case AVAuthorizationStatusDeniedMac: + case SystemPermission::kDenied: return "denied"; - case AVAuthorizationStatusAuthorizedMac: + case SystemPermission::kAllowed: return "granted"; default: return "unknown"; @@ -597,14 +600,15 @@ AVMediaType ParseMediaType(const std::string& media_type) { std::string SystemPreferences::GetMediaAccessStatus( const std::string& media_type, mate::Arguments* args) { - if (auto type = ParseMediaType(media_type)) { - if (@available(macOS 10.14, *)) { - return ConvertAuthorizationStatus( - [AVCaptureDevice authorizationStatusForMediaType:type]); - } else { - // access always allowed pre-10.14 Mojave - return ConvertAuthorizationStatus(AVAuthorizationStatusAuthorizedMac); - } + if (media_type == "camera") { + return ConvertSystemPermission( + system_media_permissions::CheckSystemVideoCapturePermission()); + } else if (media_type == "microphone") { + return ConvertSystemPermission( + system_media_permissions::CheckSystemAudioCapturePermission()); + } else if (media_type == "screen") { + return ConvertSystemPermission( + system_media_permissions::CheckSystemScreenCapturePermission()); } else { args->ThrowError("Invalid media type"); return std::string(); diff --git a/shell/browser/mac/atom_application.h b/shell/browser/mac/atom_application.h index 0058b8e852af9..a9d1817b4e6e6 100644 --- a/shell/browser/mac/atom_application.h +++ b/shell/browser/mac/atom_application.h @@ -9,80 +9,6 @@ #import #import -// Forward Declare Appearance APIs -@interface NSApplication (MojaveSDK) -@property(copy, readonly) - NSAppearance* effectiveAppearance API_AVAILABLE(macosx(10.14)); -@property(copy, readonly) NSAppearance* appearance API_AVAILABLE(macosx(10.14)); -- (void)setAppearance:(NSAppearance*)appearance API_AVAILABLE(macosx(10.14)); -@end - -// forward declare Access APIs -typedef NSString* AVMediaType NS_EXTENSIBLE_STRING_ENUM; - -AVF_EXPORT AVMediaType const AVMediaTypeVideo; -AVF_EXPORT AVMediaType const AVMediaTypeAudio; - -typedef NS_ENUM(NSInteger, AVAuthorizationStatusMac) { - AVAuthorizationStatusNotDeterminedMac = 0, - AVAuthorizationStatusRestrictedMac = 1, - AVAuthorizationStatusDeniedMac = 2, - AVAuthorizationStatusAuthorizedMac = 3, -}; - -@interface AVCaptureDevice (MojaveSDK) -+ (void)requestAccessForMediaType:(AVMediaType)mediaType - completionHandler:(void (^)(BOOL granted))handler - API_AVAILABLE(macosx(10.14)); -+ (AVAuthorizationStatusMac)authorizationStatusForMediaType: - (AVMediaType)mediaType API_AVAILABLE(macosx(10.14)); -@end - -@interface NSColor (MojaveSDK) -@property(class, strong, readonly) - NSColor* controlAccentColor API_AVAILABLE(macosx(10.14)); - -// macOS system colors -@property(class, strong, readonly) - NSColor* systemBlueColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemBrownColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemGrayColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemGreenColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemOrangeColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemPinkColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemPurpleColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemRedColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* systemYellowColor API_AVAILABLE(macosx(10.10)); - -// misc dynamic colors declarations -@property(class, strong, readonly) - NSColor* linkColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* placeholderTextColor API_AVAILABLE(macosx(10.10)); -@property(class, strong, readonly) - NSColor* findHighlightColor API_AVAILABLE(macosx(10.13)); -@property(class, strong, readonly) - NSColor* separatorColor API_AVAILABLE(macosx(10.14)); -@property(class, strong, readonly) - NSColor* selectedContentBackgroundColor API_AVAILABLE(macosx(10.14)); -@property(class, strong, readonly) - NSColor* unemphasizedSelectedContentBackgroundColor API_AVAILABLE( - macosx(10.14)); -@property(class, strong, readonly) - NSColor* unemphasizedSelectedTextBackgroundColor API_AVAILABLE(macosx(10.14) - ); -@property(class, strong, readonly) - NSColor* unemphasizedSelectedTextColor API_AVAILABLE(macosx(10.14)); -@end - @interface AtomApplication : NSApplication { diff --git a/spec-main/api-system-preferences-spec.ts b/spec-main/api-system-preferences-spec.ts index 85e776995dff1..158c0a08626c0 100644 --- a/spec-main/api-system-preferences-spec.ts +++ b/spec-main/api-system-preferences-spec.ts @@ -246,6 +246,11 @@ describe('systemPreferences module', () => { const microphoneStatus = systemPreferences.getMediaAccessStatus('microphone') expect(statuses).to.include(microphoneStatus) }) + + it('returns an access status for a screen access request', () => { + const screenStatus = systemPreferences.getMediaAccessStatus('screen') + expect(statuses).to.include(screenStatus) + }) }) describe('systemPreferences.getAnimationSettings()', () => {