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 WebCore { 16 17 class ExceptionState; 18 class HTMLMediaElement; 19 class MediaKeys; 20 21 class HTMLMediaElementEncryptedMedia FINAL : public NoBaseWillBeGarbageCollected<HTMLMediaElementEncryptedMedia>, public WillBeHeapSupplement<HTMLMediaElement> { 22 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLMediaElementEncryptedMedia); 23 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia); 24 public: 25 // encrypted media extensions (v0.1b) 26 static void webkitGenerateKeyRequest(HTMLMediaElement&, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionState&); 27 static void webkitGenerateKeyRequest(HTMLMediaElement&, const String& keySystem, ExceptionState&); 28 static void webkitAddKey(HTMLMediaElement&, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData, const String& sessionId, ExceptionState&); 29 static void webkitAddKey(HTMLMediaElement&, const String& keySystem, PassRefPtr<Uint8Array> key, ExceptionState&); 30 static void webkitCancelKeyRequest(HTMLMediaElement&, const String& keySystem, const String& sessionId, ExceptionState&); 31 32 DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitkeyadded); 33 DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitkeyerror); 34 DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitkeymessage); 35 DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(webkitneedkey); 36 37 // encrypted media extensions (WD) 38 static MediaKeys* mediaKeys(HTMLMediaElement&); 39 static void setMediaKeys(HTMLMediaElement&, MediaKeys*, ExceptionState&); 40 DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(needkey); 41 42 static void keyAdded(HTMLMediaElement&, const String& keySystem, const String& sessionId); 43 static void keyError(HTMLMediaElement&, const String& keySystem, const String& sessionId, blink::WebMediaPlayerClient::MediaKeyErrorCode, unsigned short systemCode); 44 static void keyMessage(HTMLMediaElement&, const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength, const blink::WebURL& defaultURL); 45 static void keyNeeded(HTMLMediaElement&, const String& contentType, const unsigned char* initData, unsigned initDataLength); 46 static void playerDestroyed(HTMLMediaElement&); 47 static blink::WebContentDecryptionModule* contentDecryptionModule(HTMLMediaElement&); 48 49 static HTMLMediaElementEncryptedMedia& from(HTMLMediaElement&); 50 static const char* supplementName(); 51 52 virtual void trace(Visitor*) OVERRIDE; 53 54 private: 55 HTMLMediaElementEncryptedMedia(); 56 void generateKeyRequest(blink::WebMediaPlayer*, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionState&); 57 void addKey(blink::WebMediaPlayer*, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData, const String& sessionId, ExceptionState&); 58 void cancelKeyRequest(blink::WebMediaPlayer*, const String& keySystem, const String& sessionId, ExceptionState&); 59 60 // EventTarget 61 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>); 62 EventListener* getAttributeEventListener(const AtomicString& eventType); 63 64 // Currently we have both EME v0.1b and EME WD implemented in media element. 65 // But we do not want to support both at the same time. The one used first 66 // will be supported. Use |m_emeMode| to track this selection. 67 // FIXME: Remove EmeMode once EME v0.1b support is removed. See crbug.com/249976. 68 enum EmeMode { EmeModeNotSelected, EmeModePrefixed, EmeModeUnprefixed }; 69 70 // check (and set if necessary) the encrypted media extensions (EME) mode 71 // (v0.1b or WD). Returns whether the mode is allowed and successfully set. 72 bool setEmeMode(EmeMode, ExceptionState&); 73 74 blink::WebContentDecryptionModule* contentDecryptionModule(); 75 void setMediaKeysInternal(HTMLMediaElement&, MediaKeys*); 76 77 EmeMode m_emeMode; 78 79 PersistentWillBeMember<MediaKeys> m_mediaKeys; 80 }; 81 82 } 83 84 #endif 85