Don't crash on Objective-C exceptions in hooked [NSWindow sendEvent:] method. b=442245 r=josh sr=roc
authorSteven Michaud <smichaud@pobox.com>
Thu, 04 Sep 2008 11:08:30 -0500
changeset 18799 d995cee98a929330e306d993fe42d1cda3b07955
parent 18798 d7a71c22c51d98da4fdc8250b2ffa5b89ee53c69
child 18800 2e8e583fc354998d0749aa0a9725c5cfa6941afd
push idunknown
push userunknown
push dateunknown
reviewersjosh, roc
bugs442245
milestone1.9.1b1pre
Don't crash on Objective-C exceptions in hooked [NSWindow sendEvent:] method. b=442245 r=josh sr=roc
widget/src/cocoa/nsCocoaWindow.mm
xpcom/base/nsObjCExceptions.h
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -2137,17 +2137,20 @@ already_AddRefed<nsIDOMElement> GetFocus
 // 413882 without regressing bmo bugs 404433, 403232 and 357535/418031.
 // For non-embedders (e.g. Firefox, Thunderbird and Seamonkey), it would
 // probably only be necessary to add a sendEvent: method to the ToolbarWindow
 // class.  But embedders (like Camino) generally create their own NSWindows.
 // So in order to fix this problem everywhere, it's necessary to "hook"
 // NSWindow's own sendEvent: method.
 - (void)nsCocoaWindow_NSWindow_sendEvent:(NSEvent *)anEvent
 {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+  // Since we've hooked a "system call" ([NSWindow sendEvent:]), we're always
+  // called from system code (not browser code).  So avoid crashing on any
+  // Objective-C exceptions that occur here.
+  NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
 
   nsCOMPtr<nsIDOMElement> oldFocusedElement;
   NSResponder *oldFirstResponder;
   NSEventType type = [anEvent type];
   if (type == NSLeftMouseDown) {
     oldFirstResponder = [self firstResponder];
     if ([oldFirstResponder isKindOfClass:[ChildView class]]) {
       oldFirstResponder = [oldFirstResponder retain];
@@ -2176,17 +2179,17 @@ already_AddRefed<nsIDOMElement> GetFocus
       else if (newFocusedElement && [(ChildView *)oldFirstResponder widget]) {
         [self makeFirstResponder:oldFirstResponder];
       }
     }
     [newFirstResponder release];
     [oldFirstResponder release];
   }
 
-  NS_OBJC_END_TRY_ABORT_BLOCK;
+  NS_OBJC_END_TRY_LOGONLY_BLOCK;
 }
 
 @end
 
 @implementation PopupWindow
 
 // The OS treats our custom popup windows very strangely -- many mouse events
 // sent to them never reach their target NSView objects.  (That these windows
--- a/xpcom/base/nsObjCExceptions.h
+++ b/xpcom/base/nsObjCExceptions.h
@@ -230,9 +230,14 @@ NS_OBJC_TRY(_e, )
                                                return NS_ERROR_FAILURE;
 
 #define NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN    @try {
 #define NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(_rv) } @catch(NSException *_exn) {   \
                                                   nsObjCExceptionLogAbort(_exn);\
                                                 }                               \
                                                 return _rv;
 
+#define NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK @try {
+#define NS_OBJC_END_TRY_LOGONLY_BLOCK   } @catch(NSException *_exn) {           \
+                                          nsObjCExceptionLog(_exn);             \
+                                        }
+
 #endif // nsObjCExceptions_h_