Home | History | Annotate | Download | only in encryptedmedia
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef HTMLMediaElementEncryptedMedia_h
      6 #define HTMLMediaElementEncryptedMedia_h
      7 
      8 #include "modules/EventTargetModules.h"
      9 #include "platform/Supplementable.h"
     10 #include "platform/graphics/media/MediaPlayer.h"
     11 #include "platform/heap/Handle.h"
     12 #include "public/platform/WebMediaPlayerClient.h"
     13 #include "wtf/Forward.h"
     14 
     15 namespace blink {
     16 
     17 class ExceptionState;
     18 class HTMLMediaElement;
     19 class MediaKeys;
     20 class ScriptPromise;
     21 class ScriptState;
     22 
     23 class HTMLMediaElementEncryptedMedia FINAL : public NoBaseWillBeGarbageCollected<HTMLMediaElementEncryptedMedia>, public WillBeHeapSupplement<HTMLMediaElement> {
     24     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLMediaElementEncryptedMedia);
     25     DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia);
     26 public:
     27     // encrypted media extensions (v0.1b)
     28     static void webkitGenerateKeyRequest(HTMLMediaElement&, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionState&);
     29     static void webkitGenerateKeyRequest(HTMLMediaElement&, const String& keySystem, ExceptionState&);
     30     static void webkitAddKey(HTMLMediaElement&, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData, const String& sessionId, ExceptionState&);
     31     static void webkitAddKey(HTMLMediaElement&, const String& keySystem, PassRefPtr<Uint8Array> key, ExceptionState&);
     32     static void webkitCancelKeyRequest(HTMLMediaElement&, const String& keySystem, const String& sessionId, ExceptionState&);
     33 
     34     DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitkeyadded);
     35     DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitkeyerror);
     36     DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitkeymessage);
     37     DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitneedkey);
     38 
     39     // encrypted media extensions (WD)
     40     static MediaKeys* mediaKeys(HTMLMediaElement&);
     41     static ScriptPromise setMediaKeys(ScriptState*, HTMLMediaElement&, MediaKeys*);
     42     DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(needkey);
     43 
     44     static void keyAdded(HTMLMediaElement&, const String& keySystem, const String& sessionId);
     45     static void keyError(HTMLMediaElement&, const String& keySystem, const String& sessionId, WebMediaPlayerClient::MediaKeyErrorCode, unsigned short systemCode);
     46     static void keyMessage(HTMLMediaElement&, const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength, const WebURL& defaultURL);
     47     static void keyNeeded(HTMLMediaElement&, const String& contentType, const unsigned char* initData, unsigned initDataLength);
     48     static void playerDestroyed(HTMLMediaElement&);
     49     static WebContentDecryptionModule* contentDecryptionModule(HTMLMediaElement&);
     50 
     51     static HTMLMediaElementEncryptedMedia& from(HTMLMediaElement&);
     52     static const char* supplementName();
     53 
     54     virtual void trace(Visitor*) OVERRIDE;
     55 
     56 private:
     57     friend class SetMediaKeysHandler;
     58 
     59     HTMLMediaElementEncryptedMedia();
     60     void generateKeyRequest(WebMediaPlayer*, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionState&);
     61     void addKey(WebMediaPlayer*, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData, const String& sessionId, ExceptionState&);
     62     void cancelKeyRequest(WebMediaPlayer*, const String& keySystem, const String& sessionId, ExceptionState&);
     63 
     64     // EventTarget
     65     bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
     66     EventListener* getAttributeEventListener(const AtomicString& eventType);
     67 
     68     // Currently we have both EME v0.1b and EME WD implemented in media element.
     69     // But we do not want to support both at the same time. The one used first
     70     // will be supported. Use |m_emeMode| to track this selection.
     71     // FIXME: Remove EmeMode once EME v0.1b support is removed. See crbug.com/249976.
     72     enum EmeMode { EmeModeNotSelected, EmeModePrefixed, EmeModeUnprefixed };
     73 
     74     // check (and set if necessary) the encrypted media extensions (EME) mode
     75     // (v0.1b or WD). Returns whether the mode is allowed and successfully set.
     76     bool setEmeMode(EmeMode);
     77 
     78     WebContentDecryptionModule* contentDecryptionModule();
     79 
     80     EmeMode m_emeMode;
     81 
     82     PersistentWillBeMember<MediaKeys> m_mediaKeys;
     83 };
     84 
     85 } // namespace blink
     86 
     87 #endif
     88