Title: [199369] releases/WebKitGTK/webkit-2.12/Source/WebCore
Revision
199369
Author
[email protected]
Date
2016-04-12 09:57:23 -0700 (Tue, 12 Apr 2016)

Log Message

Merge r198238 - Delay HTMLFormControlElement::focus() call until after layout is finished.
https://bugs.webkit.org/show_bug.cgi?id=155503
<rdar://problem/24046635>

Reviewed by Simon Fraser.

Calling focus on a form element can trigger arbitrary JS code which could interfere with
the ongoing layout.
This patch delays HTMLFormControlElement::focus() call until after layout is finished.
If we are currently not in the middle of a layout, HTMLFormControlElement::focus() is delayed until
after style resolution is done.

Covered by LayoutTests/fast/dom/adopt-node-crash-2.html

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::updateBackingStore):
* dom/Document.cpp:
(WebCore::Document::updateStyleIfNeeded):
(WebCore::Document::updateLayout):
(WebCore::Document::updateLayoutIfDimensionsOutOfDate):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::renderWidgetLoadingPlugin):
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::didAttachRenderers):
* page/FrameView.cpp:
(WebCore::FrameView::layout):
(WebCore::FrameView::queuePostLayoutCallback):
(WebCore::FrameView::flushPostLayoutTasksQueue):
(WebCore::FrameView::performPostLayoutTasks):
(WebCore::FrameView::sendResizeEventIfNeeded):
* page/FrameView.h:
* rendering/RenderBox.cpp:
(WebCore::RenderBox::imageChanged):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollTo):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog	2016-04-12 16:57:23 UTC (rev 199369)
@@ -1,3 +1,41 @@
+2016-03-15  Zalan Bujtas  <[email protected]>
+
+        Delay HTMLFormControlElement::focus() call until after layout is finished.
+        https://bugs.webkit.org/show_bug.cgi?id=155503
+        <rdar://problem/24046635>
+
+        Reviewed by Simon Fraser.
+
+        Calling focus on a form element can trigger arbitrary JS code which could interfere with
+        the ongoing layout. 
+        This patch delays HTMLFormControlElement::focus() call until after layout is finished.
+        If we are currently not in the middle of a layout, HTMLFormControlElement::focus() is delayed until
+        after style resolution is done. 
+
+        Covered by LayoutTests/fast/dom/adopt-node-crash-2.html
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::updateBackingStore):
+        * dom/Document.cpp:
+        (WebCore::Document::updateStyleIfNeeded):
+        (WebCore::Document::updateLayout):
+        (WebCore::Document::updateLayoutIfDimensionsOutOfDate):
+        * html/HTMLEmbedElement.cpp:
+        (WebCore::HTMLEmbedElement::renderWidgetLoadingPlugin):
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::didAttachRenderers):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::layout):
+        (WebCore::FrameView::queuePostLayoutCallback):
+        (WebCore::FrameView::flushPostLayoutTasksQueue):
+        (WebCore::FrameView::performPostLayoutTasks):
+        (WebCore::FrameView::sendResizeEventIfNeeded):
+        * page/FrameView.h:
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::imageChanged):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::scrollTo):
+
 2016-03-15  Antti Koivisto  <[email protected]>
 
         REGRESSION (196383): Class change invalidation does not handle :not correctly

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/accessibility/AccessibilityObject.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/accessibility/AccessibilityObject.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/accessibility/AccessibilityObject.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -1623,7 +1623,7 @@
     RefPtr<AccessibilityObject> protector(this);
 
     if (Document* document = this->document()) {
-        if (!document->view()->isInLayout())
+        if (!document->view()->isInRenderTreeLayout())
             document->updateLayoutIgnorePendingStylesheets();
     }
     

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/dom/Document.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/dom/Document.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/dom/Document.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -1928,7 +1928,7 @@
     ASSERT(isMainThread());
     ASSERT(!view() || !view()->isPainting());
 
-    if (!view() || view()->isInLayout())
+    if (!view() || view()->isInRenderTreeLayout())
         return;
 
     if (m_optimizedStyleSheetUpdateTimer.isActive())
@@ -1945,7 +1945,7 @@
     ASSERT(isMainThread());
 
     FrameView* frameView = view();
-    if (frameView && frameView->isInLayout()) {
+    if (frameView && frameView->isInRenderTreeLayout()) {
         // View layout should not be re-entrant.
         ASSERT_NOT_REACHED();
         return;
@@ -2025,7 +2025,7 @@
     
     // Check for re-entrancy and assert (same code that is in updateLayout()).
     FrameView* frameView = view();
-    if (frameView && frameView->isInLayout()) {
+    if (frameView && frameView->isInRenderTreeLayout()) {
         // View layout should not be re-entrant.
         ASSERT_NOT_REACHED();
         return true;

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/html/HTMLEmbedElement.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/html/HTMLEmbedElement.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/html/HTMLEmbedElement.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -71,7 +71,7 @@
 RenderWidget* HTMLEmbedElement::renderWidgetLoadingPlugin() const
 {
     FrameView* view = document().view();
-    if (!view || (!view->isInLayout() && !view->isPainting())) {
+    if (!view || (!view->isInRenderTreeLayout() && !view->isPainting())) {
         // Needs to load the plugin immediatedly because this function is called
         // when _javascript_ code accesses the plugin.
         // FIXME: <rdar://16893708> Check if dispatching events here is safe.

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/html/HTMLFormControlElement.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/html/HTMLFormControlElement.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/html/HTMLFormControlElement.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -31,6 +31,7 @@
 #include "EventHandler.h"
 #include "EventNames.h"
 #include "Frame.h"
+#include "FrameView.h"
 #include "HTMLFieldSetElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLInputElement.h"
@@ -234,9 +235,16 @@
         setAutofocused();
 
         RefPtr<HTMLFormControlElement> element = this;
-        Style::queuePostResolutionCallback([element] {
-            element->focus();
-        });
+        auto* frameView = document().view();
+        if (frameView && frameView->isInLayout()) {
+            frameView->queuePostLayoutCallback([element] {
+                element->focus();
+            });
+        } else {
+            Style::queuePostResolutionCallback([element] {
+                element->focus();
+            });
+        }
     }
 }
 

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/page/FrameView.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/page/FrameView.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/page/FrameView.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -1209,7 +1209,7 @@
 void FrameView::layout(bool allowSubtree)
 {
     LOG(Layout, "FrameView %p (%dx%d) layout, main frameview %d, allowSubtree=%d", this, size().width(), size().height(), frame().isMainFrame(), allowSubtree);
-    if (isInLayout()) {
+    if (isInRenderTreeLayout()) {
         LOG(Layout, "  in layout, bailing");
         return;
     }
@@ -1397,11 +1397,11 @@
         RenderView::RepaintRegionAccumulator repaintRegionAccumulator(&root->view());
 
         ASSERT(m_layoutPhase == InPreLayout);
-        m_layoutPhase = InLayout;
+        m_layoutPhase = InRenderTreeLayout;
 
         forceLayoutParentViewIfNeeded();
 
-        ASSERT(m_layoutPhase == InLayout);
+        ASSERT(m_layoutPhase == InRenderTreeLayout);
 
         root->layout();
 #if ENABLE(IOS_TEXT_AUTOSIZING)
@@ -1420,7 +1420,7 @@
             root->layout();
 #endif
 
-        ASSERT(m_layoutPhase == InLayout);
+        ASSERT(m_layoutPhase == InRenderTreeLayout);
         m_layoutRoot = nullptr;
         // Close block here to end the scope of changeSchedulingEnabled and SubtreeLayoutStateMaintainer.
     }
@@ -3073,6 +3073,25 @@
         updateEmbeddedObjectsTimerFired();
 }
 
+void FrameView::queuePostLayoutCallback(std::function<void()> callback)
+{
+    m_postLayoutCallbackQueue.append(callback);
+}
+
+void FrameView::flushPostLayoutTasksQueue()
+{
+    if (m_nestedLayoutCount > 1)
+        return;
+
+    if (!m_postLayoutCallbackQueue.size())
+        return;
+
+    const auto queue = m_postLayoutCallbackQueue;
+    m_postLayoutCallbackQueue.clear();
+    for (size_t i = 0; i < queue.size(); ++i)
+        queue[i]();
+}
+
 void FrameView::performPostLayoutTasks()
 {
     LOG(Layout, "FrameView %p performPostLayoutTasks", this);
@@ -3083,6 +3102,8 @@
 
     frame().selection().updateAppearanceAfterLayout();
 
+    flushPostLayoutTasksQueue();
+
     if (m_nestedLayoutCount <= 1 && frame().document()->documentElement())
         fireLayoutRelatedMilestonesIfNeeded();
 
@@ -3148,7 +3169,7 @@
 
 void FrameView::sendResizeEventIfNeeded()
 {
-    if (isInLayout() || needsLayout())
+    if (isInRenderTreeLayout() || needsLayout())
         return;
 
     RenderView* renderView = this->renderView();

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/page/FrameView.h (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/page/FrameView.h	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/page/FrameView.h	2016-04-12 16:57:23 UTC (rev 199369)
@@ -111,9 +111,11 @@
     void scheduleRelayout();
     void scheduleRelayoutOfSubtree(RenderElement&);
     void unscheduleRelayout();
+    void queuePostLayoutCallback(std::function<void()>);
     bool layoutPending() const;
-    bool isInLayout() const { return m_layoutPhase == InLayout; }
-    WEBCORE_EXPORT bool inPaintableState() { return m_layoutPhase != InLayout && m_layoutPhase != InViewSizeAdjust && m_layoutPhase != InPostLayout; }
+    bool isInLayout() const { return m_layoutPhase != OutsideLayout; }
+    bool isInRenderTreeLayout() const { return m_layoutPhase == InRenderTreeLayout; }
+    WEBCORE_EXPORT bool inPaintableState() { return m_layoutPhase != InRenderTreeLayout && m_layoutPhase != InViewSizeAdjust && m_layoutPhase != InPostLayout; }
 
     RenderElement* layoutRoot() const { return m_layoutRoot; }
     void clearLayoutRoot() { m_layoutRoot = nullptr; }
@@ -572,7 +574,7 @@
         OutsideLayout,
         InPreLayout,
         InPreLayoutStyleUpdate,
-        InLayout,
+        InRenderTreeLayout,
         InViewSizeAdjust,
         InPostLayout,
         InPostLayerPositionsUpdatedAfterLayout,
@@ -604,6 +606,7 @@
     WEBCORE_EXPORT void paintControlTints();
 
     void forceLayoutParentViewIfNeeded();
+    void flushPostLayoutTasksQueue();
     void performPostLayoutTasks();
     void autoSizeIfEnabled();
 
@@ -817,6 +820,7 @@
     ScrollPinningBehavior m_scrollPinningBehavior;
 
     IntRect* m_cachedWindowClipRect { nullptr };
+    Vector<std::function<void()>> m_postLayoutCallbackQueue;
 };
 
 inline void FrameView::incrementVisuallyNonEmptyCharacterCount(unsigned count)

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/rendering/RenderBox.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/rendering/RenderBox.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/rendering/RenderBox.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -1692,7 +1692,7 @@
 
 #if ENABLE(CSS_SHAPES)
     ShapeValue* shapeOutsideValue = style().shapeOutside();
-    if (!view().frameView().isInLayout() && isFloating() && shapeOutsideValue && shapeOutsideValue->image() && shapeOutsideValue->image()->data() == image) {
+    if (!view().frameView().isInRenderTreeLayout() && isFloating() && shapeOutsideValue && shapeOutsideValue->image() && shapeOutsideValue->image()->data() == image) {
         ShapeOutsideInfo::ensureInfo(*this).markShapeAsDirty();
         markShapeOutsideDependentsForLayout();
     }

Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/rendering/RenderLayer.cpp (199368 => 199369)


--- releases/WebKitGTK/webkit-2.12/Source/WebCore/rendering/RenderLayer.cpp	2016-04-12 16:50:02 UTC (rev 199368)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/rendering/RenderLayer.cpp	2016-04-12 16:57:23 UTC (rev 199369)
@@ -2385,8 +2385,7 @@
 
     // Update the positions of our child layers (if needed as only fixed layers should be impacted by a scroll).
     // We don't update compositing layers, because we need to do a deep update from the compositing ancestor.
-    bool inLayout = view.frameView().isInLayout();
-    if (!inLayout) {
+    if (!view.frameView().isInRenderTreeLayout()) {
         // If we're in the middle of layout, we'll just update layers once layout has finished.
         updateLayerPositionsAfterOverflowScroll();
         // Update regions, scrolling may change the clip of a particular region.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to