From e18bd28ac72f4c9aa1d8d4c5a463592e4ca81ed5 Mon Sep 17 00:00:00 2001 From: Phil Beauvoir Date: Mon, 20 May 2024 05:47:18 +0100 Subject: [PATCH] Fix warning message on Mac about secure coding not enabled (#1231) - See https://github.com/eclipse-platform/eclipse.platform.swt/issues/1228 - On macOS 14 and later a warning message is written to console: "WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES." - As recommended by Apple, this change adds a new selector for applicationSupportsSecureRestorableState and returns a 1 value (YES) in the callback in the Display class - However, this only takes care of the NSApplicationDelegate created in the Display class. The warning message will still appear when a splash screen is created in Equinox JNI code so a fix there is also required. See https://github.com/eclipse-equinox/equinox/issues/630 - This implementation for SWT can be tested by using the -noSplash argument when launching Eclipse --- .../cocoa/org/eclipse/swt/internal/cocoa/OS.java | 5 +++-- .../cocoa/org/eclipse/swt/internal/cocoa/Selector.java | 3 ++- .../Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index e125e46194e..49403b17c9e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -156,8 +156,9 @@ public static int VERSION (int major, int minor, int bugfix) { public static final long sel_setStyle = Selector.sel_setStyle.value; public static final int NSTableViewStylePlain = 4; - /** 14.0 selector */ - public static final long sel_setClipsToBounds_ = Selector.sel_setClipsToBounds_.value; + /** 14.0 selectors */ + public static final long sel_setClipsToBounds_ = Selector.sel_setClipsToBounds_.value; + public static final long sel_applicationSupportsSecureRestorableState_ = Selector.sel_applicationSupportsSecureRestorableState_.value; /* AWT application delegate. Remove these when JavaRuntimeSupport.framework has bridgesupport generated for it. */ public static final long class_JRSAppKitAWT = objc_getClass("JRSAppKitAWT"); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java index d400229e1a4..a88a45b46db 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java @@ -82,8 +82,9 @@ public enum Selector { /** 11.0 selector */ , sel_setStyle("setStyle:") - /** 14.0 selector */ + /** 14.0 selectors */ , sel_setClipsToBounds_("setClipsToBounds:") + , sel_applicationSupportsSecureRestorableState_("applicationSupportsSecureRestorableState:") , sel_awtAppDelegate("awtAppDelegate") diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index c1abd1a31bf..9c72a0e296f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -1052,6 +1052,7 @@ void createDisplay (DeviceData data) { OS.class_addMethod(cls, OS.sel_application_openUrls_, appProc4, "@:@@"); OS.class_addMethod(cls, OS.sel_applicationShouldHandleReopen_hasVisibleWindows_, appProc4, "@:@B"); OS.class_addMethod(cls, OS.sel_applicationShouldTerminate_, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_applicationSupportsSecureRestorableState_, appProc3, "@:@"); OS.objc_registerClassPair(cls); } @@ -5902,6 +5903,9 @@ static long applicationProc(long id, long sel, long arg0) { } return 0; } + case sel_applicationSupportsSecureRestorableState_: { + return 1; + } default: { return 0; }