Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / base / mac / mac_util.h
blobf8ffa97545decf3717c102853461d92877f5e8a6
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 IsOSYosemiteOrLater();
150 // This should be infrequently used. It only makes sense to use this to avoid
151 // codepaths that are very likely to break on future (unreleased, untested,
152 // unborn) OS releases, or to log when the OS is newer than any known version.
153 BASE_EXPORT bool IsOSLaterThanYosemite_DontCallThis();
155 // Inline functions that are redundant due to version ranges being mutually-
156 // exclusive.
157 inline bool IsOSLionOrEarlier() { return !IsOSMountainLionOrLater(); }
158 inline bool IsOSMountainLionOrEarlier() { return !IsOSMavericksOrLater(); }
159 inline bool IsOSMavericksOrEarlier() { return !IsOSYosemiteOrLater(); }
161 // When the deployment target is set, the code produced cannot run on earlier
162 // OS releases. That enables some of the IsOS* family to be implemented as
163 // constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro
164 // contains the value of the deployment target.
166 #if defined(MAC_OS_X_VERSION_10_7) && \
167 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
168 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7
169 inline bool IsOSSnowLeopard() { return false; }
170 inline bool IsOSLionOrLater() { return true; }
171 #endif
173 #if defined(MAC_OS_X_VERSION_10_7) && \
174 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_7
175 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7
176 inline bool IsOSLion() { return false; }
177 #endif
179 #if defined(MAC_OS_X_VERSION_10_8) && \
180 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
181 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_8
182 inline bool IsOSMountainLionOrLater() { return true; }
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_GT_10_8
188 inline bool IsOSMountainLion() { return false; }
189 #endif
191 #if defined(MAC_OS_X_VERSION_10_9) && \
192 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
193 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_9
194 inline bool IsOSMavericksOrLater() { return true; }
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_GT_10_9
200 inline bool IsOSMavericks() { return false; }
201 #endif
203 #if defined(MAC_OS_X_VERSION_10_10) && \
204 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
205 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10
206 inline bool IsOSYosemiteOrLater() { return true; }
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_GT_10_10
212 inline bool IsOSYosemite() { return false; }
213 inline bool IsOSLaterThanYosemite_DontCallThis() { return true; }
214 #endif
216 // Retrieve the system's model identifier string from the IOKit registry:
217 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
218 // failure.
219 BASE_EXPORT std::string GetModelIdentifier();
221 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1).
222 // If any error occurs, none of the input pointers are touched.
223 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
224 std::string* type,
225 int32* major,
226 int32* minor);
228 } // namespace mac
229 } // namespace base
231 #endif // BASE_MAC_MAC_UTIL_H_