Changeset 231866 in webkit


Ignore:
Timestamp:
May 16, 2018 1:36:26 PM (6 years ago)
Author:
eric.carlson@apple.com
Message:

Improve NowPlaying "title"
https://bugs.webkit.org/show_bug.cgi?id=185680
<rdar://problem/40296700>

Reviewed by Jer Noble.
Source/WebCore:

We send NowPlaying the element's title attribute if not empty, else the element's current url.
Title should be preferred because it is the most specific, but we should use the document
title if non-empty next, and if falling back to the element's url use just the domain instead
of the full url because it isn't likely to be useful to the user given the small amount of
space control center uses to display the title. Further, don't use any title at all when
in private browsing mode.

Tests: http/tests/media/now-playing-info-private-browsing.html

http/tests/media/now-playing-info.html

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::parseAttribute): Update NowPlaying when the title attribute changes.
(WebCore::HTMLMediaElement::finishSeek): Update NowPlaying when a seek completes.
(WebCore::HTMLMediaElement::mediaSessionTitle const): Update logic.
(WebCore::HTMLMediaElement::mediaSessionUniqueIdentifier const): Use the hash of the current
url as the unique identifier.

  • html/HTMLMediaElement.h:
  • platform/audio/PlatformMediaSession.cpp:

(WebCore::PlatformMediaSession::uniqueIdentifier const): New.
(WebCore::PlatformMediaSessionClient::mediaSessionUniqueIdentifier const): Ditto.

  • platform/audio/PlatformMediaSession.h:
  • platform/audio/ios/MediaSessionManagerIOS.mm:

(WebCore::MediaSessionManageriOS::updateNowPlayingInfo): Update m_lastUpdatedNowPlayingInfoUniqueIdentifier.

  • platform/audio/mac/MediaSessionManagerMac.mm:

(WebCore::MediaSessionManagerMac::updateNowPlayingInfo): Update.

  • testing/Internals.cpp:

(WebCore::Internals::nowPlayingState const): Expose NowPlaying state.

  • testing/Internals.h:
  • testing/Internals.idl:

LayoutTests:

  • http/tests/media/now-playing-info-expected.txt: Added.
  • http/tests/media/now-playing-info-private-browsing-expected.txt: Added.
  • http/tests/media/now-playing-info-private-browsing.html: Added.
  • http/tests/media/now-playing-info.html: Added.
  • platform/gtk/TestExpectations:
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r231865 r231866  
     12018-05-16  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Improve NowPlaying "title"
     4        https://bugs.webkit.org/show_bug.cgi?id=185680
     5        <rdar://problem/40296700>
     6
     7        Reviewed by Jer Noble.
     8
     9        * http/tests/media/now-playing-info-expected.txt: Added.
     10        * http/tests/media/now-playing-info-private-browsing-expected.txt: Added.
     11        * http/tests/media/now-playing-info-private-browsing.html: Added.
     12        * http/tests/media/now-playing-info.html: Added.
     13        * platform/gtk/TestExpectations:
     14
    1152018-05-16  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/LayoutTests/media/video-test.js

    r231817 r231866  
    187187}
    188188
    189 function waitFor(element, event) {
     189function waitFor(element, type) {
    190190    return new Promise(resolve => {
    191         element.addEventListener(event, event => {
     191        element.addEventListener(type, event => {
    192192            consoleWrite(`EVENT(${event.type})`);
    193193            resolve(event);
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r231701 r231866  
    11881188webkit.org/b/184295 http/wpt/loading/redirect-headers.html [ Skip ]
    11891189
     1190# NowPlaying is macOS and iOS only.
     1191http/tests/media/now-playing-info-private-browsing.html [ Skip ]
     1192http/tests/media/now-playing-info.html [ Skip ]
     1193
    11901194#////////////////////////////////////////////////////////////////////////////////////////
    11911195# End of Expected failures.
  • trunk/Source/WebCore/ChangeLog

    r231862 r231866  
     12018-05-16  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Improve NowPlaying "title"
     4        https://bugs.webkit.org/show_bug.cgi?id=185680
     5        <rdar://problem/40296700>
     6
     7        Reviewed by Jer Noble.
     8       
     9        We send NowPlaying the element's title attribute if not empty, else the element's current url.
     10        Title should be preferred because it is the most specific, but we should use the document
     11        title if non-empty next, and if falling back to the element's url use just the domain instead
     12        of the full url because it isn't likely to be useful to the user given the small amount of
     13        space control center uses to display the title. Further, don't use any title at all when
     14        in private browsing mode.
     15
     16        Tests: http/tests/media/now-playing-info-private-browsing.html
     17               http/tests/media/now-playing-info.html
     18
     19        * html/HTMLMediaElement.cpp:
     20        (WebCore::HTMLMediaElement::parseAttribute): Update NowPlaying when the title attribute changes.
     21        (WebCore::HTMLMediaElement::finishSeek): Update NowPlaying when a seek completes.
     22        (WebCore::HTMLMediaElement::mediaSessionTitle const): Update logic.
     23        (WebCore::HTMLMediaElement::mediaSessionUniqueIdentifier const): Use the hash of the current
     24        url as the unique identifier.
     25        * html/HTMLMediaElement.h:
     26
     27        * platform/audio/PlatformMediaSession.cpp:
     28        (WebCore::PlatformMediaSession::uniqueIdentifier const): New.
     29        (WebCore::PlatformMediaSessionClient::mediaSessionUniqueIdentifier const): Ditto.
     30        * platform/audio/PlatformMediaSession.h:
     31
     32        * platform/audio/ios/MediaSessionManagerIOS.mm:
     33        (WebCore::MediaSessionManageriOS::updateNowPlayingInfo): Update m_lastUpdatedNowPlayingInfoUniqueIdentifier.
     34
     35        * platform/audio/mac/MediaSessionManagerMac.mm:
     36        (WebCore::MediaSessionManagerMac::updateNowPlayingInfo): Update.
     37
     38        * testing/Internals.cpp:
     39        (WebCore::Internals::nowPlayingState const): Expose NowPlaying state.
     40        * testing/Internals.h:
     41        * testing/Internals.idl:
     42
    1432018-05-16  Daniel Bates  <dabates@apple.com>
    244
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r231839 r231866  
    879879        if (processingUserGestureForMedia())
    880880            removeBehaviorsRestrictionsAfterFirstUserGesture();
     881    } else if (name == titleAttr) {
     882        if (m_mediaSession)
     883            m_mediaSession->clientCharacteristicsChanged();
    881884    }
    882885    else
     
    30813084    // 17 - Queue a task to fire a simple event named seeked at the element.
    30823085    scheduleEvent(eventNames().seekedEvent);
     3086
     3087    if (m_mediaSession)
     3088        m_mediaSession->clientCharacteristicsChanged();
    30833089
    30843090#if ENABLE(MEDIA_SOURCE)
     
    74447450String HTMLMediaElement::mediaSessionTitle() const
    74457451{
    7446     if (hasAttributeWithoutSynchronization(titleAttr))
    7447         return attributeWithoutSynchronization(titleAttr);
    7448 
    7449     return m_currentSrc;
     7452    if (!document().page() || document().page()->usesEphemeralSession())
     7453        return emptyString();
     7454
     7455    if (hasAttributeWithoutSynchronization(titleAttr)) {
     7456        auto title = attributeWithoutSynchronization(titleAttr);
     7457        if (!title.isEmpty())
     7458            return title;
     7459    }
     7460
     7461    auto title = document().title();
     7462    if (!title.isEmpty())
     7463        return title;
     7464
     7465    return m_currentSrc.host();
     7466}
     7467
     7468uint64_t HTMLMediaElement::mediaSessionUniqueIdentifier() const
     7469{
     7470    auto& url = m_currentSrc.string();
     7471    return url.impl() ? url.impl()->hash() : 0;
    74507472}
    74517473
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r231817 r231866  
    861861    void resumeAutoplaying() override;
    862862    void mayResumePlayback(bool shouldResume) override;
     863    uint64_t mediaSessionUniqueIdentifier() const final;
    863864    String mediaSessionTitle() const override;
    864865    double mediaSessionDuration() const override { return duration(); }
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp

    r231817 r231866  
    239239
    240240#if ENABLE(VIDEO)
     241uint64_t PlatformMediaSession::uniqueIdentifier() const
     242{
     243    return m_client.mediaSessionUniqueIdentifier();
     244}
     245
    241246String PlatformMediaSession::title() const
    242247{
     
    324329
    325330#if ENABLE(VIDEO)
     331uint64_t PlatformMediaSessionClient::mediaSessionUniqueIdentifier() const
     332{
     333    return 0;
     334}
     335
    326336String PlatformMediaSessionClient::mediaSessionTitle() const
    327337{
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.h

    r231817 r231866  
    114114   
    115115#if ENABLE(VIDEO)
     116    uint64_t uniqueIdentifier() const;
    116117    String title() const;
    117118    double duration() const;
     
    217218
    218219#if ENABLE(VIDEO)
     220    virtual uint64_t mediaSessionUniqueIdentifier() const;
    219221    virtual String mediaSessionTitle() const;
    220222    virtual double mediaSessionDuration() const;
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm

    r231817 r231866  
    281281    m_reportedTitle = title;
    282282    m_reportedCurrentTime = currentTime;
     283    m_lastUpdatedNowPlayingInfoUniqueIdentifier = currentSession->uniqueIdentifier();
    283284
    284285    auto info = adoptNS([[NSMutableDictionary alloc] init]);
  • trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm

    r227529 r231866  
    177177    CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoPlaybackRate, cfRate.get());
    178178
    179     m_lastUpdatedNowPlayingInfoUniqueIdentifier = title.impl() ? title.impl()->hash() : 0;
     179    m_lastUpdatedNowPlayingInfoUniqueIdentifier = currentSession->uniqueIdentifier();
    180180    auto cfIdentifier = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &m_lastUpdatedNowPlayingInfoUniqueIdentifier));
    181181    CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoUniqueIdentifier, cfIdentifier.get());
  • trunk/Source/WebCore/testing/Internals.cpp

    r231839 r231866  
    36933693}
    36943694
     3695ExceptionOr<Internals::NowPlayingState> Internals::nowPlayingState() const
     3696{
     3697#if ENABLE(VIDEO)
     3698    return { { PlatformMediaSessionManager::sharedManager().lastUpdatedNowPlayingTitle(),
     3699        PlatformMediaSessionManager::sharedManager().lastUpdatedNowPlayingDuration(),
     3700        PlatformMediaSessionManager::sharedManager().lastUpdatedNowPlayingElapsedTime(),
     3701        PlatformMediaSessionManager::sharedManager().lastUpdatedNowPlayingInfoUniqueIdentifier(),
     3702        PlatformMediaSessionManager::sharedManager().hasActiveNowPlayingSession(),
     3703        PlatformMediaSessionManager::sharedManager().registeredAsNowPlayingApplication()
     3704    } };
     3705#else
     3706    return Exception { InvalidAccessError };
     3707#endif
     3708}
     3709
    36953710#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    36963711
  • trunk/Source/WebCore/testing/Internals.h

    r231817 r231866  
    671671    bool usingAppleInternalSDK() const;
    672672
     673    struct NowPlayingState {
     674        String title;
     675        double duration;
     676        double elapsedTime;
     677        uint64_t uniqueIdentifier;
     678        bool hasActiveSession;
     679        bool registeredAsNowPlayingApplication;
     680    };
     681    ExceptionOr<NowPlayingState> nowPlayingState() const;
     682
    673683private:
    674684    explicit Internals(Document&);
  • trunk/Source/WebCore/testing/Internals.idl

    r231817 r231866  
    8585[
    8686    ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
     87    Conditional=VIDEO,
     88    JSGenerateToJSObject,
     89] dictionary NowPlayingState {
     90    boolean hasActiveSession;
     91    boolean registeredAsNowPlayingApplication;
     92    DOMString title;
     93    unrestricted double duration;
     94    unrestricted double elapsedTime;
     95    unsigned long long uniqueIdentifier;
     96};
     97
     98[
     99    ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
    87100    NoInterfaceObject,
    88101] interface Internals {
     
    602615
    603616    boolean usingAppleInternalSDK();
    604 };
     617
     618    [Conditional=VIDEO, MayThrowException] readonly attribute NowPlayingState nowPlayingState;
     619};
Note: See TracChangeset for help on using the changeset viewer.