1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/media/crypto/render_cdm_factory.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "media/base/cdm_config.h"
14 #include "media/base/cdm_promise.h"
15 #include "media/base/key_systems.h"
16 #include "media/base/media_keys.h"
17 #include "media/cdm/aes_decryptor.h"
19 #if defined(ENABLE_PEPPER_CDMS)
20 #include "content/renderer/media/crypto/ppapi_decryptor.h"
21 #elif defined(ENABLE_BROWSER_CDMS)
22 #include "content/renderer/media/crypto/proxy_media_keys.h"
23 #endif // defined(ENABLE_PEPPER_CDMS)
27 #if defined(ENABLE_PEPPER_CDMS)
28 RenderCdmFactory::RenderCdmFactory(
29 const CreatePepperCdmCB
& create_pepper_cdm_cb
)
30 : create_pepper_cdm_cb_(create_pepper_cdm_cb
) {
32 #elif defined(ENABLE_BROWSER_CDMS)
33 RenderCdmFactory::RenderCdmFactory(RendererCdmManager
* manager
)
37 RenderCdmFactory::RenderCdmFactory() {
39 #endif // defined(ENABLE_PEPPER_CDMS)
41 RenderCdmFactory::~RenderCdmFactory() {
42 DCHECK(thread_checker_
.CalledOnValidThread());
45 void RenderCdmFactory::Create(
46 const std::string
& key_system
,
47 const GURL
& security_origin
,
48 const media::CdmConfig
& cdm_config
,
49 const media::SessionMessageCB
& session_message_cb
,
50 const media::SessionClosedCB
& session_closed_cb
,
51 const media::LegacySessionErrorCB
& legacy_session_error_cb
,
52 const media::SessionKeysChangeCB
& session_keys_change_cb
,
53 const media::SessionExpirationUpdateCB
& session_expiration_update_cb
,
54 const media::CdmCreatedCB
& cdm_created_cb
) {
55 DCHECK(thread_checker_
.CalledOnValidThread());
57 if (!security_origin
.is_valid()) {
58 base::ThreadTaskRunnerHandle::Get()->PostTask(
59 FROM_HERE
, base::Bind(cdm_created_cb
, nullptr, "Invalid origin."));
63 if (media::CanUseAesDecryptor(key_system
)) {
64 // TODO(sandersd): Currently the prefixed API always allows distinctive
65 // identifiers and persistent state. Once that changes we can sanity check
66 // here that neither is allowed for AesDecryptor, since it does not support
67 // them and should never be configured that way. http://crbug.com/455271
68 scoped_ptr
<media::MediaKeys
> cdm(
69 new media::AesDecryptor(security_origin
, session_message_cb
,
70 session_closed_cb
, session_keys_change_cb
));
71 base::ThreadTaskRunnerHandle::Get()->PostTask(
72 FROM_HERE
, base::Bind(cdm_created_cb
, base::Passed(&cdm
), ""));
76 #if defined(ENABLE_PEPPER_CDMS)
77 DCHECK(!cdm_config
.use_hw_secure_codecs
);
78 PpapiDecryptor::Create(
79 key_system
, security_origin
, cdm_config
.allow_distinctive_identifier
,
80 cdm_config
.allow_persistent_state
, create_pepper_cdm_cb_
,
81 session_message_cb
, session_closed_cb
, legacy_session_error_cb
,
82 session_keys_change_cb
, session_expiration_update_cb
, cdm_created_cb
);
83 #elif defined(ENABLE_BROWSER_CDMS)
84 DCHECK(cdm_config
.allow_distinctive_identifier
);
85 DCHECK(cdm_config
.allow_persistent_state
);
86 ProxyMediaKeys::Create(
87 key_system
, security_origin
, cdm_config
.use_hw_secure_codecs
, manager_
,
88 session_message_cb
, session_closed_cb
, legacy_session_error_cb
,
89 session_keys_change_cb
, session_expiration_update_cb
, cdm_created_cb
);
91 // No possible CDM to create, so fail the request.
92 base::ThreadTaskRunnerHandle::Get()->PostTask(
94 base::Bind(cdm_created_cb
, nullptr, "Key system not supported."));
95 #endif // defined(ENABLE_PEPPER_CDMS)
98 } // namespace content