[webkit-changes] [WebKit/WebKit] 04fce8: Refactor logic for muting autoplaying video elemen...
Wenson Hsieh
noreply at github.com
Fri May 3 18:06:27 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 04fce867503f4cab34c98b03c5b5c117dd914767
https://github.com/WebKit/WebKit/commit/04fce867503f4cab34c98b03c5b5c117dd914767
Author: Wenson Hsieh <wenson_hsieh at apple.com>
Date: 2024-05-03 (Fri, 03 May 2024)
Changed paths:
A LayoutTests/fast/element-targeting/target-video-in-subframe-expected.txt
A LayoutTests/fast/element-targeting/target-video-in-subframe.html
M LayoutTests/resources/ui-helper.js
M Source/WebCore/dom/Document.cpp
M Source/WebCore/dom/Document.h
M Source/WebCore/dom/Element.cpp
M Source/WebCore/dom/Element.h
M Source/WebCore/html/HTMLMediaElement.cpp
M Source/WebCore/html/HTMLMediaElement.h
M Source/WebCore/page/ElementTargetingController.cpp
M Source/WebCore/page/ElementTargetingController.h
M Source/WebCore/page/ElementTargetingTypes.h
M Source/WebCore/page/MediaProducer.h
M Source/WebCore/page/Page.cpp
M Source/WebCore/page/Page.h
M Source/WebCore/testing/Internals.cpp
M Source/WebCore/testing/Internals.h
M Source/WebCore/testing/Internals.idl
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
M Source/WebKit/UIProcess/API/APITargetedElementInfo.h
M Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h
M Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm
M Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
M Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
M Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h
M Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm
Log Message:
-----------
Refactor logic for muting autoplaying video elements in background tabs
https://bugs.webkit.org/show_bug.cgi?id=273633
rdar://125859510
Reviewed by Aditya Keerthi.
Refactor some logic related to muting media elements. See below for more details.
* LayoutTests/fast/element-targeting/target-video-in-subframe-expected.txt: Added.
* LayoutTests/fast/element-targeting/target-video-in-subframe.html: Added.
* LayoutTests/resources/ui-helper.js:
(window.UIHelper.resetVisibilityAdjustments):
(window.UIHelper):
Add a new layout test (and testing hooks) to exercise the change.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::visibilityAdjustmentStateDidChange):
Add plumbing to propagate visibility state change to all audio producers.
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::setVisibilityAdjustment):
Set a flag on `Page` to indicate that we've applied visibility adjustment to at least one element
before. Used in `isInVisibilityAdjustmentSubtree()` below to exit right away, in the common case
where there has never been visibility adjustment.
(WebCore::Element::isInVisibilityAdjustmentSubtree const):
Add a helper method to compute whether or not the element is inside of a visibility adjustment
subtree, by traversing ancestors in the DOM.
* Source/WebCore/dom/Element.h:
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didFinishInsertingNode):
(WebCore::HTMLMediaElement::removedFromAncestor):
(WebCore::HTMLMediaElement::visibilityAdjustmentStateDidChange):
Recompute and cache the visibility adjustment subtree state whenever the media element is
unparented, re-parented, or visibility state otherwise changes.
(WebCore::HTMLMediaElement::effectiveMuted const):
Consult the cached state flag that's updated above when determining whether the media element should
be `effectivelyMuted()`.
* Source/WebCore/html/HTMLMediaElement.h:
* Source/WebCore/page/ElementTargetingController.cpp:
(WebCore::hasAudibleMedia):
(WebCore::targetedElementInfo):
Add support for a `hasAudibleMedia` flag on targeted element info.
(WebCore::findOnlyMainElement):
(WebCore::isNavigationalElement):
(WebCore::containsNavigationalElement):
Drive-by fix: mark the arguments to a few helper functions as `const`.
(WebCore::ElementTargetingController::adjustVisibility):
(WebCore::ElementTargetingController::adjustVisibilityInRepeatedlyTargetedRegions):
(WebCore::ElementTargetingController::resetVisibilityAdjustments):
(WebCore::ElementTargetingController::dispatchVisibilityAdjustmentStateDidChange):
* Source/WebCore/page/ElementTargetingController.h:
* Source/WebCore/page/ElementTargetingTypes.h:
* Source/WebCore/page/MediaProducer.h:
(WebCore::MediaProducer::visibilityAdjustmentStateDidChange):
Add a new delegate hook to inform media producers when visibility state changes. Currently, this is
only implemented by `HTMLMediaElement`, which allows it to adjust whether or not the underlying
media player should be muted, through `effectiveMuted()`.
* Source/WebCore/page/Page.cpp:
(WebCore::Page::didCommitLoad):
* Source/WebCore/page/Page.h:
Add a boolean flag to track whether or not there has ever been any visibility adjustment in the
page (this bit is cleared out in `didCommitLoad` above).
(WebCore::Page::hasEverSetVisibilityAdjustment const):
(WebCore::Page::didSetVisibilityAdjustment):
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::isEffectivelyMuted):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
Add a new testing-only hook to ask for `HTMLMediaElement::effectiveMuted()`.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/APITargetedElementInfo.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm:
(-[_WKTargetedElementInfo hasAudibleMedia]):
* Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* Tools/TestRunnerShared/UIScriptContext/UIScriptController.h:
(WTR::UIScriptController::resetVisibilityAdjustments):
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h:
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
(WTR::UIScriptControllerCocoa::resetVisibilityAdjustments):
Canonical link: https://commits.webkit.org/278356@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list