3
3
// found in the LICENSE file.
4
4
5
5
#include < dwmapi.h>
6
+ #include < windows.devices.enumeration.h>
7
+ #include < wrl/client.h>
6
8
#include < iomanip>
7
9
8
10
#include " shell/browser/api/electron_api_system_preferences.h"
9
11
12
+ #include " base/win/core_winrt_util.h"
10
13
#include " base/win/wrapped_window_proc.h"
11
14
#include " shell/common/color_util.h"
12
15
#include " ui/base/win/shell.h"
@@ -20,6 +23,51 @@ namespace {
20
23
const wchar_t kSystemPreferencesWindowClass [] =
21
24
L" Electron_SystemPreferencesHostWindow" ;
22
25
26
+ using ABI::Windows::Devices::Enumeration::DeviceAccessStatus;
27
+ using ABI::Windows::Devices::Enumeration::DeviceClass;
28
+ using ABI::Windows::Devices::Enumeration::IDeviceAccessInformation;
29
+ using ABI::Windows::Devices::Enumeration::IDeviceAccessInformationStatics;
30
+ using Microsoft::WRL::ComPtr;
31
+
32
+ DeviceAccessStatus GetDeviceAccessStatus (DeviceClass device_class) {
33
+ ComPtr<IDeviceAccessInformationStatics> dev_access_info_statics;
34
+ HRESULT hr = base::win::GetActivationFactory<
35
+ IDeviceAccessInformationStatics,
36
+ RuntimeClass_Windows_Devices_Enumeration_DeviceAccessInformation>(
37
+ &dev_access_info_statics);
38
+ if (FAILED (hr)) {
39
+ VLOG (1 ) << " IDeviceAccessInformationStatics failed: " << hr;
40
+ return DeviceAccessStatus::DeviceAccessStatus_Allowed;
41
+ }
42
+
43
+ ComPtr<IDeviceAccessInformation> dev_access_info;
44
+ hr = dev_access_info_statics->CreateFromDeviceClass (device_class,
45
+ &dev_access_info);
46
+ if (FAILED (hr)) {
47
+ VLOG (1 ) << " IDeviceAccessInformation failed: " << hr;
48
+ return DeviceAccessStatus::DeviceAccessStatus_Allowed;
49
+ }
50
+
51
+ auto status = DeviceAccessStatus::DeviceAccessStatus_Unspecified;
52
+ dev_access_info->get_CurrentStatus (&status);
53
+ return status;
54
+ }
55
+
56
+ std::string ConvertDeviceAccessStatus (DeviceAccessStatus value) {
57
+ switch (value) {
58
+ case DeviceAccessStatus::DeviceAccessStatus_Unspecified:
59
+ return " not-determined" ;
60
+ case DeviceAccessStatus::DeviceAccessStatus_Allowed:
61
+ return " granted" ;
62
+ case DeviceAccessStatus::DeviceAccessStatus_DeniedBySystem:
63
+ return " restricted" ;
64
+ case DeviceAccessStatus::DeviceAccessStatus_DeniedByUser:
65
+ return " denied" ;
66
+ default :
67
+ return " unknown" ;
68
+ }
69
+ }
70
+
23
71
} // namespace
24
72
25
73
namespace api {
@@ -117,6 +165,24 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
117
165
return ToRGBHex (color_utils::GetSysSkColor (id));
118
166
}
119
167
168
+ std::string SystemPreferences::GetMediaAccessStatus (
169
+ const std::string& media_type,
170
+ gin_helper::Arguments* args) {
171
+ if (media_type == " camera" ) {
172
+ return ConvertDeviceAccessStatus (
173
+ GetDeviceAccessStatus (DeviceClass::DeviceClass_VideoCapture));
174
+ } else if (media_type == " microphone" ) {
175
+ return ConvertDeviceAccessStatus (
176
+ GetDeviceAccessStatus (DeviceClass::DeviceClass_AudioCapture));
177
+ } else if (media_type == " screen" ) {
178
+ return ConvertDeviceAccessStatus (
179
+ DeviceAccessStatus::DeviceAccessStatus_Allowed);
180
+ } else {
181
+ args->ThrowError (" Invalid media type" );
182
+ return std::string ();
183
+ }
184
+ }
185
+
120
186
void SystemPreferences::InitializeWindow () {
121
187
invertered_color_scheme_ = IsInvertedColorScheme ();
122
188
high_contrast_color_scheme_ = IsHighContrastColorScheme ();
0 commit comments