Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: base/mac/foundation_util.mm

Issue 1927003004: Mac: Introduce "StaticCast" variants of base::mac::FooCastStrict, which do not typecheck in Release (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split out NSClassFromString stuff Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 #define CF_CAST_DEFN(TypeCF) \ 335 #define CF_CAST_DEFN(TypeCF) \
336 template<> TypeCF##Ref \ 336 template<> TypeCF##Ref \
337 CFCast<TypeCF##Ref>(const CFTypeRef& cf_val) { \ 337 CFCast<TypeCF##Ref>(const CFTypeRef& cf_val) { \
338 if (cf_val == NULL) { \ 338 if (cf_val == NULL) { \
339 return NULL; \ 339 return NULL; \
340 } \ 340 } \
341 if (CFGetTypeID(cf_val) == TypeCF##GetTypeID()) { \ 341 if (CFGetTypeID(cf_val) == TypeCF##GetTypeID()) { \
342 return (TypeCF##Ref)(cf_val); \ 342 return (TypeCF##Ref)(cf_val); \
343 } \ 343 } \
344 return NULL; \ 344 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 } 345 }
353 346
354 CF_CAST_DEFN(CFArray); 347 CF_CAST_DEFN(CFArray);
355 CF_CAST_DEFN(CFBag); 348 CF_CAST_DEFN(CFBag);
356 CF_CAST_DEFN(CFBoolean); 349 CF_CAST_DEFN(CFBoolean);
357 CF_CAST_DEFN(CFData); 350 CF_CAST_DEFN(CFData);
358 CF_CAST_DEFN(CFDate); 351 CF_CAST_DEFN(CFDate);
359 CF_CAST_DEFN(CFDictionary); 352 CF_CAST_DEFN(CFDictionary);
360 CF_CAST_DEFN(CFNull); 353 CF_CAST_DEFN(CFNull);
361 CF_CAST_DEFN(CFNumber); 354 CF_CAST_DEFN(CFNumber);
(...skipping 24 matching lines...) Expand all
386 379
387 if (!_CFIsObjC(CTFontGetTypeID(), cf_val)) 380 if (!_CFIsObjC(CTFontGetTypeID(), cf_val))
388 return NULL; 381 return NULL;
389 382
390 id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val)); 383 id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val));
391 if ([ns_val isKindOfClass:NSClassFromString(@"NSFont")]) { 384 if ([ns_val isKindOfClass:NSClassFromString(@"NSFont")]) {
392 return (CTFontRef)(cf_val); 385 return (CTFontRef)(cf_val);
393 } 386 }
394 return NULL; 387 return NULL;
395 } 388 }
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 389 #endif
404 390
405 #if !defined(OS_IOS) 391 #if !defined(OS_IOS)
406 CF_CAST_DEFN(SecACL); 392 CF_CAST_DEFN(SecACL);
407 CF_CAST_DEFN(SecTrustedApplication); 393 CF_CAST_DEFN(SecTrustedApplication);
408 #endif 394 #endif
409 395
410 #undef CF_CAST_DEFN 396 #undef CF_CAST_DEFN
411 397
412 std::string GetValueFromDictionaryErrorMessage( 398 std::string GetValueFromDictionaryErrorMessage(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 449 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
464 } 450 }
465 o << "Code: " << CFErrorGetCode(err) 451 o << "Code: " << CFErrorGetCode(err)
466 << " Domain: " << CFErrorGetDomain(err) 452 << " Domain: " << CFErrorGetDomain(err)
467 << " Desc: " << desc.get(); 453 << " Desc: " << desc.get();
468 if(errorDesc) { 454 if(errorDesc) {
469 o << "(" << errorDesc << ")"; 455 o << "(" << errorDesc << ")";
470 } 456 }
471 return o; 457 return o;
472 } 458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698