Bug 210518

Summary: [macOS] Update ScreenTime as playback state changes
Product: WebKit Reporter: Eric Carlson <eric.carlson>
Component: MediaAssignee: Eric Carlson <eric.carlson>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, benjamin, calvaris, cdumez, cmarcelo, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jer.noble, jiewen_tan, jonlee, peng.liu6, philipj, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=223731
Attachments:
Description Flags
WIP patch for the bots to check
none
updated WIP patch for the bots
none
updated WIP patch for the bots
none
updated WIP patch for the bots
none
Patch
none
Patch for landing
none
Follow-up Patch eric.carlson: review+

Description Eric Carlson 2020-04-14 15:09:25 PDT
Update ScreenTime as playback state changes
Comment 1 Eric Carlson 2020-04-14 15:10:05 PDT
<rdar://problem/61181092>
Comment 2 Eric Carlson 2020-04-14 17:29:58 PDT
Created attachment 396481 [details]
WIP patch for the bots to check
Comment 3 Eric Carlson 2020-04-14 21:44:25 PDT
Created attachment 396497 [details]
updated WIP patch for the bots
Comment 4 Eric Carlson 2020-04-15 07:04:52 PDT
Created attachment 396528 [details]
updated WIP patch for the bots
Comment 5 Eric Carlson 2020-04-15 08:36:35 PDT
Created attachment 396540 [details]
updated WIP patch for the bots
Comment 6 Jer Noble 2020-04-15 09:31:57 PDT
Comment on attachment 396540 [details]
updated WIP patch for the bots

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

> Source/WebCore/ChangeLog:1
> +2020-04-14  Eric Carlson  <eric.carlson@apple.com>

...

> Source/WebCore/ChangeLog:60
> +2020-04-14  Eric Carlson  <eric.carlson@apple.com>

Looks like you got a double changelong here.

> Source/WebKit/ChangeLog:52
> +2020-04-14  Eric Carlson  <eric.carlson@apple.com>

Here too.

> Source/WebCore/html/MediaElementSession.cpp:123
> +#if PLATFORM(MACCATALYST) || PLATFORM(MAC)

Could you add a ENABLE(MEDIA_USAGE) pragma and use it in platform-independent code instead? That way other ports could adopt without having to touch all these call sites.

> Source/WebKit/UIProcess/WebPageProxy.h:1739
> +    void addMediaUsageManagerSession(WebCore::MediaSessionIdentifier, const String& /* bundleIdentifier */, const URL& /* pageURL */);

Is there a reason these parameter names are commented out?
Comment 7 Eric Carlson 2020-04-15 16:23:59 PDT
Created attachment 396586 [details]
Patch
Comment 8 Eric Carlson 2020-04-15 16:28:45 PDT
Comment on attachment 396540 [details]
updated WIP patch for the bots

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

>> Source/WebCore/ChangeLog:60
>> +2020-04-14  Eric Carlson  <eric.carlson@apple.com>
> 
> Looks like you got a double changelong here.

Fixed.

>> Source/WebCore/html/MediaElementSession.cpp:123
>> +#if PLATFORM(MACCATALYST) || PLATFORM(MAC)
> 
> Could you add a ENABLE(MEDIA_USAGE) pragma and use it in platform-independent code instead? That way other ports could adopt without having to touch all these call sites.

Good suggestion, changed.

>> Source/WebKit/UIProcess/WebPageProxy.h:1739
>> +    void addMediaUsageManagerSession(WebCore::MediaSessionIdentifier, const String& /* bundleIdentifier */, const URL& /* pageURL */);
> 
> Is there a reason these parameter names are commented out?

Left over from an earlier version with more parameters. Removed.
Comment 9 Peng Liu 2020-04-15 17:12:24 PDT
Comment on attachment 396586 [details]
Patch

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

> Source/WebKit/UIProcess/Media/cocoa/MediaUsageManagerCocoa.h:42
> +    void reset() final;

Nit. Looks like these functions can be private?
Comment 10 Jon Lee 2020-04-15 17:29:17 PDT
Comment on attachment 396586 [details]
Patch

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

> Source/WebCore/html/MediaElementSession.cpp:1021
> +    auto* fullscreenElement = m_element.document().fullscreenManager().currentFullscreenElement();

document.fullscreenManager()...

> Source/WebCore/html/MediaElementSession.cpp:1036
> +        m_element.document().isMediaDocument() && (m_element.document().frame() && m_element.document().frame()->isMainFrame()),

ditto
Comment 11 Jer Noble 2020-04-15 17:40:36 PDT
Comment on attachment 396586 [details]
Patch

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

R=me with just a couple of nits.

> Source/WebCore/testing/Internals.idl:120
> +[
> +    ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
> +    Conditional=VIDEO,
> +    JSGenerateToJSObject,
> +] dictionary MediaUsageState {

It's unfortunate you can't just re-use MediaUsageInfo here, and not re-declare the existing struct, but I guess that the URL -> DOMString for mediaURL makes that untenable.

> Source/WebKit/UIProcess/Media/cocoa/MediaUsageManagerCocoa.h:63
> +        WebCore::MediaSessionIdentifier m_identifier;
> +        String m_bundleIdentifier;
> +        URL m_pageURL;
> +        Optional<WebCore::MediaUsageInfo> m_mediaUsageInfo;
> +        RetainPtr<USVideoUsage> m_usageTracker;

Since structs have public members, there's no no need to prefix these with `m_`.

> Source/WebKit/UIProcess/Media/cocoa/MediaUsageManagerCocoa.mm:198
> +        WTFLogAlways("MediaUsageManagerCocoa::updateMediaUsage caught exception!");

Do you want to include the exception.description here?
Comment 12 Eric Carlson 2020-04-15 21:33:33 PDT
Created attachment 396616 [details]
Patch for landing
Comment 13 EWS 2020-04-16 06:36:12 PDT
Committed r260182: <https://trac.webkit.org/changeset/260182>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396616 [details].
Comment 14 Jer Noble 2020-04-16 11:04:15 PDT
Reopening to attach new patch.
Comment 15 Jer Noble 2020-04-16 11:04:17 PDT
Created attachment 396672 [details]
Follow-up Patch
Comment 16 Jer Noble 2020-04-16 11:11:30 PDT
Committed r260201: <https://trac.webkit.org/changeset/260201>