⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 143072 in webkit


Ignore:
Timestamp:
Feb 15, 2013, 5:03:29 PM (14 years ago)
Author:
jer.noble@apple.com
Message:

Add a CDMClient class which allows the CDM to query for the currently attached MediaPlayer.
https://bugs.webkit.org/show_bug.cgi?id=109702

Reviewed by Eric Carlson.

Some CDM implementations will need to work closely with an associated
MediaPlayer in order to generate key requests and provide keys. Add a
client protocol to be implemented by the MediaKeys object which can
provide access to the associated MediaPlayer if present.

  • Modules/encryptedmedia/CDM.cpp:

(WebCore::CDM::CDM): Initialize the m_client ivar.
(WebCore::CDM::mediaPlayer): Pass to the client, if present.

  • Modules/encryptedmedia/CDM.h:

(WebCore::CDM::client): Simple getter.
(WebCore::CDM::setClient): Simple setter.

  • Modules/encryptedmedia/MediaKeys.cpp:

(WebCore::MediaKeys::MediaKeys): Initialize the m_mediaElement ivar

and call setClient() on the passed in CDM.

(WebCore::MediaKeys::setMediaElement): Simple setter.
(WebCore::MediaKeys::cdmMediaPlayer): Retrieve the MediaPlayer from

the m_mediaElement if present.

  • Modules/encryptedmedia/MediaKeys.h:
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::~HTMLMediaElement): Call setMediaKeys(0)

to clear the mediaElement in any associated MediaKeys.

(WebCore::HTMLMediaElement::setMediaKeys): Clear the mediaElement on

any associated MediaKeys, and set the mediaElement on the newly
associated MediaKeys.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143070 r143072  
     12013-02-13  Jer Noble  <jer.noble@apple.com>
     2
     3        Add a CDMClient class which allows the CDM to query for the currently attached MediaPlayer.
     4        https://bugs.webkit.org/show_bug.cgi?id=109702
     5
     6        Reviewed by Eric Carlson.
     7
     8        Some CDM implementations will need to work closely with an associated
     9        MediaPlayer in order to generate key requests and provide keys. Add a
     10        client protocol to be implemented by the MediaKeys object which can
     11        provide access to the associated MediaPlayer if present.
     12
     13        * Modules/encryptedmedia/CDM.cpp:
     14        (WebCore::CDM::CDM): Initialize the m_client ivar.
     15        (WebCore::CDM::mediaPlayer): Pass to the client, if present.
     16        * Modules/encryptedmedia/CDM.h:
     17        (WebCore::CDM::client): Simple getter.
     18        (WebCore::CDM::setClient): Simple setter.
     19        * Modules/encryptedmedia/MediaKeys.cpp:
     20        (WebCore::MediaKeys::MediaKeys): Initialize the m_mediaElement ivar
     21            and call setClient() on the passed in CDM.
     22        (WebCore::MediaKeys::setMediaElement): Simple setter.
     23        (WebCore::MediaKeys::cdmMediaPlayer): Retrieve the MediaPlayer from
     24            the m_mediaElement if present.
     25        * Modules/encryptedmedia/MediaKeys.h:
     26        * html/HTMLMediaElement.cpp:
     27        (WebCore::HTMLMediaElement::~HTMLMediaElement): Call setMediaKeys(0)
     28            to clear the mediaElement in any associated MediaKeys.
     29        (WebCore::HTMLMediaElement::setMediaKeys): Clear the mediaElement on
     30            any associated MediaKeys, and set the mediaElement on the newly
     31            associated MediaKeys.
     32
    1332013-02-15  Simon Fraser  <simon.fraser@apple.com>
    234
  • trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp

    r142327 r143072  
    9393CDM::CDM(const String& keySystem)
    9494    : m_keySystem(keySystem)
     95    , m_client(0)
    9596{
    9697    m_private = CDMFactoryForKeySystem(keySystem)->constructor(this);
     
    101102}
    102103
    103 bool CDM::supportsMIMEType(const String& mimeType)
     104bool CDM::supportsMIMEType(const String& mimeType) const
    104105{
    105106    return m_private->supportsMIMEType(mimeType);
     
    111112}
    112113
     114MediaPlayer* CDM::mediaPlayer() const
     115{
     116    if (!m_client)
     117        return 0;
     118    return m_client->cdmMediaPlayer(this);
     119}
     120
    113121}
    114122
  • trunk/Source/WebCore/Modules/encryptedmedia/CDM.h

    r142918 r143072  
    3939class CDMPrivateInterface;
    4040class CDMSession;
    41 class MediaKeyError;
    42 class MediaKeySession;
    43 class MediaKeys;
     41class MediaPlayer;
    4442
    4543typedef PassOwnPtr<CDMPrivateInterface> (*CreateCDM)(CDM*);
    4644typedef bool (*CDMSupportsKeySystem)(const String&);
     45
     46class CDMClient {
     47public:
     48    virtual ~CDMClient() { }
     49
     50    virtual MediaPlayer* cdmMediaPlayer(const CDM*) const = 0;
     51};
    4752
    4853class CDMSession {
     
    5156    virtual ~CDMSession() { }
    5257
    53     virtual const String& sessionId() = 0;
     58    virtual const String& sessionId() const = 0;
    5459    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) = 0;
    5560    virtual void releaseKeys() = 0;
     
    6469    ~CDM();
    6570
    66     bool supportsMIMEType(const String&);
     71    bool supportsMIMEType(const String&) const;
    6772    PassOwnPtr<CDMSession> createSession();
    6873
    6974    const String& keySystem() const { return m_keySystem; }
     75
     76    CDMClient* client() const { return m_client; }
     77    void setClient(CDMClient* client) { m_client = client; }
     78
     79    MediaPlayer* mediaPlayer() const;
    7080
    7181private:
     
    7484    String m_keySystem;
    7585    OwnPtr<CDMPrivateInterface> m_private;
     86    CDMClient* m_client;
    7687};
    7788
  • trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp

    r142327 r143072  
    3131#include "CDM.h"
    3232#include "EventNames.h"
     33#include "HTMLMediaElement.h"
    3334#include "MediaKeyMessageEvent.h"
    3435#include "MediaKeySession.h"
     
    6667
    6768MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<CDM> cdm)
    68     : m_keySystem(keySystem)
     69    : m_mediaElement(0)
     70    , m_keySystem(keySystem)
    6971    , m_cdm(cdm)
    7072{
     73    m_cdm->setClient(this);
    7174}
    7275
     
    116119}
    117120
     121void MediaKeys::setMediaElement(HTMLMediaElement* element)
     122{
     123    m_mediaElement = element;
     124}
     125
     126MediaPlayer* MediaKeys::cdmMediaPlayer(const CDM*) const
     127{
     128    if (m_mediaElement)
     129        return m_mediaElement->player();
     130    return 0;
     131}
     132
    118133}
    119134
  • trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h

    r142327 r143072  
    2929#if ENABLE(ENCRYPTED_MEDIA_V2)
    3030
     31#include "CDM.h"
    3132#include "EventTarget.h"
    3233#include "ExceptionCode.h"
     
    4041namespace WebCore {
    4142
    42 class CDM;
    4343class MediaKeySession;
     44class HTMLMediaElement;
    4445
    45 class MediaKeys : public RefCounted<MediaKeys> {
     46class MediaKeys : public RefCounted<MediaKeys>, public CDMClient {
    4647public:
    4748    static PassRefPtr<MediaKeys> create(const String& keySystem, ExceptionCode&);
     
    5354    CDM* cdm() { return m_cdm.get(); }
    5455
     56    HTMLMediaElement* mediaElement() const { return m_mediaElement; }
     57    void setMediaElement(HTMLMediaElement*);
     58
    5559protected:
     60    // CDMClient:
     61    virtual MediaPlayer* cdmMediaPlayer(const CDM*) const OVERRIDE;
     62
    5663    MediaKeys(const String& keySystem, PassOwnPtr<CDM>);
    5764
    5865    Vector<RefPtr<MediaKeySession> > m_sessions;
    5966
     67    HTMLMediaElement* m_mediaElement;
    6068    String m_keySystem;
    6169    OwnPtr<CDM> m_cdm;
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r143021 r143072  
    350350#endif
    351351
     352#if ENABLE(ENCRYPTED_MEDIA_V2)
     353    setMediaKeys(0);
     354#endif
     355
    352356    removeElementFromDocumentMap(this, document());
    353357}
     
    19962000void HTMLMediaElement::setMediaKeys(MediaKeys* mediaKeys)
    19972001{
     2002    if (m_mediaKeys == mediaKeys)
     2003        return;
     2004
     2005    if (m_mediaKeys)
     2006        m_mediaKeys->setMediaElement(0);
    19982007    m_mediaKeys = mediaKeys;
     2008    if (m_mediaKeys)
     2009        m_mediaKeys->setMediaElement(this);
    19992010}
    20002011#endif
  • trunk/Source/WebCore/testing/MockCDM.cpp

    r142918 r143072  
    4040    virtual ~MockCDMSession() { }
    4141
    42     virtual const String& sessionId() OVERRIDE { return m_sessionId; }
     42    virtual const String& sessionId() const OVERRIDE { return m_sessionId; }
    4343    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) OVERRIDE;
    4444    virtual void releaseKeys() OVERRIDE;
Note: See TracChangeset for help on using the changeset viewer.