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