OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import <IOKit/IOKitLib.h> | 8 #import <IOKit/IOKitLib.h> |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <string.h> | 11 #include <string.h> |
12 #include <sys/utsname.h> | 12 #include <sys/utsname.h> |
13 #include <sys/xattr.h> | 13 #include <sys/xattr.h> |
14 | 14 |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/mac/bundle_locations.h" | 17 #include "base/mac/bundle_locations.h" |
18 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
19 #include "base/mac/mac_logging.h" | 19 #include "base/mac/mac_logging.h" |
20 #include "base/mac/scoped_cftyperef.h" | 20 #include "base/mac/scoped_cftyperef.h" |
21 #include "base/mac/scoped_ioobject.h" | 21 #include "base/mac/scoped_ioobject.h" |
22 #include "base/memory/scoped_nsobject.h" | 22 #include "base/mac/scoped_nsobject.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_piece.h" | 24 #include "base/strings/string_piece.h" |
25 #include "base/strings/sys_string_conversions.h" | 25 #include "base/strings/sys_string_conversions.h" |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 namespace mac { | 28 namespace mac { |
29 | 29 |
30 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 30 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
31 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 31 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
32 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 32 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // retained reference to it. Caller is responsible for releasing the reference. | 92 // retained reference to it. Caller is responsible for releasing the reference. |
93 LSSharedFileListItemRef GetLoginItemForApp() { | 93 LSSharedFileListItemRef GetLoginItemForApp() { |
94 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( | 94 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( |
95 NULL, kLSSharedFileListSessionLoginItems, NULL)); | 95 NULL, kLSSharedFileListSessionLoginItems, NULL)); |
96 | 96 |
97 if (!login_items.get()) { | 97 if (!login_items.get()) { |
98 DLOG(ERROR) << "Couldn't get a Login Items list."; | 98 DLOG(ERROR) << "Couldn't get a Login Items list."; |
99 return NULL; | 99 return NULL; |
100 } | 100 } |
101 | 101 |
102 scoped_nsobject<NSArray> login_items_array( | 102 base::scoped_nsobject<NSArray> login_items_array( |
103 CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL))); | 103 CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL))); |
104 | 104 |
105 NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]]; | 105 NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]]; |
106 | 106 |
107 for(NSUInteger i = 0; i < [login_items_array count]; ++i) { | 107 for(NSUInteger i = 0; i < [login_items_array count]; ++i) { |
108 LSSharedFileListItemRef item = reinterpret_cast<LSSharedFileListItemRef>( | 108 LSSharedFileListItemRef item = reinterpret_cast<LSSharedFileListItemRef>( |
109 [login_items_array objectAtIndex:i]); | 109 [login_items_array objectAtIndex:i]); |
110 CFURLRef item_url_ref = NULL; | 110 CFURLRef item_url_ref = NULL; |
111 | 111 |
112 if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr) { | 112 if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr) { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 DLOG(ERROR) << "Couldn't get a Login Items list."; | 482 DLOG(ERROR) << "Couldn't get a Login Items list."; |
483 return; | 483 return; |
484 } | 484 } |
485 | 485 |
486 LSSharedFileListItemRemove(login_items, item); | 486 LSSharedFileListItemRemove(login_items, item); |
487 } | 487 } |
488 | 488 |
489 bool WasLaunchedAsLoginOrResumeItem() { | 489 bool WasLaunchedAsLoginOrResumeItem() { |
490 ProcessSerialNumber psn = { 0, kCurrentProcess }; | 490 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
491 | 491 |
492 scoped_nsobject<NSDictionary> process_info( | 492 base::scoped_nsobject<NSDictionary> process_info( |
493 CFToNSCast(ProcessInformationCopyDictionary(&psn, | 493 CFToNSCast(ProcessInformationCopyDictionary( |
494 kProcessDictionaryIncludeAllInformationMask))); | 494 &psn, kProcessDictionaryIncludeAllInformationMask))); |
495 | 495 |
496 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue]; | 496 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue]; |
497 ProcessSerialNumber parent_psn = | 497 ProcessSerialNumber parent_psn = |
498 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL }; | 498 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL }; |
499 | 499 |
500 scoped_nsobject<NSDictionary> parent_info( | 500 base::scoped_nsobject<NSDictionary> parent_info( |
501 CFToNSCast(ProcessInformationCopyDictionary(&parent_psn, | 501 CFToNSCast(ProcessInformationCopyDictionary( |
502 kProcessDictionaryIncludeAllInformationMask))); | 502 &parent_psn, kProcessDictionaryIncludeAllInformationMask))); |
503 | 503 |
504 // Check that creator process code is that of loginwindow. | 504 // Check that creator process code is that of loginwindow. |
505 BOOL result = | 505 BOOL result = |
506 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"]; | 506 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"]; |
507 | 507 |
508 return result == YES; | 508 return result == YES; |
509 } | 509 } |
510 | 510 |
511 bool WasLaunchedAsHiddenLoginItem() { | 511 bool WasLaunchedAsHiddenLoginItem() { |
512 if (!WasLaunchedAsLoginOrResumeItem()) | 512 if (!WasLaunchedAsLoginOrResumeItem()) |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) | 694 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) |
695 return false; | 695 return false; |
696 *type = ident.substr(0, number_loc); | 696 *type = ident.substr(0, number_loc); |
697 *major = major_tmp; | 697 *major = major_tmp; |
698 *minor = minor_tmp; | 698 *minor = minor_tmp; |
699 return true; | 699 return true; |
700 } | 700 } |
701 | 701 |
702 } // namespace mac | 702 } // namespace mac |
703 } // namespace base | 703 } // namespace base |
OLD | NEW |