Chromium Code Reviews| 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 "media/cdm/proxy_decryptor.h" | 5 #include "media/cdm/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" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 // Special system code to signal a closed persistent session in a SessionError() | 23 // Special system code to signal a closed persistent session in a SessionError() |
| 24 // call. This is needed because there is no SessionClosed() call in the prefixed | 24 // call. This is needed because there is no SessionClosed() call in the prefixed |
| 25 // EME API. | 25 // EME API. |
| 26 const int kSessionClosedSystemCode = 29127; | 26 const int kSessionClosedSystemCode = 29127; |
| 27 | 27 |
| 28 ProxyDecryptor::ProxyDecryptor(MediaPermission* media_permission, | 28 ProxyDecryptor::ProxyDecryptor(MediaPermission* media_permission, |
| 29 const KeyAddedCB& key_added_cb, | 29 const KeyAddedCB& key_added_cb, |
| 30 const KeyErrorCB& key_error_cb, | 30 const KeyErrorCB& key_error_cb, |
| 31 const KeyMessageCB& key_message_cb) | 31 const KeyMessageCB& key_message_cb) |
| 32 : key_added_cb_(key_added_cb), | 32 : media_permission_(media_permission), |
| 33 key_added_cb_(key_added_cb), | |
| 33 key_error_cb_(key_error_cb), | 34 key_error_cb_(key_error_cb), |
| 34 key_message_cb_(key_message_cb), | 35 key_message_cb_(key_message_cb), |
| 35 is_clear_key_(false), | 36 is_clear_key_(false), |
| 36 weak_ptr_factory_(this) { | 37 weak_ptr_factory_(this) { |
| 37 DCHECK(media_permission); | 38 DCHECK(media_permission); |
| 38 DCHECK(!key_added_cb_.is_null()); | 39 DCHECK(!key_added_cb_.is_null()); |
| 39 DCHECK(!key_error_cb_.is_null()); | 40 DCHECK(!key_error_cb_.is_null()); |
| 40 DCHECK(!key_message_cb_.is_null()); | 41 DCHECK(!key_message_cb_.is_null()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 ProxyDecryptor::~ProxyDecryptor() { | 44 ProxyDecryptor::~ProxyDecryptor() { |
| 44 // Destroy the decryptor explicitly before destroying the plugin. | 45 // Destroy the decryptor explicitly before destroying the plugin. |
| 45 media_keys_.reset(); | 46 media_keys_.reset(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 CdmContext* ProxyDecryptor::GetCdmContext() { | 49 CdmContext* ProxyDecryptor::GetCdmContext() { |
| 49 return media_keys_ ? media_keys_->GetCdmContext() : nullptr; | 50 return media_keys_ ? media_keys_->GetCdmContext() : nullptr; |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool ProxyDecryptor::InitializeCDM(CdmFactory* cdm_factory, | 53 bool ProxyDecryptor::InitializeCDM(CdmFactory* cdm_factory, |
| 53 const std::string& key_system, | 54 const std::string& key_system, |
| 54 const GURL& security_origin) { | 55 const GURL& security_origin) { |
| 55 DVLOG(1) << "InitializeCDM: key_system = " << key_system; | 56 DVLOG(1) << "InitializeCDM: key_system = " << key_system; |
| 56 | 57 |
| 57 DCHECK(!media_keys_); | 58 DCHECK(!media_keys_); |
| 58 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin); | 59 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin); |
| 59 if (!media_keys_) | 60 if (!media_keys_) |
| 60 return false; | 61 return false; |
| 61 | 62 |
| 63 key_system_ = key_system; | |
| 64 security_origin_ = security_origin; | |
| 65 | |
| 62 is_clear_key_ = | 66 is_clear_key_ = |
| 63 IsClearKey(key_system) || IsExternalClearKey(key_system); | 67 IsClearKey(key_system) || IsExternalClearKey(key_system); |
| 64 return true; | 68 return true; |
| 65 } | 69 } |
| 66 | 70 |
| 67 // Returns true if |data| is prefixed with |header| and has data after the | 71 // Returns true if |data| is prefixed with |header| and has data after the |
| 68 // |header|. | 72 // |header|. |
| 69 bool HasHeader(const uint8* data, int data_length, const std::string& header) { | 73 bool HasHeader(const uint8* data, int data_length, const std::string& header) { |
| 70 return static_cast<size_t>(data_length) > header.size() && | 74 return static_cast<size_t>(data_length) > header.size() && |
| 71 std::equal(data, data + header.size(), header.begin()); | 75 std::equal(data, data + header.size(), header.begin()); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 96 } | 100 } |
| 97 | 101 |
| 98 scoped_ptr<NewSessionCdmPromise> promise( | 102 scoped_ptr<NewSessionCdmPromise> promise( |
| 99 new CdmCallbackPromise<std::string>( | 103 new CdmCallbackPromise<std::string>( |
| 100 base::Bind(&ProxyDecryptor::SetSessionId, | 104 base::Bind(&ProxyDecryptor::SetSessionId, |
| 101 weak_ptr_factory_.GetWeakPtr(), | 105 weak_ptr_factory_.GetWeakPtr(), |
| 102 session_creation_type), | 106 session_creation_type), |
| 103 base::Bind(&ProxyDecryptor::OnSessionError, | 107 base::Bind(&ProxyDecryptor::OnSessionError, |
| 104 weak_ptr_factory_.GetWeakPtr(), | 108 weak_ptr_factory_.GetWeakPtr(), |
| 105 std::string()))); // No session id until created. | 109 std::string()))); // No session id until created. |
| 106 uint8* init_data_vector_data = | |
| 107 (init_data_vector.size() > 0) ? &init_data_vector[0] : nullptr; | |
| 108 | 110 |
| 109 if (session_creation_type == LoadSession) { | 111 if (session_creation_type == LoadSession) { |
| 112 uint8* init_data_vector_data = | |
| 113 (init_data_vector.size() > 0) ? &init_data_vector[0] : nullptr; | |
| 110 media_keys_->LoadSession( | 114 media_keys_->LoadSession( |
| 111 MediaKeys::PERSISTENT_LICENSE_SESSION, | 115 MediaKeys::PERSISTENT_LICENSE_SESSION, |
| 112 std::string(reinterpret_cast<const char*>(init_data_vector_data), | 116 std::string(reinterpret_cast<const char*>(init_data_vector_data), |
| 113 init_data_vector.size()), | 117 init_data_vector.size()), |
| 114 promise.Pass()); | 118 promise.Pass()); |
| 115 return true; | 119 return true; |
| 116 } | 120 } |
| 117 | 121 |
| 118 MediaKeys::SessionType session_type = | 122 MediaKeys::SessionType session_type = |
| 119 session_creation_type == PersistentSession | 123 session_creation_type == PersistentSession |
| 120 ? MediaKeys::PERSISTENT_LICENSE_SESSION | 124 ? MediaKeys::PERSISTENT_LICENSE_SESSION |
| 121 : MediaKeys::TEMPORARY_SESSION; | 125 : MediaKeys::TEMPORARY_SESSION; |
| 122 | 126 |
| 127 // No permission required when AesDecryptor is used or when the key system is | |
| 128 // external clear key. | |
| 129 DCHECK(!key_system_.empty()); | |
| 130 if (CanUseAesDecryptor(key_system_) || IsExternalClearKey(key_system_)) { | |
|
ddorwin
2015/03/12 21:38:54
Do Widevine browser tests fail too (on the linux_c
xhwang
2015/03/13 00:54:42
No. Only ECK failed.
| |
| 131 OnPermissionStatus(session_type, init_data_type, init_data_vector, | |
| 132 promise.Pass(), true /* granted */); | |
| 133 return true; | |
| 134 } | |
| 135 | |
| 136 #if defined(OS_CHROMEOS) | |
| 137 media_permission_->RequestPermission( | |
| 138 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, security_origin_, | |
| 139 base::Bind(&ProxyDecryptor::OnPermissionStatus, | |
| 140 weak_ptr_factory_.GetWeakPtr(), session_type, init_data_type, | |
| 141 init_data_vector, base::Passed(&promise))); | |
| 142 #else | |
| 143 // TODO(xhwang): Fix the Android path by requesting permission for key systems | |
| 144 // that don't use AesDecryptor in M43. | |
| 145 OnPermissionStatus(session_type, init_data_type, init_data_vector, | |
| 146 promise.Pass(), true /* granted */); | |
| 147 #endif | |
| 148 | |
| 149 return true; | |
| 150 } | |
| 151 | |
| 152 void ProxyDecryptor::OnPermissionStatus( | |
| 153 MediaKeys::SessionType session_type, | |
| 154 const std::string& init_data_type, | |
| 155 const std::vector<uint8>& init_data, | |
| 156 scoped_ptr<NewSessionCdmPromise> promise, | |
| 157 bool granted) { | |
| 158 DVLOG_IF(1, !granted) << "Permission request rejected."; | |
|
Darren Krahn
2015/03/12 22:12:17
Maybe I'm not following -- is this all we do when
xhwang
2015/03/13 00:54:42
ProxyDecryptor is only used by Prefixed EME, where
Darren Krahn
2015/03/13 22:47:11
Understood. Can you please put a comment to clarif
xhwang
2015/03/13 23:52:50
Done.
| |
| 159 | |
| 160 const uint8* init_data_vector_data = | |
| 161 (init_data.size() > 0) ? &init_data[0] : nullptr; | |
| 162 | |
| 123 media_keys_->CreateSessionAndGenerateRequest( | 163 media_keys_->CreateSessionAndGenerateRequest( |
| 124 session_type, init_data_type, init_data_vector_data, | 164 session_type, init_data_type, init_data_vector_data, init_data.size(), |
| 125 init_data_vector.size(), promise.Pass()); | 165 promise.Pass()); |
| 126 return true; | |
| 127 } | 166 } |
| 128 | 167 |
| 129 void ProxyDecryptor::AddKey(const uint8* key, | 168 void ProxyDecryptor::AddKey(const uint8* key, |
| 130 int key_length, | 169 int key_length, |
| 131 const uint8* init_data, | 170 const uint8* init_data, |
| 132 int init_data_length, | 171 int init_data_length, |
| 133 const std::string& session_id) { | 172 const std::string& session_id) { |
| 134 DVLOG(1) << "AddKey()"; | 173 DVLOG(1) << "AddKey()"; |
| 135 | 174 |
| 136 // In the prefixed API, the session parameter provided to addKey() is | 175 // In the prefixed API, the session parameter provided to addKey() is |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 bool is_persistent = | 335 bool is_persistent = |
| 297 session_type == PersistentSession || session_type == LoadSession; | 336 session_type == PersistentSession || session_type == LoadSession; |
| 298 active_sessions_.insert(std::make_pair(session_id, is_persistent)); | 337 active_sessions_.insert(std::make_pair(session_id, is_persistent)); |
| 299 | 338 |
| 300 // For LoadSession(), generate the KeyAdded event. | 339 // For LoadSession(), generate the KeyAdded event. |
| 301 if (session_type == LoadSession) | 340 if (session_type == LoadSession) |
| 302 GenerateKeyAdded(session_id); | 341 GenerateKeyAdded(session_id); |
| 303 } | 342 } |
| 304 | 343 |
| 305 } // namespace media | 344 } // namespace media |
| OLD | NEW |