Commit 645830fb authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Ensure popups can't be moved off-screen

BUG=681511
R=mkwst@chromium.org

Change-Id: I351b28a09bfe09e5045ada5e228f8f0958a9eccb
Reviewed-on: https://chromium-review.googlesource.com/700264
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506771}
parent 39cc339e
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
let minWindowDimension = 100;
if (window.testRunner) {
testRunner.setCanOpenWindows();
testRunner.setCloseRemainingWindowsWhenComplete();
}
test(t => {
let w = window.open('about:blank', '', 'resizable=1,menubar=0,status=1');
w.moveTo(screen.width + 1000, screen.height + 1000);
assert_equals(w.screenY, (screen.availTop + screen.availHeight) - minWindowDimension);
assert_equals(w.screenX, (screen.availLeft + screen.availWidth) - minWindowDimension);
}, 'popup must not be moved outside of screen');
</script>
......@@ -54,20 +54,29 @@ void ChromeClient::SetWindowRectWithAdjustment(const IntRect& pending_rect,
IntRect window = pending_rect;
IntSize minimum_size = MinimumWindowSize();
IntSize size_for_constraining_move = minimum_size;
// Let size 0 pass through, since that indicates default size, not minimum
// size.
if (window.Width())
if (window.Width()) {
window.SetWidth(std::min(std::max(minimum_size.Width(), window.Width()),
screen.Width()));
if (window.Height())
size_for_constraining_move.SetWidth(window.Width());
}
if (window.Height()) {
window.SetHeight(std::min(std::max(minimum_size.Height(), window.Height()),
screen.Height()));
size_for_constraining_move.SetHeight(window.Height());
}
// Constrain the window position within the valid screen area.
window.SetX(std::max(screen.X(),
std::min(window.X(), screen.MaxX() - window.Width())));
window.SetY(std::max(screen.Y(),
std::min(window.Y(), screen.MaxY() - window.Height())));
window.SetX(
std::max(screen.X(),
std::min(window.X(),
screen.MaxX() - size_for_constraining_move.Width())));
window.SetY(
std::max(screen.Y(),
std::min(window.Y(),
screen.MaxY() - size_for_constraining_move.Height())));
SetWindowRect(window, frame);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment