Title: [286642] trunk/Source/WebCore
Revision
286642
Author
[email protected]
Date
2021-12-07 22:28:55 -0800 (Tue, 07 Dec 2021)

Log Message

ActiveDOMObject::suspendIfNeeded() should not be called in the WebAnimation constructor
https://bugs.webkit.org/show_bug.cgi?id=233932

Reviewed by Chris Dumez.

It is not safe to call ActiveDOMObject::suspendIfNeeded() in a constructor. Since WebAnimation has several subclasses
(DeclarativeAnimation, and then CSSTransition and CSSAnimation deriving from DeclarativeAnimation) each with their own
create() methods, we add a new protected initialize() method which refactors code from the WebAnimation constructor
and is called from the two WebAnimation::create() methods.

DeclarativeAnimation already had an initialize method for common setup for the create() methods in CSSTransition and
CSS Animation, so we can simply call WebAnimation::initialize() from DeclarativeAnimation::initialize() and this guarantees
all create() methods for WebAnimation and all of its subclasses are correctly calling ActiveDOMObject::suspendIfNeeded().

* animation/DeclarativeAnimation.cpp:
(WebCore::DeclarativeAnimation::initialize):
* animation/DeclarativeAnimation.h:
* animation/WebAnimation.cpp:
(WebCore::WebAnimation::create):
(WebCore::WebAnimation::initialize):
(WebCore::WebAnimation::WebAnimation):
* animation/WebAnimation.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286641 => 286642)


--- trunk/Source/WebCore/ChangeLog	2021-12-08 05:30:53 UTC (rev 286641)
+++ trunk/Source/WebCore/ChangeLog	2021-12-08 06:28:55 UTC (rev 286642)
@@ -1,3 +1,28 @@
+2021-12-07  Antoine Quint  <[email protected]>
+
+        ActiveDOMObject::suspendIfNeeded() should not be called in the WebAnimation constructor
+        https://bugs.webkit.org/show_bug.cgi?id=233932
+
+        Reviewed by Chris Dumez.
+
+        It is not safe to call ActiveDOMObject::suspendIfNeeded() in a constructor. Since WebAnimation has several subclasses
+        (DeclarativeAnimation, and then CSSTransition and CSSAnimation deriving from DeclarativeAnimation) each with their own
+        create() methods, we add a new protected initialize() method which refactors code from the WebAnimation constructor
+        and is called from the two WebAnimation::create() methods.
+
+        DeclarativeAnimation already had an initialize method for common setup for the create() methods in CSSTransition and
+        CSS Animation, so we can simply call WebAnimation::initialize() from DeclarativeAnimation::initialize() and this guarantees
+        all create() methods for WebAnimation and all of its subclasses are correctly calling ActiveDOMObject::suspendIfNeeded().
+
+        * animation/DeclarativeAnimation.cpp:
+        (WebCore::DeclarativeAnimation::initialize):
+        * animation/DeclarativeAnimation.h:
+        * animation/WebAnimation.cpp:
+        (WebCore::WebAnimation::create):
+        (WebCore::WebAnimation::initialize):
+        (WebCore::WebAnimation::WebAnimation):
+        * animation/WebAnimation.h:
+
 2021-12-07  Wenson Hsieh  <[email protected]>
 
         Add support for `navigator.requestCookieConsent()` behind a disabled feature flag

Modified: trunk/Source/WebCore/animation/DeclarativeAnimation.cpp (286641 => 286642)


--- trunk/Source/WebCore/animation/DeclarativeAnimation.cpp	2021-12-08 05:30:53 UTC (rev 286641)
+++ trunk/Source/WebCore/animation/DeclarativeAnimation.cpp	2021-12-08 06:28:55 UTC (rev 286642)
@@ -107,6 +107,8 @@
 
 void DeclarativeAnimation::initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext& resolutionContext)
 {
+    WebAnimation::initialize();
+
     // We need to suspend invalidation of the animation's keyframe effect during its creation
     // as it would otherwise trigger invalidation of the document's style and this would be
     // incorrect since it would happen during style invalidation.

Modified: trunk/Source/WebCore/animation/DeclarativeAnimation.h (286641 => 286642)


--- trunk/Source/WebCore/animation/DeclarativeAnimation.h	2021-12-08 05:30:53 UTC (rev 286641)
+++ trunk/Source/WebCore/animation/DeclarativeAnimation.h	2021-12-08 06:28:55 UTC (rev 286642)
@@ -75,7 +75,7 @@
 protected:
     DeclarativeAnimation(const Styleable&, const Animation&);
 
-    virtual void initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext&);
+    void initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext&);
     virtual void syncPropertiesWithBackingAnimation();
     // elapsedTime is the animation's current time at the time the event is added and is exposed through the DOM API, timelineTime is the animations'
     // timeline current time and is not exposed through the DOM API but used by the DocumentTimeline for sorting events before dispatch. 

Modified: trunk/Source/WebCore/animation/WebAnimation.cpp (286641 => 286642)


--- trunk/Source/WebCore/animation/WebAnimation.cpp	2021-12-08 05:30:53 UTC (rev 286641)
+++ trunk/Source/WebCore/animation/WebAnimation.cpp	2021-12-08 06:28:55 UTC (rev 286642)
@@ -66,6 +66,7 @@
 Ref<WebAnimation> WebAnimation::create(Document& document, AnimationEffect* effect)
 {
     auto result = adoptRef(*new WebAnimation(document));
+    result->initialize();
     result->setEffect(effect);
     result->setTimeline(&document.timeline());
 
@@ -77,6 +78,7 @@
 Ref<WebAnimation> WebAnimation::create(Document& document, AnimationEffect* effect, AnimationTimeline* timeline)
 {
     auto result = adoptRef(*new WebAnimation(document));
+    result->initialize();
     result->setEffect(effect);
     if (timeline)
         result->setTimeline(timeline);
@@ -86,14 +88,17 @@
     return result;
 }
 
+void WebAnimation::initialize()
+{
+    suspendIfNeeded();
+    m_readyPromise->resolve(*this);
+}
+
 WebAnimation::WebAnimation(Document& document)
     : ActiveDOMObject(document)
     , m_readyPromise(makeUniqueRef<ReadyPromise>(*this, &WebAnimation::readyPromiseResolve))
     , m_finishedPromise(makeUniqueRef<FinishedPromise>(*this, &WebAnimation::finishedPromiseResolve))
 {
-    m_readyPromise->resolve(*this);
-    suspendIfNeeded();
-
     instances().add(this);
 }
 

Modified: trunk/Source/WebCore/animation/WebAnimation.h (286641 => 286642)


--- trunk/Source/WebCore/animation/WebAnimation.h	2021-12-08 05:30:53 UTC (rev 286641)
+++ trunk/Source/WebCore/animation/WebAnimation.h	2021-12-08 06:28:55 UTC (rev 286642)
@@ -155,6 +155,7 @@
 protected:
     explicit WebAnimation(Document&);
 
+    void initialize();
     void enqueueAnimationEvent(Ref<AnimationEventBase>&&);
 
 private:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to