Skip to content

Commit

Permalink
Consume transient activation more directly after script runs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259224
rdar://112122350

Reviewed by Chris Dumez.

Old code walked the frame tree of each impacted document, which was unecessary.
Let's just directly set the transient activation timestamp for any remaining impacted documents.

* Source/WebCore/bindings/js/ScriptController.cpp:
(WebCore::ScriptController::executeScriptInWorld):

* Source/WebCore/page/LocalDOMWindow.cpp:
(WebCore::LocalDOMWindow::consumeTransientActivation):
(WebCore::LocalDOMWindow::consumeLastActivationIfNecessary):
* Source/WebCore/page/LocalDOMWindow.h:

Canonical link: https://commits.webkit.org/266072@main
  • Loading branch information
beidson committed Jul 14, 2023
1 parent df1f3e3 commit e1dd613
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/bindings/js/ScriptController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ ValueOrException ScriptController::executeScriptInWorld(DOMWrapperWorld& world,
UserGestureIndicator::currentUserGesture()->addDestructionObserver([](UserGestureToken& token) {
token.forEachImpactedDocument([](Document& document) {
if (auto* window = document.domWindow())
window->consumeTransientActivation();
window->consumeLastActivationIfNecessary();
});
});
}
Expand Down
11 changes: 8 additions & 3 deletions Source/WebCore/page/LocalDOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,14 +1610,19 @@ bool LocalDOMWindow::consumeTransientActivation()
RefPtr localFrame = dynamicDowncast<LocalFrame>(frame.get());
if (!localFrame)
continue;
auto* window = localFrame->window();
if (!window || window->lastActivationTimestamp() != MonotonicTime::infinity())
window->setLastActivationTimestamp(-MonotonicTime::infinity());
if (auto* window = localFrame->window())
window->consumeLastActivationIfNecessary();
}

return true;
}

void LocalDOMWindow::consumeLastActivationIfNecessary()
{
if (!std::isinf(m_lastActivationTimestamp))
m_lastActivationTimestamp = -MonotonicTime::infinity();
}

// https://html.spec.whatwg.org/multipage/interaction.html#activation-notification
void LocalDOMWindow::notifyActivated(MonotonicTime activationTime)
{
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/LocalDOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class LocalDOMWindow final

WEBCORE_EXPORT static void overrideTransientActivationDurationForTesting(std::optional<Seconds>&&);
void setLastActivationTimestamp(MonotonicTime lastActivationTimestamp) { m_lastActivationTimestamp = lastActivationTimestamp; }
void consumeLastActivationIfNecessary();
MonotonicTime lastActivationTimestamp() const { return m_lastActivationTimestamp; }
void notifyActivated(MonotonicTime);
WEBCORE_EXPORT bool hasTransientActivation() const;
Expand Down

0 comments on commit e1dd613

Please sign in to comment.