Commit 5c5b1b7e authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Don't dispatch SMIL events in SVGImage contexts

In SVGImages scripts don't run, so there will be no event handlers there
to do anything with the events. There's also no "internal" processing
that uses the actual events.
This avoids wasting memory when the animation processing ends up with a
backlog.

Bug: 1021630
Change-Id: Ibf7b3e998b8c130568c359bc284645556b952d4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012020Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#733615}
parent 08924e3a
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "third_party/blink/renderer/core/frame/web_feature.h" #include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/svg/animation/element_smil_animations.h" #include "third_party/blink/renderer/core/svg/animation/element_smil_animations.h"
#include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h" #include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/core/svg/svg_svg_element.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h" #include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
...@@ -64,6 +65,7 @@ SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner) ...@@ -64,6 +65,7 @@ SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner)
: frame_scheduling_state_(kIdle), : frame_scheduling_state_(kIdle),
started_(false), started_(false),
paused_(false), paused_(false),
should_dispatch_events_(!SVGImage::IsInSVGImage(&owner)),
document_order_indexes_dirty_(false), document_order_indexes_dirty_(false),
is_updating_intervals_(false), is_updating_intervals_(false),
wakeup_timer_( wakeup_timer_(
...@@ -457,7 +459,7 @@ void SMILTimeContainer::UpdateIntervals(SMILTime document_time) { ...@@ -457,7 +459,7 @@ void SMILTimeContainer::UpdateIntervals(SMILTime document_time) {
SVGSMILElement* element = priority_queue_.MinElement(); SVGSMILElement* element = priority_queue_.MinElement();
element->UpdateInterval(document_time); element->UpdateInterval(document_time);
auto events_to_dispatch = element->UpdateActiveState(document_time); auto events_to_dispatch = element->UpdateActiveState(document_time);
if (events_to_dispatch) if (should_dispatch_events_ && events_to_dispatch)
element->DispatchEvents(events_to_dispatch); element->DispatchEvents(events_to_dispatch);
SMILTime next_interval_time = SMILTime next_interval_time =
element->ComputeNextIntervalTime(document_time); element->ComputeNextIntervalTime(document_time);
......
...@@ -72,6 +72,7 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { ...@@ -72,6 +72,7 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> {
// Advance the animation timeline a single frame. // Advance the animation timeline a single frame.
void AdvanceFrameForTesting(); void AdvanceFrameForTesting();
bool EventsDisabled() const { return !should_dispatch_events_; }
void Trace(blink::Visitor*); void Trace(blink::Visitor*);
...@@ -133,6 +134,7 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { ...@@ -133,6 +134,7 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> {
bool started_ : 1; // The timeline has been started. bool started_ : 1; // The timeline has been started.
bool paused_ : 1; // The timeline is paused. bool paused_ : 1; // The timeline is paused.
const bool should_dispatch_events_ : 1;
bool document_order_indexes_dirty_ : 1; bool document_order_indexes_dirty_ : 1;
bool is_updating_intervals_; bool is_updating_intervals_;
......
...@@ -247,6 +247,7 @@ class CORE_EXPORT SVGImage final : public Image { ...@@ -247,6 +247,7 @@ class CORE_EXPORT SVGImage final : public Image {
FRIEND_TEST_ALL_PREFIXES(SVGImageTest, LayoutShiftTrackerDisabled); FRIEND_TEST_ALL_PREFIXES(SVGImageTest, LayoutShiftTrackerDisabled);
FRIEND_TEST_ALL_PREFIXES(SVGImageTest, SetSizeOnVisualViewport); FRIEND_TEST_ALL_PREFIXES(SVGImageTest, SetSizeOnVisualViewport);
FRIEND_TEST_ALL_PREFIXES(SVGImageTest, IsSizeAvailable); FRIEND_TEST_ALL_PREFIXES(SVGImageTest, IsSizeAvailable);
FRIEND_TEST_ALL_PREFIXES(SVGImageTest, DisablesSMILEvents);
}; };
DEFINE_IMAGE_TYPE_CASTS(SVGImage); DEFINE_IMAGE_TYPE_CASTS(SVGImage);
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
#include "third_party/blink/renderer/core/layout/layout_shift_tracker.h" #include "third_party/blink/renderer/core/layout/layout_shift_tracker.h"
#include "third_party/blink/renderer/core/layout/layout_view.h" #include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h" #include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/svg/animation/smil_time_container.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h" #include "third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h"
#include "third_party/blink/renderer/core/testing/sim/sim_request.h" #include "third_party/blink/renderer/core/testing/sim/sim_request.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h" #include "third_party/blink/renderer/core/testing/sim/sim_test.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h"
...@@ -252,6 +254,18 @@ TEST_F(SVGImageTest, IsSizeAvailable) { ...@@ -252,6 +254,18 @@ TEST_F(SVGImageTest, IsSizeAvailable) {
EXPECT_FALSE(GetImage().IsSizeAvailable()); EXPECT_FALSE(GetImage().IsSizeAvailable());
} }
TEST_F(SVGImageTest, DisablesSMILEvents) {
const bool kShouldPause = true;
Load(kAnimatedDocument, kShouldPause);
LocalFrame* local_frame =
To<LocalFrame>(GetImage().GetPageForTesting()->MainFrame());
EXPECT_TRUE(local_frame->GetDocument()->IsSVGDocument());
SMILTimeContainer* time_container =
To<SVGSVGElement>(local_frame->GetDocument()->documentElement())
->TimeContainer();
EXPECT_TRUE(time_container->EventsDisabled());
}
TEST_F(SVGImageTest, DarkModeClassification) { TEST_F(SVGImageTest, DarkModeClassification) {
DarkModeImageClassifier::Features features; DarkModeImageClassifier::Features features;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment