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_symbolication = false; | |
| 52 static IMP g_originalDescriptionWithLocaleImplementation; | |
|
erikchen
2016/01/05 23:52:40
I would probably use the same nomenclature as g_di
Robert Sesek
2016/01/06 17:23:51
Yes, full under_scores is the correct way to write
| |
| 53 | |
| 54 @interface FullSizeContentWindowSwizzlingSupport : NSObject | |
| 55 @end | |
| 56 | |
| 57 @implementation FullSizeContentWindowSwizzlingSupport | |
| 58 | |
| 59 // This method replaces [_NSCallStackArray descriptionWithLocale:indent:] via | |
| 60 // swizzling - see +load below. | |
| 61 - (NSString*)descriptionWithLocale:(id)aLocale | |
| 62 indent:(unsigned long long)indent { | |
| 63 return g_disable_symbolication ? | |
| 64 @"" : | |
| 65 g_originalDescriptionWithLocaleImplementation( | |
| 66 self, @selector(descriptionWithLocale:indent:), aLocale, indent); | |
| 67 } | |
| 68 | |
| 69 @end | |
| 70 | |
| 47 @implementation FullSizeContentWindow | 71 @implementation FullSizeContentWindow |
| 48 | 72 |
| 49 #pragma mark - Lifecycle | 73 #pragma mark - Lifecycle |
| 50 | 74 |
| 75 // In initWithContentRect:styleMask:backing:defer:, the call to | |
| 76 // [NSView addSubview:positioned:relativeTo:] causes NSWindow to complain that | |
| 77 // an unknown view is being added to it, and to generate a stack trace. | |
| 78 // Not only does this stack trace pollute the console, it can also take hundreds | |
| 79 // of milliseconds to generate (because of symbolication). The AppKit uses an | |
| 80 // _NSCallStackArray to dump the symbols to the console - by swizzling | |
| 81 // descriptionWithLocale:indent: we can disable this output. See | |
| 82 // crbug.com/520373 . | |
| 83 + (void)load { | |
| 84 // Swizzling should only happen in the browser process. | |
| 85 const char* const* const argv = *_NSGetArgv(); | |
| 86 const int argc = *_NSGetArgc(); | |
| 87 const char kType[] = "--type="; | |
| 88 for (int i = 1; i < argc; ++i) { | |
| 89 const char* arg = argv[i]; | |
| 90 if (strncmp(arg, kType, strlen(kType)) == 0) { | |
| 91 return; | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 static dispatch_once_t onceToken; | |
| 96 dispatch_once(&onceToken, ^{ | |
| 97 Class callStackArrayClass = NSClassFromString(@"_NSCallStackArray"); | |
| 98 Class swizzleClass = [FullSizeContentWindowSwizzlingSupport class]; | |
| 99 SEL targetSelector = @selector(descriptionWithLocale:indent:); | |
| 100 | |
| 101 if (callStackArrayClass) { | |
| 102 CR_DEFINE_STATIC_LOCAL(base::mac::ScopedObjCClassSwizzler, | |
| 103 callStackSuppressor, (callStackArrayClass, | |
| 104 swizzleClass, targetSelector)); | |
| 105 g_originalDescriptionWithLocaleImplementation = | |
| 106 callStackSuppressor.GetOriginalImplementation(); | |
| 107 } | |
| 108 }); | |
| 109 } | |
| 110 | |
| 51 - (instancetype)init { | 111 - (instancetype)init { |
| 52 NOTREACHED(); | 112 NOTREACHED(); |
| 53 return nil; | 113 return nil; |
| 54 } | 114 } |
| 55 | 115 |
| 56 - (instancetype)initWithContentRect:(NSRect)contentRect | 116 - (instancetype)initWithContentRect:(NSRect)contentRect |
| 57 styleMask:(NSUInteger)windowStyle | 117 styleMask:(NSUInteger)windowStyle |
| 58 backing:(NSBackingStoreType)bufferingType | 118 backing:(NSBackingStoreType)bufferingType |
| 59 defer:(BOOL)deferCreation { | 119 defer:(BOOL)deferCreation { |
| 60 return [self initWithContentRect:contentRect | 120 return [self initWithContentRect:contentRect |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 80 chromeWindowView_.reset([[FullSizeContentView alloc] init]); | 140 chromeWindowView_.reset([[FullSizeContentView alloc] init]); |
| 81 [chromeWindowView_ | 141 [chromeWindowView_ |
| 82 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 142 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 83 [self setContentView:chromeWindowView_]; | 143 [self setContentView:chromeWindowView_]; |
| 84 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]]; | 144 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]]; |
| 85 | 145 |
| 86 // Our content view overlaps the window control buttons, so we must ensure | 146 // Our content view overlaps the window control buttons, so we must ensure |
| 87 // it is positioned below the buttons. | 147 // it is positioned below the buttons. |
| 88 NSView* superview = [chromeWindowView_ superview]; | 148 NSView* superview = [chromeWindowView_ superview]; |
| 89 [chromeWindowView_ removeFromSuperview]; | 149 [chromeWindowView_ removeFromSuperview]; |
| 150 | |
| 151 // Prevent the AppKit from generating a backtrace to include in it's | |
| 152 // complaint about our upcoming call to addSubview:positioned:relativeTo:. | |
| 153 // See +load for more info. | |
| 154 base::AutoReset<bool> disable_symbolication(&g_disable_symbolication, | |
| 155 true); | |
| 156 | |
| 90 [superview addSubview:chromeWindowView_ | 157 [superview addSubview:chromeWindowView_ |
| 91 positioned:NSWindowBelow | 158 positioned:NSWindowBelow |
| 92 relativeTo:nil]; | 159 relativeTo:nil]; |
| 93 } | 160 } |
| 94 } | 161 } |
| 95 return self; | 162 return self; |
| 96 } | 163 } |
| 97 | 164 |
| 98 - (void)forceContentViewFrame:(NSRect)frame { | 165 - (void)forceContentViewFrame:(NSRect)frame { |
| 99 FullSizeContentView* contentView = | 166 FullSizeContentView* contentView = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 127 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 194 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
| 128 } | 195 } |
| 129 | 196 |
| 130 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 197 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 131 if (chromeWindowView_) | 198 if (chromeWindowView_) |
| 132 return frameRect; | 199 return frameRect; |
| 133 return [super contentRectForFrameRect:frameRect]; | 200 return [super contentRectForFrameRect:frameRect]; |
| 134 } | 201 } |
| 135 | 202 |
| 136 @end | 203 @end |
| OLD | NEW |