< prev index next >
src/java.desktop/share/classes/java/awt/Desktop.java
Print this page
*** 269,278 ****
--- 269,286 ----
if (defaultToolkit instanceof SunToolkit) {
peer = ((SunToolkit) defaultToolkit).createDesktopPeer(this);
}
}
+ 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
* supported; use the {@link #isDesktopSupported} method to
* determine if the current desktop is supported.
*** 660,670 ****
*
* @param listener listener
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")}
* permission
*
* @see java.awt.desktop.AppForegroundListener
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
--- 668,679 ----
*
* @param listener listener
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
! * {@code RuntimePermission("canProcessApplicationEvents")}
* permission
*
* @see java.awt.desktop.AppForegroundListener
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
*** 672,681 ****
--- 681,691 ----
* @see java.awt.desktop.SystemSleepListener
* @see java.awt.desktop.UserSessionListener
* @since 9
*/
public void addAppEventListener(final SystemEventListener listener) {
+ checkEventsProcessingPermission();
checkAWTPermission();
peer.addAppEventListener(listener);
}
/**
*** 687,697 ****
*
* @param listener listener
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")}
* permission
*
* @see java.awt.desktop.AppForegroundListener
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
--- 697,708 ----
*
* @param listener listener
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
! * {@code RuntimePermission("canProcessApplicationEvents")}
* permission
*
* @see java.awt.desktop.AppForegroundListener
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
*** 699,708 ****
--- 710,720 ----
* @see java.awt.desktop.SystemSleepListener
* @see java.awt.desktop.UserSessionListener
* @since 9
*/
public void removeAppEventListener(final SystemEventListener listener) {
+ checkEventsProcessingPermission();
checkAWTPermission();
peer.removeAppEventListener(listener);
}
/**
*** 714,731 ****
* @param aboutHandler the handler to respond to the
* {@link java.awt.desktop.AboutHandler#handleAbout} )} message
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")}
* permission
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_ABOUT} action
*
* @since 9
*/
public void setAboutHandler(final AboutHandler aboutHandler) {
checkAWTPermission();
checkActionSupport(Action.APP_ABOUT);
peer.setAboutHandler(aboutHandler);
}
--- 726,745 ----
* @param aboutHandler the handler to respond to the
* {@link java.awt.desktop.AboutHandler#handleAbout} )} message
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@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
*
* @since 9
*/
public void setAboutHandler(final AboutHandler aboutHandler) {
+ checkEventsProcessingPermission();
checkAWTPermission();
checkActionSupport(Action.APP_ABOUT);
peer.setAboutHandler(aboutHandler);
}
*** 739,755 ****
* @param preferencesHandler the handler to respond to the
* {@link PreferencesHandler#handlePreferences(PreferencesEvent)}
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")}
* 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) {
checkAWTPermission();
checkActionSupport(Action.APP_PREFERENCES);
peer.setPreferencesHandler(preferencesHandler);
}
--- 753,771 ----
* @param preferencesHandler the handler to respond to the
* {@link PreferencesHandler#handlePreferences(PreferencesEvent)}
*
* @throws SecurityException if a security manager exists and it
* denies the
! * {@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);
}
*** 768,785 ****
* @param openFileHandler handler
*
* @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")}
* permission, or the calling thread is not allowed to create a
* subprocess
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_OPEN_FILE} action
* @since 9
*/
public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
checkAWTPermission();
checkExec();
checkRead();
checkActionSupport(Action.APP_OPEN_FILE);
peer.setOpenFileHandler(openFileHandler);
--- 784,803 ----
* @param openFileHandler handler
*
* @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")} or the
! * {@code RuntimePermission("canProcessApplicationEvents")}
* permission, or the calling thread is not allowed to create a
* subprocess
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_OPEN_FILE} action
* @since 9
*/
public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
+ checkEventsProcessingPermission();
checkAWTPermission();
checkExec();
checkRead();
checkActionSupport(Action.APP_OPEN_FILE);
peer.setOpenFileHandler(openFileHandler);
*** 798,813 ****
* {@code CFBundleDocumentTypes} key to your app's Info.plist.
*
* @param printFileHandler handler
* @throws SecurityException if a security manager exists and its
* {@link java.lang.SecurityManager#checkPrintJobAccess()} method denies
! * the permission to print.
* @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) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPrintJobAccess();
}
checkActionSupport(Action.APP_PRINT_FILE);
--- 816,833 ----
* {@code CFBundleDocumentTypes} key to your app's Info.plist.
*
* @param printFileHandler handler
* @throws SecurityException if a security manager exists and its
* {@link java.lang.SecurityManager#checkPrintJobAccess()} method denies
! * 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();
}
checkActionSupport(Action.APP_PRINT_FILE);
*** 830,847 ****
* Info.plist Key Reference</a> for more information about adding a
* {@code CFBundleDocumentTypes} key to your app's Info.plist.
*
* @param openURIHandler handler
*
! * {@code AWTPermission("showWindowWithoutWarningBanner")}
* permission, or the calling thread is not allowed to create a
* subprocess
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_OPEN_URI} action
* @since 9
*/
public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
checkAWTPermission();
checkExec();
checkActionSupport(Action.APP_OPEN_URI);
peer.setOpenURIHandler(openURIHandler);
}
--- 850,869 ----
* Info.plist Key Reference</a> for more information about adding a
* {@code CFBundleDocumentTypes} key to your app's Info.plist.
*
* @param openURIHandler handler
*
! * {@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
* does not support the {@link Desktop.Action#APP_OPEN_URI} action
* @since 9
*/
public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
+ checkEventsProcessingPermission();
checkAWTPermission();
checkExec();
checkActionSupport(Action.APP_OPEN_URI);
peer.setOpenURIHandler(openURIHandler);
}
*** 854,869 ****
*
* @param quitHandler the handler that is called when the application is
* asked to quit
*
* @throws SecurityException if a security manager exists and it
! * will not allow the caller to invoke {@code System.exit}
* @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) {
checkQuitPermission();
checkActionSupport(Action.APP_QUIT_HANDLER);
peer.setQuitHandler(quitHandler);
}
--- 876,893 ----
*
* @param quitHandler the handler that is called when the application is
* asked to quit
*
* @throws SecurityException if a security manager exists and it
! * 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);
}
*** 872,888 ****
* calling SYSTEM_EXIT_0.
*
* @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}
* @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) {
checkQuitPermission();
checkActionSupport(Action.APP_QUIT_STRATEGY);
peer.setQuitStrategy(strategy);
}
--- 896,914 ----
* calling SYSTEM_EXIT_0.
*
* @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} 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);
}
*** 899,915 ****
* hooks.</b>
* E.g. user-initiated Cmd-Q, logout, restart, or shutdown requests will
* effectively "kill -KILL" your application.
*
* @throws SecurityException if a security manager exists and it
! * will not allow the caller to invoke {@code System.exit}
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action
* @see #disableSuddenTermination()
* @since 9
*/
public void enableSuddenTermination() {
checkQuitPermission();
checkActionSupport(Action.APP_SUDDEN_TERMINATION);
peer.enableSuddenTermination();
}
--- 925,943 ----
* hooks.</b>
* E.g. user-initiated Cmd-Q, logout, restart, or shutdown requests will
* effectively "kill -KILL" your application.
*
* @throws SecurityException if a security manager exists and it
! * 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();
}
*** 918,934 ****
*
* Call this method to indicate that your application has unsaved state, and
* 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}
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action
* @see #enableSuddenTermination()
* @since 9
*/
public void disableSuddenTermination() {
checkQuitPermission();
checkActionSupport(Action.APP_SUDDEN_TERMINATION);
peer.disableSuddenTermination();
}
--- 946,964 ----
*
* Call this method to indicate that your application has unsaved state, and
* 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} 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();
}
*** 936,951 ****
* Requests this application to move to the foreground.
*
* @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.
* @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) {
checkAWTPermission();
checkActionSupport(Action.APP_REQUEST_FOREGROUND);
peer.requestForeground(allWindows);
}
--- 966,983 ----
* Requests this application to move to the foreground.
*
* @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")} 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);
}
*** 955,970 ****
* @implNote Please note that for Mac OS, it opens the native help viewer
* application if a Help Book has been added to the application bundler
* and registered in the Info.plist with CFBundleHelpBookFolder
*
* @throws SecurityException if a security manager exists and it denies the
! * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
* @throws UnsupportedOperationException if the current platform
* does not support the {@link Desktop.Action#APP_HELP_VIEWER} action
* @since 9
*/
public void openHelpViewer() {
checkAWTPermission();
checkActionSupport(Action.APP_HELP_VIEWER);
peer.openHelpViewer();
}
--- 987,1004 ----
* @implNote Please note that for Mac OS, it opens the native help viewer
* application if a Help Book has been added to the application bundler
* and registered in the Info.plist with CFBundleHelpBookFolder
*
* @throws SecurityException if a security manager exists and it denies the
! * {@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();
}
*** 973,988 ****
*
* @implNote Aqua Look and Feel should be active to support this on Mac OS.
*
* @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.
* @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) {
checkAWTPermission();
checkActionSupport(Action.APP_MENU_BAR);
peer.setDefaultMenuBar(menuBar);
}
--- 1007,1024 ----
*
* @implNote Aqua Look and Feel should be active to support this on Mac OS.
*
* @param menuBar to use when no other frames are active
* @throws SecurityException if a security manager exists and it denies the
! * {@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);
}
< prev index next >