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