| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/media/cdm/browser_cdm_manager.h" | 5 #include "content/browser/media/cdm/browser_cdm_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 282 |
| 283 void BrowserCdmManager::OnSessionExpirationUpdate( | 283 void BrowserCdmManager::OnSessionExpirationUpdate( |
| 284 int render_frame_id, | 284 int render_frame_id, |
| 285 int cdm_id, | 285 int cdm_id, |
| 286 const std::string& session_id, | 286 const std::string& session_id, |
| 287 const base::Time& new_expiry_time) { | 287 const base::Time& new_expiry_time) { |
| 288 Send(new CdmMsg_SessionExpirationUpdate(render_frame_id, cdm_id, session_id, | 288 Send(new CdmMsg_SessionExpirationUpdate(render_frame_id, cdm_id, session_id, |
| 289 new_expiry_time)); | 289 new_expiry_time)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void BrowserCdmManager::OnInitializeCdm(int render_frame_id, | 292 void BrowserCdmManager::OnInitializeCdm( |
| 293 int cdm_id, | 293 int render_frame_id, |
| 294 uint32_t promise_id, | 294 int cdm_id, |
| 295 const std::string& key_system, | 295 uint32_t promise_id, |
| 296 const GURL& security_origin) { | 296 const CdmHostMsg_InitializeCdm_Params& params) { |
| 297 if (key_system.size() > media::limits::kMaxKeySystemLength) { | 297 if (params.key_system.size() > media::limits::kMaxKeySystemLength) { |
| 298 NOTREACHED() << "Invalid key system: " << key_system; | 298 NOTREACHED() << "Invalid key system: " << params.key_system; |
| 299 RejectPromise(render_frame_id, cdm_id, promise_id, | 299 RejectPromise(render_frame_id, cdm_id, promise_id, |
| 300 MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); | 300 MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 | 303 |
| 304 AddCdm(render_frame_id, cdm_id, promise_id, key_system, security_origin); | 304 AddCdm(render_frame_id, cdm_id, promise_id, params.key_system, |
| 305 params.security_origin, parameters.use_hw_secure_codecs); |
| 305 } | 306 } |
| 306 | 307 |
| 307 void BrowserCdmManager::OnSetServerCertificate( | 308 void BrowserCdmManager::OnSetServerCertificate( |
| 308 int render_frame_id, | 309 int render_frame_id, |
| 309 int cdm_id, | 310 int cdm_id, |
| 310 uint32_t promise_id, | 311 uint32_t promise_id, |
| 311 const std::vector<uint8_t>& certificate) { | 312 const std::vector<uint8_t>& certificate) { |
| 312 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 313 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 313 | 314 |
| 314 scoped_ptr<SimplePromise> promise( | 315 scoped_ptr<SimplePromise> promise( |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 434 |
| 434 // Use a weak pointer here instead of |this| to avoid circular references. | 435 // Use a weak pointer here instead of |this| to avoid circular references. |
| 435 #define BROWSER_CDM_MANAGER_CB(func) \ | 436 #define BROWSER_CDM_MANAGER_CB(func) \ |
| 436 base::Bind(&BrowserCdmManager::func, weak_ptr_factory_.GetWeakPtr(), \ | 437 base::Bind(&BrowserCdmManager::func, weak_ptr_factory_.GetWeakPtr(), \ |
| 437 render_frame_id, cdm_id) | 438 render_frame_id, cdm_id) |
| 438 | 439 |
| 439 void BrowserCdmManager::AddCdm(int render_frame_id, | 440 void BrowserCdmManager::AddCdm(int render_frame_id, |
| 440 int cdm_id, | 441 int cdm_id, |
| 441 uint32_t promise_id, | 442 uint32_t promise_id, |
| 442 const std::string& key_system, | 443 const std::string& key_system, |
| 443 const GURL& security_origin) { | 444 const GURL& security_origin, |
| 445 bool use_hw_secure_codecs) { |
| 444 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 446 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 445 DCHECK(!GetCdm(render_frame_id, cdm_id)); | 447 DCHECK(!GetCdm(render_frame_id, cdm_id)); |
| 446 | 448 |
| 447 bool use_secure_surface = false; | |
| 448 scoped_ptr<SimplePromise> promise( | 449 scoped_ptr<SimplePromise> promise( |
| 449 new SimplePromise(this, render_frame_id, cdm_id, promise_id)); | 450 new SimplePromise(this, render_frame_id, cdm_id, promise_id)); |
| 450 | 451 |
| 451 #if defined(OS_ANDROID) | |
| 452 // TODO(sandersd): Pass the security level from key system instead. | |
| 453 // http://crbug.com/467779 | |
| 454 RenderFrameHost* rfh = | |
| 455 RenderFrameHost::FromID(render_process_id_, render_frame_id); | |
| 456 WebContents* web_contents = WebContents::FromRenderFrameHost(rfh); | |
| 457 if (web_contents) { | |
| 458 content::RendererPreferences* prefs = | |
| 459 web_contents->GetMutableRendererPrefs(); | |
| 460 use_secure_surface = prefs->use_video_overlay_for_embedded_encrypted_video; | |
| 461 } | |
| 462 #endif | |
| 463 | |
| 464 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm( | 452 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm( |
| 465 key_system, use_secure_surface, BROWSER_CDM_MANAGER_CB(OnSessionMessage), | 453 key_system, use_hw_secure_codecs, |
| 454 BROWSER_CDM_MANAGER_CB(OnSessionMessage), |
| 466 BROWSER_CDM_MANAGER_CB(OnSessionClosed), | 455 BROWSER_CDM_MANAGER_CB(OnSessionClosed), |
| 467 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), | 456 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), |
| 468 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), | 457 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), |
| 469 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate))); | 458 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate))); |
| 470 | 459 |
| 471 if (!cdm) { | 460 if (!cdm) { |
| 472 DVLOG(1) << "failed to create CDM."; | 461 DVLOG(1) << "failed to create CDM."; |
| 473 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "Failed to create CDM."); | 462 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "Failed to create CDM."); |
| 474 return; | 463 return; |
| 475 } | 464 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 567 } |
| 579 | 568 |
| 580 // Only the temporary session type is supported in browser CDM path. | 569 // Only the temporary session type is supported in browser CDM path. |
| 581 // TODO(xhwang): Add SessionType support if needed. | 570 // TODO(xhwang): Add SessionType support if needed. |
| 582 cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, | 571 cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, |
| 583 init_data_type, init_data, | 572 init_data_type, init_data, |
| 584 promise.Pass()); | 573 promise.Pass()); |
| 585 } | 574 } |
| 586 | 575 |
| 587 } // namespace content | 576 } // namespace content |
| OLD | NEW |