Commit 1a413b53 authored by bokan's avatar bokan Committed by Commit bot

Don't assume current root scroller is a LayoutBox.

There was an edge case here where we might get an arbitrary element as the
document.documentElement. In these cases, the element won't get a LayoutObject
as LayoutView will refuse to attach to it, but when we replace it a layout will
create a non-LayoutBox for it and when RootScroller tries to replace it as the
effective root scroller it needs to do some book keeping using the old root
scroller. It incorrectly assumed it must be a LayoutBox.

This patch now guards against this edge case.

BUG=668553

Review-Url: https://codereview.chromium.org/2531343002
Cr-Commit-Position: refs/heads/master@{#434771}
parent c5dd67fc
...@@ -36,10 +36,9 @@ ScrollableArea* scrollableAreaForRootScroller(const Element& element) { ...@@ -36,10 +36,9 @@ ScrollableArea* scrollableAreaForRootScroller(const Element& element) {
} }
PaintLayer* paintLayerForRootScroller(const Element* element) { PaintLayer* paintLayerForRootScroller(const Element* element) {
if (!element || !element->layoutObject()) if (!element || !element->layoutObject() || !element->layoutObject()->isBox())
return nullptr; return nullptr;
DCHECK(element->layoutObject()->isBox());
LayoutBox* box = toLayoutBox(element->layoutObject()); LayoutBox* box = toLayoutBox(element->layoutObject());
// If the root scroller is the <html> element we do a bit of a fake out // If the root scroller is the <html> element we do a bit of a fake out
......
...@@ -1168,6 +1168,25 @@ TEST_F(RootScrollerTest, RotationAnchoring) { ...@@ -1168,6 +1168,25 @@ TEST_F(RootScrollerTest, RotationAnchoring) {
EXPECT_EQ(rect->top(), visualViewport().scrollOffset().height()); EXPECT_EQ(rect->top(), visualViewport().scrollOffset().height());
} }
// Tests that we don't crash if the default documentElement isn't a valid root
// scroller. This can happen in some edge cases where documentElement isn't
// <html>. crbug.com/668553.
TEST_F(RootScrollerTest, InvalidDefaultRootScroller) {
initialize("overflow-scrolling.html");
Document* document = mainFrame()->document();
Element* br = document->createElement("br");
document->replaceChild(br, document->documentElement());
mainFrameView()->updateAllLifecyclePhases();
Element* html = document->createElement("html");
Element* body = document->createElement("body");
html->appendChild(body);
body->appendChild(br);
document->appendChild(html);
mainFrameView()->updateAllLifecyclePhases();
}
} // namespace } // namespace
} // namespace blink } // namespace blink
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