| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 13 #include "content/common/media/cdm_messages.h" |
| 13 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/browser/permission_manager.h" | 17 #include "content/public/browser/permission_manager.h" |
| 17 #include "content/public/browser/permission_type.h" | 18 #include "content/public/browser/permission_type.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "media/base/browser_cdm.h" | 23 #include "media/base/browser_cdm.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 282 |
| 282 void BrowserCdmManager::OnSessionExpirationUpdate( | 283 void BrowserCdmManager::OnSessionExpirationUpdate( |
| 283 int render_frame_id, | 284 int render_frame_id, |
| 284 int cdm_id, | 285 int cdm_id, |
| 285 const std::string& session_id, | 286 const std::string& session_id, |
| 286 const base::Time& new_expiry_time) { | 287 const base::Time& new_expiry_time) { |
| 287 Send(new CdmMsg_SessionExpirationUpdate(render_frame_id, cdm_id, session_id, | 288 Send(new CdmMsg_SessionExpirationUpdate(render_frame_id, cdm_id, session_id, |
| 288 new_expiry_time)); | 289 new_expiry_time)); |
| 289 } | 290 } |
| 290 | 291 |
| 291 void BrowserCdmManager::OnInitializeCdm( | 292 void BrowserCdmManager::OnInitializeCdm(int render_frame_id, |
| 292 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 const CdmHostMsg_InitializeCdm_Params& params) { | 296 const GURL& security_origin) { |
| 296 if (params.key_system.size() > media::limits::kMaxKeySystemLength) { | 297 if (key_system.size() > media::limits::kMaxKeySystemLength) { |
| 297 NOTREACHED() << "Invalid key system: " << params.key_system; | 298 NOTREACHED() << "Invalid key system: " << key_system; |
| 298 RejectPromise(render_frame_id, cdm_id, promise_id, | 299 RejectPromise(render_frame_id, cdm_id, promise_id, |
| 299 MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); | 300 MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); |
| 300 return; | 301 return; |
| 301 } | 302 } |
| 302 | 303 |
| 303 AddCdm(render_frame_id, cdm_id, promise_id, params.key_system, | 304 AddCdm(render_frame_id, cdm_id, promise_id, key_system, security_origin); |
| 304 params.security_origin, params.use_hw_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_hw_secure_codecs) { | |
| 445 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 444 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 446 DCHECK(!GetCdm(render_frame_id, cdm_id)); | 445 DCHECK(!GetCdm(render_frame_id, cdm_id)); |
| 447 | 446 |
| 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 |
| 451 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm( | 464 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm( |
| 452 key_system, use_hw_secure_codecs, | 465 key_system, use_secure_surface, BROWSER_CDM_MANAGER_CB(OnSessionMessage), |
| 453 BROWSER_CDM_MANAGER_CB(OnSessionMessage), | |
| 454 BROWSER_CDM_MANAGER_CB(OnSessionClosed), | 466 BROWSER_CDM_MANAGER_CB(OnSessionClosed), |
| 455 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), | 467 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), |
| 456 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), | 468 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), |
| 457 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate))); | 469 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate))); |
| 458 | 470 |
| 459 if (!cdm) { | 471 if (!cdm) { |
| 460 DVLOG(1) << "failed to create CDM."; | 472 DVLOG(1) << "failed to create CDM."; |
| 461 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "Failed to create CDM."); | 473 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "Failed to create CDM."); |
| 462 return; | 474 return; |
| 463 } | 475 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 } | 578 } |
| 567 | 579 |
| 568 // Only the temporary session type is supported in browser CDM path. | 580 // Only the temporary session type is supported in browser CDM path. |
| 569 // TODO(xhwang): Add SessionType support if needed. | 581 // TODO(xhwang): Add SessionType support if needed. |
| 570 cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, | 582 cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, |
| 571 init_data_type, init_data, | 583 init_data_type, init_data, |
| 572 promise.Pass()); | 584 promise.Pass()); |
| 573 } | 585 } |
| 574 | 586 |
| 575 } // namespace content | 587 } // namespace content |
| OLD | NEW |