| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/mac/bundle_locations.h" | 13 #include "base/mac/bundle_locations.h" |
| 14 #include "base/mac/mac_logging.h" | 14 #include "base/mac/mac_logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 | 19 |
| 20 #if !defined(OS_IOS) | 20 #if !defined(OS_IOS) |
| 21 #import <AppKit/AppKit.h> |
| 22 #endif |
| 23 |
| 24 #if !defined(OS_IOS) |
| 21 extern "C" { | 25 extern "C" { |
| 22 CFTypeID SecACLGetTypeID(); | 26 CFTypeID SecACLGetTypeID(); |
| 23 CFTypeID SecTrustedApplicationGetTypeID(); | 27 CFTypeID SecTrustedApplicationGetTypeID(); |
| 24 Boolean _CFIsObjC(CFTypeID typeID, CFTypeRef obj); | 28 Boolean _CFIsObjC(CFTypeID typeID, CFTypeRef obj); |
| 25 } // extern "C" | 29 } // extern "C" |
| 26 #endif | 30 #endif |
| 27 | 31 |
| 28 namespace base { | 32 namespace base { |
| 29 namespace mac { | 33 namespace mac { |
| 30 | 34 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 #else | 313 #else |
| 310 // The NSFont/CTFont toll-free bridging is broken when it comes to type | 314 // The NSFont/CTFont toll-free bridging is broken when it comes to type |
| 311 // checking, so do some special-casing. | 315 // checking, so do some special-casing. |
| 312 // http://www.openradar.me/15341349 rdar://15341349 | 316 // http://www.openradar.me/15341349 rdar://15341349 |
| 313 NSFont* CFToNSCast(CTFontRef cf_val) { | 317 NSFont* CFToNSCast(CTFontRef cf_val) { |
| 314 NSFont* ns_val = | 318 NSFont* ns_val = |
| 315 const_cast<NSFont*>(reinterpret_cast<const NSFont*>(cf_val)); | 319 const_cast<NSFont*>(reinterpret_cast<const NSFont*>(cf_val)); |
| 316 DCHECK(!cf_val || | 320 DCHECK(!cf_val || |
| 317 CTFontGetTypeID() == CFGetTypeID(cf_val) || | 321 CTFontGetTypeID() == CFGetTypeID(cf_val) || |
| 318 (_CFIsObjC(CTFontGetTypeID(), cf_val) && | 322 (_CFIsObjC(CTFontGetTypeID(), cf_val) && |
| 319 [ns_val isKindOfClass:NSClassFromString(@"NSFont")])); | 323 [ns_val isKindOfClass:[NSFont class]])); |
| 320 return ns_val; | 324 return ns_val; |
| 321 } | 325 } |
| 322 | 326 |
| 323 CTFontRef NSToCFCast(NSFont* ns_val) { | 327 CTFontRef NSToCFCast(NSFont* ns_val) { |
| 324 CTFontRef cf_val = reinterpret_cast<CTFontRef>(ns_val); | 328 CTFontRef cf_val = reinterpret_cast<CTFontRef>(ns_val); |
| 325 DCHECK(!cf_val || | 329 DCHECK(!cf_val || |
| 326 CTFontGetTypeID() == CFGetTypeID(cf_val) || | 330 CTFontGetTypeID() == CFGetTypeID(cf_val) || |
| 327 [ns_val isKindOfClass:NSClassFromString(@"NSFont")]); | 331 [ns_val isKindOfClass:[NSFont class]]); |
| 328 return cf_val; | 332 return cf_val; |
| 329 } | 333 } |
| 330 #endif | 334 #endif |
| 331 | 335 |
| 332 #undef CF_TO_NS_CAST_DEFN | 336 #undef CF_TO_NS_CAST_DEFN |
| 333 #undef CF_TO_NS_MUTABLE_CAST_DEFN | 337 #undef CF_TO_NS_MUTABLE_CAST_DEFN |
| 334 | 338 |
| 335 #define CF_CAST_DEFN(TypeCF) \ | 339 #define CF_CAST_DEFN(TypeCF) \ |
| 336 template<> TypeCF##Ref \ | 340 template<> TypeCF##Ref \ |
| 337 CFCast<TypeCF##Ref>(const CFTypeRef& cf_val) { \ | 341 CFCast<TypeCF##Ref>(const CFTypeRef& cf_val) { \ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return NULL; | 385 return NULL; |
| 382 } | 386 } |
| 383 if (CFGetTypeID(cf_val) == CTFontGetTypeID()) { | 387 if (CFGetTypeID(cf_val) == CTFontGetTypeID()) { |
| 384 return (CTFontRef)(cf_val); | 388 return (CTFontRef)(cf_val); |
| 385 } | 389 } |
| 386 | 390 |
| 387 if (!_CFIsObjC(CTFontGetTypeID(), cf_val)) | 391 if (!_CFIsObjC(CTFontGetTypeID(), cf_val)) |
| 388 return NULL; | 392 return NULL; |
| 389 | 393 |
| 390 id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val)); | 394 id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val)); |
| 391 if ([ns_val isKindOfClass:NSClassFromString(@"NSFont")]) { | 395 if ([ns_val isKindOfClass:[NSFont class]]) { |
| 392 return (CTFontRef)(cf_val); | 396 return (CTFontRef)(cf_val); |
| 393 } | 397 } |
| 394 return NULL; | 398 return NULL; |
| 395 } | 399 } |
| 396 | 400 |
| 397 template<> CTFontRef | 401 template<> CTFontRef |
| 398 CFCastStrict<CTFontRef>(const CFTypeRef& cf_val) { | 402 CFCastStrict<CTFontRef>(const CFTypeRef& cf_val) { |
| 399 CTFontRef rv = CFCast<CTFontRef>(cf_val); | 403 CTFontRef rv = CFCast<CTFontRef>(cf_val); |
| 400 DCHECK(cf_val == NULL || rv); | 404 DCHECK(cf_val == NULL || rv); |
| 401 return rv; | 405 return rv; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 467 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
| 464 } | 468 } |
| 465 o << "Code: " << CFErrorGetCode(err) | 469 o << "Code: " << CFErrorGetCode(err) |
| 466 << " Domain: " << CFErrorGetDomain(err) | 470 << " Domain: " << CFErrorGetDomain(err) |
| 467 << " Desc: " << desc.get(); | 471 << " Desc: " << desc.get(); |
| 468 if(errorDesc) { | 472 if(errorDesc) { |
| 469 o << "(" << errorDesc << ")"; | 473 o << "(" << errorDesc << ")"; |
| 470 } | 474 } |
| 471 return o; | 475 return o; |
| 472 } | 476 } |
| OLD | NEW |