diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m index 150e82c6965..5826cbf31d1 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m @@ -841,7 +841,7 @@ - (void) activateWindowMenuBar { isDisabled = !awtWindow.isEnabled; } - if (menuBar == nil) { + if (menuBar == nil && [ApplicationDelegate sharedDelegate] != nil) { menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar]; isDisabled = NO; } @@ -1228,7 +1228,7 @@ + (AWTWindow *) lastKeyWindow { window.javaMenuBar = menuBar; CMenuBar* actualMenuBar = menuBar; - if (actualMenuBar == nil) { + if (actualMenuBar == nil && [ApplicationDelegate sharedDelegate] != nil) { actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar]; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m index 590ed56e0c6..a8a821423de 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m @@ -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; @@ -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]; } @@ -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]; @@ -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 @@ -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); @@ -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; + } } }]; @@ -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); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m index 49a6a80da21..b02cc818063 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m @@ -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]; + } } } } diff --git a/src/java.desktop/macosx/native/libosxapp/QueuingApplicationDelegate.m b/src/java.desktop/macosx/native/libosxapp/QueuingApplicationDelegate.m index 034a990ebc8..ced48c72a36 100644 --- a/src/java.desktop/macosx/native/libosxapp/QueuingApplicationDelegate.m +++ b/src/java.desktop/macosx/native/libosxapp/QueuingApplicationDelegate.m @@ -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 )delegate { self.realDelegate = delegate;