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/webcontentdecryptionmodule_impl.h"
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "content/renderer/media/cdm_session_adapter.h"
16 #include "content/renderer/media/crypto/key_systems.h"
17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
18 #include "media/base/media_keys.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
23 #if defined(ENABLE_PEPPER_CDMS)
24 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
29 WebContentDecryptionModuleImpl
* WebContentDecryptionModuleImpl::Create(
30 #if defined(ENABLE_PEPPER_CDMS)
31 blink::WebLocalFrame
* frame
,
32 #elif defined(ENABLE_BROWSER_CDMS)
33 RendererCdmManager
* manager
,
35 const blink::WebSecurityOrigin
& security_origin
,
36 const base::string16
& key_system
) {
37 #if defined(ENABLE_PEPPER_CDMS)
39 #elif defined(ENABLE_BROWSER_CDMS)
42 DCHECK(!security_origin
.isNull());
43 DCHECK(!key_system
.empty());
45 // TODO(ddorwin): Guard against this in supported types check and remove this.
46 // Chromium only supports ASCII key systems.
47 if (!base::IsStringASCII(key_system
)) {
52 std::string key_system_ascii
= base::UTF16ToASCII(key_system
);
53 if (!IsConcreteSupportedKeySystem(key_system_ascii
))
56 // If unique security origin, don't try to create the CDM.
57 if (security_origin
.isUnique() || security_origin
.toString() == "null") {
58 DLOG(ERROR
) << "CDM use not allowed for unique security origin.";
62 scoped_refptr
<CdmSessionAdapter
> adapter(new CdmSessionAdapter());
63 GURL
security_origin_as_gurl(security_origin
.toString());
65 if (!adapter
->Initialize(
66 #if defined(ENABLE_PEPPER_CDMS)
67 base::Bind(&PepperCdmWrapperImpl::Create
, frame
),
68 #elif defined(ENABLE_BROWSER_CDMS)
72 security_origin_as_gurl
)) {
76 return new WebContentDecryptionModuleImpl(adapter
);
79 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
80 scoped_refptr
<CdmSessionAdapter
> adapter
)
81 : adapter_(adapter
) {}
83 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() {
86 // The caller owns the created session.
87 blink::WebContentDecryptionModuleSession
*
88 WebContentDecryptionModuleImpl::createSession() {
89 return adapter_
->CreateSession();
92 blink::WebContentDecryptionModuleSession
*
93 WebContentDecryptionModuleImpl::createSession(
94 blink::WebContentDecryptionModuleSession::Client
* client
) {
95 WebContentDecryptionModuleSessionImpl
* session
= adapter_
->CreateSession();
96 session
->setClientInterface(client
);
100 media::Decryptor
* WebContentDecryptionModuleImpl::GetDecryptor() {
101 return adapter_
->GetDecryptor();
104 #if defined(ENABLE_BROWSER_CDMS)
105 int WebContentDecryptionModuleImpl::GetCdmId() const {
106 return adapter_
->GetCdmId();
108 #endif // defined(ENABLE_BROWSER_CDMS)
110 } // namespace content