4343// The following is a AWT convention?
4444#define PREFERENCES_TAG 42
4545
46+ // Custom event that is provided by AWT to allow libraries like
47+ // JavaFX to forward native events to AWT even if AWT runs in
48+ // embedded mode.
49+ static NSString * awtEmbeddedEvent = @" AWTEmbeddedEvent" ;
50+
4651static void addMenuItem (NSMenuItem * menuItem, NSInteger index) {
4752AWT_ASSERT_APPKIT_THREAD ;
4853
@@ -125,6 +130,14 @@ + (ApplicationDelegate *)sharedDelegate {
125130 isApplicationOwner = YES ;
126131 }
127132 }
133+
134+ if (!isApplicationOwner) {
135+ // Register embedded event listener
136+ NSNotificationCenter *ctr = [NSNotificationCenter defaultCenter ];
137+ Class clz = [ApplicationDelegate class ];
138+ [ctr addObserver: clz selector: @selector (_embeddedEvent: ) name: awtEmbeddedEvent object: nil ];
139+ }
140+
128141 checked = YES ;
129142 if (!shouldInstall) {
130143 [ThreadUtilities setApplicationOwner: NO ];
@@ -290,11 +303,16 @@ - (void)dealloc {
290303 GET_CLASS_RETURN (sjc_AppEventHandler, " com/apple/eawt/_AppEventHandler" , ret);
291304
292305- (void )_handleOpenURLEvent : (NSAppleEventDescriptor *)openURLEvent withReplyEvent : (NSAppleEventDescriptor *)replyEvent {
293- AWT_ASSERT_APPKIT_THREAD ;
294306 if (!fHandlesURLTypes) return ;
295307
296308 NSString *url = [[openURLEvent paramDescriptorForKeyword: keyDirectObject] stringValue ];
309+ [ApplicationDelegate _openURL: url];
310+
311+ [replyEvent insertDescriptor: [NSAppleEventDescriptor nullDescriptor ] atIndex: 0 ];
312+ }
297313
314+ + (void )_openURL : (NSString *)url {
315+ AWT_ASSERT_APPKIT_THREAD ;
298316 // fprintf(stderr,"jm_handleOpenURL\n");
299317 JNIEnv *env = [ThreadUtilities getJNIEnv ];
300318 jstring jURL = NSStringToJavaString(env, url);
@@ -303,8 +321,6 @@ - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEven
303321 (*env)->CallStaticVoidMethod (env, sjc_AppEventHandler, jm_handleOpenURI, jURL);
304322 CHECK_EXCEPTION ();
305323 (*env)->DeleteLocalRef (env, jURL);
306-
307- [replyEvent insertDescriptor: [NSAppleEventDescriptor nullDescriptor ] atIndex: 0 ];
308324}
309325
310326// Helper for both open file and print file methods
@@ -475,6 +491,15 @@ + (void)_systemDidWake {
475491 [self _notifyJava: com_apple_eawt__AppEventHandler_NOTIFY_SYSTEM_WAKE];
476492}
477493
494+ + (void )_embeddedEvent : (NSNotification *)notification {
495+ NSString *name = notification.userInfo [@" name" ];
496+
497+ if ([name isEqualToString: @" openURL" ]) {
498+ NSString *url = notification.userInfo [@" url" ];
499+ [ApplicationDelegate _openURL: url];
500+ }
501+ }
502+
478503+ (void )_registerForNotification : (NSNumber *)notificationTypeNum {
479504 NSNotificationCenter *ctr = [[NSWorkspace sharedWorkspace ] notificationCenter ];
480505 Class clz = [ApplicationDelegate class ];
0 commit comments