Skip to content

Commit

Permalink
8318854: [macos14] Running any AWT app prints Secure coding warning
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, kizune, prr
  • Loading branch information
Harshitha Onkar committed Nov 29, 2023
1 parent c864317 commit 940f67c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ - (void) activateWindowMenuBar {
isDisabled = !awtWindow.isEnabled;
}

if (menuBar == nil) {
if (menuBar == nil && [ApplicationDelegate sharedDelegate] != nil) {
menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
isDisabled = NO;
}
Expand Down Expand Up @@ -1230,7 +1230,7 @@ + (AWTWindow *) lastKeyWindow {
window.javaMenuBar = menuBar;

CMenuBar* actualMenuBar = menuBar;
if (actualMenuBar == nil) {
if (actualMenuBar == nil && [ApplicationDelegate sharedDelegate] != nil) {
actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ + (ApplicationDelegate *)sharedDelegate {

// don't install the EAWT delegate if another kind of NSApplication is installed, like say, Safari
BOOL shouldInstall = NO;
BOOL overrideDelegate = (getenv("AWT_OVERRIDE_NSDELEGATE") != NULL);
if (NSApp != nil) {
if ([NSApp isMemberOfClass:[NSApplication class]]) shouldInstall = YES;
if ([NSApp isMemberOfClass:[NSApplication class]] && overrideDelegate) shouldInstall = YES;
if ([NSApp isKindOfClass:[NSApplicationAWT class]]) shouldInstall = YES;
}
checked = YES;
Expand Down Expand Up @@ -409,6 +410,19 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app {
return NSTerminateLater;
}

- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app {
static BOOL checked = NO;
static BOOL supportsSecureState = YES;

if (checked == NO) {
checked = YES;
if (getenv("AWT_DISABLE_NSDELEGATE_SECURE_SAVE") != NULL) {
supportsSecureState = NO;
}
}
return supportsSecureState;
}

+ (void)_systemWillPowerOff {
[self _notifyJava:com_apple_eawt__AppEventHandler_NOTIFY_SHUTDOWN];
}
Expand Down Expand Up @@ -506,8 +520,10 @@ + (void)_setDockIconImage:(NSImage *)image {
[dockImageView setImageScaling:NSImageScaleProportionallyUpOrDown];
[dockImageView setImage:image];

[[ApplicationDelegate sharedDelegate].fProgressIndicator removeFromSuperview];
[dockImageView addSubview:[ApplicationDelegate sharedDelegate].fProgressIndicator];
if ([ApplicationDelegate sharedDelegate] != nil) {
[[ApplicationDelegate sharedDelegate].fProgressIndicator removeFromSuperview];
[dockImageView addSubview:[ApplicationDelegate sharedDelegate].fProgressIndicator];
}

// add it to the NSDockTile
[dockTile setContentView: dockImageView];
Expand All @@ -520,14 +536,15 @@ + (void)_setDockIconProgress:(NSNumber *)value {
AWT_ASSERT_APPKIT_THREAD;

ApplicationDelegate *delegate = [ApplicationDelegate sharedDelegate];
if ([value doubleValue] >= 0 && [value doubleValue] <=100) {
[delegate.fProgressIndicator setDoubleValue:[value doubleValue]];
[delegate.fProgressIndicator setHidden:NO];
} else {
[delegate.fProgressIndicator setHidden:YES];
if (delegate != nil) {
if ([value doubleValue] >= 0 && [value doubleValue] <=100) {
[delegate.fProgressIndicator setDoubleValue:[value doubleValue]];
[delegate.fProgressIndicator setHidden:NO];
} else {
[delegate.fProgressIndicator setHidden:YES];
}
[[NSApp dockTile] display];
}

[[NSApp dockTile] display];
}

// Obtains the image of the Dock icon, either manually set, a drawn copy, or the default NSApplicationIcon
Expand Down Expand Up @@ -638,7 +655,9 @@ + (NSImage *)_dockIconImage {

NSMenu *menu = (NSMenu *)jlong_to_ptr(nsMenuPtr);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
[ApplicationDelegate sharedDelegate].fDockMenu = menu;
if ([ApplicationDelegate sharedDelegate] != nil) {
[ApplicationDelegate sharedDelegate].fDockMenu = menu;
}
}];

JNI_COCOA_EXIT(env);
Expand Down Expand Up @@ -818,13 +837,15 @@ + (NSImage *)_dockIconImage {

[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
ApplicationDelegate *delegate = [ApplicationDelegate sharedDelegate];
switch (menuID) {
case com_apple_eawt__AppMenuBarHandler_MENU_ABOUT:
[delegate _updateAboutMenu:visible enabled:enabled];
break;
case com_apple_eawt__AppMenuBarHandler_MENU_PREFS:
[delegate _updatePreferencesMenu:visible enabled:enabled];
break;
if (delegate != nil) {
switch (menuID) {
case com_apple_eawt__AppMenuBarHandler_MENU_ABOUT:
[delegate _updateAboutMenu:visible enabled:enabled];
break;
case com_apple_eawt__AppMenuBarHandler_MENU_PREFS:
[delegate _updatePreferencesMenu:visible enabled:enabled];
break;
}
}
}];

Expand All @@ -843,7 +864,9 @@ + (NSImage *)_dockIconImage {

CMenuBar *menu = (CMenuBar *)jlong_to_ptr(cMenuBarPtr);
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
[ApplicationDelegate sharedDelegate].fDefaultMenuBar = menu;
if ([ApplicationDelegate sharedDelegate] != nil) {
[ApplicationDelegate sharedDelegate].fDefaultMenuBar = menu;
}
}];

JNI_COCOA_EXIT(env);
Expand Down
8 changes: 5 additions & 3 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ -(void) deactivate {
// In theory, this might cause flickering if the window gaining focus
// has its own menu. However, I couldn't reproduce it on practice, so
// perhaps this is a non issue.
CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
if (defaultMenu != nil) {
[CMenuBar activate:defaultMenu modallyDisabled:NO];
if ([ApplicationDelegate sharedDelegate] != nil) {
CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
if (defaultMenu != nil) {
[CMenuBar activate:defaultMenu modallyDisabled:NO];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ - (void)_appDidUnhide
} copy]];
}


- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
{
static BOOL checked = NO;
static BOOL supportsSecureState = YES;

if (checked == NO) {
checked = YES;
if (getenv("AWT_DISABLE_NSDELEGATE_SECURE_SAVE") != NULL) {
supportsSecureState = NO;
}
}
return supportsSecureState;
}

- (void)processQueuedEventsWithTargetDelegate:(id <NSApplicationDelegate>)delegate
{
self.realDelegate = delegate;
Expand Down

1 comment on commit 940f67c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.