Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / mac / mac_util.h
bloba452a39bdd4077d13e078134873b0fa2bc5c19c4
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_MAC_MAC_UTIL_H_
6 #define BASE_MAC_MAC_UTIL_H_
8 #include <AvailabilityMacros.h>
9 #include <Carbon/Carbon.h>
10 #include <string>
12 #include "base/base_export.h"
13 #include "base/logging.h"
15 #if defined(__OBJC__)
16 #import <Foundation/Foundation.h>
17 #else // __OBJC__
18 class NSImage;
19 #endif // __OBJC__
21 namespace base {
23 class FilePath;
25 namespace mac {
27 // Full screen modes, in increasing order of priority. More permissive modes
28 // take predecence.
29 enum FullScreenMode {
30 kFullScreenModeHideAll = 0,
31 kFullScreenModeHideDock = 1,
32 kFullScreenModeAutoHideAll = 2,
33 kNumFullScreenModes = 3,
35 // kFullScreenModeNormal is not a valid FullScreenMode, but it is useful to
36 // other classes, so we include it here.
37 kFullScreenModeNormal = 10,
40 BASE_EXPORT std::string PathFromFSRef(const FSRef& ref);
41 BASE_EXPORT bool FSRefFromPath(const std::string& path, FSRef* ref);
43 // Returns an sRGB color space. The return value is a static value; do not
44 // release it!
45 BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace();
47 // Returns the generic RGB color space. The return value is a static value; do
48 // not release it!
49 BASE_EXPORT CGColorSpaceRef GetGenericRGBColorSpace();
51 // Returns the color space being used by the main display. The return value
52 // is a static value; do not release it!
53 BASE_EXPORT CGColorSpaceRef GetSystemColorSpace();
55 // Add a full screen request for the given |mode|. Must be paired with a
56 // ReleaseFullScreen() call for the same |mode|. This does not by itself create
57 // a fullscreen window; rather, it manages per-application state related to
58 // hiding the dock and menubar. Must be called on the main thread.
59 BASE_EXPORT void RequestFullScreen(FullScreenMode mode);
61 // Release a request for full screen mode. Must be matched with a
62 // RequestFullScreen() call for the same |mode|. As with RequestFullScreen(),
63 // this does not affect windows directly, but rather manages per-application
64 // state. For example, if there are no other outstanding
65 // |kFullScreenModeAutoHideAll| requests, this will reshow the menu bar. Must
66 // be called on main thread.
67 BASE_EXPORT void ReleaseFullScreen(FullScreenMode mode);
69 // Convenience method to switch the current fullscreen mode. This has the same
70 // net effect as a ReleaseFullScreen(from_mode) call followed immediately by a
71 // RequestFullScreen(to_mode). Must be called on the main thread.
72 BASE_EXPORT void SwitchFullScreenModes(FullScreenMode from_mode,
73 FullScreenMode to_mode);
75 // Set the visibility of the cursor.
76 BASE_EXPORT void SetCursorVisibility(bool visible);
78 // Activates the process with the given PID.
79 BASE_EXPORT void ActivateProcess(pid_t pid);
81 // Returns true if this process is in the foreground, meaning that it's the
82 // frontmost process, the one whose menu bar is shown at the top of the main
83 // display.
84 BASE_EXPORT bool AmIForeground();
86 // Excludes the file given by |file_path| from being backed up by Time Machine.
87 BASE_EXPORT bool SetFileBackupExclusion(const FilePath& file_path);
89 // Checks if the current application is set as a Login Item, so it will launch
90 // on Login. If a non-NULL pointer to is_hidden is passed, the Login Item also
91 // is queried for the 'hide on launch' flag.
92 BASE_EXPORT bool CheckLoginItemStatus(bool* is_hidden);
94 // Adds current application to the set of Login Items with specified "hide"
95 // flag. This has the same effect as adding/removing the application in
96 // SystemPreferences->Accounts->LoginItems or marking Application in the Dock
97 // as "Options->Open on Login".
98 // Does nothing if the application is already set up as Login Item with
99 // specified hide flag.
100 BASE_EXPORT void AddToLoginItems(bool hide_on_startup);
102 // Removes the current application from the list Of Login Items.
103 BASE_EXPORT void RemoveFromLoginItems();
105 // Returns true if the current process was automatically launched as a
106 // 'Login Item' or via Lion's Resume. Used to suppress opening windows.
107 BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
109 // Returns true if the current process was automatically launched as a
110 // 'Login Item' or via Resume, and the 'Reopen windows when logging back in'
111 // checkbox was selected by the user. This indicates that the previous
112 // session should be restored.
113 BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState();
115 // Returns true if the current process was automatically launched as a
116 // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
117 BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
119 // Remove the quarantine xattr from the given file. Returns false if there was
120 // an error, or true otherwise.
121 BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path);
123 // Run-time OS version checks. Use these instead of
124 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and
125 // "OrLater" variants to those that check for a specific version, unless you
126 // know for sure that you need to check for a specific version.
128 // Snow Leopard is Mac OS X 10.6, Darwin 10.
129 BASE_EXPORT bool IsOSSnowLeopard();
131 // Lion is Mac OS X 10.7, Darwin 11.
132 BASE_EXPORT bool IsOSLion();
133 BASE_EXPORT bool IsOSLionOrEarlier();
134 BASE_EXPORT bool IsOSLionOrLater();
136 // Mountain Lion is Mac OS X 10.8, Darwin 12.
137 BASE_EXPORT bool IsOSMountainLion();
138 BASE_EXPORT bool IsOSMountainLionOrEarlier();
139 BASE_EXPORT bool IsOSMountainLionOrLater();
141 // Mavericks is Mac OS X 10.9, Darwin 13.
142 BASE_EXPORT bool IsOSMavericks();
143 BASE_EXPORT bool IsOSMavericksOrEarlier();
144 BASE_EXPORT bool IsOSMavericksOrLater();
146 // Yosemite is Mac OS X 10.10, Darwin 14.
147 BASE_EXPORT bool IsOSYosemite();
148 BASE_EXPORT bool IsOSYosemiteOrEarlier();
149 BASE_EXPORT bool IsOSYosemiteOrLater();
151 // El Capitan is Mac OS X 10.11, Darwin 15.
152 BASE_EXPORT bool IsOSElCapitan();
153 BASE_EXPORT bool IsOSElCapitanOrLater();
155 // This should be infrequently used. It only makes sense to use this to avoid
156 // codepaths that are very likely to break on future (unreleased, untested,
157 // unborn) OS releases, or to log when the OS is newer than any known version.
158 BASE_EXPORT bool IsOSLaterThanElCapitan_DontCallThis();
160 // Inline functions that are redundant due to version ranges being mutually-
161 // exclusive.
162 inline bool IsOSLionOrEarlier() { return !IsOSMountainLionOrLater(); }
163 inline bool IsOSMountainLionOrEarlier() { return !IsOSMavericksOrLater(); }
164 inline bool IsOSMavericksOrEarlier() { return !IsOSYosemiteOrLater(); }
165 inline bool IsOSYosemiteOrEarlier() { return !IsOSElCapitanOrLater(); }
167 // When the deployment target is set, the code produced cannot run on earlier
168 // OS releases. That enables some of the IsOS* family to be implemented as
169 // constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro
170 // contains the value of the deployment target.
172 #if defined(MAC_OS_X_VERSION_10_7) && \
173 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
174 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7
175 inline bool IsOSSnowLeopard() { return false; }
176 inline bool IsOSLionOrLater() { return true; }
177 #endif
179 #if defined(MAC_OS_X_VERSION_10_7) && \
180 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_7
181 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7
182 inline bool IsOSLion() { return false; }
183 #endif
185 #if defined(MAC_OS_X_VERSION_10_8) && \
186 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
187 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_8
188 inline bool IsOSMountainLionOrLater() { return true; }
189 #endif
191 #if defined(MAC_OS_X_VERSION_10_8) && \
192 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_8
193 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_8
194 inline bool IsOSMountainLion() { return false; }
195 #endif
197 #if defined(MAC_OS_X_VERSION_10_9) && \
198 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
199 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_9
200 inline bool IsOSMavericksOrLater() { return true; }
201 #endif
203 #if defined(MAC_OS_X_VERSION_10_9) && \
204 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
205 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9
206 inline bool IsOSMavericks() { return false; }
207 #endif
209 #if defined(MAC_OS_X_VERSION_10_10) && \
210 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
211 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10
212 inline bool IsOSYosemiteOrLater() { return true; }
213 #endif
215 #if defined(MAC_OS_X_VERSION_10_10) && \
216 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_10
217 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10
218 inline bool IsOSYosemite() { return false; }
219 #endif
221 #if defined(MAC_OS_X_VERSION_10_11) && \
222 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11
223 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11
224 inline bool IsOSElCapitanOrLater() { return true; }
225 #endif
227 #if defined(MAC_OS_X_VERSION_10_11) && \
228 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_11
229 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11
230 inline bool IsOSElCapitan() { return false; }
231 inline bool IsOSLaterThanElCapitan_DontCallThis() { return true; }
232 #endif
234 // Retrieve the system's model identifier string from the IOKit registry:
235 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
236 // failure.
237 BASE_EXPORT std::string GetModelIdentifier();
239 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1).
240 // If any error occurs, none of the input pointers are touched.
241 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
242 std::string* type,
243 int32* major,
244 int32* minor);
246 } // namespace mac
247 } // namespace base
249 #endif // BASE_MAC_MAC_UTIL_H_