Get rid of ref-counting on RenderWidget.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Sep 2013 07:27:52 +0000 (07:27 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Sep 2013 07:27:52 +0000 (07:27 +0000)
commitd64157a512a08ac278bbf38cb0ac3b65b476c960
treefcd25c7daccdb0cc1a4b2129bac7f80a275e8eb8
parent36ee9fe6b6070547aef13380a590f5398a7fdfbd
Get rid of ref-counting on RenderWidget.
<https://webkit.org/b/121357>

Reviewed by Darin Adler.

Source/WebCore:

Instead of RenderView tracking RenderWidgets, have FrameView track Widgets
that are currently in the render tree.

To protect ourselves during NPAPI tomfoolery, we now let RenderWidget hand
out weak pointers through a createWeakPtr() method so call sites can monitor
the renderer for deletion without having to take shared ownership.

This works out quite nicely since instead of keeping a limping object alive
for a little longer just so we can call methods on it (to accomplish nothing),
we're forced to check right away if it's gone, and take immediate action.

De-virtualized RenderObject::destroy() since it's no longer needed for
RenderWidget to defer destruction.

* page/FrameView.cpp:
(WebCore::FrameView::layout):
(WebCore::FrameView::repaintFixedElementsAfterScrolling):

    Call updateWidgetPositions() on FrameView instead of RenderView.

(WebCore::FrameView::updateEmbeddedObject):

    Turn null checking of embedded object's element backpointer into an
    assertion. This will eventually go away completely once that renderer
    can return a HTMLFrameOwnerElement&.

    Use WeakPtr to check for renderer destruction following the call out
    to updateWidget().

(WebCore::FrameView::updateEmbeddedObjects):

    Slap a WidgetHierarchyUpdatesSuspensionScope guard on this function
    to defer Widget updates until all the updateEmbeddedObject calls are
    done. This avoids RenderWidget::setWidget() having to handle 'this'
    disappearing from underneath.

    Also use a ListHashSet with a null sentinel to avoid looping forever.

(WebCore::FrameView::performPostLayoutTasks):

    Only call updateEmbeddedObjects() once since that function no longer
    operates in chunks.

(WebCore::FrameView::notifyWidgetsInAllFrames):

    Call notifyWidgets() on FrameView instead of RenderView.

(WebCore::FrameView::didAddWidgetToRenderTree):
(WebCore::FrameView::willRemoveWidgetFromRenderTree):

    Added. These are called by RenderWidget when a Widget is being
    added or removed from a RenderWidget.

(WebCore::collectWidgets):

    Helper to collect raw Widget pointers into a Vector and ref them.

(WebCore::FrameView::updateWidgetPositions):

    Moved here from RenderView. This function holds a ref on all the
    attached Widgets and calls RenderWidget::updateWidgetPosition() on
    their corresponding renderers.

(WebCore::FrameView::notifyWidgets):

    Moved here from RenderView. Holds a ref on all the widgets while
    calling Widget::notifyWidget() on each one.

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollTo):

    Call updateWidgetPositions() on FrameView instead of RenderView.

* rendering/RenderObject.h:

    De-virtualized destroy().

* rendering/RenderView.cpp:
* rendering/RenderView.h:

    Moved a bunch of things to FrameView. Made protected section private
    since nothing inherits from RenderView.

* rendering/RenderWidget.h:
(WebCore::RenderWidget::createWeakPtr):

    Added a WeakPtr factory for clients that want to monitor this object
    for destruction.

* rendering/RenderWidget.cpp:
(WebCore::RenderWidget::RenderWidget):
(WebCore::RenderWidget::willBeDestroyed):
(WebCore::RenderWidget::~RenderWidget):

    Removed ref counting.
    Removed registration with RenderView in ctor/willBeDestroyed.

(WebCore::RenderWidget::setWidgetGeometry):

    Monitor the RenderWidget itself through a WeakPtr and check on it
    after each step that we're still alive. In that case just bail out.

(WebCore::RenderWidget::setWidget):

    Register the incoming/outgoing Widget with the FrameView.
    Use a WeakPtr to check on 'this' after updateWidgetGeometry().

(WebCore::RenderWidget::updateWidgetPosition):

    Use a WeakPtr to check on 'this' after updateWidgetGeometry().

* GNUmakefile.list.am:
* rendering/RenderWidgetProtector.h:

    Removed.

Source/WTF:

* wtf/WeakPtr.h:
(WTF::WeakPtr::operator!):

    Add operator! to WeakPtr.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155796 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/WeakPtr.h
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/RenderView.cpp
Source/WebCore/rendering/RenderView.h
Source/WebCore/rendering/RenderWidget.cpp
Source/WebCore/rendering/RenderWidget.h
Source/WebCore/rendering/RenderWidgetProtector.h [deleted file]