Chromium Code Reviews| 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]])); |
|
Nico
2016/04/29 02:50:57
Splitting these NSClassFromString("foo") -> [foo c
tapted
2016/04/29 03:17:45
Done.
| |
| 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) { \ |
| 338 if (cf_val == NULL) { \ | 342 if (cf_val == NULL) { \ |
| 339 return NULL; \ | 343 return NULL; \ |
| 340 } \ | 344 } \ |
| 341 if (CFGetTypeID(cf_val) == TypeCF##GetTypeID()) { \ | 345 if (CFGetTypeID(cf_val) == TypeCF##GetTypeID()) { \ |
| 342 return (TypeCF##Ref)(cf_val); \ | 346 return (TypeCF##Ref)(cf_val); \ |
| 343 } \ | 347 } \ |
| 344 return NULL; \ | 348 return NULL; \ |
| 345 } \ | |
| 346 \ | |
| 347 template<> TypeCF##Ref \ | |
| 348 CFCastStrict<TypeCF##Ref>(const CFTypeRef& cf_val) { \ | |
| 349 TypeCF##Ref rv = CFCast<TypeCF##Ref>(cf_val); \ | |
| 350 DCHECK(cf_val == NULL || rv); \ | |
| 351 return rv; \ | |
| 352 } | 349 } |
| 353 | 350 |
| 354 CF_CAST_DEFN(CFArray); | 351 CF_CAST_DEFN(CFArray); |
| 355 CF_CAST_DEFN(CFBag); | 352 CF_CAST_DEFN(CFBag); |
| 356 CF_CAST_DEFN(CFBoolean); | 353 CF_CAST_DEFN(CFBoolean); |
| 357 CF_CAST_DEFN(CFData); | 354 CF_CAST_DEFN(CFData); |
| 358 CF_CAST_DEFN(CFDate); | 355 CF_CAST_DEFN(CFDate); |
| 359 CF_CAST_DEFN(CFDictionary); | 356 CF_CAST_DEFN(CFDictionary); |
| 360 CF_CAST_DEFN(CFNull); | 357 CF_CAST_DEFN(CFNull); |
| 361 CF_CAST_DEFN(CFNumber); | 358 CF_CAST_DEFN(CFNumber); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 381 return NULL; | 378 return NULL; |
| 382 } | 379 } |
| 383 if (CFGetTypeID(cf_val) == CTFontGetTypeID()) { | 380 if (CFGetTypeID(cf_val) == CTFontGetTypeID()) { |
| 384 return (CTFontRef)(cf_val); | 381 return (CTFontRef)(cf_val); |
| 385 } | 382 } |
| 386 | 383 |
| 387 if (!_CFIsObjC(CTFontGetTypeID(), cf_val)) | 384 if (!_CFIsObjC(CTFontGetTypeID(), cf_val)) |
| 388 return NULL; | 385 return NULL; |
| 389 | 386 |
| 390 id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val)); | 387 id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val)); |
| 391 if ([ns_val isKindOfClass:NSClassFromString(@"NSFont")]) { | 388 if ([ns_val isKindOfClass:[NSFont class]]) { |
| 392 return (CTFontRef)(cf_val); | 389 return (CTFontRef)(cf_val); |
| 393 } | 390 } |
| 394 return NULL; | 391 return NULL; |
| 395 } | 392 } |
| 396 | |
| 397 template<> CTFontRef | |
| 398 CFCastStrict<CTFontRef>(const CFTypeRef& cf_val) { | |
| 399 CTFontRef rv = CFCast<CTFontRef>(cf_val); | |
| 400 DCHECK(cf_val == NULL || rv); | |
| 401 return rv; | |
| 402 } | |
| 403 #endif | 393 #endif |
| 404 | 394 |
| 405 #if !defined(OS_IOS) | 395 #if !defined(OS_IOS) |
| 406 CF_CAST_DEFN(SecACL); | 396 CF_CAST_DEFN(SecACL); |
| 407 CF_CAST_DEFN(SecTrustedApplication); | 397 CF_CAST_DEFN(SecTrustedApplication); |
| 408 #endif | 398 #endif |
| 409 | 399 |
| 410 #undef CF_CAST_DEFN | 400 #undef CF_CAST_DEFN |
| 411 | 401 |
| 412 std::string GetValueFromDictionaryErrorMessage( | 402 std::string GetValueFromDictionaryErrorMessage( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 453 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
| 464 } | 454 } |
| 465 o << "Code: " << CFErrorGetCode(err) | 455 o << "Code: " << CFErrorGetCode(err) |
| 466 << " Domain: " << CFErrorGetDomain(err) | 456 << " Domain: " << CFErrorGetDomain(err) |
| 467 << " Desc: " << desc.get(); | 457 << " Desc: " << desc.get(); |
| 468 if(errorDesc) { | 458 if(errorDesc) { |
| 469 o << "(" << errorDesc << ")"; | 459 o << "(" << errorDesc << ")"; |
| 470 } | 460 } |
| 471 return o; | 461 return o; |
| 472 } | 462 } |
| OLD | NEW |