Roll ANGLE bc75f36:ef9d63e
[chromium-blink-merge.git] / content / renderer / media / crypto / encrypted_media_player_support_impl.h
blob71ddea64f4852c8afe07d0c42fa94b08a48d90a3
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_
8 #include <string>
9 #include <vector>
11 #include "base/memory/weak_ptr.h"
12 #include "content/renderer/media/crypto/encrypted_media_player_support.h"
13 #include "content/renderer/media/crypto/proxy_decryptor.h"
15 namespace content {
17 class WebContentDecryptionModuleImpl;
19 class EncryptedMediaPlayerSupportImpl
20 : public EncryptedMediaPlayerSupport,
21 public base::SupportsWeakPtr<EncryptedMediaPlayerSupportImpl> {
22 public:
23 explicit EncryptedMediaPlayerSupportImpl(blink::WebMediaPlayerClient* client);
24 virtual ~EncryptedMediaPlayerSupportImpl();
26 // EncryptedMediaPlayerSupport implementation.
27 virtual blink::WebMediaPlayer::MediaKeyException GenerateKeyRequest(
28 blink::WebLocalFrame* frame,
29 const blink::WebString& key_system,
30 const unsigned char* init_data,
31 unsigned init_data_length) OVERRIDE;
33 virtual blink::WebMediaPlayer::MediaKeyException AddKey(
34 const blink::WebString& key_system,
35 const unsigned char* key,
36 unsigned key_length,
37 const unsigned char* init_data,
38 unsigned init_data_length,
39 const blink::WebString& session_id) OVERRIDE;
41 virtual blink::WebMediaPlayer::MediaKeyException CancelKeyRequest(
42 const blink::WebString& key_system,
43 const blink::WebString& session_id) OVERRIDE;
45 virtual void SetContentDecryptionModule(
46 blink::WebContentDecryptionModule* cdm) OVERRIDE;
47 virtual void SetContentDecryptionModule(
48 blink::WebContentDecryptionModule* cdm,
49 blink::WebContentDecryptionModuleResult result) OVERRIDE;
50 virtual void SetContentDecryptionModuleSync(
51 blink::WebContentDecryptionModule* cdm) OVERRIDE;
53 virtual media::SetDecryptorReadyCB CreateSetDecryptorReadyCB() OVERRIDE;
54 virtual media::Demuxer::NeedKeyCB CreateNeedKeyCB() OVERRIDE;
56 virtual void OnPipelineDecryptError() OVERRIDE;
58 private:
59 // Requests that this object notifies when a decryptor is ready through the
60 // |decryptor_ready_cb| provided.
61 // If |decryptor_ready_cb| is null, the existing callback will be fired with
62 // NULL immediately and reset.
63 void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb);
65 blink::WebMediaPlayer::MediaKeyException GenerateKeyRequestInternal(
66 blink::WebLocalFrame* frame,
67 const std::string& key_system,
68 const unsigned char* init_data,
69 unsigned init_data_length);
71 blink::WebMediaPlayer::MediaKeyException AddKeyInternal(
72 const std::string& key_system,
73 const unsigned char* key,
74 unsigned key_length,
75 const unsigned char* init_data,
76 unsigned init_data_length,
77 const std::string& session_id);
79 blink::WebMediaPlayer::MediaKeyException CancelKeyRequestInternal(
80 const std::string& key_system,
81 const std::string& session_id);
83 void OnNeedKey(const std::string& type,
84 const std::vector<uint8>& init_data);
86 void OnKeyAdded(const std::string& session_id);
87 void OnKeyError(const std::string& session_id,
88 media::MediaKeys::KeyError error_code,
89 uint32 system_code);
90 void OnKeyMessage(const std::string& session_id,
91 const std::vector<uint8>& message,
92 const GURL& destination_url);
94 void ContentDecryptionModuleAttached(
95 blink::WebContentDecryptionModuleResult result,
96 bool success);
98 blink::WebMediaPlayerClient* client_;
100 // The currently selected key system. Empty string means that no key system
101 // has been selected.
102 std::string current_key_system_;
104 // Temporary for EME v0.1. In the future the init data type should be passed
105 // through GenerateKeyRequest() directly from WebKit.
106 std::string init_data_type_;
108 // Manages decryption keys and decrypts encrypted frames.
109 scoped_ptr<ProxyDecryptor> proxy_decryptor_;
111 // Non-owned pointer to the CDM. Updated via calls to
112 // setContentDecryptionModule().
113 WebContentDecryptionModuleImpl* web_cdm_;
115 media::DecryptorReadyCB decryptor_ready_cb_;
117 DISALLOW_COPY_AND_ASSIGN(EncryptedMediaPlayerSupportImpl);
121 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_