Changeset 224356 in webkit


Ignore:
Timestamp:
Nov 2, 2017 2:56:30 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Eliminate isMainThread() checks in most call sites of NoEventDispatchAssertion
https://bugs.webkit.org/show_bug.cgi?id=179161

Reviewed by Zalan Bujtas.

Introduced NoEventDispatchAssertion::InMainThread which bypasses the expensive isMainThread() check
in order to turn NoEventDispatchAssertion into a release assertion in a separate patch.

Also removed instances of NoEventDispatchAssertion in notifyChildNodeInserted and notifyChildNodeRemoved
and asserted that the caller has instantiated NoEventDispatchAssertion instead.

No new tests since there should be no behavioral changes.

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::canExecuteScripts):

  • dom/Attr.cpp:
  • dom/CharacterData.cpp:
  • dom/ContainerNode.cpp:

(WebCore::ContainerNode::removeAllChildrenWithScriptAssertion):
(WebCore::ContainerNode::removeNodeWithScriptAssertion):
(WebCore::executeNodeInsertionWithScriptAssertion):
(WebCore::ContainerNode::removeDetachedChildren): Instantiated NoEventDispatchAssertion::InMainThread
so that notifyChildNodeRemoved would be called inside NoEventDispatchAssertion.
(WebCore::ContainerNode::insertBeforeCommon):
(WebCore::ContainerNode::appendChildCommon):
(WebCore::ContainerNode::removeBetween):
(WebCore::dispatchChildInsertionEvents):
(WebCore::dispatchChildRemovalEvents):

  • dom/ContainerNodeAlgorithms.cpp:

(WebCore::notifyChildNodeInserted): Assert that the caller has instantiated NoEventDispatchAssertion.
(WebCore::notifyChildNodeRemoved): Ditto.

  • dom/Document.cpp:

(WebCore::Document::resolveStyle):
(WebCore::Document::updateStyleIfNeeded):
(WebCore::Document::nodeChildrenWillBeRemoved):
(WebCore::Document::nodeWillBeRemoved):
(WebCore::Document::dispatchWindowEvent): Replaced RELEASE_ASSERT with ASSERT_WITH_SECURITY_IMPLICATION
for clarity since NoEventDispatchAssertion::isEventAllowedInMainThread() always returns true in release
builds right now.
(WebCore::Document::dispatchWindowLoadEvent): Ditto.
(WebCore::Document::applyPendingXSLTransformsTimerFired): Use ASSERT_WITH_SECURITY_IMPLICATION instead
of regular ASSERT.

  • dom/Element.cpp:

(WebCore::Element::addShadowRoot): Instantiate NoEventDispatchAssertion::InMainThread to call
notifyChildNodeInserted will it.
(WebCore::Element::attachAttributeNodeIfNeeded):
(WebCore::Element::setAttributeNode): Fixed the indentation.
(WebCore::Element::setAttributeNodeNS): Ditto.
(WebCore::Element::dispatchFocusInEvent):
(WebCore::Element::dispatchFocusOutEvent):

  • dom/EventDispatcher.cpp:

(WebCore::EventDispatcher::dispatchEvent):

  • dom/NoEventDispatchAssertion.h:

(WebCore::NoEventDispatchAssertion::isEventDispatchAllowedInSubtree): Moved to InMainThread.
(WebCore::NoEventDispatchAssertion::InMainThread): Added.
(WebCore::NoEventDispatchAssertion::InMainThread::InMainThread): Assert that we're in the main thread
instead of exiting early.
(WebCore::NoEventDispatchAssertion::InMainThread::~InMainThread): Ditto.
(WebCore::NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree): Moved here.
(WebCore::NoEventDispatchAssertion::InMainThread::isEventAllowed):

  • dom/Node.cpp:

(WebCore::Node::dispatchSubtreeModifiedEvent):
(WebCore::Node::dispatchDOMActivateEvent):

  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::canSuspendActiveDOMObjectsForDocumentSuspension):
(WebCore::ScriptExecutionContext::suspendActiveDOMObjects):
(WebCore::ScriptExecutionContext::resumeActiveDOMObjects):

  • history/CachedPage.cpp:

(WebCore::CachedPage::restore):

  • history/PageCache.cpp:

(WebCore::PageCache::addIfCacheable):

  • page/LayoutContext.cpp:

(WebCore::LayoutContext::layout):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::scrollRectToVisible):

Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r224353 r224356  
     12017-11-02  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Eliminate isMainThread() checks in most call sites of NoEventDispatchAssertion
     4        https://bugs.webkit.org/show_bug.cgi?id=179161
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Introduced NoEventDispatchAssertion::InMainThread which bypasses the expensive isMainThread() check
     9        in order to turn NoEventDispatchAssertion into a release assertion in a separate patch.
     10
     11        Also removed instances of NoEventDispatchAssertion in notifyChildNodeInserted and notifyChildNodeRemoved
     12        and asserted that the caller has instantiated NoEventDispatchAssertion instead.
     13
     14        No new tests since there should be no behavioral changes.
     15
     16        * bindings/js/ScriptController.cpp:
     17        (WebCore::ScriptController::canExecuteScripts):
     18        * dom/Attr.cpp:
     19        * dom/CharacterData.cpp:
     20        * dom/ContainerNode.cpp:
     21        (WebCore::ContainerNode::removeAllChildrenWithScriptAssertion):
     22        (WebCore::ContainerNode::removeNodeWithScriptAssertion):
     23        (WebCore::executeNodeInsertionWithScriptAssertion):
     24        (WebCore::ContainerNode::removeDetachedChildren): Instantiated NoEventDispatchAssertion::InMainThread
     25        so that notifyChildNodeRemoved would be called inside NoEventDispatchAssertion.
     26        (WebCore::ContainerNode::insertBeforeCommon):
     27        (WebCore::ContainerNode::appendChildCommon):
     28        (WebCore::ContainerNode::removeBetween):
     29        (WebCore::dispatchChildInsertionEvents):
     30        (WebCore::dispatchChildRemovalEvents):
     31        * dom/ContainerNodeAlgorithms.cpp:
     32        (WebCore::notifyChildNodeInserted): Assert that the caller has instantiated NoEventDispatchAssertion.
     33        (WebCore::notifyChildNodeRemoved): Ditto.
     34        * dom/Document.cpp:
     35        (WebCore::Document::resolveStyle):
     36        (WebCore::Document::updateStyleIfNeeded):
     37        (WebCore::Document::nodeChildrenWillBeRemoved):
     38        (WebCore::Document::nodeWillBeRemoved):
     39        (WebCore::Document::dispatchWindowEvent): Replaced RELEASE_ASSERT with ASSERT_WITH_SECURITY_IMPLICATION
     40        for clarity since NoEventDispatchAssertion::isEventAllowedInMainThread() always returns true in release
     41        builds right now.
     42        (WebCore::Document::dispatchWindowLoadEvent): Ditto.
     43        (WebCore::Document::applyPendingXSLTransformsTimerFired): Use ASSERT_WITH_SECURITY_IMPLICATION instead
     44        of regular ASSERT.
     45        * dom/Element.cpp:
     46        (WebCore::Element::addShadowRoot): Instantiate NoEventDispatchAssertion::InMainThread to call
     47        notifyChildNodeInserted will it.
     48        (WebCore::Element::attachAttributeNodeIfNeeded):
     49        (WebCore::Element::setAttributeNode): Fixed the indentation.
     50        (WebCore::Element::setAttributeNodeNS): Ditto.
     51        (WebCore::Element::dispatchFocusInEvent):
     52        (WebCore::Element::dispatchFocusOutEvent):
     53        * dom/EventDispatcher.cpp:
     54        (WebCore::EventDispatcher::dispatchEvent):
     55        * dom/NoEventDispatchAssertion.h:
     56        (WebCore::NoEventDispatchAssertion::isEventDispatchAllowedInSubtree): Moved to InMainThread.
     57        (WebCore::NoEventDispatchAssertion::InMainThread): Added.
     58        (WebCore::NoEventDispatchAssertion::InMainThread::InMainThread): Assert that we're in the main thread
     59        instead of exiting early.
     60        (WebCore::NoEventDispatchAssertion::InMainThread::~InMainThread): Ditto.
     61        (WebCore::NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree): Moved here.
     62        (WebCore::NoEventDispatchAssertion::InMainThread::isEventAllowed):
     63        * dom/Node.cpp:
     64        (WebCore::Node::dispatchSubtreeModifiedEvent):
     65        (WebCore::Node::dispatchDOMActivateEvent):
     66        * dom/ScriptExecutionContext.cpp:
     67        (WebCore::ScriptExecutionContext::canSuspendActiveDOMObjectsForDocumentSuspension):
     68        (WebCore::ScriptExecutionContext::suspendActiveDOMObjects):
     69        (WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
     70        * history/CachedPage.cpp:
     71        (WebCore::CachedPage::restore):
     72        * history/PageCache.cpp:
     73        (WebCore::PageCache::addIfCacheable):
     74        * page/LayoutContext.cpp:
     75        (WebCore::LayoutContext::layout):
     76        * rendering/RenderLayer.cpp:
     77        (WebCore::RenderLayer::scrollRectToVisible):
     78
    1792017-11-02  John Wilander  <wilander@apple.com>
    280
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r224290 r224356  
    679679{
    680680    if (reason == AboutToExecuteScript)
    681         ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventAllowedInMainThread());
     681        ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    682682
    683683    if (m_frame.document() && m_frame.document()->isSandboxed(SandboxScripts)) {
  • trunk/Source/WebCore/dom/Attr.cpp

    r219856 r224356  
    2626#include "AttributeChangeInvalidation.h"
    2727#include "Event.h"
    28 #include "NoEventDispatchAssertion.h"
    2928#include "ScopedEventQueue.h"
    3029#include "StyleProperties.h"
  • trunk/Source/WebCore/dom/CharacterData.cpp

    r223687 r224356  
    3131#include "MutationObserverInterestGroup.h"
    3232#include "MutationRecord.h"
    33 #include "NoEventDispatchAssertion.h"
    3433#include "ProcessingInstruction.h"
    3534#include "RenderText.h"
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r223788 r224356  
    9090    } else {
    9191        ASSERT(source == ContainerNode::ChildChangeSource::Parser);
    92         NoEventDispatchAssertion assertNoEventDispatch;
     92        NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    9393        if (UNLIKELY(document().hasMutationObserversOfType(MutationObserver::ChildList))) {
    9494            ChildListMutationScope mutation(*this);
     
    101101
    102102    WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
    103     NoEventDispatchAssertion assertNoEventDispatch;
     103    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    104104
    105105    document().nodeChildrenWillBeRemoved(*this);
     
    121121    ASSERT_WITH_SECURITY_IMPLICATION(childToRemove.parentNode() == this);
    122122    {
    123         NoEventDispatchAssertion assertNoEventDispatch;
     123        NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    124124        ChildListMutationScope(*this).willRemoveChild(childToRemove);
    125125    }
    126126
    127     ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventDispatchAllowedInSubtree(childToRemove));
     127    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree(childToRemove));
    128128    if (source == ContainerNode::ChildChangeSource::API) {
    129129        childToRemove.notifyMutationObserversNodeWillDetach();
     
    145145
    146146    WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
    147     NoEventDispatchAssertion assertNoEventDispatch;
     147    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    148148
    149149    document().nodeWillBeRemoved(childToRemove);
     
    175175    NodeVector postInsertionNotificationTargets;
    176176    {
    177         NoEventDispatchAssertion assertNoEventDispatch;
     177        NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    178178        doNodeInsertion();
    179179        ChildListMutationScope(containerNode).childAdded(child);
     
    193193    }
    194194
    195     ASSERT(NoEventDispatchAssertion::isEventDispatchAllowedInSubtree(child));
     195    ASSERT(NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree(child));
    196196    for (auto& target : postInsertionNotificationTargets)
    197197        target->didFinishInsertingNode();
     
    226226    }
    227227    // FIXME: We should be able to ASSERT(!attached()) here: https://bugs.webkit.org/show_bug.cgi?id=107801
     228    NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
    228229    removeDetachedChildrenInContainer(*this);
    229230}
     
    400401void ContainerNode::insertBeforeCommon(Node& nextChild, Node& newChild)
    401402{
    402     NoEventDispatchAssertion assertNoEventDispatch;
     403    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    403404
    404405    ASSERT(!newChild.parentNode()); // Use insertBefore if you need to handle reparenting (and want DOM mutation events).
     
    425426void ContainerNode::appendChildCommon(Node& child)
    426427{
    427     NoEventDispatchAssertion assertNoEventDispatch;
     428    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    428429
    429430    child.setParentNode(this);
     
    564565    InspectorInstrumentation::didRemoveDOMNode(oldChild.document(), oldChild);
    565566
    566     NoEventDispatchAssertion assertNoEventDispatch;
     567    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    567568
    568569    ASSERT(oldChild.parentNode() == this);
     
    763764        return;
    764765
    765     ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventDispatchAllowedInSubtree(child));
     766    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree(child));
    766767
    767768    RefPtr<Node> c = &child;
     
    780781static void dispatchChildRemovalEvents(Ref<Node>& child)
    781782{
    782     ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventDispatchAllowedInSubtree(child));
     783    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree(child));
    783784    InspectorInstrumentation::willRemoveDOMNode(child->document(), child.get());
    784785
  • trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp

    r223802 r224356  
    8585NodeVector notifyChildNodeInserted(ContainerNode& parentOfInsertedTree, Node& node)
    8686{
    87     NoEventDispatchAssertion assertNoEventDispatch;
     87    ASSERT(!NoEventDispatchAssertion::InMainThread::isEventAllowed());
    8888
    8989    InspectorInstrumentation::didInsertDOMNode(node.document(), node);
     
    148148void notifyChildNodeRemoved(ContainerNode& oldParentOfRemovedTree, Node& child)
    149149{
    150     NoEventDispatchAssertion assertNoEventDispatch;
     150    // Assert that the caller of this function has an instance of NoEventDispatchAssertion.
     151    ASSERT(!isMainThread() || !NoEventDispatchAssertion::InMainThread::isEventAllowed());
    151152
    152153    // Tree scope has changed if the container node from which "node" is removed is in a document or a shadow root.
  • trunk/Source/WebCore/dom/Document.cpp

    r224320 r224356  
    17941794
    17951795    {
    1796         NoEventDispatchAssertion noEventDispatchAssertion;
     1796        NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
    17971797        styleScope().flushPendingUpdate();
    17981798        frameView.willRecalcStyle();
     
    18051805        Style::PostResolutionCallbackDisabler disabler(*this);
    18061806        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
    1807         NoEventDispatchAssertion noEventDispatchAssertion;
     1807        NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
    18081808
    18091809        m_inStyleRecalc = true;
     
    19251925{
    19261926    {
    1927         NoEventDispatchAssertion noEventDispatchAssertion;
     1927        NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
    19281928        ASSERT(isMainThread());
    19291929        ASSERT(!view() || !view()->isPainting());
     
    40864086void Document::nodeChildrenWillBeRemoved(ContainerNode& container)
    40874087{
    4088     NoEventDispatchAssertion assertNoEventDispatch;
     4088    ASSERT(!NoEventDispatchAssertion::InMainThread::isEventAllowed());
    40894089
    40904090    removeFocusedNodeOfSubtree(container, true /* amongChildrenOnly */);
     
    41194119void Document::nodeWillBeRemoved(Node& node)
    41204120{
    4121     NoEventDispatchAssertion assertNoEventDispatch;
     4121    ASSERT(!NoEventDispatchAssertion::InMainThread::isEventAllowed());
    41224122
    41234123    removeFocusedNodeOfSubtree(node);
     
    42634263void Document::dispatchWindowEvent(Event& event, EventTarget* target)
    42644264{
    4265     RELEASE_ASSERT(NoEventDispatchAssertion::isEventAllowedInMainThread());
     4265    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    42664266    if (!m_domWindow)
    42674267        return;
     
    42714271void Document::dispatchWindowLoadEvent()
    42724272{
    4273     RELEASE_ASSERT(NoEventDispatchAssertion::isEventAllowedInMainThread());
     4273    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    42744274    if (!m_domWindow)
    42754275        return;
     
    51015101
    51025102    m_hasPendingXSLTransforms = false;
    5103     ASSERT(NoEventDispatchAssertion::isEventAllowedInMainThread());
     5103    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    51045104    for (auto& processingInstruction : styleScope().collectXSLTransforms()) {
    51055105        ASSERT(processingInstruction->isXSL());
  • trunk/Source/WebCore/dom/Element.cpp

    r224320 r224356  
    17721772    ASSERT(!newShadowRoot->hasChildNodes());
    17731773    ASSERT(!shadowRoot());
    1774    
    1775     if (renderer())
    1776         RenderTreeUpdater::tearDownRenderers(*this);
    17771774
    17781775    ShadowRoot& shadowRoot = newShadowRoot;
    1779     ensureElementRareData().setShadowRoot(WTFMove(newShadowRoot));
    1780 
    1781     shadowRoot.setHost(this);
    1782     shadowRoot.setParentTreeScope(treeScope());
     1776    {
     1777        NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
     1778        if (renderer())
     1779            RenderTreeUpdater::tearDownRenderers(*this);
     1780
     1781        ensureElementRareData().setShadowRoot(WTFMove(newShadowRoot));
     1782
     1783        shadowRoot.setHost(this);
     1784        shadowRoot.setParentTreeScope(treeScope());
    17831785
    17841786#if !ASSERT_DISABLED
    1785     ASSERT(notifyChildNodeInserted(*this, shadowRoot).isEmpty());
     1787        ASSERT(notifyChildNodeInserted(*this, shadowRoot).isEmpty());
    17861788#else
    1787     notifyChildNodeInserted(*this, shadowRoot);
     1789        notifyChildNodeInserted(*this, shadowRoot);
    17881790#endif
    17891791
    1790     invalidateStyleAndRenderersForSubtree();
    1791 
    1792     InspectorInstrumentation::didPushShadowRoot(*this, shadowRoot);
     1792        invalidateStyleAndRenderersForSubtree();
     1793    }
    17931794
    17941795    if (shadowRoot.mode() == ShadowRootMode::UserAgent)
    17951796        didAddUserAgentShadowRoot(shadowRoot);
     1797
     1798    InspectorInstrumentation::didPushShadowRoot(*this, shadowRoot);
    17961799}
    17971800
     
    21472150        return;
    21482151
    2149     NoEventDispatchAssertion assertNoEventDispatch;
     2152    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    21502153
    21512154    attrNode.attachToElement(*this);
     
    21652168
    21662169    {
    2167     NoEventDispatchAssertion assertNoEventDispatch;
    2168     synchronizeAllAttributes();
     2170        NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
     2171        synchronizeAllAttributes();
    21692172    }
    21702173
     
    22112214        return Exception { InUseAttributeError };
    22122215
    2213     unsigned index = 0;
    2214    
    22152216    // Attr::value() will return its 'm_standaloneValue' member any time its Element is set to nullptr. We need to cache this value
    22162217    // before making changes to attrNode's Element connections.
    22172218    auto attrNodeValue = attrNode.value();
    2218 
     2219    unsigned index = 0;
    22192220    {
    2220     NoEventDispatchAssertion assertNoEventDispatch;
    2221     synchronizeAllAttributes();
    2222     auto& elementData = ensureUniqueElementData();
    2223 
    2224     index = elementData.findAttributeIndexByName(attrNode.qualifiedName());
    2225 
    2226     if (index != ElementData::attributeNotFound) {
    2227         if (oldAttrNode)
    2228             detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData.attributeAt(index).value());
    2229         else
    2230             oldAttrNode = Attr::create(document(), attrNode.qualifiedName(), elementData.attributeAt(index).value());
    2231     }
     2221        NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
     2222        synchronizeAllAttributes();
     2223        auto& elementData = ensureUniqueElementData();
     2224
     2225        index = elementData.findAttributeIndexByName(attrNode.qualifiedName());
     2226
     2227        if (index != ElementData::attributeNotFound) {
     2228            if (oldAttrNode)
     2229                detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData.attributeAt(index).value());
     2230            else
     2231                oldAttrNode = Attr::create(document(), attrNode.qualifiedName(), elementData.attributeAt(index).value());
     2232        }
    22322233    }
    22332234
     
    24752476void Element::dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement)
    24762477{
    2477     ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventAllowedInMainThread());
     2478    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    24782479    ASSERT(eventType == eventNames().focusinEvent || eventType == eventNames().DOMFocusInEvent);
    24792480    dispatchScopedEvent(FocusEvent::create(eventType, true, false, document().defaultView(), 0, WTFMove(oldFocusedElement)));
     
    24822483void Element::dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement)
    24832484{
    2484     ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventAllowedInMainThread());
     2485    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    24852486    ASSERT(eventType == eventNames().focusoutEvent || eventType == eventNames().DOMFocusOutEvent);
    24862487    dispatchScopedEvent(FocusEvent::create(eventType, true, false, document().defaultView(), 0, WTFMove(newFocusedElement)));
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r224159 r224356  
    131131bool EventDispatcher::dispatchEvent(Node& node, Event& event)
    132132{
    133     ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::isEventDispatchAllowedInSubtree(node));
     133    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree(node));
    134134    Ref<Node> protectedNode(node);
    135135    RefPtr<FrameView> view = node.document().view();
  • trunk/Source/WebCore/dom/NoEventDispatchAssertion.h

    r215787 r224356  
    6464    }
    6565
    66     static bool isEventDispatchAllowedInSubtree(Node& node)
    67     {
    68         return isEventAllowedInMainThread() || EventAllowedScope::isAllowedNode(node);
    69     }
     66    class InMainThread {
     67    public:
     68        InMainThread()
     69        {
     70            ASSERT(isMainThread());
     71#if !ASSERT_DISABLED
     72            ++s_count;
     73#endif
     74        }
    7075
     76        ~InMainThread()
     77        {
     78            ASSERT(isMainThread());
     79#if !ASSERT_DISABLED
     80            ASSERT(s_count);
     81            --s_count;
     82#endif
     83        }
     84
     85        static bool isEventDispatchAllowedInSubtree(Node& node)
     86        {
     87            return isEventAllowed() || EventAllowedScope::isAllowedNode(node);
     88        }
     89
     90        static bool isEventAllowed()
     91        {
     92            ASSERT(isMainThread());
     93#if !ASSERT_DISABLED
     94            return !s_count;
     95#else
     96            return true;
     97#endif
     98        }
     99    };
     100   
    71101#if !ASSERT_DISABLED
    72102    class EventAllowedScope {
  • trunk/Source/WebCore/dom/Node.cpp

    r224325 r224356  
    23272327        return;
    23282328
    2329     RELEASE_ASSERT(NoEventDispatchAssertion::isEventDispatchAllowedInSubtree(*this));
     2329    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventDispatchAllowedInSubtree(*this));
    23302330
    23312331    if (!document().hasListenerType(Document::DOMSUBTREEMODIFIED_LISTENER))
     
    23402340bool Node::dispatchDOMActivateEvent(int detail, Event& underlyingEvent)
    23412341{
    2342     RELEASE_ASSERT(NoEventDispatchAssertion::isEventAllowedInMainThread());
     2342    ASSERT_WITH_SECURITY_IMPLICATION(NoEventDispatchAssertion::InMainThread::isEventAllowed());
    23432343    Ref<UIEvent> event = UIEvent::create(eventNames().DOMActivateEvent, true, true, document().defaultView(), detail);
    23442344    event->setUnderlyingEvent(&underlyingEvent);
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r224218 r224356  
    191191    // An ASSERT_WITH_SECURITY_IMPLICATION or RELEASE_ASSERT will fire if this happens, but it's important to code
    192192    // canSuspend functions so it will not happen!
    193     NoEventDispatchAssertion assertNoEventDispatch;
     193    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    194194    for (auto* activeDOMObject : m_activeDOMObjects) {
    195195        if (!activeDOMObject->canSuspendForDocumentSuspension()) {
     
    233233    // An ASSERT_WITH_SECURITY_IMPLICATION or RELEASE_ASSERT will fire if this happens, but it's important to code
    234234    // suspend functions so it will not happen!
    235     NoEventDispatchAssertion assertNoEventDispatch;
     235    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    236236    for (auto* activeDOMObject : m_activeDOMObjects)
    237237        activeDOMObject->suspend(why);
     
    262262    // An ASSERT_WITH_SECURITY_IMPLICATION or RELEASE_ASSERT will fire if this happens, but it's important to code
    263263    // resume functions so it will not happen!
    264     NoEventDispatchAssertion assertNoEventDispatch;
     264    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    265265    for (auto* activeDOMObject : m_activeDOMObjects)
    266266        activeDOMObject->resume();
  • trunk/Source/WebCore/history/CachedPage.cpp

    r223476 r224356  
    109109        // Do not dispatch DOM events as their JavaScript listeners could cause the page to be put
    110110        // into the page cache before we have finished restoring it from the page cache.
    111         NoEventDispatchAssertion noEventDispatchAssertion;
     111        NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
    112112
    113113        m_cachedMainFrame->open();
  • trunk/Source/WebCore/history/PageCache.cpp

    r220734 r224356  
    424424
    425425    // Make sure we no longer fire any JS events past this point.
    426     NoEventDispatchAssertion assertNoEventDispatch;
     426    NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    427427
    428428    item.m_cachedPage = std::make_unique<CachedPage>(*page);
  • trunk/Source/WebCore/page/LayoutContext.cpp

    r224225 r224356  
    212212    {
    213213        SetForScope<LayoutPhase> layoutPhase(m_layoutPhase, LayoutPhase::InRenderTreeLayout);
    214         NoEventDispatchAssertion noEventDispatchAssertion;
     214        NoEventDispatchAssertion::InMainThread noEventDispatchAssertion;
    215215        SubtreeLayoutStateMaintainer subtreeLayoutStateMaintainer(subtreeLayoutRoot());
    216216        RenderView::RepaintRegionAccumulator repaintRegionAccumulator(renderView());
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r224265 r224356  
    25272527            if (frameElementAndViewPermitScroll(frameElementBase, frameView)) {
    25282528                // If this assertion fires we need to protect the ownerElement from being destroyed.
    2529                 NoEventDispatchAssertion assertNoEventDispatch;
     2529                NoEventDispatchAssertion::InMainThread assertNoEventDispatch;
    25302530
    25312531                LayoutRect viewRect = frameView.visibleContentRect(LegacyIOSDocumentVisibleRect);
Note: See TracChangeset for help on using the changeset viewer.