| 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 "webcontentdecryptionmodulesession_impl.h" | 5 #include "webcontentdecryptionmodulesession_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "media/base/cdm_key_information.h" | 14 #include "media/base/cdm_key_information.h" |
| 14 #include "media/base/cdm_promise.h" | 15 #include "media/base/cdm_promise.h" |
| 15 #include "media/base/key_systems.h" | 16 #include "media/base/key_systems.h" |
| 16 #include "media/base/limits.h" | 17 #include "media/base/limits.h" |
| 17 #include "media/base/media_keys.h" | 18 #include "media/base/media_keys.h" |
| 18 #include "media/blink/cdm_result_promise.h" | 19 #include "media/blink/cdm_result_promise.h" |
| 19 #include "media/blink/cdm_session_adapter.h" | 20 #include "media/blink/cdm_session_adapter.h" |
| 20 #include "media/blink/new_session_cdm_result_promise.h" | 21 #include "media/blink/new_session_cdm_result_promise.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 error_message->assign("Initialization data too long."); | 104 error_message->assign("Initialization data too long."); |
| 104 return false; | 105 return false; |
| 105 } | 106 } |
| 106 | 107 |
| 107 switch (init_data_type) { | 108 switch (init_data_type) { |
| 108 case EmeInitDataType::WEBM: | 109 case EmeInitDataType::WEBM: |
| 109 sanitized_init_data->assign(init_data, init_data + init_data_length); | 110 sanitized_init_data->assign(init_data, init_data + init_data_length); |
| 110 return true; | 111 return true; |
| 111 | 112 |
| 112 case EmeInitDataType::CENC: | 113 case EmeInitDataType::CENC: |
| 113 if (!ValidatePsshInput(init_data, init_data_length)) { | 114 sanitized_init_data->assign(init_data, init_data + init_data_length); |
| 115 if (!ValidatePsshInput(*sanitized_init_data)) { |
| 114 error_message->assign("Initialization data for CENC is incorrect."); | 116 error_message->assign("Initialization data for CENC is incorrect."); |
| 115 return false; | 117 return false; |
| 116 } | 118 } |
| 117 | |
| 118 sanitized_init_data->assign(init_data, init_data + init_data_length); | |
| 119 return true; | 119 return true; |
| 120 | 120 |
| 121 case EmeInitDataType::KEYIDS: { | 121 case EmeInitDataType::KEYIDS: { |
| 122 // Extract the keys and then rebuild the message. This ensures that any | 122 // Extract the keys and then rebuild the message. This ensures that any |
| 123 // extra data in the provided JSON is dropped. | 123 // extra data in the provided JSON is dropped. |
| 124 std::string init_data_string(init_data, init_data + init_data_length); | 124 std::string init_data_string(init_data, init_data + init_data_length); |
| 125 KeyIdList key_ids; | 125 KeyIdList key_ids; |
| 126 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &key_ids, | 126 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &key_ids, |
| 127 error_message)) | 127 error_message)) |
| 128 return false; | 128 return false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 166 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
| 167 return blink::WebString::fromUTF8(session_id_); | 167 return blink::WebString::fromUTF8(session_id_); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void WebContentDecryptionModuleSessionImpl::initializeNewSession( | 170 void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
| 171 blink::WebEncryptedMediaInitDataType init_data_type, | 171 blink::WebEncryptedMediaInitDataType init_data_type, |
| 172 const unsigned char* init_data, | 172 const unsigned char* init_data, |
| 173 size_t init_data_length, | 173 size_t init_data_length, |
| 174 blink::WebEncryptedMediaSessionType session_type, | 174 blink::WebEncryptedMediaSessionType session_type, |
| 175 blink::WebContentDecryptionModuleResult result) { | 175 blink::WebContentDecryptionModuleResult result) { |
| 176 DCHECK(init_data); |
| 176 DCHECK(session_id_.empty()); | 177 DCHECK(session_id_.empty()); |
| 177 | 178 |
| 178 // From https://w3c.github.io/encrypted-media/#generateRequest. | 179 // From https://w3c.github.io/encrypted-media/#generateRequest. |
| 179 // 5. If the Key System implementation represented by this object's cdm | 180 // 5. If the Key System implementation represented by this object's cdm |
| 180 // implementation value does not support initDataType as an Initialization | 181 // implementation value does not support initDataType as an Initialization |
| 181 // Data Type, return a promise rejected with a new DOMException whose name | 182 // Data Type, return a promise rejected with a new DOMException whose name |
| 182 // is NotSupportedError. String comparison is case-sensitive. | 183 // is NotSupportedError. String comparison is case-sensitive. |
| 183 EmeInitDataType eme_init_data_type = ConvertToEmeInitDataType(init_data_type); | 184 EmeInitDataType eme_init_data_type = ConvertToEmeInitDataType(init_data_type); |
| 184 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(), | 185 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(), |
| 185 eme_init_data_type)) { | 186 eme_init_data_type)) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // 9.4 Let session id be the empty string. | 219 // 9.4 Let session id be the empty string. |
| 219 // (Done in constructor.) | 220 // (Done in constructor.) |
| 220 | 221 |
| 221 // 9.5 Let message be null. | 222 // 9.5 Let message be null. |
| 222 // (Done by CDM.) | 223 // (Done by CDM.) |
| 223 | 224 |
| 224 // 9.6 Let cdm be the CDM instance represented by this object's cdm | 225 // 9.6 Let cdm be the CDM instance represented by this object's cdm |
| 225 // instance value. | 226 // instance value. |
| 226 // 9.7 Use the cdm to execute the following steps: | 227 // 9.7 Use the cdm to execute the following steps: |
| 227 adapter_->InitializeNewSession( | 228 adapter_->InitializeNewSession( |
| 228 eme_init_data_type, vector_as_array(&sanitized_init_data), | 229 eme_init_data_type, sanitized_init_data, convertSessionType(session_type), |
| 229 base::saturated_cast<int>(sanitized_init_data.size()), | |
| 230 convertSessionType(session_type), | |
| 231 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 230 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
| 232 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, | 231 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, |
| 233 base::Bind( | 232 base::Bind( |
| 234 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 233 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
| 235 base::Unretained(this))))); | 234 base::Unretained(this))))); |
| 236 } | 235 } |
| 237 | 236 |
| 238 void WebContentDecryptionModuleSessionImpl::load( | 237 void WebContentDecryptionModuleSessionImpl::load( |
| 239 const blink::WebString& session_id, | 238 const blink::WebString& session_id, |
| 240 blink::WebContentDecryptionModuleResult result) { | 239 blink::WebContentDecryptionModuleResult result) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 253 base::Unretained(this))))); | 252 base::Unretained(this))))); |
| 254 } | 253 } |
| 255 | 254 |
| 256 void WebContentDecryptionModuleSessionImpl::update( | 255 void WebContentDecryptionModuleSessionImpl::update( |
| 257 const uint8* response, | 256 const uint8* response, |
| 258 size_t response_length, | 257 size_t response_length, |
| 259 blink::WebContentDecryptionModuleResult result) { | 258 blink::WebContentDecryptionModuleResult result) { |
| 260 DCHECK(response); | 259 DCHECK(response); |
| 261 DCHECK(!session_id_.empty()); | 260 DCHECK(!session_id_.empty()); |
| 262 adapter_->UpdateSession( | 261 adapter_->UpdateSession( |
| 263 session_id_, response, base::saturated_cast<int>(response_length), | 262 session_id_, std::vector<uint8>(response, response + response_length), |
| 264 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 263 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 265 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); | 264 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); |
| 266 } | 265 } |
| 267 | 266 |
| 268 void WebContentDecryptionModuleSessionImpl::close( | 267 void WebContentDecryptionModuleSessionImpl::close( |
| 269 blink::WebContentDecryptionModuleResult result) { | 268 blink::WebContentDecryptionModuleResult result) { |
| 270 DCHECK(!session_id_.empty()); | 269 DCHECK(!session_id_.empty()); |
| 271 adapter_->CloseSession( | 270 adapter_->CloseSession( |
| 272 session_id_, | 271 session_id_, |
| 273 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 272 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return blink::WebContentDecryptionModuleResult::SessionNotFound; | 328 return blink::WebContentDecryptionModuleResult::SessionNotFound; |
| 330 | 329 |
| 331 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; | 330 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; |
| 332 session_id_ = session_id; | 331 session_id_ = session_id; |
| 333 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) | 332 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) |
| 334 ? blink::WebContentDecryptionModuleResult::NewSession | 333 ? blink::WebContentDecryptionModuleResult::NewSession |
| 335 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 334 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
| 336 } | 335 } |
| 337 | 336 |
| 338 } // namespace media | 337 } // namespace media |
| OLD | NEW |