Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 5 | #ifndef BASE_MAC_MAC_UTIL_H_ |
| 6 | #define BASE_MAC_MAC_UTIL_H_ |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 7 | |
Avi Drissman | 5197d3bca | 2020-07-23 03:11:32 | [diff] [blame] | 8 | #include <AvailabilityMacros.h> |
Meredith Lane | a43420c | 2020-07-22 23:40:41 | [diff] [blame] | 9 | #import <CoreGraphics/CoreGraphics.h> |
Avi Drissman | 5197d3bca | 2020-07-23 03:11:32 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
| 12 | #include <string> |
Avi Drissman | 922a94f2 | 2023-08-28 23:43:41 | [diff] [blame] | 13 | #include <string_view> |
Avi Drissman | fc29fbd | 2024-01-22 21:37:25 | [diff] [blame] | 14 | #include <vector> |
Meredith Lane | a43420c | 2020-07-22 23:40:41 | [diff] [blame] | 15 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 16 | #include "base/base_export.h" |
[email protected] | 45568795 | 2010-12-17 18:42:23 | [diff] [blame] | 17 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 18 | namespace base { |
[email protected] | 45568795 | 2010-12-17 18:42:23 | [diff] [blame] | 19 | class FilePath; |
Avi Drissman | efca412 | 2022-01-05 23:59:36 | [diff] [blame] | 20 | } |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 21 | |
Avi Drissman | efca412 | 2022-01-05 23:59:36 | [diff] [blame] | 22 | namespace base::mac { |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 23 | |
[email protected] | 265cf96b | 2009-09-03 21:51:10 | [diff] [blame] | 24 | // Returns an sRGB color space. The return value is a static value; do not |
| 25 | // release it! |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 26 | BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace(); |
[email protected] | 265cf96b | 2009-09-03 21:51:10 | [diff] [blame] | 27 | |
Mike Jackson | a481f3f | 2021-01-13 04:00:19 | [diff] [blame] | 28 | // Adds the specified application to the set of Login Items with specified |
| 29 | // "hide" flag. This has the same effect as adding/removing the application in |
| 30 | // SystemPreferences->Accounts->LoginItems or marking Application in the Dock |
| 31 | // as "Options->Open on Login". |
| 32 | // Does nothing if the application is already set up as Login Item with |
| 33 | // specified hide flag. |
| 34 | BASE_EXPORT void AddToLoginItems(const FilePath& app_bundle_file_path, |
| 35 | bool hide_on_startup); |
| 36 | |
Avi Drissman | fee70e5f | 2022-11-02 20:50:11 | [diff] [blame] | 37 | // Removes the specified application from the list of Login Items. |
Mike Jackson | a481f3f | 2021-01-13 04:00:19 | [diff] [blame] | 38 | BASE_EXPORT void RemoveFromLoginItems(const FilePath& app_bundle_file_path); |
| 39 | |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 40 | // Returns true if the current process was automatically launched as a |
[email protected] | 751d410 | 2011-08-10 17:18:45 | [diff] [blame] | 41 | // 'Login Item' or via Lion's Resume. Used to suppress opening windows. |
| 42 | BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem(); |
| 43 | |
| 44 | // Returns true if the current process was automatically launched as a |
[email protected] | 769ddfe | 2014-06-13 23:13:20 | [diff] [blame] | 45 | // 'Login Item' or via Resume, and the 'Reopen windows when logging back in' |
| 46 | // checkbox was selected by the user. This indicates that the previous |
| 47 | // session should be restored. |
| 48 | BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState(); |
| 49 | |
| 50 | // Returns true if the current process was automatically launched as a |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 51 | // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 52 | BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 53 | |
[email protected] | ccfab59 | 2013-01-15 06:24:32 | [diff] [blame] | 54 | // Remove the quarantine xattr from the given file. Returns false if there was |
| 55 | // an error, or true otherwise. |
| 56 | BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); |
| 57 | |
Avi Drissman | fc29fbd | 2024-01-22 21:37:25 | [diff] [blame] | 58 | // Sets the tags on a given file or folder. |
| 59 | BASE_EXPORT void SetFileTags(const FilePath& file_path, |
| 60 | const std::vector<std::string>& file_tags); |
| 61 | |
Avi Drissman | 922a94f2 | 2023-08-28 23:43:41 | [diff] [blame] | 62 | // The following two functions return the version of the macOS currently |
| 63 | // running. MacOSVersion() returns the full trio of version numbers, packed into |
| 64 | // one int (e.g. macOS 12.6.5 returns 12'06'05), and MacOSMajorVersion() returns |
| 65 | // only the major version number (e.g. macOS 12.6.5 returns 12). Use for runtime |
| 66 | // OS version checking. Prefer to use @available in Objective-C files. Note that |
| 67 | // this does not include any Rapid Security Response (RSR) suffixes (the "(a)" |
| 68 | // at the end of version numbers.) |
| 69 | BASE_EXPORT __attribute__((const)) int MacOSVersion(); |
| 70 | inline __attribute__((const)) int MacOSMajorVersion() { |
| 71 | return MacOSVersion() / 1'00'00; |
| 72 | } |
mark | fd1cb64d | 2016-07-08 19:58:59 | [diff] [blame] | 73 | |
Avi Drissman | 0783380 | 2020-07-25 18:29:23 | [diff] [blame] | 74 | enum class CPUType { |
| 75 | kIntel, |
| 76 | kTranslatedIntel, // Rosetta |
| 77 | kArm, |
| 78 | }; |
| 79 | |
| 80 | // Returns the type of CPU this is being executed on. |
| 81 | BASE_EXPORT CPUType GetCPUType(); |
| 82 | |
Nicolas Ouellet-Payeur | f5b3aa3 | 2019-06-11 00:50:24 | [diff] [blame] | 83 | // Returns an OS name + version string. e.g.: |
| 84 | // |
| 85 | // "macOS Version 10.14.3 (Build 18D109)" |
| 86 | // |
| 87 | // Parts of this string change based on OS locale, so it's only useful for |
| 88 | // displaying to the user. |
| 89 | BASE_EXPORT std::string GetOSDisplayName(); |
| 90 | |
Tim Song | 3aa6779 | 2019-12-10 22:43:13 | [diff] [blame] | 91 | // Returns the serial number of the macOS device. |
| 92 | BASE_EXPORT std::string GetPlatformSerialNumber(); |
| 93 | |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 94 | // System Settings (née System Preferences) pane or subpanes to open via |
| 95 | // `OpenSystemSettingsPane()`, below. The naming is based on the naming in the |
| 96 | // System Settings app in the latest macOS release, macOS 13 Ventura. |
| 97 | enum class SystemSettingsPane { |
| 98 | // Accessibility > Captions |
| 99 | kAccessibility_Captions, |
| 100 | |
| 101 | // Date & Time |
| 102 | kDateTime, |
| 103 | |
| 104 | // Network > Proxies |
| 105 | kNetwork_Proxies, |
| 106 | |
Marijn Kruisselbrink | 957a66c | 2024-02-22 21:26:45 | [diff] [blame] | 107 | // Notifications; optionally pass a bundle identifier as `id_param` to |
| 108 | // directly open the notification settings page for the given app. |
| 109 | kNotifications, |
| 110 | |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 111 | // Printers & Scanners |
| 112 | kPrintersScanners, |
| 113 | |
Muyao Xu | 6166dba7 | 2024-08-14 18:46:32 | [diff] [blame] | 114 | // Privacy & Security |
| 115 | kPrivacySecurity, |
| 116 | |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 117 | // Privacy & Security > Accessibility |
| 118 | kPrivacySecurity_Accessibility, |
| 119 | |
| 120 | // Privacy & Security > Bluetooth |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 121 | kPrivacySecurity_Bluetooth, |
| 122 | |
| 123 | // Privacy & Security > Camera |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 124 | kPrivacySecurity_Camera, |
| 125 | |
| 126 | // Privacy & Security > Extensions > Sharing |
| 127 | kPrivacySecurity_Extensions_Sharing, |
| 128 | |
| 129 | // Privacy & Security > Location Services |
| 130 | kPrivacySecurity_LocationServices, |
| 131 | |
| 132 | // Privacy & Security > Microphone |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 133 | kPrivacySecurity_Microphone, |
| 134 | |
| 135 | // Privacy & Security > Screen Recording |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 136 | kPrivacySecurity_ScreenRecording, |
Charles Meng | 4a9eff0e | 2023-08-17 22:45:31 | [diff] [blame] | 137 | |
| 138 | // Trackpad |
| 139 | kTrackpad, |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | // Opens the specified System Settings pane. If the specified subpane does not |
| 143 | // exist on the release of macOS that is running, the parent pane will open |
Marijn Kruisselbrink | 957a66c | 2024-02-22 21:26:45 | [diff] [blame] | 144 | // instead. For some panes, `id_param` can be used to specify a subpane. See the |
| 145 | // various SystemSettingsPane values for details. |
| 146 | BASE_EXPORT void OpenSystemSettingsPane(SystemSettingsPane pane, |
| 147 | const std::string& id_param = ""); |
Avi Drissman | 35b115d | 2022-11-01 19:28:50 | [diff] [blame] | 148 | |
Avi Drissman | 922a94f2 | 2023-08-28 23:43:41 | [diff] [blame] | 149 | // ------- For testing -------- |
| 150 | |
| 151 | // An implementation detail of `MacOSVersion()` above, exposed for testing. |
| 152 | BASE_EXPORT int ParseOSProductVersionForTesting( |
| 153 | const std::string_view& version); |
| 154 | |
Avi Drissman | efca412 | 2022-01-05 23:59:36 | [diff] [blame] | 155 | } // namespace base::mac |
[email protected] | 45568795 | 2010-12-17 18:42:23 | [diff] [blame] | 156 | |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 157 | #endif // BASE_MAC_MAC_UTIL_H_ |