Bug 171227

Summary: Indicate presence of audio when handling autoplay events
Product: WebKit Reporter: Matt Rajca <mrajca>
Component: MediaAssignee: Matt Rajca <mrajca>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, sam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch achristensen: review+

Description Matt Rajca 2017-04-24 09:47:02 PDT
When notifying clients of autoplay events, indicate whether there is audio.
Comment 1 Matt Rajca 2017-04-24 13:03:32 PDT
Created attachment 307998 [details]
Patch
Comment 2 Sam Weinig 2017-04-24 13:12:53 PDT
Comment on attachment 307998 [details]
Patch

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

> Source/WebCore/page/AutoplayEvent.h:41
> +enum AutoplayEventFlags {
> +    AutoplayEventFlagsNone = 0,
> +    AutoplayEventFlagsHasAudio = 1 << 0,
> +};

Generally we are using enum class for things like this theses days.

> Source/WebKit2/UIProcess/API/C/WKPage.cpp:2249
> +            m_client.handleAutoplayEvent(toAPI(&page), static_cast<WKAutoplayEvent>(event), static_cast<WKAutoplayEventFlags>(flags), m_client.base.clientInfo);

This should use an explicit conversion function that enumerates the enums, rather than assuming the WebCore type and the API type will have the same bit values. This is also true for WKAutoplayEvent.
Comment 3 Matt Rajca 2017-04-24 13:35:50 PDT
(In reply to Sam Weinig from comment #2)
> Comment on attachment 307998 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=307998&action=review
> 
> > Source/WebCore/page/AutoplayEvent.h:41
> > +enum AutoplayEventFlags {
> > +    AutoplayEventFlagsNone = 0,
> > +    AutoplayEventFlagsHasAudio = 1 << 0,
> > +};
> 
> Generally we are using enum class for things like this theses days.

I didn't use an enum class because this is used as a set of options (bitmask) and we can't use the usual operators like | and & with enum classes.

> 
> > Source/WebKit2/UIProcess/API/C/WKPage.cpp:2249
> > +            m_client.handleAutoplayEvent(toAPI(&page), static_cast<WKAutoplayEvent>(event), static_cast<WKAutoplayEventFlags>(flags), m_client.base.clientInfo);
> 
> This should use an explicit conversion function that enumerates the enums,
> rather than assuming the WebCore type and the API type will have the same
> bit values. This is also true for WKAutoplayEvent.

I'll add one.
Comment 4 Matt Rajca 2017-04-24 14:00:59 PDT
Created attachment 308007 [details]
Patch
Comment 5 Sam Weinig 2017-04-24 15:55:17 PDT
(In reply to Matt Rajca from comment #3)
> (In reply to Sam Weinig from comment #2)
> > Comment on attachment 307998 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=307998&action=review
> > 
> > > Source/WebCore/page/AutoplayEvent.h:41
> > > +enum AutoplayEventFlags {
> > > +    AutoplayEventFlagsNone = 0,
> > > +    AutoplayEventFlagsHasAudio = 1 << 0,
> > > +};
> > 
> > Generally we are using enum class for things like this theses days.
> 
> I didn't use an enum class because this is used as a set of options
> (bitmask) and we can't use the usual operators like | and & with enum
> classes.

If you want to use it as a bit set, then we have the OptionSet<> wrapper for that, which can use an enum class.
Comment 6 Matt Rajca 2017-04-24 16:41:48 PDT
(In reply to Sam Weinig from comment #5)
> (In reply to Matt Rajca from comment #3)
> > (In reply to Sam Weinig from comment #2)
> > > Comment on attachment 307998 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=307998&action=review
> > > 
> > > > Source/WebCore/page/AutoplayEvent.h:41
> > > > +enum AutoplayEventFlags {
> > > > +    AutoplayEventFlagsNone = 0,
> > > > +    AutoplayEventFlagsHasAudio = 1 << 0,
> > > > +};
> > > 
> > > Generally we are using enum class for things like this theses days.
> > 
> > I didn't use an enum class because this is used as a set of options
> > (bitmask) and we can't use the usual operators like | and & with enum
> > classes.
> 
> If you want to use it as a bit set, then we have the OptionSet<> wrapper for
> that, which can use an enum class.

Thanks, didn't know about that.
Comment 7 Matt Rajca 2017-04-25 09:51:51 PDT
Created attachment 308109 [details]
Patch
Comment 8 Matt Rajca 2017-04-25 17:03:03 PDT
Committed r215771: <http://trac.webkit.org/changeset/215771>