• 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 <string>
11 
12 #include "base/base_export.h"
13 #include "base/logging.h"
14 
15 // TODO(rohitrao): Clean up sites that include mac_util.h and remove this line.
16 #include "base/mac/foundation_util.h"
17 
18 #if defined(__OBJC__)
19 #import <Foundation/Foundation.h>
20 #else  // __OBJC__
21 class NSImage;
22 #endif  // __OBJC__
23 
24 namespace base {
25 
26 class FilePath;
27 
28 namespace mac {
29 
30 // Full screen modes, in increasing order of priority.  More permissive modes
31 // take predecence.
32 enum FullScreenMode {
33   kFullScreenModeHideAll = 0,
34   kFullScreenModeHideDock = 1,
35   kFullScreenModeAutoHideAll = 2,
36   kNumFullScreenModes = 3,
37 
38   // kFullScreenModeNormal is not a valid FullScreenMode, but it is useful to
39   // other classes, so we include it here.
40   kFullScreenModeNormal = 10,
41 };
42 
43 BASE_EXPORT std::string PathFromFSRef(const FSRef& ref);
44 BASE_EXPORT bool FSRefFromPath(const std::string& path, FSRef* ref);
45 
46 // Returns an sRGB color space.  The return value is a static value; do not
47 // release it!
48 BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace();
49 
50 // Returns the generic RGB color space. The return value is a static value; do
51 // not release it!
52 BASE_EXPORT CGColorSpaceRef GetGenericRGBColorSpace();
53 
54 // Returns the color space being used by the main display.  The return value
55 // is a static value; do not release it!
56 BASE_EXPORT CGColorSpaceRef GetSystemColorSpace();
57 
58 // Add a full screen request for the given |mode|.  Must be paired with a
59 // ReleaseFullScreen() call for the same |mode|.  This does not by itself create
60 // a fullscreen window; rather, it manages per-application state related to
61 // hiding the dock and menubar.  Must be called on the main thread.
62 BASE_EXPORT void RequestFullScreen(FullScreenMode mode);
63 
64 // Release a request for full screen mode.  Must be matched with a
65 // RequestFullScreen() call for the same |mode|.  As with RequestFullScreen(),
66 // this does not affect windows directly, but rather manages per-application
67 // state.  For example, if there are no other outstanding
68 // |kFullScreenModeAutoHideAll| requests, this will reshow the menu bar.  Must
69 // be called on main thread.
70 BASE_EXPORT void ReleaseFullScreen(FullScreenMode mode);
71 
72 // Convenience method to switch the current fullscreen mode.  This has the same
73 // net effect as a ReleaseFullScreen(from_mode) call followed immediately by a
74 // RequestFullScreen(to_mode).  Must be called on the main thread.
75 BASE_EXPORT void SwitchFullScreenModes(FullScreenMode from_mode,
76                                        FullScreenMode to_mode);
77 
78 // Set the visibility of the cursor.
79 BASE_EXPORT void SetCursorVisibility(bool visible);
80 
81 // Should windows miniaturize on a double-click (on the title bar)?
82 BASE_EXPORT bool ShouldWindowsMiniaturizeOnDoubleClick();
83 
84 // Activates the process with the given PID.
85 BASE_EXPORT void ActivateProcess(pid_t pid);
86 
87 // Returns true if this process is in the foreground, meaning that it's the
88 // frontmost process, the one whose menu bar is shown at the top of the main
89 // display.
90 BASE_EXPORT bool AmIForeground();
91 
92 // Excludes the file given by |file_path| from being backed up by Time Machine.
93 BASE_EXPORT bool SetFileBackupExclusion(const FilePath& file_path);
94 
95 // Checks if the current application is set as a Login Item, so it will launch
96 // on Login. If a non-NULL pointer to is_hidden is passed, the Login Item also
97 // is queried for the 'hide on launch' flag.
98 BASE_EXPORT bool CheckLoginItemStatus(bool* is_hidden);
99 
100 // Adds current application to the set of Login Items with specified "hide"
101 // flag. This has the same effect as adding/removing the application in
102 // SystemPreferences->Accounts->LoginItems or marking Application in the Dock
103 // as "Options->Open on Login".
104 // Does nothing if the application is already set up as Login Item with
105 // specified hide flag.
106 BASE_EXPORT void AddToLoginItems(bool hide_on_startup);
107 
108 // Removes the current application from the list Of Login Items.
109 BASE_EXPORT void RemoveFromLoginItems();
110 
111 // Returns true if the current process was automatically launched as a
112 // 'Login Item' or via Lion's Resume. Used to suppress opening windows.
113 BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
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 IsOSMavericksOrLater();
144 
145 // This should be infrequently used. It only makes sense to use this to avoid
146 // codepaths that are very likely to break on future (unreleased, untested,
147 // unborn) OS releases, or to log when the OS is newer than any known version.
148 BASE_EXPORT bool IsOSLaterThanMavericks_DontCallThis();
149 
150 // Inline functions that are redundant due to version ranges being mutually-
151 // exclusive.
IsOSLionOrEarlier()152 inline bool IsOSLionOrEarlier() { return !IsOSMountainLionOrLater(); }
IsOSMountainLionOrEarlier()153 inline bool IsOSMountainLionOrEarlier() { return !IsOSMavericksOrLater(); }
154 
155 // When the deployment target is set, the code produced cannot run on earlier
156 // OS releases. That enables some of the IsOS* family to be implemented as
157 // constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro
158 // contains the value of the deployment target.
159 
160 #if defined(MAC_OS_X_VERSION_10_7) && \
161     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
162 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7
IsOSSnowLeopard()163 inline bool IsOSSnowLeopard() { return false; }
IsOSLionOrLater()164 inline bool IsOSLionOrLater() { return true; }
165 #endif
166 
167 #if defined(MAC_OS_X_VERSION_10_7) && \
168     MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_7
169 #define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7
IsOSLion()170 inline bool IsOSLion() { return false; }
171 #endif
172 
173 #if defined(MAC_OS_X_VERSION_10_8) && \
174     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
175 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_8
IsOSMountainLionOrLater()176 inline bool IsOSMountainLionOrLater() { return true; }
177 #endif
178 
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_GT_10_8
IsOSMountainLion()182 inline bool IsOSMountainLion() { return false; }
183 #endif
184 
185 #if defined(MAC_OS_X_VERSION_10_9) && \
186     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
187 #define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_9
IsOSMavericksOrLater()188 inline bool IsOSMavericksOrLater() { return true; }
189 #endif
190 
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_GT_10_9
IsOSMavericks()194 inline bool IsOSMavericks() { return false; }
IsOSLaterThanMavericks_DontCallThis()195 inline bool IsOSLaterThanMavericks_DontCallThis() { return true; }
196 #endif
197 
198 // Retrieve the system's model identifier string from the IOKit registry:
199 // for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
200 // failure.
201 BASE_EXPORT std::string GetModelIdentifier();
202 
203 // Parse a model identifier string; for example, into ("MacBookPro", 6, 1).
204 // If any error occurs, none of the input pointers are touched.
205 BASE_EXPORT bool ParseModelIdentifier(const std::string& ident,
206                                       std::string* type,
207                                       int32* major,
208                                       int32* minor);
209 
210 }  // namespace mac
211 }  // namespace base
212 
213 #endif  // BASE_MAC_MAC_UTIL_H_
214