提交 47965642 编写于 作者: A anthony

7170716: JVM crash when opening an AWT app from a registered file.

Summary: Copy the queued blocks to prevent their deallocation
Reviewed-by: anthony, swingler
Contributed-by: NMarco Dinacci <marco.dinacci@gmail.com>
上级 8677a552
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
BOOL fHandlesDocumentTypes; BOOL fHandlesDocumentTypes;
BOOL fHandlesURLTypes; BOOL fHandlesURLTypes;
id <NSApplicationDelegate> realDelegate;
NSMutableArray* queue; NSMutableArray* queue;
} }
...@@ -40,5 +42,9 @@ ...@@ -40,5 +42,9 @@
- (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate; - (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate;
@property(retain) id <NSApplicationDelegate> realDelegate;
@property(retain) NSMutableArray* queue;
@end @end
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#import "QueuingApplicationDelegate.h" #import "QueuingApplicationDelegate.h"
static id <NSApplicationDelegate> realDelegate = nil;
@interface NSBundle (EAWTOverrides) @interface NSBundle (EAWTOverrides)
- (BOOL)_hasEAWTOverride:(NSString *)key; - (BOOL)_hasEAWTOverride:(NSString *)key;
@end @end
...@@ -44,6 +42,9 @@ static id <NSApplicationDelegate> realDelegate = nil; ...@@ -44,6 +42,9 @@ static id <NSApplicationDelegate> realDelegate = nil;
@implementation QueuingApplicationDelegate @implementation QueuingApplicationDelegate
@synthesize realDelegate;
@synthesize queue;
+ (QueuingApplicationDelegate*) sharedDelegate + (QueuingApplicationDelegate*) sharedDelegate
{ {
static QueuingApplicationDelegate * qad = nil; static QueuingApplicationDelegate * qad = nil;
...@@ -62,7 +63,7 @@ static id <NSApplicationDelegate> realDelegate = nil; ...@@ -62,7 +63,7 @@ static id <NSApplicationDelegate> realDelegate = nil;
return self; return self;
} }
self->queue = [[NSMutableArray arrayWithCapacity: 0] retain]; self.queue = [NSMutableArray arrayWithCapacity: 0];
// If the java application has a bundle with an Info.plist file with // If the java application has a bundle with an Info.plist file with
// a CFBundleDocumentTypes entry, then it is set up to handle Open Doc // a CFBundleDocumentTypes entry, then it is set up to handle Open Doc
...@@ -100,8 +101,8 @@ static id <NSApplicationDelegate> realDelegate = nil; ...@@ -100,8 +101,8 @@ static id <NSApplicationDelegate> realDelegate = nil;
Class clz = [QueuingApplicationDelegate class]; Class clz = [QueuingApplicationDelegate class];
[ctr removeObserver:clz]; [ctr removeObserver:clz];
[self->queue release]; self.queue = nil;
self->queue = nil; self.realDelegate = nil;
[super dealloc]; [super dealloc];
} }
...@@ -109,16 +110,16 @@ static id <NSApplicationDelegate> realDelegate = nil; ...@@ -109,16 +110,16 @@ static id <NSApplicationDelegate> realDelegate = nil;
- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent]; [self.realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent];
}]; } copy]];
} }
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNames - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNames
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[realDelegate application:theApplication openFiles:fileNames]; [self.realDelegate application:theApplication openFiles:fileNames];
}]; } copy]];
} }
- (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels - (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels
...@@ -127,9 +128,9 @@ static id <NSApplicationDelegate> realDelegate = nil; ...@@ -127,9 +128,9 @@ static id <NSApplicationDelegate> realDelegate = nil;
return NSPrintingCancelled; return NSPrintingCancelled;
} }
[self->queue addObject:^(){ [self.queue addObject:[^(){
[realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels]; [self.realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels];
}]; } copy]];
// well, a bit premature, but what else can we do?.. // well, a bit premature, but what else can we do?..
return NSPrintingSuccess; return NSPrintingSuccess;
...@@ -137,76 +138,76 @@ static id <NSApplicationDelegate> realDelegate = nil; ...@@ -137,76 +138,76 @@ static id <NSApplicationDelegate> realDelegate = nil;
- (void)_willFinishLaunching - (void)_willFinishLaunching
{ {
QueuingApplicationDelegate * q = self; [self.queue addObject:[^(){
[self->queue addObject:^(){ [[self.realDelegate class] _willFinishLaunching];
[[realDelegate class] _willFinishLaunching]; } copy]];
}];
} }
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; [self.realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag];
}]; } copy]];
return YES; return YES;
} }
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[realDelegate applicationShouldTerminate:app]; [self.realDelegate applicationShouldTerminate:app];
}]; } copy]];
return NSTerminateLater; return NSTerminateLater;
} }
- (void)_systemWillPowerOff - (void)_systemWillPowerOff
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[[realDelegate class] _systemWillPowerOff]; [[self.realDelegate class] _systemWillPowerOff];
}]; } copy]];
} }
- (void)_appDidActivate - (void)_appDidActivate
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[[realDelegate class] _appDidActivate]; [[self.realDelegate class] _appDidActivate];
}]; } copy]];
} }
- (void)_appDidDeactivate - (void)_appDidDeactivate
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[[realDelegate class] _appDidDeactivate]; [[self.realDelegate class] _appDidDeactivate];
}]; } copy]];
} }
- (void)_appDidHide - (void)_appDidHide
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[[realDelegate class] _appDidHide]; [[self.realDelegate class] _appDidHide];
}]; } copy]];
} }
- (void)_appDidUnhide - (void)_appDidUnhide
{ {
[self->queue addObject:^(){ [self.queue addObject:[^(){
[[realDelegate class] _appDidUnhide]; [[self.realDelegate class] _appDidUnhide];
}]; } copy]];
} }
- (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate - (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate
{ {
NSUInteger i; self.realDelegate = delegate;
NSUInteger count = [self->queue count];
realDelegate = delegate; NSUInteger i;
NSUInteger count = [self.queue count];
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
void (^event)() = (void (^)())[self->queue objectAtIndex: i]; void (^event)() = (void (^)())[self.queue objectAtIndex: i];
event(); event();
[event release];
} }
[self->queue removeAllObjects]; [self.queue removeAllObjects];
} }
@end @end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册