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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 245 } |
246 }; | 246 }; |
247 | 247 |
248 } // namespace | 248 } // namespace |
249 | 249 |
250 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 250 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
251 const scoped_refptr<CdmSessionAdapter>& adapter) | 251 const scoped_refptr<CdmSessionAdapter>& adapter) |
252 : adapter_(adapter), | 252 : adapter_(adapter), |
253 has_close_been_called_(false), | 253 has_close_been_called_(false), |
254 is_closed_(false), | 254 is_closed_(false), |
| 255 is_persistent_session_(false), |
255 weak_ptr_factory_(this) {} | 256 weak_ptr_factory_(this) {} |
256 | 257 |
257 WebContentDecryptionModuleSessionImpl:: | 258 WebContentDecryptionModuleSessionImpl:: |
258 ~WebContentDecryptionModuleSessionImpl() { | 259 ~WebContentDecryptionModuleSessionImpl() { |
259 DCHECK(thread_checker_.CalledOnValidThread()); | 260 DCHECK(thread_checker_.CalledOnValidThread()); |
260 | 261 |
261 if (!session_id_.empty()) { | 262 if (!session_id_.empty()) { |
262 adapter_->UnregisterSession(session_id_); | 263 adapter_->UnregisterSession(session_id_); |
263 | 264 |
264 // From http://w3c.github.io/encrypted-media/#mediakeysession-interface | 265 // From http://w3c.github.io/encrypted-media/#mediakeysession-interface |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // 10.5 Let session id be the empty string. | 351 // 10.5 Let session id be the empty string. |
351 // (Done in constructor.) | 352 // (Done in constructor.) |
352 | 353 |
353 // 10.6 Let message be null. | 354 // 10.6 Let message be null. |
354 // 10.7 Let message type be null. | 355 // 10.7 Let message type be null. |
355 // (Done by CDM.) | 356 // (Done by CDM.) |
356 | 357 |
357 // 10.8 Let cdm be the CDM instance represented by this object's cdm | 358 // 10.8 Let cdm be the CDM instance represented by this object's cdm |
358 // instance value. | 359 // instance value. |
359 // 10.9 Use the cdm to execute the following steps: | 360 // 10.9 Use the cdm to execute the following steps: |
| 361 CdmSessionType cdm_session_type = convertSessionType(session_type); |
| 362 is_persistent_session_ = |
| 363 cdm_session_type != CdmSessionType::TEMPORARY_SESSION; |
360 adapter_->InitializeNewSession( | 364 adapter_->InitializeNewSession( |
361 eme_init_data_type, sanitized_init_data, convertSessionType(session_type), | 365 eme_init_data_type, sanitized_init_data, cdm_session_type, |
362 std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 366 std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
363 result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName, | 367 result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName, |
364 base::Bind( | 368 base::Bind( |
365 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 369 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
366 weak_ptr_factory_.GetWeakPtr())))); | 370 weak_ptr_factory_.GetWeakPtr())))); |
367 } | 371 } |
368 | 372 |
369 void WebContentDecryptionModuleSessionImpl::Load( | 373 void WebContentDecryptionModuleSessionImpl::Load( |
370 const blink::WebString& session_id, | 374 const blink::WebString& session_id, |
371 blink::WebContentDecryptionModuleResult result) { | 375 blink::WebContentDecryptionModuleResult result) { |
(...skipping 12 matching lines...) Expand all Loading... |
384 if (!SanitizeSessionId(session_id, &sanitized_session_id)) { | 388 if (!SanitizeSessionId(session_id, &sanitized_session_id)) { |
385 result.CompleteWithError( | 389 result.CompleteWithError( |
386 blink::kWebContentDecryptionModuleExceptionTypeError, 0, | 390 blink::kWebContentDecryptionModuleExceptionTypeError, 0, |
387 "Invalid session ID."); | 391 "Invalid session ID."); |
388 return; | 392 return; |
389 } | 393 } |
390 | 394 |
391 // TODO(jrummell): Now that there are 2 types of persistent sessions, the | 395 // TODO(jrummell): Now that there are 2 types of persistent sessions, the |
392 // session type should be passed from blink. Type should also be passed in the | 396 // session type should be passed from blink. Type should also be passed in the |
393 // constructor (and removed from initializeNewSession()). | 397 // constructor (and removed from initializeNewSession()). |
| 398 is_persistent_session_ = true; |
394 adapter_->LoadSession( | 399 adapter_->LoadSession( |
395 CdmSessionType::PERSISTENT_LICENSE_SESSION, sanitized_session_id, | 400 CdmSessionType::PERSISTENT_LICENSE_SESSION, sanitized_session_id, |
396 std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 401 std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
397 result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName, | 402 result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName, |
398 base::Bind( | 403 base::Bind( |
399 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 404 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
400 weak_ptr_factory_.GetWeakPtr())))); | 405 weak_ptr_factory_.GetWeakPtr())))); |
401 } | 406 } |
402 | 407 |
403 void WebContentDecryptionModuleSessionImpl::Update( | 408 void WebContentDecryptionModuleSessionImpl::Update( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 adapter_->CloseSession( | 457 adapter_->CloseSession( |
453 session_id_, | 458 session_id_, |
454 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 459 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
455 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); | 460 result, adapter_->GetKeySystemUMAPrefix() + kCloseSessionUMAName))); |
456 } | 461 } |
457 | 462 |
458 void WebContentDecryptionModuleSessionImpl::Remove( | 463 void WebContentDecryptionModuleSessionImpl::Remove( |
459 blink::WebContentDecryptionModuleResult result) { | 464 blink::WebContentDecryptionModuleResult result) { |
460 DCHECK(!session_id_.empty()); | 465 DCHECK(!session_id_.empty()); |
461 DCHECK(thread_checker_.CalledOnValidThread()); | 466 DCHECK(thread_checker_.CalledOnValidThread()); |
| 467 |
| 468 // TODO(http://crbug.com/616166). Once all supported CDMs allow remove() on |
| 469 // temporary sessions, remove this code. |
| 470 if (!is_persistent_session_ && !IsClearKey(adapter_->GetKeySystem())) { |
| 471 result.CompleteWithError( |
| 472 blink::kWebContentDecryptionModuleExceptionTypeError, 0, |
| 473 "remove() on temporary sessions is not supported by this key system."); |
| 474 return; |
| 475 } |
| 476 |
462 adapter_->RemoveSession( | 477 adapter_->RemoveSession( |
463 session_id_, | 478 session_id_, |
464 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 479 std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
465 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName))); | 480 result, adapter_->GetKeySystemUMAPrefix() + kRemoveSessionUMAName))); |
466 } | 481 } |
467 | 482 |
468 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 483 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
469 ContentDecryptionModule::MessageType message_type, | 484 ContentDecryptionModule::MessageType message_type, |
470 const std::vector<uint8_t>& message) { | 485 const std::vector<uint8_t>& message) { |
471 DCHECK(client_) << "Client not set before message event"; | 486 DCHECK(client_) << "Client not set before message event"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 540 |
526 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; | 541 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; |
527 session_id_ = session_id; | 542 session_id_ = session_id; |
528 *status = | 543 *status = |
529 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) | 544 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) |
530 ? SessionInitStatus::NEW_SESSION | 545 ? SessionInitStatus::NEW_SESSION |
531 : SessionInitStatus::SESSION_ALREADY_EXISTS; | 546 : SessionInitStatus::SESSION_ALREADY_EXISTS; |
532 } | 547 } |
533 | 548 |
534 } // namespace media | 549 } // namespace media |
OLD | NEW |