提交 9bc18470 编写于 作者: A anthony

6821948: Consider removing the constraints for bounds of untrusted top-level windows

Summary: The constrainBounds() methods are removed.
Reviewed-by: art, dcherepanov
上级 8229796f
......@@ -490,8 +490,7 @@ abstract class XDecoratedPeer extends XWindowPeer {
// 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 @@ abstract class XDecoratedPeer extends XWindowPeer {
// 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
*/
......
......@@ -196,12 +196,6 @@ public class XEmbeddedFramePeer extends XFramePeer {
}
}
@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);
......
......@@ -156,11 +156,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
}
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 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
| 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));
}
......
......@@ -180,9 +180,6 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
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 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
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 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
//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();
......
......@@ -114,12 +114,10 @@ class WDialogPeer extends WWindowPeer implements DialogPeer {
}
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);
}
}
......
......@@ -67,12 +67,6 @@ public class WEmbeddedFramePeer extends WFramePeer {
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
......
......@@ -89,12 +89,10 @@ class WFramePeer extends WWindowPeer implements FramePeer {
}
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);
}
}
......
......@@ -546,81 +546,16 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
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 = newBounds.x;
sysY = newBounds.y;
sysW = newBounds.width;
sysH = newBounds.height;
sysX = x;
sysY = y;
sysW = width;
sysH = height;
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
super.setBounds(x, y, width, height, op);
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册