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 "media/base/cdm_callback_promise.h" | 13 #include "media/base/cdm_callback_promise.h" |
14 #include "media/base/cdm_factory.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_BROWSER_CDMS) | |
19 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | |
20 #endif // defined(ENABLE_BROWSER_CDMS) | |
21 | |
22 namespace content { | 18 namespace content { |
23 | 19 |
24 // Special system code to signal a closed persistent session in a SessionError() | 20 // Special system code to signal a closed persistent session in a SessionError() |
25 // call. This is needed because there is no SessionClosed() call in the prefixed | 21 // call. This is needed because there is no SessionClosed() call in the prefixed |
26 // EME API. | 22 // EME API. |
27 const int kSessionClosedSystemCode = 29127; | 23 const int kSessionClosedSystemCode = 29127; |
28 | 24 |
29 ProxyDecryptor::ProxyDecryptor(const KeyAddedCB& key_added_cb, | 25 ProxyDecryptor::ProxyDecryptor(const KeyAddedCB& key_added_cb, |
30 const KeyErrorCB& key_error_cb, | 26 const KeyErrorCB& key_error_cb, |
31 const KeyMessageCB& key_message_cb) | 27 const KeyMessageCB& key_message_cb) |
32 : key_added_cb_(key_added_cb), | 28 : key_added_cb_(key_added_cb), |
33 key_error_cb_(key_error_cb), | 29 key_error_cb_(key_error_cb), |
34 key_message_cb_(key_message_cb), | 30 key_message_cb_(key_message_cb), |
35 is_clear_key_(false), | 31 is_clear_key_(false), |
36 #if defined(ENABLE_BROWSER_CDMS) | |
37 cdm_id_(RendererCdmManager::kInvalidCdmId), | |
38 #endif // defined(ENABLE_PEPPER_CDMS) | |
39 weak_ptr_factory_(this) { | 32 weak_ptr_factory_(this) { |
40 DCHECK(!key_added_cb_.is_null()); | 33 DCHECK(!key_added_cb_.is_null()); |
41 DCHECK(!key_error_cb_.is_null()); | 34 DCHECK(!key_error_cb_.is_null()); |
42 DCHECK(!key_message_cb_.is_null()); | 35 DCHECK(!key_message_cb_.is_null()); |
43 } | 36 } |
44 | 37 |
45 ProxyDecryptor::~ProxyDecryptor() { | 38 ProxyDecryptor::~ProxyDecryptor() { |
46 // Destroy the decryptor explicitly before destroying the plugin. | 39 // Destroy the decryptor explicitly before destroying the plugin. |
47 media_keys_.reset(); | 40 media_keys_.reset(); |
48 } | 41 } |
49 | 42 |
50 media::Decryptor* ProxyDecryptor::GetDecryptor() { | 43 media::Decryptor* ProxyDecryptor::GetDecryptor() { |
51 return media_keys_ ? media_keys_->GetDecryptor() : NULL; | 44 return media_keys_ ? media_keys_->GetDecryptor() : NULL; |
52 } | 45 } |
53 | 46 |
54 #if defined(ENABLE_BROWSER_CDMS) | 47 #if defined(ENABLE_BROWSER_CDMS) |
55 int ProxyDecryptor::GetCdmId() { | 48 int ProxyDecryptor::GetCdmId() { |
56 return cdm_id_; | 49 return media_keys_->GetCdmId(); |
57 } | 50 } |
58 #endif | 51 #endif |
59 | 52 |
60 bool ProxyDecryptor::InitializeCDM(media::CdmFactory* cdm_factory, | 53 bool ProxyDecryptor::InitializeCDM(media::CdmFactory* cdm_factory, |
61 const std::string& key_system, | 54 const std::string& key_system, |
62 const GURL& security_origin) { | 55 const GURL& security_origin) { |
63 DVLOG(1) << "InitializeCDM: key_system = " << key_system; | 56 DVLOG(1) << "InitializeCDM: key_system = " << key_system; |
64 | 57 |
65 DCHECK(!media_keys_); | 58 DCHECK(!media_keys_); |
66 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin); | 59 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 200 } |
208 | 201 |
209 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( | 202 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( |
210 media::CdmFactory* cdm_factory, | 203 media::CdmFactory* cdm_factory, |
211 const std::string& key_system, | 204 const std::string& key_system, |
212 const GURL& security_origin) { | 205 const GURL& security_origin) { |
213 base::WeakPtr<ProxyDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); | 206 base::WeakPtr<ProxyDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); |
214 return cdm_factory->Create( | 207 return cdm_factory->Create( |
215 key_system, | 208 key_system, |
216 security_origin, | 209 security_origin, |
217 #if defined(ENABLE_BROWSER_CDMS) | |
218 &cdm_id_, | |
219 #endif | |
220 base::Bind(&ProxyDecryptor::OnSessionMessage, weak_this), | 210 base::Bind(&ProxyDecryptor::OnSessionMessage, weak_this), |
221 base::Bind(&ProxyDecryptor::OnSessionReady, weak_this), | 211 base::Bind(&ProxyDecryptor::OnSessionReady, weak_this), |
222 base::Bind(&ProxyDecryptor::OnSessionClosed, weak_this), | 212 base::Bind(&ProxyDecryptor::OnSessionClosed, weak_this), |
223 base::Bind(&ProxyDecryptor::OnSessionError, weak_this), | 213 base::Bind(&ProxyDecryptor::OnSessionError, weak_this), |
224 base::Bind(&ProxyDecryptor::OnSessionKeysChange, weak_this), | 214 base::Bind(&ProxyDecryptor::OnSessionKeysChange, weak_this), |
225 base::Bind(&ProxyDecryptor::OnSessionExpirationUpdate, weak_this)); | 215 base::Bind(&ProxyDecryptor::OnSessionExpirationUpdate, weak_this)); |
226 } | 216 } |
227 | 217 |
228 void ProxyDecryptor::OnSessionMessage(const std::string& web_session_id, | 218 void ProxyDecryptor::OnSessionMessage(const std::string& web_session_id, |
229 const std::vector<uint8>& message, | 219 const std::vector<uint8>& message, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 bool is_persistent = | 303 bool is_persistent = |
314 session_type == PersistentSession || session_type == LoadSession; | 304 session_type == PersistentSession || session_type == LoadSession; |
315 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); | 305 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); |
316 | 306 |
317 // For LoadSession(), generate the SessionReady event. | 307 // For LoadSession(), generate the SessionReady event. |
318 if (session_type == LoadSession) | 308 if (session_type == LoadSession) |
319 OnSessionReady(web_session_id); | 309 OnSessionReady(web_session_id); |
320 } | 310 } |
321 | 311 |
322 } // namespace content | 312 } // namespace content |
OLD | NEW |