OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 7 #import "base/logging.h" |
8 #include "base/mac/crash_logging.h" | 8 #include "base/mac/crash_logging.h" |
9 #import "base/mac/scoped_nsexception_enabler.h" | 9 #import "base/mac/scoped_nsexception_enabler.h" |
10 #import "base/metrics/histogram.h" | 10 #import "base/metrics/histogram.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 } | 214 } |
215 | 215 |
216 - (id)init { | 216 - (id)init { |
217 SwizzleInit(); | 217 SwizzleInit(); |
218 if ((self = [super init])) { | 218 if ((self = [super init])) { |
219 eventHooks_.reset([[NSMutableArray alloc] init]); | 219 eventHooks_.reset([[NSMutableArray alloc] init]); |
220 } | 220 } |
221 return self; | 221 return self; |
222 } | 222 } |
223 | 223 |
224 // Initialize NSApplication using the custom subclass. Check whether NSApp | |
225 // was already initialized using another class, because that would break | |
226 // some things. | |
227 + (NSApplication*)sharedApplication { | |
228 NSApplication* app = [super sharedApplication]; | |
229 if (![NSApp isKindOfClass:self]) { | |
230 LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] | |
Robert Sesek
2011/12/02 17:10:17
LOG(FATAL)?
Scott Hess - ex-Googler
2011/12/02 19:15:25
My goal was crash-if-debug, but warn-if-release.
| |
231 << ", not " << [[NSApp className] UTF8String]; | |
232 DCHECK(false) << "NSApp is of wrong type"; | |
233 } | |
234 if (!base::MessagePumpMac::UsingCrApp()) { | |
235 LOG(ERROR) << "MessagePumpMac::Create() was called before " | |
236 << [[self className] UTF8String] << " was initialized."; | |
237 DCHECK(false) << "MessagePumpMac is using the wrong pump implementation."; | |
238 } | |
239 return app; | |
240 } | |
241 | |
224 //////////////////////////////////////////////////////////////////////////////// | 242 //////////////////////////////////////////////////////////////////////////////// |
225 // HISTORICAL COMMENT (by viettrungluu, from | 243 // HISTORICAL COMMENT (by viettrungluu, from |
226 // http://codereview.chromium.org/1520006 with mild editing): | 244 // http://codereview.chromium.org/1520006 with mild editing): |
227 // | 245 // |
228 // A quick summary of the state of things (before the changes to shutdown): | 246 // A quick summary of the state of things (before the changes to shutdown): |
229 // | 247 // |
230 // Currently, we are totally hosed (put in a bad state in which Cmd-W does the | 248 // Currently, we are totally hosed (put in a bad state in which Cmd-W does the |
231 // wrong thing, and which will probably eventually lead to a crash) if we begin | 249 // wrong thing, and which will probably eventually lead to a crash) if we begin |
232 // quitting but termination is aborted for some reason. | 250 // quitting but termination is aborted for some reason. |
233 // | 251 // |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 } | 379 } |
362 | 380 |
363 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler { | 381 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler { |
364 [eventHooks_ addObject:handler]; | 382 [eventHooks_ addObject:handler]; |
365 } | 383 } |
366 | 384 |
367 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler { | 385 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler { |
368 [eventHooks_ removeObject:handler]; | 386 [eventHooks_ removeObject:handler]; |
369 } | 387 } |
370 | 388 |
389 - (BOOL)isHandlingSendEvent { | |
390 return handlingSendEvent_; | |
391 } | |
392 | |
393 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent { | |
394 handlingSendEvent_ = handlingSendEvent; | |
395 } | |
396 | |
371 - (void)sendEvent:(NSEvent*)event { | 397 - (void)sendEvent:(NSEvent*)event { |
372 base::mac::ScopedSendingEvent sendingEventScoper; | 398 base::mac::ScopedSendingEvent sendingEventScoper; |
373 for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { | 399 for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { |
374 [handler hookForEvent:event]; | 400 [handler hookForEvent:event]; |
375 } | 401 } |
376 [super sendEvent:event]; | 402 [super sendEvent:event]; |
377 } | 403 } |
378 | 404 |
379 // NSExceptions which are caught by the event loop are logged here. | 405 // NSExceptions which are caught by the event loop are logged here. |
380 // NSException uses setjmp/longjmp, which can be very bad for C++, so | 406 // NSException uses setjmp/longjmp, which can be very bad for C++, so |
381 // we attempt to track and report them. | 407 // we attempt to track and report them. |
382 - (void)reportException:(NSException *)anException { | 408 - (void)reportException:(NSException *)anException { |
383 // If we throw an exception in this code, we can create an infinite | 409 // If we throw an exception in this code, we can create an infinite |
384 // loop. If we throw out of the if() without resetting | 410 // loop. If we throw out of the if() without resetting |
385 // |reportException|, we'll stop reporting exceptions for this run. | 411 // |reportException|, we'll stop reporting exceptions for this run. |
386 static BOOL reportingException = NO; | 412 static BOOL reportingException = NO; |
387 DCHECK(!reportingException); | 413 DCHECK(!reportingException); |
388 if (!reportingException) { | 414 if (!reportingException) { |
389 reportingException = YES; | 415 reportingException = YES; |
390 chrome_browser_application_mac::RecordExceptionWithUma(anException); | 416 chrome_browser_application_mac::RecordExceptionWithUma(anException); |
391 | 417 |
392 // http://crbug.com/45928 is a bug about needing to double-close | 418 // http://crbug.com/45928 is a bug about needing to double-close |
393 // windows sometimes. One theory is that |-isHandlingSendEvent| | 419 // windows sometimes. One theory is that |-isHandlingSendEvent| |
394 // gets latched to always return |YES|. Since scopers are used to | 420 // gets latched to always return |YES|. Since scopers are used to |
395 // manipulate that value, that should not be possible. One way to | 421 // manipulate that value, that should not be possible. One way to |
396 // sidestep scopers is setjmp/longjmp (see above). The following | 422 // sidestep scopers is setjmp/longjmp (see above). The following |
397 // is to "fix" this while the more fundamental concern is | 423 // is to "fix" this while the more fundamental concern is |
398 // addressed elsewhere. | 424 // addressed elsewhere. |
399 [self clearIsHandlingSendEvent]; | 425 [self setHandlingSendEvent:NO]; |
400 | 426 |
401 // If |ScopedNSExceptionEnabler| is used to allow exceptions, and an | 427 // If |ScopedNSExceptionEnabler| is used to allow exceptions, and an |
402 // uncaught exception is thrown, it will throw past all of the scopers. | 428 // uncaught exception is thrown, it will throw past all of the scopers. |
403 // Reset the flag so that future exceptions are not masked. | 429 // Reset the flag so that future exceptions are not masked. |
404 base::mac::SetNSExceptionsAllowed(false); | 430 base::mac::SetNSExceptionsAllowed(false); |
405 | 431 |
406 // Store some human-readable information in breakpad keys in case | 432 // Store some human-readable information in breakpad keys in case |
407 // there is a crash. Since breakpad does not provide infinite | 433 // there is a crash. Since breakpad does not provide infinite |
408 // storage, we track two exceptions. The first exception thrown | 434 // storage, we track two exceptions. The first exception thrown |
409 // is tracked because it may be the one which caused the system to | 435 // is tracked because it may be the one which caused the system to |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 if (RenderViewHost* rvh = contents->render_view_host()) { | 474 if (RenderViewHost* rvh = contents->render_view_host()) { |
449 rvh->EnableRendererAccessibility(); | 475 rvh->EnableRendererAccessibility(); |
450 } | 476 } |
451 } | 477 } |
452 } | 478 } |
453 } | 479 } |
454 return [super accessibilitySetValue:value forAttribute:attribute]; | 480 return [super accessibilitySetValue:value forAttribute:attribute]; |
455 } | 481 } |
456 | 482 |
457 @end | 483 @end |
OLD | NEW |