blob: bb53fe4e0ef999fcf50a12e456898e83964dadb1 [file] [log] [blame]
[email protected]aebadfe2012-02-15 02:57:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e2ac70002008-12-09 14:58:132// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]0378bf42011-01-01 18:20:145#ifndef BASE_MAC_MAC_UTIL_H_
6#define BASE_MAC_MAC_UTIL_H_
[email protected]e2ac70002008-12-09 14:58:137
avidbcc8412015-12-24 06:28:328#include <stdint.h>
[email protected]4b77bf12009-08-11 21:27:309#include <string>
10
erikchen6ac225932016-10-12 01:16:4511#import <CoreGraphics/CoreGraphics.h>
12
[email protected]0bea7252011-08-05 15:34:0013#include "base/base_export.h"
[email protected]455687952010-12-17 18:42:2314
[email protected]a3ef4832013-02-02 05:12:3315namespace base {
16
[email protected]455687952010-12-17 18:42:2317class FilePath;
[email protected]e2ac70002008-12-09 14:58:1318
[email protected]0378bf42011-01-01 18:20:1419namespace mac {
[email protected]e2ac70002008-12-09 14:58:1320
[email protected]ce04f0c92010-03-03 19:27:2821// Full screen modes, in increasing order of priority. More permissive modes
Avi Drissmanfbbb1ff2019-06-06 18:51:0922// take precedence.
[email protected]ce04f0c92010-03-03 19:27:2823enum 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]265cf96b2009-09-03 21:51:1034// Returns an sRGB color space. The return value is a static value; do not
35// release it!
[email protected]0bea7252011-08-05 15:34:0036BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace();
[email protected]265cf96b2009-09-03 21:51:1037
[email protected]bf42472a2013-06-22 01:55:2638// Returns the generic RGB color space. The return value is a static value; do
39// not release it!
40BASE_EXPORT CGColorSpaceRef GetGenericRGBColorSpace();
41
[email protected]265cf96b2009-09-03 21:51:1042// Returns the color space being used by the main display. The return value
43// is a static value; do not release it!
[email protected]0bea7252011-08-05 15:34:0044BASE_EXPORT CGColorSpaceRef GetSystemColorSpace();
[email protected]265cf96b2009-09-03 21:51:1045
[email protected]ce04f0c92010-03-03 19:27:2846// 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]0bea7252011-08-05 15:34:0050BASE_EXPORT void RequestFullScreen(FullScreenMode mode);
[email protected]b44dbd12009-10-11 19:02:1551
[email protected]ce04f0c92010-03-03 19:27:2852// 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]0bea7252011-08-05 15:34:0058BASE_EXPORT void ReleaseFullScreen(FullScreenMode mode);
[email protected]ce04f0c92010-03-03 19:27:2859
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]0bea7252011-08-05 15:34:0063BASE_EXPORT void SwitchFullScreenModes(FullScreenMode from_mode,
64 FullScreenMode to_mode);
[email protected]b44dbd12009-10-11 19:02:1565
Victor Costan7e74dce2019-01-28 20:15:2566// Returns true if the file at |file_path| is excluded from Time Machine
67// backups.
68BASE_EXPORT bool GetFileBackupExclusion(const FilePath& file_path);
69
70// Excludes the file given by |file_path| from Time Machine backups.
[email protected]0bea7252011-08-05 15:34:0071BASE_EXPORT bool SetFileBackupExclusion(const FilePath& file_path);
[email protected]b4113d52009-11-11 02:49:0572
[email protected]91484af2010-08-27 17:55:5473// 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]0bea7252011-08-05 15:34:0076BASE_EXPORT bool CheckLoginItemStatus(bool* is_hidden);
[email protected]91484af2010-08-27 17:55:5477
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]0bea7252011-08-05 15:34:0084BASE_EXPORT void AddToLoginItems(bool hide_on_startup);
[email protected]91484af2010-08-27 17:55:5485
86// Removes the current application from the list Of Login Items.
[email protected]0bea7252011-08-05 15:34:0087BASE_EXPORT void RemoveFromLoginItems();
[email protected]91484af2010-08-27 17:55:5488
89// Returns true if the current process was automatically launched as a
[email protected]751d4102011-08-10 17:18:4590// 'Login Item' or via Lion's Resume. Used to suppress opening windows.
91BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
92
93// Returns true if the current process was automatically launched as a
[email protected]769ddfe2014-06-13 23:13:2094// '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.
97BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState();
98
99// Returns true if the current process was automatically launched as a
[email protected]91484af2010-08-27 17:55:54100// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
[email protected]0bea7252011-08-05 15:34:00101BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
[email protected]91484af2010-08-27 17:55:54102
[email protected]ccfab592013-01-15 06:24:32103// Remove the quarantine xattr from the given file. Returns false if there was
104// an error, or true otherwise.
105BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path);
106
sdy07171a42016-08-30 18:22:04107namespace 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.
111BASE_EXPORT int MacOSXMinorVersion();
112
113} // namespace internal
114
Avi Drissmanfbbb1ff2019-06-06 18:51:09115// Run-time OS version checks. Prefer @available in Objective-C files. If that
116// is not possible, use these functions instead of
sdy07171a42016-08-30 18:22:04117// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and
Avi Drissmanfbbb1ff2019-06-06 18:51:09118// "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]ba64e2b2011-06-14 18:18:38120
Avi Drissmanfbbb1ff2019-06-06 18:51:09121#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; \
sdy07171a42016-08-30 18:22:04136 }
[email protected]aaf93de42013-10-02 07:41:57137
sdy9745ad332016-08-30 19:24:49138#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]81ceb2b2014-06-12 18:28:19142
Avi Drissmanfbbb1ff2019-06-06 18:51:09143// 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.
shrike49c9add32015-07-16 18:40:19151
Avi Drissmanfbbb1ff2019-06-06 18:51:09152DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED(10, TEST_DEPLOYMENT_TARGET)
sdy9745ad332016-08-30 19:24:49153DEFINE_IS_OS_FUNCS(11, TEST_DEPLOYMENT_TARGET)
sdy9745ad332016-08-30 19:24:49154DEFINE_IS_OS_FUNCS(12, TEST_DEPLOYMENT_TARGET)
Avi Drissman8ae1afe2017-07-10 20:11:57155DEFINE_IS_OS_FUNCS(13, TEST_DEPLOYMENT_TARGET)
Avi Drissman8ae1afe2017-07-10 20:11:57156
Avi Drissman17901fb2018-06-11 18:28:48157#ifdef MAC_OS_X_VERSION_10_14
158DEFINE_IS_OS_FUNCS(14, TEST_DEPLOYMENT_TARGET)
159#else
160DEFINE_IS_OS_FUNCS(14, IGNORE_DEPLOYMENT_TARGET)
161#endif
162
Avi Drissmanfbbb1ff2019-06-06 18:51:09163#ifdef MAC_OS_X_VERSION_10_15
164DEFINE_IS_OS_FUNCS(15, TEST_DEPLOYMENT_TARGET)
165#else
166DEFINE_IS_OS_FUNCS(15, IGNORE_DEPLOYMENT_TARGET)
167#endif
168
sdy9745ad332016-08-30 19:24:49169#undef IGNORE_DEPLOYMENT_TARGET
170#undef TEST_DEPLOYMENT_TARGET
Avi Drissmanfbbb1ff2019-06-06 18:51:09171#undef DEFINE_IS_OS_FUNCS_CR_MIN_REQUIRED
sdy07171a42016-08-30 18:22:04172#undef DEFINE_IS_OS_FUNCS
markfd1cb64d2016-07-08 19:58:59173
[email protected]ba64e2b2011-06-14 18:18:38174// 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]4d170e82012-12-04 00:34:13176// unborn) OS releases, or to log when the OS is newer than any known version.
Avi Drissmanfbbb1ff2019-06-06 18:51:09177inline bool IsOSLaterThan10_15_DontCallThis() {
178 return !IsAtMostOS10_15();
sdy07171a42016-08-30 18:22:04179}
shrike49c9add32015-07-16 18:40:19180
[email protected]aebadfe2012-02-15 02:57:02181// Retrieve the system's model identifier string from the IOKit registry:
182// for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
183// failure.
184BASE_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.
188BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
189 std::string* type,
avidbcc8412015-12-24 06:28:32190 int32_t* major,
191 int32_t* minor);
[email protected]aebadfe2012-02-15 02:57:02192
Nicolas Ouellet-Payeurf5b3aa32019-06-11 00:50:24193// 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.
199BASE_EXPORT std::string GetOSDisplayName();
200
Tim Song3aa67792019-12-10 22:43:13201// Returns the serial number of the macOS device.
202BASE_EXPORT std::string GetPlatformSerialNumber();
203
[email protected]0c3bf952011-03-03 04:29:10204} // namespace mac
205} // namespace base
[email protected]455687952010-12-17 18:42:23206
[email protected]0378bf42011-01-01 18:20:14207#endif // BASE_MAC_MAC_UTIL_H_