1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/media/crypto/proxy_decryptor.h"
#include "base/logging.h"
#include "media/base/decoder_buffer.h"
#include "media/base/decryptor_client.h"
#include "media/crypto/aes_decryptor.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "webkit/media/crypto/key_systems.h"
#include "webkit/media/crypto/ppapi_decryptor.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
// TODO(xhwang): Put this include after "ppapi_plugin_instance.h" for definition
// of "uint8_t", which WebMediaPlayer.h uses without including a header for it.
// See: https://bugs.webkit.org/show_bug.cgi?id=92031
// Fix include order here when the bug is fixed.
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.h"
namespace webkit_media {
static scoped_refptr<webkit::ppapi::PluginInstance> CreatePluginInstance(
const std::string& plugin_type,
WebKit::WebMediaPlayerClient* web_media_player_client,
WebKit::WebFrame* web_frame) {
DCHECK(web_media_player_client);
DCHECK(web_frame);
WebKit::WebPlugin* web_plugin = web_media_player_client->createHelperPlugin(
WebKit::WebString::fromUTF8(plugin_type), web_frame);
if (!web_plugin)
return NULL;
DCHECK(!web_plugin->isPlaceholder()); // Prevented by WebKit.
// Only Pepper plugins are supported, so it must be a ppapi object.
webkit::ppapi::WebPluginImpl* ppapi_plugin =
static_cast<webkit::ppapi::WebPluginImpl*>(web_plugin);
return ppapi_plugin->instance();
}
ProxyDecryptor::ProxyDecryptor(
media::DecryptorClient* decryptor_client,
WebKit::WebMediaPlayerClient* web_media_player_client,
WebKit::WebFrame* web_frame)
: client_(decryptor_client),
web_media_player_client_(web_media_player_client),
web_frame_(web_frame) {
}
ProxyDecryptor::~ProxyDecryptor() {
}
void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system,
const uint8* init_data,
int init_data_length) {
// We do not support run-time switching of decryptors. GenerateKeyRequest()
// only creates a new decryptor when |decryptor_| is not initialized.
if (!decryptor_.get()) {
base::AutoLock auto_lock(lock_);
decryptor_ = CreateDecryptor(key_system);
}
DCHECK(client_);
if (!decryptor_.get()) {
client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0);
return;
}
decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length);
}
void ProxyDecryptor::AddKey(const std::string& key_system,
const uint8* key,
int key_length,
const uint8* init_data,
int init_data_length,
const std::string& session_id) {
// WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
DCHECK(decryptor_.get());
decryptor_->AddKey(key_system, key, key_length, init_data, init_data_length,
session_id);
}
void ProxyDecryptor::CancelKeyRequest(const std::string& key_system,
const std::string& session_id) {
// WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
DCHECK(decryptor_.get());
decryptor_->CancelKeyRequest(key_system, session_id);
}
void ProxyDecryptor::Decrypt(
const scoped_refptr<media::DecoderBuffer>& encrypted,
const DecryptCB& decrypt_cb) {
// This is safe as we do not replace/delete an existing decryptor at run-time.
media::Decryptor* decryptor = NULL;
{
base::AutoLock auto_lock(lock_);
decryptor = decryptor_.get();
}
if (!decryptor) {
DVLOG(1) << "ProxyDecryptor::Decrypt(): decryptor not initialized.";
decrypt_cb.Run(kError, NULL);
return;
}
decryptor->Decrypt(encrypted, decrypt_cb);
}
scoped_ptr<media::Decryptor> ProxyDecryptor::CreatePpapiDecryptor(
const std::string& key_system) {
DCHECK(client_);
DCHECK(web_media_player_client_);
DCHECK(web_frame_);
std::string plugin_type = GetPluginType(key_system);
DCHECK(!plugin_type.empty());
const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance =
CreatePluginInstance(plugin_type, web_media_player_client_, web_frame_);
if (!plugin_instance) {
DVLOG(1) << "PpapiDecryptor: plugin instance creation failed.";
return scoped_ptr<media::Decryptor>();
}
return scoped_ptr<media::Decryptor>(new PpapiDecryptor(client_,
plugin_instance));
}
scoped_ptr<media::Decryptor> ProxyDecryptor::CreateDecryptor(
const std::string& key_system) {
DCHECK(client_);
if (CanUseAesDecryptor(key_system))
return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client_));
// We only support AesDecryptor and PpapiDecryptor. So if we cannot
// use the AesDecryptor, then we'll try to create a PpapiDecryptor for given
// |key_system|.
return CreatePpapiDecryptor(key_system);
}
} // namespace webkit_media
|