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.
5 #ifndef HTMLMediaElementEncryptedMedia_h
6 #define HTMLMediaElementEncryptedMedia_h
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"
18 class HTMLMediaElement;
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);
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&);
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);
39 // encrypted media extensions (WD)
40 static MediaKeys* mediaKeys(HTMLMediaElement&);
41 static ScriptPromise setMediaKeys(ScriptState*, HTMLMediaElement&, MediaKeys*);
42 DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(needkey);
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&);
51 static HTMLMediaElementEncryptedMedia& from(HTMLMediaElement&);
52 static const char* supplementName();
54 virtual void trace(Visitor*) OVERRIDE;
57 friend class SetMediaKeysHandler;
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&);
65 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
66 EventListener* getAttributeEventListener(const AtomicString& eventType);
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 };
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);
78 WebContentDecryptionModule* contentDecryptionModule();
82 PersistentWillBeMember<MediaKeys> m_mediaKeys;