--- old/src/java.desktop/share/classes/java/awt/Desktop.java 2016-08-31 00:58:17.000000000 +0300 +++ new/src/java.desktop/share/classes/java/awt/Desktop.java 2016-08-31 00:58:17.000000000 +0300 @@ -271,6 +271,14 @@ } } + private static void checkEventsProcessingPermission() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission( + "canProcessApplicationEvents")); + } + } + /** * Returns the {@code Desktop} instance of the current * desktop context. On some platforms the Desktop API may not be @@ -662,7 +670,8 @@ * * @throws SecurityException if a security manager exists and it * denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} * permission * * @see java.awt.desktop.AppForegroundListener @@ -674,6 +683,7 @@ * @since 9 */ public void addAppEventListener(final SystemEventListener listener) { + checkEventsProcessingPermission(); checkAWTPermission(); peer.addAppEventListener(listener); } @@ -689,7 +699,8 @@ * * @throws SecurityException if a security manager exists and it * denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} * permission * * @see java.awt.desktop.AppForegroundListener @@ -701,6 +712,7 @@ * @since 9 */ public void removeAppEventListener(final SystemEventListener listener) { + checkEventsProcessingPermission(); checkAWTPermission(); peer.removeAppEventListener(listener); } @@ -716,7 +728,8 @@ * * @throws SecurityException if a security manager exists and it * denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} * permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_ABOUT} action @@ -724,6 +737,7 @@ * @since 9 */ public void setAboutHandler(final AboutHandler aboutHandler) { + checkEventsProcessingPermission(); checkAWTPermission(); checkActionSupport(Action.APP_ABOUT); peer.setAboutHandler(aboutHandler); @@ -741,13 +755,15 @@ * * @throws SecurityException if a security manager exists and it * denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} * permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_PREFERENCES} action * @since 9 */ public void setPreferencesHandler(final PreferencesHandler preferencesHandler) { + checkEventsProcessingPermission(); checkAWTPermission(); checkActionSupport(Action.APP_PREFERENCES); peer.setPreferencesHandler(preferencesHandler); @@ -770,7 +786,8 @@ * @throws SecurityException if a security manager exists and its * {@link java.lang.SecurityManager#checkRead(java.lang.String)} * method denies read access to the files, or it denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} * permission, or the calling thread is not allowed to create a * subprocess * @throws UnsupportedOperationException if the current platform @@ -778,6 +795,7 @@ * @since 9 */ public void setOpenFileHandler(final OpenFilesHandler openFileHandler) { + checkEventsProcessingPermission(); checkAWTPermission(); checkExec(); checkRead(); @@ -800,12 +818,14 @@ * @param printFileHandler handler * @throws SecurityException if a security manager exists and its * {@link java.lang.SecurityManager#checkPrintJobAccess()} method denies - * the permission to print. + * the permission to print or it denies the + * {@code RuntimePermission("canProcessApplicationEvents")} permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_PRINT_FILE} action * @since 9 */ public void setPrintFileHandler(final PrintFilesHandler printFileHandler) { + checkEventsProcessingPermission(); SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPrintJobAccess(); @@ -832,7 +852,8 @@ * * @param openURIHandler handler * - * {@code AWTPermission("showWindowWithoutWarningBanner")} + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} * permission, or the calling thread is not allowed to create a * subprocess * @throws UnsupportedOperationException if the current platform @@ -840,6 +861,7 @@ * @since 9 */ public void setOpenURIHandler(final OpenURIHandler openURIHandler) { + checkEventsProcessingPermission(); checkAWTPermission(); checkExec(); checkActionSupport(Action.APP_OPEN_URI); @@ -856,12 +878,14 @@ * asked to quit * * @throws SecurityException if a security manager exists and it - * will not allow the caller to invoke {@code System.exit} + * will not allow the caller to invoke {@code System.exit} or it denies the + * {@code RuntimePermission("canProcessApplicationEvents")} permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_QUIT_HANDLER} action * @since 9 */ public void setQuitHandler(final QuitHandler quitHandler) { + checkEventsProcessingPermission(); checkQuitPermission(); checkActionSupport(Action.APP_QUIT_HANDLER); peer.setQuitHandler(quitHandler); @@ -874,13 +898,15 @@ * @param strategy the way this application should be shutdown * * @throws SecurityException if a security manager exists and it - * will not allow the caller to invoke {@code System.exit} + * will not allow the caller to invoke {@code System.exit} or it denies the + * {@code RuntimePermission("canProcessApplicationEvents")} permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_QUIT_STRATEGY} action * @see QuitStrategy * @since 9 */ public void setQuitStrategy(final QuitStrategy strategy) { + checkEventsProcessingPermission(); checkQuitPermission(); checkActionSupport(Action.APP_QUIT_STRATEGY); peer.setQuitStrategy(strategy); @@ -901,13 +927,15 @@ * effectively "kill -KILL" your application. * * @throws SecurityException if a security manager exists and it - * will not allow the caller to invoke {@code System.exit} + * will not allow the caller to invoke {@code System.exit} or it denies the + * {@code RuntimePermission("canProcessApplicationEvents")} permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action * @see #disableSuddenTermination() * @since 9 */ public void enableSuddenTermination() { + checkEventsProcessingPermission(); checkQuitPermission(); checkActionSupport(Action.APP_SUDDEN_TERMINATION); peer.enableSuddenTermination(); @@ -920,13 +948,15 @@ * may not be terminated without notification. * * @throws SecurityException if a security manager exists and it - * will not allow the caller to invoke {@code System.exit} + * will not allow the caller to invoke {@code System.exit} or it denies the + * {@code RuntimePermission("canProcessApplicationEvents")} permission * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action * @see #enableSuddenTermination() * @since 9 */ public void disableSuddenTermination() { + checkEventsProcessingPermission(); checkQuitPermission(); checkActionSupport(Action.APP_SUDDEN_TERMINATION); peer.disableSuddenTermination(); @@ -938,12 +968,14 @@ * @param allWindows if all windows of this application should be moved to * the foreground, or only the foremost one * @throws SecurityException if a security manager exists and it denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} permission. + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} permission. * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_REQUEST_FOREGROUND} action * @since 9 */ public void requestForeground(final boolean allWindows) { + checkEventsProcessingPermission(); checkAWTPermission(); checkActionSupport(Action.APP_REQUEST_FOREGROUND); peer.requestForeground(allWindows); @@ -957,12 +989,14 @@ * and registered in the Info.plist with CFBundleHelpBookFolder * * @throws SecurityException if a security manager exists and it denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} permission. + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} permission. * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_HELP_VIEWER} action * @since 9 */ public void openHelpViewer() { + checkEventsProcessingPermission(); checkAWTPermission(); checkActionSupport(Action.APP_HELP_VIEWER); peer.openHelpViewer(); @@ -975,12 +1009,14 @@ * * @param menuBar to use when no other frames are active * @throws SecurityException if a security manager exists and it denies the - * {@code AWTPermission("showWindowWithoutWarningBanner")} permission. + * {@code AWTPermission("showWindowWithoutWarningBanner")} or the + * {@code RuntimePermission("canProcessApplicationEvents")} permission. * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_MENU_BAR} action * @since 9 */ public void setDefaultMenuBar(final JMenuBar menuBar) { + checkEventsProcessingPermission(); checkAWTPermission(); checkActionSupport(Action.APP_MENU_BAR); peer.setDefaultMenuBar(menuBar);