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/foundation_util.h" | 5 #include "base/mac/foundation_util.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/bundle_locations.h" | 12 #include "base/mac/bundle_locations.h" |
13 #include "base/mac/mac_logging.h" | 13 #include "base/mac/mac_logging.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 | 15 |
| 16 #if !defined(OS_IOS) |
16 extern "C" { | 17 extern "C" { |
17 CFTypeID SecACLGetTypeID(); | 18 CFTypeID SecACLGetTypeID(); |
18 CFTypeID SecTrustedApplicationGetTypeID(); | 19 CFTypeID SecTrustedApplicationGetTypeID(); |
19 } // extern "C" | 20 } // extern "C" |
| 21 #endif |
20 | 22 |
21 namespace base { | 23 namespace base { |
22 namespace mac { | 24 namespace mac { |
23 | 25 |
24 static bool g_override_am_i_bundled = false; | 26 static bool g_override_am_i_bundled = false; |
25 static bool g_override_am_i_bundled_value = false; | 27 static bool g_override_am_i_bundled_value = false; |
26 | 28 |
27 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled | 29 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled |
28 static bool UncachedAmIBundled() { | 30 static bool UncachedAmIBundled() { |
| 31 #if defined(OS_IOS) |
| 32 // All apps are bundled on iOS |
| 33 return true; |
| 34 #else |
29 if (g_override_am_i_bundled) | 35 if (g_override_am_i_bundled) |
30 return g_override_am_i_bundled_value; | 36 return g_override_am_i_bundled_value; |
31 | 37 |
32 ProcessSerialNumber psn = {0, kCurrentProcess}; | 38 ProcessSerialNumber psn = {0, kCurrentProcess}; |
33 | 39 |
34 FSRef fsref; | 40 FSRef fsref; |
35 OSStatus pbErr; | 41 OSStatus pbErr; |
36 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { | 42 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { |
37 OSSTATUS_DLOG(ERROR, pbErr) << "GetProcessBundleLocation failed"; | 43 OSSTATUS_DLOG(ERROR, pbErr) << "GetProcessBundleLocation failed"; |
38 return false; | 44 return false; |
39 } | 45 } |
40 | 46 |
41 FSCatalogInfo info; | 47 FSCatalogInfo info; |
42 OSErr fsErr; | 48 OSErr fsErr; |
43 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, | 49 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, |
44 NULL, NULL, NULL)) != noErr) { | 50 NULL, NULL, NULL)) != noErr) { |
45 OSSTATUS_DLOG(ERROR, fsErr) << "FSGetCatalogInfo failed"; | 51 OSSTATUS_DLOG(ERROR, fsErr) << "FSGetCatalogInfo failed"; |
46 return false; | 52 return false; |
47 } | 53 } |
48 | 54 |
49 return info.nodeFlags & kFSNodeIsDirectoryMask; | 55 return info.nodeFlags & kFSNodeIsDirectoryMask; |
| 56 #endif |
50 } | 57 } |
51 | 58 |
52 bool AmIBundled() { | 59 bool AmIBundled() { |
53 // If the return value is not cached, this function will return different | 60 // If the return value is not cached, this function will return different |
54 // values depending on when it's called. This confuses some client code, see | 61 // values depending on when it's called. This confuses some client code, see |
55 // http://crbug.com/63183 . | 62 // http://crbug.com/63183 . |
56 static bool result = UncachedAmIBundled(); | 63 static bool result = UncachedAmIBundled(); |
57 DCHECK_EQ(result, UncachedAmIBundled()) | 64 DCHECK_EQ(result, UncachedAmIBundled()) |
58 << "The return value of AmIBundled() changed. This will confuse tests. " | 65 << "The return value of AmIBundled() changed. This will confuse tests. " |
59 << "Call SetAmIBundled() override manually if your test binary " | 66 << "Call SetAmIBundled() override manually if your test binary " |
60 << "delay-loads the framework."; | 67 << "delay-loads the framework."; |
61 return result; | 68 return result; |
62 } | 69 } |
63 | 70 |
64 void SetOverrideAmIBundled(bool value) { | 71 void SetOverrideAmIBundled(bool value) { |
| 72 #if defined(OS_IOS) |
| 73 // It doesn't make sense not to be bundled on iOS. |
| 74 if (!value) |
| 75 NOTREACHED(); |
| 76 #endif |
65 g_override_am_i_bundled = true; | 77 g_override_am_i_bundled = true; |
66 g_override_am_i_bundled_value = value; | 78 g_override_am_i_bundled_value = value; |
67 } | 79 } |
68 | 80 |
69 bool IsBackgroundOnlyProcess() { | 81 bool IsBackgroundOnlyProcess() { |
70 // This function really does want to examine NSBundle's idea of the main | 82 // This function really does want to examine NSBundle's idea of the main |
71 // bundle dictionary. It needs to look at the actual running .app's | 83 // bundle dictionary. It needs to look at the actual running .app's |
72 // Info.plist to access its LSUIElement property. | 84 // Info.plist to access its LSUIElement property. |
73 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary]; | 85 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary]; |
74 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO; | 86 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 CF_CAST_DEFN(CFBag); | 322 CF_CAST_DEFN(CFBag); |
311 CF_CAST_DEFN(CFBoolean); | 323 CF_CAST_DEFN(CFBoolean); |
312 CF_CAST_DEFN(CFData); | 324 CF_CAST_DEFN(CFData); |
313 CF_CAST_DEFN(CFDate); | 325 CF_CAST_DEFN(CFDate); |
314 CF_CAST_DEFN(CFDictionary); | 326 CF_CAST_DEFN(CFDictionary); |
315 CF_CAST_DEFN(CFNull); | 327 CF_CAST_DEFN(CFNull); |
316 CF_CAST_DEFN(CFNumber); | 328 CF_CAST_DEFN(CFNumber); |
317 CF_CAST_DEFN(CFSet); | 329 CF_CAST_DEFN(CFSet); |
318 CF_CAST_DEFN(CFString); | 330 CF_CAST_DEFN(CFString); |
319 | 331 |
| 332 #if !defined(OS_IOS) |
320 CF_CAST_DEFN(SecACL); | 333 CF_CAST_DEFN(SecACL); |
321 CF_CAST_DEFN(SecTrustedApplication); | 334 CF_CAST_DEFN(SecTrustedApplication); |
| 335 #endif |
322 | 336 |
323 #undef CF_CAST_DEFN | 337 #undef CF_CAST_DEFN |
324 | 338 |
325 std::string GetValueFromDictionaryErrorMessage( | 339 std::string GetValueFromDictionaryErrorMessage( |
326 CFStringRef key, const std::string& expected_type, CFTypeRef value) { | 340 CFStringRef key, const std::string& expected_type, CFTypeRef value) { |
327 ScopedCFTypeRef<CFStringRef> actual_type_ref( | 341 ScopedCFTypeRef<CFStringRef> actual_type_ref( |
328 CFCopyTypeIDDescription(CFGetTypeID(value))); | 342 CFCopyTypeIDDescription(CFGetTypeID(value))); |
329 return "Expected value for key " + | 343 return "Expected value for key " + |
330 base::SysCFStringRefToUTF8(key) + | 344 base::SysCFStringRefToUTF8(key) + |
331 " to be " + | 345 " to be " + |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 378 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
365 } | 379 } |
366 o << "Code: " << CFErrorGetCode(err) | 380 o << "Code: " << CFErrorGetCode(err) |
367 << " Domain: " << CFErrorGetDomain(err) | 381 << " Domain: " << CFErrorGetDomain(err) |
368 << " Desc: " << desc.get(); | 382 << " Desc: " << desc.get(); |
369 if(errorDesc) { | 383 if(errorDesc) { |
370 o << "(" << errorDesc << ")"; | 384 o << "(" << errorDesc << ")"; |
371 } | 385 } |
372 return o; | 386 return o; |
373 } | 387 } |
OLD | NEW |