| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mac_util.h" | 5 #include "base/mac/mac_util.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/utsname.h> | 9 #include <sys/utsname.h> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } else if (g_full_screen_requests[kFullScreenModeHideDock] > 0) { | 49 } else if (g_full_screen_requests[kFullScreenModeHideDock] > 0) { |
| 50 desired_mode = kUIModeContentHidden; | 50 desired_mode = kUIModeContentHidden; |
| 51 } else if (g_full_screen_requests[kFullScreenModeHideAll] > 0) { | 51 } else if (g_full_screen_requests[kFullScreenModeHideAll] > 0) { |
| 52 desired_mode = kUIModeAllHidden; | 52 desired_mode = kUIModeAllHidden; |
| 53 } | 53 } |
| 54 | 54 |
| 55 if (current_mode != desired_mode) | 55 if (current_mode != desired_mode) |
| 56 SetSystemUIMode(desired_mode, desired_options); | 56 SetSystemUIMode(desired_mode, desired_options); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool WasLaunchedAsLoginItem() { | |
| 60 ProcessSerialNumber psn = { 0, kCurrentProcess }; | |
| 61 | |
| 62 scoped_nsobject<NSDictionary> process_info( | |
| 63 CFToNSCast(ProcessInformationCopyDictionary(&psn, | |
| 64 kProcessDictionaryIncludeAllInformationMask))); | |
| 65 | |
| 66 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue]; | |
| 67 ProcessSerialNumber parent_psn = | |
| 68 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL }; | |
| 69 | |
| 70 scoped_nsobject<NSDictionary> parent_info( | |
| 71 CFToNSCast(ProcessInformationCopyDictionary(&parent_psn, | |
| 72 kProcessDictionaryIncludeAllInformationMask))); | |
| 73 | |
| 74 // Check that creator process code is that of loginwindow. | |
| 75 BOOL result = | |
| 76 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"]; | |
| 77 | |
| 78 return result == YES; | |
| 79 } | |
| 80 | |
| 81 // Looks into Shared File Lists corresponding to Login Items for the item | 59 // Looks into Shared File Lists corresponding to Login Items for the item |
| 82 // representing the current application. If such an item is found, returns a | 60 // representing the current application. If such an item is found, returns a |
| 83 // retained reference to it. Caller is responsible for releasing the reference. | 61 // retained reference to it. Caller is responsible for releasing the reference. |
| 84 LSSharedFileListItemRef GetLoginItemForApp() { | 62 LSSharedFileListItemRef GetLoginItemForApp() { |
| 85 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( | 63 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( |
| 86 NULL, kLSSharedFileListSessionLoginItems, NULL)); | 64 NULL, kLSSharedFileListSessionLoginItems, NULL)); |
| 87 | 65 |
| 88 if (!login_items.get()) { | 66 if (!login_items.get()) { |
| 89 LOG(ERROR) << "Couldn't get a Login Items list."; | 67 LOG(ERROR) << "Couldn't get a Login Items list."; |
| 90 return NULL; | 68 return NULL; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 NULL, kLSSharedFileListSessionLoginItems, NULL)); | 443 NULL, kLSSharedFileListSessionLoginItems, NULL)); |
| 466 | 444 |
| 467 if (!login_items.get()) { | 445 if (!login_items.get()) { |
| 468 LOG(ERROR) << "Couldn't get a Login Items list."; | 446 LOG(ERROR) << "Couldn't get a Login Items list."; |
| 469 return; | 447 return; |
| 470 } | 448 } |
| 471 | 449 |
| 472 LSSharedFileListItemRemove(login_items, item); | 450 LSSharedFileListItemRemove(login_items, item); |
| 473 } | 451 } |
| 474 | 452 |
| 453 bool WasLaunchedAsLoginOrResumeItem() { |
| 454 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 455 |
| 456 scoped_nsobject<NSDictionary> process_info( |
| 457 CFToNSCast(ProcessInformationCopyDictionary(&psn, |
| 458 kProcessDictionaryIncludeAllInformationMask))); |
| 459 |
| 460 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue]; |
| 461 ProcessSerialNumber parent_psn = |
| 462 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL }; |
| 463 |
| 464 scoped_nsobject<NSDictionary> parent_info( |
| 465 CFToNSCast(ProcessInformationCopyDictionary(&parent_psn, |
| 466 kProcessDictionaryIncludeAllInformationMask))); |
| 467 |
| 468 // Check that creator process code is that of loginwindow. |
| 469 BOOL result = |
| 470 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"]; |
| 471 |
| 472 return result == YES; |
| 473 } |
| 474 |
| 475 bool WasLaunchedAsHiddenLoginItem() { | 475 bool WasLaunchedAsHiddenLoginItem() { |
| 476 if (!WasLaunchedAsLoginItem()) | 476 if (!WasLaunchedAsLoginOrResumeItem()) |
| 477 return false; | 477 return false; |
| 478 | 478 |
| 479 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); | 479 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); |
| 480 if (!item.get()) { | 480 if (!item.get()) { |
| 481 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; | 481 // Lion can launch items for the resume feature. So log an error only for |
| 482 // Snow Leopard or earlier. |
| 483 if (IsOSSnowLeopardOrEarlier()) |
| 484 LOG(ERROR) << |
| 485 "Process launched at Login but can't access Login Item List."; |
| 486 |
| 482 return false; | 487 return false; |
| 483 } | 488 } |
| 484 return IsHiddenLoginItem(item); | 489 return IsHiddenLoginItem(item); |
| 485 } | 490 } |
| 486 | 491 |
| 487 namespace { | 492 namespace { |
| 488 | 493 |
| 489 // Returns the running system's Darwin major version. Don't call this, it's | 494 // Returns the running system's Darwin major version. Don't call this, it's |
| 490 // an implementation detail and its result is meant to be cached by | 495 // an implementation detail and its result is meant to be cached by |
| 491 // MacOSXMinorVersion. | 496 // MacOSXMinorVersion. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 #endif | 613 #endif |
| 609 | 614 |
| 610 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7) | 615 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7) |
| 611 bool IsOSLaterThanLion() { | 616 bool IsOSLaterThanLion() { |
| 612 return MacOSXMinorVersion() > LION_MINOR_VERSION; | 617 return MacOSXMinorVersion() > LION_MINOR_VERSION; |
| 613 } | 618 } |
| 614 #endif | 619 #endif |
| 615 | 620 |
| 616 } // namespace mac | 621 } // namespace mac |
| 617 } // namespace base | 622 } // namespace base |
| OLD | NEW |