Chromium Code Reviews| 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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/browser/permission_manager.h" | 17 #include "content/public/browser/permission_manager.h" |
| 18 #include "content/public/browser/permission_type.h" | 18 #include "content/public/browser/permission_type.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_process_host_observer.h" | 21 #include "content/public/browser/render_process_host_observer.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "media/base/cdm_config.h" | 23 #include "media/base/cdm_config.h" |
| 24 #include "media/base/cdm_factory.h" | 24 #include "media/base/cdm_factory.h" |
| 25 #include "media/base/cdm_promise.h" | 25 #include "media/base/cdm_promise.h" |
| 26 #include "media/base/limits.h" | 26 #include "media/base/limits.h" |
| 27 | 27 |
| 28 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 29 #include "content/browser/media/android/url_provision_fetcher.h" | |
| 29 #include "content/public/common/renderer_preferences.h" | 30 #include "content/public/common/renderer_preferences.h" |
| 30 #include "media/base/android/android_cdm_factory.h" | 31 #include "media/base/android/android_cdm_factory.h" |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 | 35 |
| 35 using media::MediaKeys; | 36 using media::MediaKeys; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 MediaKeys::Exception exception, | 269 MediaKeys::Exception exception, |
| 269 uint32_t system_code, | 270 uint32_t system_code, |
| 270 const std::string& error_message) { | 271 const std::string& error_message) { |
| 271 Send(new CdmMsg_RejectPromise(render_frame_id, cdm_id, promise_id, exception, | 272 Send(new CdmMsg_RejectPromise(render_frame_id, cdm_id, promise_id, exception, |
| 272 system_code, error_message)); | 273 system_code, error_message)); |
| 273 } | 274 } |
| 274 | 275 |
| 275 media::CdmFactory* BrowserCdmManager::GetCdmFactory() { | 276 media::CdmFactory* BrowserCdmManager::GetCdmFactory() { |
| 276 if (!cdm_factory_) { | 277 if (!cdm_factory_) { |
| 277 // Create a new CdmFactory. | 278 // Create a new CdmFactory. |
| 279 #if defined(OS_ANDROID) | |
| 280 cdm_factory_.reset(new media::AndroidCdmFactory()); | |
| 281 #else | |
|
xhwang
2015/11/11 09:53:21
Why making this change? Different embedders could
Tima Vaisburd
2015/11/11 23:26:35
Restored your original code and passed ProvisionFe
| |
| 278 cdm_factory_ = GetContentClient()->browser()->CreateCdmFactory(); | 282 cdm_factory_ = GetContentClient()->browser()->CreateCdmFactory(); |
| 279 | |
| 280 #if defined(OS_ANDROID) | |
| 281 if (!cdm_factory_) | |
| 282 cdm_factory_.reset(new media::AndroidCdmFactory()); | |
| 283 #endif | 283 #endif |
| 284 } | 284 } |
| 285 | 285 |
| 286 return cdm_factory_.get(); | 286 return cdm_factory_.get(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void BrowserCdmManager::OnSessionMessage(int render_frame_id, | 289 void BrowserCdmManager::OnSessionMessage(int render_frame_id, |
| 290 int cdm_id, | 290 int cdm_id, |
| 291 const std::string& session_id, | 291 const std::string& session_id, |
| 292 MediaKeys::MessageType message_type, | 292 MediaKeys::MessageType message_type, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); | 365 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Invalid key system."); |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 | 368 |
| 369 if (!GetCdmFactory()) { | 369 if (!GetCdmFactory()) { |
| 370 NOTREACHED() << "CDM not supported."; | 370 NOTREACHED() << "CDM not supported."; |
| 371 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "CDM not supported."); | 371 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "CDM not supported."); |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 | 374 |
| 375 media::CdmFactory* cdm_factory = GetCdmFactory(); | |
| 376 DCHECK(cdm_factory); | |
| 377 | |
| 378 #if defined(OS_ANDROID) | |
| 379 // Create ProvisionFetcher based on render process context. | |
| 380 net::URLRequestContextGetter* context = | |
| 381 RenderProcessHost::FromID(render_process_id_) | |
| 382 ->GetBrowserContext() | |
| 383 ->GetRequestContext(); | |
| 384 DCHECK(context); | |
| 385 scoped_ptr<media::ProvisionFetcher> provision_fetcher( | |
| 386 new URLProvisionFetcher(context)); | |
| 387 | |
| 388 // Attach |provision_fetcher| to Android CDM factory. | |
| 389 media::AndroidCdmFactory* android_cdm_factory = | |
| 390 static_cast<media::AndroidCdmFactory*>(cdm_factory); | |
| 391 android_cdm_factory->SetProvisionFetcher(provision_fetcher.Pass()); | |
| 392 #endif // OS_ANDROID | |
| 393 | |
| 375 // The render process makes sure |allow_distinctive_identifier| and | 394 // The render process makes sure |allow_distinctive_identifier| and |
| 376 // |allow_persistent_state| are true. See RenderCdmFactory::Create(). | 395 // |allow_persistent_state| are true. See RenderCdmFactory::Create(). |
| 377 // TODO(xhwang): Pass |allow_distinctive_identifier| and | 396 // TODO(xhwang): Pass |allow_distinctive_identifier| and |
| 378 // |allow_persistent_state| from the render process. | 397 // |allow_persistent_state| from the render process. |
| 379 media::CdmConfig cdm_config; | 398 media::CdmConfig cdm_config; |
| 380 cdm_config.allow_distinctive_identifier = true; | 399 cdm_config.allow_distinctive_identifier = true; |
| 381 cdm_config.allow_persistent_state = true; | 400 cdm_config.allow_persistent_state = true; |
| 382 cdm_config.use_hw_secure_codecs = params.use_hw_secure_codecs; | 401 cdm_config.use_hw_secure_codecs = params.use_hw_secure_codecs; |
| 383 | 402 |
| 384 GetCdmFactory()->Create( | 403 cdm_factory->Create( |
| 385 params.key_system, params.security_origin, cdm_config, | 404 params.key_system, params.security_origin, cdm_config, |
| 386 BROWSER_CDM_MANAGER_CB(OnSessionMessage), | 405 BROWSER_CDM_MANAGER_CB(OnSessionMessage), |
| 387 BROWSER_CDM_MANAGER_CB(OnSessionClosed), | 406 BROWSER_CDM_MANAGER_CB(OnSessionClosed), |
| 388 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), | 407 BROWSER_CDM_MANAGER_CB(OnLegacySessionError), |
| 389 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), | 408 BROWSER_CDM_MANAGER_CB(OnSessionKeysChange), |
| 390 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate), | 409 BROWSER_CDM_MANAGER_CB(OnSessionExpirationUpdate), |
| 391 BROWSER_CDM_MANAGER_CB(OnCdmCreated, params.security_origin, | 410 BROWSER_CDM_MANAGER_CB(OnCdmCreated, params.security_origin, |
| 392 base::Passed(&promise))); | 411 base::Passed(&promise))); |
| 393 } | 412 } |
| 394 | 413 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); | 728 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); |
| 710 if (!cdm) { | 729 if (!cdm) { |
| 711 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 730 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 712 return; | 731 return; |
| 713 } | 732 } |
| 714 | 733 |
| 715 cdm->LoadSession(session_type, session_id, promise.Pass()); | 734 cdm->LoadSession(session_type, session_id, promise.Pass()); |
| 716 } | 735 } |
| 717 | 736 |
| 718 } // namespace content | 737 } // namespace content |
| OLD | NEW |