< prev index next >
src/java.desktop/share/classes/java/awt/Desktop.java
Print this page
@@ -269,10 +269,18 @@
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,11 +668,12 @@
*
* @param listener listener
*
* @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
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
@@ -672,10 +681,11 @@
* @see java.awt.desktop.SystemSleepListener
* @see java.awt.desktop.UserSessionListener
* @since 9
*/
public void addAppEventListener(final SystemEventListener listener) {
+ checkEventsProcessingPermission();
checkAWTPermission();
peer.addAppEventListener(listener);
}
/**
@@ -687,11 +697,12 @@
*
* @param listener listener
*
* @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
* @see java.awt.desktop.AppHiddenListener
* @see java.awt.desktop.AppReopenedListener
@@ -699,10 +710,11 @@
* @see java.awt.desktop.SystemSleepListener
* @see java.awt.desktop.UserSessionListener
* @since 9
*/
public void removeAppEventListener(final SystemEventListener listener) {
+ checkEventsProcessingPermission();
checkAWTPermission();
peer.removeAppEventListener(listener);
}
/**
@@ -714,18 +726,20 @@
* @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")}
+ * {@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,17 +753,19 @@
* @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")}
+ * {@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,18 +784,20 @@
* @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")}
+ * {@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,16 +816,18 @@
* {@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.
+ * 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,18 +850,20 @@
* 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")}
+ * {@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,16 +876,18 @@
*
* @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}
+ * 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,17 +896,19 @@
* 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}
+ * 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,17 +925,19 @@
* 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}
+ * 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,17 +946,19 @@
*
* 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}
+ * 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,16 +966,18 @@
* 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.
+ * {@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,16 +987,18 @@
* @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.
+ * {@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,16 +1007,18 @@
*
* @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.
+ * {@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 >