Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/chrome_browser_application_mac.mm

Issue 345243007: Add ScopedObjCClassSwizzler in base/mac, absorbs objc_method_swizzle and ScopedClassSwizzler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Inlude in shiny new gn base_unittests target Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mac/scoped_objc_class_swizzler_unittest.mm ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_browser_application_mac.h" 5 #import "chrome/browser/chrome_browser_application_mac.h"
6 6
7 #import "base/auto_reset.h" 7 #import "base/auto_reset.h"
8 #include "base/debug/crash_logging.h" 8 #include "base/debug/crash_logging.h"
9 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #import "base/logging.h" 10 #import "base/logging.h"
11 #import "base/mac/scoped_nsexception_enabler.h" 11 #import "base/mac/scoped_nsexception_enabler.h"
12 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
13 #import "base/mac/scoped_objc_class_swizzler.h"
13 #import "base/metrics/histogram.h" 14 #import "base/metrics/histogram.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #import "base/strings/sys_string_conversions.h" 16 #import "base/strings/sys_string_conversions.h"
16 #import "chrome/browser/app_controller_mac.h" 17 #import "chrome/browser/app_controller_mac.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
18 #include "chrome/common/crash_keys.h" 19 #include "chrome/common/crash_keys.h"
19 #import "chrome/common/mac/objc_method_swizzle.h"
20 #import "chrome/common/mac/objc_zombie.h" 20 #import "chrome/common/mac/objc_zombie.h"
21 #include "content/public/browser/browser_accessibility_state.h" 21 #include "content/public/browser/browser_accessibility_state.h"
22 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 24
25 namespace { 25 namespace {
26 26
27 // Tracking for cases being hit by -crInitWithName:reason:userInfo:. 27 // Tracking for cases being hit by -crInitWithName:reason:userInfo:.
28 enum ExceptionEventType { 28 enum ExceptionEventType {
29 EXCEPTION_ACCESSIBILITY = 0, 29 EXCEPTION_ACCESSIBILITY = 0,
(...skipping 26 matching lines...) Expand all
56 @end 56 @end
57 57
58 static IMP gOriginalInitIMP = NULL; 58 static IMP gOriginalInitIMP = NULL;
59 59
60 @implementation NSException (CrNSExceptionSwizzle) 60 @implementation NSException (CrNSExceptionSwizzle)
61 - (id)crInitWithName:(NSString*)aName 61 - (id)crInitWithName:(NSString*)aName
62 reason:(NSString*)aReason 62 reason:(NSString*)aReason
63 userInfo:(NSDictionary*)someUserInfo { 63 userInfo:(NSDictionary*)someUserInfo {
64 // Method only called when swizzled. 64 // Method only called when swizzled.
65 DCHECK(_cmd == @selector(initWithName:reason:userInfo:)); 65 DCHECK(_cmd == @selector(initWithName:reason:userInfo:));
66 DCHECK(gOriginalInitIMP);
66 67
67 // Parts of Cocoa rely on creating and throwing exceptions. These are not 68 // Parts of Cocoa rely on creating and throwing exceptions. These are not
68 // worth bugging-out over. It is very important that there be zero chance that 69 // worth bugging-out over. It is very important that there be zero chance that
69 // any Chromium code is on the stack; these must be created by Apple code and 70 // any Chromium code is on the stack; these must be created by Apple code and
70 // then immediately consumed by Apple code. 71 // then immediately consumed by Apple code.
71 static NSString* const kAcceptableNSExceptionNames[] = { 72 static NSString* const kAcceptableNSExceptionNames[] = {
72 // If an object does not support an accessibility attribute, this will 73 // If an object does not support an accessibility attribute, this will
73 // get thrown. 74 // get thrown.
74 NSAccessibilityException, 75 NSAccessibilityException,
75 }; 76 };
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 229 }
229 230
230 } // namespace chrome_browser_application_mac 231 } // namespace chrome_browser_application_mac
231 232
232 namespace { 233 namespace {
233 234
234 void SwizzleInit() { 235 void SwizzleInit() {
235 // Do-nothing wrapper so that we can arrange to only swizzle 236 // Do-nothing wrapper so that we can arrange to only swizzle
236 // -[NSException raise] when DCHECK() is turned on (as opposed to 237 // -[NSException raise] when DCHECK() is turned on (as opposed to
237 // replicating the preprocess logic which turns DCHECK() on). 238 // replicating the preprocess logic which turns DCHECK() on).
238 gOriginalInitIMP = ObjcEvilDoers::SwizzleImplementedInstanceMethods( 239 CR_DEFINE_STATIC_LOCAL(base::mac::ScopedObjCClassSwizzler,
239 [NSException class], 240 swizzle_exception,
240 @selector(initWithName:reason:userInfo:), 241 ([NSException class],
241 @selector(crInitWithName:reason:userInfo:)); 242 @selector(initWithName:reason:userInfo:),
243 @selector(crInitWithName:reason:userInfo:)));
244 gOriginalInitIMP = swizzle_exception.GetOriginalImplementation();
242 } 245 }
243 246
244 } // namespace 247 } // namespace
245 248
246 // These methods are being exposed for the purposes of overriding. 249 // These methods are being exposed for the purposes of overriding.
247 // Used to determine when a Panel window can become the key window. 250 // Used to determine when a Panel window can become the key window.
248 @interface NSApplication (PanelsCanBecomeKey) 251 @interface NSApplication (PanelsCanBecomeKey)
249 - (void)_cycleWindowsReversed:(BOOL)arg1; 252 - (void)_cycleWindowsReversed:(BOOL)arg1;
250 - (id)_removeWindow:(NSWindow*)window; 253 - (id)_removeWindow:(NSWindow*)window;
251 - (id)_setKeyWindow:(NSWindow*)window; 254 - (id)_setKeyWindow:(NSWindow*)window;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 std::vector<NSWindow*>::iterator window_iterator = 603 std::vector<NSWindow*>::iterator window_iterator =
601 std::find(previousKeyWindows_.begin(), 604 std::find(previousKeyWindows_.begin(),
602 previousKeyWindows_.end(), 605 previousKeyWindows_.end(),
603 window); 606 window);
604 if (window_iterator != previousKeyWindows_.end()) { 607 if (window_iterator != previousKeyWindows_.end()) {
605 previousKeyWindows_.erase(window_iterator); 608 previousKeyWindows_.erase(window_iterator);
606 } 609 }
607 } 610 }
608 611
609 @end 612 @end
OLDNEW
« no previous file with comments | « base/mac/scoped_objc_class_swizzler_unittest.mm ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698