Index: ppapi/cpp/dev/content_decryption_module_dev.cc |
diff --git a/ppapi/cpp/dev/content_decryption_module_dev.cc b/ppapi/cpp/dev/content_decryption_module_dev.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4fc6a45f2be7152a8d32139a3e48b6cf6117008a |
--- /dev/null |
+++ b/ppapi/cpp/dev/content_decryption_module_dev.cc |
@@ -0,0 +1,111 @@ |
+// 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 "ppapi/cpp/dev/content_decryption_module_dev.h" |
+ |
+#include "ppapi/c/dev/ppp_content_decryption_module_dev.h" |
+#include "ppapi/cpp/instance.h" |
+#include "ppapi/cpp/instance_handle.h" |
+#include "ppapi/cpp/module.h" |
+#include "ppapi/cpp/module_impl.h" |
+ |
+namespace pp { |
+ |
+namespace { |
+ |
+static const char kPPPContentDecryptionModuleInterface[] = |
+ PPP_CONTENTDECRYPTIONMODULE_DEV_INTERFACE; |
+ |
+PP_Bool GenerateKeyRequest(PP_Instance instance, |
+ PP_Var key_system, |
+ PP_Resource init_data) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, |
+ kPPPContentDecryptionModuleInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptionModule_Dev*>(object)->GenerateKeyRequest( |
+ key_system, |
+ init_data)); |
+} |
+ |
+PP_Bool AddKey(PP_Instance instance, |
+ PP_Var session_id, |
+ PP_Resource key) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, |
+ kPPPContentDecryptionModuleInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptionModule_Dev*>(object)->AddKey(session_id, |
+ key)); |
+} |
+ |
+PP_Bool CancelKeyRequest(PP_Instance instance, |
+ PP_Var session_id) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, |
+ kPPPContentDecryptionModuleInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptionModule_Dev*>(object)->CancelKeyRequest( |
+ session_id)); |
+} |
+ |
+ |
+PP_Bool Decrypt(PP_Instance instance, |
+ PP_Resource encrypted_block, |
+ PP_CompletionCallback callback) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, |
+ kPPPContentDecryptionModuleInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptionModule_Dev*>(object)->Decrypt( |
+ encrypted_block, |
+ callback)); |
+} |
+ |
+PP_Bool DecryptAndDecode(PP_Instance instance, |
+ PP_Resource encrypted_block, |
+ PP_CompletionCallback callback) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, |
+ kPPPContentDecryptionModuleInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptionModule_Dev*>(object)->DecryptAndDecode( |
+ encrypted_block, |
+ callback)); |
+} |
+ |
+const PPP_ContentDecryptionModule_Dev ppp_content_decryption_module = { |
+ &GenerateKeyRequest, |
+ &AddKey, |
+ &CancelKeyRequest, |
+ &Decrypt, |
+ &DecryptAndDecode |
+}; |
+ |
+} // namespace |
+ |
+ContentDecryptionModule_Dev::ContentDecryptionModule_Dev(Instance* instance) |
+ : associated_instance_(instance) { |
+ Module::Get()->AddPluginInterface(kPPPContentDecryptionModuleInterface, |
+ &ppp_content_decryption_module); |
+ instance->AddPerInstanceObject(kPPPContentDecryptionModuleInterface, this); |
+} |
+ |
+ContentDecryptionModule_Dev::~ContentDecryptionModule_Dev() { |
+ Instance::RemovePerInstanceObject(associated_instance_, |
+ kPPPContentDecryptionModuleInterface, |
+ this); |
+} |
+ |
+} // namespace pp |