Index: ppapi/cpp/dev/content_decryptor_dev.cc |
diff --git a/ppapi/cpp/dev/content_decryptor_dev.cc b/ppapi/cpp/dev/content_decryptor_dev.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dddbd521806ee7f177fcc96787678b8fcbeea22b |
--- /dev/null |
+++ b/ppapi/cpp/dev/content_decryptor_dev.cc |
@@ -0,0 +1,107 @@ |
+// 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_decryptor_dev.h" |
+ |
+#include "ppapi/c/dev/ppp_content_decryptor_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 kPPPContentDecryptorInterface[] = |
+ PPP_CONTENTDECRYPTOR_DEV_INTERFACE; |
+ |
+PP_Bool GenerateKeyRequest(PP_Instance instance, |
+ PP_Var key_system, |
+ PP_Resource init_data) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptor_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, |
+ kPPPContentDecryptorInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptor_Dev*>(object)->AddKey(session_id, |
+ key)); |
+} |
+ |
+PP_Bool CancelKeyRequest(PP_Instance instance, |
+ PP_Var session_id) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptor_Dev*>(object)->CancelKeyRequest( |
+ session_id)); |
+} |
+ |
+ |
+PP_Bool Decrypt(PP_Instance instance, |
+ PP_Resource encrypted_block, |
+ PP_CompletionCallback callback) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptor_Dev*>(object)->Decrypt( |
+ encrypted_block, |
+ callback)); |
+} |
+ |
+PP_Bool DecryptAndDecode(PP_Instance instance, |
+ PP_Resource encrypted_block, |
+ PP_CompletionCallback callback) { |
+ void* object = |
+ Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
+ if (!object) |
+ return PP_FALSE; |
+ return PP_FromBool( |
+ static_cast<ContentDecryptor_Dev*>(object)->DecryptAndDecode( |
+ encrypted_block, |
+ callback)); |
+} |
+ |
+const PPP_ContentDecryptor_Dev ppp_content_decryptor = { |
+ &GenerateKeyRequest, |
+ &AddKey, |
+ &CancelKeyRequest, |
+ &Decrypt, |
+ &DecryptAndDecode |
+}; |
+ |
+} // namespace |
+ |
+ContentDecryptor_Dev::ContentDecryptor_Dev(Instance* instance) |
+ : associated_instance_(instance) { |
+ Module::Get()->AddPluginInterface(kPPPContentDecryptorInterface, |
+ &ppp_content_decryptor); |
+ instance->AddPerInstanceObject(kPPPContentDecryptorInterface, this); |
+} |
+ |
+ContentDecryptor_Dev::~ContentDecryptor_Dev() { |
+ Instance::RemovePerInstanceObject(associated_instance_, |
+ kPPPContentDecryptorInterface, |
+ this); |
+} |
+ |
+} // namespace pp |