• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdint.h>
11 #include <string>
12 
13 #include "base/base_export.h"
14 
15 namespace base {
16 
17 class FilePath;
18 
19 namespace mac {
20 
21 // Full screen modes, in increasing order of priority.  More permissive modes
22 // take predecence.
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 
34 BASE_EXPORT std::string PathFromFSRef(const FSRef& ref);
35 BASE_EXPORT bool FSRefFromPath(const std::string& path, FSRef* ref);
36 
37 // Returns an sRGB color space.  The return value is a static value; do not
38 // release it!
39 BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace();
40 
41 // Returns the generic RGB color space. The return value is a static value; do
42 // not release it!
43 BASE_EXPORT CGColorSpaceRef GetGenericRGBColorSpace();
44 
45 // Returns the color space being used by the main display.  The return value
46 // is a static value; do not release it!
47 BASE_EXPORT CGColorSpaceRef GetSystemColorSpace();
48 
49 // Add a full screen request for the given |mode|.  Must be paired with a
50 // ReleaseFullScreen() call for the same |mode|.  This does not by itself create
51 // a fullscreen window; rather, it manages per-application state related to
52 // hiding the dock and menubar.  Must be called on the main thread.
53 BASE_EXPORT void RequestFullScreen(FullScreenMode mode);
54 
55 // Release a request for full screen mode.  Must be matched with a
56 // RequestFullScreen() call for the same |mode|.  As with RequestFullScreen(),
57 // this does not affect windows directly, but rather manages per-application
58 // state.  For example, if there are no other outstanding
59 // |kFullScreenModeAutoHideAll| requests, this will reshow the menu bar.  Must
60 // be called on main thread.
61 BASE_EXPORT void ReleaseFullScreen(FullScreenMode mode);
62 
63 // Convenience method to switch the current fullscreen mode.  This has the same
64 // net effect as a ReleaseFullScreen(from_mode) call followed immediately by a
65 // RequestFullScreen(to_mode).  Must be called on the main thread.
66 BASE_EXPORT void SwitchFullScreenModes(FullScreenMode from_mode,
67                                        FullScreenMode to_mode);
68 
69 // Returns true if this process is in the foreground, meaning that it's the
70 // frontmost process, the one whose menu bar is shown at the top of the main
71 // display.
72 BASE_EXPORT bool AmIForeground();
73 
74 // Excludes the file given by |file_path| from being backed up by Time Machine.
75 BASE_EXPORT bool SetFileBackupExclusion(const FilePath& file_path);
76 
77 // Checks if the current application is set as a Login Item, so it will launch
78 // on Login. If a non-NULL pointer to is_hidden is passed, the Login Item also
79 // is queried for the 'hide on launch' flag.
80 BASE_EXPORT bool CheckLoginItemStatus(bool* is_hidden);
81 
82 // Adds current application to the set of Login Items with specified "hide"
83 // flag. This has the same effect as adding/removing the application in
84 // SystemPreferences->Accounts->LoginItems or marking Application in the Dock
85 // as "Options->Open on Login".
86 // Does nothing if the application is already set up as Login Item with
87 // specified hide flag.
88 BASE_EXPORT void AddToLoginItems(bool hide_on_startup);
89 
90 // Removes the current application from the list Of Login Items.
91 BASE_EXPORT void RemoveFromLoginItems();
92 
93 // Returns true if the current process was automatically launched as a
94 // 'Login Item' or via Lion's Resume. Used to suppress opening windows.
95 BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
96 
97 // Returns true if the current process was automatically launched as a
98 // 'Login Item' or via Resume, and the 'Reopen windows when logging back in'
99 // checkbox was selected by the user.  This indicates that the previous
100 // session should be restored.
101 BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState();
102 
103 // Returns true if the current process was automatically launched as a
104 // 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
105 BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
106 
107 // Remove the quarantine xattr from the given file. Returns false if there was
108 // an error, or true otherwise.
109 BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path);
110 
111 // Run-time OS version checks. Use these instead of
112 // base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and
113 // "OrLater" variants to those that check for a specific version, unless you
114 // know for sure that you need to check for a specific version.
115 
116 // Mavericks is OS X 10.9, Darwin 13.
117 BASE_EXPORT bool IsOSMavericks();
118 
119 // Yosemite is OS X 10.10, Darwin 14.
120 BASE_EXPORT bool IsOSYosemite();
121 BASE_EXPORT bool IsOSYosemiteOrEarlier();
122 BASE_EXPORT bool IsOSYosemiteOrLater();
123 
124 // El Capitan is OS X 10.11, Darwin 15.
125 BASE_EXPORT bool IsOSElCapitan();
126 BASE_EXPORT bool IsOSElCapitanOrEarlier();
127 BASE_EXPORT bool IsOSElCapitanOrLater();
128 
129 // Sierra is macOS 10.12, Darwin 16.
130 BASE_EXPORT bool IsOSSierra();
131 BASE_EXPORT bool IsOSSierraOrLater();
132 
133 // This should be infrequently used. It only makes sense to use this to avoid
134 // codepaths that are very likely to break on future (unreleased, untested,
135 // unborn) OS releases, or to log when the OS is newer than any known version.
136 BASE_EXPORT bool IsOSLaterThanSierra_DontCallThis();
137 
138 // Inline functions that are redundant due to version ranges being mutually-
139 // exclusive.
IsOSYosemiteOrEarlier()140 inline bool IsOSYosemiteOrEarlier() { return !IsOSElCapitanOrLater(); }
IsOSElCapitanOrEarlier()141 inline bool IsOSElCapitanOrEarlier() { return !IsOSSierraOrLater(); }
142 
143 // When the deployment target is set, the code produced cannot run on earlier
144 // OS releases. That enables some of the IsOS* family to be implemented as
145 // constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro
146 // contains the value of the deployment target.
147 
148 #if defined(MAC_OS_X_VERSION_10_9) && \
149     MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
150 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_9
IsOSMavericks()151 inline bool IsOSMavericks() { return false; }
152 #endif
153 
154 #if defined(MAC_OS_X_VERSION_10_10) && \
155     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
156 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_10
IsOSYosemiteOrLater()157 inline bool IsOSYosemiteOrLater() { return true; }
158 #endif
159 
160 #if defined(MAC_OS_X_VERSION_10_10) && \
161     MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_10
162 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_10
IsOSYosemite()163 inline bool IsOSYosemite() { return false; }
164 #endif
165 
166 #if defined(MAC_OS_X_VERSION_10_11) && \
167     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11
168 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_11
IsOSElCapitanOrLater()169 inline bool IsOSElCapitanOrLater() { return true; }
170 #endif
171 
172 #if defined(MAC_OS_X_VERSION_10_11) && \
173     MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_11
174 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_11
IsOSElCapitan()175 inline bool IsOSElCapitan() { return false; }
176 #endif
177 
178 #if defined(MAC_OS_X_VERSION_10_12) && \
179     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
180 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_12
IsOSSierraOrLater()181 inline bool IsOSSierraOrLater() { return true; }
182 #endif
183 
184 #if defined(MAC_OS_X_VERSION_10_12) && \
185     MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_12
186 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_12
IsOSSierra()187 inline bool IsOSSierra() { return false; }
IsOSLaterThanSierra_DontCallThis()188 inline bool IsOSLaterThanSierra_DontCallThis() { return true; }
189 #endif
190 
191 // Retrieve the system's model identifier string from the IOKit registry:
192 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
193 // failure.
194 BASE_EXPORT std::string GetModelIdentifier();
195 
196 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1).
197 // If any error occurs, none of the input pointers are touched.
198 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
199                                       std::string* type,
200                                       int32_t* major,
201                                       int32_t* minor);
202 
203 }  // namespace mac
204 }  // namespace base
205 
206 #endif  // BASE_MAC_MAC_UTIL_H_
207