Chromium Code Reviews| Index: chrome/browser/ui/cocoa/full_size_content_window.mm |
| diff --git a/chrome/browser/ui/cocoa/full_size_content_window.mm b/chrome/browser/ui/cocoa/full_size_content_window.mm |
| index 555c523fa209983c74662b42b9cfb23c12e579ca..5d32a643413ac6d7110bd36f14922a77e31e5e28 100644 |
| --- a/chrome/browser/ui/cocoa/full_size_content_window.mm |
| +++ b/chrome/browser/ui/cocoa/full_size_content_window.mm |
| @@ -6,6 +6,7 @@ |
| #include "base/logging.h" |
| #include "base/mac/foundation_util.h" |
| +#include "base/mac/scoped_objc_class_swizzler.h" |
| @interface FullSizeContentWindow () |
| @@ -44,10 +45,55 @@ |
| @end |
| +static BOOL disableSymbolication = NO; |
|
Robert Sesek
2016/01/05 22:17:00
naming: g_disable_symbolication, same as below
shrike
2016/01/05 22:53:01
Thank you - I had looked for the naming convention
|
| +static IMP originalDescriptionWithLocaleImplementation; |
| + |
| +@interface FullSizeContentWindowSwizzlingSupport : NSObject |
| +@end |
| + |
| +@implementation FullSizeContentWindowSwizzlingSupport |
| + |
| +// This method replaces [_NSCallStackArray descriptionWithLocale:indent:] via |
| +// swizzling - see +load below. |
| +- (NSString*)descriptionWithLocale:(id)aLocale |
| + indent:(unsigned long long)indent { |
| + return disableSymbolication ? |
| + @"" : |
| + originalDescriptionWithLocaleImplementation( |
| + self, @selector(descriptionWithLocale:indent:), aLocale, indent); |
| +} |
| + |
| +@end |
| + |
| @implementation FullSizeContentWindow |
| #pragma mark - Lifecycle |
| +// In initWithContentRect:styleMask:backing:defer:, the call to |
| +// [NSView addSubview:positioned:relativeTo:] causes NSWindow to complain that |
| +// an unknown view is being added to it, and to generate a stack trace. |
| +// Not only does this stack trace pollute the console, it can also take hundreds |
| +// of milliseconds to generate (because of symbolication). The AppKit uses an |
| +// _NSCallStackArray to dump the symbols to the console - by swizzling |
| +// descriptionWithLocale:indent: we can disable this output. See |
| +// crbug.com/520373 . |
| ++ (void)load { |
|
Robert Sesek
2016/01/05 22:16:59
Can you limit this to just the browser process, li
shrike
2016/01/05 22:53:01
Thank you. I wondered about this but didn't see ho
|
| + static dispatch_once_t onceToken; |
| + dispatch_once(&onceToken, ^{ |
| + Class callStackArrayClass = NSClassFromString(@"_NSCallStackArray"); |
| + Class swizzleClass = [FullSizeContentWindowSwizzlingSupport class]; |
| + SEL targetSelector = @selector(descriptionWithLocale:indent:); |
| + |
| + if (callStackArrayClass) { |
| + CR_DEFINE_STATIC_LOCAL(base::mac::ScopedObjCClassSwizzler, |
| + callStackSuppressor, (callStackArrayClass, |
| + swizzleClass, targetSelector)); |
| + originalDescriptionWithLocaleImplementation = |
| + callStackSuppressor.GetOriginalImplementation(); |
| + } |
| + }); |
| +} |
| + |
| - (instancetype)init { |
| NOTREACHED(); |
| return nil; |
| @@ -87,9 +133,18 @@ |
| // it is positioned below the buttons. |
| NSView* superview = [chromeWindowView_ superview]; |
| [chromeWindowView_ removeFromSuperview]; |
| + |
| + // Prevent the AppKit from generating a backtrace to include in it's |
| + // complaint about our upcoming call to addSubview:positioned:relativeTo:. |
| + // See +load for more info. |
| + disableSymbolication = YES; |
|
Robert Sesek
2016/01/05 22:16:59
You can use base::AutoReset<BOOL>
shrike
2016/01/05 22:53:01
Thank you again! I wondered if there was a mechani
|
| + |
| [superview addSubview:chromeWindowView_ |
| positioned:NSWindowBelow |
| relativeTo:nil]; |
| + |
| + // Clean up from the AppKit console message workaround. |
| + disableSymbolication = NO; |
| } |
| } |
| return self; |