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