6821948: Consider removing the constraints for bounds of untrusted top-level windows
Summary: The constrainBounds() methods are removed.
Reviewed-by: art, dcherepanov
--- a/jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -490,8 +490,7 @@
// if the window manager or any other part of the windowing
// system sets inappropriate size for this window, we can
// do nothing but accept it.
- Rectangle reqBounds = newDimensions.getBounds();
- Rectangle newBounds = constrainBounds(reqBounds.x, reqBounds.y, reqBounds.width, reqBounds.height);
+ Rectangle newBounds = newDimensions.getBounds();
Insets insets = newDimensions.getInsets();
// Inherit isClientSizeSet from newDimensions
if (newDimensions.isClientSizeSet()) {
@@ -619,46 +618,6 @@
// This method gets overriden in XFramePeer & XDialogPeer.
abstract boolean isTargetUndecorated();
- @Override
- Rectangle constrainBounds(int x, int y, int width, int height) {
- // We don't restrict the setBounds() operation if the code is trusted.
- if (!hasWarningWindow()) {
- return new Rectangle(x, y, width, height);
- }
-
- // If it's undecorated or is not currently visible,
- // apply the same constraints as for the Window.
- if (!isVisible() || isTargetUndecorated()) {
- return super.constrainBounds(x, y, width, height);
- }
-
- // If it's visible & decorated, constraint the size only
- int newX = x;
- int newY = y;
- int newW = width;
- int newH = height;
-
- GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
- Rectangle sB = gc.getBounds();
- Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
-
- Rectangle curBounds = getBounds();
-
- int maxW = Math.max(sB.width - sIn.left - sIn.right, curBounds.width);
- int maxH = Math.max(sB.height - sIn.top - sIn.bottom, curBounds.height);
-
- // First make sure the size is withing the visible part of the screen
- if (newW > maxW) {
- newW = maxW;
- }
-
- if (newH > maxH) {
- newH = maxH;
- }
-
- return new Rectangle(newX, newY, newW, newH);
- }
-
/**
* @see java.awt.peer.ComponentPeer#setBounds
*/
--- a/jdk/src/solaris/classes/sun/awt/X11/XEmbeddedFramePeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XEmbeddedFramePeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -196,12 +196,6 @@
}
}
- @Override
- Rectangle constrainBounds(int x, int y, int width, int height) {
- // We don't constrain the bounds of the EmbeddedFrames
- return new Rectangle(x, y, width, height);
- }
-
// don't use getBounds() inherited from XDecoratedPeer
public Rectangle getBounds() {
return new Rectangle(x, y, width, height);
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java Fri Apr 17 16:30:15 2009 +0400
@@ -156,11 +156,11 @@
}
XWindow(Component target, long parentWindow) {
- this(target, parentWindow, target.getBounds());
+ this(target, parentWindow, new Rectangle(target.getBounds()));
}
XWindow(Component target) {
- this(target, (target.getParent() == null) ? 0 : getParentWindowID(target), target.getBounds());
+ this(target, (target.getParent() == null) ? 0 : getParentWindowID(target), new Rectangle(target.getBounds()));
}
XWindow(Object target) {
@@ -198,7 +198,7 @@
| XConstants.ButtonMotionMask | XConstants.ExposureMask | XConstants.StructureNotifyMask);
if (target != null) {
- params.putIfNull(BOUNDS, target.getBounds());
+ params.putIfNull(BOUNDS, new Rectangle(target.getBounds()));
} else {
params.putIfNull(BOUNDS, new Rectangle(0, 0, MIN_SIZE, MIN_SIZE));
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -180,9 +180,6 @@
GraphicsConfiguration gc = getGraphicsConfiguration();
((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
-
- Rectangle bounds = (Rectangle)(params.get(BOUNDS));
- params.put(BOUNDS, constrainBounds(bounds.x, bounds.y, bounds.width, bounds.height));
}
protected String getWMName() {
@@ -437,56 +434,6 @@
return ownerPeer;
}
- // This method is overriden at the XDecoratedPeer to handle
- // decorated windows a bit differently.
- Rectangle constrainBounds(int x, int y, int width, int height) {
- // We don't restrict the setBounds() operation if the code is trusted.
- if (!hasWarningWindow()) {
- return new Rectangle(x, y, width, height);
- }
-
- // The window bounds should be within the visible part of the screen
- int newX = x;
- int newY = y;
- int newW = width;
- int newH = height;
-
- // Now check each point is within the visible part of the screen
- GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
- Rectangle sB = gc.getBounds();
- Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
-
- int screenX = sB.x + sIn.left;
- int screenY = sB.y + sIn.top;
- int screenW = sB.width - sIn.left - sIn.right;
- int screenH = sB.height - sIn.top - sIn.bottom;
-
-
- // First make sure the size is withing the visible part of the screen
- if (newW > screenW) {
- newW = screenW;
- }
-
- if (newH > screenH) {
- newH = screenH;
- }
-
- // Tweak the location if needed
- if (newX < screenX) {
- newX = screenX;
- } else if (newX + newW > screenX + screenW) {
- newX = screenX + screenW - newW;
- }
-
- if (newY < screenY) {
- newY = screenY;
- } else if (newY + newH > screenY + screenH) {
- newY = screenY + screenH - newH;
- }
-
- return new Rectangle(newX, newY, newW, newH);
- }
-
//Fix for 6318144: PIT:Setting Min Size bigger than current size enlarges
//the window but fails to revalidate, Sol-CDE
//This bug is regression for
@@ -495,13 +442,11 @@
//Note that this function is overriden in XDecoratedPeer so event
//posting is not changing for decorated peers
public void setBounds(int x, int y, int width, int height, int op) {
- Rectangle newBounds = constrainBounds(x, y, width, height);
-
XToolkit.awtLock();
try {
Rectangle oldBounds = getBounds();
- super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
+ super.setBounds(x, y, width, height, op);
Rectangle bounds = getBounds();
--- a/jdk/src/windows/classes/sun/awt/windows/WDialogPeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WDialogPeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -114,12 +114,10 @@
}
public void reshape(int x, int y, int width, int height) {
- Rectangle newBounds = constrainBounds(x, y, width, height);
-
if (((Dialog)target).isUndecorated()) {
- super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
+ super.reshape(x, y, width, height);
} else {
- reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
+ reshapeFrame(x, y, width, height);
}
}
--- a/jdk/src/windows/classes/sun/awt/windows/WEmbeddedFramePeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WEmbeddedFramePeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -68,12 +68,6 @@
public native void synthesizeWmActivate(boolean doActivate);
@Override
- Rectangle constrainBounds(int x, int y, int width, int height) {
- // We don't constrain the bounds of the EmbeddedFrames
- return new Rectangle(x, y, width, height);
- }
-
- @Override
public boolean isAccelCapable() {
// REMIND: Temp workaround for issues with using HW acceleration
// in the browser on Vista when DWM is enabled
--- a/jdk/src/windows/classes/sun/awt/windows/WFramePeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WFramePeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -89,12 +89,10 @@
}
public void reshape(int x, int y, int width, int height) {
- Rectangle newBounds = constrainBounds(x, y, width, height);
-
if (((Frame)target).isUndecorated()) {
- super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
+ super.reshape(x, y, width, height);
} else {
- reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
+ reshapeFrame(x, y, width, height);
}
}
--- a/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java Fri Apr 17 16:16:14 2009 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java Fri Apr 17 16:30:15 2009 +0400
@@ -546,81 +546,16 @@
private volatile int sysW = 0;
private volatile int sysH = 0;
- Rectangle constrainBounds(int x, int y, int width, int height) {
- GraphicsConfiguration gc = this.winGraphicsConfig;
-
- // We don't restrict the setBounds() operation if the code is trusted.
- if (!hasWarningWindow() || gc == null) {
- return new Rectangle(x, y, width, height);
- }
-
- int newX = x;
- int newY = y;
- int newW = width;
- int newH = height;
-
- Rectangle sB = gc.getBounds();
- Insets sIn = Toolkit.getDefaultToolkit().getScreenInsets(gc);
-
- int screenW = sB.width - sIn.left - sIn.right;
- int screenH = sB.height - sIn.top - sIn.bottom;
-
- // If it's undecorated or is not currently visible
- if (!AWTAccessor.getComponentAccessor().isVisible_NoClientCode(
- (Component)target) || isTargetUndecorated())
- {
- // Now check each point is within the visible part of the screen
- int screenX = sB.x + sIn.left;
- int screenY = sB.y + sIn.top;
-
- // First make sure the size is within the visible part of the screen
- if (newW > screenW) {
- newW = screenW;
- }
- if (newH > screenH) {
- newH = screenH;
- }
-
- // Tweak the location if needed
- if (newX < screenX) {
- newX = screenX;
- } else if (newX + newW > screenX + screenW) {
- newX = screenX + screenW - newW;
- }
- if (newY < screenY) {
- newY = screenY;
- } else if (newY + newH > screenY + screenH) {
- newY = screenY + screenH - newH;
- }
- } else {
- int maxW = Math.max(screenW, sysW);
- int maxH = Math.max(screenH, sysH);
-
- // Make sure the size is withing the visible part of the screen
- // OR less that the current size of the window.
- if (newW > maxW) {
- newW = maxW;
- }
- if (newH > maxH) {
- newH = maxH;
- }
- }
-
- return new Rectangle(newX, newY, newW, newH);
- }
-
public native void repositionSecurityWarning();
@Override
public void setBounds(int x, int y, int width, int height, int op) {
- Rectangle newBounds = constrainBounds(x, y, width, height);
+ sysX = x;
+ sysY = y;
+ sysW = width;
+ sysH = height;
- sysX = newBounds.x;
- sysY = newBounds.y;
- sysW = newBounds.width;
- sysH = newBounds.height;
-
- super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
+ super.setBounds(x, y, width, height, op);
}
@Override