Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/full_size_content_window.h" | 5 #import "chrome/browser/ui/cocoa/full_size_content_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/scoped_objc_class_swizzler.h" | |
| 9 | 10 |
| 10 @interface FullSizeContentWindow () | 11 @interface FullSizeContentWindow () |
| 11 | 12 |
| 12 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; | 13 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; |
| 13 | 14 |
| 14 @end | 15 @end |
| 15 | 16 |
| 16 // This view always takes the size of its superview. It is intended to be used | 17 // This view always takes the size of its superview. It is intended to be used |
| 17 // as a NSWindow's contentView. It is needed because NSWindow's implementation | 18 // as a NSWindow's contentView. It is needed because NSWindow's implementation |
| 18 // explicitly resizes the contentView at inopportune times. | 19 // explicitly resizes the contentView at inopportune times. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 37 } | 38 } |
| 38 | 39 |
| 39 - (void)forceFrame:(NSRect)frame { | 40 - (void)forceFrame:(NSRect)frame { |
| 40 forceFrameFlag_ = YES; | 41 forceFrameFlag_ = YES; |
| 41 [super setFrame:frame]; | 42 [super setFrame:frame]; |
| 42 forceFrameFlag_ = NO; | 43 forceFrameFlag_ = NO; |
| 43 } | 44 } |
| 44 | 45 |
| 45 @end | 46 @end |
| 46 | 47 |
| 48 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
| |
| 49 static IMP originalDescriptionWithLocaleImplementation; | |
| 50 | |
| 51 @interface FullSizeContentWindowSwizzlingSupport : NSObject | |
| 52 @end | |
| 53 | |
| 54 @implementation FullSizeContentWindowSwizzlingSupport | |
| 55 | |
| 56 // This method replaces [_NSCallStackArray descriptionWithLocale:indent:] via | |
| 57 // swizzling - see +load below. | |
| 58 - (NSString*)descriptionWithLocale:(id)aLocale | |
| 59 indent:(unsigned long long)indent { | |
| 60 return disableSymbolication ? | |
| 61 @"" : | |
| 62 originalDescriptionWithLocaleImplementation( | |
| 63 self, @selector(descriptionWithLocale:indent:), aLocale, indent); | |
| 64 } | |
| 65 | |
| 66 @end | |
| 67 | |
| 47 @implementation FullSizeContentWindow | 68 @implementation FullSizeContentWindow |
| 48 | 69 |
| 49 #pragma mark - Lifecycle | 70 #pragma mark - Lifecycle |
| 50 | 71 |
| 72 // In initWithContentRect:styleMask:backing:defer:, the call to | |
| 73 // [NSView addSubview:positioned:relativeTo:] causes NSWindow to complain that | |
| 74 // an unknown view is being added to it, and to generate a stack trace. | |
| 75 // Not only does this stack trace pollute the console, it can also take hundreds | |
| 76 // of milliseconds to generate (because of symbolication). The AppKit uses an | |
| 77 // _NSCallStackArray to dump the symbols to the console - by swizzling | |
| 78 // descriptionWithLocale:indent: we can disable this output. See | |
| 79 // crbug.com/520373 . | |
| 80 + (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
| |
| 81 static dispatch_once_t onceToken; | |
| 82 dispatch_once(&onceToken, ^{ | |
| 83 Class callStackArrayClass = NSClassFromString(@"_NSCallStackArray"); | |
| 84 Class swizzleClass = [FullSizeContentWindowSwizzlingSupport class]; | |
| 85 SEL targetSelector = @selector(descriptionWithLocale:indent:); | |
| 86 | |
| 87 if (callStackArrayClass) { | |
| 88 CR_DEFINE_STATIC_LOCAL(base::mac::ScopedObjCClassSwizzler, | |
| 89 callStackSuppressor, (callStackArrayClass, | |
| 90 swizzleClass, targetSelector)); | |
| 91 originalDescriptionWithLocaleImplementation = | |
| 92 callStackSuppressor.GetOriginalImplementation(); | |
| 93 } | |
| 94 }); | |
| 95 } | |
| 96 | |
| 51 - (instancetype)init { | 97 - (instancetype)init { |
| 52 NOTREACHED(); | 98 NOTREACHED(); |
| 53 return nil; | 99 return nil; |
| 54 } | 100 } |
| 55 | 101 |
| 56 - (instancetype)initWithContentRect:(NSRect)contentRect | 102 - (instancetype)initWithContentRect:(NSRect)contentRect |
| 57 styleMask:(NSUInteger)windowStyle | 103 styleMask:(NSUInteger)windowStyle |
| 58 backing:(NSBackingStoreType)bufferingType | 104 backing:(NSBackingStoreType)bufferingType |
| 59 defer:(BOOL)deferCreation { | 105 defer:(BOOL)deferCreation { |
| 60 return [self initWithContentRect:contentRect | 106 return [self initWithContentRect:contentRect |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 80 chromeWindowView_.reset([[FullSizeContentView alloc] init]); | 126 chromeWindowView_.reset([[FullSizeContentView alloc] init]); |
| 81 [chromeWindowView_ | 127 [chromeWindowView_ |
| 82 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 128 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 83 [self setContentView:chromeWindowView_]; | 129 [self setContentView:chromeWindowView_]; |
| 84 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]]; | 130 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]]; |
| 85 | 131 |
| 86 // Our content view overlaps the window control buttons, so we must ensure | 132 // Our content view overlaps the window control buttons, so we must ensure |
| 87 // it is positioned below the buttons. | 133 // it is positioned below the buttons. |
| 88 NSView* superview = [chromeWindowView_ superview]; | 134 NSView* superview = [chromeWindowView_ superview]; |
| 89 [chromeWindowView_ removeFromSuperview]; | 135 [chromeWindowView_ removeFromSuperview]; |
| 136 | |
| 137 // Prevent the AppKit from generating a backtrace to include in it's | |
| 138 // complaint about our upcoming call to addSubview:positioned:relativeTo:. | |
| 139 // See +load for more info. | |
| 140 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
| |
| 141 | |
| 90 [superview addSubview:chromeWindowView_ | 142 [superview addSubview:chromeWindowView_ |
| 91 positioned:NSWindowBelow | 143 positioned:NSWindowBelow |
| 92 relativeTo:nil]; | 144 relativeTo:nil]; |
| 145 | |
| 146 // Clean up from the AppKit console message workaround. | |
| 147 disableSymbolication = NO; | |
| 93 } | 148 } |
| 94 } | 149 } |
| 95 return self; | 150 return self; |
| 96 } | 151 } |
| 97 | 152 |
| 98 - (void)forceContentViewFrame:(NSRect)frame { | 153 - (void)forceContentViewFrame:(NSRect)frame { |
| 99 FullSizeContentView* contentView = | 154 FullSizeContentView* contentView = |
| 100 base::mac::ObjCCast<FullSizeContentView>(chromeWindowView_); | 155 base::mac::ObjCCast<FullSizeContentView>(chromeWindowView_); |
| 101 [contentView forceFrame:frame]; | 156 [contentView forceFrame:frame]; |
| 102 } | 157 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 127 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 182 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
| 128 } | 183 } |
| 129 | 184 |
| 130 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 185 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 131 if (chromeWindowView_) | 186 if (chromeWindowView_) |
| 132 return frameRect; | 187 return frameRect; |
| 133 return [super contentRectForFrameRect:frameRect]; | 188 return [super contentRectForFrameRect:frameRect]; |
| 134 } | 189 } |
| 135 | 190 |
| 136 @end | 191 @end |
| OLD | NEW |