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 CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_
11 #include "base/memory/weak_ptr.h"
12 #include "content/renderer/media/crypto/proxy_decryptor.h"
13 #include "media/blink/encrypted_media_player_support.h"
16 class WebMediaPlayerClient
;
21 class WebContentDecryptionModuleImpl
;
23 class EncryptedMediaPlayerSupportImpl
24 : public media::EncryptedMediaPlayerSupport
,
25 public base::SupportsWeakPtr
<EncryptedMediaPlayerSupportImpl
> {
27 static scoped_ptr
<EncryptedMediaPlayerSupport
> Create(
28 blink::WebMediaPlayerClient
* client
);
30 virtual ~EncryptedMediaPlayerSupportImpl();
32 // EncryptedMediaPlayerSupport implementation.
33 virtual blink::WebMediaPlayer::MediaKeyException
GenerateKeyRequest(
34 blink::WebLocalFrame
* frame
,
35 const blink::WebString
& key_system
,
36 const unsigned char* init_data
,
37 unsigned init_data_length
) override
;
39 virtual blink::WebMediaPlayer::MediaKeyException
AddKey(
40 const blink::WebString
& key_system
,
41 const unsigned char* key
,
43 const unsigned char* init_data
,
44 unsigned init_data_length
,
45 const blink::WebString
& session_id
) override
;
47 virtual blink::WebMediaPlayer::MediaKeyException
CancelKeyRequest(
48 const blink::WebString
& key_system
,
49 const blink::WebString
& session_id
) override
;
51 virtual void SetInitialContentDecryptionModule(
52 blink::WebContentDecryptionModule
* initial_cdm
) override
;
54 virtual void SetContentDecryptionModule(
55 blink::WebContentDecryptionModule
* cdm
) override
;
56 virtual void SetContentDecryptionModule(
57 blink::WebContentDecryptionModule
* cdm
,
58 blink::WebContentDecryptionModuleResult result
) override
;
60 virtual media::SetDecryptorReadyCB
CreateSetDecryptorReadyCB() override
;
61 virtual media::Demuxer::NeedKeyCB
CreateNeedKeyCB() override
;
63 virtual void OnPipelineDecryptError() override
;
66 explicit EncryptedMediaPlayerSupportImpl(blink::WebMediaPlayerClient
* client
);
68 // Requests that this object notifies when a decryptor is ready through the
69 // |decryptor_ready_cb| provided.
70 // If |decryptor_ready_cb| is null, the existing callback will be fired with
71 // NULL immediately and reset.
72 void SetDecryptorReadyCB(const media::DecryptorReadyCB
& decryptor_ready_cb
);
74 blink::WebMediaPlayer::MediaKeyException
GenerateKeyRequestInternal(
75 blink::WebLocalFrame
* frame
,
76 const std::string
& key_system
,
77 const unsigned char* init_data
,
78 unsigned init_data_length
);
80 blink::WebMediaPlayer::MediaKeyException
AddKeyInternal(
81 const std::string
& key_system
,
82 const unsigned char* key
,
84 const unsigned char* init_data
,
85 unsigned init_data_length
,
86 const std::string
& session_id
);
88 blink::WebMediaPlayer::MediaKeyException
CancelKeyRequestInternal(
89 const std::string
& key_system
,
90 const std::string
& session_id
);
92 void OnNeedKey(const std::string
& type
,
93 const std::vector
<uint8
>& init_data
);
95 void OnKeyAdded(const std::string
& session_id
);
96 void OnKeyError(const std::string
& session_id
,
97 media::MediaKeys::KeyError error_code
,
99 void OnKeyMessage(const std::string
& session_id
,
100 const std::vector
<uint8
>& message
,
101 const GURL
& destination_url
);
103 void ContentDecryptionModuleAttached(
104 blink::WebContentDecryptionModuleResult result
,
107 blink::WebMediaPlayerClient
* client_
;
109 // The currently selected key system. Empty string means that no key system
110 // has been selected.
111 std::string current_key_system_
;
113 // Temporary for EME v0.1. In the future the init data type should be passed
114 // through GenerateKeyRequest() directly from WebKit.
115 std::string init_data_type_
;
117 // Manages decryption keys and decrypts encrypted frames.
118 scoped_ptr
<ProxyDecryptor
> proxy_decryptor_
;
120 // Non-owned pointer to the CDM. Updated via calls to
121 // setContentDecryptionModule().
122 WebContentDecryptionModuleImpl
* web_cdm_
;
124 media::DecryptorReadyCB decryptor_ready_cb_
;
126 DISALLOW_COPY_AND_ASSIGN(EncryptedMediaPlayerSupportImpl
);
130 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_