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
|
@ -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 "net/base/mac/url_conversions.h"
|
||||
#include "shell/browser/mac/atom_application.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
|
||||
|
||||
void SystemPreferences::PostNotification(const std::string& name,
|
||||
|
@ -574,24 +592,15 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
|
|||
std::string SystemPreferences::GetMediaAccessStatus(
|
||||
const std::string& media_type,
|
||||
gin_helper::Arguments* args) {
|
||||
if (auto type = ParseMediaType(media_type)) {
|
||||
if (@available(macOS 10.14, *)) {
|
||||
switch ([AVCaptureDevice authorizationStatusForMediaType:type]) {
|
||||
case AVAuthorizationStatusNotDetermined:
|
||||
return "not-determined";
|
||||
case AVAuthorizationStatusRestricted:
|
||||
return "restricted";
|
||||
case AVAuthorizationStatusDenied:
|
||||
return "denied";
|
||||
case AVAuthorizationStatusAuthorized:
|
||||
return "granted";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
} else {
|
||||
// access always allowed pre-10.14 Mojave
|
||||
return "granted";
|
||||
}
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue