Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: base/mac/mac_util.h

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/mac/mac_logging.cc ('k') | base/mac/mac_util.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef BASE_MAC_MAC_UTIL_H_
6 #define BASE_MAC_MAC_UTIL_H_
7
8 #include <AvailabilityMacros.h>
9 #include <Carbon/Carbon.h>
10 #include <string>
11
12 #include "base/base_export.h"
13 #include "base/logging.h"
14
15 #if defined(__OBJC__)
16 #import <Foundation/Foundation.h>
17 #else // __OBJC__
18 class NSImage;
19 #endif // __OBJC__
20
21 namespace base {
22
23 class FilePath;
24
25 namespace mac {
26
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,
34
35 // kFullScreenModeNormal is not a valid FullScreenMode, but it is useful to
36 // other classes, so we include it here.
37 kFullScreenModeNormal = 10,
38 };
39
40 BASE_EXPORT std::string PathFromFSRef(const FSRef& ref);
41 BASE_EXPORT bool FSRefFromPath(const std::string& path, FSRef* ref);
42
43 // Returns an sRGB color space. The return value is a static value; do not
44 // release it!
45 BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace();
46
47 // Returns the generic RGB color space. The return value is a static value; do
48 // not release it!
49 BASE_EXPORT CGColorSpaceRef GetGenericRGBColorSpace();
50
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();
54
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);
60
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);
68
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);
74
75 // Set the visibility of the cursor.
76 BASE_EXPORT void SetCursorVisibility(bool visible);
77
78 // Activates the process with the given PID.
79 BASE_EXPORT void ActivateProcess(pid_t pid);
80
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();
85
86 // Excludes the file given by |file_path| from being backed up by Time Machine.
87 BASE_EXPORT bool SetFileBackupExclusion(const FilePath& file_path);
88
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);
93
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);
101
102 // Removes the current application from the list Of Login Items.
103 BASE_EXPORT void RemoveFromLoginItems();
104
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();
108
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();
114
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();
118
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);
122
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.
127
128 // Snow Leopard is Mac OS X 10.6, Darwin 10.
129 BASE_EXPORT bool IsOSSnowLeopard();
130
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();
135
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();
140
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();
145
146 // Yosemite is Mac OS X 10.10, Darwin 14.
147 BASE_EXPORT bool IsOSYosemite();
148 BASE_EXPORT bool IsOSYosemiteOrLater();
149
150 // El Capitan is Mac OS X 10.11, Darwin 15.
151 BASE_EXPORT bool IsOSElCapitan();
152 BASE_EXPORT bool IsOSElCapitanOrLater();
153
154 // This should be infrequently used. It only makes sense to use this to avoid
155 // codepaths that are very likely to break on future (unreleased, untested,
156 // unborn) OS releases, or to log when the OS is newer than any known version.
157 BASE_EXPORT bool IsOSLaterThanYosemite_DontCallThis();
158
159 // Inline functions that are redundant due to version ranges being mutually-
160 // exclusive.
161 inline bool IsOSLionOrEarlier() { return !IsOSMountainLionOrLater(); }
162 inline bool IsOSMountainLionOrEarlier() { return !IsOSMavericksOrLater(); }
163 inline bool IsOSMavericksOrEarlier() { return !IsOSYosemiteOrLater(); }
164 inline bool IsOSYosemiteOrEarlier() {
165 return !IsOSElCapitanOrLater();
166 }
167
168 // When the deployment target is set, the code produced cannot run on earlier
169 // OS releases. That enables some of the IsOS* family to be implemented as
170 // constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro
171 // contains the value of the deployment target.
172
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_GE_10_7
176 inline bool IsOSSnowLeopard() { return false; }
177 inline bool IsOSLionOrLater() { return true; }
178 #endif
179
180 #if defined(MAC_OS_X_VERSION_10_7) && \
181 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_7
182 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7
183 inline bool IsOSLion() { return false; }
184 #endif
185
186 #if defined(MAC_OS_X_VERSION_10_8) && \
187 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
188 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_8
189 inline bool IsOSMountainLionOrLater() { return true; }
190 #endif
191
192 #if defined(MAC_OS_X_VERSION_10_8) && \
193 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_8
194 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_8
195 inline bool IsOSMountainLion() { return false; }
196 #endif
197
198 #if defined(MAC_OS_X_VERSION_10_9) && \
199 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
200 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_9
201 inline bool IsOSMavericksOrLater() { return true; }
202 #endif
203
204 #if defined(MAC_OS_X_VERSION_10_9) && \
205 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
206 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9
207 inline bool IsOSMavericks() { return false; }
208 #endif
209
210 #if defined(MAC_OS_X_VERSION_10_10) && \
211 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
212 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10
213 inline bool IsOSYosemiteOrLater() { return true; }
214 #endif
215
216 #if defined(MAC_OS_X_VERSION_10_10) && \
217 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_10
218 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10
219 inline bool IsOSYosemite() { return false; }
220 inline bool IsOSLaterThanYosemite_DontCallThis() { return true; }
221 #endif
222
223 #if defined(MAC_OS_X_VERSION_10_11) && \
224 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11
225 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11
226 inline bool IsOSElCapitanOrLater() {
227 return true;
228 }
229 #endif
230
231 #if defined(MAC_OS_X_VERSION_10_11) && \
232 MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_11
233 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11
234 inline bool IsOSElCapitan() {
235 return false;
236 }
237 #endif
238
239 // Retrieve the system's model identifier string from the IOKit registry:
240 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
241 // failure.
242 BASE_EXPORT std::string GetModelIdentifier();
243
244 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1).
245 // If any error occurs, none of the input pointers are touched.
246 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
247 std::string* type,
248 int32* major,
249 int32* minor);
250
251 } // namespace mac
252 } // namespace base
253
254 #endif // BASE_MAC_MAC_UTIL_H_
OLDNEW
« no previous file with comments | « base/mac/mac_logging.cc ('k') | base/mac/mac_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698