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"
33 WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create(
34 blink::WebLocalFrame* frame,
35 const blink::WebSecurityOrigin& security_origin,
36 const base::string16& key_system) {
38 DCHECK(!security_origin.isNull());
39 DCHECK(!key_system.empty());
41 // TODO(ddorwin): Guard against this in supported types check and remove this.
42 // Chromium only supports ASCII key systems.
43 if (!base::IsStringASCII(key_system)) {
48 std::string key_system_ascii = base::UTF16ToASCII(key_system);
49 if (!IsConcreteSupportedKeySystem(key_system_ascii))
52 // If unique security origin, don't try to create the CDM.
53 if (security_origin.isUnique() || security_origin.toString() == "null") {
54 DLOG(ERROR) << "CDM use not allowed for unique security origin.";
58 scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter());
59 GURL security_origin_as_gurl(security_origin.toString());
61 if (!adapter->Initialize(
62 #if defined(ENABLE_PEPPER_CDMS)
63 base::Bind(&PepperCdmWrapperImpl::Create, frame),
66 security_origin_as_gurl)) {
70 return new WebContentDecryptionModuleImpl(adapter);
73 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
74 scoped_refptr<CdmSessionAdapter> adapter)
75 : adapter_(adapter) {}
77 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() {
80 // The caller owns the created session.
81 blink::WebContentDecryptionModuleSession*
82 WebContentDecryptionModuleImpl::createSession(
83 blink::WebContentDecryptionModuleSession::Client* client) {
84 return adapter_->CreateSession(client);
87 media::Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() {
88 return adapter_->GetDecryptor();
91 #if defined(OS_ANDROID)
92 int WebContentDecryptionModuleImpl::GetCdmId() const {
93 return adapter_->GetCdmId();
95 #endif // defined(OS_ANDROID)
97 } // namespace content