Skip to content

Commit

Permalink
Revert a1197f8. rdar://103331141
Browse files Browse the repository at this point in the history
    Revert "Remove Quirk for shouldAutoplayForArbitraryUserGesture"

    This reverts commit a1197f8.

Canonical link: https://commits.webkit.org/257698.7@safari-7615.1.15-branch
  • Loading branch information
alancoon authored and MyahCobbs committed Dec 15, 2022
1 parent 6de097d commit 8164c63
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions LayoutTests/media/media-usage-state-expected.txt
Expand Up @@ -27,6 +27,7 @@ EXPECTED (usage.pageMediaPlaybackSuspended == 'false') OK
EXPECTED (usage.isMediaDocumentAndNotOwnerElement == 'false') OK
EXPECTED (usage.pageExplicitlyAllowsElementToAutoplayInline == 'false') OK
EXPECTED (usage.requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted == 'false') OK
EXPECTED (usage.hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture == 'false') OK
EXPECTED (usage.isVideoAndRequiresUserGestureForVideoRateChange == 'true') OK
EXPECTED (usage.isAudioAndRequiresUserGestureForAudioRateChange == 'false') OK
EXPECTED (usage.isVideoAndRequiresUserGestureForVideoDueToLowPowerMode == 'false') OK
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/media/media-usage-state.html
Expand Up @@ -47,6 +47,7 @@
testExpected('usage.isMediaDocumentAndNotOwnerElement', false);
testExpected('usage.pageExplicitlyAllowsElementToAutoplayInline', false);
testExpected('usage.requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted', false);
testExpected('usage.hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture', false);
testExpected('usage.isVideoAndRequiresUserGestureForVideoRateChange', true);
testExpected('usage.isAudioAndRequiresUserGestureForAudioRateChange', false);
testExpected('usage.isVideoAndRequiresUserGestureForVideoDueToLowPowerMode', false);
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/PAL/pal/cocoa/UsageTrackingSoftLink.h
Expand Up @@ -68,6 +68,8 @@ SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, UsageTracking, USVideoMetadataKeyPag
#define USVideoMetadataKeyPageExplicitlyAllowsElementToAutoplayInline PAL::get_UsageTracking_USVideoMetadataKeyPageExplicitlyAllowsElementToAutoplayInline()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, UsageTracking, USVideoMetadataKeyRequiresFullscreenForVideoPlaybackAndFullscreenNotPermitted, NSString *)
#define USVideoMetadataKeyRequiresFullscreenForVideoPlaybackAndFullscreenNotPermitted PAL::get_UsageTracking_USVideoMetadataKeyRequiresFullscreenForVideoPlaybackAndFullscreenNotPermitted()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, UsageTracking, USVideoMetadataKeyHasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture, NSString *)
#define USVideoMetadataKeyHasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture PAL::get_UsageTracking_USVideoMetadataKeyHasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, UsageTracking, USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoRateChange, NSString *)
#define USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoRateChange PAL::get_UsageTracking_USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoRateChange()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, UsageTracking, USVideoMetadataKeyIsAudioAndRequiresUserGestureForAudioRateChange, NSString *)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/cocoa/UsageTrackingSoftLink.mm
Expand Up @@ -50,6 +50,7 @@
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyIsMediaDocumentAndNotOwnerElement, NSString*, PAL_EXPORT);
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyPageExplicitlyAllowsElementToAutoplayInline, NSString*, PAL_EXPORT);
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyRequiresFullscreenForVideoPlaybackAndFullscreenNotPermitted, NSString*, PAL_EXPORT);
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyHasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture, NSString*, PAL_EXPORT);
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoRateChange, NSString*, PAL_EXPORT);
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyIsAudioAndRequiresUserGestureForAudioRateChange, NSString*, PAL_EXPORT);
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, UsageTracking, USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoDueToLowPowerMode, NSString*, PAL_EXPORT);
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/html/MediaElementSession.cpp
Expand Up @@ -420,6 +420,9 @@ Expected<void, MediaPlaybackDenialReason> MediaElementSession::playbackStateChan
if (topDocument.mediaState() & MediaProducerMediaState::HasUserInteractedWithMediaElement && topDocument.quirks().needsPerDocumentAutoplayBehavior())
return { };

if (topDocument.hasHadUserInteraction() && document.quirks().shouldAutoplayForArbitraryUserGesture())
return { };

if (m_restrictions & RequireUserGestureForVideoRateChange && m_element.isVideo() && !document.processingUserGestureForMedia()) {
ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because a user gesture is required for video rate change restriction");
return makeUnexpected(MediaPlaybackDenialReason::UserGestureRequired);
Expand Down Expand Up @@ -1275,6 +1278,7 @@ void MediaElementSession::updateMediaUsageIfChanged()
document.isMediaDocument() && !document.ownerElement(),
pageExplicitlyAllowsElementToAutoplayInline(m_element),
requiresFullscreenForVideoPlayback() && !fullscreenPermitted(),
document.topDocument().hasHadUserInteraction() && document.quirks().shouldAutoplayForArbitraryUserGesture(),
isVideo && hasBehaviorRestriction(RequireUserGestureForVideoRateChange) && !processingUserGesture,
isAudio && hasBehaviorRestriction(RequireUserGestureForAudioRateChange) && !processingUserGesture && !m_element.muted() && m_element.volume(),
isVideo && hasBehaviorRestriction(RequireUserGestureForVideoDueToLowPowerMode) && !processingUserGesture,
Expand Down
13 changes: 13 additions & 0 deletions Source/WebCore/page/Quirks.cpp
Expand Up @@ -149,6 +149,19 @@ bool Quirks::needsPerDocumentAutoplayBehavior() const
#endif
}

bool Quirks::shouldAutoplayForArbitraryUserGesture() const
{
#if PLATFORM(MAC)
return needsQuirks() && allowedAutoplayQuirks(*m_document).contains(AutoplayQuirk::ArbitraryUserGestures);
#else
if (!needsQuirks())
return false;

auto domain = RegistrableDomain { m_document->topDocument().url() };
return domain == "twitter.com"_s || domain == "facebook.com"_s;
#endif
}

bool Quirks::shouldAutoplayWebAudioForArbitraryUserGesture() const
{
if (!needsQuirks())
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/Quirks.h
Expand Up @@ -62,6 +62,7 @@ class Quirks {
bool needsAutoplayPlayPauseEvents() const;
bool needsSeekingSupportDisabled() const;
bool needsPerDocumentAutoplayBehavior() const;
bool shouldAutoplayForArbitraryUserGesture() const;
bool shouldAutoplayWebAudioForArbitraryUserGesture() const;
bool hasBrokenEncryptedMediaAPISupportQuirk() const;
#if ENABLE(TOUCH_EVENTS)
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/platform/graphics/MediaUsageInfo.h
Expand Up @@ -55,6 +55,7 @@ struct MediaUsageInfo {
bool isMediaDocumentAndNotOwnerElement { false };
bool pageExplicitlyAllowsElementToAutoplayInline { false };
bool requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted { false };
bool hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture { false };
bool isVideoAndRequiresUserGestureForVideoRateChange { false };
bool isAudioAndRequiresUserGestureForAudioRateChange { false };
bool isVideoAndRequiresUserGestureForVideoDueToLowPowerMode { false };
Expand Down Expand Up @@ -92,6 +93,7 @@ struct MediaUsageInfo {
&& isMediaDocumentAndNotOwnerElement == other.isMediaDocumentAndNotOwnerElement
&& pageExplicitlyAllowsElementToAutoplayInline == other.pageExplicitlyAllowsElementToAutoplayInline
&& requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted == other.requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted
&& hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture == other.hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture
&& isVideoAndRequiresUserGestureForVideoRateChange == other.isVideoAndRequiresUserGestureForVideoRateChange
&& isAudioAndRequiresUserGestureForAudioRateChange == other.isAudioAndRequiresUserGestureForAudioRateChange
&& isVideoAndRequiresUserGestureForVideoDueToLowPowerMode == other.isVideoAndRequiresUserGestureForVideoDueToLowPowerMode
Expand Down Expand Up @@ -140,6 +142,7 @@ template<class Encoder> inline void MediaUsageInfo::encode(Encoder& encoder) con
encoder << isMediaDocumentAndNotOwnerElement;
encoder << pageExplicitlyAllowsElementToAutoplayInline;
encoder << requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted;
encoder << hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture;
encoder << isVideoAndRequiresUserGestureForVideoRateChange;
encoder << isAudioAndRequiresUserGestureForAudioRateChange;
encoder << isVideoAndRequiresUserGestureForVideoDueToLowPowerMode;
Expand Down Expand Up @@ -226,6 +229,9 @@ template<class Decoder> inline std::optional<MediaUsageInfo> MediaUsageInfo::dec
if (!decoder.decode(info.requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted))
return { };

if (!decoder.decode(info.hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture))
return { };

if (!decoder.decode(info.isVideoAndRequiresUserGestureForVideoRateChange))
return { };

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/testing/Internals.cpp
Expand Up @@ -4753,6 +4753,7 @@ ExceptionOr<Internals::MediaUsageState> Internals::mediaUsageState(HTMLMediaElem
info.value().isMediaDocumentAndNotOwnerElement,
info.value().pageExplicitlyAllowsElementToAutoplayInline,
info.value().requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted,
info.value().hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture,
info.value().isVideoAndRequiresUserGestureForVideoRateChange,
info.value().isAudioAndRequiresUserGestureForAudioRateChange,
info.value().isVideoAndRequiresUserGestureForVideoDueToLowPowerMode,
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/testing/Internals.h
Expand Up @@ -1081,6 +1081,7 @@ class Internals final : public RefCounted<Internals>, private ContextDestruction
bool isMediaDocumentAndNotOwnerElement;
bool pageExplicitlyAllowsElementToAutoplayInline;
bool requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted;
bool hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture;
bool isVideoAndRequiresUserGestureForVideoRateChange;
bool isAudioAndRequiresUserGestureForAudioRateChange;
bool isVideoAndRequiresUserGestureForVideoDueToLowPowerMode;
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/testing/Internals.idl
Expand Up @@ -177,6 +177,7 @@ enum AutoplayPolicy {
boolean isMediaDocumentAndNotOwnerElement;
boolean pageExplicitlyAllowsElementToAutoplayInline;
boolean requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted;
boolean hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture;
boolean isVideoAndRequiresUserGestureForVideoRateChange;
boolean isAudioAndRequiresUserGestureForAudioRateChange;
boolean isVideoAndRequiresUserGestureForVideoDueToLowPowerMode;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/Media/cocoa/MediaUsageManagerCocoa.mm
Expand Up @@ -70,6 +70,7 @@ static bool usageTrackingAvailable()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyIsMediaDocumentAndNotOwnerElement()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyPageExplicitlyAllowsElementToAutoplayInline()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyRequiresFullscreenForVideoPlaybackAndFullscreenNotPermitted()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyHasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoRateChange()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyIsAudioAndRequiresUserGestureForAudioRateChange()
&& PAL::canLoad_UsageTracking_USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoDueToLowPowerMode()
Expand Down Expand Up @@ -170,6 +171,7 @@ static bool usageTrackingAvailable()
USVideoMetadataKeyIsMediaDocumentAndNotOwnerElement: @(mediaUsageInfo.isMediaDocumentAndNotOwnerElement),
USVideoMetadataKeyPageExplicitlyAllowsElementToAutoplayInline: @(mediaUsageInfo.pageExplicitlyAllowsElementToAutoplayInline),
USVideoMetadataKeyRequiresFullscreenForVideoPlaybackAndFullscreenNotPermitted: @(mediaUsageInfo.requiresFullscreenForVideoPlaybackAndFullscreenNotPermitted),
USVideoMetadataKeyHasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture: @(mediaUsageInfo.hasHadUserInteractionAndQuirksContainsShouldAutoplayForArbitraryUserGesture),
USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoRateChange: @(mediaUsageInfo.isVideoAndRequiresUserGestureForVideoRateChange),
USVideoMetadataKeyIsAudioAndRequiresUserGestureForAudioRateChange: @(mediaUsageInfo.isAudioAndRequiresUserGestureForAudioRateChange),
USVideoMetadataKeyIsVideoAndRequiresUserGestureForVideoDueToLowPowerMode: @(mediaUsageInfo.isVideoAndRequiresUserGestureForVideoDueToLowPowerMode),
Expand Down
33 changes: 33 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm
Expand Up @@ -772,6 +772,39 @@ - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)tas
}

#if PLATFORM(MAC)
TEST(WebpagePreferences, WebsitePoliciesArbitraryUserGestureQuirk)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);

auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
[webView setNavigationDelegate:delegate.get()];

WKRetainPtr<WKPreferencesRef> preferences = adoptWK(WKPreferencesCreate());
WKPreferencesSetNeedsSiteSpecificQuirks(preferences.get(), true);
WKPageGroupSetPreferences(WKPageGetPageGroup([webView _pageForTesting]), preferences.get());

[delegate setAllowedAutoplayQuirksForURL:^_WKWebsiteAutoplayQuirk(NSURL *url)
{
return _WKWebsiteAutoplayQuirkArbitraryUserGestures;
}];
[delegate setAutoplayPolicyForURL:^(NSURL *)
{
return _WKWebsiteAutoplayPolicyDeny;
}];

NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
[webView loadRequest:request];
[webView waitForMessage:@"did-not-play"];

const NSPoint clickPoint = NSMakePoint(760, 560);
[webView mouseDownAtPoint:clickPoint simulatePressure:NO];
[webView mouseUpAtPoint:clickPoint];

[webView stringByEvaluatingJavaScript:@"playVideo()"];
[webView waitForMessage:@"autoplayed"];
}

TEST(WebpagePreferences, WebsitePoliciesAutoplayQuirks)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
Expand Down

0 comments on commit 8164c63

Please sign in to comment.