Source/WebCore: Improve handling of frame removal during requestAnimationFrame callback invocation
https://bugs.webkit.org/show_bug.cgi?id=74036

Reviewed by Adam Barth.

See bug for details.

Test: fast/animation/request-animation-frame-detach-element.html

* dom/Document.cpp:
(WebCore::Document::removedLastRef):
(WebCore::Document::detach):
* dom/Document.h:
* dom/ScriptedAnimationController.cpp:
(WebCore::ScriptedAnimationController::~ScriptedAnimationController):
(WebCore::ScriptedAnimationController::serviceScriptedAnimations):
(WebCore::ScriptedAnimationController::scheduleAnimation):
* dom/ScriptedAnimationController.h:
(WebCore::ScriptedAnimationController::create):
(WebCore::ScriptedAnimationController::clearDocumentPointer):
* page/FrameView.cpp:
(WebCore::FrameView::serviceScriptedAnimations):

LayoutTests: Add some tests for removing frames from the document while servicing requestAnimationFrame callbacks
https://bugs.webkit.org/show_bug.cgi?id=74036

Reviewed by Adam Barth.

* fast/animation/request-animation-frame-detach-element-expected.txt: Added.
* fast/animation/request-animation-frame-detach-element.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@102405 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/ScriptedAnimationController.h b/Source/WebCore/dom/ScriptedAnimationController.h
index dfdd503..d2c9c0c 100644
--- a/Source/WebCore/dom/ScriptedAnimationController.h
+++ b/Source/WebCore/dom/ScriptedAnimationController.h
@@ -35,8 +35,7 @@
 #include "Timer.h"
 #endif
 #include "PlatformScreen.h"
-#include <wtf/Noncopyable.h>
-#include <wtf/PassOwnPtr.h>
+#include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 
@@ -46,17 +45,18 @@
 class Element;
 class RequestAnimationFrameCallback;
 
-class ScriptedAnimationController
+class ScriptedAnimationController : public RefCounted<ScriptedAnimationController>
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
-    : public DisplayRefreshMonitorClient
+    , public DisplayRefreshMonitorClient
 #endif
 {
-WTF_MAKE_NONCOPYABLE(ScriptedAnimationController);
 public:
-    static PassOwnPtr<ScriptedAnimationController> create(Document* document, PlatformDisplayID displayID)
+    static PassRefPtr<ScriptedAnimationController> create(Document* document, PlatformDisplayID displayID)
     {
-        return adoptPtr(new ScriptedAnimationController(document, displayID));
+        return adoptRef(new ScriptedAnimationController(document, displayID));
     }
+    ~ScriptedAnimationController();
+    void clearDocumentPointer() { m_document = 0; }
 
     typedef int CallbackId;
 
@@ -70,7 +70,7 @@
     void windowScreenDidChange(PlatformDisplayID);
 
 private:
-    explicit ScriptedAnimationController(Document*, PlatformDisplayID);
+    ScriptedAnimationController(Document*, PlatformDisplayID);
     
     typedef Vector<RefPtr<RequestAnimationFrameCallback> > CallbackList;
     CallbackList m_callbacks;