Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/app/startup/setup_debugging.h" | 5 #include "ios/chrome/app/startup/setup_debugging.h" |
| 6 | 6 |
| 7 #include <objc/runtime.h> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "components/crash/core/common/objc_zombie.h" | 10 #include "components/crash/core/common/objc_zombie.h" |
| 9 | 11 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
| 12 #endif | 14 #endif |
| 13 | 15 |
| 16 namespace { | |
| 17 | |
| 18 #ifndef NDEBUG | |
| 19 | |
| 20 void swizzleUIImageImageNamed() { | |
| 21 NSMutableSet* whiteList = [NSMutableSet set]; | |
|
marq (ping after 24h)
2017/05/09 09:35:30
Add a comment that the whitelist will be retained
| |
| 22 | |
| 23 // TODO(crbug.com/): Add missing image. | |
| 24 [whiteList addObject:@"card_close_button_pressed_incognito"]; | |
| 25 // TODO(crbug.com/): Add missing image. | |
| 26 [whiteList addObject:@"glif-mic-to-dots-large_37"]; | |
| 27 | |
| 28 // The original implementation of [UIImage imageNamed:]. | |
|
lpromero
2017/05/05 15:24:37
Super tiny nit: Add a dash: "of -[".
marq (ping after 24h)
2017/05/09 09:35:31
I don't think that's needed, since imageNamed: is
sdefresne
2017/05/09 10:07:27
Shouldn't it be "of +[UIImage imageNamed:." then?
marq (ping after 24h)
2017/05/10 12:59:11
Either:
[UIImage imageNamed:]
or
UIImage's +im
jif
2017/05/10 13:34:46
Done.
| |
| 29 // Called by the new implementation. | |
| 30 static IMP originalImp; | |
| 31 IMP* originalImpPtr = &originalImp; | |
| 32 | |
| 33 id swizzleBlock = ^(id self, NSString* imageName) { | |
| 34 // Call the original [UIImage imageNamed:] method. | |
| 35 IMP imp = *originalImpPtr; | |
| 36 Class klass = objc_getClass("UIImage"); | |
|
marq (ping after 24h)
2017/05/09 09:35:30
Don't use the Java 'klass' naming convention. 'cla
sdefresne
2017/05/09 10:07:27
But "class" is a C++ reserved name, and cannot be
marq (ping after 24h)
2017/05/10 12:59:11
Then, 'aClass'.
jif
2017/05/10 13:34:46
Done.
| |
| 37 UIImage* image = imp(klass, @selector(imageNamed:), imageName); | |
| 38 | |
| 39 if (![whiteList containsObject:imageName]) { | |
| 40 DCHECK(image); | |
| 41 } | |
| 42 return image; | |
| 43 }; | |
| 44 | |
| 45 Method method = class_getClassMethod([UIImage class], @selector(imageNamed:)); | |
| 46 DCHECK(method); | |
| 47 | |
| 48 IMP blockImp = imp_implementationWithBlock(swizzleBlock); | |
| 49 originalImp = method_setImplementation(method, blockImp); | |
| 50 } | |
| 51 | |
| 52 #endif | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 14 @implementation SetupDebugging | 56 @implementation SetupDebugging |
| 15 | 57 |
| 16 + (void)setUpDebuggingOptions { | 58 + (void)setUpDebuggingOptions { |
| 17 // Enable the zombie treadmill on simulator builds. | 59 // Enable the zombie treadmill on simulator builds. |
| 18 // TODO(crbug.com/663390): Consider enabling this on device builds too. | 60 // TODO(crbug.com/663390): Consider enabling this on device builds too. |
| 19 #if TARGET_IPHONE_SIMULATOR | 61 #if TARGET_IPHONE_SIMULATOR |
| 20 DCHECK(ObjcEvilDoers::ZombieEnable(true, 10000)); | 62 DCHECK(ObjcEvilDoers::ZombieEnable(true, 10000)); |
| 21 #endif | 63 #endif |
| 64 | |
| 65 // Enable the detection of missing image assets. | |
| 66 #ifndef NDEBUG | |
| 67 swizzleUIImageImageNamed(); | |
| 68 #endif | |
| 22 } | 69 } |
| 23 | 70 |
| 24 @end | 71 @end |
| OLD | NEW |