Source/core/dom/ContainerNode.cpp
// this differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
this differs from other remove functions because it forcibly removes all the children,
regardless of read-only status or event exceptions, e.g.
this differs from other remove functions because it forcibly removes all the children regardless of read - only status or event exceptions e . g .
void ContainerNode::removeChildren()
{
    if (!m_firstChild)
        return;
    RefPtrWillBeRawPtr<ContainerNode> protect(this);
    if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(document()))
        fullscreen->removeFullScreenElementOfSubtree(this, true);
    willRemoveChildren();
    {
        SubframeLoadingDisabler disabler(*this);
        document().removeFocusedElementOfSubtree(this, true);
        document().nodeChildrenWillBeRemoved(*this);
    }
    NodeVector removedChildren;
    {
        HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates;
        {
            NoEventDispatchAssertion assertNoEventDispatch;
            ScriptForbiddenScope forbidScript;
            removedChildren.reserveInitialCapacity(countChildren());
            while (RefPtrWillBeRawPtr<Node> child = m_firstChild) {
                removeBetween(0, child->nextSibling(), *child);
                removedChildren.append(child.get());
                notifyNodeRemoved(*child);
            }
        }
        childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size()));
    }
    dispatchSubtreeModifiedEvent();
}
void ContainerNode :: removeChildren ( ) { if ( ! m_firstChild ) return ; RefPtrWillBeRawPtr < ContainerNode > protect ( this ) ; if ( FullscreenElementStack * fullscreen = FullscreenElementStack :: fromIfExists ( document ( ) ) ) fullscreen -> removeFullScreenElementOfSubtree ( this , true ) ; willRemoveChildren ( ) ; { SubframeLoadingDisabler disabler ( * this ) ; document ( ) . removeFocusedElementOfSubtree ( this , true ) ; document ( ) . nodeChildrenWillBeRemoved ( * this ) ; } NodeVector removedChildren ; { HTMLFrameOwnerElement :: UpdateSuspendScope suspendWidgetHierarchyUpdates ; { NoEventDispatchAssertion assertNoEventDispatch ; ScriptForbiddenScope forbidScript ; removedChildren . reserveInitialCapacity ( countChildren ( ) ) ; while ( RefPtrWillBeRawPtr < Node > child = m_firstChild ) { removeBetween ( 0 , child -> nextSibling ( ) , * child ) ; removedChildren . append ( child . get ( ) ) ; notifyNodeRemoved ( * child ) ; } } childrenChanged ( false , 0 , 0 , - static_cast < int > ( removedChildren . size ( ) ) ) ; } dispatchSubtreeModifiedEvent ( ) ; }
this differs from other remove functions because it forcibly removes all the children,
regardless of read-only status or event exceptions, e.g.
this differs from other remove functions because it forcibly removes all the children regardless of read - only status or event exceptions e . g .
// The container node can be removed from event handlers. // Do any prep work needed before actually starting to detach // and remove... e.g. stop loading frames, fire unload events. // Removing focus can cause frames to load, either via events (focusout, blur) // or widget updates (e.g., for <embed>). // Exclude this node when looking for removed focusedElement since only // children will be removed. // This must be later than willRemoveChildren, which might change focus // state of a child. // Removing a node from a selection can cause widget updates. // FIXME: Remove this NodeVector. Right now WebPluginContainerImpl::m_element is a // raw ptr which means the code below can drop the last ref to a plugin element and // then the code in UpdateSuspendScope::performDeferredWidgetTreeOperations will // try to destroy the plugin which will be a use-after-free. We should use a RefPtr // in the WebPluginContainerImpl instead.