2016-04-24 12:13:46 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_system_preferences.h"
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2019-05-02 12:05:37 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2016-04-25 05:25:14 +00:00
|
|
|
|
2018-12-04 15:54:13 +00:00
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2016-04-25 03:35:09 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2019-02-14 02:36:28 +00:00
|
|
|
#import <LocalAuthentication/LocalAuthentication.h>
|
|
|
|
#import <Security/Security.h>
|
2016-04-25 03:35:09 +00:00
|
|
|
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
#include "base/apple/scoped_cftyperef.h"
|
2024-01-05 11:18:31 +00:00
|
|
|
#include "base/containers/flat_map.h"
|
2019-01-03 21:24:55 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2016-04-25 05:25:14 +00:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2021-11-24 08:45:59 +00:00
|
|
|
#include "base/task/sequenced_task_runner.h"
|
2016-05-18 05:40:19 +00:00
|
|
|
#include "base/values.h"
|
2019-11-13 21:47:51 +00:00
|
|
|
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
|
2024-02-14 17:33:32 +00:00
|
|
|
#include "net/base/apple/url_conversions.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/mac/dict_util.h"
|
|
|
|
#include "shell/browser/mac/electron_application.h"
|
2021-03-13 07:31:08 +00:00
|
|
|
#include "shell/common/color_util.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_converters/gurl_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2021-07-02 00:51:37 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/common/process_util.h"
|
2021-03-13 07:31:08 +00:00
|
|
|
#include "skia/ext/skia_utils_mac.h"
|
2019-07-17 00:06:32 +00:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2016-04-25 05:25:14 +00:00
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
namespace gin {
|
|
|
|
|
2018-09-27 15:33:31 +00:00
|
|
|
template <>
|
|
|
|
struct Converter<NSAppearance*> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2023-07-18 22:26:27 +00:00
|
|
|
NSAppearance* __strong* out) {
|
2018-09-27 15:33:31 +00:00
|
|
|
if (val->IsNull()) {
|
|
|
|
*out = nil;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name;
|
2019-10-24 05:47:58 +00:00
|
|
|
if (!gin::ConvertFromV8(isolate, val, &name)) {
|
2018-09-27 15:33:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "light") {
|
|
|
|
*out = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
|
|
|
|
return true;
|
|
|
|
} else if (name == "dark") {
|
2023-07-01 20:22:55 +00:00
|
|
|
*out = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
|
2018-09-27 15:33:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, NSAppearance* val) {
|
2023-07-01 20:22:55 +00:00
|
|
|
if (val == nil)
|
2018-09-27 15:33:31 +00:00
|
|
|
return v8::Null(isolate);
|
2018-10-01 14:52:04 +00:00
|
|
|
|
2019-06-07 16:55:29 +00:00
|
|
|
if ([val.name isEqualToString:NSAppearanceNameAqua]) {
|
2019-10-24 05:47:58 +00:00
|
|
|
return gin::ConvertToV8(isolate, "light");
|
2023-07-01 20:22:55 +00:00
|
|
|
} else if ([val.name isEqualToString:NSAppearanceNameDarkAqua]) {
|
|
|
|
return gin::ConvertToV8(isolate, "dark");
|
2018-09-27 15:33:31 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
return gin::ConvertToV8(isolate, "unknown");
|
2018-09-27 15:33:31 +00:00
|
|
|
}
|
|
|
|
};
|
2019-10-24 05:47:58 +00:00
|
|
|
|
|
|
|
} // namespace gin
|
2018-09-27 15:33:31 +00:00
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2016-04-25 05:25:14 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int g_next_id = 0;
|
|
|
|
|
|
|
|
// The map to convert |id| to |int|.
|
2024-01-05 11:18:31 +00:00
|
|
|
base::flat_map<int, id> g_id_map;
|
2016-04-25 05:25:14 +00:00
|
|
|
|
2018-12-04 15:54:13 +00:00
|
|
|
AVMediaType ParseMediaType(const std::string& media_type) {
|
|
|
|
if (media_type == "camera") {
|
|
|
|
return AVMediaTypeVideo;
|
|
|
|
} else if (media_type == "microphone") {
|
|
|
|
return AVMediaTypeAudio;
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 21:47:51 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 02:32:55 +00:00
|
|
|
NSNotificationCenter* GetNotificationCenter(NotificationCenterKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case NotificationCenterKind::kNSDistributedNotificationCenter:
|
|
|
|
return [NSDistributedNotificationCenter defaultCenter];
|
|
|
|
case NotificationCenterKind::kNSNotificationCenter:
|
|
|
|
return [NSNotificationCenter defaultCenter];
|
|
|
|
case NotificationCenterKind::kNSWorkspaceNotificationCenter:
|
|
|
|
return [[NSWorkspace sharedWorkspace] notificationCenter];
|
|
|
|
default:
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 05:25:14 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-12-14 21:46:46 +00:00
|
|
|
void SystemPreferences::PostNotification(const std::string& name,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict user_info,
|
2020-07-28 18:03:30 +00:00
|
|
|
gin::Arguments* args) {
|
2018-12-14 21:46:46 +00:00
|
|
|
bool immediate = false;
|
|
|
|
args->GetNext(&immediate);
|
|
|
|
|
|
|
|
NSDistributedNotificationCenter* center =
|
|
|
|
[NSDistributedNotificationCenter defaultCenter];
|
2022-06-23 06:28:41 +00:00
|
|
|
[center
|
|
|
|
postNotificationName:base::SysUTF8ToNSString(name)
|
|
|
|
object:nil
|
2022-07-05 15:25:18 +00:00
|
|
|
userInfo:DictionaryValueToNSDictionary(std::move(user_info))
|
2022-06-23 06:28:41 +00:00
|
|
|
deliverImmediately:immediate];
|
2018-03-22 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:34:21 +00:00
|
|
|
int SystemPreferences::SubscribeNotification(
|
2022-04-13 20:02:33 +00:00
|
|
|
v8::Local<v8::Value> maybe_name,
|
2019-06-10 16:34:21 +00:00
|
|
|
const NotificationCallback& callback) {
|
2020-12-08 04:39:33 +00:00
|
|
|
return DoSubscribeNotification(
|
2022-04-13 20:02:33 +00:00
|
|
|
maybe_name, callback,
|
|
|
|
NotificationCenterKind::kNSDistributedNotificationCenter);
|
2018-03-22 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemPreferences::UnsubscribeNotification(int request_id) {
|
2020-12-08 04:39:33 +00:00
|
|
|
DoUnsubscribeNotification(
|
|
|
|
request_id, NotificationCenterKind::kNSDistributedNotificationCenter);
|
2016-08-05 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
void SystemPreferences::PostLocalNotification(const std::string& name,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict user_info) {
|
2018-12-14 21:46:46 +00:00
|
|
|
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
2022-06-23 06:28:41 +00:00
|
|
|
[center
|
|
|
|
postNotificationName:base::SysUTF8ToNSString(name)
|
|
|
|
object:nil
|
2022-07-05 15:25:18 +00:00
|
|
|
userInfo:DictionaryValueToNSDictionary(std::move(user_info))];
|
2016-08-05 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:34:21 +00:00
|
|
|
int SystemPreferences::SubscribeLocalNotification(
|
2022-04-13 20:02:33 +00:00
|
|
|
v8::Local<v8::Value> maybe_name,
|
2019-06-10 16:34:21 +00:00
|
|
|
const NotificationCallback& callback) {
|
2022-04-13 20:02:33 +00:00
|
|
|
return DoSubscribeNotification(maybe_name, callback,
|
2020-12-08 04:39:33 +00:00
|
|
|
NotificationCenterKind::kNSNotificationCenter);
|
2016-08-05 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:41:03 +00:00
|
|
|
void SystemPreferences::UnsubscribeLocalNotification(int request_id) {
|
2020-12-08 04:39:33 +00:00
|
|
|
DoUnsubscribeNotification(request_id,
|
|
|
|
NotificationCenterKind::kNSNotificationCenter);
|
2016-06-21 00:48:42 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
void SystemPreferences::PostWorkspaceNotification(const std::string& name,
|
|
|
|
base::Value::Dict user_info) {
|
2018-12-14 21:46:46 +00:00
|
|
|
NSNotificationCenter* center =
|
|
|
|
[[NSWorkspace sharedWorkspace] notificationCenter];
|
2022-06-23 06:28:41 +00:00
|
|
|
[center
|
|
|
|
postNotificationName:base::SysUTF8ToNSString(name)
|
|
|
|
object:nil
|
2022-07-05 15:25:18 +00:00
|
|
|
userInfo:DictionaryValueToNSDictionary(std::move(user_info))];
|
2016-06-21 00:48:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:34:21 +00:00
|
|
|
int SystemPreferences::SubscribeWorkspaceNotification(
|
2022-04-13 20:02:33 +00:00
|
|
|
v8::Local<v8::Value> maybe_name,
|
2019-06-10 16:34:21 +00:00
|
|
|
const NotificationCallback& callback) {
|
2020-12-08 04:39:33 +00:00
|
|
|
return DoSubscribeNotification(
|
2022-04-13 20:02:33 +00:00
|
|
|
maybe_name, callback,
|
|
|
|
NotificationCenterKind::kNSWorkspaceNotificationCenter);
|
2016-06-21 00:48:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:41:03 +00:00
|
|
|
void SystemPreferences::UnsubscribeWorkspaceNotification(int request_id) {
|
2020-12-08 04:39:33 +00:00
|
|
|
DoUnsubscribeNotification(
|
|
|
|
request_id, NotificationCenterKind::kNSWorkspaceNotificationCenter);
|
2018-03-22 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:34:21 +00:00
|
|
|
int SystemPreferences::DoSubscribeNotification(
|
2022-04-13 20:02:33 +00:00
|
|
|
v8::Local<v8::Value> maybe_name,
|
2019-06-10 16:34:21 +00:00
|
|
|
const NotificationCallback& callback,
|
|
|
|
NotificationCenterKind kind) {
|
2016-04-25 05:25:14 +00:00
|
|
|
int request_id = g_next_id++;
|
2019-06-10 16:34:21 +00:00
|
|
|
__block NotificationCallback copied_callback = callback;
|
2018-04-20 18:47:04 +00:00
|
|
|
|
2022-04-13 20:02:33 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
std::string name_str;
|
|
|
|
if (!(maybe_name->IsNull() ||
|
|
|
|
gin::ConvertFromV8(isolate, maybe_name, &name_str))) {
|
|
|
|
isolate->ThrowException(v8::Exception::Error(
|
|
|
|
gin::StringToV8(isolate, "Must pass null or a string")));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* name = maybe_name->IsNull() ? nil : base::SysUTF8ToNSString(name_str);
|
|
|
|
|
2021-05-24 02:32:55 +00:00
|
|
|
g_id_map[request_id] = [GetNotificationCenter(kind)
|
2022-04-13 20:02:33 +00:00
|
|
|
addObserverForName:name
|
2018-04-20 18:47:04 +00:00
|
|
|
object:nil
|
|
|
|
queue:nil
|
|
|
|
usingBlock:^(NSNotification* notification) {
|
2019-07-11 17:06:31 +00:00
|
|
|
std::string object = "";
|
|
|
|
if ([notification.object isKindOfClass:[NSString class]]) {
|
|
|
|
object = base::SysNSStringToUTF8(notification.object);
|
|
|
|
}
|
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
if (notification.userInfo) {
|
2019-06-10 16:34:21 +00:00
|
|
|
copied_callback.Run(
|
2019-10-30 05:30:59 +00:00
|
|
|
base::SysNSStringToUTF8(notification.name),
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value(NSDictionaryToValue(notification.userInfo)),
|
2019-07-11 17:06:31 +00:00
|
|
|
object);
|
2018-04-20 18:47:04 +00:00
|
|
|
} else {
|
2019-06-10 16:34:21 +00:00
|
|
|
copied_callback.Run(
|
|
|
|
base::SysNSStringToUTF8(notification.name),
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value(base::Value::Dict()), object);
|
2018-04-20 18:47:04 +00:00
|
|
|
}
|
|
|
|
}];
|
2019-06-10 16:34:21 +00:00
|
|
|
return request_id;
|
2016-04-25 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
void SystemPreferences::DoUnsubscribeNotification(int request_id,
|
|
|
|
NotificationCenterKind kind) {
|
2016-04-25 05:25:14 +00:00
|
|
|
auto iter = g_id_map.find(request_id);
|
|
|
|
if (iter != g_id_map.end()) {
|
|
|
|
id observer = iter->second;
|
2021-05-24 02:32:55 +00:00
|
|
|
[GetNotificationCenter(kind) removeObserver:observer];
|
2016-04-25 05:25:14 +00:00
|
|
|
g_id_map.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 06:35:52 +00:00
|
|
|
v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
2020-07-28 18:03:30 +00:00
|
|
|
v8::Isolate* isolate,
|
2018-04-20 18:47:04 +00:00
|
|
|
const std::string& name,
|
|
|
|
const std::string& type) {
|
2016-04-25 06:35:52 +00:00
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSString* key = base::SysUTF8ToNSString(name);
|
|
|
|
if (type == "string") {
|
2019-10-24 05:47:58 +00:00
|
|
|
return gin::StringToV8(
|
2020-07-28 18:03:30 +00:00
|
|
|
isolate, base::SysNSStringToUTF8([defaults stringForKey:key]));
|
2016-04-25 06:35:52 +00:00
|
|
|
} else if (type == "boolean") {
|
2020-07-28 18:03:30 +00:00
|
|
|
return v8::Boolean::New(isolate, [defaults boolForKey:key]);
|
2016-04-25 06:35:52 +00:00
|
|
|
} else if (type == "float") {
|
2020-07-28 18:03:30 +00:00
|
|
|
return v8::Number::New(isolate, [defaults floatForKey:key]);
|
2016-04-25 06:35:52 +00:00
|
|
|
} else if (type == "integer") {
|
2020-07-28 18:03:30 +00:00
|
|
|
return v8::Integer::New(isolate, [defaults integerForKey:key]);
|
2016-04-25 06:35:52 +00:00
|
|
|
} else if (type == "double") {
|
2020-07-28 18:03:30 +00:00
|
|
|
return v8::Number::New(isolate, [defaults doubleForKey:key]);
|
2016-04-25 06:35:52 +00:00
|
|
|
} else if (type == "url") {
|
2020-07-28 18:03:30 +00:00
|
|
|
return gin::ConvertToV8(isolate,
|
2019-10-24 05:47:58 +00:00
|
|
|
net::GURLWithNSURL([defaults URLForKey:key]));
|
2016-06-02 02:21:17 +00:00
|
|
|
} else if (type == "array") {
|
2022-06-23 06:28:41 +00:00
|
|
|
return gin::ConvertToV8(
|
|
|
|
isolate, base::Value(NSArrayToValue([defaults arrayForKey:key])));
|
2016-06-02 02:21:17 +00:00
|
|
|
} else if (type == "dictionary") {
|
2022-06-23 06:28:41 +00:00
|
|
|
return gin::ConvertToV8(
|
|
|
|
isolate,
|
|
|
|
base::Value(NSDictionaryToValue([defaults dictionaryForKey:key])));
|
2016-06-02 01:55:20 +00:00
|
|
|
} else {
|
2020-07-28 18:03:30 +00:00
|
|
|
return v8::Undefined(isolate);
|
2016-06-02 01:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 18:03:30 +00:00
|
|
|
void SystemPreferences::RegisterDefaults(gin::Arguments* args) {
|
2022-10-03 20:21:00 +00:00
|
|
|
base::Value::Dict dict_value;
|
2017-12-12 18:08:09 +00:00
|
|
|
|
2022-10-03 20:21:00 +00:00
|
|
|
if (!args->GetNext(&dict_value)) {
|
2020-07-28 18:03:30 +00:00
|
|
|
args->ThrowError();
|
2022-07-05 15:25:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
@try {
|
2022-10-03 20:21:00 +00:00
|
|
|
NSDictionary* dict = DictionaryValueToNSDictionary(std::move(dict_value));
|
2022-07-05 15:25:18 +00:00
|
|
|
for (id key in dict) {
|
|
|
|
id value = [dict objectForKey:key];
|
|
|
|
if ([value isKindOfClass:[NSNull class]] || value == nil) {
|
|
|
|
args->ThrowError();
|
|
|
|
return;
|
2017-12-13 19:02:43 +00:00
|
|
|
}
|
2017-12-12 18:08:09 +00:00
|
|
|
}
|
2022-07-05 15:25:18 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
|
|
|
} @catch (NSException* exception) {
|
|
|
|
args->ThrowError();
|
2017-12-12 18:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 23:08:22 +00:00
|
|
|
void SystemPreferences::SetUserDefault(const std::string& name,
|
|
|
|
const std::string& type,
|
2020-07-28 18:03:30 +00:00
|
|
|
gin::Arguments* args) {
|
2016-11-28 23:08:22 +00:00
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSString* key = base::SysUTF8ToNSString(name);
|
|
|
|
if (type == "string") {
|
|
|
|
std::string value;
|
2020-05-09 22:38:15 +00:00
|
|
|
if (args->GetNext(&value)) {
|
|
|
|
[defaults setObject:base::SysUTF8ToNSString(value) forKey:key];
|
2016-11-28 23:08:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "boolean") {
|
|
|
|
bool value;
|
2020-07-28 18:03:30 +00:00
|
|
|
v8::Local<v8::Value> next = args->PeekNext();
|
|
|
|
if (!next.IsEmpty() && next->IsBoolean() && args->GetNext(&value)) {
|
2020-05-09 22:38:15 +00:00
|
|
|
[defaults setBool:value forKey:key];
|
2016-11-28 23:08:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "float") {
|
|
|
|
float value;
|
2020-05-09 22:38:15 +00:00
|
|
|
if (args->GetNext(&value)) {
|
|
|
|
[defaults setFloat:value forKey:key];
|
2016-11-28 23:08:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "integer") {
|
|
|
|
int value;
|
2020-05-09 22:38:15 +00:00
|
|
|
if (args->GetNext(&value)) {
|
|
|
|
[defaults setInteger:value forKey:key];
|
2016-11-28 23:08:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "double") {
|
|
|
|
double value;
|
2020-05-09 22:38:15 +00:00
|
|
|
if (args->GetNext(&value)) {
|
|
|
|
[defaults setDouble:value forKey:key];
|
2016-11-28 23:08:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "url") {
|
|
|
|
GURL value;
|
2020-05-09 22:38:15 +00:00
|
|
|
if (args->GetNext(&value)) {
|
|
|
|
if (NSURL* url = net::NSURLWithGURL(value)) {
|
|
|
|
[defaults setURL:url forKey:key];
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 23:08:22 +00:00
|
|
|
}
|
|
|
|
} else if (type == "array") {
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value value;
|
|
|
|
if (args->GetNext(&value) && value.is_list()) {
|
|
|
|
if (NSArray* array = ListValueToNSArray(value.GetList())) {
|
2020-05-09 22:38:15 +00:00
|
|
|
[defaults setObject:array forKey:key];
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 23:08:22 +00:00
|
|
|
}
|
|
|
|
} else if (type == "dictionary") {
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value value;
|
|
|
|
if (args->GetNext(&value) && value.is_dict()) {
|
|
|
|
if (NSDictionary* dict = DictionaryValueToNSDictionary(value.GetDict())) {
|
2020-05-09 22:38:15 +00:00
|
|
|
[defaults setObject:dict forKey:key];
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 23:08:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-28 18:03:30 +00:00
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
.ThrowTypeError("Invalid type: " + type);
|
2016-11-28 23:08:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-09 22:38:15 +00:00
|
|
|
|
2020-07-28 18:03:30 +00:00
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
.ThrowTypeError("Unable to convert value to: " + type);
|
2016-11-28 23:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 21:24:55 +00:00
|
|
|
std::string SystemPreferences::GetAccentColor() {
|
2023-07-01 20:22:55 +00:00
|
|
|
NSColor* sysColor = sysColor = [NSColor controlAccentColor];
|
2021-03-13 07:31:08 +00:00
|
|
|
return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor),
|
|
|
|
false /* include_hash */);
|
2019-01-03 21:24:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
|
2019-08-19 16:10:18 +00:00
|
|
|
const std::string& color) {
|
2019-02-25 17:21:57 +00:00
|
|
|
NSColor* sysColor = nil;
|
|
|
|
if (color == "blue") {
|
|
|
|
sysColor = [NSColor systemBlueColor];
|
|
|
|
} else if (color == "brown") {
|
|
|
|
sysColor = [NSColor systemBrownColor];
|
|
|
|
} else if (color == "gray") {
|
|
|
|
sysColor = [NSColor systemGrayColor];
|
|
|
|
} else if (color == "green") {
|
|
|
|
sysColor = [NSColor systemGreenColor];
|
|
|
|
} else if (color == "orange") {
|
|
|
|
sysColor = [NSColor systemOrangeColor];
|
|
|
|
} else if (color == "pink") {
|
|
|
|
sysColor = [NSColor systemPinkColor];
|
|
|
|
} else if (color == "purple") {
|
|
|
|
sysColor = [NSColor systemPurpleColor];
|
|
|
|
} else if (color == "red") {
|
|
|
|
sysColor = [NSColor systemRedColor];
|
|
|
|
} else if (color == "yellow") {
|
|
|
|
sysColor = [NSColor systemYellowColor];
|
2019-01-03 22:30:38 +00:00
|
|
|
} else {
|
2019-08-19 16:10:18 +00:00
|
|
|
thrower.ThrowError("Unknown system color: " + color);
|
2019-01-03 22:30:38 +00:00
|
|
|
return "";
|
|
|
|
}
|
2019-02-25 17:21:57 +00:00
|
|
|
|
2021-07-12 18:08:10 +00:00
|
|
|
return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor));
|
2019-01-03 22:30:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 02:36:28 +00:00
|
|
|
bool SystemPreferences::CanPromptTouchID() {
|
2023-07-18 22:26:27 +00:00
|
|
|
LAContext* context = [[LAContext alloc] init];
|
2023-07-01 20:22:55 +00:00
|
|
|
LAPolicy auth_policy = LAPolicyDeviceOwnerAuthenticationWithBiometricsOrWatch;
|
2023-01-26 12:05:42 +00:00
|
|
|
if (![context canEvaluatePolicy:auth_policy error:nil])
|
2022-06-02 18:43:40 +00:00
|
|
|
return false;
|
2023-07-01 20:22:55 +00:00
|
|
|
return [context biometryType] == LABiometryTypeTouchID;
|
2019-02-14 02:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const std::string& reason) {
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate);
|
2019-02-21 12:32:44 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
2023-07-18 22:26:27 +00:00
|
|
|
LAContext* context = [[LAContext alloc] init];
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
base::apple::ScopedCFTypeRef<SecAccessControlRef> access_control =
|
|
|
|
base::apple::ScopedCFTypeRef<SecAccessControlRef>(
|
2022-06-02 18:43:40 +00:00
|
|
|
SecAccessControlCreateWithFlags(
|
|
|
|
kCFAllocatorDefault, kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
|
|
|
kSecAccessControlPrivateKeyUsage | kSecAccessControlUserPresence,
|
|
|
|
nullptr));
|
|
|
|
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> runner =
|
2023-02-03 11:43:42 +00:00
|
|
|
base::SequencedTaskRunner::GetCurrentDefault();
|
2022-06-02 18:43:40 +00:00
|
|
|
|
|
|
|
__block gin_helper::Promise<void> p = std::move(promise);
|
|
|
|
[context
|
2023-11-14 21:21:32 +00:00
|
|
|
evaluateAccessControl:access_control.get()
|
2022-06-02 18:43:40 +00:00
|
|
|
operation:LAAccessControlOperationUseKeySign
|
|
|
|
localizedReason:[NSString stringWithUTF8String:reason.c_str()]
|
|
|
|
reply:^(BOOL success, NSError* error) {
|
2023-04-26 14:09:54 +00:00
|
|
|
// NOLINTBEGIN(bugprone-use-after-move)
|
2022-06-02 18:43:40 +00:00
|
|
|
if (!success) {
|
|
|
|
std::string err_msg = std::string(
|
|
|
|
[error.localizedDescription UTF8String]);
|
|
|
|
runner->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(
|
|
|
|
gin_helper::Promise<void>::RejectPromise,
|
|
|
|
std::move(p), std::move(err_msg)));
|
|
|
|
} else {
|
|
|
|
runner->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(
|
|
|
|
gin_helper::Promise<void>::ResolvePromise,
|
|
|
|
std::move(p)));
|
|
|
|
}
|
2023-04-26 14:09:54 +00:00
|
|
|
// NOLINTEND(bugprone-use-after-move)
|
2022-06-02 18:43:40 +00:00
|
|
|
}];
|
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2019-02-14 02:36:28 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 04:40:17 +00:00
|
|
|
// static
|
2018-12-18 16:15:22 +00:00
|
|
|
bool SystemPreferences::IsTrustedAccessibilityClient(bool prompt) {
|
2023-07-18 22:26:27 +00:00
|
|
|
NSDictionary* options =
|
|
|
|
@{(__bridge id)kAXTrustedCheckOptionPrompt : @(prompt)};
|
2018-12-18 16:15:22 +00:00
|
|
|
return AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
|
|
|
|
}
|
|
|
|
|
2019-10-21 21:31:03 +00:00
|
|
|
std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& color) {
|
2019-01-04 00:17:07 +00:00
|
|
|
NSColor* sysColor = nil;
|
2023-09-11 15:34:13 +00:00
|
|
|
if (color == "control-background") {
|
2019-01-04 00:17:07 +00:00
|
|
|
sysColor = [NSColor controlBackgroundColor];
|
|
|
|
} else if (color == "control") {
|
|
|
|
sysColor = [NSColor controlColor];
|
|
|
|
} else if (color == "control-text") {
|
|
|
|
sysColor = [NSColor controlTextColor];
|
2019-10-21 21:31:03 +00:00
|
|
|
} else if (color == "disabled-control-text") {
|
2019-01-04 00:17:07 +00:00
|
|
|
sysColor = [NSColor disabledControlTextColor];
|
|
|
|
} else if (color == "find-highlight") {
|
2023-07-01 20:22:55 +00:00
|
|
|
sysColor = [NSColor findHighlightColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "grid") {
|
|
|
|
sysColor = [NSColor gridColor];
|
|
|
|
} else if (color == "header-text") {
|
|
|
|
sysColor = [NSColor headerTextColor];
|
|
|
|
} else if (color == "highlight") {
|
|
|
|
sysColor = [NSColor highlightColor];
|
|
|
|
} else if (color == "keyboard-focus-indicator") {
|
|
|
|
sysColor = [NSColor keyboardFocusIndicatorColor];
|
|
|
|
} else if (color == "label") {
|
2019-02-25 17:21:57 +00:00
|
|
|
sysColor = [NSColor labelColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "link") {
|
2019-02-25 17:21:57 +00:00
|
|
|
sysColor = [NSColor linkColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "placeholder-text") {
|
2019-02-25 17:21:57 +00:00
|
|
|
sysColor = [NSColor placeholderTextColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "quaternary-label") {
|
2019-02-25 17:21:57 +00:00
|
|
|
sysColor = [NSColor quaternaryLabelColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "scrubber-textured-background") {
|
2022-06-02 18:43:40 +00:00
|
|
|
sysColor = [NSColor scrubberTexturedBackgroundColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "secondary-label") {
|
2019-02-25 17:21:57 +00:00
|
|
|
sysColor = [NSColor secondaryLabelColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "selected-content-background") {
|
2023-07-01 20:22:55 +00:00
|
|
|
sysColor = [NSColor selectedContentBackgroundColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "selected-control") {
|
|
|
|
sysColor = [NSColor selectedControlColor];
|
|
|
|
} else if (color == "selected-control-text") {
|
|
|
|
sysColor = [NSColor selectedControlTextColor];
|
|
|
|
} else if (color == "selected-menu-item-text") {
|
|
|
|
sysColor = [NSColor selectedMenuItemTextColor];
|
|
|
|
} else if (color == "selected-text-background") {
|
|
|
|
sysColor = [NSColor selectedTextBackgroundColor];
|
|
|
|
} else if (color == "selected-text") {
|
|
|
|
sysColor = [NSColor selectedTextColor];
|
|
|
|
} else if (color == "separator") {
|
2023-07-01 20:22:55 +00:00
|
|
|
sysColor = [NSColor separatorColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "shadow") {
|
|
|
|
sysColor = [NSColor shadowColor];
|
|
|
|
} else if (color == "tertiary-label") {
|
2019-02-25 17:21:57 +00:00
|
|
|
sysColor = [NSColor tertiaryLabelColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "text-background") {
|
|
|
|
sysColor = [NSColor textBackgroundColor];
|
|
|
|
} else if (color == "text") {
|
|
|
|
sysColor = [NSColor textColor];
|
|
|
|
} else if (color == "under-page-background") {
|
|
|
|
sysColor = [NSColor underPageBackgroundColor];
|
|
|
|
} else if (color == "unemphasized-selected-content-background") {
|
2023-07-01 20:22:55 +00:00
|
|
|
sysColor = [NSColor unemphasizedSelectedContentBackgroundColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "unemphasized-selected-text-background") {
|
2023-07-01 20:22:55 +00:00
|
|
|
sysColor = [NSColor unemphasizedSelectedTextBackgroundColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "unemphasized-selected-text") {
|
2023-07-01 20:22:55 +00:00
|
|
|
sysColor = [NSColor unemphasizedSelectedTextColor];
|
2019-01-04 00:17:07 +00:00
|
|
|
} else if (color == "window-background") {
|
|
|
|
sysColor = [NSColor windowBackgroundColor];
|
|
|
|
} else if (color == "window-frame-text") {
|
|
|
|
sysColor = [NSColor windowFrameTextColor];
|
|
|
|
} else {
|
2019-10-21 21:31:03 +00:00
|
|
|
thrower.ThrowError("Unknown color: " + color);
|
2019-01-04 00:17:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 21:31:03 +00:00
|
|
|
if (sysColor)
|
2023-09-28 22:56:16 +00:00
|
|
|
return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor));
|
2019-10-21 21:31:03 +00:00
|
|
|
return "";
|
2019-01-04 00:17:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 15:54:13 +00:00
|
|
|
std::string SystemPreferences::GetMediaAccessStatus(
|
2020-07-28 18:03:30 +00:00
|
|
|
gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& media_type) {
|
2019-11-13 21:47:51 +00:00
|
|
|
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());
|
2018-12-04 15:54:13 +00:00
|
|
|
} else {
|
2020-07-28 18:03:30 +00:00
|
|
|
thrower.ThrowError("Invalid media type");
|
2018-12-04 15:54:13 +00:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise> SystemPreferences::AskForMediaAccess(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const std::string& media_type) {
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<bool> promise(isolate);
|
2019-02-21 12:32:44 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2018-12-04 15:54:13 +00:00
|
|
|
|
|
|
|
if (auto type = ParseMediaType(media_type)) {
|
2023-07-01 20:22:55 +00:00
|
|
|
__block gin_helper::Promise<bool> p = std::move(promise);
|
|
|
|
[AVCaptureDevice requestAccessForMediaType:type
|
|
|
|
completionHandler:^(BOOL granted) {
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
p.Resolve(!!granted);
|
|
|
|
});
|
|
|
|
}];
|
2018-12-04 15:54:13 +00:00
|
|
|
} else {
|
2019-02-21 12:32:44 +00:00
|
|
|
promise.RejectWithErrorMessage("Invalid media type");
|
2018-12-04 15:54:13 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2018-12-04 15:54:13 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 19:55:15 +00:00
|
|
|
void SystemPreferences::RemoveUserDefault(const std::string& name) {
|
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
[defaults removeObjectForKey:base::SysUTF8ToNSString(name)];
|
|
|
|
}
|
|
|
|
|
2016-08-03 02:27:56 +00:00
|
|
|
bool SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled() {
|
2016-08-03 13:46:39 +00:00
|
|
|
return [NSEvent isSwipeTrackingFromScrollEventsEnabled];
|
2016-08-03 02:27:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-27 15:33:31 +00:00
|
|
|
v8::Local<v8::Value> SystemPreferences::GetEffectiveAppearance(
|
|
|
|
v8::Isolate* isolate) {
|
2023-07-01 20:22:55 +00:00
|
|
|
return gin::ConvertToV8(
|
|
|
|
isolate, [NSApplication sharedApplication].effectiveAppearance);
|
2018-09-27 15:33:31 +00:00
|
|
|
}
|
|
|
|
|
2023-09-20 19:48:02 +00:00
|
|
|
bool SystemPreferences::AccessibilityDisplayShouldReduceTransparency() {
|
|
|
|
return [[NSWorkspace sharedWorkspace]
|
|
|
|
accessibilityDisplayShouldReduceTransparency];
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|