Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: webkit/media/crypto/proxy_decryptor.cc

Issue 10704241: Add PpapiDecryptor which wraps a CDM plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/media/crypto/proxy_decryptor.h ('k') | webkit/media/webkit_media.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/media/crypto/proxy_decryptor.h" 5 #include "webkit/media/crypto/proxy_decryptor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/decoder_buffer.h" 8 #include "media/base/decoder_buffer.h"
9 #include "media/base/decryptor_client.h" 9 #include "media/base/decryptor_client.h"
10 #include "media/crypto/aes_decryptor.h" 10 #include "media/crypto/aes_decryptor.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
11 #include "webkit/media/crypto/key_systems.h" 14 #include "webkit/media/crypto/key_systems.h"
15 #include "webkit/media/crypto/ppapi_decryptor.h"
16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
17 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
12 18
13 namespace webkit_media { 19 namespace webkit_media {
14 20
15 ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client) 21 static scoped_refptr<webkit::ppapi::PluginInstance> CreatePluginInstance(
16 : client_(client) { 22 const std::string& plugin_type,
23 WebKit::WebMediaPlayerClient* web_media_player_client,
24 WebKit::WebFrame* web_frame) {
25 DCHECK(web_media_player_client);
26 DCHECK(web_frame);
27
28 WebKit::WebPlugin* web_plugin = web_media_player_client->createHelperPlugin(
29 WebKit::WebString::fromUTF8(plugin_type), web_frame);
30 if (!web_plugin)
31 return NULL;
32
33 DCHECK(!web_plugin->isPlaceholder()); // Prevented by WebKit.
34 // Only Pepper plugins are supported, so it must be a ppapi object.
35 webkit::ppapi::WebPluginImpl* ppapi_plugin =
36 static_cast<webkit::ppapi::WebPluginImpl*>(web_plugin);
37 return ppapi_plugin->instance();
38 }
39
40 ProxyDecryptor::ProxyDecryptor(
41 media::DecryptorClient* decryptor_client,
42 WebKit::WebMediaPlayerClient* web_media_player_client,
43 WebKit::WebFrame* web_frame)
44 : client_(decryptor_client),
45 web_media_player_client_(web_media_player_client),
46 web_frame_(web_frame) {
17 } 47 }
18 48
19 ProxyDecryptor::~ProxyDecryptor() { 49 ProxyDecryptor::~ProxyDecryptor() {
20 } 50 }
21 51
22 void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, 52 void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system,
23 const uint8* init_data, 53 const uint8* init_data,
24 int init_data_length) { 54 int init_data_length) {
25 // We do not support run-time switching of decryptors. GenerateKeyRequest() 55 // We do not support run-time switching of decryptors. GenerateKeyRequest()
26 // only creates a new decryptor when |decryptor_| is not initialized. 56 // only creates a new decryptor when |decryptor_| is not initialized.
27 if (!decryptor_.get()) { 57 if (!decryptor_.get()) {
28 base::AutoLock auto_lock(lock_); 58 base::AutoLock auto_lock(lock_);
29 decryptor_ = CreateDecryptor(key_system, client_); 59 decryptor_ = CreateDecryptor(key_system);
30 } 60 }
31 61
32 DCHECK(decryptor_.get()); 62 DCHECK(client_);
63 if (!decryptor_.get()) {
64 // TODO(ddorwin): Update the spec about generateKeyRequest to include an
65 // error for handler loading failure. In our case, this can happen when the
66 // plugin cannot be loaded.
67 client_->KeyError(key_system, "", Decryptor::kUnknownError, 0);
68 return;
69 }
70
33 decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); 71 decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length);
34 } 72 }
35 73
36 void ProxyDecryptor::AddKey(const std::string& key_system, 74 void ProxyDecryptor::AddKey(const std::string& key_system,
37 const uint8* key, 75 const uint8* key,
38 int key_length, 76 int key_length,
39 const uint8* init_data, 77 const uint8* init_data,
40 int init_data_length, 78 int init_data_length,
41 const std::string& session_id) { 79 const std::string& session_id) {
42 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. 80 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
(...skipping 17 matching lines...) Expand all
60 { 98 {
61 base::AutoLock auto_lock(lock_); 99 base::AutoLock auto_lock(lock_);
62 decryptor = decryptor_.get(); 100 decryptor = decryptor_.get();
63 } 101 }
64 if (!decryptor) 102 if (!decryptor)
65 decrypt_cb.Run(kError, NULL); 103 decrypt_cb.Run(kError, NULL);
66 104
67 return decryptor->Decrypt(encrypted, decrypt_cb); 105 return decryptor->Decrypt(encrypted, decrypt_cb);
68 } 106 }
69 107
108 scoped_ptr<media::Decryptor> ProxyDecryptor::CreatePpapiDecryptor(
109 const std::string& key_system) {
110 DCHECK(client_);
111 DCHECK(web_media_player_client_);
112 DCHECK(web_frame_);
113
114 std::string plugin_type = GetPluginType(key_system);
115 DCHECK(!plugin_type.empty());
116 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance =
117 CreatePluginInstance(plugin_type, web_media_player_client_, web_frame_);
118 if (!plugin_instance) {
119 DVLOG(1) << "PpapiDecryptor: plugin instance creation failed.";
120 return scoped_ptr<media::Decryptor>();
121 }
122
123 return scoped_ptr<Decryptor>(new PpapiDecryptor(client_, plugin_instance));
ddorwin 2012/07/19 20:50:09 media:: appears with Decryptor in most places but
xhwang 2012/07/19 21:54:03 Since ProxyDecryptor inherits media::Decryptor, so
124 }
125
126 scoped_ptr<media::Decryptor> ProxyDecryptor::CreateDecryptor(
127 const std::string& key_system) {
128 DCHECK(client_);
129
130 if (CanUseAesDecryptor(key_system))
131 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client_));
132
133 // We only support AesDecryptor and PpapiDecryptor. So if we cannot
134 // use the AesDecryptor, then we'll try to create a PpapiDecryptor for given
135 // |key_system|.
136 return CreatePpapiDecryptor(key_system);
137 }
138
70 } // namespace webkit_media 139 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/crypto/proxy_decryptor.h ('k') | webkit/media/webkit_media.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698