Chromium Code Reviews| Index: ios/chrome/app/startup/setup_debugging.mm |
| diff --git a/ios/chrome/app/startup/setup_debugging.mm b/ios/chrome/app/startup/setup_debugging.mm |
| index d918ccb836971567d2034d6cf317a53de7340921..e620d4d8131a1693e0f4927125cc524a5289447e 100644 |
| --- a/ios/chrome/app/startup/setup_debugging.mm |
| +++ b/ios/chrome/app/startup/setup_debugging.mm |
| @@ -4,6 +4,8 @@ |
| #include "ios/chrome/app/startup/setup_debugging.h" |
| +#include <objc/runtime.h> |
| + |
| #include "base/logging.h" |
| #include "components/crash/core/common/objc_zombie.h" |
| @@ -11,6 +13,46 @@ |
| #error "This file requires ARC support." |
| #endif |
| +namespace { |
| + |
| +#ifndef NDEBUG |
| + |
| +void swizzleUIImageImageNamed() { |
| + NSMutableSet* whiteList = [NSMutableSet set]; |
|
marq (ping after 24h)
2017/05/09 09:35:30
Add a comment that the whitelist will be retained
|
| + |
| + // TODO(crbug.com/): Add missing image. |
| + [whiteList addObject:@"card_close_button_pressed_incognito"]; |
| + // TODO(crbug.com/): Add missing image. |
| + [whiteList addObject:@"glif-mic-to-dots-large_37"]; |
| + |
| + // 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.
|
| + // Called by the new implementation. |
| + static IMP originalImp; |
| + IMP* originalImpPtr = &originalImp; |
| + |
| + id swizzleBlock = ^(id self, NSString* imageName) { |
| + // Call the original [UIImage imageNamed:] method. |
| + IMP imp = *originalImpPtr; |
| + 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.
|
| + UIImage* image = imp(klass, @selector(imageNamed:), imageName); |
| + |
| + if (![whiteList containsObject:imageName]) { |
| + DCHECK(image); |
| + } |
| + return image; |
| + }; |
| + |
| + Method method = class_getClassMethod([UIImage class], @selector(imageNamed:)); |
| + DCHECK(method); |
| + |
| + IMP blockImp = imp_implementationWithBlock(swizzleBlock); |
| + originalImp = method_setImplementation(method, blockImp); |
| +} |
| + |
| +#endif |
| + |
| +} // namespace |
| + |
| @implementation SetupDebugging |
| + (void)setUpDebuggingOptions { |
| @@ -19,6 +61,11 @@ + (void)setUpDebuggingOptions { |
| #if TARGET_IPHONE_SIMULATOR |
| DCHECK(ObjcEvilDoers::ZombieEnable(true, 10000)); |
| #endif |
| + |
| +// Enable the detection of missing image assets. |
| +#ifndef NDEBUG |
| + swizzleUIImageImageNamed(); |
| +#endif |
| } |
| @end |