feat: add 'screen' to systemPreferences.getMediaAccessStatus() (#20764)
* feat: add 'screen' to systemPreferences.getMediaAccessStatus() * Update docs/api/system-preferences.md
This commit is contained in:
parent
ba85d4c3bb
commit
97e2569f02
5 changed files with 42 additions and 20 deletions
|
@ -32,6 +32,8 @@ static_library("chrome") {
|
||||||
"//chrome/browser/icon_loader_win.cc",
|
"//chrome/browser/icon_loader_win.cc",
|
||||||
"//chrome/browser/icon_manager.cc",
|
"//chrome/browser/icon_manager.cc",
|
||||||
"//chrome/browser/icon_manager.h",
|
"//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.cc",
|
||||||
"//chrome/browser/net/chrome_mojo_proxy_resolver_factory.h",
|
"//chrome/browser/net/chrome_mojo_proxy_resolver_factory.h",
|
||||||
"//chrome/browser/net/proxy_config_monitor.cc",
|
"//chrome/browser/net/proxy_config_monitor.cc",
|
||||||
|
|
|
@ -91,7 +91,11 @@ The `desktopCapturer` module has the following methods:
|
||||||
|
|
||||||
Returns `Promise<DesktopCapturerSource[]>` - 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.
|
Returns `Promise<DesktopCapturerSource[]>` - 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
|
[`navigator.mediaDevices.getUserMedia`]: https://developer.mozilla.org/en/docs/Web/API/MediaDevices/getUserMedia
|
||||||
|
[`systemPreferences.getMediaAccessStatus`]: system-preferences.md#systempreferencesgetmediaaccessstatusmediatype-macos
|
||||||
|
|
||||||
## Caveats
|
## Caveats
|
||||||
|
|
||||||
|
|
|
@ -434,11 +434,13 @@ Returns `Boolean` - `true` if the current process is a trusted accessibility cli
|
||||||
|
|
||||||
### `systemPreferences.getMediaAccessStatus(mediaType)` _macOS_
|
### `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`.
|
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_
|
### `systemPreferences.askForMediaAccess(mediaType)` _macOS_
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "base/threading/sequenced_task_runner_handle.h"
|
#include "base/threading/sequenced_task_runner_handle.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
|
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
|
||||||
#include "net/base/mac/url_conversions.h"
|
#include "net/base/mac/url_conversions.h"
|
||||||
#include "shell/browser/mac/atom_application.h"
|
#include "shell/browser/mac/atom_application.h"
|
||||||
#include "shell/browser/mac/dict_util.h"
|
#include "shell/browser/mac/dict_util.h"
|
||||||
|
@ -103,6 +104,23 @@ AVMediaType ParseMediaType(const std::string& media_type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ConvertSystemPermission(
|
||||||
|
system_media_permissions::SystemPermission value) {
|
||||||
|
using SystemPermission = system_media_permissions::SystemPermission;
|
||||||
|
switch (value) {
|
||||||
|
case SystemPermission::kNotDetermined:
|
||||||
|
return "not-determined";
|
||||||
|
case SystemPermission::kRestricted:
|
||||||
|
return "restricted";
|
||||||
|
case SystemPermission::kDenied:
|
||||||
|
return "denied";
|
||||||
|
case SystemPermission::kAllowed:
|
||||||
|
return "granted";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void SystemPreferences::PostNotification(const std::string& name,
|
void SystemPreferences::PostNotification(const std::string& name,
|
||||||
|
@ -574,24 +592,15 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
|
||||||
std::string SystemPreferences::GetMediaAccessStatus(
|
std::string SystemPreferences::GetMediaAccessStatus(
|
||||||
const std::string& media_type,
|
const std::string& media_type,
|
||||||
gin_helper::Arguments* args) {
|
gin_helper::Arguments* args) {
|
||||||
if (auto type = ParseMediaType(media_type)) {
|
if (media_type == "camera") {
|
||||||
if (@available(macOS 10.14, *)) {
|
return ConvertSystemPermission(
|
||||||
switch ([AVCaptureDevice authorizationStatusForMediaType:type]) {
|
system_media_permissions::CheckSystemVideoCapturePermission());
|
||||||
case AVAuthorizationStatusNotDetermined:
|
} else if (media_type == "microphone") {
|
||||||
return "not-determined";
|
return ConvertSystemPermission(
|
||||||
case AVAuthorizationStatusRestricted:
|
system_media_permissions::CheckSystemAudioCapturePermission());
|
||||||
return "restricted";
|
} else if (media_type == "screen") {
|
||||||
case AVAuthorizationStatusDenied:
|
return ConvertSystemPermission(
|
||||||
return "denied";
|
system_media_permissions::CheckSystemScreenCapturePermission());
|
||||||
case AVAuthorizationStatusAuthorized:
|
|
||||||
return "granted";
|
|
||||||
default:
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// access always allowed pre-10.14 Mojave
|
|
||||||
return "granted";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError("Invalid media type");
|
args->ThrowError("Invalid media type");
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
|
@ -246,6 +246,11 @@ describe('systemPreferences module', () => {
|
||||||
const microphoneStatus = systemPreferences.getMediaAccessStatus('microphone')
|
const microphoneStatus = systemPreferences.getMediaAccessStatus('microphone')
|
||||||
expect(statuses).to.include(microphoneStatus)
|
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()', () => {
|
describe('systemPreferences.getAnimationSettings()', () => {
|
||||||
|
|
Loading…
Reference in a new issue