| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(int render_frame_id, |
| 293 int cdm_id, | 293 int cdm_id, |
| 294 uint32_t promise_id, | 294 uint32_t promise_id, |
| 295 const std::string& key_system, | 295 InitializeCdmParameters& parameters) { |
| 296 const GURL& security_origin) { | 296 if (parameters.key_system.size() > media::limits::kMaxKeySystemLength) { |
| 297 if (key_system.size() > media::limits::kMaxKeySystemLength) { | 297 NOTREACHED() << "Invalid key system: " << parameters.key_system; |
| 298 NOTREACHED() << "Invalid key system: " << key_system; | |
| 299 RejectPromise(render_frame_id, cdm_id, promise_id, | 298 RejectPromise(render_frame_id, cdm_id, promise_id, |
| 300 MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); | 299 MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); |
| 301 return; | 300 return; |
| 302 } | 301 } |
| 303 | 302 |
| 304 AddCdm(render_frame_id, cdm_id, promise_id, key_system, security_origin); | 303 AddCdm(render_frame_id, cdm_id, promise_id, parameters.key_system, |
| 304 parameters.security_origin, parameters.use_secure_codecs); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void BrowserCdmManager::OnSetServerCertificate( | 307 void BrowserCdmManager::OnSetServerCertificate( |
| 308 int render_frame_id, | 308 int render_frame_id, |
| 309 int cdm_id, | 309 int cdm_id, |
| 310 uint32_t promise_id, | 310 uint32_t promise_id, |
| 311 const std::vector<uint8_t>& certificate) { | 311 const std::vector<uint8_t>& certificate) { |
| 312 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 312 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 313 | 313 |
| 314 scoped_ptr<SimplePromise> promise( | 314 scoped_ptr<SimplePromise> promise( |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 // Use a weak pointer here instead of |this| to avoid circular references. | 434 // Use a weak pointer here instead of |this| to avoid circular references. |
| 435 #define BROWSER_CDM_MANAGER_CB(func) \ | 435 #define BROWSER_CDM_MANAGER_CB(func) \ |
| 436 base::Bind(&BrowserCdmManager::func, weak_ptr_factory_.GetWeakPtr(), \ | 436 base::Bind(&BrowserCdmManager::func, weak_ptr_factory_.GetWeakPtr(), \ |
| 437 render_frame_id, cdm_id) | 437 render_frame_id, cdm_id) |
| 438 | 438 |
| 439 void BrowserCdmManager::AddCdm(int render_frame_id, | 439 void BrowserCdmManager::AddCdm(int render_frame_id, |
| 440 int cdm_id, | 440 int cdm_id, |
| 441 uint32_t promise_id, | 441 uint32_t promise_id, |
| 442 const std::string& key_system, | 442 const std::string& key_system, |
| 443 const GURL& security_origin) { | 443 const GURL& security_origin, |
| 444 bool use_secure_codecs) { |
| 444 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 445 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 445 DCHECK(!GetCdm(render_frame_id, cdm_id)); | 446 DCHECK(!GetCdm(render_frame_id, cdm_id)); |
| 446 | 447 |
| 447 bool use_secure_surface = false; | |
| 448 scoped_ptr<SimplePromise> promise( | 448 scoped_ptr<SimplePromise> promise( |
| 449 new SimplePromise(this, render_frame_id, cdm_id, promise_id)); | 449 new SimplePromise(this, render_frame_id, cdm_id, promise_id)); |
| 450 | 450 |
| 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( | 451 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm( |
| 465 key_system, use_secure_surface, BROWSER_CDM_MANAGER_CB(OnSessionMessage), | 452 key_system, use_secure_codecs, BROWSER_CDM_MANAGER_CB(OnSessionMessage), |
| 466 BROWSER_CDM_MANAGER_CB(OnSessionClosed), | 453 BROWSER_CDM_MANAGER_CB(OnSessionClosed), |
| 467 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), | 454 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), |
| 468 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), | 455 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), |
| 469 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate))); | 456 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate))); |
| 470 | 457 |
| 471 if (!cdm) { | 458 if (!cdm) { |
| 472 DVLOG(1) << "failed to create CDM."; | 459 DVLOG(1) << "failed to create CDM."; |
| 473 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "Failed to create CDM."); | 460 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "Failed to create CDM."); |
| 474 return; | 461 return; |
| 475 } | 462 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 565 } |
| 579 | 566 |
| 580 // Only the temporary session type is supported in browser CDM path. | 567 // Only the temporary session type is supported in browser CDM path. |
| 581 // TODO(xhwang): Add SessionType support if needed. | 568 // TODO(xhwang): Add SessionType support if needed. |
| 582 cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, | 569 cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, |
| 583 init_data_type, init_data, | 570 init_data_type, init_data, |
| 584 promise.Pass()); | 571 promise.Pass()); |
| 585 } | 572 } |
| 586 | 573 |
| 587 } // namespace content | 574 } // namespace content |
| OLD | NEW |