OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/crypto/proxy_decryptor.h" | 5 #include "content/renderer/media/crypto/proxy_decryptor.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "content/renderer/media/crypto/content_decryption_module_factory.h" | |
14 #include "media/base/cdm_callback_promise.h" | 13 #include "media/base/cdm_callback_promise.h" |
| 14 #include "media/base/cdm_factory.h" |
15 #include "media/cdm/json_web_key.h" | 15 #include "media/cdm/json_web_key.h" |
16 #include "media/cdm/key_system_names.h" | 16 #include "media/cdm/key_system_names.h" |
17 | 17 |
18 #if defined(ENABLE_PEPPER_CDMS) | |
19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | |
20 #endif // defined(ENABLE_PEPPER_CDMS) | |
21 | |
22 #if defined(ENABLE_BROWSER_CDMS) | 18 #if defined(ENABLE_BROWSER_CDMS) |
23 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | 19 #include "content/renderer/media/crypto/renderer_cdm_manager.h" |
24 #endif // defined(ENABLE_BROWSER_CDMS) | 20 #endif // defined(ENABLE_BROWSER_CDMS) |
25 | 21 |
26 namespace content { | 22 namespace content { |
27 | 23 |
28 // Special system code to signal a closed persistent session in a SessionError() | 24 // Special system code to signal a closed persistent session in a SessionError() |
29 // call. This is needed because there is no SessionClosed() call in the prefixed | 25 // call. This is needed because there is no SessionClosed() call in the prefixed |
30 // EME API. | 26 // EME API. |
31 const int kSessionClosedSystemCode = 29127; | 27 const int kSessionClosedSystemCode = 29127; |
32 | 28 |
33 ProxyDecryptor::ProxyDecryptor( | 29 ProxyDecryptor::ProxyDecryptor(const KeyAddedCB& key_added_cb, |
34 #if defined(ENABLE_PEPPER_CDMS) | 30 const KeyErrorCB& key_error_cb, |
35 const CreatePepperCdmCB& create_pepper_cdm_cb, | 31 const KeyMessageCB& key_message_cb) |
36 #elif defined(ENABLE_BROWSER_CDMS) | 32 : key_added_cb_(key_added_cb), |
37 RendererCdmManager* manager, | |
38 #endif // defined(ENABLE_PEPPER_CDMS) | |
39 const KeyAddedCB& key_added_cb, | |
40 const KeyErrorCB& key_error_cb, | |
41 const KeyMessageCB& key_message_cb) | |
42 : | |
43 #if defined(ENABLE_PEPPER_CDMS) | |
44 create_pepper_cdm_cb_(create_pepper_cdm_cb), | |
45 #elif defined(ENABLE_BROWSER_CDMS) | |
46 manager_(manager), | |
47 cdm_id_(RendererCdmManager::kInvalidCdmId), | |
48 #endif // defined(ENABLE_PEPPER_CDMS) | |
49 key_added_cb_(key_added_cb), | |
50 key_error_cb_(key_error_cb), | 33 key_error_cb_(key_error_cb), |
51 key_message_cb_(key_message_cb), | 34 key_message_cb_(key_message_cb), |
52 is_clear_key_(false), | 35 is_clear_key_(false), |
| 36 #if defined(ENABLE_BROWSER_CDMS) |
| 37 cdm_id_(RendererCdmManager::kInvalidCdmId), |
| 38 #endif // defined(ENABLE_PEPPER_CDMS) |
53 weak_ptr_factory_(this) { | 39 weak_ptr_factory_(this) { |
54 #if defined(ENABLE_PEPPER_CDMS) | |
55 DCHECK(!create_pepper_cdm_cb_.is_null()); | |
56 #endif // defined(ENABLE_PEPPER_CDMS) | |
57 DCHECK(!key_added_cb_.is_null()); | 40 DCHECK(!key_added_cb_.is_null()); |
58 DCHECK(!key_error_cb_.is_null()); | 41 DCHECK(!key_error_cb_.is_null()); |
59 DCHECK(!key_message_cb_.is_null()); | 42 DCHECK(!key_message_cb_.is_null()); |
60 } | 43 } |
61 | 44 |
62 ProxyDecryptor::~ProxyDecryptor() { | 45 ProxyDecryptor::~ProxyDecryptor() { |
63 // Destroy the decryptor explicitly before destroying the plugin. | 46 // Destroy the decryptor explicitly before destroying the plugin. |
64 media_keys_.reset(); | 47 media_keys_.reset(); |
65 } | 48 } |
66 | 49 |
67 media::Decryptor* ProxyDecryptor::GetDecryptor() { | 50 media::Decryptor* ProxyDecryptor::GetDecryptor() { |
68 return media_keys_ ? media_keys_->GetDecryptor() : NULL; | 51 return media_keys_ ? media_keys_->GetDecryptor() : NULL; |
69 } | 52 } |
70 | 53 |
71 #if defined(ENABLE_BROWSER_CDMS) | 54 #if defined(ENABLE_BROWSER_CDMS) |
72 int ProxyDecryptor::GetCdmId() { | 55 int ProxyDecryptor::GetCdmId() { |
73 return cdm_id_; | 56 return cdm_id_; |
74 } | 57 } |
75 #endif | 58 #endif |
76 | 59 |
77 bool ProxyDecryptor::InitializeCDM(const std::string& key_system, | 60 bool ProxyDecryptor::InitializeCDM(const media::CdmFactory& cdm_factory, |
| 61 const std::string& key_system, |
78 const GURL& security_origin) { | 62 const GURL& security_origin) { |
79 DVLOG(1) << "InitializeCDM: key_system = " << key_system; | 63 DVLOG(1) << "InitializeCDM: key_system = " << key_system; |
80 | 64 |
81 DCHECK(!media_keys_); | 65 DCHECK(!media_keys_); |
82 media_keys_ = CreateMediaKeys(key_system, security_origin); | 66 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin); |
83 if (!media_keys_) | 67 if (!media_keys_) |
84 return false; | 68 return false; |
85 | 69 |
86 is_clear_key_ = | 70 is_clear_key_ = |
87 media::IsClearKey(key_system) || media::IsExternalClearKey(key_system); | 71 media::IsClearKey(key_system) || media::IsExternalClearKey(key_system); |
88 return true; | 72 return true; |
89 } | 73 } |
90 | 74 |
91 // Returns true if |data| is prefixed with |header| and has data after the | 75 // Returns true if |data| is prefixed with |header| and has data after the |
92 // |header|. | 76 // |header|. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 base::Bind(&ProxyDecryptor::OnSessionClosed, | 200 base::Bind(&ProxyDecryptor::OnSessionClosed, |
217 weak_ptr_factory_.GetWeakPtr(), | 201 weak_ptr_factory_.GetWeakPtr(), |
218 web_session_id), | 202 web_session_id), |
219 base::Bind(&ProxyDecryptor::OnSessionError, | 203 base::Bind(&ProxyDecryptor::OnSessionError, |
220 weak_ptr_factory_.GetWeakPtr(), | 204 weak_ptr_factory_.GetWeakPtr(), |
221 web_session_id))); | 205 web_session_id))); |
222 media_keys_->RemoveSession(web_session_id, promise.Pass()); | 206 media_keys_->RemoveSession(web_session_id, promise.Pass()); |
223 } | 207 } |
224 | 208 |
225 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( | 209 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( |
| 210 const media::CdmFactory& cdm_factory, |
226 const std::string& key_system, | 211 const std::string& key_system, |
227 const GURL& security_origin) { | 212 const GURL& security_origin) { |
228 return ContentDecryptionModuleFactory::Create( | 213 base::WeakPtr<ProxyDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); |
| 214 return cdm_factory.Create( |
229 key_system, | 215 key_system, |
230 security_origin, | 216 security_origin, |
231 #if defined(ENABLE_PEPPER_CDMS) | 217 #if defined(ENABLE_BROWSER_CDMS) |
232 create_pepper_cdm_cb_, | |
233 #elif defined(ENABLE_BROWSER_CDMS) | |
234 manager_, | |
235 &cdm_id_, | 218 &cdm_id_, |
236 #endif // defined(ENABLE_PEPPER_CDMS) | 219 #endif |
237 base::Bind(&ProxyDecryptor::OnSessionMessage, | 220 base::Bind(&ProxyDecryptor::OnSessionMessage, weak_this), |
238 weak_ptr_factory_.GetWeakPtr()), | 221 base::Bind(&ProxyDecryptor::OnSessionReady, weak_this), |
239 base::Bind(&ProxyDecryptor::OnSessionReady, | 222 base::Bind(&ProxyDecryptor::OnSessionClosed, weak_this), |
240 weak_ptr_factory_.GetWeakPtr()), | 223 base::Bind(&ProxyDecryptor::OnSessionError, weak_this), |
241 base::Bind(&ProxyDecryptor::OnSessionClosed, | 224 base::Bind(&ProxyDecryptor::OnSessionKeysChange, weak_this), |
242 weak_ptr_factory_.GetWeakPtr()), | 225 base::Bind(&ProxyDecryptor::OnSessionExpirationUpdate, weak_this)); |
243 base::Bind(&ProxyDecryptor::OnSessionError, | |
244 weak_ptr_factory_.GetWeakPtr()), | |
245 base::Bind(&ProxyDecryptor::OnSessionKeysChange, | |
246 weak_ptr_factory_.GetWeakPtr()), | |
247 base::Bind(&ProxyDecryptor::OnSessionExpirationUpdate, | |
248 weak_ptr_factory_.GetWeakPtr())); | |
249 } | 226 } |
250 | 227 |
251 void ProxyDecryptor::OnSessionMessage(const std::string& web_session_id, | 228 void ProxyDecryptor::OnSessionMessage(const std::string& web_session_id, |
252 const std::vector<uint8>& message, | 229 const std::vector<uint8>& message, |
253 const GURL& destination_url) { | 230 const GURL& destination_url) { |
254 // Assumes that OnSessionCreated() has been called before this. | 231 // Assumes that OnSessionCreated() has been called before this. |
255 | 232 |
256 // For ClearKey, convert the message from JSON into just passing the key | 233 // For ClearKey, convert the message from JSON into just passing the key |
257 // as the message. If unable to extract the key, return the message unchanged. | 234 // as the message. If unable to extract the key, return the message unchanged. |
258 if (is_clear_key_) { | 235 if (is_clear_key_) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 bool is_persistent = | 313 bool is_persistent = |
337 session_type == PersistentSession || session_type == LoadSession; | 314 session_type == PersistentSession || session_type == LoadSession; |
338 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); | 315 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); |
339 | 316 |
340 // For LoadSession(), generate the SessionReady event. | 317 // For LoadSession(), generate the SessionReady event. |
341 if (session_type == LoadSession) | 318 if (session_type == LoadSession) |
342 OnSessionReady(web_session_id); | 319 OnSessionReady(web_session_id); |
343 } | 320 } |
344 | 321 |
345 } // namespace content | 322 } // namespace content |
OLD | NEW |