Bug 167355

Summary: TAKE 2: Pass down website autoplay policies to media elements
Product: WebKit Reporter: Matt Rajca <mrajca>
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

Description Matt Rajca 2017-01-23 18:28:22 PST
Website autoplay policies passed to the web frame loader should be respected by media elements.

This is take 2 of https://bugs.webkit.org/show_bug.cgi?id=167132 with follow-up work from https://bugs.webkit.org/show_bug.cgi?id=167325 and fixes introduced in https://bugs.webkit.org/show_bug.cgi?id=167346 .

If non-default autoplay policies are passed during navigation, prefer those to global preferences.
If not, use the values specified in document settings.
Comment 1 Matt Rajca 2017-01-23 18:36:08 PST
Created attachment 299566 [details]
Patch
Comment 2 Alex Christensen 2017-01-24 10:58:42 PST
Comment on attachment 299566 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=299566&action=review

> Source/WebCore/loader/DocumentLoader.h:471
> +    std::optional<bool> m_audioPlaybackRequiresUserGesture;
> +    std::optional<bool> m_videoPlaybackRequiresUserGesture;

I think this should be a 3-state enum, probably with a different name like m_audioPlaybackPolicy.
enum class AutoplayPolicy {
    RequireUserGesture,
    AutoPlay,
    AutoPlayWithoutSound,
    Default, <-- This name might need to be more descriptive indicating that the policy hasn't been set by the WebsitePolicies so default to the Settings value.  Maybe just a comment explaining this.
    etc.
}
These two could probably even be made into one enum

> Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:820
> +#if PLATFORM(MAC)

Let's get rid of this now that it doesn't do anything for other platforms.

> Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:823
> +        documentLoader->setAudioPlaybackRequiresUserGesture(std::optional<bool>());

std::nullopt
Comment 3 Matt Rajca 2017-01-24 11:31:00 PST
Created attachment 299613 [details]
Patch
Comment 4 Matt Rajca 2017-01-24 11:31:54 PST
(In reply to comment #2)
> Comment on attachment 299566 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=299566&action=review
> 
> > Source/WebCore/loader/DocumentLoader.h:471
> > +    std::optional<bool> m_audioPlaybackRequiresUserGesture;
> > +    std::optional<bool> m_videoPlaybackRequiresUserGesture;
> 
> I think this should be a 3-state enum, probably with a different name like
> m_audioPlaybackPolicy.
> enum class AutoplayPolicy {
>     RequireUserGesture,
>     AutoPlay,
>     AutoPlayWithoutSound,
>     Default, <-- This name might need to be more descriptive indicating that
> the policy hasn't been set by the WebsitePolicies so default to the Settings
> value.  Maybe just a comment explaining this.
>     etc.
> }
> These two could probably even be made into one enum

Done.

> 
> > Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:820
> > +#if PLATFORM(MAC)
> 
> Let's get rid of this now that it doesn't do anything for other platforms.

Okay, and I made the tests run on iOS as well.

> 
> > Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:823
> > +        documentLoader->setAudioPlaybackRequiresUserGesture(std::optional<bool>());
> 
> std::nullopt

Not necessary with the changes above.
Comment 5 WebKit Commit Bot 2017-01-24 13:05:00 PST
Comment on attachment 299613 [details]
Patch

Clearing flags on attachment: 299613

Committed r211097: <http://trac.webkit.org/changeset/211097>
Comment 6 WebKit Commit Bot 2017-01-24 13:05:04 PST
All reviewed patches have been landed.  Closing bug.
Comment 7 Matt Rajca 2017-01-24 13:12:10 PST
*** Bug 167346 has been marked as a duplicate of this bug. ***
Comment 8 Matt Rajca 2017-01-24 13:12:49 PST
*** Bug 167132 has been marked as a duplicate of this bug. ***
Comment 9 Matt Rajca 2017-01-24 13:13:22 PST
*** Bug 167325 has been marked as a duplicate of this bug. ***