OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac_util.h" | 5 #include "base/mac/mac_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/scoped_nsobject.h" | 13 #include "base/scoped_nsobject.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 | 15 |
16 using base::mac::ScopedCFTypeRef; | 16 namespace base { |
| 17 namespace mac { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // a count of currently outstanding requests for full screen mode from browser | 21 // a count of currently outstanding requests for full screen mode from browser |
21 // windows, plugins, etc. | 22 // windows, plugins, etc. |
22 int g_full_screen_requests[mac_util::kNumFullScreenModes] = { 0, 0, 0}; | 23 int g_full_screen_requests[kNumFullScreenModes] = { 0, 0, 0}; |
23 | 24 |
24 // Sets the appropriate SystemUIMode based on the current full screen requests. | 25 // Sets the appropriate SystemUIMode based on the current full screen requests. |
25 // Since only one SystemUIMode can be active at a given time, full screen | 26 // Since only one SystemUIMode can be active at a given time, full screen |
26 // requests are ordered by priority. If there are no outstanding full screen | 27 // requests are ordered by priority. If there are no outstanding full screen |
27 // requests, reverts to normal mode. If the correct SystemUIMode is already | 28 // requests, reverts to normal mode. If the correct SystemUIMode is already |
28 // set, does nothing. | 29 // set, does nothing. |
29 void SetUIMode() { | 30 void SetUIMode() { |
30 // Get the current UI mode. | 31 // Get the current UI mode. |
31 SystemUIMode current_mode; | 32 SystemUIMode current_mode; |
32 GetSystemUIMode(¤t_mode, NULL); | 33 GetSystemUIMode(¤t_mode, NULL); |
33 | 34 |
34 // Determine which mode should be active, based on which requests are | 35 // Determine which mode should be active, based on which requests are |
35 // currently outstanding. More permissive requests take precedence. For | 36 // currently outstanding. More permissive requests take precedence. For |
36 // example, plugins request |kFullScreenModeAutoHideAll|, while browser | 37 // example, plugins request |kFullScreenModeAutoHideAll|, while browser |
37 // windows request |kFullScreenModeHideDock| when the fullscreen overlay is | 38 // windows request |kFullScreenModeHideDock| when the fullscreen overlay is |
38 // down. Precedence goes to plugins in this case, so AutoHideAll wins over | 39 // down. Precedence goes to plugins in this case, so AutoHideAll wins over |
39 // HideDock. | 40 // HideDock. |
40 SystemUIMode desired_mode = kUIModeNormal; | 41 SystemUIMode desired_mode = kUIModeNormal; |
41 SystemUIOptions desired_options = 0; | 42 SystemUIOptions desired_options = 0; |
42 if (g_full_screen_requests[mac_util::kFullScreenModeAutoHideAll] > 0) { | 43 if (g_full_screen_requests[kFullScreenModeAutoHideAll] > 0) { |
43 desired_mode = kUIModeAllHidden; | 44 desired_mode = kUIModeAllHidden; |
44 desired_options = kUIOptionAutoShowMenuBar; | 45 desired_options = kUIOptionAutoShowMenuBar; |
45 } else if (g_full_screen_requests[mac_util::kFullScreenModeHideDock] > 0) { | 46 } else if (g_full_screen_requests[kFullScreenModeHideDock] > 0) { |
46 desired_mode = kUIModeContentHidden; | 47 desired_mode = kUIModeContentHidden; |
47 } else if (g_full_screen_requests[mac_util::kFullScreenModeHideAll] > 0) { | 48 } else if (g_full_screen_requests[kFullScreenModeHideAll] > 0) { |
48 desired_mode = kUIModeAllHidden; | 49 desired_mode = kUIModeAllHidden; |
49 } | 50 } |
50 | 51 |
51 if (current_mode != desired_mode) | 52 if (current_mode != desired_mode) |
52 SetSystemUIMode(desired_mode, desired_options); | 53 SetSystemUIMode(desired_mode, desired_options); |
53 } | 54 } |
54 | 55 |
55 bool WasLaunchedAsLoginItem() { | 56 bool WasLaunchedAsLoginItem() { |
56 ProcessSerialNumber psn = { 0, kCurrentProcess }; | 57 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
57 | 58 |
58 scoped_nsobject<NSDictionary> process_info( | 59 scoped_nsobject<NSDictionary> process_info( |
59 mac_util::CFToNSCast(ProcessInformationCopyDictionary(&psn, | 60 CFToNSCast(ProcessInformationCopyDictionary(&psn, |
60 kProcessDictionaryIncludeAllInformationMask))); | 61 kProcessDictionaryIncludeAllInformationMask))); |
61 | 62 |
62 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue]; | 63 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue]; |
63 ProcessSerialNumber parent_psn = | 64 ProcessSerialNumber parent_psn = |
64 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL }; | 65 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL }; |
65 | 66 |
66 scoped_nsobject<NSDictionary> parent_info( | 67 scoped_nsobject<NSDictionary> parent_info( |
67 mac_util::CFToNSCast(ProcessInformationCopyDictionary(&parent_psn, | 68 CFToNSCast(ProcessInformationCopyDictionary(&parent_psn, |
68 kProcessDictionaryIncludeAllInformationMask))); | 69 kProcessDictionaryIncludeAllInformationMask))); |
69 | 70 |
70 // Check that creator process code is that of loginwindow. | 71 // Check that creator process code is that of loginwindow. |
71 BOOL result = | 72 BOOL result = |
72 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"]; | 73 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"]; |
73 | 74 |
74 return result == YES; | 75 return result == YES; |
75 } | 76 } |
76 | 77 |
77 // Looks into Shared File Lists corresponding to Login Items for the item | 78 // Looks into Shared File Lists corresponding to Login Items for the item |
78 // representing the current application. If such an item is found, returns | 79 // representing the current application. If such an item is found, returns |
79 // retained reference to it. Caller is responsible for releasing the reference. | 80 // retained reference to it. Caller is responsible for releasing the reference. |
80 LSSharedFileListItemRef GetLoginItemForApp() { | 81 LSSharedFileListItemRef GetLoginItemForApp() { |
81 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( | 82 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( |
82 NULL, kLSSharedFileListSessionLoginItems, NULL)); | 83 NULL, kLSSharedFileListSessionLoginItems, NULL)); |
83 | 84 |
84 if (!login_items.get()) { | 85 if (!login_items.get()) { |
85 LOG(ERROR) << "Couldn't get a Login Items list."; | 86 LOG(ERROR) << "Couldn't get a Login Items list."; |
86 return NULL; | 87 return NULL; |
87 } | 88 } |
88 | 89 |
89 scoped_nsobject<NSArray> login_items_array( | 90 scoped_nsobject<NSArray> login_items_array( |
90 mac_util::CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL))); | 91 CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL))); |
91 | 92 |
92 NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; | 93 NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; |
93 | 94 |
94 for(NSUInteger i = 0; i < [login_items_array count]; ++i) { | 95 for(NSUInteger i = 0; i < [login_items_array count]; ++i) { |
95 LSSharedFileListItemRef item = reinterpret_cast<LSSharedFileListItemRef>( | 96 LSSharedFileListItemRef item = reinterpret_cast<LSSharedFileListItemRef>( |
96 [login_items_array objectAtIndex:i]); | 97 [login_items_array objectAtIndex:i]); |
97 CFURLRef item_url_ref = NULL; | 98 CFURLRef item_url_ref = NULL; |
98 | 99 |
99 if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr) { | 100 if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr) { |
100 ScopedCFTypeRef<CFURLRef> item_url(item_url_ref); | 101 ScopedCFTypeRef<CFURLRef> item_url(item_url_ref); |
(...skipping 17 matching lines...) Expand all Loading... |
118 #endif | 119 #endif |
119 | 120 |
120 bool IsHiddenLoginItem(LSSharedFileListItemRef item) { | 121 bool IsHiddenLoginItem(LSSharedFileListItemRef item) { |
121 ScopedCFTypeRef<CFBooleanRef> hidden(reinterpret_cast<CFBooleanRef>( | 122 ScopedCFTypeRef<CFBooleanRef> hidden(reinterpret_cast<CFBooleanRef>( |
122 LSSharedFileListItemCopyProperty(item, | 123 LSSharedFileListItemCopyProperty(item, |
123 reinterpret_cast<CFStringRef>(kLSSharedFileListLoginItemHidden)))); | 124 reinterpret_cast<CFStringRef>(kLSSharedFileListLoginItemHidden)))); |
124 | 125 |
125 return hidden && hidden == kCFBooleanTrue; | 126 return hidden && hidden == kCFBooleanTrue; |
126 } | 127 } |
127 | 128 |
128 } // end namespace | 129 } // namespace |
129 | |
130 namespace mac_util { | |
131 | 130 |
132 std::string PathFromFSRef(const FSRef& ref) { | 131 std::string PathFromFSRef(const FSRef& ref) { |
133 ScopedCFTypeRef<CFURLRef> url( | 132 ScopedCFTypeRef<CFURLRef> url( |
134 CFURLCreateFromFSRef(kCFAllocatorDefault, &ref)); | 133 CFURLCreateFromFSRef(kCFAllocatorDefault, &ref)); |
135 NSString *path_string = [(NSURL *)url.get() path]; | 134 NSString *path_string = [(NSURL *)url.get() path]; |
136 return [path_string fileSystemRepresentation]; | 135 return [path_string fileSystemRepresentation]; |
137 } | 136 } |
138 | 137 |
139 bool FSRefFromPath(const std::string& path, FSRef* ref) { | 138 bool FSRefFromPath(const std::string& path, FSRef* ref) { |
140 OSStatus status = FSPathMakeRef((const UInt8*)path.c_str(), | 139 OSStatus status = FSPathMakeRef((const UInt8*)path.c_str(), |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 void NSObjectRetain(void* obj) { | 705 void NSObjectRetain(void* obj) { |
707 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); | 706 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); |
708 [nsobj retain]; | 707 [nsobj retain]; |
709 } | 708 } |
710 | 709 |
711 void NSObjectRelease(void* obj) { | 710 void NSObjectRelease(void* obj) { |
712 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); | 711 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); |
713 [nsobj release]; | 712 [nsobj release]; |
714 } | 713 } |
715 | 714 |
716 } // namespace mac_util | 715 } // namespace mac |
| 716 } // namespace base |
OLD | NEW |