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 "content/renderer/media/cdm/ppapi_decryptor.h" | 5 #include "content/renderer/media/cdm/ppapi_decryptor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 void PpapiDecryptor::Create( | 29 void PpapiDecryptor::Create( |
30 const std::string& key_system, | 30 const std::string& key_system, |
31 const GURL& security_origin, | 31 const GURL& security_origin, |
32 bool allow_distinctive_identifier, | 32 bool allow_distinctive_identifier, |
33 bool allow_persistent_state, | 33 bool allow_persistent_state, |
34 const CreatePepperCdmCB& create_pepper_cdm_cb, | 34 const CreatePepperCdmCB& create_pepper_cdm_cb, |
35 const media::SessionMessageCB& session_message_cb, | 35 const media::SessionMessageCB& session_message_cb, |
36 const media::SessionClosedCB& session_closed_cb, | 36 const media::SessionClosedCB& session_closed_cb, |
37 const media::LegacySessionErrorCB& legacy_session_error_cb, | |
38 const media::SessionKeysChangeCB& session_keys_change_cb, | 37 const media::SessionKeysChangeCB& session_keys_change_cb, |
39 const media::SessionExpirationUpdateCB& session_expiration_update_cb, | 38 const media::SessionExpirationUpdateCB& session_expiration_update_cb, |
40 const media::CdmCreatedCB& cdm_created_cb) { | 39 const media::CdmCreatedCB& cdm_created_cb) { |
41 std::string plugin_type = media::GetPepperType(key_system); | 40 std::string plugin_type = media::GetPepperType(key_system); |
42 DCHECK(!plugin_type.empty()); | 41 DCHECK(!plugin_type.empty()); |
43 | 42 |
44 std::unique_ptr<PepperCdmWrapper> pepper_cdm_wrapper; | 43 std::unique_ptr<PepperCdmWrapper> pepper_cdm_wrapper; |
45 { | 44 { |
46 TRACE_EVENT0("media", "PpapiDecryptor::CreatePepperCDM"); | 45 TRACE_EVENT0("media", "PpapiDecryptor::CreatePepperCDM"); |
47 pepper_cdm_wrapper = create_pepper_cdm_cb.Run(plugin_type, security_origin); | 46 pepper_cdm_wrapper = create_pepper_cdm_cb.Run(plugin_type, security_origin); |
48 } | 47 } |
49 | 48 |
50 if (!pepper_cdm_wrapper) { | 49 if (!pepper_cdm_wrapper) { |
51 std::string message = | 50 std::string message = |
52 "Unable to create the CDM for the key system " + key_system + "."; | 51 "Unable to create the CDM for the key system " + key_system + "."; |
53 DLOG(ERROR) << message; | 52 DLOG(ERROR) << message; |
54 base::ThreadTaskRunnerHandle::Get()->PostTask( | 53 base::ThreadTaskRunnerHandle::Get()->PostTask( |
55 FROM_HERE, base::Bind(cdm_created_cb, nullptr, message)); | 54 FROM_HERE, base::Bind(cdm_created_cb, nullptr, message)); |
56 return; | 55 return; |
57 } | 56 } |
58 | 57 |
59 scoped_refptr<PpapiDecryptor> ppapi_decryptor( | 58 scoped_refptr<PpapiDecryptor> ppapi_decryptor(new PpapiDecryptor( |
60 new PpapiDecryptor(std::move(pepper_cdm_wrapper), session_message_cb, | 59 std::move(pepper_cdm_wrapper), session_message_cb, session_closed_cb, |
61 session_closed_cb, legacy_session_error_cb, | 60 session_keys_change_cb, session_expiration_update_cb)); |
62 session_keys_change_cb, session_expiration_update_cb)); | |
63 | 61 |
64 // |ppapi_decryptor| ownership is passed to the promise. | 62 // |ppapi_decryptor| ownership is passed to the promise. |
65 std::unique_ptr<media::CdmInitializedPromise> promise( | 63 std::unique_ptr<media::CdmInitializedPromise> promise( |
66 new media::CdmInitializedPromise(cdm_created_cb, ppapi_decryptor)); | 64 new media::CdmInitializedPromise(cdm_created_cb, ppapi_decryptor)); |
67 | 65 |
68 ppapi_decryptor->InitializeCdm(key_system, allow_distinctive_identifier, | 66 ppapi_decryptor->InitializeCdm(key_system, allow_distinctive_identifier, |
69 allow_persistent_state, std::move(promise)); | 67 allow_persistent_state, std::move(promise)); |
70 } | 68 } |
71 | 69 |
72 PpapiDecryptor::PpapiDecryptor( | 70 PpapiDecryptor::PpapiDecryptor( |
73 std::unique_ptr<PepperCdmWrapper> pepper_cdm_wrapper, | 71 std::unique_ptr<PepperCdmWrapper> pepper_cdm_wrapper, |
74 const media::SessionMessageCB& session_message_cb, | 72 const media::SessionMessageCB& session_message_cb, |
75 const media::SessionClosedCB& session_closed_cb, | 73 const media::SessionClosedCB& session_closed_cb, |
76 const media::LegacySessionErrorCB& legacy_session_error_cb, | |
77 const media::SessionKeysChangeCB& session_keys_change_cb, | 74 const media::SessionKeysChangeCB& session_keys_change_cb, |
78 const media::SessionExpirationUpdateCB& session_expiration_update_cb) | 75 const media::SessionExpirationUpdateCB& session_expiration_update_cb) |
79 : pepper_cdm_wrapper_(std::move(pepper_cdm_wrapper)), | 76 : pepper_cdm_wrapper_(std::move(pepper_cdm_wrapper)), |
80 session_message_cb_(session_message_cb), | 77 session_message_cb_(session_message_cb), |
81 session_closed_cb_(session_closed_cb), | 78 session_closed_cb_(session_closed_cb), |
82 legacy_session_error_cb_(legacy_session_error_cb), | |
83 session_keys_change_cb_(session_keys_change_cb), | 79 session_keys_change_cb_(session_keys_change_cb), |
84 session_expiration_update_cb_(session_expiration_update_cb), | 80 session_expiration_update_cb_(session_expiration_update_cb), |
85 render_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 81 render_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
86 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
87 DCHECK(pepper_cdm_wrapper_.get()); | 83 DCHECK(pepper_cdm_wrapper_.get()); |
88 DCHECK(!session_message_cb_.is_null()); | 84 DCHECK(!session_message_cb_.is_null()); |
89 DCHECK(!session_closed_cb_.is_null()); | 85 DCHECK(!session_closed_cb_.is_null()); |
90 DCHECK(!legacy_session_error_cb_.is_null()); | |
91 DCHECK(!session_keys_change_cb.is_null()); | 86 DCHECK(!session_keys_change_cb.is_null()); |
92 DCHECK(!session_expiration_update_cb.is_null()); | 87 DCHECK(!session_expiration_update_cb.is_null()); |
93 } | 88 } |
94 | 89 |
95 PpapiDecryptor::~PpapiDecryptor() { | 90 PpapiDecryptor::~PpapiDecryptor() { |
96 pepper_cdm_wrapper_.reset(); | 91 pepper_cdm_wrapper_.reset(); |
97 } | 92 } |
98 | 93 |
99 void PpapiDecryptor::InitializeCdm( | 94 void PpapiDecryptor::InitializeCdm( |
100 const std::string& key_system, | 95 const std::string& key_system, |
101 bool allow_distinctive_identifier, | 96 bool allow_distinctive_identifier, |
102 bool allow_persistent_state, | 97 bool allow_persistent_state, |
103 std::unique_ptr<media::SimpleCdmPromise> promise) { | 98 std::unique_ptr<media::SimpleCdmPromise> promise) { |
104 base::WeakPtr<PpapiDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); | 99 base::WeakPtr<PpapiDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); |
105 CdmDelegate()->Initialize( | 100 CdmDelegate()->Initialize( |
106 key_system, allow_distinctive_identifier, allow_persistent_state, | 101 key_system, allow_distinctive_identifier, allow_persistent_state, |
107 base::Bind(&PpapiDecryptor::OnSessionMessage, weak_this), | 102 base::Bind(&PpapiDecryptor::OnSessionMessage, weak_this), |
108 base::Bind(&PpapiDecryptor::OnSessionClosed, weak_this), | 103 base::Bind(&PpapiDecryptor::OnSessionClosed, weak_this), |
109 base::Bind(&PpapiDecryptor::OnLegacySessionError, weak_this), | |
110 base::Bind(&PpapiDecryptor::OnSessionKeysChange, weak_this), | 104 base::Bind(&PpapiDecryptor::OnSessionKeysChange, weak_this), |
111 base::Bind(&PpapiDecryptor::OnSessionExpirationUpdate, weak_this), | 105 base::Bind(&PpapiDecryptor::OnSessionExpirationUpdate, weak_this), |
112 base::Bind(&PpapiDecryptor::OnFatalPluginError, weak_this), | 106 base::Bind(&PpapiDecryptor::OnFatalPluginError, weak_this), |
113 std::move(promise)); | 107 std::move(promise)); |
114 } | 108 } |
115 | 109 |
116 void PpapiDecryptor::SetServerCertificate( | 110 void PpapiDecryptor::SetServerCertificate( |
117 const std::vector<uint8_t>& certificate, | 111 const std::vector<uint8_t>& certificate, |
118 std::unique_ptr<media::SimpleCdmPromise> promise) { | 112 std::unique_ptr<media::SimpleCdmPromise> promise) { |
119 DVLOG(2) << __func__; | 113 DVLOG(2) << __func__; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 DCHECK(!video_decoder_init_cb_.is_null()); | 383 DCHECK(!video_decoder_init_cb_.is_null()); |
390 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); | 384 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); |
391 break; | 385 break; |
392 default: | 386 default: |
393 NOTREACHED(); | 387 NOTREACHED(); |
394 } | 388 } |
395 } | 389 } |
396 | 390 |
397 void PpapiDecryptor::OnSessionMessage(const std::string& session_id, | 391 void PpapiDecryptor::OnSessionMessage(const std::string& session_id, |
398 MessageType message_type, | 392 MessageType message_type, |
399 const std::vector<uint8_t>& message, | 393 const std::vector<uint8_t>& message) { |
400 const GURL& legacy_destination_url) { | |
401 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 394 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
402 session_message_cb_.Run(session_id, message_type, message, | 395 session_message_cb_.Run(session_id, message_type, message); |
403 legacy_destination_url); | |
404 } | 396 } |
405 | 397 |
406 void PpapiDecryptor::OnSessionKeysChange(const std::string& session_id, | 398 void PpapiDecryptor::OnSessionKeysChange(const std::string& session_id, |
407 bool has_additional_usable_key, | 399 bool has_additional_usable_key, |
408 media::CdmKeysInfo keys_info) { | 400 media::CdmKeysInfo keys_info) { |
409 DVLOG(2) << __func__ << ": " << has_additional_usable_key; | 401 DVLOG(2) << __func__ << ": " << has_additional_usable_key; |
410 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 402 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
411 | 403 |
412 // TODO(jrummell): Handling resume playback should be done in the media | 404 // TODO(jrummell): Handling resume playback should be done in the media |
413 // player, not in the Decryptors. http://crbug.com/413413. | 405 // player, not in the Decryptors. http://crbug.com/413413. |
414 if (has_additional_usable_key) | 406 if (has_additional_usable_key) |
415 AttemptToResumePlayback(); | 407 AttemptToResumePlayback(); |
416 | 408 |
417 session_keys_change_cb_.Run(session_id, has_additional_usable_key, | 409 session_keys_change_cb_.Run(session_id, has_additional_usable_key, |
418 std::move(keys_info)); | 410 std::move(keys_info)); |
419 } | 411 } |
420 | 412 |
421 void PpapiDecryptor::OnSessionExpirationUpdate( | 413 void PpapiDecryptor::OnSessionExpirationUpdate( |
422 const std::string& session_id, | 414 const std::string& session_id, |
423 const base::Time& new_expiry_time) { | 415 const base::Time& new_expiry_time) { |
424 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 416 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
425 session_expiration_update_cb_.Run(session_id, new_expiry_time); | 417 session_expiration_update_cb_.Run(session_id, new_expiry_time); |
426 } | 418 } |
427 | 419 |
428 void PpapiDecryptor::OnSessionClosed(const std::string& session_id) { | 420 void PpapiDecryptor::OnSessionClosed(const std::string& session_id) { |
429 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 421 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
430 session_closed_cb_.Run(session_id); | 422 session_closed_cb_.Run(session_id); |
431 } | 423 } |
432 | 424 |
433 void PpapiDecryptor::OnLegacySessionError( | |
434 const std::string& session_id, | |
435 MediaKeys::Exception exception_code, | |
436 uint32_t system_code, | |
437 const std::string& error_description) { | |
438 DCHECK(render_task_runner_->BelongsToCurrentThread()); | |
439 legacy_session_error_cb_.Run(session_id, exception_code, system_code, | |
440 error_description); | |
441 } | |
442 | |
443 void PpapiDecryptor::AttemptToResumePlayback() { | 425 void PpapiDecryptor::AttemptToResumePlayback() { |
444 if (!new_audio_key_cb_.is_null()) | 426 if (!new_audio_key_cb_.is_null()) |
445 new_audio_key_cb_.Run(); | 427 new_audio_key_cb_.Run(); |
446 | 428 |
447 if (!new_video_key_cb_.is_null()) | 429 if (!new_video_key_cb_.is_null()) |
448 new_video_key_cb_.Run(); | 430 new_video_key_cb_.Run(); |
449 } | 431 } |
450 | 432 |
451 void PpapiDecryptor::OnFatalPluginError() { | 433 void PpapiDecryptor::OnFatalPluginError() { |
452 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 434 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
453 pepper_cdm_wrapper_.reset(); | 435 pepper_cdm_wrapper_.reset(); |
454 } | 436 } |
455 | 437 |
456 ContentDecryptorDelegate* PpapiDecryptor::CdmDelegate() { | 438 ContentDecryptorDelegate* PpapiDecryptor::CdmDelegate() { |
457 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 439 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
458 return (pepper_cdm_wrapper_) ? pepper_cdm_wrapper_->GetCdmDelegate() : NULL; | 440 return (pepper_cdm_wrapper_) ? pepper_cdm_wrapper_->GetCdmDelegate() : NULL; |
459 } | 441 } |
460 | 442 |
461 } // namespace content | 443 } // namespace content |
OLD | NEW |