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" | 13 #include "content/renderer/media/crypto/content_decryption_module_factory.h" |
14 #include "media/cdm/json_web_key.h" | 14 #include "media/cdm/json_web_key.h" |
15 #include "media/cdm/key_system_names.h" | 15 #include "media/cdm/key_system_names.h" |
16 | 16 |
17 #if defined(ENABLE_PEPPER_CDMS) | 17 #if defined(ENABLE_PEPPER_CDMS) |
18 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 18 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
19 #endif // defined(ENABLE_PEPPER_CDMS) | 19 #endif // defined(ENABLE_PEPPER_CDMS) |
20 | 20 |
21 #if defined(OS_ANDROID) | 21 #if defined(ENABLE_BROWSER_CDMS) |
22 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | 22 #include "content/renderer/media/crypto/renderer_cdm_manager.h" |
23 #endif // defined(OS_ANDROID) | 23 #endif // defined(ENABLE_BROWSER_CDMS) |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 // Since these reference IDs may conflict with the ones generated in | 27 // Since these reference IDs may conflict with the ones generated in |
28 // WebContentDecryptionModuleSessionImpl for the short time both paths are | 28 // WebContentDecryptionModuleSessionImpl for the short time both paths are |
29 // active, start with 100000 and generate the IDs from there. | 29 // active, start with 100000 and generate the IDs from there. |
30 // TODO(jrummell): Only allow one path http://crbug.com/306680. | 30 // TODO(jrummell): Only allow one path http://crbug.com/306680. |
31 uint32 ProxyDecryptor::next_session_id_ = 100000; | 31 uint32 ProxyDecryptor::next_session_id_ = 100000; |
32 | 32 |
33 const uint32 kInvalidSessionId = 0; | 33 const uint32 kInvalidSessionId = 0; |
34 | 34 |
35 // Special system code to signal a closed persistent session in a SessionError() | 35 // Special system code to signal a closed persistent session in a SessionError() |
36 // call. This is needed because there is no SessionClosed() call in the prefixed | 36 // call. This is needed because there is no SessionClosed() call in the prefixed |
37 // EME API. | 37 // EME API. |
38 const int kSessionClosedSystemCode = 29127; | 38 const int kSessionClosedSystemCode = 29127; |
39 | 39 |
40 ProxyDecryptor::ProxyDecryptor( | 40 ProxyDecryptor::ProxyDecryptor( |
41 #if defined(ENABLE_PEPPER_CDMS) | 41 #if defined(ENABLE_PEPPER_CDMS) |
42 const CreatePepperCdmCB& create_pepper_cdm_cb, | 42 const CreatePepperCdmCB& create_pepper_cdm_cb, |
43 #elif defined(OS_ANDROID) | 43 #elif defined(ENABLE_BROWSER_CDMS) |
44 RendererCdmManager* manager, | 44 RendererCdmManager* manager, |
45 #endif // defined(ENABLE_PEPPER_CDMS) | 45 #endif // defined(ENABLE_PEPPER_CDMS) |
46 const KeyAddedCB& key_added_cb, | 46 const KeyAddedCB& key_added_cb, |
47 const KeyErrorCB& key_error_cb, | 47 const KeyErrorCB& key_error_cb, |
48 const KeyMessageCB& key_message_cb) | 48 const KeyMessageCB& key_message_cb) |
49 : | 49 : |
50 #if defined(ENABLE_PEPPER_CDMS) | 50 #if defined(ENABLE_PEPPER_CDMS) |
51 create_pepper_cdm_cb_(create_pepper_cdm_cb), | 51 create_pepper_cdm_cb_(create_pepper_cdm_cb), |
52 #elif defined(OS_ANDROID) | 52 #elif defined(ENABLE_BROWSER_CDMS) |
53 manager_(manager), | 53 manager_(manager), |
54 cdm_id_(RendererCdmManager::kInvalidCdmId), | 54 cdm_id_(RendererCdmManager::kInvalidCdmId), |
55 #endif // defined(ENABLE_PEPPER_CDMS) | 55 #endif // defined(ENABLE_PEPPER_CDMS) |
56 key_added_cb_(key_added_cb), | 56 key_added_cb_(key_added_cb), |
57 key_error_cb_(key_error_cb), | 57 key_error_cb_(key_error_cb), |
58 key_message_cb_(key_message_cb), | 58 key_message_cb_(key_message_cb), |
59 is_clear_key_(false), | 59 is_clear_key_(false), |
60 weak_ptr_factory_(this) { | 60 weak_ptr_factory_(this) { |
61 #if defined(ENABLE_PEPPER_CDMS) | 61 #if defined(ENABLE_PEPPER_CDMS) |
62 DCHECK(!create_pepper_cdm_cb_.is_null()); | 62 DCHECK(!create_pepper_cdm_cb_.is_null()); |
63 #endif // defined(ENABLE_PEPPER_CDMS) | 63 #endif // defined(ENABLE_PEPPER_CDMS) |
64 DCHECK(!key_added_cb_.is_null()); | 64 DCHECK(!key_added_cb_.is_null()); |
65 DCHECK(!key_error_cb_.is_null()); | 65 DCHECK(!key_error_cb_.is_null()); |
66 DCHECK(!key_message_cb_.is_null()); | 66 DCHECK(!key_message_cb_.is_null()); |
67 } | 67 } |
68 | 68 |
69 ProxyDecryptor::~ProxyDecryptor() { | 69 ProxyDecryptor::~ProxyDecryptor() { |
70 // Destroy the decryptor explicitly before destroying the plugin. | 70 // Destroy the decryptor explicitly before destroying the plugin. |
71 media_keys_.reset(); | 71 media_keys_.reset(); |
72 } | 72 } |
73 | 73 |
74 media::Decryptor* ProxyDecryptor::GetDecryptor() { | 74 media::Decryptor* ProxyDecryptor::GetDecryptor() { |
75 return media_keys_ ? media_keys_->GetDecryptor() : NULL; | 75 return media_keys_ ? media_keys_->GetDecryptor() : NULL; |
76 } | 76 } |
77 | 77 |
78 #if defined(OS_ANDROID) | 78 #if defined(ENABLE_BROWSER_CDMS) |
79 int ProxyDecryptor::GetCdmId() { | 79 int ProxyDecryptor::GetCdmId() { |
80 return cdm_id_; | 80 return cdm_id_; |
81 } | 81 } |
82 #endif | 82 #endif |
83 | 83 |
84 bool ProxyDecryptor::InitializeCDM(const std::string& key_system, | 84 bool ProxyDecryptor::InitializeCDM(const std::string& key_system, |
85 const GURL& security_origin) { | 85 const GURL& security_origin) { |
86 DVLOG(1) << "InitializeCDM: key_system = " << key_system; | 86 DVLOG(1) << "InitializeCDM: key_system = " << key_system; |
87 | 87 |
88 DCHECK(!media_keys_); | 88 DCHECK(!media_keys_); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 | 189 |
190 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( | 190 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( |
191 const std::string& key_system, | 191 const std::string& key_system, |
192 const GURL& security_origin) { | 192 const GURL& security_origin) { |
193 return ContentDecryptionModuleFactory::Create( | 193 return ContentDecryptionModuleFactory::Create( |
194 key_system, | 194 key_system, |
195 security_origin, | 195 security_origin, |
196 #if defined(ENABLE_PEPPER_CDMS) | 196 #if defined(ENABLE_PEPPER_CDMS) |
197 create_pepper_cdm_cb_, | 197 create_pepper_cdm_cb_, |
198 #elif defined(OS_ANDROID) | 198 #elif defined(ENABLE_BROWSER_CDMS) |
199 manager_, | 199 manager_, |
200 &cdm_id_, | 200 &cdm_id_, |
201 #endif // defined(ENABLE_PEPPER_CDMS) | 201 #endif // defined(ENABLE_PEPPER_CDMS) |
202 base::Bind(&ProxyDecryptor::OnSessionCreated, | 202 base::Bind(&ProxyDecryptor::OnSessionCreated, |
203 weak_ptr_factory_.GetWeakPtr()), | 203 weak_ptr_factory_.GetWeakPtr()), |
204 base::Bind(&ProxyDecryptor::OnSessionMessage, | 204 base::Bind(&ProxyDecryptor::OnSessionMessage, |
205 weak_ptr_factory_.GetWeakPtr()), | 205 weak_ptr_factory_.GetWeakPtr()), |
206 base::Bind(&ProxyDecryptor::OnSessionReady, | 206 base::Bind(&ProxyDecryptor::OnSessionReady, |
207 weak_ptr_factory_.GetWeakPtr()), | 207 weak_ptr_factory_.GetWeakPtr()), |
208 base::Bind(&ProxyDecryptor::OnSessionClosed, | 208 base::Bind(&ProxyDecryptor::OnSessionClosed, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 const std::string& ProxyDecryptor::LookupWebSessionId(uint32 session_id) const { | 270 const std::string& ProxyDecryptor::LookupWebSessionId(uint32 session_id) const { |
271 DCHECK_NE(session_id, kInvalidSessionId); | 271 DCHECK_NE(session_id, kInvalidSessionId); |
272 | 272 |
273 // Session may not exist if error happens during GenerateKeyRequest(). | 273 // Session may not exist if error happens during GenerateKeyRequest(). |
274 SessionIdMap::const_iterator it = sessions_.find(session_id); | 274 SessionIdMap::const_iterator it = sessions_.find(session_id); |
275 return (it != sessions_.end()) ? it->second : base::EmptyString(); | 275 return (it != sessions_.end()) ? it->second : base::EmptyString(); |
276 } | 276 } |
277 | 277 |
278 } // namespace content | 278 } // namespace content |
OLD | NEW |