Title: [199003] trunk/Source/WebCore
Revision
199003
Author
[email protected]
Date
2016-04-04 05:56:33 -0700 (Mon, 04 Apr 2016)

Log Message

Enable assertions against DOM mutations in RenderTreeUpdater
https://bugs.webkit.org/show_bug.cgi?id=156156

Reviewed by Andreas Kling.

Ensure we don't mutate DOM or dispatch events during render tree updates.

* WebCore.xcodeproj/project.pbxproj:
* dom/ContainerNode.cpp:
* dom/ContainerNode.h:
(WebCore::NoEventDispatchAssertion::NoEventDispatchAssertion): Deleted.
(WebCore::NoEventDispatchAssertion::~NoEventDispatchAssertion): Deleted.
(WebCore::NoEventDispatchAssertion::isEventDispatchForbidden): Deleted.

    Move NoEventDispatchAssertion to a header of its own.

* dom/NoEventDispatchAssertion.h: Added.
(WebCore::NoEventDispatchAssertion::NoEventDispatchAssertion):
(WebCore::NoEventDispatchAssertion::~NoEventDispatchAssertion):
(WebCore::NoEventDispatchAssertion::isEventDispatchForbidden):
(WebCore::NoEventDispatchAssertion::dropTemporarily):
(WebCore::NoEventDispatchAssertion::restoreDropped):

    Add a way to disable event assertions temporarily.

* loader/cache/CachedSVGFont.cpp:
(WebCore::CachedSVGFont::ensureCustomFontData):

    Temporary SVG font document may get constructed during render tree update. These can't run scripts or generally
    affect anything outside the font document as it does not have a frame. Disable event assertions temporarily.

    Tested by svg/W3C-SVG-1.1/fonts-elem-07-b.svg

* style/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::updateRenderTree):

    Enable assertions.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (199002 => 199003)


--- trunk/Source/WebCore/ChangeLog	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/ChangeLog	2016-04-04 12:56:33 UTC (rev 199003)
@@ -1,3 +1,43 @@
+2016-04-04  Antti Koivisto  <[email protected]>
+
+        Enable assertions against DOM mutations in RenderTreeUpdater
+        https://bugs.webkit.org/show_bug.cgi?id=156156
+
+        Reviewed by Andreas Kling.
+
+        Ensure we don't mutate DOM or dispatch events during render tree updates.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/ContainerNode.cpp:
+        * dom/ContainerNode.h:
+        (WebCore::NoEventDispatchAssertion::NoEventDispatchAssertion): Deleted.
+        (WebCore::NoEventDispatchAssertion::~NoEventDispatchAssertion): Deleted.
+        (WebCore::NoEventDispatchAssertion::isEventDispatchForbidden): Deleted.
+
+            Move NoEventDispatchAssertion to a header of its own.
+
+        * dom/NoEventDispatchAssertion.h: Added.
+        (WebCore::NoEventDispatchAssertion::NoEventDispatchAssertion):
+        (WebCore::NoEventDispatchAssertion::~NoEventDispatchAssertion):
+        (WebCore::NoEventDispatchAssertion::isEventDispatchForbidden):
+        (WebCore::NoEventDispatchAssertion::dropTemporarily):
+        (WebCore::NoEventDispatchAssertion::restoreDropped):
+
+            Add a way to disable event assertions temporarily.
+
+        * loader/cache/CachedSVGFont.cpp:
+        (WebCore::CachedSVGFont::ensureCustomFontData):
+
+            Temporary SVG font document may get constructed during render tree update. These can't run scripts or generally
+            affect anything outside the font document as it does not have a frame. Disable event assertions temporarily.
+
+            Tested by svg/W3C-SVG-1.1/fonts-elem-07-b.svg
+
+        * style/RenderTreeUpdater.cpp:
+        (WebCore::RenderTreeUpdater::updateRenderTree):
+
+            Enable assertions.
+
 2016-04-04  Emanuele Aina  <[email protected]>
 
         [TexMap] Trim redundant guards

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (199002 => 199003)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-04-04 12:56:33 UTC (rev 199003)
@@ -6625,6 +6625,7 @@
 		E462A4A1113E71BE004A4220 /* IntPointHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E462A4A0113E71BE004A4220 /* IntPointHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E46A2B1C17CA65B9000DBCD8 /* TypedElementDescendantIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A2B1B17CA65B9000DBCD8 /* TypedElementDescendantIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E46A2B1E17CA76B1000DBCD8 /* ElementChildIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E46B41F91CB24E70008F11DE /* NoEventDispatchAssertion.h in Headers */ = {isa = PBXBuildFile; fileRef = E46B41F81CB24E70008F11DE /* NoEventDispatchAssertion.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E47127CA163438A100ED6F5A /* StyleInvalidationAnalysis.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47A97CE163059FC005DCD99 /* StyleInvalidationAnalysis.cpp */; };
 		E47127CB163438AE00ED6F5A /* StyleInvalidationAnalysis.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A97CF163059FC005DCD99 /* StyleInvalidationAnalysis.h */; };
 		E4778B7F115A581A00B5D372 /* JSCustomEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */; };
@@ -14657,6 +14658,7 @@
 		E462A4A0113E71BE004A4220 /* IntPointHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntPointHash.h; sourceTree = "<group>"; };
 		E46A2B1B17CA65B9000DBCD8 /* TypedElementDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypedElementDescendantIterator.h; sourceTree = "<group>"; };
 		E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementChildIterator.h; sourceTree = "<group>"; };
+		E46B41F81CB24E70008F11DE /* NoEventDispatchAssertion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NoEventDispatchAssertion.h; sourceTree = "<group>"; };
 		E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomEvent.cpp; sourceTree = "<group>"; };
 		E4778B7E115A581A00B5D372 /* JSCustomEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomEvent.h; sourceTree = "<group>"; };
 		E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSharingResolver.cpp; sourceTree = "<group>"; };
@@ -24420,6 +24422,7 @@
 				E43105B716750F0C00DB2FB8 /* NodeTraversal.cpp */,
 				E43105BA16750F1600DB2FB8 /* NodeTraversal.h */,
 				9382AAB10D8C386100F357A6 /* NodeWithIndex.h */,
+				E46B41F81CB24E70008F11DE /* NoEventDispatchAssertion.h */,
 				8369E58F1AFDD0300087DF68 /* NonDocumentTypeChildNode.idl */,
 				7C6752BA1B06E82000C279CB /* NonElementParentNode.idl */,
 				1A0D57340A5C77FE007EDD4C /* OverflowEvent.cpp */,
@@ -26306,6 +26309,7 @@
 				5185FC991BB4C4E80012898F /* IDBKeyPath.h in Headers */,
 				5185FC9B1BB4C4E80012898F /* IDBKeyRange.h in Headers */,
 				5185FC9E1BB4C4E80012898F /* IDBKeyRangeData.h in Headers */,
+				E46B41F91CB24E70008F11DE /* NoEventDispatchAssertion.h in Headers */,
 				5185FCA01BB4C4E80012898F /* IDBObjectStore.h in Headers */,
 				5160712F1BD8307800DBC4F2 /* IDBObjectStoreInfo.h in Headers */,
 				5185FCA41BB4C4E80012898F /* IDBOpenDBRequest.h in Headers */,

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -42,6 +42,7 @@
 #include "LabelsNodeList.h"
 #include "MutationEvent.h"
 #include "NameNodeList.h"
+#include "NoEventDispatchAssertion.h"
 #include "NodeOrString.h"
 #include "NodeRareData.h"
 #include "NodeRenderStyle.h"

Modified: trunk/Source/WebCore/dom/ContainerNode.h (199002 => 199003)


--- trunk/Source/WebCore/dom/ContainerNode.h	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2016-04-04 12:56:33 UTC (rev 199003)
@@ -34,49 +34,6 @@
 class RadioNodeList;
 class RenderElement;
 
-class NoEventDispatchAssertion {
-public:
-    NoEventDispatchAssertion()
-    {
-#if !ASSERT_DISABLED
-        if (!isMainThread())
-            return;
-        ++s_count;
-#endif
-    }
-
-    NoEventDispatchAssertion(const NoEventDispatchAssertion&)
-        : NoEventDispatchAssertion()
-    {
-    }
-
-    ~NoEventDispatchAssertion()
-    {
-#if !ASSERT_DISABLED
-        if (!isMainThread())
-            return;
-        ASSERT(s_count);
-        s_count--;
-#endif
-    }
-
-    static bool isEventDispatchForbidden()
-    {
-#if ASSERT_DISABLED
-        return false;
-#else
-        return isMainThread() && s_count;
-#endif
-    }
-
-#if !ASSERT_DISABLED
-
-private:
-    WEBCORE_EXPORT static unsigned s_count;
-
-#endif
-};
-
 class ContainerNode : public Node {
 public:
     virtual ~ContainerNode();

Modified: trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "ContainerNodeAlgorithms.h"
 
+#include "NoEventDispatchAssertion.h"
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/dom/Document.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/Document.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -116,6 +116,7 @@
 #include "MutationEvent.h"
 #include "NameNodeList.h"
 #include "NestingLevelIncrementer.h"
+#include "NoEventDispatchAssertion.h"
 #include "NodeIterator.h"
 #include "NodeRareData.h"
 #include "NodeWithIndex.h"

Modified: trunk/Source/WebCore/dom/Element.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/Element.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -66,6 +66,7 @@
 #include "MainFrame.h"
 #include "MutationObserverInterestGroup.h"
 #include "MutationRecord.h"
+#include "NoEventDispatchAssertion.h"
 #include "NodeRenderStyle.h"
 #include "PlatformWheelEvent.h"
 #include "PointerLockController.h"

Modified: trunk/Source/WebCore/dom/ElementIteratorAssertions.h (199002 => 199003)


--- trunk/Source/WebCore/dom/ElementIteratorAssertions.h	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/ElementIteratorAssertions.h	2016-04-04 12:56:33 UTC (rev 199003)
@@ -27,6 +27,7 @@
 #define ElementIteratorAssertions_h
 
 #include "Element.h"
+#include "NoEventDispatchAssertion.h"
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/dom/EventDispatcher.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/EventDispatcher.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/EventDispatcher.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -31,6 +31,7 @@
 #include "FrameView.h"
 #include "HTMLInputElement.h"
 #include "MouseEvent.h"
+#include "NoEventDispatchAssertion.h"
 #include "PseudoElement.h"
 #include "ScopedEventQueue.h"
 #include "ShadowRoot.h"

Modified: trunk/Source/WebCore/dom/EventTarget.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/EventTarget.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/EventTarget.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -34,6 +34,7 @@
 
 #include "ExceptionCode.h"
 #include "InspectorInstrumentation.h"
+#include "NoEventDispatchAssertion.h"
 #include "ScriptController.h"
 #include "WebKitAnimationEvent.h"
 #include "WebKitTransitionEvent.h"

Added: trunk/Source/WebCore/dom/NoEventDispatchAssertion.h (0 => 199003)


--- trunk/Source/WebCore/dom/NoEventDispatchAssertion.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/NoEventDispatchAssertion.h	2016-04-04 12:56:33 UTC (rev 199003)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 1999 Lars Knoll ([email protected])
+ *           (C) 1999 Antti Koivisto ([email protected])
+ *           (C) 2001 Dirk Mueller ([email protected])
+ * Copyright (C) 2004-2016 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef NoEventDispatchAssertion_h
+#define NoEventDispatchAssertion_h
+
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+class NoEventDispatchAssertion {
+public:
+    NoEventDispatchAssertion()
+    {
+#if !ASSERT_DISABLED
+        if (!isMainThread())
+            return;
+        ++s_count;
+#endif
+    }
+
+    NoEventDispatchAssertion(const NoEventDispatchAssertion&)
+        : NoEventDispatchAssertion()
+    {
+    }
+
+    ~NoEventDispatchAssertion()
+    {
+#if !ASSERT_DISABLED
+        if (!isMainThread())
+            return;
+        ASSERT(s_count);
+        s_count--;
+#endif
+    }
+
+    static bool isEventDispatchForbidden()
+    {
+#if ASSERT_DISABLED
+        return false;
+#else
+        return isMainThread() && s_count;
+#endif
+    }
+
+    static unsigned dropTemporarily()
+    {
+#if ASSERT_DISABLED
+        return 0;
+#else
+        unsigned count = s_count;
+        s_count = 0;
+        return count;
+#endif
+    }
+
+    static void restoreDropped(unsigned count)
+    {
+#if ASSERT_DISABLED
+        UNUSED_PARAM(count);
+#else
+        ASSERT(!s_count);
+        s_count = count;
+#endif
+    }
+
+#if !ASSERT_DISABLED
+private:
+    WEBCORE_EXPORT static unsigned s_count;
+#endif
+};
+
+}
+
+#endif

Modified: trunk/Source/WebCore/dom/Node.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/Node.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/Node.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -51,6 +51,7 @@
 #include "KeyboardEvent.h"
 #include "Logging.h"
 #include "MutationEvent.h"
+#include "NoEventDispatchAssertion.h"
 #include "NodeOrString.h"
 #include "NodeRenderStyle.h"
 #include "ProcessingInstruction.h"

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -34,6 +34,7 @@
 #include "Document.h"
 #include "ErrorEvent.h"
 #include "MessagePort.h"
+#include "NoEventDispatchAssertion.h"
 #include "PublicURLManager.h"
 #include "Settings.h"
 #include "WorkerGlobalScope.h"

Modified: trunk/Source/WebCore/dom/WebKitNamedFlow.cpp (199002 => 199003)


--- trunk/Source/WebCore/dom/WebKitNamedFlow.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/dom/WebKitNamedFlow.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -31,6 +31,7 @@
 #include "WebKitNamedFlow.h"
 
 #include "NamedFlowCollection.h"
+#include "NoEventDispatchAssertion.h"
 #include "RenderNamedFlowFragment.h"
 #include "RenderNamedFlowThread.h"
 #include "RenderRegion.h"

Modified: trunk/Source/WebCore/history/PageCache.cpp (199002 => 199003)


--- trunk/Source/WebCore/history/PageCache.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/history/PageCache.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -46,6 +46,7 @@
 #include "Logging.h"
 #include "MainFrame.h"
 #include "MemoryPressureHandler.h"
+#include "NoEventDispatchAssertion.h"
 #include "Page.h"
 #include "Settings.h"
 #include "SubframeLoader.h"

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (199002 => 199003)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -68,6 +68,7 @@
 #include "MediaResourceLoader.h"
 #include "MemoryPressureHandler.h"
 #include "NetworkingContext.h"
+#include "NoEventDispatchAssertion.h"
 #include "PageGroup.h"
 #include "PageThrottler.h"
 #include "PlatformMediaSessionManager.h"

Modified: trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp (199002 => 199003)


--- trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -31,6 +31,7 @@
 
 #include "FontDescription.h"
 #include "FontPlatformData.h"
+#include "NoEventDispatchAssertion.h"
 #include "SVGDocument.h"
 #include "SVGFontElement.h"
 #include "SVGFontFaceElement.h"
@@ -64,9 +65,16 @@
 bool CachedSVGFont::ensureCustomFontData(const AtomicString& remoteURI)
 {
     if (!m_externalSVGDocument && !errorOccurred() && !isLoading() && m_data) {
+        // We may get here during render tree updates when events are forbidden.
+        // Frameless document can't run scripts or call back to the client so this is safe.
+        auto count = NoEventDispatchAssertion::dropTemporarily();
+
         m_externalSVGDocument = SVGDocument::create(nullptr, URL());
         RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("application/xml");
         m_externalSVGDocument->setContent(decoder->decodeAndFlush(m_data->data(), m_data->size()));
+
+        NoEventDispatchAssertion::restoreDropped(count);
+
         if (decoder->sawError())
             m_externalSVGDocument = nullptr;
         if (m_externalSVGDocument)

Modified: trunk/Source/WebCore/style/RenderTreeUpdater.cpp (199002 => 199003)


--- trunk/Source/WebCore/style/RenderTreeUpdater.cpp	2016-04-04 10:26:28 UTC (rev 199002)
+++ trunk/Source/WebCore/style/RenderTreeUpdater.cpp	2016-04-04 12:56:33 UTC (rev 199003)
@@ -109,9 +109,6 @@
     auto it = descendants.begin();
     auto end = descendants.end();
 
-    // FIXME: SVG <use> element may cause tree mutations during style recalc.
-    it.dropAssertions();
-
     while (it != end) {
         popParentsToDepth(it.depth());
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to