Index: webkit/media/crypto/proxy_decryptor.cc |
diff --git a/webkit/media/crypto/proxy_decryptor.cc b/webkit/media/crypto/proxy_decryptor.cc |
index 0c9646452325c69a2a93bbebbf586e4377f2ed70..27284273d0c5ac84e2ec6c5243ff9af548cf213a 100644 |
--- a/webkit/media/crypto/proxy_decryptor.cc |
+++ b/webkit/media/crypto/proxy_decryptor.cc |
@@ -8,12 +8,42 @@ |
#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/WebMediaPlayerClient.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" |
namespace webkit_media { |
-ProxyDecryptor::ProxyDecryptor(media::DecryptorClient* client) |
- : client_(client) { |
+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() { |
@@ -26,10 +56,18 @@ void ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, |
// only creates a new decryptor when |decryptor_| is not initialized. |
if (!decryptor_.get()) { |
base::AutoLock auto_lock(lock_); |
- decryptor_ = CreateDecryptor(key_system, client_); |
+ decryptor_ = CreateDecryptor(key_system); |
+ } |
+ |
+ DCHECK(client_); |
+ if (!decryptor_.get()) { |
+ // TODO(ddorwin): Update the spec about generateKeyRequest to include an |
+ // error for handler loading failure. In our case, this can happen when the |
+ // plugin cannot be loaded. |
+ client_->KeyError(key_system, "", Decryptor::kUnknownError, 0); |
+ return; |
} |
- DCHECK(decryptor_.get()); |
decryptor_->GenerateKeyRequest(key_system, init_data, init_data_length); |
} |
@@ -67,4 +105,35 @@ void ProxyDecryptor::Decrypt( |
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<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
|
+} |
+ |
+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 |