8360120: Bundled macOS applications not receiving OpenURL events when launched as subprocess

Reviewed-by: kizune, prr
This commit is contained in:
Dmitry Kulikov 2025-11-05 18:54:34 +00:00 committed by Phil Race
parent 7d93cb73c4
commit 2872f815fd
3 changed files with 38 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -75,6 +75,7 @@ import sun.lwawt.macosx.CPlatformWindow;
*/
public final class Application {
private static native void nativeInitializeApplicationDelegate();
private static native void nativeInstallOpenURLEventHandler();
static Application sApplication = null;
@ -211,6 +212,7 @@ public final class Application {
* @since Java for Mac OS X 10.5 Update 8
*/
public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
nativeInstallOpenURLEventHandler();
eventHandler.openURIDispatcher.setHandler(openURIHandler);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,6 +44,7 @@
BOOL fHandlesDocumentTypes;
BOOL fHandlesURLTypes;
BOOL fOpenURLHandlerInstalled;
}
@property (nonatomic, retain) NSMenuItem *fPreferencesMenu;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -243,11 +243,9 @@ AWT_ASSERT_APPKIT_THREAD;
NSBundle *bundle = [NSBundle mainBundle];
fHandlesDocumentTypes = [bundle objectForInfoDictionaryKey:@"CFBundleDocumentTypes"] != nil || [bundle _hasEAWTOverride:@"DocumentHandler"];
fHandlesURLTypes = [bundle objectForInfoDictionaryKey:@"CFBundleURLTypes"] != nil || [bundle _hasEAWTOverride:@"URLHandler"];
fOpenURLHandlerInstalled = NO;
if (fHandlesURLTypes) {
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(_handleOpenURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
[self _installOpenURLHandler];
}
// By HIG, Preferences are not available unless there is a handler. By default in Mac OS X,
@ -302,9 +300,19 @@ static jclass sjc_AppEventHandler = NULL;
#define GET_APPEVENTHANDLER_CLASS_RETURN(ret) \
GET_CLASS_RETURN(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler", ret);
- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
if (!fHandlesURLTypes) return;
- (void)_installOpenURLHandler {
AWT_ASSERT_APPKIT_THREAD;
if (fOpenURLHandlerInstalled) return;
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(_handleOpenURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
fOpenURLHandlerInstalled = YES;
}
- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
NSString *url = [[openURLEvent paramDescriptorForKeyword:keyDirectObject] stringValue];
[ApplicationDelegate _openURL:url];
@ -626,6 +634,24 @@ JNI_COCOA_ENTER(env);
JNI_COCOA_EXIT(env);
}
/*
* Class: com_apple_eawt_Application
* Method: nativeInstallOpenURLEventHandler
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_apple_eawt_Application_nativeInstallOpenURLEventHandler
(JNIEnv *env, jclass clz)
{
JNI_COCOA_ENTER(env);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
ApplicationDelegate *delegate = [ApplicationDelegate sharedDelegate];
if (delegate != nil) {
[delegate _installOpenURLHandler];
}
}];
JNI_COCOA_EXIT(env);
}
/*
* Class: com_apple_eawt__AppEventHandler
* Method: nativeOpenCocoaAboutWindow