8344667: Remove most uses of AWT Permissions from the desktop module

Reviewed-by: azvegint, kizune
This commit is contained in:
Phil Race 2024-11-25 22:16:07 +00:00
parent 8de158aefe
commit 027607968b
22 changed files with 6 additions and 318 deletions

View File

@ -25,7 +25,6 @@
package sun.awt; package sun.awt;
import java.awt.AWTPermission;
import java.awt.DisplayMode; import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
@ -62,8 +61,6 @@ public final class CGraphicsDevice extends GraphicsDevice
private static boolean oglPipelineEnabled = false; private static boolean oglPipelineEnabled = false;
private static AWTPermission fullScreenExclusivePermission;
// Save/restore DisplayMode for the Full Screen mode // Save/restore DisplayMode for the Full Screen mode
private DisplayMode originalMode; private DisplayMode originalMode;
private DisplayMode initialMode; private DisplayMode initialMode;
@ -260,23 +257,6 @@ public final class CGraphicsDevice extends GraphicsDevice
*/ */
@Override @Override
public boolean isFullScreenSupported() { public boolean isFullScreenSupported() {
return isFSExclusiveModeAllowed();
}
private static boolean isFSExclusiveModeAllowed() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (fullScreenExclusivePermission == null) {
fullScreenExclusivePermission =
new AWTPermission("fullScreenExclusive");
}
try {
security.checkPermission(fullScreenExclusivePermission);
} catch (SecurityException e) {
return false;
}
}
return true; return true;
} }

View File

@ -25,7 +25,6 @@
package java.applet; package java.applet;
import java.awt.AWTPermission;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException; import java.awt.HeadlessException;
@ -127,12 +126,6 @@ public class Applet extends Panel {
* @param stub the new stub * @param stub the new stub
*/ */
public final void setStub(AppletStub stub) { public final void setStub(AppletStub stub) {
if (this.stub != null) {
SecurityManager s = System.getSecurityManager();
if (s != null) {
s.checkPermission(new AWTPermission("setAppletStub"));
}
}
this.stub = stub; this.stub = stub;
} }

View File

@ -33,7 +33,6 @@ import java.awt.peer.DialogPeer;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serial; import java.io.Serial;
import java.security.AccessControlException;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@ -42,7 +41,6 @@ import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleState; import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet; import javax.accessibility.AccessibleStateSet;
import sun.awt.AWTPermissions;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.util.IdentityArrayList; import sun.awt.util.IdentityArrayList;
@ -844,8 +842,6 @@ public class Dialog extends Window {
return; return;
} }
checkModalityPermission(type);
modalityType = type; modalityType = type;
modal = (modalityType != ModalityType.MODELESS); modal = (modalityType != ModalityType.MODELESS);
} }
@ -1561,16 +1557,6 @@ public class Dialog extends Window {
} }
} }
private void checkModalityPermission(ModalityType mt) {
if (mt == ModalityType.TOOLKIT_MODAL) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(AWTPermissions.TOOLKIT_MODALITY_PERMISSION);
}
}
}
/** /**
* Reads serializable fields from stream. * Reads serializable fields from stream.
* *
@ -1592,12 +1578,6 @@ public class Dialog extends Window {
ModalityType localModalityType = (ModalityType)fields.get("modalityType", null); ModalityType localModalityType = (ModalityType)fields.get("modalityType", null);
try {
checkModalityPermission(localModalityType);
} catch (@SuppressWarnings("removal") AccessControlException ace) {
localModalityType = DEFAULT_MODALITY_TYPE;
}
// in 1.5 or earlier modalityType was absent, so use "modal" instead // in 1.5 or earlier modalityType was absent, so use "modal" instead
if (localModalityType == null) { if (localModalityType == null) {
this.modal = fields.get("modal", false); this.modal = fields.get("modal", false);

View File

@ -226,7 +226,6 @@ public abstract class KeyboardFocusManager
* @see DefaultKeyboardFocusManager * @see DefaultKeyboardFocusManager
*/ */
public static void setCurrentKeyboardFocusManager(KeyboardFocusManager newManager) { public static void setCurrentKeyboardFocusManager(KeyboardFocusManager newManager) {
checkReplaceKFMPermission();
KeyboardFocusManager oldManager = null; KeyboardFocusManager oldManager = null;
@ -354,12 +353,6 @@ public abstract class KeyboardFocusManager
*/ */
private static java.util.Map<Window, WeakReference<Component>> mostRecentFocusOwners = new WeakHashMap<>(); private static java.util.Map<Window, WeakReference<Component>> mostRecentFocusOwners = new WeakHashMap<>();
/**
* We cache the permission used to verify that the calling thread is
* permitted to access the global focus state.
*/
private static AWTPermission replaceKeyboardFocusManagerPermission;
/* /*
* SequencedEvent which is currently dispatched in AppContext. * SequencedEvent which is currently dispatched in AppContext.
*/ */
@ -473,7 +466,6 @@ public abstract class KeyboardFocusManager
*/ */
protected Component getGlobalFocusOwner() { protected Component getGlobalFocusOwner() {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
return focusOwner; return focusOwner;
} }
} }
@ -506,7 +498,6 @@ public abstract class KeyboardFocusManager
if (focusOwner == null || focusOwner.isFocusable()) { if (focusOwner == null || focusOwner.isFocusable()) {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
oldFocusOwner = getFocusOwner(); oldFocusOwner = getFocusOwner();
@ -584,7 +575,6 @@ public abstract class KeyboardFocusManager
* @see java.awt.event.FocusEvent#FOCUS_LOST * @see java.awt.event.FocusEvent#FOCUS_LOST
*/ */
public void clearGlobalFocusOwner() { public void clearGlobalFocusOwner() {
checkReplaceKFMPermission();
if (!GraphicsEnvironment.isHeadless()) { if (!GraphicsEnvironment.isHeadless()) {
// Toolkit must be fully initialized, otherwise // Toolkit must be fully initialized, otherwise
// _clearGlobalFocusOwner will crash or throw an exception // _clearGlobalFocusOwner will crash or throw an exception
@ -660,7 +650,6 @@ public abstract class KeyboardFocusManager
*/ */
protected Component getGlobalPermanentFocusOwner() { protected Component getGlobalPermanentFocusOwner() {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
return permanentFocusOwner; return permanentFocusOwner;
} }
} }
@ -694,7 +683,6 @@ public abstract class KeyboardFocusManager
if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) { if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
oldPermanentFocusOwner = getPermanentFocusOwner(); oldPermanentFocusOwner = getPermanentFocusOwner();
@ -755,7 +743,6 @@ public abstract class KeyboardFocusManager
*/ */
protected Window getGlobalFocusedWindow() { protected Window getGlobalFocusedWindow() {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
return focusedWindow; return focusedWindow;
} }
} }
@ -785,7 +772,6 @@ public abstract class KeyboardFocusManager
if (focusedWindow == null || focusedWindow.isFocusableWindow()) { if (focusedWindow == null || focusedWindow.isFocusableWindow()) {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
oldFocusedWindow = getFocusedWindow(); oldFocusedWindow = getFocusedWindow();
@ -847,7 +833,6 @@ public abstract class KeyboardFocusManager
*/ */
protected Window getGlobalActiveWindow() { protected Window getGlobalActiveWindow() {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
return activeWindow; return activeWindow;
} }
} }
@ -875,7 +860,6 @@ public abstract class KeyboardFocusManager
protected void setGlobalActiveWindow(Window activeWindow) { protected void setGlobalActiveWindow(Window activeWindow) {
Window oldActiveWindow; Window oldActiveWindow;
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
oldActiveWindow = getActiveWindow(); oldActiveWindow = getActiveWindow();
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
@ -1152,7 +1136,6 @@ public abstract class KeyboardFocusManager
*/ */
protected Container getGlobalCurrentFocusCycleRoot() { protected Container getGlobalCurrentFocusCycleRoot() {
synchronized (KeyboardFocusManager.class) { synchronized (KeyboardFocusManager.class) {
checkKFMSecurity();
return currentFocusCycleRoot; return currentFocusCycleRoot;
} }
} }
@ -1172,7 +1155,6 @@ public abstract class KeyboardFocusManager
* @see #getGlobalCurrentFocusCycleRoot * @see #getGlobalCurrentFocusCycleRoot
*/ */
public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) { public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) {
checkReplaceKFMPermission();
Container oldFocusCycleRoot; Container oldFocusCycleRoot;
@ -2976,40 +2958,4 @@ public abstract class KeyboardFocusManager
: null; : null;
} }
} }
private static void checkReplaceKFMPermission()
throws SecurityException
{
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (replaceKeyboardFocusManagerPermission == null) {
replaceKeyboardFocusManagerPermission =
new AWTPermission("replaceKeyboardFocusManager");
}
security.
checkPermission(replaceKeyboardFocusManagerPermission);
}
}
// Checks if this KeyboardFocusManager instance is the current KFM,
// or otherwise checks if the calling thread has "replaceKeyboardFocusManager"
// permission. Here's the reasoning to do so:
//
// A system KFM instance (which is the current KFM by default) may have no
// "replaceKFM" permission when a client code is on the call stack beneath,
// but still it should be able to execute the methods protected by this check
// due to the system KFM is trusted (and so it does like "privileged").
//
// If this KFM instance is not the current KFM but the client code has all
// permissions we can't throw SecurityException because it would contradict
// the security concepts. In this case the trusted client code is responsible
// for calling the secured methods from KFM instance which is not current.
private void checkKFMSecurity()
throws SecurityException
{
if (this != getCurrentKeyboardFocusManager()) {
checkReplaceKFMPermission();
}
}
} }

View File

@ -25,7 +25,6 @@
package java.awt; package java.awt;
import sun.awt.AWTPermissions;
import sun.awt.ComponentFactory; import sun.awt.ComponentFactory;
/** /**
@ -66,12 +65,6 @@ public class MouseInfo {
throw new HeadlessException(); throw new HeadlessException();
} }
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.WATCH_MOUSE_PERMISSION);
}
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
Point point = new Point(0, 0); Point point = new Point(0, 0);
int deviceNum = 0; int deviceNum = 0;

View File

@ -37,7 +37,6 @@ import java.awt.image.Raster;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.awt.peer.RobotPeer; import java.awt.peer.RobotPeer;
import sun.awt.AWTPermissions;
import sun.awt.ComponentFactory; import sun.awt.ComponentFactory;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.image.SunWritableRaster; import sun.awt.image.SunWritableRaster;
@ -163,7 +162,6 @@ public class Robot {
} }
private void init(GraphicsDevice screen) throws AWTException { private void init(GraphicsDevice screen) throws AWTException {
checkRobotAllowed();
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof ComponentFactory) { if (toolkit instanceof ComponentFactory) {
peer = ((ComponentFactory)toolkit).createRobot(screen); peer = ((ComponentFactory)toolkit).createRobot(screen);
@ -193,15 +191,6 @@ public class Robot {
LEGAL_BUTTON_MASK = tmpMask; LEGAL_BUTTON_MASK = tmpMask;
} }
/* determine if the security policy allows Robot's to be created */
private static void checkRobotAllowed() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.CREATE_ROBOT_PERMISSION);
}
}
/** /**
* Check for headless state and throw {@code AWTException} if headless. * Check for headless state and throw {@code AWTException} if headless.
*/ */
@ -437,7 +426,6 @@ public class Robot {
* @return Color of the pixel * @return Color of the pixel
*/ */
public synchronized Color getPixelColor(int x, int y) { public synchronized Color getPixelColor(int x, int y) {
checkScreenCaptureAllowed();
Point point = peer.useAbsoluteCoordinates() ? toDeviceSpaceAbs(x, y) Point point = peer.useAbsoluteCoordinates() ? toDeviceSpaceAbs(x, y)
: toDeviceSpace(x, y); : toDeviceSpace(x, y);
return new Color(peer.getRGBPixel(point.x, point.y)); return new Color(peer.getRGBPixel(point.x, point.y));
@ -518,8 +506,6 @@ public class Robot {
private synchronized BufferedImage[] private synchronized BufferedImage[]
createCompatibleImage(Rectangle screenRect, boolean isHiDPI) { createCompatibleImage(Rectangle screenRect, boolean isHiDPI) {
checkScreenCaptureAllowed();
checkValidRect(screenRect); checkValidRect(screenRect);
BufferedImage lowResolutionImage; BufferedImage lowResolutionImage;
@ -635,14 +621,6 @@ public class Robot {
} }
} }
private static void checkScreenCaptureAllowed() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.READ_DISPLAY_PIXELS_PERMISSION);
}
}
/* /*
* Called after an event is generated * Called after an event is generated
*/ */

View File

@ -32,7 +32,6 @@ import java.beans.PropertyChangeSupport;
import java.util.Vector; import java.util.Vector;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.AWTPermissions;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.HeadlessToolkit; import sun.awt.HeadlessToolkit;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
@ -160,7 +159,6 @@ public class SystemTray {
* @see #isSupported * @see #isSupported
*/ */
public static SystemTray getSystemTray() { public static SystemTray getSystemTray() {
checkSystemTrayAllowed();
if (GraphicsEnvironment.isHeadless()) { if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException(); throw new HeadlessException();
} }
@ -494,14 +492,6 @@ public class SystemTray {
} }
} }
static void checkSystemTrayAllowed() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ACCESS_SYSTEM_TRAY_PERMISSION);
}
}
private static void initializeSystemTrayIfNeeded() { private static void initializeSystemTrayIfNeeded() {
synchronized (SystemTray.class) { synchronized (SystemTray.class) {
if (systemTray == null) { if (systemTray == null) {

View File

@ -72,7 +72,6 @@ import java.util.stream.Collectors;
import javax.accessibility.AccessibilityProvider; import javax.accessibility.AccessibilityProvider;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.AWTPermissions;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.HeadlessToolkit; import sun.awt.HeadlessToolkit;
import sun.awt.PeerEvent; import sun.awt.PeerEvent;
@ -1360,11 +1359,6 @@ public abstract class Toolkit {
* @return the {@code EventQueue} object * @return the {@code EventQueue} object
*/ */
public final EventQueue getSystemEventQueue() { public final EventQueue getSystemEventQueue() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.CHECK_AWT_EVENTQUEUE_PERMISSION);
}
return getSystemEventQueueImpl(); return getSystemEventQueueImpl();
} }
@ -1690,11 +1684,6 @@ public abstract class Toolkit {
if (localL == null) { if (localL == null) {
return; return;
} }
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
}
synchronized (this) { synchronized (this) {
SelectiveAWTEventListener selectiveListener = SelectiveAWTEventListener selectiveListener =
listener2SelectiveListener.get(localL); listener2SelectiveListener.get(localL);
@ -1750,11 +1739,6 @@ public abstract class Toolkit {
if (listener == null) { if (listener == null) {
return; return;
} }
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
}
synchronized (this) { synchronized (this) {
SelectiveAWTEventListener selectiveListener = SelectiveAWTEventListener selectiveListener =
@ -1807,11 +1791,6 @@ public abstract class Toolkit {
* @since 1.4 * @since 1.4
*/ */
public AWTEventListener[] getAWTEventListeners() { public AWTEventListener[] getAWTEventListeners() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
}
synchronized (this) { synchronized (this) {
EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class); EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
@ -1851,11 +1830,6 @@ public abstract class Toolkit {
* @since 1.4 * @since 1.4
*/ */
public AWTEventListener[] getAWTEventListeners(long eventMask) { public AWTEventListener[] getAWTEventListeners(long eventMask) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
}
synchronized (this) { synchronized (this) {
EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class); EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);

View File

@ -118,9 +118,8 @@ public class TrayIcon {
} }
private TrayIcon() private TrayIcon()
throws UnsupportedOperationException, HeadlessException, SecurityException throws UnsupportedOperationException, HeadlessException
{ {
SystemTray.checkSystemTrayAllowed();
if (GraphicsEnvironment.isHeadless()) { if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException(); throw new HeadlessException();
} }

View File

@ -64,7 +64,6 @@ import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet; import javax.accessibility.AccessibleStateSet;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.AWTPermissions;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.DebugSettings; import sun.awt.DebugSettings;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
@ -1627,13 +1626,6 @@ public class Window extends Container implements Accessible {
if (modalExclusionType == exclusionType) { if (modalExclusionType == exclusionType) {
return; return;
} }
if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(AWTPermissions.TOOLKIT_MODALITY_PERMISSION);
}
}
modalExclusionType = exclusionType; modalExclusionType = exclusionType;
// if we want on-fly changes, we need to uncomment the lines below // if we want on-fly changes, we need to uncomment the lines below
@ -2169,12 +2161,6 @@ public class Window extends Container implements Accessible {
* @since 1.5 * @since 1.5
*/ */
public final void setAlwaysOnTop(boolean alwaysOnTop) { public final void setAlwaysOnTop(boolean alwaysOnTop) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
}
boolean oldAlwaysOnTop; boolean oldAlwaysOnTop;
synchronized(this) { synchronized(this) {
oldAlwaysOnTop = this.alwaysOnTop; oldAlwaysOnTop = this.alwaysOnTop;

View File

@ -1096,12 +1096,8 @@ public class JInternalFrame extends JComponent implements
fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED); fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
else { else {
fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED); fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
try { java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
new sun.awt.UngrabEvent(this)); new sun.awt.UngrabEvent(this));
} catch (SecurityException e) {
this.dispatchEvent(new sun.awt.UngrabEvent(this));
}
} }
repaint(); repaint();
} }

View File

@ -1970,14 +1970,6 @@ public class SwingUtilities implements SwingConstants
public void show() { public void show() {
// This frame can never be shown // This frame can never be shown
} }
public void dispose() {
try {
getToolkit().getSystemEventQueue();
super.dispose();
} catch (Exception e) {
// untrusted code not allowed to dispose
}
}
} }
/** /**

View File

@ -528,12 +528,7 @@ public class BasicInternalFrameTitlePane extends JComponent
protected void postClosingEvent(JInternalFrame frame) { protected void postClosingEvent(JInternalFrame frame) {
InternalFrameEvent e = new InternalFrameEvent( InternalFrameEvent e = new InternalFrameEvent(
frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING); frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
// Try posting event, unless there's a SecurityManager. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
try {
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
} catch (SecurityException se) {
frame.dispatchEvent(e);
}
} }
/** /**

View File

@ -35,28 +35,4 @@ public final class AWTPermissions {
public static final AWTPermission ACCESS_CLIPBOARD_PERMISSION = public static final AWTPermission ACCESS_CLIPBOARD_PERMISSION =
new AWTPermission("accessClipboard"); new AWTPermission("accessClipboard");
public static final AWTPermission CHECK_AWT_EVENTQUEUE_PERMISSION =
new AWTPermission("accessEventQueue");
public static final AWTPermission TOOLKIT_MODALITY_PERMISSION =
new AWTPermission("toolkitModality");
public static final AWTPermission READ_DISPLAY_PIXELS_PERMISSION =
new AWTPermission("readDisplayPixels");
public static final AWTPermission CREATE_ROBOT_PERMISSION =
new AWTPermission("createRobot");
public static final AWTPermission WATCH_MOUSE_PERMISSION =
new AWTPermission("watchMousePointer");
public static final AWTPermission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION =
new AWTPermission("setWindowAlwaysOnTop");
public static final AWTPermission ALL_AWT_EVENTS_PERMISSION =
new AWTPermission("listenToAllAWTEvents");
public static final AWTPermission ACCESS_SYSTEM_TRAY_PERMISSION =
new AWTPermission("accessSystemTray");
} }

View File

@ -1082,22 +1082,9 @@ public abstract class SunToolkit extends Toolkit
/** /**
* Returns whether popup is allowed to be shown above the task bar. * Returns whether popup is allowed to be shown above the task bar.
* This is a default implementation of this method, which checks
* corresponding security permission.
*/ */
public boolean canPopupOverlapTaskBar() { public boolean canPopupOverlapTaskBar() {
boolean result = true; return true;
try {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
}
} catch (SecurityException se) {
// There is no permission to show popups over the task bar
result = false;
}
return result;
} }
/** /**

View File

@ -437,11 +437,6 @@ public class BufImgSurfaceData extends SurfaceData {
return new Rectangle(bufImg.getWidth(), bufImg.getHeight()); return new Rectangle(bufImg.getWidth(), bufImg.getHeight());
} }
protected void checkCustomComposite() {
// BufferedImages always allow Custom Composite objects since
// their pixels are immediately retrievable anyway.
}
/** /**
* Returns destination Image associated with this SurfaceData. * Returns destination Image associated with this SurfaceData.
*/ */

View File

@ -130,15 +130,6 @@ public class NullSurfaceData extends SurfaceData {
return new Rectangle(); return new Rectangle();
} }
/**
* Performs Security Permissions checks to see if a Custom
* Composite object should be allowed access to the pixels
* of this surface.
*/
protected void checkCustomComposite() {
return;
}
/** /**
* Performs a copyarea within this surface. Returns * Performs a copyarea within this surface. Returns
* false if there is no algorithm to perform the copyarea * false if there is no algorithm to perform the copyarea

View File

@ -974,7 +974,6 @@ public final class SunGraphics2D
} else if (comp == null) { } else if (comp == null) {
throw new IllegalArgumentException("null Composite"); throw new IllegalArgumentException("null Composite");
} else { } else {
surfaceData.checkCustomComposite();
newCompState = COMP_CUSTOM; newCompState = COMP_CUSTOM;
newCompType = CompositeType.General; newCompType = CompositeType.General;
} }

View File

@ -1002,25 +1002,6 @@ public abstract class SurfaceData
*/ */
public abstract Rectangle getBounds(); public abstract Rectangle getBounds();
static java.security.Permission compPermission;
/**
* Performs Security Permissions checks to see if a Custom
* Composite object should be allowed access to the pixels
* of this surface.
*/
protected void checkCustomComposite() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
if (compPermission == null) {
compPermission =
new java.awt.AWTPermission("readDisplayPixels");
}
sm.checkPermission(compPermission);
}
}
/** /**
* Fetches private field IndexColorModel.allgrayopaque * Fetches private field IndexColorModel.allgrayopaque
* which is true when all palette entries in the color * which is true when all palette entries in the color

View File

@ -25,7 +25,6 @@
package sun.awt; package sun.awt;
import java.awt.AWTPermission;
import java.awt.DisplayMode; import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
@ -65,7 +64,6 @@ public final class X11GraphicsDevice extends GraphicsDevice
private volatile int screen; private volatile int screen;
Map<SurfaceType, SurfaceManager.ProxyCache> x11ProxyCacheMap = Collections.synchronizedMap(new HashMap<>()); Map<SurfaceType, SurfaceManager.ProxyCache> x11ProxyCacheMap = Collections.synchronizedMap(new HashMap<>());
private static AWTPermission fullScreenExclusivePermission;
private static Boolean xrandrExtSupported; private static Boolean xrandrExtSupported;
private SunDisplayChanger topLevels = new SunDisplayChanger(); private SunDisplayChanger topLevels = new SunDisplayChanger();
private DisplayMode origDisplayMode; private DisplayMode origDisplayMode;
@ -335,23 +333,7 @@ public final class X11GraphicsDevice extends GraphicsDevice
@Override @Override
public boolean isFullScreenSupported() { public boolean isFullScreenSupported() {
boolean fsAvailable = isXrandrExtensionSupported(); return isXrandrExtensionSupported();
if (fsAvailable) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (fullScreenExclusivePermission == null) {
fullScreenExclusivePermission =
new AWTPermission("fullScreenExclusive");
}
try {
security.checkPermission(fullScreenExclusivePermission);
} catch (SecurityException e) {
return false;
}
}
}
return fsAvailable;
} }
@Override @Override

View File

@ -25,7 +25,6 @@
package sun.awt; package sun.awt;
import java.awt.AWTPermission;
import java.awt.DisplayMode; import java.awt.DisplayMode;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Frame; import java.awt.Frame;
@ -81,7 +80,6 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
// pipelines which are mutually exclusive with opengl, for which // pipelines which are mutually exclusive with opengl, for which
// pixel formats were added in the first place // pixel formats were added in the first place
protected static boolean pfDisabled; protected static boolean pfDisabled;
private static AWTPermission fullScreenExclusivePermission;
// the original display mode we had before entering the fullscreen // the original display mode we had before entering the fullscreen
// mode // mode
private DisplayMode defaultDisplayMode; private DisplayMode defaultDisplayMode;
@ -349,29 +347,12 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
getLocalGraphicsEnvironment().getDefaultScreenDevice()); getLocalGraphicsEnvironment().getDefaultScreenDevice());
} }
private static boolean isFSExclusiveModeAllowed() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (fullScreenExclusivePermission == null) {
fullScreenExclusivePermission =
new AWTPermission("fullScreenExclusive");
}
try {
security.checkPermission(fullScreenExclusivePermission);
} catch (SecurityException e) {
return false;
}
}
return true;
}
/** /**
* returns true unless we're not allowed to use fullscreen mode. * returns true unless we're not allowed to use fullscreen mode.
*/ */
@Override @Override
public boolean isFullScreenSupported() { public boolean isFullScreenSupported() {
return isFSExclusiveModeAllowed(); return true;
} }
@Override @Override

View File

@ -68,11 +68,8 @@ public class ExtendedRobot extends Robot {
* @throws AWTException if the platform configuration does not allow low-level input * @throws AWTException if the platform configuration does not allow low-level input
* control. This exception is always thrown when * control. This exception is always thrown when
* GraphicsEnvironment.isHeadless() returns true * GraphicsEnvironment.isHeadless() returns true
* @throws SecurityException if {@code createRobot} permission is not granted
* *
* @see java.awt.GraphicsEnvironment#isHeadless * @see java.awt.GraphicsEnvironment#isHeadless
* @see SecurityManager#checkPermission
* @see java.awt.AWTPermission
*/ */
public ExtendedRobot() throws AWTException { public ExtendedRobot() throws AWTException {
super(); super();
@ -99,12 +96,9 @@ public class ExtendedRobot extends Robot {
* GraphicsEnvironment.isHeadless() returns true. * GraphicsEnvironment.isHeadless() returns true.
* @throws IllegalArgumentException if {@code screen} is not a screen * @throws IllegalArgumentException if {@code screen} is not a screen
* GraphicsDevice. * GraphicsDevice.
* @throws SecurityException if {@code createRobot} permission is not granted
* *
* @see java.awt.GraphicsEnvironment#isHeadless * @see java.awt.GraphicsEnvironment#isHeadless
* @see GraphicsDevice * @see GraphicsDevice
* @see SecurityManager#checkPermission
* @see java.awt.AWTPermission
*/ */
public ExtendedRobot(GraphicsDevice screen) throws AWTException { public ExtendedRobot(GraphicsDevice screen) throws AWTException {
super(screen); super(screen);