[email protected] | aebadfe | 2012-02-15 02:57:02 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[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 | dbcc841 | 2015-12-24 06:28:32 | [diff] [blame] | 8 | #include <stdint.h> |
[email protected] | 4b77bf1 | 2009-08-11 21:27:30 | [diff] [blame] | 9 | #include <string> |
| 10 | |
erikchen | 6ac22593 | 2016-10-12 01:16:45 | [diff] [blame] | 11 | #import <CoreGraphics/CoreGraphics.h> |
| 12 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 13 | #include "base/base_export.h" |
[email protected] | 45568795 | 2010-12-17 18:42:23 | [diff] [blame] | 14 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 15 | namespace base { |
| 16 | |
[email protected] | 45568795 | 2010-12-17 18:42:23 | [diff] [blame] | 17 | class FilePath; |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 18 | |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 19 | namespace mac { |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 20 | |
[email protected] | ce04f0c9 | 2010-03-03 19:27:28 | [diff] [blame] | 21 | // Full screen modes, in increasing order of priority. More permissive modes |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 22 | // take precedence. |
[email protected] | ce04f0c9 | 2010-03-03 19:27:28 | [diff] [blame] | 23 | enum FullScreenMode { |
| 24 | kFullScreenModeHideAll = 0, |
| 25 | kFullScreenModeHideDock = 1, |
| 26 | kFullScreenModeAutoHideAll = 2, |
| 27 | kNumFullScreenModes = 3, |
| 28 | |
| 29 | // kFullScreenModeNormal is not a valid FullScreenMode, but it is useful to |
| 30 | // other classes, so we include it here. |
| 31 | kFullScreenModeNormal = 10, |
| 32 | }; |
| 33 | |
[email protected] | 265cf96b | 2009-09-03 21:51:10 | [diff] [blame] | 34 | // Returns an sRGB color space. The return value is a static value; do not |
| 35 | // release it! |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 36 | BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace(); |
[email protected] | 265cf96b | 2009-09-03 21:51:10 | [diff] [blame] | 37 | |
[email protected] | bf42472a | 2013-06-22 01:55:26 | [diff] [blame] | 38 | // Returns the generic RGB color space. The return value is a static value; do |
| 39 | // not release it! |
| 40 | BASE_EXPORT CGColorSpaceRef GetGenericRGBColorSpace(); |
| 41 | |
[email protected] | 265cf96b | 2009-09-03 21:51:10 | [diff] [blame] | 42 | // Returns the color space being used by the main display. The return value |
| 43 | // is a static value; do not release it! |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 44 | BASE_EXPORT CGColorSpaceRef GetSystemColorSpace(); |
[email protected] | 265cf96b | 2009-09-03 21:51:10 | [diff] [blame] | 45 | |
[email protected] | ce04f0c9 | 2010-03-03 19:27:28 | [diff] [blame] | 46 | // Add a full screen request for the given |mode|. Must be paired with a |
| 47 | // ReleaseFullScreen() call for the same |mode|. This does not by itself create |
| 48 | // a fullscreen window; rather, it manages per-application state related to |
| 49 | // hiding the dock and menubar. Must be called on the main thread. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 50 | BASE_EXPORT void RequestFullScreen(FullScreenMode mode); |
[email protected] | b44dbd1 | 2009-10-11 19:02:15 | [diff] [blame] | 51 | |
[email protected] | ce04f0c9 | 2010-03-03 19:27:28 | [diff] [blame] | 52 | // Release a request for full screen mode. Must be matched with a |
| 53 | // RequestFullScreen() call for the same |mode|. As with RequestFullScreen(), |
| 54 | // this does not affect windows directly, but rather manages per-application |
| 55 | // state. For example, if there are no other outstanding |
| 56 | // |kFullScreenModeAutoHideAll| requests, this will reshow the menu bar. Must |
| 57 | // be called on main thread. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 58 | BASE_EXPORT void ReleaseFullScreen(FullScreenMode mode); |
[email protected] | ce04f0c9 | 2010-03-03 19:27:28 | [diff] [blame] | 59 | |
| 60 | // Convenience method to switch the current fullscreen mode. This has the same |
| 61 | // net effect as a ReleaseFullScreen(from_mode) call followed immediately by a |
| 62 | // RequestFullScreen(to_mode). Must be called on the main thread. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 63 | BASE_EXPORT void SwitchFullScreenModes(FullScreenMode from_mode, |
| 64 | FullScreenMode to_mode); |
[email protected] | b44dbd1 | 2009-10-11 19:02:15 | [diff] [blame] | 65 | |
Victor Costan | 7e74dce | 2019-01-28 20:15:25 | [diff] [blame] | 66 | // Returns true if the file at |file_path| is excluded from Time Machine |
| 67 | // backups. |
| 68 | BASE_EXPORT bool GetFileBackupExclusion(const FilePath& file_path); |
| 69 | |
| 70 | // Excludes the file given by |file_path| from Time Machine backups. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 71 | BASE_EXPORT bool SetFileBackupExclusion(const FilePath& file_path); |
[email protected] | b4113d5 | 2009-11-11 02:49:05 | [diff] [blame] | 72 | |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 73 | // Checks if the current application is set as a Login Item, so it will launch |
| 74 | // on Login. If a non-NULL pointer to is_hidden is passed, the Login Item also |
| 75 | // is queried for the 'hide on launch' flag. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 76 | BASE_EXPORT bool CheckLoginItemStatus(bool* is_hidden); |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 77 | |
| 78 | // Adds current application to the set of Login Items with specified "hide" |
| 79 | // flag. This has the same effect as adding/removing the application in |
| 80 | // SystemPreferences->Accounts->LoginItems or marking Application in the Dock |
| 81 | // as "Options->Open on Login". |
| 82 | // Does nothing if the application is already set up as Login Item with |
| 83 | // specified hide flag. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 84 | BASE_EXPORT void AddToLoginItems(bool hide_on_startup); |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 85 | |
| 86 | // Removes the current application from the list Of Login Items. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 87 | BASE_EXPORT void RemoveFromLoginItems(); |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 88 | |
| 89 | // Returns true if the current process was automatically launched as a |
[email protected] | 751d410 | 2011-08-10 17:18:45 | [diff] [blame] | 90 | // 'Login Item' or via Lion's Resume. Used to suppress opening windows. |
| 91 | BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem(); |
| 92 | |
| 93 | // Returns true if the current process was automatically launched as a |
[email protected] | 769ddfe | 2014-06-13 23:13:20 | [diff] [blame] | 94 | // 'Login Item' or via Resume, and the 'Reopen windows when logging back in' |
| 95 | // checkbox was selected by the user. This indicates that the previous |
| 96 | // session should be restored. |
| 97 | BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState(); |
| 98 | |
| 99 | // Returns true if the current process was automatically launched as a |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 100 | // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 101 | BASE_EXPORT bool WasLaunchedAsHiddenLoginItem(); |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 102 | |
[email protected] | ccfab59 | 2013-01-15 06:24:32 | [diff] [blame] | 103 | // Remove the quarantine xattr from the given file. Returns false if there was |
| 104 | // an error, or true otherwise. |
| 105 | BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path); |
| 106 | |
sdy | 07171a4 | 2016-08-30 18:22:04 | [diff] [blame] | 107 | namespace internal { |
| 108 | |
| 109 | // Returns the system's Mac OS X minor version. This is the |y| value |
| 110 | // in 10.y or 10.y.z. |
| 111 | BASE_EXPORT int MacOSXMinorVersion(); |
| 112 | |
| 113 | } // namespace internal |
| 114 | |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 115 | // Run-time OS version checks. Prefer @available in Objective-C files. If that |
| 116 | // is not possible, use these functions instead of |
sdy | 07171a4 | 2016-08-30 18:22:04 | [diff] [blame] | 117 | // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 118 | // "AtMost" variants to those that check for a specific version, unless you know |
| 119 | // for sure that you need to check for a specific version. |
[email protected] | ba64e2b | 2011-06-14 18:18:38 | [diff] [blame] | 120 | |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 121 | #define DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED(V, TEST_DEPLOYMENT_TARGET) \ |
| 122 | inline bool IsOS10_##V() { \ |
| 123 | TEST_DEPLOYMENT_TARGET(>, V, false) \ |
| 124 | return internal::MacOSXMinorVersion() == V; \ |
| 125 | } \ |
| 126 | inline bool IsAtMostOS10_##V() { \ |
| 127 | TEST_DEPLOYMENT_TARGET(>, V, false) \ |
| 128 | return internal::MacOSXMinorVersion() <= V; \ |
| 129 | } |
| 130 | |
| 131 | #define DEFINE_IS_OS_FUNCS(V, TEST_DEPLOYMENT_TARGET) \ |
| 132 | DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED(V, TEST_DEPLOYMENT_TARGET) \ |
| 133 | inline bool IsAtLeastOS10_##V() { \ |
| 134 | TEST_DEPLOYMENT_TARGET(>=, V, true) \ |
| 135 | return internal::MacOSXMinorVersion() >= V; \ |
sdy | 07171a4 | 2016-08-30 18:22:04 | [diff] [blame] | 136 | } |
[email protected] | aaf93de4 | 2013-10-02 07:41:57 | [diff] [blame] | 137 | |
sdy | 9745ad33 | 2016-08-30 19:24:49 | [diff] [blame] | 138 | #define TEST_DEPLOYMENT_TARGET(OP, V, RET) \ |
| 139 | if (MAC_OS_X_VERSION_MIN_REQUIRED OP MAC_OS_X_VERSION_10_##V) \ |
| 140 | return RET; |
| 141 | #define IGNORE_DEPLOYMENT_TARGET(OP, V, RET) |
[email protected] | 81ceb2b | 2014-06-12 18:28:19 | [diff] [blame] | 142 | |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 143 | // Notes: |
| 144 | // - When bumping the minimum version of the macOS required by Chromium, remove |
| 145 | // lines from below corresponding to versions of the macOS no longer |
| 146 | // supported. Ensure that the minimum supported version uses the |
| 147 | // DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED macro. |
| 148 | // - When bumping the minimum version of the macOS SDK required to build |
| 149 | // Chromium, remove the #ifdef that switches between TEST_DEPLOYMENT_TARGET |
| 150 | // and IGNORE_DEPLOYMENT_TARGET. |
shrike | 49c9add3 | 2015-07-16 18:40:19 | [diff] [blame] | 151 | |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 152 | DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED(10, TEST_DEPLOYMENT_TARGET) |
sdy | 9745ad33 | 2016-08-30 19:24:49 | [diff] [blame] | 153 | DEFINE_IS_OS_FUNCS(11, TEST_DEPLOYMENT_TARGET) |
sdy | 9745ad33 | 2016-08-30 19:24:49 | [diff] [blame] | 154 | DEFINE_IS_OS_FUNCS(12, TEST_DEPLOYMENT_TARGET) |
Avi Drissman | 8ae1afe | 2017-07-10 20:11:57 | [diff] [blame] | 155 | DEFINE_IS_OS_FUNCS(13, TEST_DEPLOYMENT_TARGET) |
Avi Drissman | 8ae1afe | 2017-07-10 20:11:57 | [diff] [blame] | 156 | |
Avi Drissman | 17901fb | 2018-06-11 18:28:48 | [diff] [blame] | 157 | #ifdef MAC_OS_X_VERSION_10_14 |
| 158 | DEFINE_IS_OS_FUNCS(14, TEST_DEPLOYMENT_TARGET) |
| 159 | #else |
| 160 | DEFINE_IS_OS_FUNCS(14, IGNORE_DEPLOYMENT_TARGET) |
| 161 | #endif |
| 162 | |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 163 | #ifdef MAC_OS_X_VERSION_10_15 |
| 164 | DEFINE_IS_OS_FUNCS(15, TEST_DEPLOYMENT_TARGET) |
| 165 | #else |
| 166 | DEFINE_IS_OS_FUNCS(15, IGNORE_DEPLOYMENT_TARGET) |
| 167 | #endif |
| 168 | |
sdy | 9745ad33 | 2016-08-30 19:24:49 | [diff] [blame] | 169 | #undef IGNORE_DEPLOYMENT_TARGET |
| 170 | #undef TEST_DEPLOYMENT_TARGET |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 171 | #undef DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED |
sdy | 07171a4 | 2016-08-30 18:22:04 | [diff] [blame] | 172 | #undef DEFINE_IS_OS_FUNCS |
mark | fd1cb64d | 2016-07-08 19:58:59 | [diff] [blame] | 173 | |
[email protected] | ba64e2b | 2011-06-14 18:18:38 | [diff] [blame] | 174 | // This should be infrequently used. It only makes sense to use this to avoid |
| 175 | // codepaths that are very likely to break on future (unreleased, untested, |
[email protected] | 4d170e8 | 2012-12-04 00:34:13 | [diff] [blame] | 176 | // unborn) OS releases, or to log when the OS is newer than any known version. |
Avi Drissman | fbbb1ff | 2019-06-06 18:51:09 | [diff] [blame] | 177 | inline bool IsOSLaterThan10_15_DontCallThis() { |
| 178 | return !IsAtMostOS10_15(); |
sdy | 07171a4 | 2016-08-30 18:22:04 | [diff] [blame] | 179 | } |
shrike | 49c9add3 | 2015-07-16 18:40:19 | [diff] [blame] | 180 | |
[email protected] | aebadfe | 2012-02-15 02:57:02 | [diff] [blame] | 181 | // Retrieve the system's model identifier string from the IOKit registry: |
| 182 | // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon |
| 183 | // failure. |
| 184 | BASE_EXPORT std::string GetModelIdentifier(); |
| 185 | |
| 186 | // Parse a model identifier string; for example, into ("MacBookPro", 6, 1). |
| 187 | // If any error occurs, none of the input pointers are touched. |
| 188 | BASE_EXPORT bool ParseModelIdentifier(const std::string& ident, |
| 189 | std::string* type, |
avi | dbcc841 | 2015-12-24 06:28:32 | [diff] [blame] | 190 | int32_t* major, |
| 191 | int32_t* minor); |
[email protected] | aebadfe | 2012-02-15 02:57:02 | [diff] [blame] | 192 | |
Nicolas Ouellet-Payeur | f5b3aa3 | 2019-06-11 00:50:24 | [diff] [blame] | 193 | // Returns an OS name + version string. e.g.: |
| 194 | // |
| 195 | // "macOS Version 10.14.3 (Build 18D109)" |
| 196 | // |
| 197 | // Parts of this string change based on OS locale, so it's only useful for |
| 198 | // displaying to the user. |
| 199 | BASE_EXPORT std::string GetOSDisplayName(); |
| 200 | |
Tim Song | 3aa6779 | 2019-12-10 22:43:13 | [diff] [blame^] | 201 | // Returns the serial number of the macOS device. |
| 202 | BASE_EXPORT std::string GetPlatformSerialNumber(); |
| 203 | |
[email protected] | 0c3bf95 | 2011-03-03 04:29:10 | [diff] [blame] | 204 | } // namespace mac |
| 205 | } // namespace base |
[email protected] | 45568795 | 2010-12-17 18:42:23 | [diff] [blame] | 206 | |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 207 | #endif // BASE_MAC_MAC_UTIL_H_ |