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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 pending_requests_.push_back( | 126 pending_requests_.push_back( |
| 127 new PendingGenerateKeyRequestData(init_data_type, init_data_vector)); | 127 new PendingGenerateKeyRequestData(init_data_type, init_data_vector)); |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 | 130 |
| 131 GenerateKeyRequestInternal(init_data_type, init_data_vector); | 131 GenerateKeyRequestInternal(init_data_type, init_data_vector); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Returns true if |data| is prefixed with |header| and has data after the | 134 // Returns true if |data| is prefixed with |header| and has data after the |
| 135 // |header|. | 135 // |header|. |
| 136 bool HasHeader(const std::vector<uint8>& data, const std::string& header) { | 136 static bool HasHeader(const std::vector<uint8>& data, |
| 137 const std::string& header) { | |
| 137 return data.size() > header.size() && | 138 return data.size() > header.size() && |
| 138 std::equal(header.begin(), header.end(), data.begin()); | 139 std::equal(header.begin(), header.end(), data.begin()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 // Removes the first |length| items from |data|. | 142 // Removes the first |length| items from |data|. |
| 142 void StripHeader(std::vector<uint8>& data, size_t length) { | 143 static void StripHeader(std::vector<uint8>& data, size_t length) { |
| 143 data.erase(data.begin(), data.begin() + length); | 144 data.erase(data.begin(), data.begin() + length); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void ProxyDecryptor::GenerateKeyRequestInternal( | 147 void ProxyDecryptor::GenerateKeyRequestInternal( |
| 147 EmeInitDataType init_data_type, | 148 EmeInitDataType init_data_type, |
| 148 const std::vector<uint8>& init_data) { | 149 const std::vector<uint8>& init_data) { |
| 149 DVLOG(1) << __FUNCTION__; | 150 DVLOG(1) << __FUNCTION__; |
| 150 DCHECK(!is_creating_cdm_); | 151 DCHECK(!is_creating_cdm_); |
| 151 | 152 |
| 152 if (!media_keys_) { | 153 if (!media_keys_) { |
| 153 OnLegacySessionError(std::string(), MediaKeys::NOT_SUPPORTED_ERROR, 0, | 154 OnLegacySessionError(std::string(), MediaKeys::NOT_SUPPORTED_ERROR, 0, |
| 154 "CDM creation failed."); | 155 "CDM creation failed."); |
| 155 return; | 156 return; |
| 156 } | 157 } |
| 157 | 158 |
| 158 const char kPrefixedApiPersistentSessionHeader[] = "PERSISTENT|"; | 159 const char kPrefixedApiPersistentSessionHeader[] = "PERSISTENT|"; |
| 159 const char kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; | 160 const char kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; |
| 160 | 161 |
| 161 SessionCreationType session_creation_type = TemporarySession; | 162 SessionCreationType session_creation_type = TemporarySession; |
| 162 std::vector<uint8> stripped_init_data = init_data; | 163 std::vector<uint8> stripped_init_data = init_data; |
| 164 std::string possible_session_id; | |
| 163 if (HasHeader(init_data, kPrefixedApiLoadSessionHeader)) { | 165 if (HasHeader(init_data, kPrefixedApiLoadSessionHeader)) { |
| 164 session_creation_type = LoadSession; | 166 session_creation_type = LoadSession; |
| 165 StripHeader(stripped_init_data, strlen(kPrefixedApiLoadSessionHeader)); | 167 StripHeader(stripped_init_data, strlen(kPrefixedApiLoadSessionHeader)); |
| 168 possible_session_id.assign(stripped_init_data.begin(), | |
| 169 stripped_init_data.end()); | |
| 166 } else if (HasHeader(init_data, kPrefixedApiPersistentSessionHeader)) { | 170 } else if (HasHeader(init_data, kPrefixedApiPersistentSessionHeader)) { |
| 167 session_creation_type = PersistentSession; | 171 session_creation_type = PersistentSession; |
| 168 StripHeader(stripped_init_data, | 172 StripHeader(stripped_init_data, |
| 169 strlen(kPrefixedApiPersistentSessionHeader)); | 173 strlen(kPrefixedApiPersistentSessionHeader)); |
| 170 } | 174 } |
| 171 | 175 |
| 172 scoped_ptr<NewSessionCdmPromise> promise(new CdmCallbackPromise<std::string>( | 176 scoped_ptr<NewSessionCdmPromise> promise(new CdmCallbackPromise<std::string>( |
| 173 base::Bind(&ProxyDecryptor::SetSessionId, weak_ptr_factory_.GetWeakPtr(), | 177 base::Bind(&ProxyDecryptor::SetSessionId, weak_ptr_factory_.GetWeakPtr(), |
| 174 session_creation_type), | 178 session_creation_type, possible_session_id), |
| 175 base::Bind(&ProxyDecryptor::OnLegacySessionError, | 179 base::Bind(&ProxyDecryptor::OnLegacySessionError, |
| 176 weak_ptr_factory_.GetWeakPtr(), | 180 weak_ptr_factory_.GetWeakPtr(), possible_session_id))); |
|
ddorwin
2015/07/08 21:50:13
Correction: _This_ appears to be a change in behav
jrummell
2015/07/08 23:15:08
Correct. Reverted.
| |
| 177 std::string()))); // No session id until created. | |
| 178 | 181 |
| 179 if (session_creation_type == LoadSession) { | 182 if (session_creation_type == LoadSession) { |
| 180 media_keys_->LoadSession( | 183 media_keys_->LoadSession(MediaKeys::PERSISTENT_LICENSE_SESSION, |
| 181 MediaKeys::PERSISTENT_LICENSE_SESSION, | 184 possible_session_id, promise.Pass()); |
|
ddorwin
2015/07/08 20:32:13
This appears to be a change in behavior.
jrummell
2015/07/08 20:58:17
It shouldn't be. 2nd parameter was a std::string o
ddorwin
2015/07/08 21:50:13
Oops, I commented on the wrong line. See my commen
jrummell
2015/07/08 23:15:07
Acknowledged.
| |
| 182 std::string( | |
| 183 reinterpret_cast<const char*>(vector_as_array(&stripped_init_data)), | |
| 184 stripped_init_data.size()), | |
| 185 promise.Pass()); | |
| 186 return; | 185 return; |
| 187 } | 186 } |
| 188 | 187 |
| 189 MediaKeys::SessionType session_type = | 188 MediaKeys::SessionType session_type = |
| 190 session_creation_type == PersistentSession | 189 session_creation_type == PersistentSession |
| 191 ? MediaKeys::PERSISTENT_LICENSE_SESSION | 190 ? MediaKeys::PERSISTENT_LICENSE_SESSION |
| 192 : MediaKeys::TEMPORARY_SESSION; | 191 : MediaKeys::TEMPORARY_SESSION; |
| 193 | 192 |
| 194 // No permission required when AesDecryptor is used or when the key system is | 193 // No permission required when AesDecryptor is used or when the key system is |
| 195 // external clear key. | 194 // external clear key. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 default: | 382 default: |
| 384 // This will include all other CDM4 errors and any error generated | 383 // This will include all other CDM4 errors and any error generated |
| 385 // by CDM5 or later. | 384 // by CDM5 or later. |
| 386 error_code = MediaKeys::kUnknownError; | 385 error_code = MediaKeys::kUnknownError; |
| 387 break; | 386 break; |
| 388 } | 387 } |
| 389 key_error_cb_.Run(session_id, error_code, system_code); | 388 key_error_cb_.Run(session_id, error_code, system_code); |
| 390 } | 389 } |
| 391 | 390 |
| 392 void ProxyDecryptor::SetSessionId(SessionCreationType session_type, | 391 void ProxyDecryptor::SetSessionId(SessionCreationType session_type, |
| 392 const std::string& possible_session_id, | |
|
ddorwin
2015/07/08 20:32:13
If keeping this, we should rename to requested_ or
| |
| 393 const std::string& session_id) { | 393 const std::string& session_id) { |
| 394 // Load() returns empty |session_id| if the session is not found, so | |
| 395 // convert this into an error. |possible_session_id| is the session ID | |
| 396 // passed to load(). | |
| 397 if (session_type == LoadSession && session_id.empty()) { | |
| 398 key_error_cb_.Run(possible_session_id, MediaKeys::kUnknownError, 0); | |
|
ddorwin
2015/07/08 20:32:13
If the above is a change in behavior, perhaps we c
jrummell
2015/07/08 20:58:17
Looking at this part again this is a change in beh
ddorwin
2015/07/08 21:50:13
Since we're going to disable this very soon, I don
jrummell
2015/07/08 23:15:08
Done.
| |
| 399 return; | |
| 400 } | |
| 401 | |
| 394 // Loaded sessions are considered persistent. | 402 // Loaded sessions are considered persistent. |
| 395 bool is_persistent = | 403 bool is_persistent = |
| 396 session_type == PersistentSession || session_type == LoadSession; | 404 session_type == PersistentSession || session_type == LoadSession; |
| 397 active_sessions_.insert(std::make_pair(session_id, is_persistent)); | 405 active_sessions_.insert(std::make_pair(session_id, is_persistent)); |
| 398 | 406 |
| 399 // For LoadSession(), generate the KeyAdded event. | 407 // For LoadSession(), generate the KeyAdded event. |
| 400 if (session_type == LoadSession) | 408 if (session_type == LoadSession) |
| 401 GenerateKeyAdded(session_id); | 409 GenerateKeyAdded(session_id); |
| 402 } | 410 } |
| 403 | 411 |
| 404 } // namespace media | 412 } // namespace media |
| OLD | NEW |