Commit db2df0ad authored by bokan's avatar bokan Committed by Commit bot

Fix crash with viewport units when using auto resize mode.

This crash is caused because of a divide-by-zero when calculating viewport
units. The zero width visual viewport occurs because the WebView is responsible
for resizing the VisualViewport but the autoresize code resizes the FrameView.
This does eventually lead to resizing the WebView when a layout occurs and
calls though to WebView::layoutUpdated, however, until that happens the layout
will use the 0 value.

This isn't ever a problem since the calculation that's dividing by 0 is used to
adjust the browser controls to the minimum page scale but autoresize isn't ever
used on Android, which is the only platform that uses browser controls and a
non-1 minimum page scale.

BUG=667712

Review-Url: https://codereview.chromium.org/2616893004
Cr-Commit-Position: refs/heads/master@{#442048}
parent e6fef819
......@@ -1378,9 +1378,9 @@ FloatSize FrameView::viewportSizeForViewportUnits() const {
// height, compensating for page scale as well, since we want to use the
// viewport with browser controls hidden for vh (to match Safari).
BrowserControls& browserControls = m_frame->host()->browserControls();
if (m_frame->isMainFrame() && size.width()) {
float pageScaleAtLayoutWidth =
m_frame->host()->visualViewport().size().width() / size.width();
int viewportWidth = m_frame->host()->visualViewport().size().width();
if (m_frame->isMainFrame() && size.width() && viewportWidth) {
float pageScaleAtLayoutWidth = viewportWidth / size.width();
size.expand(0, browserControls.height() / pageScaleAtLayoutWidth);
}
......
......@@ -2456,4 +2456,24 @@ TEST_P(VisualViewportTest, InvalidateLayoutViewWhenDocumentSmallerThanView) {
RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls);
}
// Make sure we don't crash when the visual viewport's height is 0. This can
// happen transiently in autoresize mode and cause a crash. This test passes if
// it doesn't crash.
TEST_P(VisualViewportTest, AutoResizeNoHeightUsesMinimumHeight) {
initializeWithDesktopSettings();
webViewImpl()->resizeWithBrowserControls(WebSize(0, 0), 0, false);
webViewImpl()->enableAutoResizeMode(WebSize(25, 25), WebSize(100, 100));
WebURL baseURL = URLTestHelpers::toKURL("http://example.com/");
FrameTestHelpers::loadHTMLString(webViewImpl()->mainFrame(),
"<!DOCTYPE html>"
"<style>"
" body {"
" margin: 0px;"
" }"
" div { height:110vh; width: 110vw; }"
"</style>"
"<div></div>",
baseURL);
}
} // namespace
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