Commit 8953fe29 authored by xhwang@chromium.org's avatar xhwang@chromium.org

Connect PpapiDecryptor and PluginInstance.

- In PpapiDecrytor, enable calls into the PluginInstance.
- In PluginInstance, passing in all data needed by the PPP_ContentDecryptor interface.
- Hook up DecryptorClient and PPB_ContentDecryptor calls in PluginInstance.

BUG=138139
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10871006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153629 0039d316-1c4b-4281-b951-d872f2087c98
parent 7c6de19b
...@@ -15,7 +15,14 @@ struct PP_DecryptTrackingInfo { ...@@ -15,7 +15,14 @@ struct PP_DecryptTrackingInfo {
* this value, the client can associate the decrypted block with a decryption * this value, the client can associate the decrypted block with a decryption
* request. * request.
*/ */
uint64_t request_id; uint32_t request_id;
/**
* 4-byte padding to make the size of <code>PP_DecryptTrackingInfo</code>
* a multiple of 8 bytes and make sure |timestamp| starts on 8-byte boundary.
* The value of this field should not be used.
*/
uint32_t padding;
/** /**
* Timestamp in microseconds of the associated block. By using this value, * Timestamp in microseconds of the associated block. By using this value,
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
/* From private/pp_content_decryptor.idl modified Thu Aug 16 20:21:00 2012. */ /* From private/pp_content_decryptor.idl modified Fri Aug 24 16:06:47 2012. */
#ifndef PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_ #ifndef PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_
#define PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_ #define PPAPI_C_PRIVATE_PP_CONTENT_DECRYPTOR_H_
...@@ -29,7 +29,13 @@ struct PP_DecryptTrackingInfo { ...@@ -29,7 +29,13 @@ struct PP_DecryptTrackingInfo {
* this value, the client can associate the decrypted block with a decryption * this value, the client can associate the decrypted block with a decryption
* request. * request.
*/ */
uint64_t request_id; uint32_t request_id;
/**
* 4-byte padding to make the size of <code>PP_DecryptTrackingInfo</code>
* a multiple of 8 bytes and make sure |timestamp| starts on 8-byte boundary.
* The value of this field should not be used.
*/
uint32_t padding;
/** /**
* Timestamp in microseconds of the associated block. By using this value, * Timestamp in microseconds of the associated block. By using this value,
* the client can associate the decrypted (and decoded) data with an input * the client can associate the decrypted (and decoded) data with an input
......
...@@ -4,7 +4,13 @@ ...@@ -4,7 +4,13 @@
#include "webkit/media/crypto/ppapi_decryptor.h" #include "webkit/media/crypto/ppapi_decryptor.h"
#include <string>
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "media/base/decoder_buffer.h" #include "media/base/decoder_buffer.h"
#include "media/base/decryptor_client.h" #include "media/base/decryptor_client.h"
#include "webkit/media/crypto/key_systems.h" #include "webkit/media/crypto/key_systems.h"
...@@ -16,7 +22,11 @@ PpapiDecryptor::PpapiDecryptor( ...@@ -16,7 +22,11 @@ PpapiDecryptor::PpapiDecryptor(
media::DecryptorClient* client, media::DecryptorClient* client,
const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance) const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance)
: client_(client), : client_(client),
cdm_plugin_(plugin_instance) { cdm_plugin_(plugin_instance),
render_loop_proxy_(base::MessageLoopProxy::current()) {
DCHECK(client_);
DCHECK(cdm_plugin_);
cdm_plugin_->set_decrypt_client(client);
} }
PpapiDecryptor::~PpapiDecryptor() { PpapiDecryptor::~PpapiDecryptor() {
...@@ -25,12 +35,18 @@ PpapiDecryptor::~PpapiDecryptor() { ...@@ -25,12 +35,18 @@ PpapiDecryptor::~PpapiDecryptor() {
void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system,
const uint8* init_data, const uint8* init_data,
int init_data_length) { int init_data_length) {
DVLOG(1) << "GenerateKeyRequest()";
DCHECK(render_loop_proxy_->BelongsToCurrentThread());
DCHECK(cdm_plugin_); DCHECK(cdm_plugin_);
// TODO(xhwang): Enable the following once we have updated PluginInstance.
// if (!cdm_plugin_->GenerateKeyRequest(key_system, // TODO(xhwang): Finalize the data type for |init_data| to avoid unnecessary
// init_data, init_data_length)) { // data type conversions.
// client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); if (!cdm_plugin_->GenerateKeyRequest(
// } key_system,
std::string(reinterpret_cast<const char*>(init_data),
init_data_length))) {
ReportFailureToCallPlugin(key_system, "");
}
} }
void PpapiDecryptor::AddKey(const std::string& key_system, void PpapiDecryptor::AddKey(const std::string& key_system,
...@@ -39,43 +55,52 @@ void PpapiDecryptor::AddKey(const std::string& key_system, ...@@ -39,43 +55,52 @@ void PpapiDecryptor::AddKey(const std::string& key_system,
const uint8* init_data, const uint8* init_data,
int init_data_length, int init_data_length,
const std::string& session_id) { const std::string& session_id) {
DVLOG(1) << "AddKey()";
DCHECK(render_loop_proxy_->BelongsToCurrentThread());
DCHECK(cdm_plugin_); DCHECK(cdm_plugin_);
// TODO(xhwang): Enable the following once we have updated PluginInstance.
// if (!cdm_plugin_->AddKey(key_system, key, key_length, if (!cdm_plugin_->AddKey(session_id,
// init_data, init_data_length, session_id)) { std::string(reinterpret_cast<const char*>(key),
// client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); key_length),
// } std::string(reinterpret_cast<const char*>(init_data),
init_data_length))) {
ReportFailureToCallPlugin(key_system, session_id);
}
} }
void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, void PpapiDecryptor::CancelKeyRequest(const std::string& key_system,
const std::string& session_id) { const std::string& session_id) {
DVLOG(1) << "CancelKeyRequest()";
DCHECK(render_loop_proxy_->BelongsToCurrentThread());
DCHECK(cdm_plugin_); DCHECK(cdm_plugin_);
// TODO(xhwang): Enable the following once we have updated PluginInstance.
// if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) if (!cdm_plugin_->CancelKeyRequest(session_id))
// client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); ReportFailureToCallPlugin(key_system, session_id);
} }
void PpapiDecryptor::Decrypt( void PpapiDecryptor::Decrypt(
const scoped_refptr<media::DecoderBuffer>& encrypted, const scoped_refptr<media::DecoderBuffer>& encrypted,
const DecryptCB& decrypt_cb) { const DecryptCB& decrypt_cb) {
DCHECK(cdm_plugin_); DVLOG(1) << "Decrypt()";
// TODO(xhwang): Enable the following once we have updated PluginInstance. if (!render_loop_proxy_->BelongsToCurrentThread()) {
// TODO(xhwang): Need to figure out thread safety about PPP calls. render_loop_proxy_->PostTask(
// if (!cdm_plugin_->Decrypt( FROM_HERE,
// encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this),
// decrypt_cb.Run(kError, NULL); encrypted, decrypt_cb));
// } return;
}
if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb))
decrypt_cb.Run(kError, NULL);
} }
void PpapiDecryptor::Stop() { void PpapiDecryptor::Stop() {
} }
void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system,
const uint8* data, int data_size ) { const std::string& session_id) {
DCHECK(!decrypt_cb.is_null()); DVLOG(1) << "Failed to call plugin.";
scoped_refptr<media::DecoderBuffer> decrypted_data = client_->KeyError(key_system, session_id, kUnknownError, 0);
media::DecoderBuffer::CopyFrom(data, data_size);
decrypt_cb.Run(kSuccess, decrypted_data);
} }
} // namespace webkit_media } // namespace webkit_media
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "media/base/decryptor.h" #include "media/base/decryptor.h"
namespace base {
class MessageLoopProxy;
}
namespace media { namespace media {
class DecryptorClient; class DecryptorClient;
} }
...@@ -22,6 +26,9 @@ class PluginInstance; ...@@ -22,6 +26,9 @@ class PluginInstance;
namespace webkit_media { namespace webkit_media {
// PpapiDecrypor implements media::Decryptor and forwards all calls to the
// PluginInstance.
// This class should always be created on the main renderer thread.
class PpapiDecryptor : public media::Decryptor { class PpapiDecryptor : public media::Decryptor {
public: public:
PpapiDecryptor( PpapiDecryptor(
...@@ -46,13 +53,12 @@ class PpapiDecryptor : public media::Decryptor { ...@@ -46,13 +53,12 @@ class PpapiDecryptor : public media::Decryptor {
virtual void Stop() OVERRIDE; virtual void Stop() OVERRIDE;
private: private:
// Callback for the plugin to hand back the decrypted data. void ReportFailureToCallPlugin(const std::string& key_system,
void DataReady(const DecryptCB& decrypt_cb, const uint8* data, int data_size); const std::string& session_id);
// TODO(xhwang): Need to figure out how the CDM plugin fires key events
// (e.g. KeyMessage).
media::DecryptorClient* client_; media::DecryptorClient* client_;
scoped_refptr<webkit::ppapi::PluginInstance> cdm_plugin_; scoped_refptr<webkit::ppapi::PluginInstance> cdm_plugin_;
scoped_refptr<base::MessageLoopProxy> render_loop_proxy_;
DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor); DISALLOW_COPY_AND_ASSIGN(PpapiDecryptor);
}; };
......
...@@ -4,6 +4,7 @@ include_rules = [ ...@@ -4,6 +4,7 @@ include_rules = [
"+ppapi/thunk", "+ppapi/thunk",
"+printing", "+printing",
"+media/audio", "+media/audio",
"+media/base",
"+media/video", "+media/video",
"+ui/base/ime", "+ui/base/ime",
"+ui/base/range", "+ui/base/range",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_ #ifndef WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_
#define WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_ #define WEBKIT_PLUGINS_PPAPI_PPAPI_PLUGIN_INSTANCE_H_
#include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/string16.h" #include "base/string16.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "media/base/decryptor.h"
#include "ppapi/c/dev/pp_cursor_type_dev.h" #include "ppapi/c/dev/pp_cursor_type_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/dev/ppp_find_dev.h" #include "ppapi/c/dev/ppp_find_dev.h"
...@@ -69,6 +71,11 @@ struct WebCursorInfo; ...@@ -69,6 +71,11 @@ struct WebCursorInfo;
struct WebPrintParams; struct WebPrintParams;
} }
namespace media {
class DecoderBuffer;
class DecryptorClient;
}
namespace ppapi { namespace ppapi {
struct InputEventData; struct InputEventData;
struct PPP_Instance_Combined; struct PPP_Instance_Combined;
...@@ -243,17 +250,19 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : ...@@ -243,17 +250,19 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
// Provides access to PPP_ContentDecryptor_Private. // Provides access to PPP_ContentDecryptor_Private.
// TODO(tomfinegan): Move decryptor methods to delegate class. // TODO(tomfinegan): Move decryptor methods to delegate class.
typedef base::Callback<void(void*, int)> DecryptedDataCB; void set_decrypt_client(media::DecryptorClient* client);
bool GenerateKeyRequest(const std::string& key_system, bool GenerateKeyRequest(const std::string& key_system,
const std::string& init_data); const std::string& init_data);
bool AddKey(const std::string& session_id, bool AddKey(const std::string& session_id,
const std::string& key, const std::string& key,
const std::string& init_data); const std::string& init_data);
bool CancelKeyRequest(const std::string& session_id); bool CancelKeyRequest(const std::string& session_id);
bool Decrypt(const base::StringPiece& encypted_block, bool Decrypt(const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
const DecryptedDataCB& callback); const media::Decryptor::DecryptCB& decrypt_cb);
bool DecryptAndDecode(const base::StringPiece& encypted_block, // TODO(xhwang): Update this when we need to support decrypt and decode.
const DecryptedDataCB& callback); bool DecryptAndDecode(
const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
const media::Decryptor::DecryptCB& decrypt_cb);
// There are 2 implementations of the fullscreen interface // There are 2 implementations of the fullscreen interface
// PPB_FlashFullscreen is used by Pepper Flash. // PPB_FlashFullscreen is used by Pepper Flash.
...@@ -337,7 +346,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : ...@@ -337,7 +346,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
void OnLockMouseACK(bool succeeded); void OnLockMouseACK(bool succeeded);
// A mouse lock was in place, but has been lost. // A mouse lock was in place, but has been lost.
void OnMouseLockLost(); void OnMouseLockLost();
// A mouse lock is enabled and mouse events are being delievered. // A mouse lock is enabled and mouse events are being delivered.
void HandleMouseLockedInputEvent(const WebKit::WebMouseEvent& event); void HandleMouseLockedInputEvent(const WebKit::WebMouseEvent& event);
// Simulates an input event to the plugin by passing it down to WebKit, // Simulates an input event to the plugin by passing it down to WebKit,
...@@ -465,7 +474,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : ...@@ -465,7 +474,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
// number of interfaces implemented by PluginInstance. // number of interfaces implemented by PluginInstance.
class GamepadImpl : public ::ppapi::thunk::PPB_Gamepad_API { class GamepadImpl : public ::ppapi::thunk::PPB_Gamepad_API {
public: public:
GamepadImpl(PluginDelegate* delegate); explicit GamepadImpl(PluginDelegate* delegate);
virtual void Sample(PP_GamepadsSampleData* data) OVERRIDE; virtual void Sample(PP_GamepadsSampleData* data) OVERRIDE;
private: private:
PluginDelegate* delegate_; PluginDelegate* delegate_;
...@@ -739,6 +748,11 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : ...@@ -739,6 +748,11 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
// the pointer so we can re-send it later if we are reset to talk to NaCl. // the pointer so we can re-send it later if we are reset to talk to NaCl.
scoped_refptr<PPB_URLLoader_Impl> document_loader_; scoped_refptr<PPB_URLLoader_Impl> document_loader_;
media::DecryptorClient* decryptor_client_;
uint32_t next_decryption_request_id_;
typedef std::map<uint32_t, media::Decryptor::DecryptCB> DecryptionCBMap;
DecryptionCBMap pending_decryption_cbs_;
DISALLOW_COPY_AND_ASSIGN(PluginInstance); DISALLOW_COPY_AND_ASSIGN(PluginInstance);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment