Bug 705154 - Hang monitor incorrectly killing the app on mac when the user is idle: unlike other platforms, the main loop on Mac doesn't call processNextEvent in a loop: instead it calls into [NSApplication run] and we check whether there are pending XPCOM events during processing. Suspend the hang monitor when we pause for incoming events by subclassing [NSApplication nextEventMatchingMask], r=smichaud
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 01 Dec 2011 12:50:04 -0500
changeset 81888 1b3f17ffa656540baebc5cac1e5df43e0303d587
parent 81887 eec3aca1b188be477b59b1d922d49dbcf518b5b8
child 81889 c120734d20ba448629dd4fc97e8441c33bcd1e01
child 81899 b4827b51003b1646ad5dbda7bc5f6b649c786021
push idunknown
push userunknown
push dateunknown
reviewerssmichaud
bugs705154
milestone11.0a1
Bug 705154 - Hang monitor incorrectly killing the app on mac when the user is idle: unlike other platforms, the main loop on Mac doesn't call processNextEvent in a loop: instead it calls into [NSApplication run] and we check whether there are pending XPCOM events during processing. Suspend the hang monitor when we pause for incoming events by subclassing [NSApplication nextEventMatchingMask], r=smichaud
widget/src/cocoa/nsAppShell.mm
--- a/widget/src/cocoa/nsAppShell.mm
+++ b/widget/src/cocoa/nsAppShell.mm
@@ -178,26 +178,40 @@ bool nsCocoaAppModalWindowList::GeckoMod
 //
 // Subclass of NSApplication for filtering out certain events.
 @interface GeckoNSApplication : NSApplication
 {
 }
 @end
 
 @implementation GeckoNSApplication
+
 - (void)sendEvent:(NSEvent *)anEvent
 {
   mozilla::HangMonitor::NotifyActivity();
   if ([anEvent type] == NSApplicationDefined &&
       [anEvent subtype] == kEventSubtypeTrace) {
     mozilla::SignalTracerThread();
     return;
   }
   [super sendEvent:anEvent];
 }
+
+- (NSEvent*)nextEventMatchingMask:(NSUInteger)mask
+                        untilDate:(NSDate*)expiration
+                           inMode:(NSString*)mode
+                          dequeue:(BOOL)flag
+{
+  if (expiration) {
+    mozilla::HangMonitor::Suspend();
+  }
+  return [super nextEventMatchingMask:mask
+          untilDate:expiration inMode:mode dequeue:flag];
+}
+
 @end
 
 
 // AppShellDelegate
 //
 // Cocoa bridge class.  An object of this class is registered to receive
 // notifications.
 //