webcontentdecryptionmodule_impl.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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.
4
5#include "content/renderer/media/webcontentdecryptionmodule_impl.h"
6
7#include <map>
8#include <vector>
9
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/webcontentdecryptionmodulesession_impl.h"
17#include "media/base/media_keys.h"
18
19#if defined(ENABLE_PEPPER_CDMS)
20#include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
21#endif
22
23namespace content {
24
25WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create(
26    const base::string16& key_system) {
27  // TODO(ddorwin): Guard against this in supported types check and remove this.
28  // Chromium only supports ASCII key systems.
29  if (!IsStringASCII(key_system)) {
30    NOTREACHED();
31    return NULL;
32  }
33
34  scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter());
35  if (!adapter->Initialize(
36#if defined(ENABLE_PEPPER_CDMS)
37          // TODO(jrummell): Figure out how to get a WebFrame from Blink (or
38          // something equivalent) so the plugin can actually get created.
39          // http://crbug.com/250049
40          base::Bind(&PepperCdmWrapperImpl::Create,
41                     static_cast<blink::WebFrame*>(NULL)),
42#endif
43          base::UTF16ToASCII(key_system))) {
44    return NULL;
45  }
46
47  return new WebContentDecryptionModuleImpl(adapter);
48}
49
50WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
51    scoped_refptr<CdmSessionAdapter> adapter)
52    : adapter_(adapter) {
53}
54
55WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() {
56}
57
58// The caller owns the created session.
59blink::WebContentDecryptionModuleSession*
60WebContentDecryptionModuleImpl::createSession(
61    blink::WebContentDecryptionModuleSession::Client* client) {
62  return adapter_->CreateSession(client);
63}
64
65media::Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() {
66  return adapter_->GetDecryptor();
67}
68
69}  // namespace content
70