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 <crt_externs.h> | |
| 8 | |
| 9 #include "base/auto_reset.h" | |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
| 12 #include "base/mac/scoped_objc_class_swizzler.h" | |
| 9 | 13 |
| 10 @interface FullSizeContentWindow () | 14 @interface FullSizeContentWindow () |
| 11 | 15 |
| 12 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; | 16 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; |
| 13 | 17 |
| 14 @end | 18 @end |
| 15 | 19 |
| 16 // This view always takes the size of its superview. It is intended to be used | 20 // 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 | 21 // as a NSWindow's contentView. It is needed because NSWindow's implementation |
| 18 // explicitly resizes the contentView at inopportune times. | 22 // explicitly resizes the contentView at inopportune times. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 37 } | 41 } |
| 38 | 42 |
| 39 - (void)forceFrame:(NSRect)frame { | 43 - (void)forceFrame:(NSRect)frame { |
| 40 forceFrameFlag_ = YES; | 44 forceFrameFlag_ = YES; |
| 41 [super setFrame:frame]; | 45 [super setFrame:frame]; |
| 42 forceFrameFlag_ = NO; | 46 forceFrameFlag_ = NO; |
| 43 } | 47 } |
| 44 | 48 |
| 45 @end | 49 @end |
| 46 | 50 |
| 51 static bool g_disable_call_stack_symbols = false; | |
| 52 static IMP g_original_call_stack_symbols_implementation; | |
| 53 | |
| 54 @interface FullSizeContentWindowSwizzlingSupport : NSObject | |
| 55 @end | |
| 56 | |
| 57 @implementation FullSizeContentWindowSwizzlingSupport | |
| 58 | |
| 59 // This method replaces [NSThread callStackSymbols] via swizzling - see +load | |
| 60 // below. | |
| 61 + (NSArray*)callStackSymbols { | |
| 62 return g_disable_call_stack_symbols ? | |
|
Robert Sesek
2016/01/06 19:36:29
This would probably read easier as if it weren't t
shrike
2016/01/06 19:51:19
Please look at my new variable name - I assume it'
| |
| 63 @[@"+callStackSymbols disabled for performance reasons"] : | |
| 64 g_original_call_stack_symbols_implementation( | |
| 65 self, @selector(callStackSymbols)); | |
| 66 } | |
| 67 | |
| 68 @end | |
| 69 | |
| 47 @implementation FullSizeContentWindow | 70 @implementation FullSizeContentWindow |
| 48 | 71 |
| 49 #pragma mark - Lifecycle | 72 #pragma mark - Lifecycle |
| 50 | 73 |
| 74 // In initWithContentRect:styleMask:backing:defer:, the call to | |
| 75 // [NSView addSubview:positioned:relativeTo:] causes NSWindow to complain that | |
| 76 // an unknown view is being added to it, and to generate a stack trace. | |
| 77 // Not only does this stack trace pollute the console, it can also take hundreds | |
| 78 // of milliseconds to generate (because of symbolication). The AppKit uses an | |
| 79 // _NSCallStackArray to dump the symbols to the console - by swizzling | |
|
Robert Sesek
2016/01/06 19:36:29
This needs a comment update now.
| |
| 80 // descriptionWithLocale:indent: we can disable this output. See | |
| 81 // crbug.com/520373 . | |
| 82 + (void)load { | |
| 83 // Swizzling should only happen in the browser process. | |
| 84 const char* const* const argv = *_NSGetArgv(); | |
| 85 const int argc = *_NSGetArgc(); | |
| 86 const char kType[] = "--type="; | |
| 87 for (int i = 1; i < argc; ++i) { | |
| 88 const char* arg = argv[i]; | |
| 89 if (strncmp(arg, kType, strlen(kType)) == 0) { | |
| 90 return; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 static dispatch_once_t onceToken; | |
| 95 dispatch_once(&onceToken, ^{ | |
| 96 Class targetClass = [NSThread class]; | |
| 97 Class swizzleClass = [FullSizeContentWindowSwizzlingSupport class]; | |
| 98 SEL targetSelector = @selector(callStackSymbols); | |
| 99 | |
| 100 CR_DEFINE_STATIC_LOCAL(base::mac::ScopedObjCClassSwizzler, | |
| 101 callStackSymbolsSuppressor, (targetClass, | |
| 102 swizzleClass, targetSelector)); | |
| 103 g_original_call_stack_symbols_implementation = | |
| 104 callStackSymbolsSuppressor.GetOriginalImplementation(); | |
| 105 }); | |
| 106 } | |
| 107 | |
| 51 - (instancetype)init { | 108 - (instancetype)init { |
| 52 NOTREACHED(); | 109 NOTREACHED(); |
| 53 return nil; | 110 return nil; |
| 54 } | 111 } |
| 55 | 112 |
| 56 - (instancetype)initWithContentRect:(NSRect)contentRect | 113 - (instancetype)initWithContentRect:(NSRect)contentRect |
| 57 styleMask:(NSUInteger)windowStyle | 114 styleMask:(NSUInteger)windowStyle |
| 58 backing:(NSBackingStoreType)bufferingType | 115 backing:(NSBackingStoreType)bufferingType |
| 59 defer:(BOOL)deferCreation { | 116 defer:(BOOL)deferCreation { |
| 60 return [self initWithContentRect:contentRect | 117 return [self initWithContentRect:contentRect |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 80 chromeWindowView_.reset([[FullSizeContentView alloc] init]); | 137 chromeWindowView_.reset([[FullSizeContentView alloc] init]); |
| 81 [chromeWindowView_ | 138 [chromeWindowView_ |
| 82 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 139 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 83 [self setContentView:chromeWindowView_]; | 140 [self setContentView:chromeWindowView_]; |
| 84 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]]; | 141 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]]; |
| 85 | 142 |
| 86 // Our content view overlaps the window control buttons, so we must ensure | 143 // Our content view overlaps the window control buttons, so we must ensure |
| 87 // it is positioned below the buttons. | 144 // it is positioned below the buttons. |
| 88 NSView* superview = [chromeWindowView_ superview]; | 145 NSView* superview = [chromeWindowView_ superview]; |
| 89 [chromeWindowView_ removeFromSuperview]; | 146 [chromeWindowView_ removeFromSuperview]; |
| 147 | |
| 148 // Prevent the AppKit from generating a backtrace to include in it's | |
| 149 // complaint about our upcoming call to addSubview:positioned:relativeTo:. | |
| 150 // See +load for more info. | |
| 151 base::AutoReset<bool> disable_symbolication(&g_disable_call_stack_symbols, | |
| 152 true); | |
| 153 | |
| 90 [superview addSubview:chromeWindowView_ | 154 [superview addSubview:chromeWindowView_ |
| 91 positioned:NSWindowBelow | 155 positioned:NSWindowBelow |
| 92 relativeTo:nil]; | 156 relativeTo:nil]; |
| 93 } | 157 } |
| 94 } | 158 } |
| 95 return self; | 159 return self; |
| 96 } | 160 } |
| 97 | 161 |
| 98 - (void)forceContentViewFrame:(NSRect)frame { | 162 - (void)forceContentViewFrame:(NSRect)frame { |
| 99 FullSizeContentView* contentView = | 163 FullSizeContentView* contentView = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 127 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 191 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
| 128 } | 192 } |
| 129 | 193 |
| 130 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 194 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 131 if (chromeWindowView_) | 195 if (chromeWindowView_) |
| 132 return frameRect; | 196 return frameRect; |
| 133 return [super contentRectForFrameRect:frameRect]; | 197 return [super contentRectForFrameRect:frameRect]; |
| 134 } | 198 } |
| 135 | 199 |
| 136 @end | 200 @end |
| OLD | NEW |