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

Unified Diff: ppapi/examples/content_decryptor/content_decryptor.cc

Issue 10836038: Call CDMWrapper from PpapiDecryptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add PP_DecryptionBuffer_Dev and update Decrypt() PPP call. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/examples/content_decryptor/content_decryptor.cc
diff --git a/ppapi/examples/content_decryptor/content_decryptor.cc b/ppapi/examples/content_decryptor/content_decryptor.cc
index f57d5b920f65ed2ac48e5bf28d922e7f63711ed3..d0f6d7a8342fa456f84a236569f0305bf4c7b10d 100644
--- a/ppapi/examples/content_decryptor/content_decryptor.cc
+++ b/ppapi/examples/content_decryptor/content_decryptor.cc
@@ -5,10 +5,13 @@
#include <cassert>
#include <string>
+#include <iostream>
+
#include "base/basictypes.h"
#include "base/rand_util.h"
#include "base/values.h"
#include "base/memory/scoped_ptr.h"
+#include "ppapi/c/dev/pp_decryption_buffer_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/core.h"
@@ -20,6 +23,7 @@
#include "ppapi/cpp/dev/content_decryptor_dev.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/utility/completion_callback_factory.h"
+#include "ppapi/utility/threading/simple_thread.h"
using ppapi::StringVar;
@@ -39,6 +43,7 @@ struct DecryptedData {
DecryptedData() : callback(PP_MakeCompletionCallback(NULL, NULL)) {}
PP_CompletionCallback callback;
std::string data;
+ uint32_t id;
};
bool IsMainThread() {
@@ -59,25 +64,33 @@ class CDMWrapper : public pp::Instance,
public:
const static size_t kSessionIdLength = 8;
CDMWrapper(PP_Instance instance, pp::Module* module);
- virtual ~CDMWrapper() {}
+ virtual ~CDMWrapper();
// PPP_ContentDecryptor_Dev methods
virtual bool GenerateKeyRequest(PP_Var key_system, PP_Resource init_data);
virtual bool AddKey(PP_Var session_id, PP_Resource key);
virtual bool CancelKeyRequest(PP_Var session_id);
- virtual bool Decrypt(PP_Resource encrypted_block,
- PP_CompletionCallback callback);
-
+ virtual bool Decrypt(const PP_DecryptionBuffer_Dev& encrypted_buffer);
virtual bool DecryptAndDecode(PP_Resource encrypted_block,
PP_CompletionCallback callback) {
return false;
}
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
+ std::cout << "Init!!!!!!!!!!!!!!!!!" << std::endl;
+ bool success = thread_->Start();
+ std::cout << "SimpleThread Start() returns: " << success << std::endl;
+ int32_t result = thread_->message_loop().PostWork(
+ callback_factory_.NewCallback(&CDMWrapper::CallOnBackground));
+ std::cout << "PostWork returns: " << result << std::endl;
return true;
}
private:
+ void CallOnBackground(int32_t result) {
+ std::cout << "CallOnBackground called on Background !!!!!!!!!" << std::endl;
+ }
+
PP_Resource StringToBufferResource(const std::string& str);
// <code>PPB_ContentDecryptor_Dev</code> dispatchers. These are passed to
@@ -111,15 +124,22 @@ class CDMWrapper : public pp::Instance,
// session_id:key? Or am I completely confused? :)
std::string key_;
std::string key_system_;
+
+ pp::SimpleThread* thread_;
};
CDMWrapper::CDMWrapper(PP_Instance instance,
pp::Module* module)
: pp::Instance(instance),
pp::ContentDecryptor_Dev(this) {
+ thread_ = new pp::SimpleThread(this);
callback_factory_.Initialize(this);
}
+CDMWrapper::~CDMWrapper() {
+ delete thread_;
+}
+
bool CDMWrapper::GenerateKeyRequest(PP_Var key_system_arg,
PP_Resource init_data) {
if (init_data) {
@@ -134,14 +154,14 @@ bool CDMWrapper::GenerateKeyRequest(PP_Var key_system_arg,
init_buffer.size());
}
- StringVar* key_system_var = StringVar::FromPPVar(key_system_arg);
+ //StringVar* key_system_var = StringVar::FromPPVar(key_system_arg);
// TODO(tomfinegan): confirm support for the key system.
DecryptorMessage decryptor_message;
- key_system_ = key_system_var->value();
+ key_system_ = "org.chromium.externalclearkey";
decryptor_message.key_system = key_system_;
- session_id_ = base::RandBytesAsString(kSessionIdLength);
+ session_id_ = "1";
decryptor_message.session_id = session_id_;
decryptor_message.default_url = "http://www.google.com";
decryptor_message.message_data = "key request";
@@ -177,16 +197,14 @@ bool CDMWrapper::CancelKeyRequest(PP_Var session_id_var) {
return true;
}
-bool CDMWrapper::Decrypt(PP_Resource encrypted_block,
- PP_CompletionCallback callback) {
- pp::Buffer_Dev block_buffer(encrypted_block);
- if (!block_buffer.data() || !callback.func) {
+bool CDMWrapper::Decrypt(const PP_DecryptionBuffer_Dev& encrypted_buffer) {
+ pp::Buffer_Dev block_buffer(encrypted_buffer.data);
+ if (!block_buffer.data())
return false;
- }
DecryptedData decrypted_data;
- decrypted_data.callback = callback;
decrypted_data.data = "Pretend I'm decrypted data!";
+ decrypted_data.id = encrypted_buffer.id;
CallOnMain(callback_factory_.NewCallback(&CDMWrapper::DeliverBlock,
decrypted_data));
return true;
@@ -215,31 +233,30 @@ void CDMWrapper::NeedKey(int32 result,
void CDMWrapper::KeyAdded(int32 result,
const DecryptorMessage& decryptor_message) {
- PP_Var key_system = StringVar::StringToPPVar(decryptor_message.key_system);
- PP_Var session_id = StringVar::StringToPPVar(decryptor_message.session_id);
- pp::ContentDecryptor_Dev::KeyAdded(key_system, session_id);
+ pp::Var key_system(decryptor_message.key_system);
+ pp::Var session_id(decryptor_message.session_id);
+ pp::ContentDecryptor_Dev::KeyAdded(key_system.pp_var(), session_id.pp_var());
}
void CDMWrapper::KeyMessage(int32 result,
const DecryptorMessage& decryptor_message) {
- PP_Var key_system = StringVar::StringToPPVar(decryptor_message.key_system);
- PP_Var session_id = StringVar::StringToPPVar(decryptor_message.session_id);
+ pp::Var key_system(decryptor_message.key_system);
+ pp::Var session_id(decryptor_message.session_id);
PP_Resource message =
StringToBufferResource(decryptor_message.message_data);
- PP_Var default_url =
- StringVar::StringToPPVar(decryptor_message.default_url);
- pp::ContentDecryptor_Dev::KeyMessage(key_system,
- session_id,
+ pp::Var default_url(decryptor_message.default_url);
+ pp::ContentDecryptor_Dev::KeyMessage(key_system.pp_var(),
+ session_id.pp_var(),
message,
- default_url);
+ default_url.pp_var());
}
void CDMWrapper::KeyError(int32 result,
const DecryptorMessage& decryptor_message) {
- PP_Var key_system = StringVar::StringToPPVar(decryptor_message.key_system);
- PP_Var session_id = StringVar::StringToPPVar(decryptor_message.session_id);
- pp::ContentDecryptor_Dev::KeyError(key_system,
- session_id,
+ pp::Var key_system(decryptor_message.key_system);
+ pp::Var session_id(decryptor_message.session_id);
+ pp::ContentDecryptor_Dev::KeyError(key_system.pp_var(),
+ session_id.pp_var(),
decryptor_message.media_error,
decryptor_message.system_error);
}
@@ -250,7 +267,7 @@ void CDMWrapper::DeliverBlock(int32 result,
decrypted_data.data);
if (decrypted_resource) {
pp::ContentDecryptor_Dev::DeliverBlock(decrypted_resource,
- decrypted_data.callback);
+ decrypted_data.id);
}
}

Powered by Google App Engine
This is Rietveld 408576698